1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.5 2001/08/31 15:28:49 apt 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 primop entries.
36 -- Section headers have the format:
38 -- section "section-name" {description}
40 -- This information is used solely when producing documentation; it is otherwise ignored.
41 -- 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 description is optional.
49 -- The default attribute values which apply if you don't specify
50 -- other ones. Attribute values can be True, False, or arbitrary
51 -- text between curly brackets. This is a kludge to enable
52 -- processors of this file to easily get hold of simple info
53 -- (eg, out_of_line), whilst avoiding parsing complex expressions
54 -- needed for strictness and usage info.
57 has_side_effects = False
62 strictness = { \ arity -> StrictnessInfo (replicate arity wwPrim) False }
63 usage = { nomangle other }
65 -- Currently, documentation is produced using latex, so contents of description fields
66 -- should be legal latex. Descriptions can contain matched pairs of embedded curly brackets.
70 section "The word size story."
71 {Haskell98 specifies that signed integers (type {\tt Int}) must contain at least 30
72 bits. GHC always implements {\tt Int} using the primitive type {\tt Int\#}, whose
73 size equals the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}. This
74 is normally set based on the {\tt config.h} parameter {\tt SIZEOF\_LONG},
75 i.e., 32 bits on 32-bit machines, 64 bits on 64-bit machines. However, it can
76 also be explicitly set to a smaller number, e.g., 31 bits, to allow the possibility
77 of using tag bits. Currently GHC itself has only 32-bit and 64-bit variants,
78 but 30 or 31-bit code can be exported as an external core file for use in
81 GHC also implements a primitive unsigned integer type {\tt Word\#} which always
82 has the same number of bits as {\tt Int\#}.
84 In addition, GHC supports families of explicit-sized integers and words at
85 8, 16, 32, and 64 bits, with the usual arithmetic operations, comparisons,
86 and a range of conversions. The 8-bit and 16-bit sizes are always represented as
87 {\tt Int\#} and {\tt Word\#}, and the operations implemented in terms of the
88 the primops on these types, with suitable range restrictions on the results
89 (using the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families of primops.
90 The 32-bit sizes are represented using {\tt Int\#} and {\tt Word\#} when
91 {\tt WORD\_SIZE\_IN\_BITS} $\geq$ 32;
92 otherwise, these are represented using distinct primitive types {\tt Int32\#}
93 and {\tt Word32\#}. These (when needed) have a complete set of corresponding
94 operations; however, nearly all of these are implemented as external C functions
95 rather than as primops. Exactly the same story applies to the 64-bit sizes.
96 All of these details are hidden under the {\tt PrelInt} and {\tt PrelWord} modules,
97 which use {\tt \#if}-defs to invoke the appropriate types and operators.
99 Word size also matters for the families of primops
100 for indexing/reading/writing fixed-size quantities at offsets from
101 an array base, address, or foreign pointer. Here, a slightly different approach is taken.
102 The names of these primops are fixed, but their
103 {\it types} vary according to the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if
104 word size is at least 32 bits then an operator like \texttt{indexInt32Array\#}
105 has type {\tt ByteArr\# -> Int\# -> Int\#}; otherwise it has type
106 {\tt ByteArr\# -> Int\# -> Int32\#}. This approach confines the necessary {\tt \#if}-defs to this file;
107 no conditional compilation is needed in the files that expose these primops, namely \texttt{lib/std/PrelStorable.lhs},
108 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated fashion) in \texttt{hslibs/lang/ForeignObj.lhs}
109 and \texttt{hslibs/lang/Addr.lhs}.
111 Finally, there are strongly deprecated primops for coercing between {\tt Addr\#}, the primitive
112 type of machine addresses, and {\tt Int\#}. These are pretty bogus anyway, but will work on
113 existing 32-bit and 64-bit GHC targets; they are completely bogus when tag bits are used in
114 {\tt Int\#}, so are not available in this case.
117 -- Define synonyms for indexing ops.
119 #if WORD_SIZE_IN_BITS < 32
121 #define WORD32 Word32#
127 #if WORD_SIZE_IN_BITS < 64
129 #define WORD64 Word64#
135 ------------------------------------------------------------------------
137 {Operations on 31-bit characters.}
138 ------------------------------------------------------------------------
141 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
142 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
144 primop CharEqOp "eqChar#" Compare
145 Char# -> Char# -> Bool
146 with commutable = True
148 primop CharNeOp "neChar#" Compare
149 Char# -> Char# -> Bool
150 with commutable = True
152 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
153 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
155 primop OrdOp "ord#" GenPrimOp Char# -> Int#
157 ------------------------------------------------------------------------
159 {Operations on native-size integers (30+ bits).}
160 ------------------------------------------------------------------------
162 primop IntAddOp "+#" Dyadic
164 with commutable = True
166 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
169 Dyadic Int# -> Int# -> Int#
170 with commutable = True
172 primop IntQuotOp "quotInt#" Dyadic
174 {Rounds towards zero.}
177 primop IntRemOp "remInt#" Dyadic
179 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
182 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
183 primop IntNegOp "negateInt#" Monadic Int# -> Int#
184 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
185 {Add with carry. First member of result is (wrapped) sum; second member is 0 iff no overflow occured.}
186 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
187 {Subtract with carry. First member of result is (wrapped) difference; second member is 0 iff no overflow occured.}
188 primop IntMulCOp "mulIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
189 {Multiply with carry. First member of result is (wrapped) product; second member is 0 iff no overflow occured.}
190 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
191 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
193 primop IntEqOp "==#" Compare
195 with commutable = True
197 primop IntNeOp "/=#" Compare
199 with commutable = True
201 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
202 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
204 primop ChrOp "chr#" GenPrimOp Int# -> Char#
206 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
207 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
208 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
210 primop Int2IntegerOp "int2Integer#"
211 GenPrimOp Int# -> (# Int#, ByteArr# #)
212 with out_of_line = True
214 primop ISllOp "iShiftL#" GenPrimOp Int# -> Int# -> Int#
215 {Shift left. Return 0 if shifted by more than size of an Int\#.}
216 primop ISraOp "iShiftRA#" GenPrimOp Int# -> Int# -> Int#
217 {Shift right arithemetic. Return 0 if shifted by more than size of an Int\#.}
218 primop ISrlOp "iShiftRL#" GenPrimOp Int# -> Int# -> Int#
219 {Shift right logical. Return 0 if shifted by more than size of an Int\#.}
221 ------------------------------------------------------------------------
223 {Operations on native-sized unsigned words (30+ bits).}
224 ------------------------------------------------------------------------
226 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
227 with commutable = True
229 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
231 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
232 with commutable = True
234 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
237 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
240 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
241 with commutable = True
243 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
244 with commutable = True
246 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
247 with commutable = True
249 primop NotOp "not#" Monadic Word# -> Word#
251 primop SllOp "shiftL#" GenPrimOp Word# -> Int# -> Word#
252 {Shift left logical. Return 0 if shifted by more than number of bits in a Word\#.}
253 primop SrlOp "shiftRL#" GenPrimOp Word# -> Int# -> Word#
254 {Shift right logical. Return 0 if shifted by more than number of bits in a Word\#.}
256 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
258 primop Word2IntegerOp "word2Integer#" GenPrimOp
259 Word# -> (# Int#, ByteArr# #)
260 with out_of_line = True
262 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
263 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
264 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
265 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
266 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
267 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
269 ------------------------------------------------------------------------
271 {Explicit narrowing of native-sized ints or words.}
272 ------------------------------------------------------------------------
274 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
275 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
276 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
277 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
278 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
279 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
282 #if WORD_SIZE_IN_BITS < 32
283 ------------------------------------------------------------------------
285 {Operations on 32-bit integers (Int32\#). This type is only used
286 if plain Int\# has less than 32 bits. In any case, the operations
287 are not primops; they are implemented (if needed) as ccalls instead.}
288 ------------------------------------------------------------------------
290 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
291 Int32# -> (# Int#, ByteArr# #)
292 with out_of_line = True
295 ------------------------------------------------------------------------
297 {Operations on 32-bit unsigned words. This type is only used
298 if plain Word\# has less than 32 bits. In any case, the operations
299 are not primops; they are implemented (if needed) as ccalls instead.}
300 ------------------------------------------------------------------------
302 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
303 Word32# -> (# Int#, ByteArr# #)
304 with out_of_line = True
310 #if WORD_SIZE_IN_BITS < 64
311 ------------------------------------------------------------------------
313 {Operations on 64-bit unsigned words. This type is only used
314 if plain Int\# has less than 64 bits. In any case, the operations
315 are not primops; they are implemented (if needed) as ccalls instead.}
316 ------------------------------------------------------------------------
318 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
319 Int64# -> (# Int#, ByteArr# #)
320 with out_of_line = True
322 ------------------------------------------------------------------------
324 {Operations on 64-bit unsigned words. This type is only used
325 if plain Word\# has less than 64 bits. In any case, the operations
326 are not primops; they are implemented (if needed) as ccalls instead.}
327 ------------------------------------------------------------------------
329 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
330 Word64# -> (# Int#, ByteArr# #)
331 with out_of_line = True
335 ------------------------------------------------------------------------
337 {Operations on arbitrary-precision integers. These operations are
338 implemented via the GMP package. An integer is represented as a pair
339 consisting of an Int\# representing the number of 'limbs' in use and
340 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
341 are returned as unboxed pairs, but must be passed as separate components.}
342 ------------------------------------------------------------------------
344 primop IntegerAddOp "plusInteger#" GenPrimOp
345 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
346 with commutable = True
349 primop IntegerSubOp "minusInteger#" GenPrimOp
350 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
351 with out_of_line = True
353 primop IntegerMulOp "timesInteger#" GenPrimOp
354 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
355 with commutable = True
358 primop IntegerGcdOp "gcdInteger#" GenPrimOp
359 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
360 {Greatest common divisor.}
361 with commutable = True
364 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
365 Int# -> ByteArr# -> Int# -> Int#
366 {Greatest common divisor, where second argument is an ordinary Int\#.}
367 -- with commutable = True (surely not? APT 8/01)
369 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
370 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
371 {Divisor is guaranteed to be a factor of dividend.}
372 with out_of_line = True
374 primop IntegerQuotOp "quotInteger#" GenPrimOp
375 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
376 {Rounds towards zero.}
377 with out_of_line = True
379 primop IntegerRemOp "remInteger#" GenPrimOp
380 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
381 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
382 with out_of_line = True
384 primop IntegerCmpOp "cmpInteger#" GenPrimOp
385 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
386 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
387 with needs_wrapper = True
389 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
390 Int# -> ByteArr# -> Int# -> Int#
391 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
392 is an ordinary Int\#.}
393 with needs_wrapper = True
395 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
396 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
397 {Compute quot and rem simulaneously.}
401 primop IntegerDivModOp "divModInteger#" GenPrimOp
402 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
403 {Compute div and mod simultaneously, where div rounds towards negative infinity
404 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
408 primop Integer2IntOp "integer2Int#" GenPrimOp
409 Int# -> ByteArr# -> Int#
410 with needs_wrapper = True
412 primop Integer2WordOp "integer2Word#" GenPrimOp
413 Int# -> ByteArr# -> Word#
414 with needs_wrapper = True
416 #if WORD_SIZE_IN_BITS < 32
417 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
418 Int# -> ByteArr# -> Int32#
420 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
421 Int# -> ByteArr# -> Word32#
424 #if WORD_SIZE_IN_BITS < 64
425 primop IntegerToInt64Op "integerToInt64#" GenPrimOp
426 Int# -> ByteArr# -> Int64#
428 primop IntegerToWord64Op "integerToWord64#" GenPrimOp
429 Int# -> ByteArr# -> Word64#
432 primop IntegerAndOp "andInteger#" GenPrimOp
433 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
434 with out_of_line = True
436 primop IntegerOrOp "orInteger#" GenPrimOp
437 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
438 with out_of_line = True
440 primop IntegerXorOp "xorInteger#" GenPrimOp
441 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
442 with out_of_line = True
444 primop IntegerComplementOp "complementInteger#" GenPrimOp
445 Int# -> ByteArr# -> (# Int#, ByteArr# #)
446 with out_of_line = True
449 ------------------------------------------------------------------------
451 {Operations on double-precision (64 bit) floating-point numbers.}
452 ------------------------------------------------------------------------
454 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
455 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
457 primop DoubleEqOp "==##" Compare
458 Double# -> Double# -> Bool
459 with commutable = True
461 primop DoubleNeOp "/=##" Compare
462 Double# -> Double# -> Bool
463 with commutable = True
465 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
466 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
468 primop DoubleAddOp "+##" Dyadic
469 Double# -> Double# -> Double#
470 with commutable = True
472 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
474 primop DoubleMulOp "*##" Dyadic
475 Double# -> Double# -> Double#
476 with commutable = True
478 primop DoubleDivOp "/##" Dyadic
479 Double# -> Double# -> Double#
482 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
484 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
485 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
487 primop DoubleExpOp "expDouble#" Monadic
489 with needs_wrapper = True
491 primop DoubleLogOp "logDouble#" Monadic
497 primop DoubleSqrtOp "sqrtDouble#" Monadic
499 with needs_wrapper = True
501 primop DoubleSinOp "sinDouble#" Monadic
503 with needs_wrapper = True
505 primop DoubleCosOp "cosDouble#" Monadic
507 with needs_wrapper = True
509 primop DoubleTanOp "tanDouble#" Monadic
511 with needs_wrapper = True
513 primop DoubleAsinOp "asinDouble#" Monadic
519 primop DoubleAcosOp "acosDouble#" Monadic
525 primop DoubleAtanOp "atanDouble#" Monadic
530 primop DoubleSinhOp "sinhDouble#" Monadic
532 with needs_wrapper = True
534 primop DoubleCoshOp "coshDouble#" Monadic
536 with needs_wrapper = True
538 primop DoubleTanhOp "tanhDouble#" Monadic
540 with needs_wrapper = True
542 primop DoublePowerOp "**##" Dyadic
543 Double# -> Double# -> Double#
545 with needs_wrapper = True
547 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
548 Double# -> (# Int#, Int#, ByteArr# #)
549 {Convert to arbitrary-precision integer.
550 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
551 holding the mantissa.}
552 with out_of_line = True
554 ------------------------------------------------------------------------
556 {Operations on single-precision (32-bit) floating-point numbers.}
557 ------------------------------------------------------------------------
559 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
560 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
562 primop FloatEqOp "eqFloat#" Compare
563 Float# -> Float# -> Bool
564 with commutable = True
566 primop FloatNeOp "neFloat#" Compare
567 Float# -> Float# -> Bool
568 with commutable = True
570 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
571 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
573 primop FloatAddOp "plusFloat#" Dyadic
574 Float# -> Float# -> Float#
575 with commutable = True
577 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
579 primop FloatMulOp "timesFloat#" Dyadic
580 Float# -> Float# -> Float#
581 with commutable = True
583 primop FloatDivOp "divideFloat#" Dyadic
584 Float# -> Float# -> Float#
587 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
589 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
591 primop FloatExpOp "expFloat#" Monadic
593 with needs_wrapper = True
595 primop FloatLogOp "logFloat#" Monadic
597 with needs_wrapper = True
600 primop FloatSqrtOp "sqrtFloat#" Monadic
602 with needs_wrapper = True
604 primop FloatSinOp "sinFloat#" Monadic
606 with needs_wrapper = True
608 primop FloatCosOp "cosFloat#" Monadic
610 with needs_wrapper = True
612 primop FloatTanOp "tanFloat#" Monadic
614 with needs_wrapper = True
616 primop FloatAsinOp "asinFloat#" Monadic
618 with needs_wrapper = True
621 primop FloatAcosOp "acosFloat#" Monadic
623 with needs_wrapper = True
626 primop FloatAtanOp "atanFloat#" Monadic
628 with needs_wrapper = True
630 primop FloatSinhOp "sinhFloat#" Monadic
632 with needs_wrapper = True
634 primop FloatCoshOp "coshFloat#" Monadic
636 with needs_wrapper = True
638 primop FloatTanhOp "tanhFloat#" Monadic
640 with needs_wrapper = True
642 primop FloatPowerOp "powerFloat#" Dyadic
643 Float# -> Float# -> Float#
644 with needs_wrapper = True
646 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
648 primop FloatDecodeOp "decodeFloat#" GenPrimOp
649 Float# -> (# Int#, Int#, ByteArr# #)
650 {Convert to arbitrary-precision integer.
651 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
652 holding the mantissa.}
653 with out_of_line = True
655 ------------------------------------------------------------------------
657 {Operations on Array\#.}
658 ------------------------------------------------------------------------
660 primop NewArrayOp "newArray#" GenPrimOp
661 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
662 {Create a new mutable array of specified size (in bytes),
663 in the specified state thread,
664 with each element containing the specified initial value.}
666 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
667 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
670 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
671 MutArr# s a -> MutArr# s a -> Bool
673 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
675 primop ReadArrayOp "readArray#" GenPrimOp
676 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
677 {Read from specified index of mutable array. Result is not yet evaluated.}
679 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
681 primop WriteArrayOp "writeArray#" GenPrimOp
682 MutArr# s a -> Int# -> a -> State# s -> State# s
683 {Write to specified index of mutable array.}
685 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
686 strictness = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
687 has_side_effects = True
689 primop IndexArrayOp "indexArray#" GenPrimOp
690 Array# a -> Int# -> (# a #)
691 {Read from specified index of immutable array. Result is packaged into
692 an unboxed singleton; the result itself is not yet evaluated.}
694 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
696 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
697 MutArr# s a -> State# s -> (# State# s, Array# a #)
698 {Make a mutable array immutable, without copying.}
700 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
701 has_side_effects = True
703 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
704 Array# a -> State# s -> (# State# s, MutArr# s a #)
705 {Make an immutable array mutable, without copying.}
707 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
710 ------------------------------------------------------------------------
711 section "Byte Arrays"
712 {Operations on ByteArray\#. A ByteArray\# is a just a region of
713 raw memory in the garbage-collected heap, which is not scanned
714 for pointers. It carries its own size (in bytes). There are
715 three sets of operations for accessing byte array contents:
716 index for reading from immutable byte arrays, and read/write
717 for mutable byte arrays. Each set contains operations for
718 a range of useful primitive data types. Each operation takes
719 an offset measured in terms of the size fo the primitive type
720 being read or written.}
722 ------------------------------------------------------------------------
724 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
725 Int# -> State# s -> (# State# s, MutByteArr# s #)
726 {Create a new mutable byte array of specified size (in bytes), in
727 the specified state thread.}
728 with out_of_line = True
730 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
731 Int# -> State# s -> (# State# s, MutByteArr# s #)
732 {Create a mutable byte array that the GC guarantees not to move.}
733 with out_of_line = True
735 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
737 {Intended for use with pinned arrays; otherwise very unsafe!}
739 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
740 MutByteArr# s -> MutByteArr# s -> Bool
742 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
743 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
744 {Make a mutable byte array immutable, without copying.}
746 has_side_effects = True
748 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
751 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
752 MutByteArr# s -> Int#
755 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
756 ByteArr# -> Int# -> Char#
757 {Read 8-bit character; offset in bytes.}
759 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
760 ByteArr# -> Int# -> Char#
761 {Read 31-bit character; offset in 4-byte words.}
763 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
764 ByteArr# -> Int# -> Int#
766 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
767 ByteArr# -> Int# -> Word#
769 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
770 ByteArr# -> Int# -> Addr#
772 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
773 ByteArr# -> Int# -> Float#
775 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
776 ByteArr# -> Int# -> Double#
778 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
779 ByteArr# -> Int# -> StablePtr# a
781 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
782 ByteArr# -> Int# -> Int#
784 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
785 ByteArr# -> Int# -> Int#
787 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
788 ByteArr# -> Int# -> INT32
790 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
791 ByteArr# -> Int# -> INT64
793 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
794 ByteArr# -> Int# -> Word#
796 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
797 ByteArr# -> Int# -> Word#
799 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
800 ByteArr# -> Int# -> WORD32
802 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
803 ByteArr# -> Int# -> WORD64
805 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
806 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
807 {Read 8-bit character; offset in bytes.}
809 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
810 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
811 {Read 31-bit character; offset in 4-byte words.}
813 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
814 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
816 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
817 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
819 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
820 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
822 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
823 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
825 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
826 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
828 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
829 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
831 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
832 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
834 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
835 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
837 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
838 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
840 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
841 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
843 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
844 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
846 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
847 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
849 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
850 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
852 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
853 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
855 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
856 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
857 {Write 8-bit character; offset in bytes.}
858 with has_side_effects = True
860 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
861 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
862 {Write 31-bit character; offset in 4-byte words.}
863 with has_side_effects = True
865 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
866 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
867 with has_side_effects = True
869 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
870 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
871 with has_side_effects = True
873 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
874 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
875 with has_side_effects = True
877 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
878 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
879 with has_side_effects = True
881 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
882 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
883 with has_side_effects = True
885 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
886 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
887 with has_side_effects = True
889 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
890 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
891 with has_side_effects = True
893 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
894 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
895 with has_side_effects = True
897 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
898 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
899 with has_side_effects = True
901 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
902 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
903 with has_side_effects = True
905 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
906 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
907 with has_side_effects = True
909 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
910 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
911 with has_side_effects = True
913 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
914 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
915 with has_side_effects = True
917 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
918 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
919 with has_side_effects = True
921 ------------------------------------------------------------------------
923 {Addr\# is an arbitrary machine address assumed to point outside
924 the garbage-collected heap.}
925 ------------------------------------------------------------------------
927 primop AddrNullOp "nullAddr#" GenPrimOp Int# -> Addr#
928 {Returns null address. Argument is ignored (nullary primops
930 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
931 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
932 {Result is meaningless if two Addr\#s are so far apart that their
933 difference doesn't fit in an Int\#.}
934 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
935 {Return the remainder when the Addr\# arg, treated like an Int\#,
936 is divided by the Int\# arg.}
937 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
938 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
939 {Coerce directly from address to int. Strongly deprecated.}
940 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
941 {Coerce directly from int to address. Strongly deprecated.}
944 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
945 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
946 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
947 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
948 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
949 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
951 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
952 Addr# -> Int# -> Char#
953 {Reads 8-bit character; offset in bytes.}
955 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
956 Addr# -> Int# -> Char#
957 {Reads 31-bit character; offset in 4-byte words.}
959 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
960 Addr# -> Int# -> Int#
962 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
963 Addr# -> Int# -> Word#
965 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
966 Addr# -> Int# -> Addr#
968 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
969 Addr# -> Int# -> Float#
971 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
972 Addr# -> Int# -> Double#
974 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
975 Addr# -> Int# -> StablePtr# a
977 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
978 Addr# -> Int# -> Int#
980 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
981 Addr# -> Int# -> Int#
983 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
984 Addr# -> Int# -> INT32
986 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
987 Addr# -> Int# -> INT64
989 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
990 Addr# -> Int# -> Word#
992 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
993 Addr# -> Int# -> Word#
995 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
996 Addr# -> Int# -> WORD32
998 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
999 Addr# -> Int# -> WORD64
1001 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1002 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1003 {Reads 8-bit character; offset in bytes.}
1005 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1006 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1007 {Reads 31-bit character; offset in 4-byte words.}
1009 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1010 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1012 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1013 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1015 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1016 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1018 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1019 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1021 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1022 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1024 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1025 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1027 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1028 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1030 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1031 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1033 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1034 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1036 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1037 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1039 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1040 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1042 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1043 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1045 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1046 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1048 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1049 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1052 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1053 Addr# -> Int# -> Char# -> State# s -> State# s
1054 with has_side_effects = True
1056 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1057 Addr# -> Int# -> Char# -> State# s -> State# s
1058 with has_side_effects = True
1060 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1061 Addr# -> Int# -> Int# -> State# s -> State# s
1062 with has_side_effects = True
1064 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1065 Addr# -> Int# -> Word# -> State# s -> State# s
1066 with has_side_effects = True
1068 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1069 Addr# -> Int# -> Addr# -> State# s -> State# s
1070 with has_side_effects = True
1072 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1073 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1074 with has_side_effects = True
1076 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1077 Addr# -> Int# -> Float# -> State# s -> State# s
1078 with has_side_effects = True
1080 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1081 Addr# -> Int# -> Double# -> State# s -> State# s
1082 with has_side_effects = True
1084 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1085 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1086 with has_side_effects = True
1088 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1089 Addr# -> Int# -> Int# -> State# s -> State# s
1090 with has_side_effects = True
1092 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1093 Addr# -> Int# -> Int# -> State# s -> State# s
1094 with has_side_effects = True
1096 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1097 Addr# -> Int# -> INT32 -> State# s -> State# s
1098 with has_side_effects = True
1100 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1101 Addr# -> Int# -> INT64 -> State# s -> State# s
1102 with has_side_effects = True
1104 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1105 Addr# -> Int# -> Word# -> State# s -> State# s
1106 with has_side_effects = True
1108 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1109 Addr# -> Int# -> Word# -> State# s -> State# s
1110 with has_side_effects = True
1112 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1113 Addr# -> Int# -> WORD32 -> State# s -> State# s
1114 with has_side_effects = True
1116 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1117 Addr# -> Int# -> WORD64 -> State# s -> State# s
1118 with has_side_effects = True
1120 ------------------------------------------------------------------------
1121 section "ForeignObj#"
1122 {Operations on ForeignObj\#. The indexing operations are
1124 ------------------------------------------------------------------------
1126 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1127 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1129 has_side_effects = True
1132 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1133 ForeignObj# -> Addr# -> State# s -> State# s
1135 has_side_effects = True
1137 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1138 ForeignObj# -> Addr#
1140 primop TouchOp "touch#" GenPrimOp
1141 o -> State# RealWorld -> State# RealWorld
1143 has_side_effects = True
1144 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1146 primop EqForeignObj "eqForeignObj#" GenPrimOp
1147 ForeignObj# -> ForeignObj# -> Bool
1148 with commutable = True
1150 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1151 ForeignObj# -> Int# -> Char#
1152 {Read 8-bit character; offset in bytes.}
1154 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1155 ForeignObj# -> Int# -> Char#
1156 {Read 31-bit character; offset in 4-byte words.}
1158 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1159 ForeignObj# -> Int# -> Int#
1161 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1162 ForeignObj# -> Int# -> Word#
1164 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1165 ForeignObj# -> Int# -> Addr#
1167 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1168 ForeignObj# -> Int# -> Float#
1170 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1171 ForeignObj# -> Int# -> Double#
1173 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1174 ForeignObj# -> Int# -> StablePtr# a
1176 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1177 ForeignObj# -> Int# -> Int#
1179 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1180 ForeignObj# -> Int# -> Int#
1182 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1183 ForeignObj# -> Int# -> INT32
1185 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1186 ForeignObj# -> Int# -> INT64
1188 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1189 ForeignObj# -> Int# -> Word#
1191 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1192 ForeignObj# -> Int# -> Word#
1194 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1195 ForeignObj# -> Int# -> WORD32
1197 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1198 ForeignObj# -> Int# -> WORD64
1202 ------------------------------------------------------------------------
1203 section "Mutable variables"
1204 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1205 ------------------------------------------------------------------------
1207 primop NewMutVarOp "newMutVar#" GenPrimOp
1208 a -> State# s -> (# State# s, MutVar# s a #)
1209 {Create MutVar\# with specified initial value in specified state thread.}
1211 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1212 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1215 primop ReadMutVarOp "readMutVar#" GenPrimOp
1216 MutVar# s a -> State# s -> (# State# s, a #)
1217 {Read contents of MutVar\#. Result is not yet evaluated.}
1219 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1221 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1222 MutVar# s a -> a -> State# s -> State# s
1223 {Write contents of MutVar\#.}
1225 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1226 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1227 has_side_effects = True
1229 primop SameMutVarOp "sameMutVar#" GenPrimOp
1230 MutVar# s a -> MutVar# s a -> Bool
1232 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1234 ------------------------------------------------------------------------
1235 section "Exceptions"
1236 ------------------------------------------------------------------------
1238 primop CatchOp "catch#" GenPrimOp
1239 (State# RealWorld -> (# State# RealWorld, a #) )
1240 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1242 -> (# State# RealWorld, a #)
1244 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
1245 -- Catch is actually strict in its first argument
1246 -- but we don't want to tell the strictness
1247 -- analyser about that!
1248 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1249 -- [mkO, mkO . (inFun mkM mkO)] mkO
1250 -- might use caught action multiply
1253 primop RaiseOp "raise#" GenPrimOp
1256 strictness = { \ arity -> StrictnessInfo [wwLazy] True }
1257 -- NB: True => result is bottom
1258 usage = { mangle RaiseOp [mkM] mkM }
1261 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1262 (State# RealWorld -> (# State# RealWorld, a #))
1263 -> (State# RealWorld -> (# State# RealWorld, a #))
1265 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1268 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1269 (State# RealWorld -> (# State# RealWorld, a #))
1270 -> (State# RealWorld -> (# State# RealWorld, a #))
1272 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1275 ------------------------------------------------------------------------
1276 section "Synchronized Mutable Variables"
1277 {Operations on MVar\#s, which are shared mutable variables
1278 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1279 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1280 ------------------------------------------------------------------------
1283 primop NewMVarOp "newMVar#" GenPrimOp
1284 State# s -> (# State# s, MVar# s a #)
1285 {Create new mvar; initially empty.}
1287 usage = { mangle NewMVarOp [mkP] mkR }
1290 primop TakeMVarOp "takeMVar#" GenPrimOp
1291 MVar# s a -> State# s -> (# State# s, a #)
1292 {If mvar is empty, block until it becomes full.
1293 Then remove and return its contents, and set it empty.}
1295 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1296 has_side_effects = True
1299 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1300 MVar# s a -> State# s -> (# State# s, Int#, a #)
1301 {If mvar is empty, immediately return with integer 0 and value undefined.
1302 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1304 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1305 has_side_effects = True
1308 primop PutMVarOp "putMVar#" GenPrimOp
1309 MVar# s a -> a -> State# s -> State# s
1310 {If mvar is full, block until it becomes empty.
1311 Then store value arg as its new contents.}
1313 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1314 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1315 has_side_effects = True
1318 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1319 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1320 {If mvar is full, immediately return with integer 0.
1321 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1323 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1324 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1325 has_side_effects = True
1328 primop SameMVarOp "sameMVar#" GenPrimOp
1329 MVar# s a -> MVar# s a -> Bool
1331 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1333 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1334 MVar# s a -> State# s -> (# State# s, Int# #)
1335 {Return 1 if mvar is empty; 0 otherwise.}
1337 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1340 ------------------------------------------------------------------------
1341 section "Delay/wait operations"
1342 ------------------------------------------------------------------------
1344 primop DelayOp "delay#" GenPrimOp
1345 Int# -> State# s -> State# s
1346 {Sleep specified number of microseconds.}
1348 needs_wrapper = True
1349 has_side_effects = True
1352 primop WaitReadOp "waitRead#" GenPrimOp
1353 Int# -> State# s -> State# s
1354 {Block until input is available on specified file descriptor.}
1356 needs_wrapper = True
1357 has_side_effects = True
1360 primop WaitWriteOp "waitWrite#" GenPrimOp
1361 Int# -> State# s -> State# s
1362 {Block until output is possible on specified file descriptor.}
1364 needs_wrapper = True
1365 has_side_effects = True
1368 ------------------------------------------------------------------------
1369 section "Concurrency primitives"
1370 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1371 type, whose (unique) value is returned by myThreadId\#. The
1372 other operations can be omitted.)}
1373 ------------------------------------------------------------------------
1375 primop ForkOp "fork#" GenPrimOp
1376 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1378 usage = { mangle ForkOp [mkO, mkP] mkR }
1379 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1380 has_side_effects = True
1383 primop KillThreadOp "killThread#" GenPrimOp
1384 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1386 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1387 has_side_effects = True
1390 primop YieldOp "yield#" GenPrimOp
1391 State# RealWorld -> State# RealWorld
1393 has_side_effects = True
1396 primop MyThreadIdOp "myThreadId#" GenPrimOp
1397 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1399 ------------------------------------------------------------------------
1400 section "Weak pointers"
1401 ------------------------------------------------------------------------
1403 -- note that tyvar "o" denotes openAlphaTyVar
1405 primop MkWeakOp "mkWeak#" GenPrimOp
1406 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1408 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
1409 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1410 has_side_effects = True
1413 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1414 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1416 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1417 has_side_effects = True
1419 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1420 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1421 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
1423 usage = { mangle FinalizeWeakOp [mkM, mkP]
1424 (mkR . (inUB FinalizeWeakOp
1425 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1426 has_side_effects = True
1429 ------------------------------------------------------------------------
1430 section "Stable pointers and names"
1431 ------------------------------------------------------------------------
1433 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1434 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1436 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1437 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1438 has_side_effects = True
1440 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1441 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1443 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1444 needs_wrapper = True
1445 has_side_effects = True
1447 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1448 StablePtr# a -> StablePtr# a -> Int#
1450 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1451 has_side_effects = True
1453 primop MakeStableNameOp "makeStableName#" GenPrimOp
1454 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1456 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1457 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
1458 needs_wrapper = True
1459 has_side_effects = True
1462 primop EqStableNameOp "eqStableName#" GenPrimOp
1463 StableName# a -> StableName# a -> Int#
1465 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1467 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1468 StableName# a -> Int#
1470 usage = { mangle StableNameToIntOp [mkP] mkR }
1472 ------------------------------------------------------------------------
1473 section "Unsafe pointer equality"
1474 -- (#1 Bad Guy: Alistair Reid :)
1475 ------------------------------------------------------------------------
1477 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1480 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
1482 ------------------------------------------------------------------------
1483 section "Parallelism"
1484 ------------------------------------------------------------------------
1486 primop SeqOp "seq#" GenPrimOp
1489 usage = { mangle SeqOp [mkO] mkR }
1490 strictness = { \ arity -> StrictnessInfo [wwStrict] False }
1491 -- Seq is strict in its argument; see notes in ConFold.lhs
1492 has_side_effects = True
1494 primop ParOp "par#" GenPrimOp
1497 usage = { mangle ParOp [mkO] mkR }
1498 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1499 -- Note that Par is lazy to avoid that the sparked thing
1500 -- gets evaluted strictly, which it should *not* be
1501 has_side_effects = True
1503 -- HWL: The first 4 Int# in all par... annotations denote:
1504 -- name, granularity info, size of result, degree of parallelism
1505 -- Same structure as _seq_ i.e. returns Int#
1506 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1507 -- `the processor containing the expression v'; it is not evaluated
1509 primop ParGlobalOp "parGlobal#" GenPrimOp
1510 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1512 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1513 has_side_effects = True
1515 primop ParLocalOp "parLocal#" GenPrimOp
1516 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1518 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1519 has_side_effects = True
1521 primop ParAtOp "parAt#" GenPrimOp
1522 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1524 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1525 has_side_effects = True
1527 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1528 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1530 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1531 has_side_effects = True
1533 primop ParAtRelOp "parAtRel#" GenPrimOp
1534 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1536 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1537 has_side_effects = True
1539 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1540 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1542 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1543 has_side_effects = True
1545 -- copyable# and noFollow# are yet to be implemented (for GpH)
1547 --primop CopyableOp "copyable#" GenPrimOp
1550 -- usage = { mangle CopyableOp [mkZ] mkR }
1551 -- has_side_effects = True
1553 --primop NoFollowOp "noFollow#" GenPrimOp
1556 -- usage = { mangle NoFollowOp [mkZ] mkR }
1557 -- has_side_effects = True
1560 ------------------------------------------------------------------------
1561 section "Tag to enum stuff"
1562 {Convert back and forth between values of enumerated types
1563 and small integers.}
1564 ------------------------------------------------------------------------
1566 primop DataToTagOp "dataToTag#" GenPrimOp
1569 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
1571 primop TagToEnumOp "tagToEnum#" GenPrimOp
1574 ------------------------------------------------------------------------
1575 section "Bytecode operations"
1576 {Support for the bytecode interpreter and linker.}
1577 ------------------------------------------------------------------------
1580 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1582 {Convert an Addr\# to a followable type.}
1584 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1589 primop NewBCOOp "newBCO#" GenPrimOp
1590 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
1592 has_side_effects = True
1595 ------------------------------------------------------------------------
1597 ------------------------------------------------------------------------