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