[project @ 2005-03-07 15:16:41 by simonmar]
[ghc-hetmet.git] / ghc / compiler / prelude / primops.txt.pp
1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.35 2005/03/07 15:16:41 simonmar Exp $
3 --
4 -- Primitive Operations
5 --
6 -----------------------------------------------------------------------
7
8 -- This file is processed by the utility program genprimopcode to produce
9 -- a number of include files within the compiler and optionally to produce
10 -- human-readable documentation.
11 --
12 -- It should first be preprocessed.
13 --
14 -- To add a new primop, you currently need to update the following files:
15 --
16 --      - this file (ghc/compiler/prelude/primops.txt.pp), which includes
17 --        the type of the primop, and various other properties (its
18 --        strictness attributes, whether it is defined as a macro
19 --        or as out-of-line code, etc.)
20 --
21 --      - if the primop is inline (i.e. a macro), then:
22 --              ghc/compiler/AbsCUtils.lhs (dscCOpStmt)
23 --                defines the translation of the primop into simpler
24 --                abstract C operations.
25 --              
26 --      - or, for an out-of-line primop:
27 --              ghc/includes/PrimOps.h (just add the declaration)
28 --              ghc/rts/PrimOps.hc     (define it here)
29 --              ghc/rts/Linker.c       (declare the symbol for GHCi)
30 --
31 --      - the User's Guide 
32 --
33
34 -- This file is divided into named sections, each containing or more
35 -- primop entries. Section headers have the format:
36 --
37 --      section "section-name" {description}
38 --
39 -- This information is used solely when producing documentation; it is
40 -- otherwise ignored.  The description is optional.
41 --
42 -- The format of each primop entry is as follows:
43 --
44 --      primop internal-name "name-in-program-text" type category {description} attributes
45
46 -- The default attribute values which apply if you don't specify
47 -- other ones.  Attribute values can be True, False, or arbitrary
48 -- text between curly brackets.  This is a kludge to enable 
49 -- processors of this file to easily get hold of simple info
50 -- (eg, out_of_line), whilst avoiding parsing complex expressions
51 -- needed for strictness and usage info.
52
53 defaults
54    has_side_effects = False
55    out_of_line      = False
56    commutable       = False
57    needs_wrapper    = False
58    can_fail         = False
59    strictness       = { \ arity -> mkStrictSig (mkTopDmdType (replicate arity lazyDmd) TopRes) }
60    usage            = { nomangle other }
61
62 -- Currently, documentation is produced using latex, so contents of
63 -- description fields should be legal latex. Descriptions can contain
64 -- matched pairs of embedded curly brackets.
65
66 #include "MachDeps.h"
67
68 -- We need platform defines (tests for mingw32 below).  However, we only
69 -- test the TARGET platform, which doesn't vary between stages, so the
70 -- stage1 platform defines are fine:
71 #include "../stage1/ghc_boot_platform.h"
72
73 section "The word size story."
74         {Haskell98 specifies that signed integers (type {\tt Int})
75          must contain at least 30 bits. GHC always implements {\tt
76          Int} using the primitive type {\tt Int\#}, whose size equals
77          the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
78          This is normally set based on the {\tt config.h} parameter
79          {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
80          bits on 64-bit machines.  However, it can also be explicitly
81          set to a smaller number, e.g., 31 bits, to allow the
82          possibility of using tag bits. Currently GHC itself has only
83          32-bit and 64-bit variants, but 30 or 31-bit code can be
84          exported as an external core file for use in other back ends.
85
86          GHC also implements a primitive unsigned integer type {\tt
87          Word\#} which always has the same number of bits as {\tt
88          Int\#}.
89         
90          In addition, GHC supports families of explicit-sized integers
91          and words at 8, 16, 32, and 64 bits, with the usual
92          arithmetic operations, comparisons, and a range of
93          conversions.  The 8-bit and 16-bit sizes are always
94          represented as {\tt Int\#} and {\tt Word\#}, and the
95          operations implemented in terms of the the primops on these
96          types, with suitable range restrictions on the results (using
97          the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
98          of primops.  The 32-bit sizes are represented using {\tt
99          Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
100          $\geq$ 32; otherwise, these are represented using distinct
101          primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
102          needed) have a complete set of corresponding operations;
103          however, nearly all of these are implemented as external C
104          functions rather than as primops.  Exactly the same story
105          applies to the 64-bit sizes.  All of these details are hidden
106          under the {\tt PrelInt} and {\tt PrelWord} modules, which use
107          {\tt \#if}-defs to invoke the appropriate types and
108          operators.
109
110          Word size also matters for the families of primops for
111          indexing/reading/writing fixed-size quantities at offsets
112          from an array base, address, or foreign pointer.  Here, a
113          slightly different approach is taken.  The names of these
114          primops are fixed, but their {\it types} vary according to
115          the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
116          size is at least 32 bits then an operator like
117          \texttt{indexInt32Array\#} has type {\tt ByteArr\# -> Int\#
118          -> Int\#}; otherwise it has type {\tt ByteArr\# -> Int\# ->
119          Int32\#}.  This approach confines the necessary {\tt
120          \#if}-defs to this file; no conditional compilation is needed
121          in the files that expose these primops, namely
122          \texttt{lib/std/PrelStorable.lhs},
123          \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated
124          fashion) in \texttt{hslibs/lang/ForeignObj.lhs} and
125          \texttt{hslibs/lang/Addr.lhs}.
126
127          Finally, there are strongly deprecated primops for coercing
128          between {\tt Addr\#}, the primitive type of machine
129          addresses, and {\tt Int\#}.  These are pretty bogus anyway,
130          but will work on existing 32-bit and 64-bit GHC targets; they
131          are completely bogus when tag bits are used in {\tt Int\#},
132          so are not available in this case.  }
133         
134 -- Define synonyms for indexing ops. 
135
136 #if WORD_SIZE_IN_BITS < 32 
137 #define INT32 Int32#
138 #define WORD32 Word32#
139 #else
140 #define INT32 Int#
141 #define WORD32 Word#
142 #endif
143
144 #if WORD_SIZE_IN_BITS < 64
145 #define INT64 Int64#
146 #define WORD64 Word64#
147 #else
148 #define INT64 Int#
149 #define WORD64 Word#
150 #endif
151
152 ------------------------------------------------------------------------
153 section "Char#" 
154         {Operations on 31-bit characters.}
155 ------------------------------------------------------------------------
156
157
158 primop   CharGtOp  "gtChar#"   Compare   Char# -> Char# -> Bool
159 primop   CharGeOp  "geChar#"   Compare   Char# -> Char# -> Bool
160
161 primop   CharEqOp  "eqChar#"   Compare
162    Char# -> Char# -> Bool
163    with commutable = True
164
165 primop   CharNeOp  "neChar#"   Compare
166    Char# -> Char# -> Bool
167    with commutable = True
168
169 primop   CharLtOp  "ltChar#"   Compare   Char# -> Char# -> Bool
170 primop   CharLeOp  "leChar#"   Compare   Char# -> Char# -> Bool
171
172 primop   OrdOp   "ord#"  GenPrimOp   Char# -> Int#
173
174 ------------------------------------------------------------------------
175 section "Int#"
176         {Operations on native-size integers (30+ bits).}
177 ------------------------------------------------------------------------
178
179 primop   IntAddOp    "+#"    Dyadic
180    Int# -> Int# -> Int#
181    with commutable = True
182
183 primop   IntSubOp    "-#"    Dyadic   Int# -> Int# -> Int#
184
185 primop   IntMulOp    "*#" 
186    Dyadic   Int# -> Int# -> Int#
187    {Low word of signed integer multiply.}
188    with commutable = True
189
190 primop   IntMulMayOfloOp  "mulIntMayOflo#" 
191    Dyadic   Int# -> Int# -> Int#
192    {Return non-zero if there is any possibility that the upper word of a
193     signed integer multiply might contain useful information.  Return
194     zero only if you are completely sure that no overflow can occur.
195     On a 32-bit platform, the recommmended implementation is to do a 
196     32 x 32 -> 64 signed multiply, and subtract result[63:32] from
197     (result[31] >>signed 31).  If this is zero, meaning that the 
198     upper word is merely a sign extension of the lower one, no
199     overflow can occur.
200
201     On a 64-bit platform it is not always possible to 
202     acquire the top 64 bits of the result.  Therefore, a recommended 
203     implementation is to take the absolute value of both operands, and 
204     return 0 iff bits[63:31] of them are zero, since that means that their 
205     magnitudes fit within 31 bits, so the magnitude of the product must fit 
206     into 62 bits.
207
208     If in doubt, return non-zero, but do make an effort to create the
209     correct answer for small args, since otherwise the performance of
210     (*) :: Integer -> Integer -> Integer will be poor.
211    }
212    with commutable = True
213
214 primop   IntQuotOp    "quotInt#"    Dyadic
215    Int# -> Int# -> Int#
216    {Rounds towards zero.}
217    with can_fail = True
218
219 primop   IntRemOp    "remInt#"    Dyadic
220    Int# -> Int# -> Int#
221    {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
222    with can_fail = True
223
224 primop   IntGcdOp    "gcdInt#"    Dyadic   Int# -> Int# -> Int#
225    with out_of_line = True
226
227 primop   IntNegOp    "negateInt#"    Monadic   Int# -> Int#
228 primop   IntAddCOp   "addIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
229          {Add with carry.  First member of result is (wrapped) sum; 
230           second member is 0 iff no overflow occured.}
231 primop   IntSubCOp   "subIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
232          {Subtract with carry.  First member of result is (wrapped) difference; 
233           second member is 0 iff no overflow occured.}
234
235 primop   IntGtOp  ">#"   Compare   Int# -> Int# -> Bool
236 primop   IntGeOp  ">=#"   Compare   Int# -> Int# -> Bool
237
238 primop   IntEqOp  "==#"   Compare
239    Int# -> Int# -> Bool
240    with commutable = True
241
242 primop   IntNeOp  "/=#"   Compare
243    Int# -> Int# -> Bool
244    with commutable = True
245
246 primop   IntLtOp  "<#"   Compare   Int# -> Int# -> Bool
247 primop   IntLeOp  "<=#"   Compare   Int# -> Int# -> Bool
248
249 primop   ChrOp   "chr#"   GenPrimOp   Int# -> Char#
250
251 primop   Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
252 primop   Int2FloatOp   "int2Float#"      GenPrimOp  Int# -> Float#
253 primop   Int2DoubleOp   "int2Double#"          GenPrimOp  Int# -> Double#
254
255 primop   Int2IntegerOp    "int2Integer#"
256    GenPrimOp Int# -> (# Int#, ByteArr# #)
257    with out_of_line = True
258
259 primop   ISllOp   "uncheckedIShiftL#" GenPrimOp  Int# -> Int# -> Int#
260          {Shift left.  Result undefined if shift amount is not
261           in the range 0 to word size - 1 inclusive.}
262 primop   ISraOp   "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
263          {Shift right arithmetic.  Result undefined if shift amount is not
264           in the range 0 to word size - 1 inclusive.}
265 primop   ISrlOp   "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
266          {Shift right logical.  Result undefined if shift amount is not
267           in the range 0 to word size - 1 inclusive.}
268
269 ------------------------------------------------------------------------
270 section "Word#"
271         {Operations on native-sized unsigned words (30+ bits).}
272 ------------------------------------------------------------------------
273
274 primop   WordAddOp   "plusWord#"   Dyadic   Word# -> Word# -> Word#
275    with commutable = True
276
277 primop   WordSubOp   "minusWord#"   Dyadic   Word# -> Word# -> Word#
278
279 primop   WordMulOp   "timesWord#"   Dyadic   Word# -> Word# -> Word#
280    with commutable = True
281
282 primop   WordQuotOp   "quotWord#"   Dyadic   Word# -> Word# -> Word#
283    with can_fail = True
284
285 primop   WordRemOp   "remWord#"   Dyadic   Word# -> Word# -> Word#
286    with can_fail = True
287
288 primop   AndOp   "and#"   Dyadic   Word# -> Word# -> Word#
289    with commutable = True
290
291 primop   OrOp   "or#"   Dyadic   Word# -> Word# -> Word#
292    with commutable = True
293
294 primop   XorOp   "xor#"   Dyadic   Word# -> Word# -> Word#
295    with commutable = True
296
297 primop   NotOp   "not#"   Monadic   Word# -> Word#
298
299 primop   SllOp   "uncheckedShiftL#"   GenPrimOp   Word# -> Int# -> Word#
300          {Shift left logical.   Result undefined if shift amount is not
301           in the range 0 to word size - 1 inclusive.}
302 primop   SrlOp   "uncheckedShiftRL#"   GenPrimOp   Word# -> Int# -> Word#
303          {Shift right logical.   Result undefined if shift  amount is not
304           in the range 0 to word size - 1 inclusive.}
305
306 primop   Word2IntOp   "word2Int#"   GenPrimOp   Word# -> Int#
307
308 primop   Word2IntegerOp   "word2Integer#"   GenPrimOp 
309    Word# -> (# Int#, ByteArr# #)
310    with out_of_line = True
311
312 primop   WordGtOp   "gtWord#"   Compare   Word# -> Word# -> Bool
313 primop   WordGeOp   "geWord#"   Compare   Word# -> Word# -> Bool
314 primop   WordEqOp   "eqWord#"   Compare   Word# -> Word# -> Bool
315 primop   WordNeOp   "neWord#"   Compare   Word# -> Word# -> Bool
316 primop   WordLtOp   "ltWord#"   Compare   Word# -> Word# -> Bool
317 primop   WordLeOp   "leWord#"   Compare   Word# -> Word# -> Bool
318
319 ------------------------------------------------------------------------
320 section "Narrowings" 
321         {Explicit narrowing of native-sized ints or words.}
322 ------------------------------------------------------------------------
323
324 primop   Narrow8IntOp      "narrow8Int#"      Monadic   Int# -> Int#
325 primop   Narrow16IntOp     "narrow16Int#"     Monadic   Int# -> Int#
326 primop   Narrow32IntOp     "narrow32Int#"     Monadic   Int# -> Int#
327 primop   Narrow8WordOp     "narrow8Word#"     Monadic   Word# -> Word#
328 primop   Narrow16WordOp    "narrow16Word#"    Monadic   Word# -> Word#
329 primop   Narrow32WordOp    "narrow32Word#"    Monadic   Word# -> Word#
330
331
332 #if WORD_SIZE_IN_BITS < 32
333 ------------------------------------------------------------------------
334 section "Int32#"
335         {Operations on 32-bit integers (Int32\#).  This type is only used
336          if plain Int\# has less than 32 bits.  In any case, the operations
337          are not primops; they are implemented (if needed) as ccalls instead.}
338 ------------------------------------------------------------------------
339
340 primop   Int32ToIntegerOp   "int32ToInteger#" GenPrimOp 
341    Int32# -> (# Int#, ByteArr# #)
342    with out_of_line = True
343
344
345 ------------------------------------------------------------------------
346 section "Word32#"
347         {Operations on 32-bit unsigned words. This type is only used 
348          if plain Word\# has less than 32 bits. In any case, the operations
349          are not primops; they are implemented (if needed) as ccalls instead.}
350 ------------------------------------------------------------------------
351
352 primop   Word32ToIntegerOp   "word32ToInteger#" GenPrimOp
353    Word32# -> (# Int#, ByteArr# #)
354    with out_of_line = True
355
356
357 #endif 
358
359
360 #if WORD_SIZE_IN_BITS < 64
361 ------------------------------------------------------------------------
362 section "Int64#"
363         {Operations on 64-bit unsigned words. This type is only used 
364          if plain Int\# has less than 64 bits. In any case, the operations
365          are not primops; they are implemented (if needed) as ccalls instead.}
366 ------------------------------------------------------------------------
367
368 primop   Int64ToIntegerOp   "int64ToInteger#" GenPrimOp 
369    Int64# -> (# Int#, ByteArr# #)
370    with out_of_line = True
371
372 ------------------------------------------------------------------------
373 section "Word64#"
374         {Operations on 64-bit unsigned words. This type is only used 
375          if plain Word\# has less than 64 bits. In any case, the operations
376          are not primops; they are implemented (if needed) as ccalls instead.}
377 ------------------------------------------------------------------------
378
379 primop   Word64ToIntegerOp   "word64ToInteger#" GenPrimOp
380    Word64# -> (# Int#, ByteArr# #)
381    with out_of_line = True
382
383 #endif
384
385 ------------------------------------------------------------------------
386 section "Integer#"
387         {Operations on arbitrary-precision integers. These operations are 
388 implemented via the GMP package. An integer is represented as a pair
389 consisting of an Int\# representing the number of 'limbs' in use and
390 the sign, and a ByteArr\# containing the 'limbs' themselves.  Such pairs
391 are returned as unboxed pairs, but must be passed as separate
392 components.
393
394 For .NET these operations are implemented by foreign imports, so the
395 primops are omitted.}
396 ------------------------------------------------------------------------
397
398 #ifndef ILX
399
400 primop   IntegerAddOp   "plusInteger#" GenPrimOp   
401    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
402    with commutable = True
403         out_of_line = True
404
405 primop   IntegerSubOp   "minusInteger#" GenPrimOp  
406    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
407    with out_of_line = True
408
409 primop   IntegerMulOp   "timesInteger#" GenPrimOp   
410    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
411    with commutable = True
412         out_of_line = True
413
414 primop   IntegerGcdOp   "gcdInteger#" GenPrimOp    
415    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
416    {Greatest common divisor.}
417    with commutable = True
418         out_of_line = True
419
420 primop   IntegerIntGcdOp   "gcdIntegerInt#" GenPrimOp
421    Int# -> ByteArr# -> Int# -> Int#
422    {Greatest common divisor, where second argument is an ordinary Int\#.}
423    with out_of_line = True
424
425 primop   IntegerDivExactOp   "divExactInteger#" GenPrimOp
426    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
427    {Divisor is guaranteed to be a factor of dividend.}
428    with out_of_line = True
429
430 primop   IntegerQuotOp   "quotInteger#" GenPrimOp
431    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
432    {Rounds towards zero.}
433    with out_of_line = True
434
435 primop   IntegerRemOp   "remInteger#" GenPrimOp
436    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
437    {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
438    with out_of_line = True
439
440 primop   IntegerCmpOp   "cmpInteger#"   GenPrimOp  
441    Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
442    {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
443    with needs_wrapper = True
444         out_of_line = True
445
446 primop   IntegerCmpIntOp   "cmpIntegerInt#" GenPrimOp
447    Int# -> ByteArr# -> Int# -> Int#
448    {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
449    is an ordinary Int\#.}
450    with needs_wrapper = True
451         out_of_line = True
452
453 primop   IntegerQuotRemOp   "quotRemInteger#" GenPrimOp
454    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
455    {Compute quot and rem simulaneously.}
456    with can_fail = True
457         out_of_line = True
458
459 primop   IntegerDivModOp    "divModInteger#"  GenPrimOp
460    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
461    {Compute div and mod simultaneously, where div rounds towards negative infinity
462     and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
463    with can_fail = True
464         out_of_line = True
465
466 primop   Integer2IntOp   "integer2Int#"    GenPrimOp
467    Int# -> ByteArr# -> Int#
468    with needs_wrapper = True
469         out_of_line = True
470
471 primop   Integer2WordOp   "integer2Word#"   GenPrimOp
472    Int# -> ByteArr# -> Word#
473    with needs_wrapper = True
474         out_of_line = True
475
476 #if WORD_SIZE_IN_BITS < 32
477 primop   IntegerToInt32Op   "integerToInt32#" GenPrimOp
478    Int# -> ByteArr# -> Int32#
479
480 primop   IntegerToWord32Op   "integerToWord32#" GenPrimOp
481    Int# -> ByteArr# -> Word32#
482 #endif
483
484 primop   IntegerAndOp  "andInteger#" GenPrimOp
485    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
486    with out_of_line = True
487
488 primop   IntegerOrOp  "orInteger#" GenPrimOp
489    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
490    with out_of_line = True
491
492 primop   IntegerXorOp  "xorInteger#" GenPrimOp
493    Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
494    with out_of_line = True
495
496 primop   IntegerComplementOp  "complementInteger#" GenPrimOp
497    Int# -> ByteArr# -> (# Int#, ByteArr# #)
498    with out_of_line = True
499
500 #endif /* ndef ILX */
501
502 ------------------------------------------------------------------------
503 section "Double#"
504         {Operations on double-precision (64 bit) floating-point numbers.}
505 ------------------------------------------------------------------------
506
507 primop   DoubleGtOp ">##"   Compare   Double# -> Double# -> Bool
508 primop   DoubleGeOp ">=##"   Compare   Double# -> Double# -> Bool
509
510 primop DoubleEqOp "==##"   Compare
511    Double# -> Double# -> Bool
512    with commutable = True
513
514 primop DoubleNeOp "/=##"   Compare
515    Double# -> Double# -> Bool
516    with commutable = True
517
518 primop   DoubleLtOp "<##"   Compare   Double# -> Double# -> Bool
519 primop   DoubleLeOp "<=##"   Compare   Double# -> Double# -> Bool
520
521 primop   DoubleAddOp   "+##"   Dyadic
522    Double# -> Double# -> Double#
523    with commutable = True
524
525 primop   DoubleSubOp   "-##"   Dyadic   Double# -> Double# -> Double#
526
527 primop   DoubleMulOp   "*##"   Dyadic
528    Double# -> Double# -> Double#
529    with commutable = True
530
531 primop   DoubleDivOp   "/##"   Dyadic
532    Double# -> Double# -> Double#
533    with can_fail = True
534
535 primop   DoubleNegOp   "negateDouble#"  Monadic   Double# -> Double#
536
537 primop   Double2IntOp   "double2Int#"          GenPrimOp  Double# -> Int#
538 primop   Double2FloatOp   "double2Float#" GenPrimOp Double# -> Float#
539
540 primop   DoubleExpOp   "expDouble#"      Monadic
541    Double# -> Double#
542    with needs_wrapper = True
543
544 primop   DoubleLogOp   "logDouble#"      Monadic         
545    Double# -> Double#
546    with
547    needs_wrapper = True
548    can_fail = True
549
550 primop   DoubleSqrtOp   "sqrtDouble#"      Monadic  
551    Double# -> Double#
552    with needs_wrapper = True
553
554 primop   DoubleSinOp   "sinDouble#"      Monadic          
555    Double# -> Double#
556    with needs_wrapper = True
557
558 primop   DoubleCosOp   "cosDouble#"      Monadic          
559    Double# -> Double#
560    with needs_wrapper = True
561
562 primop   DoubleTanOp   "tanDouble#"      Monadic          
563    Double# -> Double#
564    with needs_wrapper = True
565
566 primop   DoubleAsinOp   "asinDouble#"      Monadic 
567    Double# -> Double#
568    with
569    needs_wrapper = True
570    can_fail = True
571
572 primop   DoubleAcosOp   "acosDouble#"      Monadic  
573    Double# -> Double#
574    with
575    needs_wrapper = True
576    can_fail = True
577
578 primop   DoubleAtanOp   "atanDouble#"      Monadic  
579    Double# -> Double#
580    with
581    needs_wrapper = True
582
583 primop   DoubleSinhOp   "sinhDouble#"      Monadic  
584    Double# -> Double#
585    with needs_wrapper = True
586
587 primop   DoubleCoshOp   "coshDouble#"      Monadic  
588    Double# -> Double#
589    with needs_wrapper = True
590
591 primop   DoubleTanhOp   "tanhDouble#"      Monadic  
592    Double# -> Double#
593    with needs_wrapper = True
594
595 primop   DoublePowerOp   "**##" Dyadic  
596    Double# -> Double# -> Double#
597    {Exponentiation.}
598    with needs_wrapper = True
599
600 primop   DoubleDecodeOp   "decodeDouble#" GenPrimOp    
601    Double# -> (# Int#, Int#, ByteArr# #)
602    {Convert to arbitrary-precision integer.
603     First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\# 
604     holding the mantissa.}
605    with out_of_line = True
606
607 ------------------------------------------------------------------------
608 section "Float#" 
609         {Operations on single-precision (32-bit) floating-point numbers.}
610 ------------------------------------------------------------------------
611
612 primop   FloatGtOp  "gtFloat#"   Compare   Float# -> Float# -> Bool
613 primop   FloatGeOp  "geFloat#"   Compare   Float# -> Float# -> Bool
614
615 primop   FloatEqOp  "eqFloat#"   Compare
616    Float# -> Float# -> Bool
617    with commutable = True
618
619 primop   FloatNeOp  "neFloat#"   Compare
620    Float# -> Float# -> Bool
621    with commutable = True
622
623 primop   FloatLtOp  "ltFloat#"   Compare   Float# -> Float# -> Bool
624 primop   FloatLeOp  "leFloat#"   Compare   Float# -> Float# -> Bool
625
626 primop   FloatAddOp   "plusFloat#"      Dyadic            
627    Float# -> Float# -> Float#
628    with commutable = True
629
630 primop   FloatSubOp   "minusFloat#"      Dyadic      Float# -> Float# -> Float#
631
632 primop   FloatMulOp   "timesFloat#"      Dyadic    
633    Float# -> Float# -> Float#
634    with commutable = True
635
636 primop   FloatDivOp   "divideFloat#"      Dyadic  
637    Float# -> Float# -> Float#
638    with can_fail = True
639
640 primop   FloatNegOp   "negateFloat#"      Monadic    Float# -> Float#
641
642 primop   Float2IntOp   "float2Int#"      GenPrimOp  Float# -> Int#
643
644 primop   FloatExpOp   "expFloat#"      Monadic          
645    Float# -> Float#
646    with needs_wrapper = True
647
648 primop   FloatLogOp   "logFloat#"      Monadic          
649    Float# -> Float#
650    with needs_wrapper = True
651         can_fail = True
652
653 primop   FloatSqrtOp   "sqrtFloat#"      Monadic          
654    Float# -> Float#
655    with needs_wrapper = True
656
657 primop   FloatSinOp   "sinFloat#"      Monadic          
658    Float# -> Float#
659    with needs_wrapper = True
660
661 primop   FloatCosOp   "cosFloat#"      Monadic          
662    Float# -> Float#
663    with needs_wrapper = True
664
665 primop   FloatTanOp   "tanFloat#"      Monadic          
666    Float# -> Float#
667    with needs_wrapper = True
668
669 primop   FloatAsinOp   "asinFloat#"      Monadic          
670    Float# -> Float#
671    with needs_wrapper = True
672         can_fail = True
673
674 primop   FloatAcosOp   "acosFloat#"      Monadic          
675    Float# -> Float#
676    with needs_wrapper = True
677         can_fail = True
678
679 primop   FloatAtanOp   "atanFloat#"      Monadic          
680    Float# -> Float#
681    with needs_wrapper = True
682
683 primop   FloatSinhOp   "sinhFloat#"      Monadic          
684    Float# -> Float#
685    with needs_wrapper = True
686
687 primop   FloatCoshOp   "coshFloat#"      Monadic          
688    Float# -> Float#
689    with needs_wrapper = True
690
691 primop   FloatTanhOp   "tanhFloat#"      Monadic          
692    Float# -> Float#
693    with needs_wrapper = True
694
695 primop   FloatPowerOp   "powerFloat#"      Dyadic   
696    Float# -> Float# -> Float#
697    with needs_wrapper = True
698
699 primop   Float2DoubleOp   "float2Double#" GenPrimOp  Float# -> Double#
700
701 primop   FloatDecodeOp   "decodeFloat#" GenPrimOp
702    Float# -> (# Int#, Int#, ByteArr# #)
703    {Convert to arbitrary-precision integer.
704     First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\# 
705     holding the mantissa.}
706    with out_of_line = True
707
708 ------------------------------------------------------------------------
709 section "Arrays"
710         {Operations on Array\#.}
711 ------------------------------------------------------------------------
712
713 primop  NewArrayOp "newArray#" GenPrimOp
714    Int# -> a -> State# s -> (# State# s, MutArr# s a #)
715    {Create a new mutable array of specified size (in bytes),
716     in the specified state thread,
717     with each element containing the specified initial value.}
718    with
719    usage       = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
720    out_of_line = True
721
722 primop  SameMutableArrayOp "sameMutableArray#" GenPrimOp
723    MutArr# s a -> MutArr# s a -> Bool
724    with
725    usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
726
727 primop  ReadArrayOp "readArray#" GenPrimOp
728    MutArr# s a -> Int# -> State# s -> (# State# s, a #)
729    {Read from specified index of mutable array. Result is not yet evaluated.}
730    with
731    usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
732
733 primop  WriteArrayOp "writeArray#" GenPrimOp
734    MutArr# s a -> Int# -> a -> State# s -> State# s
735    {Write to specified index of mutable array.}
736    with
737    usage            = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
738    has_side_effects = True
739
740 primop  IndexArrayOp "indexArray#" GenPrimOp
741    Array# a -> Int# -> (# a #)
742    {Read from specified index of immutable array. Result is packaged into
743     an unboxed singleton; the result itself is not yet evaluated.}
744    with
745    usage = { mangle  IndexArrayOp [mkM, mkP] mkM }
746
747 primop  UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
748    MutArr# s a -> State# s -> (# State# s, Array# a #)
749    {Make a mutable array immutable, without copying.}
750    with
751    usage            = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
752    has_side_effects = True
753
754 primop  UnsafeThawArrayOp  "unsafeThawArray#" GenPrimOp
755    Array# a -> State# s -> (# State# s, MutArr# s a #)
756    {Make an immutable array mutable, without copying.}
757    with
758    usage       = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
759    out_of_line = True
760
761 ------------------------------------------------------------------------
762 section "Byte Arrays"
763         {Operations on ByteArray\#. A ByteArray\# is a just a region of
764          raw memory in the garbage-collected heap, which is not scanned
765          for pointers. It carries its own size (in bytes). There are
766          three sets of operations for accessing byte array contents:
767          index for reading from immutable byte arrays, and read/write
768          for mutable byte arrays.  Each set contains operations for 
769          a range of useful primitive data types.  Each operation takes  
770          an offset measured in terms of the size fo the primitive type
771          being read or written.}
772
773 ------------------------------------------------------------------------
774
775 primop  NewByteArrayOp_Char "newByteArray#" GenPrimOp
776    Int# -> State# s -> (# State# s, MutByteArr# s #)
777    {Create a new mutable byte array of specified size (in bytes), in
778     the specified state thread.}
779    with out_of_line = True
780
781 primop  NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
782    Int# -> State# s -> (# State# s, MutByteArr# s #)
783    {Create a mutable byte array that the GC guarantees not to move.}
784    with out_of_line = True
785
786 primop  ByteArrayContents_Char "byteArrayContents#" GenPrimOp
787    ByteArr# -> Addr#
788    {Intended for use with pinned arrays; otherwise very unsafe!}
789
790 primop  SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
791    MutByteArr# s -> MutByteArr# s -> Bool
792
793 primop  UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
794    MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
795    {Make a mutable byte array immutable, without copying.}
796    with
797    has_side_effects = True
798
799 primop  SizeofByteArrayOp "sizeofByteArray#" GenPrimOp  
800    ByteArr# -> Int#
801
802 primop  SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
803    MutByteArr# s -> Int#
804
805
806 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
807    ByteArr# -> Int# -> Char#
808    {Read 8-bit character; offset in bytes.}
809
810 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
811    ByteArr# -> Int# -> Char#
812    {Read 31-bit character; offset in 4-byte words.}
813
814 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
815    ByteArr# -> Int# -> Int#
816
817 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
818    ByteArr# -> Int# -> Word#
819
820 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
821    ByteArr# -> Int# -> Addr#
822
823 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
824    ByteArr# -> Int# -> Float#
825
826 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
827    ByteArr# -> Int# -> Double#
828
829 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
830    ByteArr# -> Int# -> StablePtr# a
831
832 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
833    ByteArr# -> Int# -> Int#
834
835 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
836    ByteArr# -> Int# -> Int#
837
838 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
839    ByteArr# -> Int# -> INT32
840
841 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
842    ByteArr# -> Int# -> INT64
843
844 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
845    ByteArr# -> Int# -> Word#
846
847 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
848    ByteArr# -> Int# -> Word#
849
850 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
851    ByteArr# -> Int# -> WORD32
852
853 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
854    ByteArr# -> Int# -> WORD64
855
856 primop  ReadByteArrayOp_Char "readCharArray#" GenPrimOp
857    MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
858    {Read 8-bit character; offset in bytes.}
859
860 primop  ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
861    MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
862    {Read 31-bit character; offset in 4-byte words.}
863
864 primop  ReadByteArrayOp_Int "readIntArray#" GenPrimOp
865    MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
866
867 primop  ReadByteArrayOp_Word "readWordArray#" GenPrimOp
868    MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
869
870 primop  ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
871    MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
872
873 primop  ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
874    MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
875
876 primop  ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
877    MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
878
879 primop  ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
880    MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
881
882 primop  ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
883    MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
884
885 primop  ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
886    MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
887
888 primop  ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
889    MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
890
891 primop  ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
892    MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
893
894 primop  ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
895    MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
896
897 primop  ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
898    MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
899
900 primop  ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
901    MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
902
903 primop  ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
904    MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
905
906 primop  WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
907    MutByteArr# s -> Int# -> Char# -> State# s -> State# s
908    {Write 8-bit character; offset in bytes.}
909    with has_side_effects = True
910
911 primop  WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
912    MutByteArr# s -> Int# -> Char# -> State# s -> State# s
913    {Write 31-bit character; offset in 4-byte words.}
914    with has_side_effects = True
915
916 primop  WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
917    MutByteArr# s -> Int# -> Int# -> State# s -> State# s
918    with has_side_effects = True
919
920 primop  WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
921    MutByteArr# s -> Int# -> Word# -> State# s -> State# s
922    with has_side_effects = True
923
924 primop  WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
925    MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
926    with has_side_effects = True
927
928 primop  WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
929    MutByteArr# s -> Int# -> Float# -> State# s -> State# s
930    with has_side_effects = True
931
932 primop  WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
933    MutByteArr# s -> Int# -> Double# -> State# s -> State# s
934    with has_side_effects = True
935
936 primop  WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
937    MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
938    with has_side_effects = True
939
940 primop  WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
941    MutByteArr# s -> Int# -> Int# -> State# s -> State# s
942    with has_side_effects = True
943
944 primop  WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
945    MutByteArr# s -> Int# -> Int# -> State# s -> State# s
946    with has_side_effects = True
947
948 primop  WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
949    MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
950    with has_side_effects = True
951
952 primop  WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
953    MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
954    with has_side_effects = True
955
956 primop  WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
957    MutByteArr# s -> Int# -> Word# -> State# s -> State# s
958    with has_side_effects = True
959
960 primop  WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
961    MutByteArr# s -> Int# -> Word# -> State# s -> State# s
962    with has_side_effects = True
963
964 primop  WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
965    MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
966    with has_side_effects = True
967
968 primop  WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
969    MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
970    with has_side_effects = True
971
972 ------------------------------------------------------------------------
973 section "Addr#"
974         {Addr\# is an arbitrary machine address assumed to point outside
975          the garbage-collected heap.  
976
977          NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
978          It is the null address.}
979 ------------------------------------------------------------------------
980
981 primop   AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
982 primop   AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
983          {Result is meaningless if two Addr\#s are so far apart that their
984          difference doesn't fit in an Int\#.}
985 primop   AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
986          {Return the remainder when the Addr\# arg, treated like an Int\#,
987           is divided by the Int\# arg.}
988 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
989 primop   Addr2IntOp  "addr2Int#"     GenPrimOp   Addr# -> Int#
990         {Coerce directly from address to int. Strongly deprecated.}
991 primop   Int2AddrOp   "int2Addr#"    GenPrimOp  Int# -> Addr#
992         {Coerce directly from int to address. Strongly deprecated.}
993 #endif
994
995 primop   AddrGtOp  "gtAddr#"   Compare   Addr# -> Addr# -> Bool
996 primop   AddrGeOp  "geAddr#"   Compare   Addr# -> Addr# -> Bool
997 primop   AddrEqOp  "eqAddr#"   Compare   Addr# -> Addr# -> Bool
998 primop   AddrNeOp  "neAddr#"   Compare   Addr# -> Addr# -> Bool
999 primop   AddrLtOp  "ltAddr#"   Compare   Addr# -> Addr# -> Bool
1000 primop   AddrLeOp  "leAddr#"   Compare   Addr# -> Addr# -> Bool
1001
1002 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
1003    Addr# -> Int# -> Char#
1004    {Reads 8-bit character; offset in bytes.}
1005
1006 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
1007    Addr# -> Int# -> Char#
1008    {Reads 31-bit character; offset in 4-byte words.}
1009
1010 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
1011    Addr# -> Int# -> Int#
1012
1013 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
1014    Addr# -> Int# -> Word#
1015
1016 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
1017    Addr# -> Int# -> Addr#
1018
1019 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
1020    Addr# -> Int# -> Float#
1021
1022 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
1023    Addr# -> Int# -> Double#
1024
1025 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
1026    Addr# -> Int# -> StablePtr# a
1027
1028 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
1029    Addr# -> Int# -> Int#
1030
1031 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1032    Addr# -> Int# -> Int#
1033
1034 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1035    Addr# -> Int# -> INT32
1036
1037 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1038    Addr# -> Int# -> INT64
1039
1040 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1041    Addr# -> Int# -> Word#
1042
1043 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1044    Addr# -> Int# -> Word#
1045
1046 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1047    Addr# -> Int# -> WORD32
1048
1049 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1050    Addr# -> Int# -> WORD64
1051
1052 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1053    Addr# -> Int# -> State# s -> (# State# s, Char# #)
1054    {Reads 8-bit character; offset in bytes.}
1055
1056 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1057    Addr# -> Int# -> State# s -> (# State# s, Char# #)
1058    {Reads 31-bit character; offset in 4-byte words.}
1059
1060 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1061    Addr# -> Int# -> State# s -> (# State# s, Int# #)
1062
1063 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1064    Addr# -> Int# -> State# s -> (# State# s, Word# #)
1065
1066 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1067    Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1068
1069 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1070    Addr# -> Int# -> State# s -> (# State# s, Float# #)
1071
1072 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1073    Addr# -> Int# -> State# s -> (# State# s, Double# #)
1074
1075 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1076    Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1077
1078 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1079    Addr# -> Int# -> State# s -> (# State# s, Int# #)
1080
1081 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1082    Addr# -> Int# -> State# s -> (# State# s, Int# #)
1083
1084 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1085    Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1086
1087 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1088    Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1089
1090 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1091    Addr# -> Int# -> State# s -> (# State# s, Word# #)
1092
1093 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1094    Addr# -> Int# -> State# s -> (# State# s, Word# #)
1095
1096 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1097    Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1098
1099 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1100    Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1101
1102
1103 primop  WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1104    Addr# -> Int# -> Char# -> State# s -> State# s
1105    with has_side_effects = True
1106
1107 primop  WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1108    Addr# -> Int# -> Char# -> State# s -> State# s
1109    with has_side_effects = True
1110
1111 primop  WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1112    Addr# -> Int# -> Int# -> State# s -> State# s
1113    with has_side_effects = True
1114
1115 primop  WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1116    Addr# -> Int# -> Word# -> State# s -> State# s
1117    with has_side_effects = True
1118
1119 primop  WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1120    Addr# -> Int# -> Addr# -> State# s -> State# s
1121    with has_side_effects = True
1122
1123 primop  WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1124    Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1125    with has_side_effects = True
1126
1127 primop  WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1128    Addr# -> Int# -> Float# -> State# s -> State# s
1129    with has_side_effects = True
1130
1131 primop  WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1132    Addr# -> Int# -> Double# -> State# s -> State# s
1133    with has_side_effects = True
1134
1135 primop  WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1136    Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1137    with has_side_effects = True
1138
1139 primop  WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1140    Addr# -> Int# -> Int# -> State# s -> State# s
1141    with has_side_effects = True
1142
1143 primop  WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1144    Addr# -> Int# -> Int# -> State# s -> State# s
1145    with has_side_effects = True
1146
1147 primop  WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1148    Addr# -> Int# -> INT32 -> State# s -> State# s
1149    with has_side_effects = True
1150
1151 primop  WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1152    Addr# -> Int# -> INT64 -> State# s -> State# s
1153    with has_side_effects = True
1154
1155 primop  WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1156    Addr# -> Int# -> Word# -> State# s -> State# s
1157    with has_side_effects = True
1158
1159 primop  WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1160    Addr# -> Int# -> Word# -> State# s -> State# s
1161    with has_side_effects = True
1162
1163 primop  WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1164    Addr# -> Int# -> WORD32 -> State# s -> State# s
1165    with has_side_effects = True
1166
1167 primop  WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1168    Addr# -> Int# -> WORD64 -> State# s -> State# s
1169    with has_side_effects = True
1170
1171 ------------------------------------------------------------------------
1172 section "ForeignObj#"
1173         {Operations on ForeignObj\#.  The indexing operations are
1174         all deprecated.}
1175 ------------------------------------------------------------------------
1176
1177 primop  MkForeignObjOp "mkForeignObj#" GenPrimOp
1178    Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1179    with
1180    has_side_effects = True
1181    out_of_line      = True
1182
1183 primop  WriteForeignObjOp "writeForeignObj#" GenPrimOp
1184    ForeignObj# -> Addr# -> State# s -> State# s
1185    with
1186    has_side_effects = True
1187
1188 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1189    ForeignObj# -> Addr#
1190
1191 primop TouchOp "touch#" GenPrimOp
1192    o -> State# RealWorld -> State# RealWorld
1193    with
1194    has_side_effects = True
1195
1196 primop EqForeignObj "eqForeignObj#" GenPrimOp
1197    ForeignObj# -> ForeignObj# -> Bool
1198    with commutable = True
1199
1200 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1201    ForeignObj# -> Int# -> Char#
1202    {Read 8-bit character; offset in bytes.}
1203
1204 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1205    ForeignObj# -> Int# -> Char#
1206    {Read 31-bit character; offset in 4-byte words.}
1207
1208 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1209    ForeignObj# -> Int# -> Int#
1210
1211 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1212    ForeignObj# -> Int# -> Word#
1213
1214 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1215    ForeignObj# -> Int# -> Addr#
1216
1217 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1218    ForeignObj# -> Int# -> Float#
1219
1220 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1221    ForeignObj# -> Int# -> Double#
1222
1223 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1224    ForeignObj# -> Int# -> StablePtr# a
1225
1226 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1227    ForeignObj# -> Int# -> Int#
1228
1229 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1230    ForeignObj# -> Int# -> Int#
1231
1232 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1233    ForeignObj# -> Int# -> INT32
1234
1235 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1236    ForeignObj# -> Int# -> INT64
1237
1238 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1239    ForeignObj# -> Int# -> Word#
1240
1241 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1242    ForeignObj# -> Int# -> Word#
1243
1244 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1245    ForeignObj# -> Int# -> WORD32
1246
1247 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1248    ForeignObj# -> Int# -> WORD64
1249
1250
1251
1252 ------------------------------------------------------------------------
1253 section "Mutable variables"
1254         {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1255 ------------------------------------------------------------------------
1256
1257 primop  NewMutVarOp "newMutVar#" GenPrimOp
1258    a -> State# s -> (# State# s, MutVar# s a #)
1259    {Create MutVar\# with specified initial value in specified state thread.}
1260    with
1261    usage       = { mangle NewMutVarOp [mkM, mkP] mkM }
1262    out_of_line = True
1263
1264 primop  ReadMutVarOp "readMutVar#" GenPrimOp
1265    MutVar# s a -> State# s -> (# State# s, a #)
1266    {Read contents of MutVar\#. Result is not yet evaluated.}
1267    with
1268    usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1269
1270 primop  WriteMutVarOp "writeMutVar#"  GenPrimOp
1271    MutVar# s a -> a -> State# s -> State# s
1272    {Write contents of MutVar\#.}
1273    with
1274    usage            = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1275    has_side_effects = True
1276
1277 primop  SameMutVarOp "sameMutVar#" GenPrimOp
1278    MutVar# s a -> MutVar# s a -> Bool
1279    with
1280    usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1281
1282 -- not really the right type, but we don't know about pairs here.  The
1283 -- correct type is
1284 --
1285 --   MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
1286 --
1287 primop  AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp
1288    MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #)
1289    with
1290    usage = { mangle AtomicModifyMutVarOp [mkP, mkM, mkP] mkM }
1291    has_side_effects = True
1292    out_of_line = True
1293
1294 ------------------------------------------------------------------------
1295 section "Exceptions"
1296 ------------------------------------------------------------------------
1297
1298 primop  CatchOp "catch#" GenPrimOp
1299           (State# RealWorld -> (# State# RealWorld, a #) )
1300        -> (b -> State# RealWorld -> (# State# RealWorld, a #) ) 
1301        -> State# RealWorld
1302        -> (# State# RealWorld, a #)
1303    with
1304         -- Catch is actually strict in its first argument
1305         -- but we don't want to tell the strictness
1306         -- analyser about that!
1307    usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1308         --     [mkO, mkO . (inFun mkM mkO)] mkO
1309         -- might use caught action multiply
1310    out_of_line = True
1311
1312 primop  RaiseOp "raise#" GenPrimOp
1313    a -> b
1314    with
1315    strictness  = { \ arity -> mkStrictSig (mkTopDmdType [lazyDmd] BotRes) }
1316       -- NB: result is bottom
1317    usage       = { mangle RaiseOp [mkM] mkM }
1318    out_of_line = True
1319
1320 -- raiseIO# needs to be a primop, because exceptions in the IO monad
1321 -- must be *precise* - we don't want the strictness analyser turning
1322 -- one kind of bottom into another, as it is allowed to do in pure code.
1323
1324 primop  RaiseIOOp "raiseIO#" GenPrimOp
1325    a -> State# RealWorld -> (# State# RealWorld, b #)
1326    with
1327    out_of_line = True
1328
1329 primop  BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1330         (State# RealWorld -> (# State# RealWorld, a #))
1331      -> (State# RealWorld -> (# State# RealWorld, a #))
1332    with
1333    out_of_line = True
1334
1335 primop  UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1336         (State# RealWorld -> (# State# RealWorld, a #))
1337      -> (State# RealWorld -> (# State# RealWorld, a #))
1338    with
1339    out_of_line = True
1340
1341 ------------------------------------------------------------------------
1342 section "STM-accessible Mutable Variables"
1343 ------------------------------------------------------------------------
1344
1345 primop  AtomicallyOp "atomically#" GenPrimOp
1346       (State# RealWorld -> (# State# RealWorld, a #) )
1347    -> State# RealWorld -> (# State# RealWorld, a #)
1348    with
1349    out_of_line = True
1350    has_side_effects = True
1351
1352 primop  RetryOp "retry#" GenPrimOp
1353    State# RealWorld -> (# State# RealWorld, a #)
1354    with 
1355    out_of_line = True
1356    has_side_effects = True
1357
1358 primop  CatchRetryOp "catchRetry#" GenPrimOp
1359       (State# RealWorld -> (# State# RealWorld, a #) )
1360    -> (State# RealWorld -> (# State# RealWorld, a #) )
1361    -> (State# RealWorld -> (# State# RealWorld, a #) )
1362    with 
1363    out_of_line = True
1364    has_side_effects = True
1365
1366 primop  CatchSTMOp "catchSTM#" GenPrimOp
1367       (State# RealWorld -> (# State# RealWorld, a #) )
1368    -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1369    -> (State# RealWorld -> (# State# RealWorld, a #) )
1370    with 
1371    out_of_line = True
1372    has_side_effects = True
1373
1374 primop  NewTVarOp "newTVar#" GenPrimOp
1375        a
1376     -> State# s -> (# State# s, TVar# s a #)
1377    {Create a new Tar\# holding a specified initial value.}
1378    with
1379    out_of_line  = True
1380
1381 primop  ReadTVarOp "readTVar#" GenPrimOp
1382        TVar# s a
1383     -> State# s -> (# State# s, a #)
1384    {Read contents of TVar\#.  Result is not yet evaluated.}
1385    with
1386    out_of_line  = True
1387
1388 primop  WriteTVarOp "writeTVar#" GenPrimOp
1389        TVar# s a
1390     -> a
1391     -> State# s -> State# s
1392    {Write contents of TVar\#.}
1393    with
1394    out_of_line      = True
1395    has_side_effects = True
1396
1397 primop  SameTVarOp "sameTVar#" GenPrimOp
1398    TVar# s a -> TVar# s a -> Bool
1399
1400
1401 ------------------------------------------------------------------------
1402 section "Synchronized Mutable Variables"
1403         {Operations on MVar\#s, which are shared mutable variables
1404         ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1405         (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1406 ------------------------------------------------------------------------
1407
1408
1409 primop  NewMVarOp "newMVar#"  GenPrimOp
1410    State# s -> (# State# s, MVar# s a #)
1411    {Create new mvar; initially empty.}
1412    with
1413    usage       = { mangle NewMVarOp [mkP] mkR }
1414    out_of_line = True
1415
1416 primop  TakeMVarOp "takeMVar#" GenPrimOp
1417    MVar# s a -> State# s -> (# State# s, a #)
1418    {If mvar is empty, block until it becomes full.
1419    Then remove and return its contents, and set it empty.}
1420    with
1421    usage            = { mangle TakeMVarOp [mkM, mkP] mkM }
1422    has_side_effects = True
1423    out_of_line      = True
1424
1425 primop  TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1426    MVar# s a -> State# s -> (# State# s, Int#, a #)
1427    {If mvar is empty, immediately return with integer 0 and value undefined.
1428    Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1429    with
1430    usage            = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1431    has_side_effects = True
1432    out_of_line      = True
1433
1434 primop  PutMVarOp "putMVar#" GenPrimOp
1435    MVar# s a -> a -> State# s -> State# s
1436    {If mvar is full, block until it becomes empty.
1437    Then store value arg as its new contents.}
1438    with
1439    usage            = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1440    has_side_effects = True
1441    out_of_line      = True
1442
1443 primop  TryPutMVarOp "tryPutMVar#" GenPrimOp
1444    MVar# s a -> a -> State# s -> (# State# s, Int# #)
1445    {If mvar is full, immediately return with integer 0.
1446     Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1447    with
1448    usage            = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1449    has_side_effects = True
1450    out_of_line      = True
1451
1452 primop  SameMVarOp "sameMVar#" GenPrimOp
1453    MVar# s a -> MVar# s a -> Bool
1454    with
1455    usage = { mangle SameMVarOp [mkP, mkP] mkM }
1456
1457 primop  IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1458    MVar# s a -> State# s -> (# State# s, Int# #)
1459    {Return 1 if mvar is empty; 0 otherwise.}
1460    with
1461    usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1462    out_of_line = True
1463
1464 ------------------------------------------------------------------------
1465 section "Delay/wait operations"
1466 ------------------------------------------------------------------------
1467
1468 primop  DelayOp "delay#" GenPrimOp
1469    Int# -> State# s -> State# s
1470    {Sleep specified number of microseconds.}
1471    with
1472    needs_wrapper    = True
1473    has_side_effects = True
1474    out_of_line      = True
1475
1476 primop  WaitReadOp "waitRead#" GenPrimOp
1477    Int# -> State# s -> State# s
1478    {Block until input is available on specified file descriptor.}
1479    with
1480    needs_wrapper    = True
1481    has_side_effects = True
1482    out_of_line      = True
1483
1484 primop  WaitWriteOp "waitWrite#" GenPrimOp
1485    Int# -> State# s -> State# s
1486    {Block until output is possible on specified file descriptor.}
1487    with
1488    needs_wrapper    = True
1489    has_side_effects = True
1490    out_of_line      = True
1491
1492 #ifdef mingw32_TARGET_OS
1493 primop  AsyncReadOp "asyncRead#" GenPrimOp
1494    Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1495    {Asynchronously read bytes from specified file descriptor.}
1496    with
1497    needs_wrapper    = True
1498    has_side_effects = True
1499    out_of_line      = True
1500
1501 primop  AsyncWriteOp "asyncWrite#" GenPrimOp
1502    Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1503    {Asynchronously write bytes from specified file descriptor.}
1504    with
1505    needs_wrapper    = True
1506    has_side_effects = True
1507    out_of_line      = True
1508
1509 primop  AsyncDoProcOp "asyncDoProc#" GenPrimOp
1510    Addr# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1511    {Asynchronously perform procedure (first arg), passing it 2nd arg.}
1512    with
1513    needs_wrapper    = True
1514    has_side_effects = True
1515    out_of_line      = True
1516
1517 #endif
1518
1519 ------------------------------------------------------------------------
1520 section "Concurrency primitives"
1521         {(In a non-concurrent implementation, ThreadId\# can be as singleton
1522         type, whose (unique) value is returned by myThreadId\#.  The 
1523         other operations can be omitted.)}
1524 ------------------------------------------------------------------------
1525
1526 primop  ForkOp "fork#" GenPrimOp
1527    a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1528    with
1529    usage            = { mangle ForkOp [mkO, mkP] mkR }
1530    has_side_effects = True
1531    out_of_line      = True
1532
1533 primop  KillThreadOp "killThread#"  GenPrimOp
1534    ThreadId# -> a -> State# RealWorld -> State# RealWorld
1535    with
1536    usage            = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1537    has_side_effects = True
1538    out_of_line      = True
1539
1540 primop  YieldOp "yield#" GenPrimOp
1541    State# RealWorld -> State# RealWorld
1542    with
1543    has_side_effects = True
1544    out_of_line      = True
1545
1546 primop  MyThreadIdOp "myThreadId#" GenPrimOp
1547    State# RealWorld -> (# State# RealWorld, ThreadId# #)
1548    with
1549    out_of_line = True
1550
1551 primop LabelThreadOp "labelThread#" GenPrimOp
1552    ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
1553    with
1554    has_side_effects = True
1555    out_of_line      = True
1556    
1557 primop  IsCurrentThreadBoundOp "isCurrentThreadBound#" GenPrimOp
1558    State# RealWorld -> (# State# RealWorld, Int# #)
1559    with
1560    out_of_line = True
1561
1562 ------------------------------------------------------------------------
1563 section "Weak pointers"
1564 ------------------------------------------------------------------------
1565
1566 -- note that tyvar "o" denotes openAlphaTyVar
1567
1568 primop  MkWeakOp "mkWeak#" GenPrimOp
1569    o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1570    with
1571    usage            = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1572    has_side_effects = True
1573    out_of_line      = True
1574
1575 primop  DeRefWeakOp "deRefWeak#" GenPrimOp
1576    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1577    with
1578    usage            = { mangle DeRefWeakOp [mkM, mkP] mkM }
1579    has_side_effects = True
1580    out_of_line      = True
1581
1582 primop  FinalizeWeakOp "finalizeWeak#" GenPrimOp
1583    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, 
1584               (State# RealWorld -> (# State# RealWorld, () #)) #)
1585    with
1586    usage            = { mangle FinalizeWeakOp [mkM, mkP] 
1587                                (mkR . (inUB FinalizeWeakOp 
1588                                             [id,id,inFun FinalizeWeakOp mkR mkM])) }
1589    has_side_effects = True
1590    out_of_line      = True
1591
1592 ------------------------------------------------------------------------
1593 section "Stable pointers and names"
1594 ------------------------------------------------------------------------
1595
1596 primop  MakeStablePtrOp "makeStablePtr#" GenPrimOp
1597    a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1598    with
1599    usage            = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1600    has_side_effects = True
1601    out_of_line      = True
1602
1603 primop  DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1604    StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1605    with
1606    usage            = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1607    needs_wrapper    = True
1608    has_side_effects = True
1609    out_of_line      = True
1610
1611 primop  EqStablePtrOp "eqStablePtr#" GenPrimOp
1612    StablePtr# a -> StablePtr# a -> Int#
1613    with
1614    usage            = { mangle EqStablePtrOp [mkP, mkP] mkR }
1615    has_side_effects = True
1616
1617 primop  MakeStableNameOp "makeStableName#" GenPrimOp
1618    a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1619    with
1620    usage            = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1621    needs_wrapper    = True
1622    has_side_effects = True
1623    out_of_line      = True
1624
1625 primop  EqStableNameOp "eqStableName#" GenPrimOp
1626    StableName# a -> StableName# a -> Int#
1627    with
1628    usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1629
1630 primop  StableNameToIntOp "stableNameToInt#" GenPrimOp
1631    StableName# a -> Int#
1632    with
1633    usage = { mangle StableNameToIntOp [mkP] mkR }
1634
1635 ------------------------------------------------------------------------
1636 section "Unsafe pointer equality"
1637 --  (#1 Bad Guy: Alistair Reid :)   
1638 ------------------------------------------------------------------------
1639
1640 primop  ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1641    a -> a -> Int#
1642    with
1643    usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
1644
1645 ------------------------------------------------------------------------
1646 section "Parallelism"
1647 ------------------------------------------------------------------------
1648
1649 primop  ParOp "par#" GenPrimOp
1650    a -> Int#
1651    with
1652    usage            = { mangle ParOp [mkO] mkR }
1653       -- Note that Par is lazy to avoid that the sparked thing
1654       -- gets evaluted strictly, which it should *not* be
1655    has_side_effects = True
1656
1657 -- HWL: The first 4 Int# in all par... annotations denote:
1658 --   name, granularity info, size of result, degree of parallelism
1659 --      Same  structure as _seq_ i.e. returns Int#
1660 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1661 --   `the processor containing the expression v'; it is not evaluated
1662
1663 primop  ParGlobalOp  "parGlobal#"  GenPrimOp
1664    a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1665    with
1666    usage            = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1667    has_side_effects = True
1668
1669 primop  ParLocalOp  "parLocal#"  GenPrimOp
1670    a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1671    with
1672    usage            = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1673    has_side_effects = True
1674
1675 primop  ParAtOp  "parAt#"  GenPrimOp
1676    b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1677    with
1678    usage            = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1679    has_side_effects = True
1680
1681 primop  ParAtAbsOp  "parAtAbs#"  GenPrimOp
1682    a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1683    with
1684    usage            = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1685    has_side_effects = True
1686
1687 primop  ParAtRelOp  "parAtRel#" GenPrimOp
1688    a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1689    with
1690    usage            = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1691    has_side_effects = True
1692
1693 primop  ParAtForNowOp  "parAtForNow#" GenPrimOp
1694    b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1695    with
1696    usage            = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1697    has_side_effects = True
1698
1699 -- copyable# and noFollow# are yet to be implemented (for GpH)
1700 --
1701 --primop  CopyableOp  "copyable#" GenPrimOp
1702 --   a -> Int#
1703 --   with
1704 --   usage            = { mangle CopyableOp [mkZ] mkR }
1705 --   has_side_effects = True
1706 --
1707 --primop  NoFollowOp "noFollow#" GenPrimOp
1708 --   a -> Int#
1709 --   with
1710 --   usage            = { mangle NoFollowOp [mkZ] mkR }
1711 --   has_side_effects = True
1712
1713
1714 ------------------------------------------------------------------------
1715 section "Tag to enum stuff"
1716         {Convert back and forth between values of enumerated types
1717         and small integers.}
1718 ------------------------------------------------------------------------
1719
1720 primop  DataToTagOp "dataToTag#" GenPrimOp
1721    a -> Int#
1722    with
1723    strictness  = { \ arity -> mkStrictSig (mkTopDmdType [seqDmd] TopRes) }
1724         -- dataToTag# must have an evaluated argument
1725
1726 primop  TagToEnumOp "tagToEnum#" GenPrimOp     
1727    Int# -> a
1728
1729 ------------------------------------------------------------------------
1730 section "Bytecode operations" 
1731         {Support for the bytecode interpreter and linker.}
1732 ------------------------------------------------------------------------
1733
1734
1735 primop   AddrToHValueOp "addrToHValue#" GenPrimOp
1736    Addr# -> (# a #)
1737    {Convert an Addr\# to a followable type.}
1738
1739 primop   MkApUpd0_Op "mkApUpd0#" GenPrimOp
1740    BCO# -> (# a #)
1741    with
1742    out_of_line = True
1743
1744 primop  NewBCOOp "newBCO#" GenPrimOp
1745    ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> Int# -> ByteArr# -> State# s -> (# State# s, BCO# #)
1746    with
1747    has_side_effects = True
1748    out_of_line      = True
1749
1750 ------------------------------------------------------------------------
1751 section "Coercion" 
1752         {{\tt unsafeCoerce\# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1753
1754 ------------------------------------------------------------------------
1755
1756
1757 ------------------------------------------------------------------------
1758 ---                                                                  ---
1759 ------------------------------------------------------------------------
1760
1761 thats_all_folks
1762
1763
1764