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