1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.9 2001/10/31 17:03:12 rrt Exp $
4 -- Primitive Operations
6 -----------------------------------------------------------------------
8 -- This file is processed by the utility program genprimopcode to produce
9 -- a number of include files within the compiler and optionally to produce
10 -- human-readable documentation.
12 -- It should first be preprocessed.
14 -- To add a new primop, you currently need to update the following files:
16 -- - this file (ghc/compiler/prelude/primops.txt.pp), which includes
17 -- the type of the primop, and various other properties (its
18 -- strictness attributes, whether it is defined as a macro
19 -- or as out-of-line code, etc.)
21 -- - ghc/lib/std/PrelGHC.hi-boot, to declare the primop
23 -- - if the primop is inline (i.e. a macro), then:
24 -- ghc/includes/PrimOps.h
25 -- ghc/compiler/nativeGen/StixPrim.lhs
26 -- ghc/compiler/nativeGen/MachCode.lhs (if implementation is machine-dependent)
28 -- - or, for an out-of-line primop:
29 -- ghc/includes/PrimOps.h (just add the declaration)
30 -- ghc/rts/PrimOps.hc (define it here)
35 -- This file is divided into named sections, each containing or more
36 -- primop entries. Section headers have the format:
38 -- section "section-name" {description}
40 -- This information is used solely when producing documentation; it is
41 -- otherwise ignored. The description is optional.
43 -- The format of each primop entry is as follows:
45 -- primop internal-name "name-in-program-text" type category {description} attributes
47 -- The default attribute values which apply if you don't specify
48 -- other ones. Attribute values can be True, False, or arbitrary
49 -- text between curly brackets. This is a kludge to enable
50 -- processors of this file to easily get hold of simple info
51 -- (eg, out_of_line), whilst avoiding parsing complex expressions
52 -- needed for strictness and usage info.
55 has_side_effects = False
60 strictness = { \ arity -> StrictnessInfo (replicate arity wwPrim) False }
61 usage = { nomangle other }
63 -- Currently, documentation is produced using latex, so contents of
64 -- description fields should be legal latex. Descriptions can contain
65 -- matched pairs of embedded curly brackets.
69 section "The word size story."
70 {Haskell98 specifies that signed integers (type {\tt Int})
71 must contain at least 30 bits. GHC always implements {\tt
72 Int} using the primitive type {\tt Int\#}, whose size equals
73 the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
74 This is normally set based on the {\tt config.h} parameter
75 {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
76 bits on 64-bit machines. However, it can also be explicitly
77 set to a smaller number, e.g., 31 bits, to allow the
78 possibility of using tag bits. Currently GHC itself has only
79 32-bit and 64-bit variants, but 30 or 31-bit code can be
80 exported as an external core file for use in other back ends.
82 GHC also implements a primitive unsigned integer type {\tt
83 Word\#} which always has the same number of bits as {\tt
86 In addition, GHC supports families of explicit-sized integers
87 and words at 8, 16, 32, and 64 bits, with the usual
88 arithmetic operations, comparisons, and a range of
89 conversions. The 8-bit and 16-bit sizes are always
90 represented as {\tt Int\#} and {\tt Word\#}, and the
91 operations implemented in terms of the the primops on these
92 types, with suitable range restrictions on the results (using
93 the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
94 of primops. The 32-bit sizes are represented using {\tt
95 Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
96 $\geq$ 32; otherwise, these are represented using distinct
97 primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
98 needed) have a complete set of corresponding operations;
99 however, nearly all of these are implemented as external C
100 functions rather than as primops. Exactly the same story
101 applies to the 64-bit sizes. All of these details are hidden
102 under the {\tt PrelInt} and {\tt PrelWord} modules, which use
103 {\tt \#if}-defs to invoke the appropriate types and
106 Word size also matters for the families of primops for
107 indexing/reading/writing fixed-size quantities at offsets
108 from an array base, address, or foreign pointer. Here, a
109 slightly different approach is taken. The names of these
110 primops are fixed, but their {\it types} vary according to
111 the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
112 size is at least 32 bits then an operator like
113 \texttt{indexInt32Array\#} has type {\tt ByteArr\# -> Int\#
114 -> Int\#}; otherwise it has type {\tt ByteArr\# -> Int\# ->
115 Int32\#}. This approach confines the necessary {\tt
116 \#if}-defs to this file; no conditional compilation is needed
117 in the files that expose these primops, namely
118 \texttt{lib/std/PrelStorable.lhs},
119 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated
120 fashion) in \texttt{hslibs/lang/ForeignObj.lhs} and
121 \texttt{hslibs/lang/Addr.lhs}.
123 Finally, there are strongly deprecated primops for coercing
124 between {\tt Addr\#}, the primitive type of machine
125 addresses, and {\tt Int\#}. These are pretty bogus anyway,
126 but will work on existing 32-bit and 64-bit GHC targets; they
127 are completely bogus when tag bits are used in {\tt Int\#},
128 so are not available in this case. }
130 -- Define synonyms for indexing ops.
132 #if WORD_SIZE_IN_BITS < 32
134 #define WORD32 Word32#
140 #if WORD_SIZE_IN_BITS < 64
142 #define WORD64 Word64#
148 ------------------------------------------------------------------------
150 {Operations on 31-bit characters.}
151 ------------------------------------------------------------------------
154 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
155 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
157 primop CharEqOp "eqChar#" Compare
158 Char# -> Char# -> Bool
159 with commutable = True
161 primop CharNeOp "neChar#" Compare
162 Char# -> Char# -> Bool
163 with commutable = True
165 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
166 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
168 primop OrdOp "ord#" GenPrimOp Char# -> Int#
170 ------------------------------------------------------------------------
172 {Operations on native-size integers (30+ bits).}
173 ------------------------------------------------------------------------
175 primop IntAddOp "+#" Dyadic
177 with commutable = True
179 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
182 Dyadic Int# -> Int# -> Int#
183 with commutable = True
185 primop IntQuotOp "quotInt#" Dyadic
187 {Rounds towards zero.}
190 primop IntRemOp "remInt#" Dyadic
192 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
195 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
196 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
357 For .NET these operations are implemented by foreign imports, so the
358 primops are omitted.}
359 ------------------------------------------------------------------------
363 primop IntegerAddOp "plusInteger#" GenPrimOp
364 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
365 with commutable = True
368 primop IntegerSubOp "minusInteger#" GenPrimOp
369 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
370 with out_of_line = True
372 primop IntegerMulOp "timesInteger#" GenPrimOp
373 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
374 with commutable = True
377 primop IntegerGcdOp "gcdInteger#" GenPrimOp
378 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
379 {Greatest common divisor.}
380 with commutable = True
383 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
384 Int# -> ByteArr# -> Int# -> Int#
385 {Greatest common divisor, where second argument is an ordinary Int\#.}
386 -- with commutable = True (surely not? APT 8/01)
388 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
389 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
390 {Divisor is guaranteed to be a factor of dividend.}
391 with out_of_line = True
393 primop IntegerQuotOp "quotInteger#" GenPrimOp
394 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
395 {Rounds towards zero.}
396 with out_of_line = True
398 primop IntegerRemOp "remInteger#" GenPrimOp
399 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
400 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
401 with out_of_line = True
403 primop IntegerCmpOp "cmpInteger#" GenPrimOp
404 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
405 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
406 with needs_wrapper = True
408 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
409 Int# -> ByteArr# -> Int# -> Int#
410 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
411 is an ordinary Int\#.}
412 with needs_wrapper = True
414 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
415 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
416 {Compute quot and rem simulaneously.}
420 primop IntegerDivModOp "divModInteger#" GenPrimOp
421 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
422 {Compute div and mod simultaneously, where div rounds towards negative infinity
423 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
427 primop Integer2IntOp "integer2Int#" GenPrimOp
428 Int# -> ByteArr# -> Int#
429 with needs_wrapper = True
431 primop Integer2WordOp "integer2Word#" GenPrimOp
432 Int# -> ByteArr# -> Word#
433 with needs_wrapper = True
435 #if WORD_SIZE_IN_BITS < 32
436 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
437 Int# -> ByteArr# -> Int32#
439 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
440 Int# -> ByteArr# -> Word32#
443 #if WORD_SIZE_IN_BITS < 64
444 primop IntegerToInt64Op "integerToInt64#" GenPrimOp
445 Int# -> ByteArr# -> Int64#
447 primop IntegerToWord64Op "integerToWord64#" GenPrimOp
448 Int# -> ByteArr# -> Word64#
451 primop IntegerAndOp "andInteger#" GenPrimOp
452 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
453 with out_of_line = True
455 primop IntegerOrOp "orInteger#" GenPrimOp
456 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
457 with out_of_line = True
459 primop IntegerXorOp "xorInteger#" GenPrimOp
460 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
461 with out_of_line = True
463 primop IntegerComplementOp "complementInteger#" GenPrimOp
464 Int# -> ByteArr# -> (# Int#, ByteArr# #)
465 with out_of_line = True
469 ------------------------------------------------------------------------
471 {Operations on double-precision (64 bit) floating-point numbers.}
472 ------------------------------------------------------------------------
474 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
475 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
477 primop DoubleEqOp "==##" Compare
478 Double# -> Double# -> Bool
479 with commutable = True
481 primop DoubleNeOp "/=##" Compare
482 Double# -> Double# -> Bool
483 with commutable = True
485 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
486 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
488 primop DoubleAddOp "+##" Dyadic
489 Double# -> Double# -> Double#
490 with commutable = True
492 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
494 primop DoubleMulOp "*##" Dyadic
495 Double# -> Double# -> Double#
496 with commutable = True
498 primop DoubleDivOp "/##" Dyadic
499 Double# -> Double# -> Double#
502 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
504 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
505 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
507 primop DoubleExpOp "expDouble#" Monadic
509 with needs_wrapper = True
511 primop DoubleLogOp "logDouble#" Monadic
517 primop DoubleSqrtOp "sqrtDouble#" Monadic
519 with needs_wrapper = True
521 primop DoubleSinOp "sinDouble#" Monadic
523 with needs_wrapper = True
525 primop DoubleCosOp "cosDouble#" Monadic
527 with needs_wrapper = True
529 primop DoubleTanOp "tanDouble#" Monadic
531 with needs_wrapper = True
533 primop DoubleAsinOp "asinDouble#" Monadic
539 primop DoubleAcosOp "acosDouble#" Monadic
545 primop DoubleAtanOp "atanDouble#" Monadic
550 primop DoubleSinhOp "sinhDouble#" Monadic
552 with needs_wrapper = True
554 primop DoubleCoshOp "coshDouble#" Monadic
556 with needs_wrapper = True
558 primop DoubleTanhOp "tanhDouble#" Monadic
560 with needs_wrapper = True
562 primop DoublePowerOp "**##" Dyadic
563 Double# -> Double# -> Double#
565 with needs_wrapper = True
567 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
568 Double# -> (# Int#, Int#, ByteArr# #)
569 {Convert to arbitrary-precision integer.
570 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
571 holding the mantissa.}
572 with out_of_line = True
574 ------------------------------------------------------------------------
576 {Operations on single-precision (32-bit) floating-point numbers.}
577 ------------------------------------------------------------------------
579 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
580 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
582 primop FloatEqOp "eqFloat#" Compare
583 Float# -> Float# -> Bool
584 with commutable = True
586 primop FloatNeOp "neFloat#" Compare
587 Float# -> Float# -> Bool
588 with commutable = True
590 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
591 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
593 primop FloatAddOp "plusFloat#" Dyadic
594 Float# -> Float# -> Float#
595 with commutable = True
597 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
599 primop FloatMulOp "timesFloat#" Dyadic
600 Float# -> Float# -> Float#
601 with commutable = True
603 primop FloatDivOp "divideFloat#" Dyadic
604 Float# -> Float# -> Float#
607 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
609 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
611 primop FloatExpOp "expFloat#" Monadic
613 with needs_wrapper = True
615 primop FloatLogOp "logFloat#" Monadic
617 with needs_wrapper = True
620 primop FloatSqrtOp "sqrtFloat#" Monadic
622 with needs_wrapper = True
624 primop FloatSinOp "sinFloat#" Monadic
626 with needs_wrapper = True
628 primop FloatCosOp "cosFloat#" Monadic
630 with needs_wrapper = True
632 primop FloatTanOp "tanFloat#" Monadic
634 with needs_wrapper = True
636 primop FloatAsinOp "asinFloat#" Monadic
638 with needs_wrapper = True
641 primop FloatAcosOp "acosFloat#" Monadic
643 with needs_wrapper = True
646 primop FloatAtanOp "atanFloat#" Monadic
648 with needs_wrapper = True
650 primop FloatSinhOp "sinhFloat#" Monadic
652 with needs_wrapper = True
654 primop FloatCoshOp "coshFloat#" Monadic
656 with needs_wrapper = True
658 primop FloatTanhOp "tanhFloat#" Monadic
660 with needs_wrapper = True
662 primop FloatPowerOp "powerFloat#" Dyadic
663 Float# -> Float# -> Float#
664 with needs_wrapper = True
666 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
668 primop FloatDecodeOp "decodeFloat#" GenPrimOp
669 Float# -> (# Int#, Int#, ByteArr# #)
670 {Convert to arbitrary-precision integer.
671 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
672 holding the mantissa.}
673 with out_of_line = True
675 ------------------------------------------------------------------------
677 {Operations on Array\#.}
678 ------------------------------------------------------------------------
680 primop NewArrayOp "newArray#" GenPrimOp
681 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
682 {Create a new mutable array of specified size (in bytes),
683 in the specified state thread,
684 with each element containing the specified initial value.}
686 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
687 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
690 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
691 MutArr# s a -> MutArr# s a -> Bool
693 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
695 primop ReadArrayOp "readArray#" GenPrimOp
696 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
697 {Read from specified index of mutable array. Result is not yet evaluated.}
699 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
701 primop WriteArrayOp "writeArray#" GenPrimOp
702 MutArr# s a -> Int# -> a -> State# s -> State# s
703 {Write to specified index of mutable array.}
705 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
706 strictness = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
707 has_side_effects = True
709 primop IndexArrayOp "indexArray#" GenPrimOp
710 Array# a -> Int# -> (# a #)
711 {Read from specified index of immutable array. Result is packaged into
712 an unboxed singleton; the result itself is not yet evaluated.}
714 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
716 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
717 MutArr# s a -> State# s -> (# State# s, Array# a #)
718 {Make a mutable array immutable, without copying.}
720 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
721 has_side_effects = True
723 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
724 Array# a -> State# s -> (# State# s, MutArr# s a #)
725 {Make an immutable array mutable, without copying.}
727 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
730 ------------------------------------------------------------------------
731 section "Byte Arrays"
732 {Operations on ByteArray\#. A ByteArray\# is a just a region of
733 raw memory in the garbage-collected heap, which is not scanned
734 for pointers. It carries its own size (in bytes). There are
735 three sets of operations for accessing byte array contents:
736 index for reading from immutable byte arrays, and read/write
737 for mutable byte arrays. Each set contains operations for
738 a range of useful primitive data types. Each operation takes
739 an offset measured in terms of the size fo the primitive type
740 being read or written.}
742 ------------------------------------------------------------------------
744 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
745 Int# -> State# s -> (# State# s, MutByteArr# s #)
746 {Create a new mutable byte array of specified size (in bytes), in
747 the specified state thread.}
748 with out_of_line = True
750 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
751 Int# -> State# s -> (# State# s, MutByteArr# s #)
752 {Create a mutable byte array that the GC guarantees not to move.}
753 with out_of_line = True
755 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
757 {Intended for use with pinned arrays; otherwise very unsafe!}
759 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
760 MutByteArr# s -> MutByteArr# s -> Bool
762 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
763 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
764 {Make a mutable byte array immutable, without copying.}
766 has_side_effects = True
768 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
771 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
772 MutByteArr# s -> Int#
775 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
776 ByteArr# -> Int# -> Char#
777 {Read 8-bit character; offset in bytes.}
779 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
780 ByteArr# -> Int# -> Char#
781 {Read 31-bit character; offset in 4-byte words.}
783 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
784 ByteArr# -> Int# -> Int#
786 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
787 ByteArr# -> Int# -> Word#
789 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
790 ByteArr# -> Int# -> Addr#
792 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
793 ByteArr# -> Int# -> Float#
795 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
796 ByteArr# -> Int# -> Double#
798 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
799 ByteArr# -> Int# -> StablePtr# a
801 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
802 ByteArr# -> Int# -> Int#
804 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
805 ByteArr# -> Int# -> Int#
807 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
808 ByteArr# -> Int# -> INT32
810 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
811 ByteArr# -> Int# -> INT64
813 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
814 ByteArr# -> Int# -> Word#
816 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
817 ByteArr# -> Int# -> Word#
819 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
820 ByteArr# -> Int# -> WORD32
822 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
823 ByteArr# -> Int# -> WORD64
825 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
826 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
827 {Read 8-bit character; offset in bytes.}
829 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
830 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
831 {Read 31-bit character; offset in 4-byte words.}
833 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
834 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
836 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
837 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
839 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
840 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
842 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
843 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
845 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
846 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
848 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
849 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
851 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
852 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
854 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
855 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
857 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
858 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
860 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
861 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
863 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
864 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
866 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
867 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
869 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
870 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
872 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
873 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
875 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
876 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
877 {Write 8-bit character; offset in bytes.}
878 with has_side_effects = True
880 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
881 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
882 {Write 31-bit character; offset in 4-byte words.}
883 with has_side_effects = True
885 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
886 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
887 with has_side_effects = True
889 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
890 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
891 with has_side_effects = True
893 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
894 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
895 with has_side_effects = True
897 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
898 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
899 with has_side_effects = True
901 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
902 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
903 with has_side_effects = True
905 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
906 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
907 with has_side_effects = True
909 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
910 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
911 with has_side_effects = True
913 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
914 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
915 with has_side_effects = True
917 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
918 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
919 with has_side_effects = True
921 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
922 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
923 with has_side_effects = True
925 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
926 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
927 with has_side_effects = True
929 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
930 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
931 with has_side_effects = True
933 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
934 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
935 with has_side_effects = True
937 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
938 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
939 with has_side_effects = True
941 ------------------------------------------------------------------------
943 {Addr\# is an arbitrary machine address assumed to point outside
944 the garbage-collected heap.
946 NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
947 It is the null address.}
948 ------------------------------------------------------------------------
950 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
951 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
952 {Result is meaningless if two Addr\#s are so far apart that their
953 difference doesn't fit in an Int\#.}
954 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
955 {Return the remainder when the Addr\# arg, treated like an Int\#,
956 is divided by the Int\# arg.}
957 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
958 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
959 {Coerce directly from address to int. Strongly deprecated.}
960 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
961 {Coerce directly from int to address. Strongly deprecated.}
964 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
965 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
966 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
967 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
968 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
969 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
971 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
972 Addr# -> Int# -> Char#
973 {Reads 8-bit character; offset in bytes.}
975 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
976 Addr# -> Int# -> Char#
977 {Reads 31-bit character; offset in 4-byte words.}
979 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
980 Addr# -> Int# -> Int#
982 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
983 Addr# -> Int# -> Word#
985 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
986 Addr# -> Int# -> Addr#
988 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
989 Addr# -> Int# -> Float#
991 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
992 Addr# -> Int# -> Double#
994 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
995 Addr# -> Int# -> StablePtr# a
997 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
998 Addr# -> Int# -> Int#
1000 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1001 Addr# -> Int# -> Int#
1003 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1004 Addr# -> Int# -> INT32
1006 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1007 Addr# -> Int# -> INT64
1009 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1010 Addr# -> Int# -> Word#
1012 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1013 Addr# -> Int# -> Word#
1015 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1016 Addr# -> Int# -> WORD32
1018 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1019 Addr# -> Int# -> WORD64
1021 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1022 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1023 {Reads 8-bit character; offset in bytes.}
1025 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1026 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1027 {Reads 31-bit character; offset in 4-byte words.}
1029 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1030 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1032 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1033 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1035 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1036 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1038 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1039 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1041 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1042 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1044 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1045 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1047 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1048 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1050 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1051 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1053 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1054 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1056 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1057 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1059 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1060 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1062 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1063 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1065 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1066 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1068 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1069 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1072 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1073 Addr# -> Int# -> Char# -> State# s -> State# s
1074 with has_side_effects = True
1076 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1077 Addr# -> Int# -> Char# -> State# s -> State# s
1078 with has_side_effects = True
1080 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1081 Addr# -> Int# -> Int# -> State# s -> State# s
1082 with has_side_effects = True
1084 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1085 Addr# -> Int# -> Word# -> State# s -> State# s
1086 with has_side_effects = True
1088 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1089 Addr# -> Int# -> Addr# -> State# s -> State# s
1090 with has_side_effects = True
1092 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1093 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1094 with has_side_effects = True
1096 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1097 Addr# -> Int# -> Float# -> State# s -> State# s
1098 with has_side_effects = True
1100 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1101 Addr# -> Int# -> Double# -> State# s -> State# s
1102 with has_side_effects = True
1104 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1105 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1106 with has_side_effects = True
1108 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1109 Addr# -> Int# -> Int# -> State# s -> State# s
1110 with has_side_effects = True
1112 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1113 Addr# -> Int# -> Int# -> State# s -> State# s
1114 with has_side_effects = True
1116 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1117 Addr# -> Int# -> INT32 -> State# s -> State# s
1118 with has_side_effects = True
1120 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1121 Addr# -> Int# -> INT64 -> State# s -> State# s
1122 with has_side_effects = True
1124 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1125 Addr# -> Int# -> Word# -> State# s -> State# s
1126 with has_side_effects = True
1128 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1129 Addr# -> Int# -> Word# -> State# s -> State# s
1130 with has_side_effects = True
1132 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1133 Addr# -> Int# -> WORD32 -> State# s -> State# s
1134 with has_side_effects = True
1136 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1137 Addr# -> Int# -> WORD64 -> State# s -> State# s
1138 with has_side_effects = True
1140 ------------------------------------------------------------------------
1141 section "ForeignObj#"
1142 {Operations on ForeignObj\#. The indexing operations are
1144 ------------------------------------------------------------------------
1146 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1147 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1149 has_side_effects = True
1152 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1153 ForeignObj# -> Addr# -> State# s -> State# s
1155 has_side_effects = True
1157 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1158 ForeignObj# -> Addr#
1160 primop TouchOp "touch#" GenPrimOp
1161 o -> State# RealWorld -> State# RealWorld
1163 has_side_effects = True
1164 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
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 }
1232 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1235 primop ReadMutVarOp "readMutVar#" GenPrimOp
1236 MutVar# s a -> State# s -> (# State# s, a #)
1237 {Read contents of MutVar\#. Result is not yet evaluated.}
1239 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1241 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1242 MutVar# s a -> a -> State# s -> State# s
1243 {Write contents of MutVar\#.}
1245 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1246 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1247 has_side_effects = True
1249 primop SameMutVarOp "sameMutVar#" GenPrimOp
1250 MutVar# s a -> MutVar# s a -> Bool
1252 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1254 ------------------------------------------------------------------------
1255 section "Exceptions"
1256 ------------------------------------------------------------------------
1258 primop CatchOp "catch#" GenPrimOp
1259 (State# RealWorld -> (# State# RealWorld, a #) )
1260 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1262 -> (# State# RealWorld, a #)
1264 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
1265 -- Catch is actually strict in its first argument
1266 -- but we don't want to tell the strictness
1267 -- analyser about that!
1268 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1269 -- [mkO, mkO . (inFun mkM mkO)] mkO
1270 -- might use caught action multiply
1273 primop RaiseOp "raise#" GenPrimOp
1276 strictness = { \ arity -> StrictnessInfo [wwLazy] True }
1277 -- NB: True => result is bottom
1278 usage = { mangle RaiseOp [mkM] mkM }
1281 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1282 (State# RealWorld -> (# State# RealWorld, a #))
1283 -> (State# RealWorld -> (# State# RealWorld, a #))
1285 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1288 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1289 (State# RealWorld -> (# State# RealWorld, a #))
1290 -> (State# RealWorld -> (# State# RealWorld, a #))
1292 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1295 ------------------------------------------------------------------------
1296 section "Synchronized Mutable Variables"
1297 {Operations on MVar\#s, which are shared mutable variables
1298 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1299 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1300 ------------------------------------------------------------------------
1303 primop NewMVarOp "newMVar#" GenPrimOp
1304 State# s -> (# State# s, MVar# s a #)
1305 {Create new mvar; initially empty.}
1307 usage = { mangle NewMVarOp [mkP] mkR }
1310 primop TakeMVarOp "takeMVar#" GenPrimOp
1311 MVar# s a -> State# s -> (# State# s, a #)
1312 {If mvar is empty, block until it becomes full.
1313 Then remove and return its contents, and set it empty.}
1315 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1316 has_side_effects = True
1319 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1320 MVar# s a -> State# s -> (# State# s, Int#, a #)
1321 {If mvar is empty, immediately return with integer 0 and value undefined.
1322 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1324 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1325 has_side_effects = True
1328 primop PutMVarOp "putMVar#" GenPrimOp
1329 MVar# s a -> a -> State# s -> State# s
1330 {If mvar is full, block until it becomes empty.
1331 Then store value arg as its new contents.}
1333 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1334 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1335 has_side_effects = True
1338 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1339 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1340 {If mvar is full, immediately return with integer 0.
1341 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1343 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1344 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1345 has_side_effects = True
1348 primop SameMVarOp "sameMVar#" GenPrimOp
1349 MVar# s a -> MVar# s a -> Bool
1351 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1353 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1354 MVar# s a -> State# s -> (# State# s, Int# #)
1355 {Return 1 if mvar is empty; 0 otherwise.}
1357 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1360 ------------------------------------------------------------------------
1361 section "Delay/wait operations"
1362 ------------------------------------------------------------------------
1364 primop DelayOp "delay#" GenPrimOp
1365 Int# -> State# s -> State# s
1366 {Sleep specified number of microseconds.}
1368 needs_wrapper = True
1369 has_side_effects = True
1372 primop WaitReadOp "waitRead#" GenPrimOp
1373 Int# -> State# s -> State# s
1374 {Block until input is available on specified file descriptor.}
1376 needs_wrapper = True
1377 has_side_effects = True
1380 primop WaitWriteOp "waitWrite#" GenPrimOp
1381 Int# -> State# s -> State# s
1382 {Block until output is possible on specified file descriptor.}
1384 needs_wrapper = True
1385 has_side_effects = True
1388 ------------------------------------------------------------------------
1389 section "Concurrency primitives"
1390 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1391 type, whose (unique) value is returned by myThreadId\#. The
1392 other operations can be omitted.)}
1393 ------------------------------------------------------------------------
1395 primop ForkOp "fork#" GenPrimOp
1396 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1398 usage = { mangle ForkOp [mkO, mkP] mkR }
1399 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1400 has_side_effects = True
1403 primop KillThreadOp "killThread#" GenPrimOp
1404 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1406 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1407 has_side_effects = True
1410 primop YieldOp "yield#" GenPrimOp
1411 State# RealWorld -> State# RealWorld
1413 has_side_effects = True
1416 primop MyThreadIdOp "myThreadId#" GenPrimOp
1417 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1419 ------------------------------------------------------------------------
1420 section "Weak pointers"
1421 ------------------------------------------------------------------------
1423 -- note that tyvar "o" denotes openAlphaTyVar
1425 primop MkWeakOp "mkWeak#" GenPrimOp
1426 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1428 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
1429 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1430 has_side_effects = True
1433 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1434 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1436 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1437 has_side_effects = True
1439 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1440 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1441 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
1443 usage = { mangle FinalizeWeakOp [mkM, mkP]
1444 (mkR . (inUB FinalizeWeakOp
1445 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1446 has_side_effects = True
1449 ------------------------------------------------------------------------
1450 section "Stable pointers and names"
1451 ------------------------------------------------------------------------
1453 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1454 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1456 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1457 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1458 has_side_effects = True
1460 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1461 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1463 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1464 needs_wrapper = True
1465 has_side_effects = True
1467 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1468 StablePtr# a -> StablePtr# a -> Int#
1470 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1471 has_side_effects = True
1473 primop MakeStableNameOp "makeStableName#" GenPrimOp
1474 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1476 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1477 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1478 needs_wrapper = True
1479 has_side_effects = True
1482 primop EqStableNameOp "eqStableName#" GenPrimOp
1483 StableName# a -> StableName# a -> Int#
1485 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1487 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1488 StableName# a -> Int#
1490 usage = { mangle StableNameToIntOp [mkP] mkR }
1492 ------------------------------------------------------------------------
1493 section "Unsafe pointer equality"
1494 -- (#1 Bad Guy: Alistair Reid :)
1495 ------------------------------------------------------------------------
1497 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1500 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
1502 ------------------------------------------------------------------------
1503 section "Parallelism"
1504 ------------------------------------------------------------------------
1506 primop SeqOp "seq#" GenPrimOp
1509 usage = { mangle SeqOp [mkO] mkR }
1510 strictness = { \ arity -> StrictnessInfo [wwStrict] False }
1511 -- Seq is strict in its argument; see notes in ConFold.lhs
1512 has_side_effects = True
1514 primop ParOp "par#" GenPrimOp
1517 usage = { mangle ParOp [mkO] mkR }
1518 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1519 -- Note that Par is lazy to avoid that the sparked thing
1520 -- gets evaluted strictly, which it should *not* be
1521 has_side_effects = True
1523 -- HWL: The first 4 Int# in all par... annotations denote:
1524 -- name, granularity info, size of result, degree of parallelism
1525 -- Same structure as _seq_ i.e. returns Int#
1526 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1527 -- `the processor containing the expression v'; it is not evaluated
1529 primop ParGlobalOp "parGlobal#" GenPrimOp
1530 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1532 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1533 has_side_effects = True
1535 primop ParLocalOp "parLocal#" GenPrimOp
1536 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1538 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1539 has_side_effects = True
1541 primop ParAtOp "parAt#" GenPrimOp
1542 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1544 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1545 has_side_effects = True
1547 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1548 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1550 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1551 has_side_effects = True
1553 primop ParAtRelOp "parAtRel#" GenPrimOp
1554 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1556 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1557 has_side_effects = True
1559 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1560 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1562 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1563 has_side_effects = True
1565 -- copyable# and noFollow# are yet to be implemented (for GpH)
1567 --primop CopyableOp "copyable#" GenPrimOp
1570 -- usage = { mangle CopyableOp [mkZ] mkR }
1571 -- has_side_effects = True
1573 --primop NoFollowOp "noFollow#" GenPrimOp
1576 -- usage = { mangle NoFollowOp [mkZ] mkR }
1577 -- has_side_effects = True
1580 ------------------------------------------------------------------------
1581 section "Tag to enum stuff"
1582 {Convert back and forth between values of enumerated types
1583 and small integers.}
1584 ------------------------------------------------------------------------
1586 primop DataToTagOp "dataToTag#" GenPrimOp
1589 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1591 primop TagToEnumOp "tagToEnum#" GenPrimOp
1594 ------------------------------------------------------------------------
1595 section "Bytecode operations"
1596 {Support for the bytecode interpreter and linker.}
1597 ------------------------------------------------------------------------
1600 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1602 {Convert an Addr\# to a followable type.}
1604 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1609 primop NewBCOOp "newBCO#" GenPrimOp
1610 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
1612 has_side_effects = True
1615 ------------------------------------------------------------------------
1617 {{\tt unsafeCoerce# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1619 ------------------------------------------------------------------------
1622 ------------------------------------------------------------------------
1624 ------------------------------------------------------------------------