inst_xsb.h

00001 /* File:      inst_xsb.h
00002 ** Author(s): Warren, Swift, Xu, Sagonas, Freire, Johnson, Rao
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.h,v 1.21 2006/01/27 17:50:19 dwarren Exp $
00023 ** 
00024 */
00025 
00026 
00027 #ifndef __XSB_INSTS__
00028 
00029 #define __XSB_INSTS__
00030 
00031 extern void init_inst_table(void);
00032 
00033 /************************************************************************/
00034 /*      The following are operand types of instructions.                */
00035 /************************************************************************/
00036 
00037 #define A    1  /* a byte of integer (for arity, size, builtin-num, etc) */
00038 #define V    2  /* variable offset */
00039 #define R    3  /* register number */
00040 #define S    4  /* structure symbol */
00041 #define C    5  /* constant symbol */
00042 #define L    6  /* label (address) */
00043 #define G    7  /* string */
00044 #define N    8  /* number (integer) */
00045 #define I    9  /* 2nd & 3rd arguments of switchonbound */
00046 #define P   10  /* pad */
00047 #define X   11  /* not present */
00048 #define PP  12  /* double pad */
00049 #define PPP 13  /* triple pad */
00050 #define PPR 14  /* = PP + R; for switchonterm and switchonbound */
00051 #define T   15  /* tabletry (tip pointer) */
00052 #define RRR 16  /* = R + R + R; for switchon3bound */
00053 #define F   17  /* floating point number */
00054 #define B   18  /* tagged (boxed) integer number */
00055 #define PRR 19  /* = P + R + R; for fun_test_ne */
00056 
00057 /************************************************************************/
00058 /*      Macros to fetch the instructions/operands.                      */
00059 /************************************************************************/
00060 
00061 #define inst_name(C)            ((char *)inst_table[C][0])
00062 
00063 #define cell_opcode(C)          (*(pb)(C))
00064 
00065 #define cell_opregaddr1(C)      (rreg+((pb)(cell))[1])
00066 #define cell_opregaddr2(C)      (rreg+((pb)(cell))[2])
00067 #define cell_opregaddr3(C)      (rreg+((pb)(cell))[3])
00068 #define cell_opregaddrn(C,N)    (rreg+((pb)(cell))[N])
00069 
00070 #define cell_opreg1(C)          (cell(opregaddr1(C)))
00071 #define cell_opreg2(C)          (cell(opregaddr2(C)))
00072 #define cell_opreg3(C)          (cell(opregaddr3(C)))
00073 #define cell_opregn(C)          (cell(opregaddrn(C,N)))
00074 
00075 #define cell_operand1(C)        (((pb)(C))[1])
00076 #define cell_operand2(C)        (((pb)(C))[2])
00077 #define cell_operand3(C)        (((pb)(C))[3])
00078 #define cell_operandn(C,N)      (((pb)(C))[N])
00079 
00080 /* Unused right now, but may come handy in future. */
00081 
00082 /*
00083 #define get_code_cell(pc)                       (*(pc)++)
00084 */
00085 
00086 /* bit fields */
00087 
00088 /*
00089 #define get_last__8bits(cell)           (((Cell)(cell))&0xff)
00090 #define get_last_16bits(cell)           (((Cell)(cell))&0xffff)
00091 #define get_last_32bits(cell)           (((Cell)(cell))&0xffffffff)
00092 
00093 #define get_first__8bits(cell)          (((Cell)(cell))>>(sizeof(Cell)*8-8))
00094 #define get_first_16bits(cell)          (((Cell)(cell))>>(sizeof(Cell)*8-16))
00095 #define get_first_32bits(cell)          (((Cell)(cell))>>(sizeof(Cell)*8-32))
00096 
00097 #define get__8bit_field(cell, pos)      \
00098                 (((Cell)(cell))>>((sizeof(Cell)-pos-1)*8)&0xff)
00099 #define get_16bit_field(cell, pos)      \
00100                 (((Cell)(cell))>>((sizeof(Cell)-pos-1)*16)&0xffff)
00101 #define get_32bit_field(cell, pos)      \
00102                 (((Cell)(cell))>>((sizeof(Cell)-pos-1)*32)&0xffffffff)
00103 */
00104 
00105 /* opcode & operand fields */
00106 
00107 /*
00108 #ifdef BITS64
00109 #define opquarter0(cell)                (get_first_16bits(cell))
00110 #define opquarter1(cell)                (get_16bit_field(cell,1))
00111 #define opquarter2(cell)                (get_16bit_field(cell,2))
00112 #define opquarter3(cell)                (get_last_16bits(cell))
00113 #define opquartern(cell,N)              (get_16bit_field(cell,N))
00114 #else
00115 #define opquarter0(cell)                (get_first__8bits(cell))
00116 #define opquarter1(cell)                (get__8bit_field(cell,1))
00117 #define opquarter2(cell)                (get__8bit_field(cell,2))
00118 #define opquarter3(cell)                (get_last__8bits(cell))
00119 #define opquartern(cell,N)              (get__8bit_field(cell,N))
00120 #endif
00121 #define opcell(cell)                    ((Cell)(cell))
00122 #define opint(cell)                     ((Integer)(cell))
00123 
00124 #define opcode(cell)                    ((short)opquarter0(cell))
00125 
00126 #define opregaddr1(cell)                (rreg+opquarter1(cell))
00127 #define opregaddr2(cell)                (rreg+opquarter2(cell))
00128 #define opregaddr3(cell)                (rreg+opquarter3(cell))
00129 #define opregaddrn(cell,N)              (rreg+opquartern(cell,N))
00130 
00131 #define opreg1(cell)                    (cell(opregaddr1(cell)))
00132 #define opreg2(cell)                    (cell(opregaddr2(cell)))
00133 #define opreg3(cell)                    (cell(opregaddr3(cell)))
00134 #define opregn(cell)                    (cell(opregaddrn(cell,N)))
00135 
00136 #define operand1(cell)                  ((short)opquarter1(cell))
00137 #define operand2(cell)                  ((short)opquarter2(cell))
00138 #define operand3(cell)                  ((short)opquarter3(cell))
00139 #define operandn(cell,N)                ((short)opquartern(cell,N))
00140 */
00141 
00142 
00143 /*
00144 #define opvaraddr(cell)                 (ereg+(-(Cell)(cell)))
00145 */
00146 /* 64 bit could benefit from change in compiler/loader for the V operands */
00147 
00148 /*
00149 #define opvaraddr1(cell)        (ereg+(-(unsigned int)(opquarter1(cell))))
00150 #define opvaraddr2(cell)        (ereg+(-(unsigned int)(opquarter2(cell))))
00151 #define opvaraddr3(cell)        (ereg+(-(unsigned int)(opquarter3(cell))))
00152 #define opvaraddrn(cell,N)      (ereg+(-(unsigned int)(opquartern(cell,n))))
00153 
00154 #define opvar1(cell)                    (cell(opvaraddr1(cell)))
00155 #define opvar2(cell)                    (cell(opvaraddr2(cell)))
00156 #define opvar3(cell)                    (cell(opvaraddr3(cell)))
00157 #define opvarn(cell,N)                  (cell(opvaraddrn(cell,N)))
00158 */
00159 
00160 
00161 #define BUILTIN_TBL_SZ 256
00162 
00163 #ifdef PROFILE
00164 extern Cell inst_table[BUILTIN_TBL_SZ][6];
00165 extern unsigned long num_switch_envs;
00166 extern unsigned long num_switch_envs_iter;
00167 #else
00168 extern Cell inst_table[BUILTIN_TBL_SZ][5];
00169 #endif
00170 
00171 /************************************************************************/
00172 /*      The following is the set of all instructions.                   */
00173 /************************************************************************/
00174 
00175 /* Basic term instructions */
00176 
00177 #define getpvar         0x00
00178 #define getpval         0x01
00179 #define getstrv         0x02
00180 #define gettval         0x03
00181 #define getcon          0x04
00182 #define getnil          0x05
00183 #define getstr          0x06
00184 #define getlist         0x07
00185 #define unipvar         0x08
00186 #define unipval         0x09
00187 #define unitvar         0x0a
00188 #define unitval         0x0b
00189 #define unicon          0x0c
00190 #define uninil          0x0d
00191 #define getnumcon       0x0e
00192 #define putnumcon       0x0f
00193 #define putpvar         0x10
00194 #define putpval         0x11
00195 #define puttvar         0x12
00196 #define putstrv         0x13
00197 #define putcon          0x14
00198 #define putnil          0x15
00199 #define putstr          0x16
00200 #define putlist         0x17
00201 #define bldpvar         0x18
00202 #define bldpval         0x19
00203 #define bldtvar         0x1a
00204 #define bldtval         0x1b
00205 #define bldcon          0x1c
00206 #define bldnil          0x1d
00207 #define uninumcon       0x1e
00208 #define bldnumcon       0x1f
00209 
00210 #define no_inst         0x20 
00211 /* the above number is used for invalid opcodes in the threading engine */
00212 
00213 #define uniavar         0x21  /* for single occurrence variables */
00214 #define bldavar         0x22
00215 
00216 #define getattv         0x30
00217 #define putattv         0x31
00218 
00219 #define getlist_tvar_tvar       0x48
00220 
00221 /*----- Instructions for tries as code (Do NOT change the numbers) -----*/
00222 
00223 #define trie_no_cp_attv         0x5c
00224 #define trie_trust_attv         0x5d
00225 #define trie_try_attv           0x5e
00226 #define trie_retry_attv         0x5f
00227 
00228 #define trie_no_cp_str          0x60
00229 #define trie_trust_str          0x61
00230 #define trie_try_str            0x62
00231 #define trie_retry_str          0x63
00232 
00233 #define trie_no_cp_list         0x64
00234 #define trie_trust_list         0x65
00235 #define trie_try_list           0x66
00236 #define trie_retry_list         0x67
00237 
00238 #define trie_no_cp_var          0x68
00239 #define trie_trust_var          0x69
00240 #define trie_try_var            0x6a
00241 #define trie_retry_var          0x6b
00242 
00243 #define trie_no_cp_val          0x6c
00244 #define trie_trust_val          0x6d
00245 #define trie_try_val            0x6e
00246 #define trie_retry_val          0x6f
00247 
00248 #define trie_no_cp_numcon       0x70
00249 #define trie_trust_numcon       0x71
00250 #define trie_try_numcon         0x72
00251 #define trie_retry_numcon       0x73
00252 
00253 #define trie_no_cp_numcon_succ  0x74
00254 #define trie_trust_numcon_succ  0x75
00255 #define trie_try_numcon_succ    0x76
00256 #define trie_retry_numcon_succ  0x77
00257 
00258 #define trie_proceed            0x78
00259 #define hash_opcode             0x79
00260 #define hash_handle             0x7a
00261 #define trie_assert_inst        0x7c
00262 #define trie_root               0x7d
00263 
00264 /* to reclaim deleted returns at completion */
00265 #define trie_no_cp_fail         0x90
00266 #define trie_trust_fail         0x91
00267 #define trie_try_fail           0x92
00268 #define trie_retry_fail         0x93
00269 
00270 /* to unlock the trie */
00271 #define trie_fail_unlock        0x94
00272 
00273 /*----------------------------------------------------------------------*/
00274 
00275 #define getfloat        0x80
00276 #define putfloat        0x81
00277 #define unifloat        0x82
00278 #define bldfloat        0x83
00279 
00280 /* Non-determinism instructions */
00281 
00282 #define dynfail         0x9e
00283 #define dyntrymeelse    0x9f
00284 #define trymeelse       0xa0
00285 #define retrymeelse     0xa1
00286 #define trustmeelsefail 0xa2
00287 #define try             0xa3
00288 #define retry           0xa4
00289 #define trust           0xa5
00290 #define getpbreg        0xa6
00291 #define gettbreg        0xa7
00292 #define putpbreg        0xa8
00293 #define puttbreg        0xa9
00294 #define jumptbreg       0xaa
00295 
00296 #define getVn           0xab      /* for tabled predicates */
00297 #define test_heap       0xac      /* for heap overflow testing */
00298 
00299 /* Indexing instructions */
00300 
00301 #define switchonterm    0xb0
00302 #define switchonbound   0xb3
00303 #define switchon3bound  0xb4
00304 #define switchonthread  0xb5
00305 
00306 /* Instructions to compile body ors     */
00307 
00308 #define trymeorelse             0xb7
00309 #define retrymeorelse           0xb8
00310 #define trustmeorelsefail       0xb9
00311 
00312 #define dyntrustmeelsefail      0xba    /* Dynamic trust instruction */
00313 #define dynretrymeelse          0xbb    /* Dynamic retry inst (for gc) */
00314 
00315 /* Tabling instructions --- they should really be changed to be as shown */
00316 
00317 #define tabletrysingle          0xc0
00318 #define tabletry                0xc1
00319 #define tableretry              0xc2
00320 #define tabletrust              0xc3
00321 #define check_complete          0xc4
00322 #define answer_return           0xc5
00323 #define resume_compl_suspension 0xc6
00324 
00325 #define check_interrupt         0xce
00326 #define new_answer_dealloc      0xcf
00327 
00328 /* Term comparison inst */
00329 
00330 #define term_comp       0xd0
00331 
00332 /* Numeric instructions */
00333 
00334 #define movreg          0xd1
00335 #define negate          0xd2
00336 #define and             0xd3
00337 #define or              0xd4
00338 #define logshiftl       0xd5
00339 #define logshiftr       0xd6
00340 #define addreg          0xd7
00341 #define subreg          0xd8
00342 #define mulreg          0xd9
00343 #define divreg          0xda
00344 #define idivreg         0xdb
00345 #define int_test_z      0xdc
00346 #define int_test_nz     0xdd
00347 #define fun_test_ne     0xde
00348 
00349 /* Unsafe term instructions */
00350 
00351 #define putdval         0xe0
00352 #define putuval         0xe1
00353 
00354 /* Other Numeric instructions */
00355 #define minreg               0xe2
00356 #define maxreg               0xe3
00357 
00358 #define dynnoop         0xe4
00359 
00360 /* Procedure instructions */
00361 
00362 #define call_forn       0xe5
00363 #define load_pred       0xe6
00364 #define allocate_gc     0xe7
00365 #define call            0xe8
00366 #define allocate        0xe9
00367 #define deallocate      0xea
00368 #define proceed         0xeb
00369 #define xsb_execute         0xec
00370 #define calld           0xef
00371 
00372 /* Branching instructions */
00373 
00374 #define jump            0xf0
00375 #define jumpz           0xf1
00376 #define jumpnz          0xf2
00377 #define jumplt          0xf3
00378 #define jumple          0xf4
00379 #define jumpgt          0xf5
00380 #define jumpge          0xf6
00381 
00382 /* Miscellaneous instructions */
00383 
00384 #define cases           0xf7
00385 #define fail            0xf8
00386 #define noop            0xf9
00387 #define halt            0xfa
00388 #define builtin         0xfb
00389 #define unifunc         0xfc
00390 #define jumpcof         0xfe
00391 #define endfile         0xff
00392    /* virtual instruction, used for disassembler to link different segs */
00393 
00394 #endif

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