inst_xsb.c

00001 /* File:      inst_xsb.c
00002 ** Author(s): Warren, Swift, Xu, Sagonas, Freire, Johnson
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: inst_xsb.c,v 1.16 2005/10/03 13:26:43 tswift Exp $
00023 ** 
00024 */
00025 
00026 
00027 #include "xsb_config.h"
00028 #include "xsb_debug.h"
00029 
00030 #include "auxlry.h"
00031 #include "cell_xsb.h"
00032 #include "inst_xsb.h"
00033 #include "subinst.h"
00034 
00035 extern void init_builtin_table(void);
00036 
00037 /* ------------------------------------------------------------------- */
00038 #ifdef PROFILE
00039 
00040 /* Initialize this stuff for profiling.  In profiling, the number of
00041    occurrences of each instruction can be counted, as well as
00042    operations that happen within instructions, such as switch_envs,
00043    and others.  Thus the instruction tables have an added field, to
00044    keep the count.  In addition, statistics on SCCs can be derived and
00045    the SDGs themselves printed out, if you like. */
00046 
00047 Cell inst_table[BUILTIN_TBL_SZ][6];
00048 
00049 unsigned long num_switch_envs;
00050 unsigned long num_switch_envs_iter;
00051 
00052 Cell subinst_table[BUILTIN_TBL_SZ][2];
00053 
00054 #define XSB_INST(inum, inst, label, op1type, op2type, op3type, op4type) \
00055         inst_table[inst][0] = (Cell)( #inst ); \
00056         inst_table[inst][1] = op1type; \
00057         inst_table[inst][2] = op2type; \
00058         inst_table[inst][3] = op3type; \
00059         inst_table[inst][4] = op4type; \
00060         inst_table[inst][5] = 0
00061 
00062 #define profile_inst(inst) \
00063         inst_table[inst][5] = inst_table[inst][5] + 1
00064 
00065 #define set_subinst_table(inst,instr) \
00066         subinst_table[inst][0] = (Cell)(instr); \
00067         subinst_table[inst][1] = 0
00068 
00069 /* ProfileLeader */
00070 int max_subgoals = 0;
00071 int max_completed = 0;
00072 int max_consumers_in_ascc = 0;
00073 int max_compl_susps_in_ascc = 0;
00074 int trapped_prolog_cps = 0;
00075 
00076 /* SpitOutGraph */
00077 int sdg_sample_rate = 2000;
00078 int sdg_check_num = 0;
00079 
00080 #else
00081 Cell inst_table[BUILTIN_TBL_SZ][5];
00082 
00083 #define XSB_INST(inum, inst, label, op1type, op2type, op3type, op4type) \
00084         inst_table[inst][0] = (Cell)( #inst ); \
00085         inst_table[inst][1] = op1type; \
00086         inst_table[inst][2] = op2type; \
00087         inst_table[inst][3] = op3type; \
00088         inst_table[inst][4] = op4type
00089 #endif /* PROFILE */
00090 
00091 /*----------------------------------------------------------------------*/
00092 
00093 int sizeof_inst(byte inst)
00094 { /* returns the size of an instruction in bytes */
00095   int i, size;
00096 
00097   size = 1;
00098   for (i=2; i <= 4 && inst_table[inst][i] != X; i++) {
00099     size++;
00100   }
00101   size *= sizeof(byte *); /* works for both 32 & 64 bit machines */
00102   return size;
00103 }
00104 
00105 void init_instructions() 
00106 {
00107 #include "xsb_inst_list.h"
00108 #undef XSB_INST
00109 }
00110 
00111 #ifdef PROFILE /* for profiling only */
00112 void init_subinst_table(void)
00113 {
00114   set_subinst_table(OUTER_FIXPOINT,"outer_fixpoint");
00115   set_subinst_table(ITER_FIXPOINT,"inner_fixpoint");
00116   set_subinst_table(SCHED_ANSWERS,"sched_answers");
00117   set_subinst_table(SIMPL_REMOVE_DL,"simpl_remove_dl");
00118   set_subinst_table(SIMPL_REMOVE_DE,"simpl_remove_de");
00119   set_subinst_table(NEW_ANSWER_SIMPL_POS_UNS,"new_answer_simpl_pos_uns");
00120   set_subinst_table(NEW_ANSWER_SIMPL_POS_UNC,"new_answer_simpl_pos_unc");
00121   set_subinst_table(NEW_ANSWER_SIMPL_NEG_FAIL,"new_answer_simpl_neg_fail");
00122   set_subinst_table(NEW_ANSWER_SIMPL_NEG_SUC,"new_answer_simpl_neg_succ");
00123   num_switch_envs=0;
00124   num_switch_envs_iter=0;
00125 }
00126 #endif
00127 
00128 /*----------------------------------------------------------------------*/
00129 
00130 void init_inst_table(void)
00131 {
00132     init_instructions();
00133     init_builtin_table();
00134 #ifdef PROFILE
00135     init_subinst_table();
00136 #endif
00137 }
00138 
00139 /*----------------------------------------------------------------------*/

Generated on Wed Jul 26 13:30:41 2006 for XSB by  doxygen 1.4.5