[project @ 2000-10-09 11:18:46 by daan]
[ghc-hetmet.git] / ghc / rts / Bytecodes.h
1
2 /* -----------------------------------------------------------------------------
3  * $Id: Bytecodes.h,v 1.17 2000/10/09 11:20:16 daan Exp $
4  *
5  * (c) The GHC Team, 1998-1999
6  *
7  * Bytecode definitions.
8  *
9  * ---------------------------------------------------------------------------*/
10
11 /* --------------------------------------------------------------------------
12  * Instructions
13  *
14  * Notes:
15  * o INTERNAL_ERROR is never generated by the compiler and usually
16  *   indicates an error in the heap.
17  *   PANIC is generated by the compiler whenever it tests an "irrefutable"
18  *   pattern which fails.  If we don't see too many of these, we could
19  *   optimise out the redundant test.
20  *
21  * o If you add any new instructions, you have to check that each enumeration
22  *   has at most 256 entries in it --- some of the lists are very close to
23  *   overflowing.
24  * ------------------------------------------------------------------------*/
25
26 #define INSTRLIST             \
27     Ins(i_INTERNAL_ERROR),    \
28     Ins(i_PANIC),             \
29     Ins(i_STK_CHECK),         \
30     Ins(i_STK_CHECK_big),     \
31     Ins(i_ARG_CHECK),         \
32     Ins(i_ALLOC_AP),          \
33     Ins(i_ALLOC_PAP),         \
34     Ins(i_ALLOC_CONSTR),      \
35     Ins(i_ALLOC_CONSTR_big),  \
36     Ins(i_MKAP),              \
37     Ins(i_MKAP_big),          \
38     Ins(i_MKPAP),             \
39     Ins(i_PACK),              \
40     Ins(i_PACK_big),          \
41     Ins(i_SLIDE),             \
42     Ins(i_SLIDE_big),         \
43     Ins(i_TEST),              \
44     Ins(i_UNPACK),            \
45     Ins(i_VAR),               \
46     Ins(i_VAR_big),           \
47     Ins(i_CONST),             \
48     Ins(i_CONST_big),         \
49     Ins(i_ENTER),             \
50     Ins(i_RETADDR),           \
51     Ins(i_RETADDR_big),       \
52     Ins(i_VOID),              \
53                               \
54     Ins(i_ALLOC_ROW),         \
55     Ins(i_ALLOC_ROW_big),     \
56     Ins(i_PACK_ROW),          \
57     Ins(i_PACK_ROW_big),      \
58     Ins(i_UNPACK_ROW),        \
59     Ins(i_CONST_ROW_TRIV),    \
60                               \
61     Ins(i_PACK_INJ),          \
62     Ins(i_PACK_INJ_VAR),      \
63     Ins(i_PACK_INJ_VAR_big),  \
64     Ins(i_PACK_INJ_CONST_8),  \
65     Ins(i_PACK_INJ_REL_8),    \
66     Ins(i_TEST_INJ),          \
67     Ins(i_TEST_INJ_VAR),      \
68     Ins(i_TEST_INJ_VAR_big),  \
69     Ins(i_TEST_INJ_CONST_8),  \
70     Ins(i_TEST_INJ_REL_8),    \
71     Ins(i_UNPACK_INJ),        \
72     Ins(i_CONST_WORD_8),      \
73     Ins(i_ADD_WORD_VAR),      \
74     Ins(i_ADD_WORD_VAR_big),  \
75     Ins(i_ADD_WORD_VAR_8),    \
76                               \
77     Ins(i_VAR_INT),           \
78     Ins(i_VAR_INT_big),       \
79     Ins(i_CONST_INT),         \
80     Ins(i_CONST_INT_big),     \
81     Ins(i_PACK_INT),          \
82     Ins(i_UNPACK_INT),        \
83     Ins(i_TEST_INT),          \
84     Ins(i_CONST_INTEGER),     \
85     Ins(i_CONST_INTEGER_big), \
86     Ins(i_VAR_WORD),          \
87     Ins(i_VAR_WORD_big),      \
88     Ins(i_CONST_WORD),        \
89     Ins(i_CONST_WORD_big),    \
90     Ins(i_PACK_WORD),         \
91     Ins(i_UNPACK_WORD),       \
92     Ins(i_VAR_ADDR),          \
93     Ins(i_VAR_ADDR_big),      \
94     Ins(i_CONST_ADDR),        \
95     Ins(i_CONST_ADDR_big),    \
96     Ins(i_PACK_ADDR),         \
97     Ins(i_UNPACK_ADDR),       \
98     Ins(i_VAR_CHAR),          \
99     Ins(i_VAR_CHAR_big),      \
100     Ins(i_CONST_CHAR),        \
101     Ins(i_CONST_CHAR_big),    \
102     Ins(i_PACK_CHAR),         \
103     Ins(i_UNPACK_CHAR),       \
104     Ins(i_VAR_FLOAT),         \
105     Ins(i_VAR_FLOAT_big),     \
106     Ins(i_CONST_FLOAT),       \
107     Ins(i_CONST_FLOAT_big),   \
108     Ins(i_PACK_FLOAT),        \
109     Ins(i_UNPACK_FLOAT),      \
110     Ins(i_VAR_DOUBLE),        \
111     Ins(i_VAR_DOUBLE_big),    \
112     Ins(i_CONST_DOUBLE),      \
113     Ins(i_CONST_DOUBLE_big),  \
114     Ins(i_PACK_DOUBLE),       \
115     Ins(i_UNPACK_DOUBLE),     \
116     Ins(i_VAR_STABLE),        \
117     Ins(i_VAR_STABLE_big),    \
118     Ins(i_PACK_STABLE),       \
119     Ins(i_UNPACK_STABLE),     \
120     Ins(i_PRIMOP1),           \
121     Ins(i_PRIMOP2),           \
122     Ins(i_RV),                \
123     Ins(i_RVE),               \
124     Ins(i_SE),                \
125     Ins(i_VV)
126
127 #define BIGGEST_OPCODE ((int)(i_VV))
128
129 #define Ins(x) x
130 typedef enum { INSTRLIST } Instr;
131 #undef Ins
132
133
134
135 typedef enum
136     { i_INTERNAL_ERROR1  /* Instruction 0 raises an internal error */
137
138     , i_pushseqframe
139     , i_pushcatchframe
140
141     /* Char# operations */
142     , i_gtChar
143     , i_geChar
144     , i_eqChar
145     , i_neChar
146     , i_ltChar
147     , i_leChar
148     , i_charToInt
149     , i_intToChar
150
151     /* Int# operations */
152     , i_gtInt
153     , i_geInt
154     , i_eqInt
155     , i_neInt
156     , i_ltInt
157     , i_leInt
158     , i_minInt
159     , i_maxInt
160     , i_plusInt
161     , i_minusInt
162     , i_timesInt
163     , i_quotInt
164     , i_remInt
165     , i_quotRemInt
166     , i_negateInt
167     , i_andInt
168     , i_orInt
169     , i_xorInt
170     , i_notInt
171     , i_shiftLInt
172     , i_shiftRAInt
173     , i_shiftRLInt
174
175     /* Word# operations */
176     , i_gtWord
177     , i_geWord
178     , i_eqWord
179     , i_neWord
180     , i_ltWord
181     , i_leWord
182     , i_minWord
183     , i_maxWord
184     , i_plusWord
185     , i_minusWord
186     , i_timesWord
187     , i_quotWord
188     , i_remWord
189     , i_quotRemWord
190     , i_negateWord
191     , i_andWord
192     , i_orWord
193     , i_xorWord
194     , i_notWord
195     , i_shiftLWord
196     , i_shiftRAWord
197     , i_shiftRLWord
198     , i_intToWord
199     , i_wordToInt
200
201     /* Addr# operations */
202     , i_gtAddr
203     , i_geAddr
204     , i_eqAddr
205     , i_neAddr
206     , i_ltAddr
207     , i_leAddr
208     , i_intToAddr
209     , i_addrToInt
210
211     /* Stable# operations */
212     , i_intToStable
213     , i_stableToInt
214
215     /* Stateless Addr operations */
216     , i_indexCharOffAddr
217     , i_indexIntOffAddr
218     , i_indexWordOffAddr
219     , i_indexAddrOffAddr
220     , i_indexFloatOffAddr
221     , i_indexDoubleOffAddr
222     , i_indexStableOffAddr
223
224     , i_readCharOffAddr
225     , i_readIntOffAddr
226     , i_readWordOffAddr
227     , i_readAddrOffAddr
228     , i_readFloatOffAddr
229     , i_readDoubleOffAddr
230     , i_readStableOffAddr
231
232     , i_writeCharOffAddr
233     , i_writeIntOffAddr
234     , i_writeWordOffAddr
235     , i_writeAddrOffAddr
236     , i_writeFloatOffAddr
237     , i_writeDoubleOffAddr
238     , i_writeStableOffAddr
239
240     /* Integer operations */
241     , i_compareInteger
242     , i_negateInteger
243     , i_plusInteger
244     , i_minusInteger
245     , i_timesInteger
246     , i_quotRemInteger
247     , i_divModInteger
248     , i_integerToInt
249     , i_intToInteger
250     , i_integerToWord
251     , i_wordToInteger
252     , i_integerToFloat
253     , i_floatToInteger
254     , i_integerToDouble
255     , i_doubleToInteger
256
257     /* Float# operations */
258     , i_gtFloat
259     , i_geFloat
260     , i_eqFloat
261     , i_neFloat
262     , i_ltFloat
263     , i_leFloat
264     , i_minFloat
265     , i_maxFloat
266     , i_radixFloat
267     , i_digitsFloat
268     , i_minExpFloat
269     , i_maxExpFloat
270     , i_plusFloat
271     , i_minusFloat
272     , i_timesFloat
273     , i_divideFloat
274     , i_negateFloat
275     , i_floatToInt
276     , i_intToFloat
277     , i_expFloat
278     , i_logFloat
279     , i_sqrtFloat
280     , i_sinFloat
281     , i_cosFloat
282     , i_tanFloat
283     , i_asinFloat
284     , i_acosFloat
285     , i_atanFloat
286     , i_sinhFloat
287     , i_coshFloat
288     , i_tanhFloat
289     , i_powerFloat
290     , i_decodeFloatZ
291     , i_encodeFloatZ
292     , i_isNaNFloat
293     , i_isInfiniteFloat
294     , i_isDenormalizedFloat
295     , i_isNegativeZeroFloat
296     , i_isIEEEFloat
297
298     /* Double# operations */
299     , i_gtDouble
300     , i_geDouble
301     , i_eqDouble
302     , i_neDouble
303     , i_ltDouble
304     , i_leDouble
305     , i_minDouble
306     , i_maxDouble
307     , i_radixDouble
308     , i_digitsDouble
309     , i_minExpDouble
310     , i_maxExpDouble
311     , i_plusDouble
312     , i_minusDouble
313     , i_timesDouble
314     , i_divideDouble
315     , i_negateDouble
316     , i_doubleToInt
317     , i_intToDouble
318     , i_doubleToFloat
319     , i_floatToDouble
320     , i_expDouble
321     , i_logDouble
322     , i_sqrtDouble
323     , i_sinDouble
324     , i_cosDouble
325     , i_tanDouble
326     , i_asinDouble
327     , i_acosDouble
328     , i_atanDouble
329     , i_sinhDouble
330     , i_coshDouble
331     , i_tanhDouble
332     , i_powerDouble
333     , i_decodeDoubleZ
334     , i_encodeDoubleZ
335     , i_isNaNDouble
336     , i_isInfiniteDouble
337     , i_isDenormalizedDouble
338     , i_isNegativeZeroDouble
339     , i_isIEEEDouble
340
341     /* If you add a new primop to this table, check you don't
342      * overflow the 256 limit.  That is MAX_Primop1 <= 255.
343      * Current value (30/10/98) = 0xc8
344      */
345     , MAX_Primop1 = i_isIEEEDouble
346 } Primop1;
347
348
349 typedef enum
350     { i_INTERNAL_ERROR2  /* Instruction 0 raises an internal error */
351
352     , i_raise       
353
354 #ifdef XMLAMBDA
355     /* row primitives. */
356     , i_rowInsertAt
357     , i_rowChainInsert
358     , i_rowChainBuild
359     , i_rowRemoveAt
360     , i_rowChainRemove
361     , i_rowChainSelect
362 #endif
363
364     /* Ref operations */
365     , i_newRef
366     , i_writeRef
367     , i_readRef
368     , i_sameRef
369
370     /* Prim[Mutable]Array operations */
371     , i_sameMutableArray
372     , i_unsafeFreezeArray
373
374     , i_newArray
375     , i_writeArray
376     , i_readArray
377     , i_indexArray
378     , i_sizeArray
379     , i_sizeMutableArray
380
381     /* Prim[Mutable]ByteArray operations */
382     , i_sameMutableByteArray
383     , i_unsafeFreezeByteArray
384     , i_newByteArray
385
386     , i_writeCharArray
387     , i_readCharArray
388     , i_indexCharArray
389
390     , i_writeIntArray
391     , i_readIntArray
392     , i_indexIntArray
393
394     /* {write,read,index}IntegerArray not provided */
395
396     , i_writeWordArray
397     , i_readWordArray
398     , i_indexWordArray
399     , i_writeAddrArray
400     , i_readAddrArray
401     , i_indexAddrArray
402     , i_writeFloatArray
403     , i_readFloatArray
404     , i_indexFloatArray
405     , i_writeDoubleArray
406     , i_readDoubleArray
407     , i_indexDoubleArray
408
409 #if 0
410 #ifdef PROVIDE_STABLE
411     , i_writeStableArray
412     , i_readStableArray
413     , i_indexStableArray
414 #endif
415 #endif
416
417     /* {write,read,index}ForeignObjArray not provided */
418
419 #ifdef PROVIDE_PTREQUALITY
420     , i_reallyUnsafePtrEquality
421 #endif
422 #ifdef PROVIDE_COERCE
423     , i_unsafeCoerce
424 #endif
425
426 #ifdef PROVIDE_FOREIGN
427     /* ForeignObj# operations */
428     , i_mkForeignObj
429
430     , indexCharOffForeignObj
431     , indexIntOffForeignObj
432     , indexInt64OffForeignObj
433     , indexWordOffForeignObj
434     , indexAddrOffForeignObj
435     , indexFloatOffForeignObj
436     , indexDoubleOffForeignObj
437     , indexStablePtrOffForeignObj
438 #endif
439 #ifdef PROVIDE_WEAK
440     /* Weak# operations */
441     , i_makeWeak
442     , i_deRefWeak
443 #endif 
444     /* StablePtr# operations */
445     , i_makeStablePtr
446     , i_deRefStablePtr
447     , i_freeStablePtr
448
449     /* foreign export dynamic support */
450     , i_createAdjThunkARCH
451
452     /* misc handy hacks */
453     , i_getArgc
454     , i_getArgv
455
456 #ifdef PROVIDE_CONCURRENT
457     /* Concurrency operations */
458     , i_forkIO
459     , i_killThread
460     , i_raiseInThread
461     , i_delay
462     , i_waitRead
463     , i_waitWrite
464     , i_yield
465     , i_getThreadId
466     , i_cmpThreadIds
467 #endif
468     , i_sameMVar
469     , i_newMVar
470     , i_takeMVar
471     , i_putMVar
472
473
474     /* CCall! */
475 #ifdef XMLAMBDA
476     , i_ccall
477 #endif
478     , i_ccall_ccall_Id
479     , i_ccall_ccall_IO
480     , i_ccall_stdcall_Id
481     , i_ccall_stdcall_IO
482
483     /* If you add a new primop to this table, check you don't
484      * overflow the 256 limit.  That is MAX_Primop2 <= 255.
485      * Current value (1 oct 2000) = 0x48
486      */
487     , MAX_Primop2 = i_ccall_stdcall_IO
488 } Primop2;
489
490 typedef unsigned int InstrPtr; /* offset of instruction within BCO */
491
492 /*-------------------------------------------------------------------------*/