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