[project @ 1999-04-27 10:06:47 by sewardj]
[ghc-hetmet.git] / ghc / rts / Bytecodes.h
1
2 /* -----------------------------------------------------------------------------
3  * $Id: Bytecodes.h,v 1.6 1999/04/27 10:07:20 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_PACK_STABLE),       \
91     Ins(i_UNPACK_STABLE),     \
92     Ins(i_PRIMOP1),           \
93     Ins(i_PRIMOP2),           \
94     Ins(i_RV),                \
95     Ins(i_RVE),               \
96     Ins(i_SE),                \
97     Ins(i_VV)
98
99 #define BIGGEST_OPCODE ((int)(i_VV))
100
101 #define Ins(x) x
102 typedef enum { INSTRLIST } Instr;
103 #undef Ins
104
105
106
107 typedef enum
108     { i_INTERNAL_ERROR1  /* Instruction 0 raises an internal error */
109
110     , i_pushseqframe
111     , i_pushcatchframe
112
113     /* Char# operations */
114     , i_gtChar
115     , i_geChar
116     , i_eqChar
117     , i_neChar
118     , i_ltChar
119     , i_leChar
120     , i_charToInt
121     , i_intToChar
122
123     /* Int# operations */
124     , i_gtInt
125     , i_geInt
126     , i_eqInt
127     , i_neInt
128     , i_ltInt
129     , i_leInt
130     , i_minInt
131     , i_maxInt
132     , i_plusInt
133     , i_minusInt
134     , i_timesInt
135     , i_quotInt
136     , i_remInt
137     , i_quotRemInt
138     , i_negateInt
139     , i_andInt
140     , i_orInt
141     , i_xorInt
142     , i_notInt
143     , i_shiftLInt
144     , i_shiftRAInt
145     , i_shiftRLInt
146
147     /* Word# operations */
148     , i_gtWord
149     , i_geWord
150     , i_eqWord
151     , i_neWord
152     , i_ltWord
153     , i_leWord
154     , i_minWord
155     , i_maxWord
156     , i_plusWord
157     , i_minusWord
158     , i_timesWord
159     , i_quotWord
160     , i_remWord
161     , i_quotRemWord
162     , i_negateWord
163     , i_andWord
164     , i_orWord
165     , i_xorWord
166     , i_notWord
167     , i_shiftLWord
168     , i_shiftRAWord
169     , i_shiftRLWord
170     , i_intToWord
171     , i_wordToInt
172
173     /* Addr# operations */
174     , i_gtAddr
175     , i_geAddr
176     , i_eqAddr
177     , i_neAddr
178     , i_ltAddr
179     , i_leAddr
180     , i_intToAddr
181     , i_addrToInt
182
183     /* Stateless Addr operations */
184     , i_indexCharOffAddr
185     , i_indexIntOffAddr
186     , i_indexWordOffAddr
187     , i_indexAddrOffAddr
188     , i_indexFloatOffAddr
189     , i_indexDoubleOffAddr
190 #ifdef PROVIDE_STABLE
191     , i_indexStableOffAddr
192 #endif
193
194     , i_readCharOffAddr
195     , i_readIntOffAddr
196     , i_readWordOffAddr
197     , i_readAddrOffAddr
198     , i_readFloatOffAddr
199     , i_readDoubleOffAddr
200 #ifdef PROVIDE_STABLE
201     , i_readStableOffAddr
202 #endif
203
204     , i_writeCharOffAddr
205     , i_writeIntOffAddr
206     , i_writeWordOffAddr
207     , i_writeAddrOffAddr
208     , i_writeFloatOffAddr
209     , i_writeDoubleOffAddr
210 #ifdef PROVIDE_STABLE
211     , i_writeStableOffAddr
212 #endif
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 #ifdef PROVIDE_STABLE
374     , i_writeStableArray
375     , i_readStableArray
376     , i_indexStableArray
377 #endif
378
379     /* {write,read,index}ForeignObjArray not provided */
380
381 #ifdef PROVIDE_PTREQUALITY
382     , i_reallyUnsafePtrEquality
383 #endif
384 #ifdef PROVIDE_COERCE
385     , i_unsafeCoerce
386 #endif
387
388 #ifdef PROVIDE_FOREIGN
389     /* ForeignObj# operations */
390     , i_makeForeignObj
391
392     , indexCharOffForeignObj
393     , indexIntOffForeignObj
394     , indexInt64OffForeignObj
395     , indexWordOffForeignObj
396     , indexAddrOffForeignObj
397     , indexFloatOffForeignObj
398     , indexDoubleOffForeignObj
399     , indexStablePtrOffForeignObj
400 #endif
401 #ifdef PROVIDE_WEAK
402     /* Weak# operations */
403     , i_makeWeak
404     , i_deRefWeak
405 #endif 
406 #ifdef PROVIDE_STABLE
407     /* StablePtr# operations */
408     , i_makeStablePtr
409     , i_deRefStablePtr
410     , i_freeStablePtr
411 #endif
412
413 #ifdef PROVIDE_CONCURRENT
414     /* Concurrency operations */
415     , i_fork
416     , i_killThread
417     , i_sameMVar
418     , i_newMVar
419     , i_takeMVar
420     , i_putMVar
421     , i_delay
422     , i_waitRead
423     , i_waitWrite
424 #endif
425
426     /* CCall! */
427     , i_ccall_Id
428     , i_ccall_IO
429
430     /* If you add a new primop to this table, check you don't
431      * overflow the 256 limit.  That is MAX_Primop2 <= 255.
432      * Current value (30/10/98) = 0x42
433      */
434     , MAX_Primop2 = i_ccall_IO
435 } Primop2;
436
437 typedef unsigned int InstrPtr; /* offset of instruction within BCO */
438
439 /*-------------------------------------------------------------------------*/