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