[project @ 1999-03-09 14:51:03 by sewardj]
[ghc-hetmet.git] / ghc / rts / Bytecodes.h
1
2 /* -----------------------------------------------------------------------------
3  * $Id: Bytecodes.h,v 1.5 1999/03/09 14:51:24 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 typedef enum
27     { i_INTERNAL_ERROR  /* Instruction 0 raises an internal error */
28
29     , i_PANIC           /* irrefutable pattern match failed! */
30
31     , i_STK_CHECK
32
33     , i_ARG_CHECK
34
35     , i_ALLOC_AP
36     , i_ALLOC_PAP
37     , i_ALLOC_CONSTR
38     , i_MKAP
39     , i_MKAP_big
40     , i_MKPAP
41     , i_PACK
42
43     , i_SLIDE
44     , i_SLIDE_big
45
46     , i_TEST
47     , i_UNPACK
48
49     , i_VAR
50     , i_VAR_big
51     , i_CONST
52     , i_CONST_big
53     , i_ENTER
54
55     , i_RETADDR
56     , i_RETADDR_big
57
58     , i_VOID
59     , i_RETURN_GENERIC
60
61     , i_VAR_INT
62     , i_VAR_INT_big
63     , i_CONST_INT
64     , i_CONST_INT_big
65     , i_RETURN_INT
66     , i_PACK_INT
67     , i_UNPACK_INT
68     , i_TEST_INT
69
70 #ifdef PROVIDE_INT64
71     , i_VAR_INT64
72     , i_CONST_INT64
73     , i_RETURN_INT64
74     , i_PACK_INT64
75     , i_UNPACK_INT64
76 #endif
77 #ifdef PROVIDE_INTEGER
78     , i_CONST_INTEGER
79     , i_CONST_INTEGER_big
80 #endif
81 #ifdef PROVIDE_WORD
82     , i_VAR_WORD
83     , i_CONST_WORD
84     , i_RETURN_WORD
85     , i_PACK_WORD
86     , i_UNPACK_WORD
87 #endif
88 #ifdef PROVIDE_ADDR
89     , i_VAR_ADDR
90     , i_VAR_ADDR_big
91     , i_CONST_ADDR
92     , i_CONST_ADDR_big
93     , i_RETURN_ADDR
94     , i_PACK_ADDR
95     , i_UNPACK_ADDR
96 #endif
97     , i_VAR_CHAR
98     , i_VAR_CHAR_big
99     , i_CONST_CHAR
100     , i_CONST_CHAR_big
101     , i_RETURN_CHAR
102     , i_PACK_CHAR
103     , i_UNPACK_CHAR
104
105     , i_VAR_FLOAT
106     , i_VAR_FLOAT_big
107     , i_CONST_FLOAT
108     , i_CONST_FLOAT_big
109     , i_RETURN_FLOAT
110     , i_PACK_FLOAT
111     , i_UNPACK_FLOAT
112
113     , i_VAR_DOUBLE
114     , i_VAR_DOUBLE_big
115     , i_CONST_DOUBLE
116     , i_CONST_DOUBLE_big
117     , i_RETURN_DOUBLE
118     , i_PACK_DOUBLE
119     , i_UNPACK_DOUBLE
120
121 #ifdef PROVIDE_STABLE
122     , i_VAR_STABLE
123     , i_RETURN_STABLE
124     , i_PACK_STABLE
125     , i_UNPACK_STABLE
126 #endif
127
128     , i_PRIMOP1         /* Primop: next byte is an Primop1 */
129     , i_PRIMOP2         /* Primop: next byte is an Primop2 */
130
131     , MAX_Instr = i_PRIMOP2
132 } Instr;
133
134 typedef enum
135     { i_INTERNAL_ERROR1  /* Instruction 0 raises an internal error */
136
137     , i_pushseqframe
138     , i_pushcatchframe
139
140     /* Char# operations */
141     , i_gtChar
142     , i_geChar
143     , i_eqChar
144     , i_neChar
145     , i_ltChar
146     , i_leChar
147     , i_charToInt
148     , i_intToChar
149
150     /* Int# operations */
151     , i_gtInt
152     , i_geInt
153     , i_eqInt
154     , i_neInt
155     , i_ltInt
156     , i_leInt
157     , i_minInt
158     , i_maxInt
159     , i_plusInt
160     , i_minusInt
161     , i_timesInt
162     , i_quotInt
163     , i_remInt
164     , i_quotRemInt
165     , i_negateInt
166     , i_andInt
167     , i_orInt
168     , i_xorInt
169     , i_notInt
170     , i_shiftLInt
171     , i_shiftRAInt
172     , i_shiftRLInt
173
174 #ifdef PROVIDE_INT64
175     /* Int64# operations */
176     , i_gtInt64
177     , i_geInt64
178     , i_eqInt64
179     , i_neInt64
180     , i_ltInt64
181     , i_leInt64
182     , i_minInt64
183     , i_maxInt64
184     , i_plusInt64
185     , i_minusInt64
186     , i_timesInt64
187     , i_quotInt64
188     , i_remInt64
189     , i_quotRemInt64
190     , i_negateInt64
191     , i_andInt64
192     , i_orInt64
193     , i_xorInt64
194     , i_notInt64
195     , i_shiftLInt64
196     , i_shiftRAInt64
197     , i_shiftRLInt64
198     , i_int64ToInt 
199     , i_intToInt64 
200 #ifdef PROVIDE_WORD
201     , i_int64ToWord 
202     , i_wordToInt64 
203 #endif
204     , i_int64ToFloat 
205     , i_floatToInt64 
206     , i_int64ToDouble 
207     , i_doubleToInt64 
208 #endif
209 #ifdef PROVIDE_WORD
210     /* Word# operations */
211     , i_gtWord
212     , i_geWord
213     , i_eqWord
214     , i_neWord
215     , i_ltWord
216     , i_leWord
217     , i_minWord
218     , i_maxWord
219     , i_plusWord
220     , i_minusWord
221     , i_timesWord
222     , i_quotWord
223     , i_remWord
224     , i_quotRemWord
225     , i_negateWord
226     , i_andWord
227     , i_orWord
228     , i_xorWord
229     , i_notWord
230     , i_shiftLWord
231     , i_shiftRAWord
232     , i_shiftRLWord
233     , i_intToWord
234     , i_wordToInt
235 #endif
236 #ifdef PROVIDE_ADDR
237     /* Addr# operations */
238     , i_gtAddr
239     , i_geAddr
240     , i_eqAddr
241     , i_neAddr
242     , i_ltAddr
243     , i_leAddr
244     , i_intToAddr
245     , i_addrToInt
246
247     /* Stateless Addr operations */
248     , i_indexCharOffAddr
249     , i_indexIntOffAddr
250 #ifdef PROVIDE_INT64
251     , i_indexInt64OffAddr
252 #endif
253 #ifdef PROVIDE_WORD
254     , i_indexWordOffAddr
255 #endif
256 #ifdef PROVIDE_ADDR
257     , i_indexAddrOffAddr
258 #endif
259     , i_indexFloatOffAddr
260     , i_indexDoubleOffAddr
261 #ifdef PROVIDE_STABLE
262     , i_indexStableOffAddr
263 #endif
264
265     , i_readCharOffAddr
266     , i_readIntOffAddr
267 #ifdef PROVIDE_INT64
268     , i_readInt64OffAddr
269 #endif
270 #ifdef PROVIDE_WORD
271     , i_readWordOffAddr
272 #endif
273 #ifdef PROVIDE_ADDR
274     , i_readAddrOffAddr
275 #endif
276     , i_readFloatOffAddr
277     , i_readDoubleOffAddr
278 #ifdef PROVIDE_STABLE
279     , i_readStableOffAddr
280 #endif
281
282     , i_writeCharOffAddr
283     , i_writeIntOffAddr
284 #ifdef PROVIDE_INT64
285     , i_writeInt64OffAddr
286 #endif
287 #ifdef PROVIDE_WORD
288     , i_writeWordOffAddr
289 #endif
290 #ifdef PROVIDE_ADDR
291     , i_writeAddrOffAddr
292 #endif
293     , i_writeFloatOffAddr
294     , i_writeDoubleOffAddr
295 #ifdef PROVIDE_STABLE
296     , i_writeStableOffAddr
297 #endif
298
299 #endif /* PROVIDE_ADDR */
300
301 #ifdef PROVIDE_INTEGER
302     /* Integer operations */
303     , i_compareInteger
304     , i_negateInteger
305     , i_plusInteger
306     , i_minusInteger
307     , i_timesInteger
308     , i_quotRemInteger
309     , i_divModInteger
310     , i_integerToInt
311     , i_intToInteger
312 #ifdef PROVIDE_INT64
313     , i_integerToInt64
314     , i_int64ToInteger
315 #endif
316 #ifdef PROVIDE_WORD
317     , i_integerToWord
318     , i_wordToInteger
319 #endif
320     , i_integerToFloat
321     , i_floatToInteger
322     , i_integerToDouble
323     , i_doubleToInteger
324 #endif
325
326     /* Float# operations */
327     , i_gtFloat
328     , i_geFloat
329     , i_eqFloat
330     , i_neFloat
331     , i_ltFloat
332     , i_leFloat
333     , i_minFloat
334     , i_maxFloat
335     , i_radixFloat
336     , i_digitsFloat
337     , i_minExpFloat
338     , i_maxExpFloat
339     , i_plusFloat
340     , i_minusFloat
341     , i_timesFloat
342     , i_divideFloat
343     , i_negateFloat
344     , i_floatToInt
345     , i_intToFloat
346     , i_expFloat
347     , i_logFloat
348     , i_sqrtFloat
349     , i_sinFloat
350     , i_cosFloat
351     , i_tanFloat
352     , i_asinFloat
353     , i_acosFloat
354     , i_atanFloat
355     , i_sinhFloat
356     , i_coshFloat
357     , i_tanhFloat
358     , i_powerFloat
359 #ifdef PROVIDE_INT64
360     , i_decodeFloatz
361     , i_encodeFloatz
362 #endif
363 #ifdef PROVIDE_INTEGER
364     , i_decodeFloatZ
365     , i_encodeFloatZ
366 #endif
367     , i_isNaNFloat
368     , i_isInfiniteFloat
369     , i_isDenormalizedFloat
370     , i_isNegativeZeroFloat
371     , i_isIEEEFloat
372
373     /* Double# operations */
374     , i_gtDouble
375     , i_geDouble
376     , i_eqDouble
377     , i_neDouble
378     , i_ltDouble
379     , i_leDouble
380     , i_minDouble
381     , i_maxDouble
382     , i_radixDouble
383     , i_digitsDouble
384     , i_minExpDouble
385     , i_maxExpDouble
386     , i_plusDouble
387     , i_minusDouble
388     , i_timesDouble
389     , i_divideDouble
390     , i_negateDouble
391     , i_doubleToInt
392     , i_intToDouble
393     , i_doubleToFloat
394     , i_floatToDouble
395     , i_expDouble
396     , i_logDouble
397     , i_sqrtDouble
398     , i_sinDouble
399     , i_cosDouble
400     , i_tanDouble
401     , i_asinDouble
402     , i_acosDouble
403     , i_atanDouble
404     , i_sinhDouble
405     , i_coshDouble
406     , i_tanhDouble
407     , i_powerDouble
408 #ifdef PROVIDE_INT64
409     , i_decodeDoublez
410     , i_encodeDoublez
411 #endif
412 #ifdef PROVIDE_INTEGER
413     , i_decodeDoubleZ
414     , i_encodeDoubleZ
415 #endif
416     , i_isNaNDouble
417     , i_isInfiniteDouble
418     , i_isDenormalizedDouble
419     , i_isNegativeZeroDouble
420     , i_isIEEEDouble
421
422     /* If you add a new primop to this table, check you don't
423      * overflow the 256 limit.  That is MAX_Primop1 <= 255.
424      * Current value (30/10/98) = 0xc8
425      */
426     , MAX_Primop1 = i_isIEEEDouble
427 } Primop1;
428
429
430 typedef enum
431     { i_INTERNAL_ERROR2  /* Instruction 0 raises an internal error */
432
433     , i_raise       
434
435 #ifdef PROVIDE_ARRAY
436     /* Ref operations */
437     , i_newRef
438     , i_writeRef
439     , i_readRef
440     , i_sameRef
441
442     /* Prim[Mutable]Array operations */
443     , i_sameMutableArray
444     , i_unsafeFreezeArray
445
446     , i_newArray
447     , i_writeArray
448     , i_readArray
449     , i_indexArray
450     , i_sizeArray
451     , i_sizeMutableArray
452
453     /* Prim[Mutable]ByteArray operations */
454     , i_sameMutableByteArray
455     , i_unsafeFreezeByteArray
456     , i_newByteArray
457
458     , i_writeCharArray
459     , i_readCharArray
460     , i_indexCharArray
461
462     , i_writeIntArray
463     , i_readIntArray
464     , i_indexIntArray
465
466 #ifdef PROVIDE_INT64
467     , i_writeInt64Array
468     , i_readInt64Array
469     , i_indexInt64Array
470 #endif
471
472     /* {write,read,index}IntegerArray not provided */
473
474 #ifdef PROVIDE_WORD
475     , i_writeWordArray
476     , i_readWordArray
477     , i_indexWordArray
478 #endif
479 #ifdef PROVIDE_ADDR
480     , i_writeAddrArray
481     , i_readAddrArray
482     , i_indexAddrArray
483 #endif
484     , i_writeFloatArray
485     , i_readFloatArray
486     , i_indexFloatArray
487
488     , i_writeDoubleArray
489     , i_readDoubleArray
490     , i_indexDoubleArray
491
492 #ifdef PROVIDE_STABLE
493     , i_writeStableArray
494     , i_readStableArray
495     , i_indexStableArray
496 #endif
497
498     /* {write,read,index}ForeignObjArray not provided */
499
500 #endif /* PROVIDE_ARRAY */
501
502 #ifdef PROVIDE_PTREQUALITY
503     , i_reallyUnsafePtrEquality
504 #endif
505 #ifdef PROVIDE_COERCE
506     , i_unsafeCoerce
507 #endif
508
509 #ifdef PROVIDE_FOREIGN
510     /* ForeignObj# operations */
511     , i_makeForeignObj
512
513     , indexCharOffForeignObj
514     , indexIntOffForeignObj
515     , indexInt64OffForeignObj
516     , indexWordOffForeignObj
517     , indexAddrOffForeignObj
518     , indexFloatOffForeignObj
519     , indexDoubleOffForeignObj
520     , indexStablePtrOffForeignObj
521 #endif
522 #ifdef PROVIDE_WEAK
523     /* Weak# operations */
524     , i_makeWeak
525     , i_deRefWeak
526 #endif 
527 #ifdef PROVIDE_STABLE
528     /* StablePtr# operations */
529     , i_makeStablePtr
530     , i_deRefStablePtr
531     , i_freeStablePtr
532 #endif
533
534 #ifdef PROVIDE_CONCURRENT
535     /* Concurrency operations */
536     , i_fork
537     , i_killThread
538     , i_sameMVar
539     , i_newMVar
540     , i_takeMVar
541     , i_putMVar
542     , i_delay
543     , i_waitRead
544     , i_waitWrite
545 #endif
546
547     /* CCall! */
548     , i_ccall_Id
549     , i_ccall_IO
550
551     /* If you add a new primop to this table, check you don't
552      * overflow the 256 limit.  That is MAX_Primop2 <= 255.
553      * Current value (30/10/98) = 0x42
554      */
555     , MAX_Primop2 = i_ccall_IO
556 } Primop2;
557
558 typedef unsigned int InstrPtr; /* offset of instruction within BCO */
559
560 /*-------------------------------------------------------------------------*/