1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.7 2001/10/16 13:31:56 simonmar 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), 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 primop IntNegOp "negateInt#" Monadic Int# -> Int#
197 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
198 {Add with carry. First member of result is (wrapped) sum; second member is 0 iff no overflow occured.}
199 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
200 {Subtract with carry. First member of result is (wrapped) difference; second member is 0 iff no overflow occured.}
201 primop IntMulCOp "mulIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
202 {Multiply with carry. First member of result is (wrapped) product; second member is 0 iff no overflow occured.}
203 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
204 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
206 primop IntEqOp "==#" Compare
208 with commutable = True
210 primop IntNeOp "/=#" Compare
212 with commutable = True
214 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
215 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
217 primop ChrOp "chr#" GenPrimOp Int# -> Char#
219 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
220 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
221 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
223 primop Int2IntegerOp "int2Integer#"
224 GenPrimOp Int# -> (# Int#, ByteArr# #)
225 with out_of_line = True
227 primop ISllOp "iShiftL#" GenPrimOp Int# -> Int# -> Int#
228 {Shift left. Return 0 if shifted by more than size of an Int\#.}
229 primop ISraOp "iShiftRA#" GenPrimOp Int# -> Int# -> Int#
230 {Shift right arithemetic. Return 0 if shifted by more than size of an Int\#.}
231 primop ISrlOp "iShiftRL#" GenPrimOp Int# -> Int# -> Int#
232 {Shift right logical. Return 0 if shifted by more than size of an Int\#.}
234 ------------------------------------------------------------------------
236 {Operations on native-sized unsigned words (30+ bits).}
237 ------------------------------------------------------------------------
239 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
240 with commutable = True
242 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
244 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
245 with commutable = True
247 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
250 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
253 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
254 with commutable = True
256 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
257 with commutable = True
259 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
260 with commutable = True
262 primop NotOp "not#" Monadic Word# -> Word#
264 primop SllOp "shiftL#" GenPrimOp Word# -> Int# -> Word#
265 {Shift left logical. Return 0 if shifted by more than number of bits in a Word\#.}
266 primop SrlOp "shiftRL#" GenPrimOp Word# -> Int# -> Word#
267 {Shift right logical. Return 0 if shifted by more than number of bits in a Word\#.}
269 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
271 primop Word2IntegerOp "word2Integer#" GenPrimOp
272 Word# -> (# Int#, ByteArr# #)
273 with out_of_line = True
275 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
276 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
277 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
278 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
279 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
280 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
282 ------------------------------------------------------------------------
284 {Explicit narrowing of native-sized ints or words.}
285 ------------------------------------------------------------------------
287 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
288 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
289 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
290 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
291 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
292 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
295 #if WORD_SIZE_IN_BITS < 32
296 ------------------------------------------------------------------------
298 {Operations on 32-bit integers (Int32\#). This type is only used
299 if plain Int\# has less than 32 bits. In any case, the operations
300 are not primops; they are implemented (if needed) as ccalls instead.}
301 ------------------------------------------------------------------------
303 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
304 Int32# -> (# Int#, ByteArr# #)
305 with out_of_line = True
308 ------------------------------------------------------------------------
310 {Operations on 32-bit unsigned words. This type is only used
311 if plain Word\# has less than 32 bits. In any case, the operations
312 are not primops; they are implemented (if needed) as ccalls instead.}
313 ------------------------------------------------------------------------
315 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
316 Word32# -> (# Int#, ByteArr# #)
317 with out_of_line = True
323 #if WORD_SIZE_IN_BITS < 64
324 ------------------------------------------------------------------------
326 {Operations on 64-bit unsigned words. This type is only used
327 if plain Int\# has less than 64 bits. In any case, the operations
328 are not primops; they are implemented (if needed) as ccalls instead.}
329 ------------------------------------------------------------------------
331 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
332 Int64# -> (# Int#, ByteArr# #)
333 with out_of_line = True
335 ------------------------------------------------------------------------
337 {Operations on 64-bit unsigned words. This type is only used
338 if plain Word\# has less than 64 bits. In any case, the operations
339 are not primops; they are implemented (if needed) as ccalls instead.}
340 ------------------------------------------------------------------------
342 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
343 Word64# -> (# Int#, ByteArr# #)
344 with out_of_line = True
348 ------------------------------------------------------------------------
350 {Operations on arbitrary-precision integers. These operations are
351 implemented via the GMP package. An integer is represented as a pair
352 consisting of an Int\# representing the number of 'limbs' in use and
353 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
354 are returned as unboxed pairs, but must be passed as separate components.}
355 ------------------------------------------------------------------------
357 primop IntegerAddOp "plusInteger#" GenPrimOp
358 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
359 with commutable = True
362 primop IntegerSubOp "minusInteger#" GenPrimOp
363 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
364 with out_of_line = True
366 primop IntegerMulOp "timesInteger#" GenPrimOp
367 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
368 with commutable = True
371 primop IntegerGcdOp "gcdInteger#" GenPrimOp
372 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
373 {Greatest common divisor.}
374 with commutable = True
377 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
378 Int# -> ByteArr# -> Int# -> Int#
379 {Greatest common divisor, where second argument is an ordinary Int\#.}
380 -- with commutable = True (surely not? APT 8/01)
382 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
383 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
384 {Divisor is guaranteed to be a factor of dividend.}
385 with out_of_line = True
387 primop IntegerQuotOp "quotInteger#" GenPrimOp
388 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
389 {Rounds towards zero.}
390 with out_of_line = True
392 primop IntegerRemOp "remInteger#" GenPrimOp
393 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
394 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
395 with out_of_line = True
397 primop IntegerCmpOp "cmpInteger#" GenPrimOp
398 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
399 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
400 with needs_wrapper = True
402 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
403 Int# -> ByteArr# -> Int# -> Int#
404 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
405 is an ordinary Int\#.}
406 with needs_wrapper = True
408 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
409 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
410 {Compute quot and rem simulaneously.}
414 primop IntegerDivModOp "divModInteger#" GenPrimOp
415 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
416 {Compute div and mod simultaneously, where div rounds towards negative infinity
417 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
421 primop Integer2IntOp "integer2Int#" GenPrimOp
422 Int# -> ByteArr# -> Int#
423 with needs_wrapper = True
425 primop Integer2WordOp "integer2Word#" GenPrimOp
426 Int# -> ByteArr# -> Word#
427 with needs_wrapper = True
429 #if WORD_SIZE_IN_BITS < 32
430 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
431 Int# -> ByteArr# -> Int32#
433 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
434 Int# -> ByteArr# -> Word32#
437 #if WORD_SIZE_IN_BITS < 64
438 primop IntegerToInt64Op "integerToInt64#" GenPrimOp
439 Int# -> ByteArr# -> Int64#
441 primop IntegerToWord64Op "integerToWord64#" GenPrimOp
442 Int# -> ByteArr# -> Word64#
445 primop IntegerAndOp "andInteger#" GenPrimOp
446 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
447 with out_of_line = True
449 primop IntegerOrOp "orInteger#" GenPrimOp
450 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
451 with out_of_line = True
453 primop IntegerXorOp "xorInteger#" GenPrimOp
454 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
455 with out_of_line = True
457 primop IntegerComplementOp "complementInteger#" GenPrimOp
458 Int# -> ByteArr# -> (# Int#, ByteArr# #)
459 with out_of_line = True
462 ------------------------------------------------------------------------
464 {Operations on double-precision (64 bit) floating-point numbers.}
465 ------------------------------------------------------------------------
467 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
468 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
470 primop DoubleEqOp "==##" Compare
471 Double# -> Double# -> Bool
472 with commutable = True
474 primop DoubleNeOp "/=##" Compare
475 Double# -> Double# -> Bool
476 with commutable = True
478 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
479 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
481 primop DoubleAddOp "+##" Dyadic
482 Double# -> Double# -> Double#
483 with commutable = True
485 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
487 primop DoubleMulOp "*##" Dyadic
488 Double# -> Double# -> Double#
489 with commutable = True
491 primop DoubleDivOp "/##" Dyadic
492 Double# -> Double# -> Double#
495 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
497 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
498 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
500 primop DoubleExpOp "expDouble#" Monadic
502 with needs_wrapper = True
504 primop DoubleLogOp "logDouble#" Monadic
510 primop DoubleSqrtOp "sqrtDouble#" Monadic
512 with needs_wrapper = True
514 primop DoubleSinOp "sinDouble#" Monadic
516 with needs_wrapper = True
518 primop DoubleCosOp "cosDouble#" Monadic
520 with needs_wrapper = True
522 primop DoubleTanOp "tanDouble#" Monadic
524 with needs_wrapper = True
526 primop DoubleAsinOp "asinDouble#" Monadic
532 primop DoubleAcosOp "acosDouble#" Monadic
538 primop DoubleAtanOp "atanDouble#" Monadic
543 primop DoubleSinhOp "sinhDouble#" Monadic
545 with needs_wrapper = True
547 primop DoubleCoshOp "coshDouble#" Monadic
549 with needs_wrapper = True
551 primop DoubleTanhOp "tanhDouble#" Monadic
553 with needs_wrapper = True
555 primop DoublePowerOp "**##" Dyadic
556 Double# -> Double# -> Double#
558 with needs_wrapper = True
560 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
561 Double# -> (# Int#, Int#, ByteArr# #)
562 {Convert to arbitrary-precision integer.
563 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
564 holding the mantissa.}
565 with out_of_line = True
567 ------------------------------------------------------------------------
569 {Operations on single-precision (32-bit) floating-point numbers.}
570 ------------------------------------------------------------------------
572 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
573 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
575 primop FloatEqOp "eqFloat#" Compare
576 Float# -> Float# -> Bool
577 with commutable = True
579 primop FloatNeOp "neFloat#" Compare
580 Float# -> Float# -> Bool
581 with commutable = True
583 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
584 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
586 primop FloatAddOp "plusFloat#" Dyadic
587 Float# -> Float# -> Float#
588 with commutable = True
590 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
592 primop FloatMulOp "timesFloat#" Dyadic
593 Float# -> Float# -> Float#
594 with commutable = True
596 primop FloatDivOp "divideFloat#" Dyadic
597 Float# -> Float# -> Float#
600 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
602 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
604 primop FloatExpOp "expFloat#" Monadic
606 with needs_wrapper = True
608 primop FloatLogOp "logFloat#" Monadic
610 with needs_wrapper = True
613 primop FloatSqrtOp "sqrtFloat#" Monadic
615 with needs_wrapper = True
617 primop FloatSinOp "sinFloat#" Monadic
619 with needs_wrapper = True
621 primop FloatCosOp "cosFloat#" Monadic
623 with needs_wrapper = True
625 primop FloatTanOp "tanFloat#" Monadic
627 with needs_wrapper = True
629 primop FloatAsinOp "asinFloat#" Monadic
631 with needs_wrapper = True
634 primop FloatAcosOp "acosFloat#" Monadic
636 with needs_wrapper = True
639 primop FloatAtanOp "atanFloat#" Monadic
641 with needs_wrapper = True
643 primop FloatSinhOp "sinhFloat#" Monadic
645 with needs_wrapper = True
647 primop FloatCoshOp "coshFloat#" Monadic
649 with needs_wrapper = True
651 primop FloatTanhOp "tanhFloat#" Monadic
653 with needs_wrapper = True
655 primop FloatPowerOp "powerFloat#" Dyadic
656 Float# -> Float# -> Float#
657 with needs_wrapper = True
659 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
661 primop FloatDecodeOp "decodeFloat#" GenPrimOp
662 Float# -> (# Int#, Int#, ByteArr# #)
663 {Convert to arbitrary-precision integer.
664 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
665 holding the mantissa.}
666 with out_of_line = True
668 ------------------------------------------------------------------------
670 {Operations on Array\#.}
671 ------------------------------------------------------------------------
673 primop NewArrayOp "newArray#" GenPrimOp
674 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
675 {Create a new mutable array of specified size (in bytes),
676 in the specified state thread,
677 with each element containing the specified initial value.}
679 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
680 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
683 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
684 MutArr# s a -> MutArr# s a -> Bool
686 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
688 primop ReadArrayOp "readArray#" GenPrimOp
689 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
690 {Read from specified index of mutable array. Result is not yet evaluated.}
692 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
694 primop WriteArrayOp "writeArray#" GenPrimOp
695 MutArr# s a -> Int# -> a -> State# s -> State# s
696 {Write to specified index of mutable array.}
698 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
699 strictness = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
700 has_side_effects = True
702 primop IndexArrayOp "indexArray#" GenPrimOp
703 Array# a -> Int# -> (# a #)
704 {Read from specified index of immutable array. Result is packaged into
705 an unboxed singleton; the result itself is not yet evaluated.}
707 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
709 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
710 MutArr# s a -> State# s -> (# State# s, Array# a #)
711 {Make a mutable array immutable, without copying.}
713 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
714 has_side_effects = True
716 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
717 Array# a -> State# s -> (# State# s, MutArr# s a #)
718 {Make an immutable array mutable, without copying.}
720 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
723 ------------------------------------------------------------------------
724 section "Byte Arrays"
725 {Operations on ByteArray\#. A ByteArray\# is a just a region of
726 raw memory in the garbage-collected heap, which is not scanned
727 for pointers. It carries its own size (in bytes). There are
728 three sets of operations for accessing byte array contents:
729 index for reading from immutable byte arrays, and read/write
730 for mutable byte arrays. Each set contains operations for
731 a range of useful primitive data types. Each operation takes
732 an offset measured in terms of the size fo the primitive type
733 being read or written.}
735 ------------------------------------------------------------------------
737 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
738 Int# -> State# s -> (# State# s, MutByteArr# s #)
739 {Create a new mutable byte array of specified size (in bytes), in
740 the specified state thread.}
741 with out_of_line = True
743 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
744 Int# -> State# s -> (# State# s, MutByteArr# s #)
745 {Create a mutable byte array that the GC guarantees not to move.}
746 with out_of_line = True
748 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
750 {Intended for use with pinned arrays; otherwise very unsafe!}
752 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
753 MutByteArr# s -> MutByteArr# s -> Bool
755 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
756 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
757 {Make a mutable byte array immutable, without copying.}
759 has_side_effects = True
761 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
764 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
765 MutByteArr# s -> Int#
768 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
769 ByteArr# -> Int# -> Char#
770 {Read 8-bit character; offset in bytes.}
772 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
773 ByteArr# -> Int# -> Char#
774 {Read 31-bit character; offset in 4-byte words.}
776 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
777 ByteArr# -> Int# -> Int#
779 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
780 ByteArr# -> Int# -> Word#
782 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
783 ByteArr# -> Int# -> Addr#
785 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
786 ByteArr# -> Int# -> Float#
788 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
789 ByteArr# -> Int# -> Double#
791 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
792 ByteArr# -> Int# -> StablePtr# a
794 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
795 ByteArr# -> Int# -> Int#
797 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
798 ByteArr# -> Int# -> Int#
800 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
801 ByteArr# -> Int# -> INT32
803 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
804 ByteArr# -> Int# -> INT64
806 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
807 ByteArr# -> Int# -> Word#
809 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
810 ByteArr# -> Int# -> Word#
812 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
813 ByteArr# -> Int# -> WORD32
815 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
816 ByteArr# -> Int# -> WORD64
818 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
819 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
820 {Read 8-bit character; offset in bytes.}
822 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
823 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
824 {Read 31-bit character; offset in 4-byte words.}
826 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
827 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
829 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
830 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
832 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
833 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
835 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
836 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
838 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
839 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
841 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
842 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
844 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
845 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
847 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
848 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
850 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
851 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
853 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
854 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
856 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
857 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
859 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
860 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
862 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
863 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
865 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
866 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
868 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
869 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
870 {Write 8-bit character; offset in bytes.}
871 with has_side_effects = True
873 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
874 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
875 {Write 31-bit character; offset in 4-byte words.}
876 with has_side_effects = True
878 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
879 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
880 with has_side_effects = True
882 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
883 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
884 with has_side_effects = True
886 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
887 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
888 with has_side_effects = True
890 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
891 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
892 with has_side_effects = True
894 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
895 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
896 with has_side_effects = True
898 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
899 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
900 with has_side_effects = True
902 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
903 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
904 with has_side_effects = True
906 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
907 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
908 with has_side_effects = True
910 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
911 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
912 with has_side_effects = True
914 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
915 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
916 with has_side_effects = True
918 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
919 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
920 with has_side_effects = True
922 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
923 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
924 with has_side_effects = True
926 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
927 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
928 with has_side_effects = True
930 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
931 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
932 with has_side_effects = True
934 ------------------------------------------------------------------------
936 {Addr\# is an arbitrary machine address assumed to point outside
937 the garbage-collected heap.}
938 ------------------------------------------------------------------------
940 primop AddrNullOp "nullAddr#" GenPrimOp Int# -> Addr#
941 {Returns null address. Argument is ignored (nullary primops
943 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
944 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
945 {Result is meaningless if two Addr\#s are so far apart that their
946 difference doesn't fit in an Int\#.}
947 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
948 {Return the remainder when the Addr\# arg, treated like an Int\#,
949 is divided by the Int\# arg.}
950 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
951 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
952 {Coerce directly from address to int. Strongly deprecated.}
953 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
954 {Coerce directly from int to address. Strongly deprecated.}
957 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
958 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
959 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
960 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
961 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
962 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
964 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
965 Addr# -> Int# -> Char#
966 {Reads 8-bit character; offset in bytes.}
968 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
969 Addr# -> Int# -> Char#
970 {Reads 31-bit character; offset in 4-byte words.}
972 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
973 Addr# -> Int# -> Int#
975 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
976 Addr# -> Int# -> Word#
978 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
979 Addr# -> Int# -> Addr#
981 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
982 Addr# -> Int# -> Float#
984 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
985 Addr# -> Int# -> Double#
987 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
988 Addr# -> Int# -> StablePtr# a
990 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
991 Addr# -> Int# -> Int#
993 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
994 Addr# -> Int# -> Int#
996 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
997 Addr# -> Int# -> INT32
999 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1000 Addr# -> Int# -> INT64
1002 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1003 Addr# -> Int# -> Word#
1005 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1006 Addr# -> Int# -> Word#
1008 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1009 Addr# -> Int# -> WORD32
1011 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1012 Addr# -> Int# -> WORD64
1014 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1015 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1016 {Reads 8-bit character; offset in bytes.}
1018 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1019 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1020 {Reads 31-bit character; offset in 4-byte words.}
1022 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1023 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1025 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1026 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1028 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1029 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1031 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1032 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1034 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1035 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1037 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1038 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1040 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1041 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1043 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1044 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1046 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1047 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1049 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1050 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1052 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1053 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1055 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1056 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1058 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1059 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1061 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1062 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1065 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1066 Addr# -> Int# -> Char# -> State# s -> State# s
1067 with has_side_effects = True
1069 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1070 Addr# -> Int# -> Char# -> State# s -> State# s
1071 with has_side_effects = True
1073 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1074 Addr# -> Int# -> Int# -> State# s -> State# s
1075 with has_side_effects = True
1077 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1078 Addr# -> Int# -> Word# -> State# s -> State# s
1079 with has_side_effects = True
1081 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1082 Addr# -> Int# -> Addr# -> State# s -> State# s
1083 with has_side_effects = True
1085 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1086 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1087 with has_side_effects = True
1089 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1090 Addr# -> Int# -> Float# -> State# s -> State# s
1091 with has_side_effects = True
1093 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1094 Addr# -> Int# -> Double# -> State# s -> State# s
1095 with has_side_effects = True
1097 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1098 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1099 with has_side_effects = True
1101 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1102 Addr# -> Int# -> Int# -> State# s -> State# s
1103 with has_side_effects = True
1105 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1106 Addr# -> Int# -> Int# -> State# s -> State# s
1107 with has_side_effects = True
1109 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1110 Addr# -> Int# -> INT32 -> State# s -> State# s
1111 with has_side_effects = True
1113 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1114 Addr# -> Int# -> INT64 -> State# s -> State# s
1115 with has_side_effects = True
1117 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1118 Addr# -> Int# -> Word# -> State# s -> State# s
1119 with has_side_effects = True
1121 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1122 Addr# -> Int# -> Word# -> State# s -> State# s
1123 with has_side_effects = True
1125 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1126 Addr# -> Int# -> WORD32 -> State# s -> State# s
1127 with has_side_effects = True
1129 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1130 Addr# -> Int# -> WORD64 -> State# s -> State# s
1131 with has_side_effects = True
1133 ------------------------------------------------------------------------
1134 section "ForeignObj#"
1135 {Operations on ForeignObj\#. The indexing operations are
1137 ------------------------------------------------------------------------
1139 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1140 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1142 has_side_effects = True
1145 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1146 ForeignObj# -> Addr# -> State# s -> State# s
1148 has_side_effects = True
1150 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1151 ForeignObj# -> Addr#
1153 primop TouchOp "touch#" GenPrimOp
1154 o -> State# RealWorld -> State# RealWorld
1156 has_side_effects = True
1157 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1159 primop EqForeignObj "eqForeignObj#" GenPrimOp
1160 ForeignObj# -> ForeignObj# -> Bool
1161 with commutable = True
1163 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1164 ForeignObj# -> Int# -> Char#
1165 {Read 8-bit character; offset in bytes.}
1167 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1168 ForeignObj# -> Int# -> Char#
1169 {Read 31-bit character; offset in 4-byte words.}
1171 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1172 ForeignObj# -> Int# -> Int#
1174 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1175 ForeignObj# -> Int# -> Word#
1177 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1178 ForeignObj# -> Int# -> Addr#
1180 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1181 ForeignObj# -> Int# -> Float#
1183 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1184 ForeignObj# -> Int# -> Double#
1186 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1187 ForeignObj# -> Int# -> StablePtr# a
1189 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1190 ForeignObj# -> Int# -> Int#
1192 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1193 ForeignObj# -> Int# -> Int#
1195 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1196 ForeignObj# -> Int# -> INT32
1198 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1199 ForeignObj# -> Int# -> INT64
1201 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1202 ForeignObj# -> Int# -> Word#
1204 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1205 ForeignObj# -> Int# -> Word#
1207 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1208 ForeignObj# -> Int# -> WORD32
1210 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1211 ForeignObj# -> Int# -> WORD64
1215 ------------------------------------------------------------------------
1216 section "Mutable variables"
1217 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1218 ------------------------------------------------------------------------
1220 primop NewMutVarOp "newMutVar#" GenPrimOp
1221 a -> State# s -> (# State# s, MutVar# s a #)
1222 {Create MutVar\# with specified initial value in specified state thread.}
1224 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1225 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1228 primop ReadMutVarOp "readMutVar#" GenPrimOp
1229 MutVar# s a -> State# s -> (# State# s, a #)
1230 {Read contents of MutVar\#. Result is not yet evaluated.}
1232 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1234 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1235 MutVar# s a -> a -> State# s -> State# s
1236 {Write contents of MutVar\#.}
1238 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1239 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1240 has_side_effects = True
1242 primop SameMutVarOp "sameMutVar#" GenPrimOp
1243 MutVar# s a -> MutVar# s a -> Bool
1245 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1247 ------------------------------------------------------------------------
1248 section "Exceptions"
1249 ------------------------------------------------------------------------
1251 primop CatchOp "catch#" GenPrimOp
1252 (State# RealWorld -> (# State# RealWorld, a #) )
1253 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1255 -> (# State# RealWorld, a #)
1257 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
1258 -- Catch is actually strict in its first argument
1259 -- but we don't want to tell the strictness
1260 -- analyser about that!
1261 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1262 -- [mkO, mkO . (inFun mkM mkO)] mkO
1263 -- might use caught action multiply
1266 primop RaiseOp "raise#" GenPrimOp
1269 strictness = { \ arity -> StrictnessInfo [wwLazy] True }
1270 -- NB: True => result is bottom
1271 usage = { mangle RaiseOp [mkM] mkM }
1274 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1275 (State# RealWorld -> (# State# RealWorld, a #))
1276 -> (State# RealWorld -> (# State# RealWorld, a #))
1278 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1281 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1282 (State# RealWorld -> (# State# RealWorld, a #))
1283 -> (State# RealWorld -> (# State# RealWorld, a #))
1285 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1288 ------------------------------------------------------------------------
1289 section "Synchronized Mutable Variables"
1290 {Operations on MVar\#s, which are shared mutable variables
1291 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1292 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1293 ------------------------------------------------------------------------
1296 primop NewMVarOp "newMVar#" GenPrimOp
1297 State# s -> (# State# s, MVar# s a #)
1298 {Create new mvar; initially empty.}
1300 usage = { mangle NewMVarOp [mkP] mkR }
1303 primop TakeMVarOp "takeMVar#" GenPrimOp
1304 MVar# s a -> State# s -> (# State# s, a #)
1305 {If mvar is empty, block until it becomes full.
1306 Then remove and return its contents, and set it empty.}
1308 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1309 has_side_effects = True
1312 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1313 MVar# s a -> State# s -> (# State# s, Int#, a #)
1314 {If mvar is empty, immediately return with integer 0 and value undefined.
1315 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1317 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1318 has_side_effects = True
1321 primop PutMVarOp "putMVar#" GenPrimOp
1322 MVar# s a -> a -> State# s -> State# s
1323 {If mvar is full, block until it becomes empty.
1324 Then store value arg as its new contents.}
1326 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1327 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1328 has_side_effects = True
1331 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1332 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1333 {If mvar is full, immediately return with integer 0.
1334 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1336 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
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 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1393 has_side_effects = True
1396 primop KillThreadOp "killThread#" GenPrimOp
1397 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1399 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1400 has_side_effects = True
1403 primop YieldOp "yield#" GenPrimOp
1404 State# RealWorld -> State# RealWorld
1406 has_side_effects = True
1409 primop MyThreadIdOp "myThreadId#" GenPrimOp
1410 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1412 ------------------------------------------------------------------------
1413 section "Weak pointers"
1414 ------------------------------------------------------------------------
1416 -- note that tyvar "o" denotes openAlphaTyVar
1418 primop MkWeakOp "mkWeak#" GenPrimOp
1419 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1421 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
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
1432 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1433 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1434 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
1436 usage = { mangle FinalizeWeakOp [mkM, mkP]
1437 (mkR . (inUB FinalizeWeakOp
1438 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1439 has_side_effects = True
1442 ------------------------------------------------------------------------
1443 section "Stable pointers and names"
1444 ------------------------------------------------------------------------
1446 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1447 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1449 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1450 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1451 has_side_effects = True
1453 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1454 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1456 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1457 needs_wrapper = True
1458 has_side_effects = True
1460 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1461 StablePtr# a -> StablePtr# a -> Int#
1463 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1464 has_side_effects = True
1466 primop MakeStableNameOp "makeStableName#" GenPrimOp
1467 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1469 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1470 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1471 needs_wrapper = True
1472 has_side_effects = True
1475 primop EqStableNameOp "eqStableName#" GenPrimOp
1476 StableName# a -> StableName# a -> Int#
1478 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1480 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1481 StableName# a -> Int#
1483 usage = { mangle StableNameToIntOp [mkP] mkR }
1485 ------------------------------------------------------------------------
1486 section "Unsafe pointer equality"
1487 -- (#1 Bad Guy: Alistair Reid :)
1488 ------------------------------------------------------------------------
1490 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1493 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] 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 ------------------------------------------------------------------------