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