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