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