1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.10 2001/12/05 17:35:14 sewardj Exp $
4 -- Primitive Operations
6 -----------------------------------------------------------------------
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.
12 -- It should first be preprocessed.
14 -- To add a new primop, you currently need to update the following files:
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.)
21 -- - ghc/lib/std/PrelGHC.hi-boot, to declare the primop
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)
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)
35 -- This file is divided into named sections, each containing or more
36 -- primop entries. Section headers have the format:
38 -- section "section-name" {description}
40 -- This information is used solely when producing documentation; it is
41 -- otherwise ignored. The description is optional.
43 -- The format of each primop entry is as follows:
45 -- primop internal-name "name-in-program-text" type category {description} attributes
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.
55 has_side_effects = False
60 strictness = { \ arity -> StrictnessInfo (replicate arity wwPrim) False }
61 usage = { nomangle other }
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.
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.
82 GHC also implements a primitive unsigned integer type {\tt
83 Word\#} which always has the same number of bits as {\tt
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
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}.
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. }
130 -- Define synonyms for indexing ops.
132 #if WORD_SIZE_IN_BITS < 32
134 #define WORD32 Word32#
140 #if WORD_SIZE_IN_BITS < 64
142 #define WORD64 Word64#
148 ------------------------------------------------------------------------
150 {Operations on 31-bit characters.}
151 ------------------------------------------------------------------------
154 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
155 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
157 primop CharEqOp "eqChar#" Compare
158 Char# -> Char# -> Bool
159 with commutable = True
161 primop CharNeOp "neChar#" Compare
162 Char# -> Char# -> Bool
163 with commutable = True
165 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
166 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
168 primop OrdOp "ord#" GenPrimOp Char# -> Int#
170 ------------------------------------------------------------------------
172 {Operations on native-size integers (30+ bits).}
173 ------------------------------------------------------------------------
175 primop IntAddOp "+#" Dyadic
177 with commutable = True
179 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
182 Dyadic Int# -> Int# -> Int#
183 with commutable = True
185 primop IntQuotOp "quotInt#" Dyadic
187 {Rounds towards zero.}
190 primop IntRemOp "remInt#" Dyadic
192 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
195 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
196 with out_of_line = True
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
208 primop IntEqOp "==#" Compare
210 with commutable = True
212 primop IntNeOp "/=#" Compare
214 with commutable = True
216 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
217 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
219 primop ChrOp "chr#" GenPrimOp Int# -> Char#
221 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
222 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
223 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
225 primop Int2IntegerOp "int2Integer#"
226 GenPrimOp Int# -> (# Int#, ByteArr# #)
227 with out_of_line = True
229 primop ISllOp "iShiftL#" GenPrimOp Int# -> Int# -> Int#
230 {Shift left. Return 0 if shifted by more than size of an Int\#.}
231 primop ISraOp "iShiftRA#" GenPrimOp Int# -> Int# -> Int#
232 {Shift right arithemetic. Return 0 if shifted by more than size of an Int\#.}
233 primop ISrlOp "iShiftRL#" GenPrimOp Int# -> Int# -> Int#
234 {Shift right logical. Return 0 if shifted by more than size of an Int\#.}
236 ------------------------------------------------------------------------
238 {Operations on native-sized unsigned words (30+ bits).}
239 ------------------------------------------------------------------------
241 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
242 with commutable = True
244 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
246 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
247 with commutable = True
249 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
252 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
255 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
256 with commutable = True
258 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
259 with commutable = True
261 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
262 with commutable = True
264 primop NotOp "not#" Monadic Word# -> Word#
266 primop SllOp "shiftL#" GenPrimOp Word# -> Int# -> Word#
267 {Shift left logical. Return 0 if shifted by more than number of bits in a Word\#.}
268 primop SrlOp "shiftRL#" GenPrimOp Word# -> Int# -> Word#
269 {Shift right logical. Return 0 if shifted by more than number of bits in a Word\#.}
271 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
273 primop Word2IntegerOp "word2Integer#" GenPrimOp
274 Word# -> (# Int#, ByteArr# #)
275 with out_of_line = True
277 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
278 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
279 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
280 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
281 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
282 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
284 ------------------------------------------------------------------------
286 {Explicit narrowing of native-sized ints or words.}
287 ------------------------------------------------------------------------
289 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
290 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
291 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
292 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
293 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
294 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
297 #if WORD_SIZE_IN_BITS < 32
298 ------------------------------------------------------------------------
300 {Operations on 32-bit integers (Int32\#). This type is only used
301 if plain Int\# has less than 32 bits. In any case, the operations
302 are not primops; they are implemented (if needed) as ccalls instead.}
303 ------------------------------------------------------------------------
305 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
306 Int32# -> (# Int#, ByteArr# #)
307 with out_of_line = True
310 ------------------------------------------------------------------------
312 {Operations on 32-bit unsigned words. This type is only used
313 if plain Word\# has less than 32 bits. In any case, the operations
314 are not primops; they are implemented (if needed) as ccalls instead.}
315 ------------------------------------------------------------------------
317 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
318 Word32# -> (# Int#, ByteArr# #)
319 with out_of_line = True
325 #if WORD_SIZE_IN_BITS < 64
326 ------------------------------------------------------------------------
328 {Operations on 64-bit unsigned words. This type is only used
329 if plain Int\# has less than 64 bits. In any case, the operations
330 are not primops; they are implemented (if needed) as ccalls instead.}
331 ------------------------------------------------------------------------
333 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
334 Int64# -> (# Int#, ByteArr# #)
335 with out_of_line = True
337 ------------------------------------------------------------------------
339 {Operations on 64-bit unsigned words. This type is only used
340 if plain Word\# has less than 64 bits. In any case, the operations
341 are not primops; they are implemented (if needed) as ccalls instead.}
342 ------------------------------------------------------------------------
344 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
345 Word64# -> (# Int#, ByteArr# #)
346 with out_of_line = True
350 ------------------------------------------------------------------------
352 {Operations on arbitrary-precision integers. These operations are
353 implemented via the GMP package. An integer is represented as a pair
354 consisting of an Int\# representing the number of 'limbs' in use and
355 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
356 are returned as unboxed pairs, but must be passed as separate
359 For .NET these operations are implemented by foreign imports, so the
360 primops are omitted.}
361 ------------------------------------------------------------------------
365 primop IntegerAddOp "plusInteger#" GenPrimOp
366 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
367 with commutable = True
370 primop IntegerSubOp "minusInteger#" GenPrimOp
371 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
372 with out_of_line = True
374 primop IntegerMulOp "timesInteger#" GenPrimOp
375 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
376 with commutable = True
379 primop IntegerGcdOp "gcdInteger#" GenPrimOp
380 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
381 {Greatest common divisor.}
382 with commutable = True
385 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
386 Int# -> ByteArr# -> Int# -> Int#
387 {Greatest common divisor, where second argument is an ordinary Int\#.}
388 with out_of_line = True
390 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
391 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
392 {Divisor is guaranteed to be a factor of dividend.}
393 with out_of_line = True
395 primop IntegerQuotOp "quotInteger#" GenPrimOp
396 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
397 {Rounds towards zero.}
398 with out_of_line = True
400 primop IntegerRemOp "remInteger#" GenPrimOp
401 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
402 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
403 with out_of_line = True
405 primop IntegerCmpOp "cmpInteger#" GenPrimOp
406 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
407 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
408 with needs_wrapper = True
411 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
412 Int# -> ByteArr# -> Int# -> Int#
413 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
414 is an ordinary Int\#.}
415 with needs_wrapper = True
418 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
419 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
420 {Compute quot and rem simulaneously.}
424 primop IntegerDivModOp "divModInteger#" GenPrimOp
425 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
426 {Compute div and mod simultaneously, where div rounds towards negative infinity
427 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
431 primop Integer2IntOp "integer2Int#" GenPrimOp
432 Int# -> ByteArr# -> Int#
433 with needs_wrapper = True
436 primop Integer2WordOp "integer2Word#" GenPrimOp
437 Int# -> ByteArr# -> Word#
438 with needs_wrapper = True
441 #if WORD_SIZE_IN_BITS < 32
442 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
443 Int# -> ByteArr# -> Int32#
445 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
446 Int# -> ByteArr# -> Word32#
449 primop IntegerAndOp "andInteger#" GenPrimOp
450 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
451 with out_of_line = True
453 primop IntegerOrOp "orInteger#" GenPrimOp
454 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
455 with out_of_line = True
457 primop IntegerXorOp "xorInteger#" GenPrimOp
458 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
459 with out_of_line = True
461 primop IntegerComplementOp "complementInteger#" GenPrimOp
462 Int# -> ByteArr# -> (# Int#, ByteArr# #)
463 with out_of_line = True
465 #endif /* ndef ILX */
467 ------------------------------------------------------------------------
469 {Operations on double-precision (64 bit) floating-point numbers.}
470 ------------------------------------------------------------------------
472 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
473 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
475 primop DoubleEqOp "==##" Compare
476 Double# -> Double# -> Bool
477 with commutable = True
479 primop DoubleNeOp "/=##" Compare
480 Double# -> Double# -> Bool
481 with commutable = True
483 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
484 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
486 primop DoubleAddOp "+##" Dyadic
487 Double# -> Double# -> Double#
488 with commutable = True
490 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
492 primop DoubleMulOp "*##" Dyadic
493 Double# -> Double# -> Double#
494 with commutable = True
496 primop DoubleDivOp "/##" Dyadic
497 Double# -> Double# -> Double#
500 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
502 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
503 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
505 primop DoubleExpOp "expDouble#" Monadic
507 with needs_wrapper = True
509 primop DoubleLogOp "logDouble#" Monadic
515 primop DoubleSqrtOp "sqrtDouble#" Monadic
517 with needs_wrapper = True
519 primop DoubleSinOp "sinDouble#" Monadic
521 with needs_wrapper = True
523 primop DoubleCosOp "cosDouble#" Monadic
525 with needs_wrapper = True
527 primop DoubleTanOp "tanDouble#" Monadic
529 with needs_wrapper = True
531 primop DoubleAsinOp "asinDouble#" Monadic
537 primop DoubleAcosOp "acosDouble#" Monadic
543 primop DoubleAtanOp "atanDouble#" Monadic
548 primop DoubleSinhOp "sinhDouble#" Monadic
550 with needs_wrapper = True
552 primop DoubleCoshOp "coshDouble#" Monadic
554 with needs_wrapper = True
556 primop DoubleTanhOp "tanhDouble#" Monadic
558 with needs_wrapper = True
560 primop DoublePowerOp "**##" Dyadic
561 Double# -> Double# -> Double#
563 with needs_wrapper = True
565 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
566 Double# -> (# Int#, Int#, ByteArr# #)
567 {Convert to arbitrary-precision integer.
568 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
569 holding the mantissa.}
570 with out_of_line = True
572 ------------------------------------------------------------------------
574 {Operations on single-precision (32-bit) floating-point numbers.}
575 ------------------------------------------------------------------------
577 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
578 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
580 primop FloatEqOp "eqFloat#" Compare
581 Float# -> Float# -> Bool
582 with commutable = True
584 primop FloatNeOp "neFloat#" Compare
585 Float# -> Float# -> Bool
586 with commutable = True
588 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
589 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
591 primop FloatAddOp "plusFloat#" Dyadic
592 Float# -> Float# -> Float#
593 with commutable = True
595 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
597 primop FloatMulOp "timesFloat#" Dyadic
598 Float# -> Float# -> Float#
599 with commutable = True
601 primop FloatDivOp "divideFloat#" Dyadic
602 Float# -> Float# -> Float#
605 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
607 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
609 primop FloatExpOp "expFloat#" Monadic
611 with needs_wrapper = True
613 primop FloatLogOp "logFloat#" Monadic
615 with needs_wrapper = True
618 primop FloatSqrtOp "sqrtFloat#" Monadic
620 with needs_wrapper = True
622 primop FloatSinOp "sinFloat#" Monadic
624 with needs_wrapper = True
626 primop FloatCosOp "cosFloat#" Monadic
628 with needs_wrapper = True
630 primop FloatTanOp "tanFloat#" Monadic
632 with needs_wrapper = True
634 primop FloatAsinOp "asinFloat#" Monadic
636 with needs_wrapper = True
639 primop FloatAcosOp "acosFloat#" Monadic
641 with needs_wrapper = True
644 primop FloatAtanOp "atanFloat#" Monadic
646 with needs_wrapper = True
648 primop FloatSinhOp "sinhFloat#" Monadic
650 with needs_wrapper = True
652 primop FloatCoshOp "coshFloat#" Monadic
654 with needs_wrapper = True
656 primop FloatTanhOp "tanhFloat#" Monadic
658 with needs_wrapper = True
660 primop FloatPowerOp "powerFloat#" Dyadic
661 Float# -> Float# -> Float#
662 with needs_wrapper = True
664 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
666 primop FloatDecodeOp "decodeFloat#" GenPrimOp
667 Float# -> (# Int#, Int#, ByteArr# #)
668 {Convert to arbitrary-precision integer.
669 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
670 holding the mantissa.}
671 with out_of_line = True
673 ------------------------------------------------------------------------
675 {Operations on Array\#.}
676 ------------------------------------------------------------------------
678 primop NewArrayOp "newArray#" GenPrimOp
679 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
680 {Create a new mutable array of specified size (in bytes),
681 in the specified state thread,
682 with each element containing the specified initial value.}
684 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
685 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
688 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
689 MutArr# s a -> MutArr# s a -> Bool
691 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
693 primop ReadArrayOp "readArray#" GenPrimOp
694 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
695 {Read from specified index of mutable array. Result is not yet evaluated.}
697 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
699 primop WriteArrayOp "writeArray#" GenPrimOp
700 MutArr# s a -> Int# -> a -> State# s -> State# s
701 {Write to specified index of mutable array.}
703 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
704 strictness = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
705 has_side_effects = True
707 primop IndexArrayOp "indexArray#" GenPrimOp
708 Array# a -> Int# -> (# a #)
709 {Read from specified index of immutable array. Result is packaged into
710 an unboxed singleton; the result itself is not yet evaluated.}
712 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
714 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
715 MutArr# s a -> State# s -> (# State# s, Array# a #)
716 {Make a mutable array immutable, without copying.}
718 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
719 has_side_effects = True
721 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
722 Array# a -> State# s -> (# State# s, MutArr# s a #)
723 {Make an immutable array mutable, without copying.}
725 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
728 ------------------------------------------------------------------------
729 section "Byte Arrays"
730 {Operations on ByteArray\#. A ByteArray\# is a just a region of
731 raw memory in the garbage-collected heap, which is not scanned
732 for pointers. It carries its own size (in bytes). There are
733 three sets of operations for accessing byte array contents:
734 index for reading from immutable byte arrays, and read/write
735 for mutable byte arrays. Each set contains operations for
736 a range of useful primitive data types. Each operation takes
737 an offset measured in terms of the size fo the primitive type
738 being read or written.}
740 ------------------------------------------------------------------------
742 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
743 Int# -> State# s -> (# State# s, MutByteArr# s #)
744 {Create a new mutable byte array of specified size (in bytes), in
745 the specified state thread.}
746 with out_of_line = True
748 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
749 Int# -> State# s -> (# State# s, MutByteArr# s #)
750 {Create a mutable byte array that the GC guarantees not to move.}
751 with out_of_line = True
753 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
755 {Intended for use with pinned arrays; otherwise very unsafe!}
757 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
758 MutByteArr# s -> MutByteArr# s -> Bool
760 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
761 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
762 {Make a mutable byte array immutable, without copying.}
764 has_side_effects = True
766 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
769 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
770 MutByteArr# s -> Int#
773 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
774 ByteArr# -> Int# -> Char#
775 {Read 8-bit character; offset in bytes.}
777 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
778 ByteArr# -> Int# -> Char#
779 {Read 31-bit character; offset in 4-byte words.}
781 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
782 ByteArr# -> Int# -> Int#
784 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
785 ByteArr# -> Int# -> Word#
787 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
788 ByteArr# -> Int# -> Addr#
790 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
791 ByteArr# -> Int# -> Float#
793 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
794 ByteArr# -> Int# -> Double#
796 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
797 ByteArr# -> Int# -> StablePtr# a
799 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
800 ByteArr# -> Int# -> Int#
802 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
803 ByteArr# -> Int# -> Int#
805 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
806 ByteArr# -> Int# -> INT32
808 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
809 ByteArr# -> Int# -> INT64
811 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
812 ByteArr# -> Int# -> Word#
814 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
815 ByteArr# -> Int# -> Word#
817 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
818 ByteArr# -> Int# -> WORD32
820 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
821 ByteArr# -> Int# -> WORD64
823 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
824 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
825 {Read 8-bit character; offset in bytes.}
827 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
828 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
829 {Read 31-bit character; offset in 4-byte words.}
831 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
832 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
834 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
835 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
837 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
838 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
840 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
841 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
843 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
844 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
846 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
847 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
849 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
850 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
852 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
853 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
855 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
856 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
858 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
859 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
861 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
862 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
864 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
865 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
867 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
868 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
870 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
871 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
873 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
874 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
875 {Write 8-bit character; offset in bytes.}
876 with has_side_effects = True
878 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
879 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
880 {Write 31-bit character; offset in 4-byte words.}
881 with has_side_effects = True
883 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
884 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
885 with has_side_effects = True
887 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
888 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
889 with has_side_effects = True
891 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
892 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
893 with has_side_effects = True
895 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
896 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
897 with has_side_effects = True
899 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
900 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
901 with has_side_effects = True
903 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
904 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
905 with has_side_effects = True
907 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
908 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
909 with has_side_effects = True
911 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
912 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
913 with has_side_effects = True
915 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
916 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
917 with has_side_effects = True
919 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
920 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
921 with has_side_effects = True
923 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
924 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
925 with has_side_effects = True
927 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
928 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
929 with has_side_effects = True
931 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
932 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
933 with has_side_effects = True
935 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
936 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
937 with has_side_effects = True
939 ------------------------------------------------------------------------
941 {Addr\# is an arbitrary machine address assumed to point outside
942 the garbage-collected heap.
944 NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
945 It is the null address.}
946 ------------------------------------------------------------------------
948 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
949 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
950 {Result is meaningless if two Addr\#s are so far apart that their
951 difference doesn't fit in an Int\#.}
952 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
953 {Return the remainder when the Addr\# arg, treated like an Int\#,
954 is divided by the Int\# arg.}
955 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
956 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
957 {Coerce directly from address to int. Strongly deprecated.}
958 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
959 {Coerce directly from int to address. Strongly deprecated.}
962 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
963 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
964 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
965 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
966 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
967 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
969 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
970 Addr# -> Int# -> Char#
971 {Reads 8-bit character; offset in bytes.}
973 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
974 Addr# -> Int# -> Char#
975 {Reads 31-bit character; offset in 4-byte words.}
977 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
978 Addr# -> Int# -> Int#
980 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
981 Addr# -> Int# -> Word#
983 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
984 Addr# -> Int# -> Addr#
986 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
987 Addr# -> Int# -> Float#
989 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
990 Addr# -> Int# -> Double#
992 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
993 Addr# -> Int# -> StablePtr# a
995 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
996 Addr# -> Int# -> Int#
998 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
999 Addr# -> Int# -> Int#
1001 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1002 Addr# -> Int# -> INT32
1004 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1005 Addr# -> Int# -> INT64
1007 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1008 Addr# -> Int# -> Word#
1010 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1011 Addr# -> Int# -> Word#
1013 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1014 Addr# -> Int# -> WORD32
1016 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1017 Addr# -> Int# -> WORD64
1019 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1020 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1021 {Reads 8-bit character; offset in bytes.}
1023 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1024 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1025 {Reads 31-bit character; offset in 4-byte words.}
1027 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1028 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1030 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1031 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1033 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1034 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1036 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1037 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1039 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1040 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1042 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1043 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1045 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1046 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1048 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1049 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1051 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1052 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1054 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1055 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1057 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1058 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1060 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1061 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1063 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1064 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1066 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1067 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1070 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1071 Addr# -> Int# -> Char# -> State# s -> State# s
1072 with has_side_effects = True
1074 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1075 Addr# -> Int# -> Char# -> State# s -> State# s
1076 with has_side_effects = True
1078 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1079 Addr# -> Int# -> Int# -> State# s -> State# s
1080 with has_side_effects = True
1082 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1083 Addr# -> Int# -> Word# -> State# s -> State# s
1084 with has_side_effects = True
1086 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1087 Addr# -> Int# -> Addr# -> State# s -> State# s
1088 with has_side_effects = True
1090 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1091 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1092 with has_side_effects = True
1094 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1095 Addr# -> Int# -> Float# -> State# s -> State# s
1096 with has_side_effects = True
1098 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1099 Addr# -> Int# -> Double# -> State# s -> State# s
1100 with has_side_effects = True
1102 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1103 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1104 with has_side_effects = True
1106 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1107 Addr# -> Int# -> Int# -> State# s -> State# s
1108 with has_side_effects = True
1110 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1111 Addr# -> Int# -> Int# -> State# s -> State# s
1112 with has_side_effects = True
1114 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1115 Addr# -> Int# -> INT32 -> State# s -> State# s
1116 with has_side_effects = True
1118 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1119 Addr# -> Int# -> INT64 -> State# s -> State# s
1120 with has_side_effects = True
1122 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1123 Addr# -> Int# -> Word# -> State# s -> State# s
1124 with has_side_effects = True
1126 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1127 Addr# -> Int# -> Word# -> State# s -> State# s
1128 with has_side_effects = True
1130 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1131 Addr# -> Int# -> WORD32 -> State# s -> State# s
1132 with has_side_effects = True
1134 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1135 Addr# -> Int# -> WORD64 -> State# s -> State# s
1136 with has_side_effects = True
1138 ------------------------------------------------------------------------
1139 section "ForeignObj#"
1140 {Operations on ForeignObj\#. The indexing operations are
1142 ------------------------------------------------------------------------
1144 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1145 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1147 has_side_effects = True
1150 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1151 ForeignObj# -> Addr# -> State# s -> State# s
1153 has_side_effects = True
1155 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1156 ForeignObj# -> Addr#
1158 primop TouchOp "touch#" GenPrimOp
1159 o -> State# RealWorld -> State# RealWorld
1161 has_side_effects = True
1162 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1164 primop EqForeignObj "eqForeignObj#" GenPrimOp
1165 ForeignObj# -> ForeignObj# -> Bool
1166 with commutable = True
1168 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1169 ForeignObj# -> Int# -> Char#
1170 {Read 8-bit character; offset in bytes.}
1172 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1173 ForeignObj# -> Int# -> Char#
1174 {Read 31-bit character; offset in 4-byte words.}
1176 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1177 ForeignObj# -> Int# -> Int#
1179 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1180 ForeignObj# -> Int# -> Word#
1182 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1183 ForeignObj# -> Int# -> Addr#
1185 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1186 ForeignObj# -> Int# -> Float#
1188 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1189 ForeignObj# -> Int# -> Double#
1191 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1192 ForeignObj# -> Int# -> StablePtr# a
1194 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1195 ForeignObj# -> Int# -> Int#
1197 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1198 ForeignObj# -> Int# -> Int#
1200 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1201 ForeignObj# -> Int# -> INT32
1203 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1204 ForeignObj# -> Int# -> INT64
1206 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1207 ForeignObj# -> Int# -> Word#
1209 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1210 ForeignObj# -> Int# -> Word#
1212 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1213 ForeignObj# -> Int# -> WORD32
1215 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1216 ForeignObj# -> Int# -> WORD64
1220 ------------------------------------------------------------------------
1221 section "Mutable variables"
1222 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1223 ------------------------------------------------------------------------
1225 primop NewMutVarOp "newMutVar#" GenPrimOp
1226 a -> State# s -> (# State# s, MutVar# s a #)
1227 {Create MutVar\# with specified initial value in specified state thread.}
1229 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1230 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1233 primop ReadMutVarOp "readMutVar#" GenPrimOp
1234 MutVar# s a -> State# s -> (# State# s, a #)
1235 {Read contents of MutVar\#. Result is not yet evaluated.}
1237 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1239 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1240 MutVar# s a -> a -> State# s -> State# s
1241 {Write contents of MutVar\#.}
1243 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1244 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1245 has_side_effects = True
1247 primop SameMutVarOp "sameMutVar#" GenPrimOp
1248 MutVar# s a -> MutVar# s a -> Bool
1250 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1252 ------------------------------------------------------------------------
1253 section "Exceptions"
1254 ------------------------------------------------------------------------
1256 primop CatchOp "catch#" GenPrimOp
1257 (State# RealWorld -> (# State# RealWorld, a #) )
1258 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1260 -> (# State# RealWorld, a #)
1262 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
1263 -- Catch is actually strict in its first argument
1264 -- but we don't want to tell the strictness
1265 -- analyser about that!
1266 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1267 -- [mkO, mkO . (inFun mkM mkO)] mkO
1268 -- might use caught action multiply
1271 primop RaiseOp "raise#" GenPrimOp
1274 strictness = { \ arity -> StrictnessInfo [wwLazy] True }
1275 -- NB: True => result is bottom
1276 usage = { mangle RaiseOp [mkM] mkM }
1279 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1280 (State# RealWorld -> (# State# RealWorld, a #))
1281 -> (State# RealWorld -> (# State# RealWorld, a #))
1283 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1286 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1287 (State# RealWorld -> (# State# RealWorld, a #))
1288 -> (State# RealWorld -> (# State# RealWorld, a #))
1290 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1293 ------------------------------------------------------------------------
1294 section "Synchronized Mutable Variables"
1295 {Operations on MVar\#s, which are shared mutable variables
1296 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1297 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1298 ------------------------------------------------------------------------
1301 primop NewMVarOp "newMVar#" GenPrimOp
1302 State# s -> (# State# s, MVar# s a #)
1303 {Create new mvar; initially empty.}
1305 usage = { mangle NewMVarOp [mkP] mkR }
1308 primop TakeMVarOp "takeMVar#" GenPrimOp
1309 MVar# s a -> State# s -> (# State# s, a #)
1310 {If mvar is empty, block until it becomes full.
1311 Then remove and return its contents, and set it empty.}
1313 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1314 has_side_effects = True
1317 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1318 MVar# s a -> State# s -> (# State# s, Int#, a #)
1319 {If mvar is empty, immediately return with integer 0 and value undefined.
1320 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1322 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1323 has_side_effects = True
1326 primop PutMVarOp "putMVar#" GenPrimOp
1327 MVar# s a -> a -> State# s -> State# s
1328 {If mvar is full, block until it becomes empty.
1329 Then store value arg as its new contents.}
1331 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1332 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1333 has_side_effects = True
1336 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1337 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1338 {If mvar is full, immediately return with integer 0.
1339 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1341 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1342 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1343 has_side_effects = True
1346 primop SameMVarOp "sameMVar#" GenPrimOp
1347 MVar# s a -> MVar# s a -> Bool
1349 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1351 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1352 MVar# s a -> State# s -> (# State# s, Int# #)
1353 {Return 1 if mvar is empty; 0 otherwise.}
1355 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1358 ------------------------------------------------------------------------
1359 section "Delay/wait operations"
1360 ------------------------------------------------------------------------
1362 primop DelayOp "delay#" GenPrimOp
1363 Int# -> State# s -> State# s
1364 {Sleep specified number of microseconds.}
1366 needs_wrapper = True
1367 has_side_effects = True
1370 primop WaitReadOp "waitRead#" GenPrimOp
1371 Int# -> State# s -> State# s
1372 {Block until input is available on specified file descriptor.}
1374 needs_wrapper = True
1375 has_side_effects = True
1378 primop WaitWriteOp "waitWrite#" GenPrimOp
1379 Int# -> State# s -> State# s
1380 {Block until output is possible on specified file descriptor.}
1382 needs_wrapper = True
1383 has_side_effects = True
1386 ------------------------------------------------------------------------
1387 section "Concurrency primitives"
1388 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1389 type, whose (unique) value is returned by myThreadId\#. The
1390 other operations can be omitted.)}
1391 ------------------------------------------------------------------------
1393 primop ForkOp "fork#" GenPrimOp
1394 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1396 usage = { mangle ForkOp [mkO, mkP] mkR }
1397 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1398 has_side_effects = True
1401 primop KillThreadOp "killThread#" GenPrimOp
1402 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1404 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1405 has_side_effects = True
1408 primop YieldOp "yield#" GenPrimOp
1409 State# RealWorld -> State# RealWorld
1411 has_side_effects = True
1414 primop MyThreadIdOp "myThreadId#" GenPrimOp
1415 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1419 ------------------------------------------------------------------------
1420 section "Weak pointers"
1421 ------------------------------------------------------------------------
1423 -- note that tyvar "o" denotes openAlphaTyVar
1425 primop MkWeakOp "mkWeak#" GenPrimOp
1426 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1428 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
1429 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1430 has_side_effects = True
1433 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1434 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1436 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1437 has_side_effects = True
1440 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1441 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1442 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
1444 usage = { mangle FinalizeWeakOp [mkM, mkP]
1445 (mkR . (inUB FinalizeWeakOp
1446 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1447 has_side_effects = True
1450 ------------------------------------------------------------------------
1451 section "Stable pointers and names"
1452 ------------------------------------------------------------------------
1454 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1455 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1457 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1458 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1459 has_side_effects = True
1462 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1463 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1465 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1466 needs_wrapper = True
1467 has_side_effects = True
1470 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1471 StablePtr# a -> StablePtr# a -> Int#
1473 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1474 has_side_effects = True
1476 primop MakeStableNameOp "makeStableName#" GenPrimOp
1477 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1479 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1480 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1481 needs_wrapper = True
1482 has_side_effects = True
1485 primop EqStableNameOp "eqStableName#" GenPrimOp
1486 StableName# a -> StableName# a -> Int#
1488 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1490 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1491 StableName# a -> Int#
1493 usage = { mangle StableNameToIntOp [mkP] mkR }
1495 ------------------------------------------------------------------------
1496 section "Parallelism"
1497 ------------------------------------------------------------------------
1499 primop SeqOp "seq#" GenPrimOp
1502 usage = { mangle SeqOp [mkO] mkR }
1503 strictness = { \ arity -> StrictnessInfo [wwStrict] False }
1504 -- Seq is strict in its argument; see notes in ConFold.lhs
1505 has_side_effects = True
1507 primop ParOp "par#" GenPrimOp
1510 usage = { mangle ParOp [mkO] mkR }
1511 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1512 -- Note that Par is lazy to avoid that the sparked thing
1513 -- gets evaluted strictly, which it should *not* be
1514 has_side_effects = True
1516 -- HWL: The first 4 Int# in all par... annotations denote:
1517 -- name, granularity info, size of result, degree of parallelism
1518 -- Same structure as _seq_ i.e. returns Int#
1519 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1520 -- `the processor containing the expression v'; it is not evaluated
1522 primop ParGlobalOp "parGlobal#" GenPrimOp
1523 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1525 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1526 has_side_effects = True
1528 primop ParLocalOp "parLocal#" GenPrimOp
1529 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1531 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1532 has_side_effects = True
1534 primop ParAtOp "parAt#" GenPrimOp
1535 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1537 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1538 has_side_effects = True
1540 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1541 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1543 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1544 has_side_effects = True
1546 primop ParAtRelOp "parAtRel#" GenPrimOp
1547 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1549 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1550 has_side_effects = True
1552 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1553 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1555 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1556 has_side_effects = True
1558 -- copyable# and noFollow# are yet to be implemented (for GpH)
1560 --primop CopyableOp "copyable#" GenPrimOp
1563 -- usage = { mangle CopyableOp [mkZ] mkR }
1564 -- has_side_effects = True
1566 --primop NoFollowOp "noFollow#" GenPrimOp
1569 -- usage = { mangle NoFollowOp [mkZ] mkR }
1570 -- has_side_effects = True
1573 ------------------------------------------------------------------------
1574 section "Tag to enum stuff"
1575 {Convert back and forth between values of enumerated types
1576 and small integers.}
1577 ------------------------------------------------------------------------
1579 primop DataToTagOp "dataToTag#" GenPrimOp
1582 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1584 primop TagToEnumOp "tagToEnum#" GenPrimOp
1587 ------------------------------------------------------------------------
1588 section "Bytecode operations"
1589 {Support for the bytecode interpreter and linker.}
1590 ------------------------------------------------------------------------
1593 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1595 {Convert an Addr\# to a followable type.}
1597 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1602 primop NewBCOOp "newBCO#" GenPrimOp
1603 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
1605 has_side_effects = True
1608 ------------------------------------------------------------------------
1610 {{\tt unsafeCoerce# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1612 ------------------------------------------------------------------------
1615 ------------------------------------------------------------------------
1617 ------------------------------------------------------------------------