1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.13 2001/12/13 10:47:28 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 -> mkStrictSig (mkTopDmdType (replicate arity lazyDmd) TopRes) }
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 "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.}
239 ------------------------------------------------------------------------
241 {Operations on native-sized unsigned words (30+ bits).}
242 ------------------------------------------------------------------------
244 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
245 with commutable = True
247 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
249 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
250 with commutable = True
252 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
255 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
258 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
259 with commutable = True
261 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
262 with commutable = True
264 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
265 with commutable = True
267 primop NotOp "not#" Monadic Word# -> Word#
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.}
276 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
278 primop Word2IntegerOp "word2Integer#" GenPrimOp
279 Word# -> (# Int#, ByteArr# #)
280 with out_of_line = True
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
289 ------------------------------------------------------------------------
291 {Explicit narrowing of native-sized ints or words.}
292 ------------------------------------------------------------------------
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#
302 #if WORD_SIZE_IN_BITS < 32
303 ------------------------------------------------------------------------
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 ------------------------------------------------------------------------
310 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
311 Int32# -> (# Int#, ByteArr# #)
312 with out_of_line = True
315 ------------------------------------------------------------------------
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 ------------------------------------------------------------------------
322 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
323 Word32# -> (# Int#, ByteArr# #)
324 with out_of_line = True
330 #if WORD_SIZE_IN_BITS < 64
331 ------------------------------------------------------------------------
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 ------------------------------------------------------------------------
338 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
339 Int64# -> (# Int#, ByteArr# #)
340 with out_of_line = True
342 ------------------------------------------------------------------------
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 ------------------------------------------------------------------------
349 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
350 Word64# -> (# Int#, ByteArr# #)
351 with out_of_line = True
355 ------------------------------------------------------------------------
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
364 For .NET these operations are implemented by foreign imports, so the
365 primops are omitted.}
366 ------------------------------------------------------------------------
370 primop IntegerAddOp "plusInteger#" GenPrimOp
371 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
372 with commutable = True
375 primop IntegerSubOp "minusInteger#" GenPrimOp
376 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
377 with out_of_line = True
379 primop IntegerMulOp "timesInteger#" GenPrimOp
380 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
381 with commutable = True
384 primop IntegerGcdOp "gcdInteger#" GenPrimOp
385 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
386 {Greatest common divisor.}
387 with commutable = True
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
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
400 primop IntegerQuotOp "quotInteger#" GenPrimOp
401 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
402 {Rounds towards zero.}
403 with out_of_line = True
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
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
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
423 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
424 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
425 {Compute quot and rem simulaneously.}
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}.}
436 primop Integer2IntOp "integer2Int#" GenPrimOp
437 Int# -> ByteArr# -> Int#
438 with needs_wrapper = True
441 primop Integer2WordOp "integer2Word#" GenPrimOp
442 Int# -> ByteArr# -> Word#
443 with needs_wrapper = True
446 #if WORD_SIZE_IN_BITS < 32
447 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
448 Int# -> ByteArr# -> Int32#
450 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
451 Int# -> ByteArr# -> Word32#
454 primop IntegerAndOp "andInteger#" GenPrimOp
455 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
456 with out_of_line = True
458 primop IntegerOrOp "orInteger#" GenPrimOp
459 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
460 with out_of_line = True
462 primop IntegerXorOp "xorInteger#" GenPrimOp
463 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
464 with out_of_line = True
466 primop IntegerComplementOp "complementInteger#" GenPrimOp
467 Int# -> ByteArr# -> (# Int#, ByteArr# #)
468 with out_of_line = True
470 #endif /* ndef ILX */
472 ------------------------------------------------------------------------
474 {Operations on double-precision (64 bit) floating-point numbers.}
475 ------------------------------------------------------------------------
477 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
478 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
480 primop DoubleEqOp "==##" Compare
481 Double# -> Double# -> Bool
482 with commutable = True
484 primop DoubleNeOp "/=##" Compare
485 Double# -> Double# -> Bool
486 with commutable = True
488 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
489 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
491 primop DoubleAddOp "+##" Dyadic
492 Double# -> Double# -> Double#
493 with commutable = True
495 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
497 primop DoubleMulOp "*##" Dyadic
498 Double# -> Double# -> Double#
499 with commutable = True
501 primop DoubleDivOp "/##" Dyadic
502 Double# -> Double# -> Double#
505 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
507 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
508 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
510 primop DoubleExpOp "expDouble#" Monadic
512 with needs_wrapper = True
514 primop DoubleLogOp "logDouble#" Monadic
520 primop DoubleSqrtOp "sqrtDouble#" Monadic
522 with needs_wrapper = True
524 primop DoubleSinOp "sinDouble#" Monadic
526 with needs_wrapper = True
528 primop DoubleCosOp "cosDouble#" Monadic
530 with needs_wrapper = True
532 primop DoubleTanOp "tanDouble#" Monadic
534 with needs_wrapper = True
536 primop DoubleAsinOp "asinDouble#" Monadic
542 primop DoubleAcosOp "acosDouble#" Monadic
548 primop DoubleAtanOp "atanDouble#" Monadic
553 primop DoubleSinhOp "sinhDouble#" Monadic
555 with needs_wrapper = True
557 primop DoubleCoshOp "coshDouble#" Monadic
559 with needs_wrapper = True
561 primop DoubleTanhOp "tanhDouble#" Monadic
563 with needs_wrapper = True
565 primop DoublePowerOp "**##" Dyadic
566 Double# -> Double# -> Double#
568 with needs_wrapper = True
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
577 ------------------------------------------------------------------------
579 {Operations on single-precision (32-bit) floating-point numbers.}
580 ------------------------------------------------------------------------
582 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
583 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
585 primop FloatEqOp "eqFloat#" Compare
586 Float# -> Float# -> Bool
587 with commutable = True
589 primop FloatNeOp "neFloat#" Compare
590 Float# -> Float# -> Bool
591 with commutable = True
593 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
594 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
596 primop FloatAddOp "plusFloat#" Dyadic
597 Float# -> Float# -> Float#
598 with commutable = True
600 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
602 primop FloatMulOp "timesFloat#" Dyadic
603 Float# -> Float# -> Float#
604 with commutable = True
606 primop FloatDivOp "divideFloat#" Dyadic
607 Float# -> Float# -> Float#
610 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
612 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
614 primop FloatExpOp "expFloat#" Monadic
616 with needs_wrapper = True
618 primop FloatLogOp "logFloat#" Monadic
620 with needs_wrapper = True
623 primop FloatSqrtOp "sqrtFloat#" Monadic
625 with needs_wrapper = True
627 primop FloatSinOp "sinFloat#" Monadic
629 with needs_wrapper = True
631 primop FloatCosOp "cosFloat#" Monadic
633 with needs_wrapper = True
635 primop FloatTanOp "tanFloat#" Monadic
637 with needs_wrapper = True
639 primop FloatAsinOp "asinFloat#" Monadic
641 with needs_wrapper = True
644 primop FloatAcosOp "acosFloat#" Monadic
646 with needs_wrapper = True
649 primop FloatAtanOp "atanFloat#" Monadic
651 with needs_wrapper = True
653 primop FloatSinhOp "sinhFloat#" Monadic
655 with needs_wrapper = True
657 primop FloatCoshOp "coshFloat#" Monadic
659 with needs_wrapper = True
661 primop FloatTanhOp "tanhFloat#" Monadic
663 with needs_wrapper = True
665 primop FloatPowerOp "powerFloat#" Dyadic
666 Float# -> Float# -> Float#
667 with needs_wrapper = True
669 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
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
678 ------------------------------------------------------------------------
680 {Operations on Array\#.}
681 ------------------------------------------------------------------------
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.}
689 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
692 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
693 MutArr# s a -> MutArr# s a -> Bool
695 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
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.}
701 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
703 primop WriteArrayOp "writeArray#" GenPrimOp
704 MutArr# s a -> Int# -> a -> State# s -> State# s
705 {Write to specified index of mutable array.}
707 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
708 has_side_effects = True
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.}
715 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
717 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
718 MutArr# s a -> State# s -> (# State# s, Array# a #)
719 {Make a mutable array immutable, without copying.}
721 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
722 has_side_effects = True
724 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
725 Array# a -> State# s -> (# State# s, MutArr# s a #)
726 {Make an immutable array mutable, without copying.}
728 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
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.}
743 ------------------------------------------------------------------------
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
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
756 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
758 {Intended for use with pinned arrays; otherwise very unsafe!}
760 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
761 MutByteArr# s -> MutByteArr# s -> Bool
763 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
764 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
765 {Make a mutable byte array immutable, without copying.}
767 has_side_effects = True
769 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
772 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
773 MutByteArr# s -> Int#
776 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
777 ByteArr# -> Int# -> Char#
778 {Read 8-bit character; offset in bytes.}
780 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
781 ByteArr# -> Int# -> Char#
782 {Read 31-bit character; offset in 4-byte words.}
784 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
785 ByteArr# -> Int# -> Int#
787 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
788 ByteArr# -> Int# -> Word#
790 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
791 ByteArr# -> Int# -> Addr#
793 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
794 ByteArr# -> Int# -> Float#
796 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
797 ByteArr# -> Int# -> Double#
799 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
800 ByteArr# -> Int# -> StablePtr# a
802 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
803 ByteArr# -> Int# -> Int#
805 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
806 ByteArr# -> Int# -> Int#
808 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
809 ByteArr# -> Int# -> INT32
811 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
812 ByteArr# -> Int# -> INT64
814 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
815 ByteArr# -> Int# -> Word#
817 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
818 ByteArr# -> Int# -> Word#
820 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
821 ByteArr# -> Int# -> WORD32
823 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
824 ByteArr# -> Int# -> WORD64
826 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
827 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
828 {Read 8-bit character; offset in bytes.}
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.}
834 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
835 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
837 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
838 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
840 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
841 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
843 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
844 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
846 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
847 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
849 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
850 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
852 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
853 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
855 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
856 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
858 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
859 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
861 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
862 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
864 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
865 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
867 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
868 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
870 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
871 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
873 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
874 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
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
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
886 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
887 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
888 with has_side_effects = True
890 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
891 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
892 with has_side_effects = True
894 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
895 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
896 with has_side_effects = True
898 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
899 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
900 with has_side_effects = True
902 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
903 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
904 with has_side_effects = True
906 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
907 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
908 with has_side_effects = True
910 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
911 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
912 with has_side_effects = True
914 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
915 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
916 with has_side_effects = True
918 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
919 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
920 with has_side_effects = True
922 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
923 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
924 with has_side_effects = True
926 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
927 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
928 with has_side_effects = True
930 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
931 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
932 with has_side_effects = True
934 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
935 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
936 with has_side_effects = True
938 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
939 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
940 with has_side_effects = True
942 ------------------------------------------------------------------------
944 {Addr\# is an arbitrary machine address assumed to point outside
945 the garbage-collected heap.
947 NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
948 It is the null address.}
949 ------------------------------------------------------------------------
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.}
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
972 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
973 Addr# -> Int# -> Char#
974 {Reads 8-bit character; offset in bytes.}
976 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
977 Addr# -> Int# -> Char#
978 {Reads 31-bit character; offset in 4-byte words.}
980 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
981 Addr# -> Int# -> Int#
983 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
984 Addr# -> Int# -> Word#
986 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
987 Addr# -> Int# -> Addr#
989 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
990 Addr# -> Int# -> Float#
992 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
993 Addr# -> Int# -> Double#
995 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
996 Addr# -> Int# -> StablePtr# a
998 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
999 Addr# -> Int# -> Int#
1001 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1002 Addr# -> Int# -> Int#
1004 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1005 Addr# -> Int# -> INT32
1007 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1008 Addr# -> Int# -> INT64
1010 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1011 Addr# -> Int# -> Word#
1013 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1014 Addr# -> Int# -> Word#
1016 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1017 Addr# -> Int# -> WORD32
1019 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1020 Addr# -> Int# -> WORD64
1022 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1023 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1024 {Reads 8-bit character; offset in bytes.}
1026 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1027 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1028 {Reads 31-bit character; offset in 4-byte words.}
1030 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1031 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1033 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1034 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1036 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1037 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1039 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1040 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1042 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1043 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1045 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1046 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1048 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1049 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1051 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1052 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1054 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1055 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1057 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1058 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1060 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1061 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1063 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1064 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1066 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1067 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1069 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1070 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1073 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1074 Addr# -> Int# -> Char# -> State# s -> State# s
1075 with has_side_effects = True
1077 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1078 Addr# -> Int# -> Char# -> State# s -> State# s
1079 with has_side_effects = True
1081 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1082 Addr# -> Int# -> Int# -> State# s -> State# s
1083 with has_side_effects = True
1085 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1086 Addr# -> Int# -> Word# -> State# s -> State# s
1087 with has_side_effects = True
1089 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1090 Addr# -> Int# -> Addr# -> State# s -> State# s
1091 with has_side_effects = True
1093 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1094 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1095 with has_side_effects = True
1097 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1098 Addr# -> Int# -> Float# -> State# s -> State# s
1099 with has_side_effects = True
1101 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1102 Addr# -> Int# -> Double# -> State# s -> State# s
1103 with has_side_effects = True
1105 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1106 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1107 with has_side_effects = True
1109 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1110 Addr# -> Int# -> Int# -> State# s -> State# s
1111 with has_side_effects = True
1113 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1114 Addr# -> Int# -> Int# -> State# s -> State# s
1115 with has_side_effects = True
1117 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1118 Addr# -> Int# -> INT32 -> State# s -> State# s
1119 with has_side_effects = True
1121 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1122 Addr# -> Int# -> INT64 -> State# s -> State# s
1123 with has_side_effects = True
1125 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1126 Addr# -> Int# -> Word# -> State# s -> State# s
1127 with has_side_effects = True
1129 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1130 Addr# -> Int# -> Word# -> State# s -> State# s
1131 with has_side_effects = True
1133 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1134 Addr# -> Int# -> WORD32 -> State# s -> State# s
1135 with has_side_effects = True
1137 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1138 Addr# -> Int# -> WORD64 -> State# s -> State# s
1139 with has_side_effects = True
1141 ------------------------------------------------------------------------
1142 section "ForeignObj#"
1143 {Operations on ForeignObj\#. The indexing operations are
1145 ------------------------------------------------------------------------
1147 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1148 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1150 has_side_effects = True
1153 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1154 ForeignObj# -> Addr# -> State# s -> State# s
1156 has_side_effects = True
1158 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1159 ForeignObj# -> Addr#
1161 primop TouchOp "touch#" GenPrimOp
1162 o -> State# RealWorld -> State# RealWorld
1164 has_side_effects = True
1166 primop EqForeignObj "eqForeignObj#" GenPrimOp
1167 ForeignObj# -> ForeignObj# -> Bool
1168 with commutable = True
1170 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1171 ForeignObj# -> Int# -> Char#
1172 {Read 8-bit character; offset in bytes.}
1174 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1175 ForeignObj# -> Int# -> Char#
1176 {Read 31-bit character; offset in 4-byte words.}
1178 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1179 ForeignObj# -> Int# -> Int#
1181 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1182 ForeignObj# -> Int# -> Word#
1184 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1185 ForeignObj# -> Int# -> Addr#
1187 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1188 ForeignObj# -> Int# -> Float#
1190 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1191 ForeignObj# -> Int# -> Double#
1193 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1194 ForeignObj# -> Int# -> StablePtr# a
1196 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1197 ForeignObj# -> Int# -> Int#
1199 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1200 ForeignObj# -> Int# -> Int#
1202 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1203 ForeignObj# -> Int# -> INT32
1205 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1206 ForeignObj# -> Int# -> INT64
1208 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1209 ForeignObj# -> Int# -> Word#
1211 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1212 ForeignObj# -> Int# -> Word#
1214 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1215 ForeignObj# -> Int# -> WORD32
1217 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1218 ForeignObj# -> Int# -> WORD64
1222 ------------------------------------------------------------------------
1223 section "Mutable variables"
1224 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1225 ------------------------------------------------------------------------
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.}
1231 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1234 primop ReadMutVarOp "readMutVar#" GenPrimOp
1235 MutVar# s a -> State# s -> (# State# s, a #)
1236 {Read contents of MutVar\#. Result is not yet evaluated.}
1238 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1240 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1241 MutVar# s a -> a -> State# s -> State# s
1242 {Write contents of MutVar\#.}
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 -- 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
1270 primop RaiseOp "raise#" GenPrimOp
1273 strictness = { \ arity -> mkStrictSig (mkTopDmdType [lazyDmd] BotRes) }
1274 -- NB: result is bottom
1275 usage = { mangle RaiseOp [mkM] mkM }
1278 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1279 (State# RealWorld -> (# State# RealWorld, a #))
1280 -> (State# RealWorld -> (# State# RealWorld, a #))
1284 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1285 (State# RealWorld -> (# State# RealWorld, a #))
1286 -> (State# RealWorld -> (# State# RealWorld, a #))
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 ------------------------------------------------------------------------
1298 primop NewMVarOp "newMVar#" GenPrimOp
1299 State# s -> (# State# s, MVar# s a #)
1300 {Create new mvar; initially empty.}
1302 usage = { mangle NewMVarOp [mkP] mkR }
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.}
1310 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1311 has_side_effects = True
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.}
1319 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1320 has_side_effects = True
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.}
1328 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1329 has_side_effects = True
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.}
1337 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1338 has_side_effects = True
1341 primop SameMVarOp "sameMVar#" GenPrimOp
1342 MVar# s a -> MVar# s a -> Bool
1344 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1346 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1347 MVar# s a -> State# s -> (# State# s, Int# #)
1348 {Return 1 if mvar is empty; 0 otherwise.}
1350 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1353 ------------------------------------------------------------------------
1354 section "Delay/wait operations"
1355 ------------------------------------------------------------------------
1357 primop DelayOp "delay#" GenPrimOp
1358 Int# -> State# s -> State# s
1359 {Sleep specified number of microseconds.}
1361 needs_wrapper = True
1362 has_side_effects = True
1365 primop WaitReadOp "waitRead#" GenPrimOp
1366 Int# -> State# s -> State# s
1367 {Block until input is available on specified file descriptor.}
1369 needs_wrapper = True
1370 has_side_effects = True
1373 primop WaitWriteOp "waitWrite#" GenPrimOp
1374 Int# -> State# s -> State# s
1375 {Block until output is possible on specified file descriptor.}
1377 needs_wrapper = True
1378 has_side_effects = True
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 ------------------------------------------------------------------------
1388 primop ForkOp "fork#" GenPrimOp
1389 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1391 usage = { mangle ForkOp [mkO, mkP] mkR }
1392 has_side_effects = True
1395 primop KillThreadOp "killThread#" GenPrimOp
1396 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1398 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1399 has_side_effects = True
1402 primop YieldOp "yield#" GenPrimOp
1403 State# RealWorld -> State# RealWorld
1405 has_side_effects = True
1408 primop MyThreadIdOp "myThreadId#" GenPrimOp
1409 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1413 ------------------------------------------------------------------------
1414 section "Weak pointers"
1415 ------------------------------------------------------------------------
1417 -- note that tyvar "o" denotes openAlphaTyVar
1419 primop MkWeakOp "mkWeak#" GenPrimOp
1420 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1422 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1423 has_side_effects = True
1426 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1427 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1429 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1430 has_side_effects = True
1433 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1434 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1435 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
1437 usage = { mangle FinalizeWeakOp [mkM, mkP]
1438 (mkR . (inUB FinalizeWeakOp
1439 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1440 has_side_effects = True
1443 ------------------------------------------------------------------------
1444 section "Stable pointers and names"
1445 ------------------------------------------------------------------------
1447 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1448 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1450 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1451 has_side_effects = True
1454 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1455 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1457 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1458 needs_wrapper = True
1459 has_side_effects = True
1462 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1463 StablePtr# a -> StablePtr# a -> Int#
1465 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1466 has_side_effects = True
1468 primop MakeStableNameOp "makeStableName#" GenPrimOp
1469 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1471 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1472 needs_wrapper = True
1473 has_side_effects = True
1476 primop EqStableNameOp "eqStableName#" GenPrimOp
1477 StableName# a -> StableName# a -> Int#
1479 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1481 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1482 StableName# a -> Int#
1484 usage = { mangle StableNameToIntOp [mkP] mkR }
1486 ------------------------------------------------------------------------
1487 section "Parallelism"
1488 ------------------------------------------------------------------------
1490 primop SeqOp "seq#" GenPrimOp
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
1498 primop ParOp "par#" GenPrimOp
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
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
1512 primop ParGlobalOp "parGlobal#" GenPrimOp
1513 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1515 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1516 has_side_effects = True
1518 primop ParLocalOp "parLocal#" GenPrimOp
1519 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1521 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1522 has_side_effects = True
1524 primop ParAtOp "parAt#" GenPrimOp
1525 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1527 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1528 has_side_effects = True
1530 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1531 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1533 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1534 has_side_effects = True
1536 primop ParAtRelOp "parAtRel#" GenPrimOp
1537 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1539 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1540 has_side_effects = True
1542 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1543 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1545 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1546 has_side_effects = True
1548 -- copyable# and noFollow# are yet to be implemented (for GpH)
1550 --primop CopyableOp "copyable#" GenPrimOp
1553 -- usage = { mangle CopyableOp [mkZ] mkR }
1554 -- has_side_effects = True
1556 --primop NoFollowOp "noFollow#" GenPrimOp
1559 -- usage = { mangle NoFollowOp [mkZ] mkR }
1560 -- has_side_effects = True
1563 ------------------------------------------------------------------------
1564 section "Tag to enum stuff"
1565 {Convert back and forth between values of enumerated types
1566 and small integers.}
1567 ------------------------------------------------------------------------
1569 primop DataToTagOp "dataToTag#" GenPrimOp
1572 primop TagToEnumOp "tagToEnum#" GenPrimOp
1575 ------------------------------------------------------------------------
1576 section "Bytecode operations"
1577 {Support for the bytecode interpreter and linker.}
1578 ------------------------------------------------------------------------
1581 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1583 {Convert an Addr\# to a followable type.}
1585 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1590 primop NewBCOOp "newBCO#" GenPrimOp
1591 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
1593 has_side_effects = True
1596 ------------------------------------------------------------------------
1598 {{\tt unsafeCoerce# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1600 ------------------------------------------------------------------------
1603 ------------------------------------------------------------------------
1605 ------------------------------------------------------------------------