1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.36 2005/07/25 14:12:48 simonmar Exp $
4 -- Primitive Operations
6 -----------------------------------------------------------------------
8 -- This file is processed by the utility program genprimopcode to produce
9 -- a number of include files within the compiler and optionally to produce
10 -- human-readable documentation.
12 -- It should first be preprocessed.
14 -- To add a new primop, you currently need to update the following files:
16 -- - this file (ghc/compiler/prelude/primops.txt.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 -- - if the primop is inline (i.e. a macro), then:
22 -- ghc/compiler/AbsCUtils.lhs (dscCOpStmt)
23 -- defines the translation of the primop into simpler
24 -- abstract C operations.
26 -- - or, for an out-of-line primop:
27 -- ghc/includes/PrimOps.h (just add the declaration)
28 -- ghc/rts/PrimOps.hc (define it here)
29 -- ghc/rts/Linker.c (declare the symbol for GHCi)
34 -- This file is divided into named sections, each containing or more
35 -- primop entries. Section headers have the format:
37 -- section "section-name" {description}
39 -- This information is used solely when producing documentation; it is
40 -- otherwise ignored. The description is optional.
42 -- The format of each primop entry is as follows:
44 -- primop internal-name "name-in-program-text" type category {description} attributes
46 -- The default attribute values which apply if you don't specify
47 -- other ones. Attribute values can be True, False, or arbitrary
48 -- text between curly brackets. This is a kludge to enable
49 -- processors of this file to easily get hold of simple info
50 -- (eg, out_of_line), whilst avoiding parsing complex expressions
51 -- needed for strictness and usage info.
54 has_side_effects = False
59 strictness = { \ arity -> mkStrictSig (mkTopDmdType (replicate arity lazyDmd) TopRes) }
60 usage = { nomangle other }
62 -- Currently, documentation is produced using latex, so contents of
63 -- description fields should be legal latex. Descriptions can contain
64 -- matched pairs of embedded curly brackets.
68 -- We need platform defines (tests for mingw32 below). However, we only
69 -- test the TARGET platform, which doesn't vary between stages, so the
70 -- stage1 platform defines are fine:
71 #include "../stage1/ghc_boot_platform.h"
73 section "The word size story."
74 {Haskell98 specifies that signed integers (type {\tt Int})
75 must contain at least 30 bits. GHC always implements {\tt
76 Int} using the primitive type {\tt Int\#}, whose size equals
77 the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
78 This is normally set based on the {\tt config.h} parameter
79 {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
80 bits on 64-bit machines. However, it can also be explicitly
81 set to a smaller number, e.g., 31 bits, to allow the
82 possibility of using tag bits. Currently GHC itself has only
83 32-bit and 64-bit variants, but 30 or 31-bit code can be
84 exported as an external core file for use in other back ends.
86 GHC also implements a primitive unsigned integer type {\tt
87 Word\#} which always has the same number of bits as {\tt
90 In addition, GHC supports families of explicit-sized integers
91 and words at 8, 16, 32, and 64 bits, with the usual
92 arithmetic operations, comparisons, and a range of
93 conversions. The 8-bit and 16-bit sizes are always
94 represented as {\tt Int\#} and {\tt Word\#}, and the
95 operations implemented in terms of the the primops on these
96 types, with suitable range restrictions on the results (using
97 the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
98 of primops. The 32-bit sizes are represented using {\tt
99 Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
100 $\geq$ 32; otherwise, these are represented using distinct
101 primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
102 needed) have a complete set of corresponding operations;
103 however, nearly all of these are implemented as external C
104 functions rather than as primops. Exactly the same story
105 applies to the 64-bit sizes. All of these details are hidden
106 under the {\tt PrelInt} and {\tt PrelWord} modules, which use
107 {\tt \#if}-defs to invoke the appropriate types and
110 Word size also matters for the families of primops for
111 indexing/reading/writing fixed-size quantities at offsets
112 from an array base, address, or foreign pointer. Here, a
113 slightly different approach is taken. The names of these
114 primops are fixed, but their {\it types} vary according to
115 the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
116 size is at least 32 bits then an operator like
117 \texttt{indexInt32Array\#} has type {\tt ByteArr\# -> Int\#
118 -> Int\#}; otherwise it has type {\tt ByteArr\# -> Int\# ->
119 Int32\#}. This approach confines the necessary {\tt
120 \#if}-defs to this file; no conditional compilation is needed
121 in the files that expose these primops.
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 {Low word of signed integer multiply.}
184 with commutable = True
186 primop IntMulMayOfloOp "mulIntMayOflo#"
187 Dyadic Int# -> Int# -> Int#
188 {Return non-zero if there is any possibility that the upper word of a
189 signed integer multiply might contain useful information. Return
190 zero only if you are completely sure that no overflow can occur.
191 On a 32-bit platform, the recommmended implementation is to do a
192 32 x 32 -> 64 signed multiply, and subtract result[63:32] from
193 (result[31] >>signed 31). If this is zero, meaning that the
194 upper word is merely a sign extension of the lower one, no
197 On a 64-bit platform it is not always possible to
198 acquire the top 64 bits of the result. Therefore, a recommended
199 implementation is to take the absolute value of both operands, and
200 return 0 iff bits[63:31] of them are zero, since that means that their
201 magnitudes fit within 31 bits, so the magnitude of the product must fit
204 If in doubt, return non-zero, but do make an effort to create the
205 correct answer for small args, since otherwise the performance of
206 (*) :: Integer -> Integer -> Integer will be poor.
208 with commutable = True
210 primop IntQuotOp "quotInt#" Dyadic
212 {Rounds towards zero.}
215 primop IntRemOp "remInt#" Dyadic
217 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
220 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
221 with out_of_line = True
223 primop IntNegOp "negateInt#" Monadic Int# -> Int#
224 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
225 {Add with carry. First member of result is (wrapped) sum;
226 second member is 0 iff no overflow occured.}
227 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
228 {Subtract with carry. First member of result is (wrapped) difference;
229 second member is 0 iff no overflow occured.}
231 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
232 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
234 primop IntEqOp "==#" Compare
236 with commutable = True
238 primop IntNeOp "/=#" Compare
240 with commutable = True
242 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
243 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
245 primop ChrOp "chr#" GenPrimOp Int# -> Char#
247 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
248 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
249 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
251 primop Int2IntegerOp "int2Integer#"
252 GenPrimOp Int# -> (# Int#, ByteArr# #)
253 with out_of_line = True
255 primop ISllOp "uncheckedIShiftL#" GenPrimOp Int# -> Int# -> Int#
256 {Shift left. Result undefined if shift amount is not
257 in the range 0 to word size - 1 inclusive.}
258 primop ISraOp "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
259 {Shift right arithmetic. Result undefined if shift amount is not
260 in the range 0 to word size - 1 inclusive.}
261 primop ISrlOp "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
262 {Shift right logical. Result undefined if shift amount is not
263 in the range 0 to word size - 1 inclusive.}
265 ------------------------------------------------------------------------
267 {Operations on native-sized unsigned words (30+ bits).}
268 ------------------------------------------------------------------------
270 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
271 with commutable = True
273 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
275 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
276 with commutable = True
278 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
281 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
284 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
285 with commutable = True
287 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
288 with commutable = True
290 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
291 with commutable = True
293 primop NotOp "not#" Monadic Word# -> Word#
295 primop SllOp "uncheckedShiftL#" GenPrimOp Word# -> Int# -> Word#
296 {Shift left logical. Result undefined if shift amount is not
297 in the range 0 to word size - 1 inclusive.}
298 primop SrlOp "uncheckedShiftRL#" GenPrimOp Word# -> Int# -> Word#
299 {Shift right logical. Result undefined if shift amount is not
300 in the range 0 to word size - 1 inclusive.}
302 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
304 primop Word2IntegerOp "word2Integer#" GenPrimOp
305 Word# -> (# Int#, ByteArr# #)
306 with out_of_line = True
308 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
309 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
310 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
311 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
312 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
313 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
315 ------------------------------------------------------------------------
317 {Explicit narrowing of native-sized ints or words.}
318 ------------------------------------------------------------------------
320 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
321 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
322 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
323 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
324 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
325 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
328 #if WORD_SIZE_IN_BITS < 32
329 ------------------------------------------------------------------------
331 {Operations on 32-bit integers (Int32\#). This type is only used
332 if plain Int\# has less than 32 bits. In any case, the operations
333 are not primops; they are implemented (if needed) as ccalls instead.}
334 ------------------------------------------------------------------------
336 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
337 Int32# -> (# Int#, ByteArr# #)
338 with out_of_line = True
341 ------------------------------------------------------------------------
343 {Operations on 32-bit unsigned words. This type is only used
344 if plain Word\# has less than 32 bits. In any case, the operations
345 are not primops; they are implemented (if needed) as ccalls instead.}
346 ------------------------------------------------------------------------
348 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
349 Word32# -> (# Int#, ByteArr# #)
350 with out_of_line = True
356 #if WORD_SIZE_IN_BITS < 64
357 ------------------------------------------------------------------------
359 {Operations on 64-bit unsigned words. This type is only used
360 if plain Int\# has less than 64 bits. In any case, the operations
361 are not primops; they are implemented (if needed) as ccalls instead.}
362 ------------------------------------------------------------------------
364 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
365 Int64# -> (# Int#, ByteArr# #)
366 with out_of_line = True
368 ------------------------------------------------------------------------
370 {Operations on 64-bit unsigned words. This type is only used
371 if plain Word\# has less than 64 bits. In any case, the operations
372 are not primops; they are implemented (if needed) as ccalls instead.}
373 ------------------------------------------------------------------------
375 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
376 Word64# -> (# Int#, ByteArr# #)
377 with out_of_line = True
381 ------------------------------------------------------------------------
383 {Operations on arbitrary-precision integers. These operations are
384 implemented via the GMP package. An integer is represented as a pair
385 consisting of an Int\# representing the number of 'limbs' in use and
386 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
387 are returned as unboxed pairs, but must be passed as separate
390 For .NET these operations are implemented by foreign imports, so the
391 primops are omitted.}
392 ------------------------------------------------------------------------
396 primop IntegerAddOp "plusInteger#" GenPrimOp
397 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
398 with commutable = True
401 primop IntegerSubOp "minusInteger#" GenPrimOp
402 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
403 with out_of_line = True
405 primop IntegerMulOp "timesInteger#" GenPrimOp
406 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
407 with commutable = True
410 primop IntegerGcdOp "gcdInteger#" GenPrimOp
411 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
412 {Greatest common divisor.}
413 with commutable = True
416 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
417 Int# -> ByteArr# -> Int# -> Int#
418 {Greatest common divisor, where second argument is an ordinary Int\#.}
419 with out_of_line = True
421 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
422 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
423 {Divisor is guaranteed to be a factor of dividend.}
424 with out_of_line = True
426 primop IntegerQuotOp "quotInteger#" GenPrimOp
427 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
428 {Rounds towards zero.}
429 with out_of_line = True
431 primop IntegerRemOp "remInteger#" GenPrimOp
432 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
433 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
434 with out_of_line = True
436 primop IntegerCmpOp "cmpInteger#" GenPrimOp
437 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
438 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
439 with needs_wrapper = True
442 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
443 Int# -> ByteArr# -> Int# -> Int#
444 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
445 is an ordinary Int\#.}
446 with needs_wrapper = True
449 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
450 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
451 {Compute quot and rem simulaneously.}
455 primop IntegerDivModOp "divModInteger#" GenPrimOp
456 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
457 {Compute div and mod simultaneously, where div rounds towards negative infinity
458 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
462 primop Integer2IntOp "integer2Int#" GenPrimOp
463 Int# -> ByteArr# -> Int#
464 with needs_wrapper = True
467 primop Integer2WordOp "integer2Word#" GenPrimOp
468 Int# -> ByteArr# -> Word#
469 with needs_wrapper = True
472 #if WORD_SIZE_IN_BITS < 32
473 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
474 Int# -> ByteArr# -> Int32#
476 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
477 Int# -> ByteArr# -> Word32#
480 primop IntegerAndOp "andInteger#" GenPrimOp
481 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
482 with out_of_line = True
484 primop IntegerOrOp "orInteger#" GenPrimOp
485 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
486 with out_of_line = True
488 primop IntegerXorOp "xorInteger#" GenPrimOp
489 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
490 with out_of_line = True
492 primop IntegerComplementOp "complementInteger#" GenPrimOp
493 Int# -> ByteArr# -> (# Int#, ByteArr# #)
494 with out_of_line = True
496 #endif /* ndef ILX */
498 ------------------------------------------------------------------------
500 {Operations on double-precision (64 bit) floating-point numbers.}
501 ------------------------------------------------------------------------
503 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
504 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
506 primop DoubleEqOp "==##" Compare
507 Double# -> Double# -> Bool
508 with commutable = True
510 primop DoubleNeOp "/=##" Compare
511 Double# -> Double# -> Bool
512 with commutable = True
514 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
515 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
517 primop DoubleAddOp "+##" Dyadic
518 Double# -> Double# -> Double#
519 with commutable = True
521 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
523 primop DoubleMulOp "*##" Dyadic
524 Double# -> Double# -> Double#
525 with commutable = True
527 primop DoubleDivOp "/##" Dyadic
528 Double# -> Double# -> Double#
531 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
533 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
534 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
536 primop DoubleExpOp "expDouble#" Monadic
538 with needs_wrapper = True
540 primop DoubleLogOp "logDouble#" Monadic
546 primop DoubleSqrtOp "sqrtDouble#" Monadic
548 with needs_wrapper = True
550 primop DoubleSinOp "sinDouble#" Monadic
552 with needs_wrapper = True
554 primop DoubleCosOp "cosDouble#" Monadic
556 with needs_wrapper = True
558 primop DoubleTanOp "tanDouble#" Monadic
560 with needs_wrapper = True
562 primop DoubleAsinOp "asinDouble#" Monadic
568 primop DoubleAcosOp "acosDouble#" Monadic
574 primop DoubleAtanOp "atanDouble#" Monadic
579 primop DoubleSinhOp "sinhDouble#" Monadic
581 with needs_wrapper = True
583 primop DoubleCoshOp "coshDouble#" Monadic
585 with needs_wrapper = True
587 primop DoubleTanhOp "tanhDouble#" Monadic
589 with needs_wrapper = True
591 primop DoublePowerOp "**##" Dyadic
592 Double# -> Double# -> Double#
594 with needs_wrapper = True
596 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
597 Double# -> (# Int#, Int#, ByteArr# #)
598 {Convert to arbitrary-precision integer.
599 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
600 holding the mantissa.}
601 with out_of_line = True
603 ------------------------------------------------------------------------
605 {Operations on single-precision (32-bit) floating-point numbers.}
606 ------------------------------------------------------------------------
608 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
609 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
611 primop FloatEqOp "eqFloat#" Compare
612 Float# -> Float# -> Bool
613 with commutable = True
615 primop FloatNeOp "neFloat#" Compare
616 Float# -> Float# -> Bool
617 with commutable = True
619 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
620 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
622 primop FloatAddOp "plusFloat#" Dyadic
623 Float# -> Float# -> Float#
624 with commutable = True
626 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
628 primop FloatMulOp "timesFloat#" Dyadic
629 Float# -> Float# -> Float#
630 with commutable = True
632 primop FloatDivOp "divideFloat#" Dyadic
633 Float# -> Float# -> Float#
636 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
638 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
640 primop FloatExpOp "expFloat#" Monadic
642 with needs_wrapper = True
644 primop FloatLogOp "logFloat#" Monadic
646 with needs_wrapper = True
649 primop FloatSqrtOp "sqrtFloat#" Monadic
651 with needs_wrapper = True
653 primop FloatSinOp "sinFloat#" Monadic
655 with needs_wrapper = True
657 primop FloatCosOp "cosFloat#" Monadic
659 with needs_wrapper = True
661 primop FloatTanOp "tanFloat#" Monadic
663 with needs_wrapper = True
665 primop FloatAsinOp "asinFloat#" Monadic
667 with needs_wrapper = True
670 primop FloatAcosOp "acosFloat#" Monadic
672 with needs_wrapper = True
675 primop FloatAtanOp "atanFloat#" Monadic
677 with needs_wrapper = True
679 primop FloatSinhOp "sinhFloat#" Monadic
681 with needs_wrapper = True
683 primop FloatCoshOp "coshFloat#" Monadic
685 with needs_wrapper = True
687 primop FloatTanhOp "tanhFloat#" Monadic
689 with needs_wrapper = True
691 primop FloatPowerOp "powerFloat#" Dyadic
692 Float# -> Float# -> Float#
693 with needs_wrapper = True
695 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
697 primop FloatDecodeOp "decodeFloat#" GenPrimOp
698 Float# -> (# Int#, Int#, ByteArr# #)
699 {Convert to arbitrary-precision integer.
700 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
701 holding the mantissa.}
702 with out_of_line = True
704 ------------------------------------------------------------------------
706 {Operations on Array\#.}
707 ------------------------------------------------------------------------
709 primop NewArrayOp "newArray#" GenPrimOp
710 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
711 {Create a new mutable array of specified size (in bytes),
712 in the specified state thread,
713 with each element containing the specified initial value.}
715 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
718 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
719 MutArr# s a -> MutArr# s a -> Bool
721 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
723 primop ReadArrayOp "readArray#" GenPrimOp
724 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
725 {Read from specified index of mutable array. Result is not yet evaluated.}
727 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
729 primop WriteArrayOp "writeArray#" GenPrimOp
730 MutArr# s a -> Int# -> a -> State# s -> State# s
731 {Write to specified index of mutable array.}
733 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
734 has_side_effects = True
736 primop IndexArrayOp "indexArray#" GenPrimOp
737 Array# a -> Int# -> (# a #)
738 {Read from specified index of immutable array. Result is packaged into
739 an unboxed singleton; the result itself is not yet evaluated.}
741 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
743 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
744 MutArr# s a -> State# s -> (# State# s, Array# a #)
745 {Make a mutable array immutable, without copying.}
747 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
748 has_side_effects = True
750 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
751 Array# a -> State# s -> (# State# s, MutArr# s a #)
752 {Make an immutable array mutable, without copying.}
754 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
757 ------------------------------------------------------------------------
758 section "Byte Arrays"
759 {Operations on ByteArray\#. A ByteArray\# is a just a region of
760 raw memory in the garbage-collected heap, which is not scanned
761 for pointers. It carries its own size (in bytes). There are
762 three sets of operations for accessing byte array contents:
763 index for reading from immutable byte arrays, and read/write
764 for mutable byte arrays. Each set contains operations for
765 a range of useful primitive data types. Each operation takes
766 an offset measured in terms of the size fo the primitive type
767 being read or written.}
769 ------------------------------------------------------------------------
771 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
772 Int# -> State# s -> (# State# s, MutByteArr# s #)
773 {Create a new mutable byte array of specified size (in bytes), in
774 the specified state thread.}
775 with out_of_line = True
777 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
778 Int# -> State# s -> (# State# s, MutByteArr# s #)
779 {Create a mutable byte array that the GC guarantees not to move.}
780 with out_of_line = True
782 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
784 {Intended for use with pinned arrays; otherwise very unsafe!}
786 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
787 MutByteArr# s -> MutByteArr# s -> Bool
789 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
790 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
791 {Make a mutable byte array immutable, without copying.}
793 has_side_effects = True
795 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
798 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
799 MutByteArr# s -> Int#
802 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
803 ByteArr# -> Int# -> Char#
804 {Read 8-bit character; offset in bytes.}
806 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
807 ByteArr# -> Int# -> Char#
808 {Read 31-bit character; offset in 4-byte words.}
810 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
811 ByteArr# -> Int# -> Int#
813 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
814 ByteArr# -> Int# -> Word#
816 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
817 ByteArr# -> Int# -> Addr#
819 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
820 ByteArr# -> Int# -> Float#
822 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
823 ByteArr# -> Int# -> Double#
825 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
826 ByteArr# -> Int# -> StablePtr# a
828 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
829 ByteArr# -> Int# -> Int#
831 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
832 ByteArr# -> Int# -> Int#
834 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
835 ByteArr# -> Int# -> INT32
837 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
838 ByteArr# -> Int# -> INT64
840 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
841 ByteArr# -> Int# -> Word#
843 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
844 ByteArr# -> Int# -> Word#
846 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
847 ByteArr# -> Int# -> WORD32
849 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
850 ByteArr# -> Int# -> WORD64
852 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
853 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
854 {Read 8-bit character; offset in bytes.}
856 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
857 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
858 {Read 31-bit character; offset in 4-byte words.}
860 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
861 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
863 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
864 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
866 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
867 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
869 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
870 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
872 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
873 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
875 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
876 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
878 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
879 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
881 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
882 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
884 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
885 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
887 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
888 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
890 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
891 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
893 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
894 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
896 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
897 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
899 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
900 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
902 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
903 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
904 {Write 8-bit character; offset in bytes.}
905 with has_side_effects = True
907 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
908 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
909 {Write 31-bit character; offset in 4-byte words.}
910 with has_side_effects = True
912 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
913 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
914 with has_side_effects = True
916 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
917 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
918 with has_side_effects = True
920 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
921 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
922 with has_side_effects = True
924 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
925 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
926 with has_side_effects = True
928 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
929 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
930 with has_side_effects = True
932 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
933 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
934 with has_side_effects = True
936 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
937 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
938 with has_side_effects = True
940 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
941 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
942 with has_side_effects = True
944 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
945 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
946 with has_side_effects = True
948 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
949 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
950 with has_side_effects = True
952 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
953 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
954 with has_side_effects = True
956 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
957 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
958 with has_side_effects = True
960 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
961 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
962 with has_side_effects = True
964 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
965 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
966 with has_side_effects = True
968 ------------------------------------------------------------------------
970 {Addr\# is an arbitrary machine address assumed to point outside
971 the garbage-collected heap.
973 NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
974 It is the null address.}
975 ------------------------------------------------------------------------
977 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
978 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
979 {Result is meaningless if two Addr\#s are so far apart that their
980 difference doesn't fit in an Int\#.}
981 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
982 {Return the remainder when the Addr\# arg, treated like an Int\#,
983 is divided by the Int\# arg.}
984 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
985 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
986 {Coerce directly from address to int. Strongly deprecated.}
987 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
988 {Coerce directly from int to address. Strongly deprecated.}
991 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
992 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
993 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
994 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
995 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
996 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
998 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
999 Addr# -> Int# -> Char#
1000 {Reads 8-bit character; offset in bytes.}
1002 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
1003 Addr# -> Int# -> Char#
1004 {Reads 31-bit character; offset in 4-byte words.}
1006 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
1007 Addr# -> Int# -> Int#
1009 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
1010 Addr# -> Int# -> Word#
1012 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
1013 Addr# -> Int# -> Addr#
1015 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
1016 Addr# -> Int# -> Float#
1018 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
1019 Addr# -> Int# -> Double#
1021 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
1022 Addr# -> Int# -> StablePtr# a
1024 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
1025 Addr# -> Int# -> Int#
1027 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1028 Addr# -> Int# -> Int#
1030 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1031 Addr# -> Int# -> INT32
1033 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1034 Addr# -> Int# -> INT64
1036 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1037 Addr# -> Int# -> Word#
1039 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1040 Addr# -> Int# -> Word#
1042 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1043 Addr# -> Int# -> WORD32
1045 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1046 Addr# -> Int# -> WORD64
1048 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1049 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1050 {Reads 8-bit character; offset in bytes.}
1052 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1053 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1054 {Reads 31-bit character; offset in 4-byte words.}
1056 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1057 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1059 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1060 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1062 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1063 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1065 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1066 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1068 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1069 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1071 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1072 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1074 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1075 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1077 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1078 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1080 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1081 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1083 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1084 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1086 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1087 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1089 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1090 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1092 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1093 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1095 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1096 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1099 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1100 Addr# -> Int# -> Char# -> State# s -> State# s
1101 with has_side_effects = True
1103 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1104 Addr# -> Int# -> Char# -> State# s -> State# s
1105 with has_side_effects = True
1107 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1108 Addr# -> Int# -> Int# -> State# s -> State# s
1109 with has_side_effects = True
1111 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1112 Addr# -> Int# -> Word# -> State# s -> State# s
1113 with has_side_effects = True
1115 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1116 Addr# -> Int# -> Addr# -> State# s -> State# s
1117 with has_side_effects = True
1119 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1120 Addr# -> Int# -> Float# -> State# s -> State# s
1121 with has_side_effects = True
1123 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1124 Addr# -> Int# -> Double# -> State# s -> State# s
1125 with has_side_effects = True
1127 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1128 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1129 with has_side_effects = True
1131 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1132 Addr# -> Int# -> Int# -> State# s -> State# s
1133 with has_side_effects = True
1135 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1136 Addr# -> Int# -> Int# -> State# s -> State# s
1137 with has_side_effects = True
1139 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1140 Addr# -> Int# -> INT32 -> State# s -> State# s
1141 with has_side_effects = True
1143 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1144 Addr# -> Int# -> INT64 -> State# s -> State# s
1145 with has_side_effects = True
1147 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1148 Addr# -> Int# -> Word# -> State# s -> State# s
1149 with has_side_effects = True
1151 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1152 Addr# -> Int# -> Word# -> State# s -> State# s
1153 with has_side_effects = True
1155 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1156 Addr# -> Int# -> WORD32 -> State# s -> State# s
1157 with has_side_effects = True
1159 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1160 Addr# -> Int# -> WORD64 -> State# s -> State# s
1161 with has_side_effects = True
1163 ------------------------------------------------------------------------
1164 section "Mutable variables"
1165 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1166 ------------------------------------------------------------------------
1168 primop NewMutVarOp "newMutVar#" GenPrimOp
1169 a -> State# s -> (# State# s, MutVar# s a #)
1170 {Create MutVar\# with specified initial value in specified state thread.}
1172 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1175 primop ReadMutVarOp "readMutVar#" GenPrimOp
1176 MutVar# s a -> State# s -> (# State# s, a #)
1177 {Read contents of MutVar\#. Result is not yet evaluated.}
1179 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1181 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1182 MutVar# s a -> a -> State# s -> State# s
1183 {Write contents of MutVar\#.}
1185 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1186 has_side_effects = True
1188 primop SameMutVarOp "sameMutVar#" GenPrimOp
1189 MutVar# s a -> MutVar# s a -> Bool
1191 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1193 -- not really the right type, but we don't know about pairs here. The
1196 -- MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
1198 primop AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp
1199 MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #)
1201 usage = { mangle AtomicModifyMutVarOp [mkP, mkM, mkP] mkM }
1202 has_side_effects = True
1205 ------------------------------------------------------------------------
1206 section "Exceptions"
1207 ------------------------------------------------------------------------
1209 primop CatchOp "catch#" GenPrimOp
1210 (State# RealWorld -> (# State# RealWorld, a #) )
1211 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1213 -> (# State# RealWorld, a #)
1215 -- Catch is actually strict in its first argument
1216 -- but we don't want to tell the strictness
1217 -- analyser about that!
1218 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1219 -- [mkO, mkO . (inFun mkM mkO)] mkO
1220 -- might use caught action multiply
1223 primop RaiseOp "raise#" GenPrimOp
1226 strictness = { \ arity -> mkStrictSig (mkTopDmdType [lazyDmd] BotRes) }
1227 -- NB: result is bottom
1228 usage = { mangle RaiseOp [mkM] mkM }
1231 -- raiseIO# needs to be a primop, because exceptions in the IO monad
1232 -- must be *precise* - we don't want the strictness analyser turning
1233 -- one kind of bottom into another, as it is allowed to do in pure code.
1235 primop RaiseIOOp "raiseIO#" GenPrimOp
1236 a -> State# RealWorld -> (# State# RealWorld, b #)
1240 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1241 (State# RealWorld -> (# State# RealWorld, a #))
1242 -> (State# RealWorld -> (# State# RealWorld, a #))
1246 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1247 (State# RealWorld -> (# State# RealWorld, a #))
1248 -> (State# RealWorld -> (# State# RealWorld, a #))
1252 ------------------------------------------------------------------------
1253 section "STM-accessible Mutable Variables"
1254 ------------------------------------------------------------------------
1256 primop AtomicallyOp "atomically#" GenPrimOp
1257 (State# RealWorld -> (# State# RealWorld, a #) )
1258 -> State# RealWorld -> (# State# RealWorld, a #)
1261 has_side_effects = True
1263 primop RetryOp "retry#" GenPrimOp
1264 State# RealWorld -> (# State# RealWorld, a #)
1267 has_side_effects = True
1269 primop CatchRetryOp "catchRetry#" GenPrimOp
1270 (State# RealWorld -> (# State# RealWorld, a #) )
1271 -> (State# RealWorld -> (# State# RealWorld, a #) )
1272 -> (State# RealWorld -> (# State# RealWorld, a #) )
1275 has_side_effects = True
1277 primop CatchSTMOp "catchSTM#" GenPrimOp
1278 (State# RealWorld -> (# State# RealWorld, a #) )
1279 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1280 -> (State# RealWorld -> (# State# RealWorld, a #) )
1283 has_side_effects = True
1285 primop NewTVarOp "newTVar#" GenPrimOp
1287 -> State# s -> (# State# s, TVar# s a #)
1288 {Create a new Tar\# holding a specified initial value.}
1292 primop ReadTVarOp "readTVar#" GenPrimOp
1294 -> State# s -> (# State# s, a #)
1295 {Read contents of TVar\#. Result is not yet evaluated.}
1299 primop WriteTVarOp "writeTVar#" GenPrimOp
1302 -> State# s -> State# s
1303 {Write contents of TVar\#.}
1306 has_side_effects = True
1308 primop SameTVarOp "sameTVar#" GenPrimOp
1309 TVar# s a -> TVar# s a -> Bool
1312 ------------------------------------------------------------------------
1313 section "Synchronized Mutable Variables"
1314 {Operations on MVar\#s, which are shared mutable variables
1315 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1316 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1317 ------------------------------------------------------------------------
1320 primop NewMVarOp "newMVar#" GenPrimOp
1321 State# s -> (# State# s, MVar# s a #)
1322 {Create new mvar; initially empty.}
1324 usage = { mangle NewMVarOp [mkP] mkR }
1327 primop TakeMVarOp "takeMVar#" GenPrimOp
1328 MVar# s a -> State# s -> (# State# s, a #)
1329 {If mvar is empty, block until it becomes full.
1330 Then remove and return its contents, and set it empty.}
1332 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1333 has_side_effects = True
1336 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1337 MVar# s a -> State# s -> (# State# s, Int#, a #)
1338 {If mvar is empty, immediately return with integer 0 and value undefined.
1339 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1341 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1342 has_side_effects = True
1345 primop PutMVarOp "putMVar#" GenPrimOp
1346 MVar# s a -> a -> State# s -> State# s
1347 {If mvar is full, block until it becomes empty.
1348 Then store value arg as its new contents.}
1350 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1351 has_side_effects = True
1354 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1355 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1356 {If mvar is full, immediately return with integer 0.
1357 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1359 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1360 has_side_effects = True
1363 primop SameMVarOp "sameMVar#" GenPrimOp
1364 MVar# s a -> MVar# s a -> Bool
1366 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1368 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1369 MVar# s a -> State# s -> (# State# s, Int# #)
1370 {Return 1 if mvar is empty; 0 otherwise.}
1372 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1375 ------------------------------------------------------------------------
1376 section "Delay/wait operations"
1377 ------------------------------------------------------------------------
1379 primop DelayOp "delay#" GenPrimOp
1380 Int# -> State# s -> State# s
1381 {Sleep specified number of microseconds.}
1383 needs_wrapper = True
1384 has_side_effects = True
1387 primop WaitReadOp "waitRead#" GenPrimOp
1388 Int# -> State# s -> State# s
1389 {Block until input is available on specified file descriptor.}
1391 needs_wrapper = True
1392 has_side_effects = True
1395 primop WaitWriteOp "waitWrite#" GenPrimOp
1396 Int# -> State# s -> State# s
1397 {Block until output is possible on specified file descriptor.}
1399 needs_wrapper = True
1400 has_side_effects = True
1403 #ifdef mingw32_TARGET_OS
1404 primop AsyncReadOp "asyncRead#" GenPrimOp
1405 Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1406 {Asynchronously read bytes from specified file descriptor.}
1408 needs_wrapper = True
1409 has_side_effects = True
1412 primop AsyncWriteOp "asyncWrite#" GenPrimOp
1413 Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1414 {Asynchronously write bytes from specified file descriptor.}
1416 needs_wrapper = True
1417 has_side_effects = True
1420 primop AsyncDoProcOp "asyncDoProc#" GenPrimOp
1421 Addr# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1422 {Asynchronously perform procedure (first arg), passing it 2nd arg.}
1424 needs_wrapper = True
1425 has_side_effects = True
1430 ------------------------------------------------------------------------
1431 section "Concurrency primitives"
1432 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1433 type, whose (unique) value is returned by myThreadId\#. The
1434 other operations can be omitted.)}
1435 ------------------------------------------------------------------------
1437 primop ForkOp "fork#" GenPrimOp
1438 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1440 usage = { mangle ForkOp [mkO, mkP] mkR }
1441 has_side_effects = True
1444 primop KillThreadOp "killThread#" GenPrimOp
1445 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1447 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1448 has_side_effects = True
1451 primop YieldOp "yield#" GenPrimOp
1452 State# RealWorld -> State# RealWorld
1454 has_side_effects = True
1457 primop MyThreadIdOp "myThreadId#" GenPrimOp
1458 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1462 primop LabelThreadOp "labelThread#" GenPrimOp
1463 ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
1465 has_side_effects = True
1468 primop IsCurrentThreadBoundOp "isCurrentThreadBound#" GenPrimOp
1469 State# RealWorld -> (# State# RealWorld, Int# #)
1473 ------------------------------------------------------------------------
1474 section "Weak pointers"
1475 ------------------------------------------------------------------------
1477 -- note that tyvar "o" denotes openAlphaTyVar
1479 primop MkWeakOp "mkWeak#" GenPrimOp
1480 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1482 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1483 has_side_effects = True
1486 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1487 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1489 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1490 has_side_effects = True
1493 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1494 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1495 (State# RealWorld -> (# State# RealWorld, () #)) #)
1497 usage = { mangle FinalizeWeakOp [mkM, mkP]
1498 (mkR . (inUB FinalizeWeakOp
1499 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1500 has_side_effects = True
1503 primop TouchOp "touch#" GenPrimOp
1504 o -> State# RealWorld -> State# RealWorld
1506 has_side_effects = True
1508 ------------------------------------------------------------------------
1509 section "Stable pointers and names"
1510 ------------------------------------------------------------------------
1512 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1513 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1515 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1516 has_side_effects = True
1519 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1520 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1522 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1523 needs_wrapper = True
1524 has_side_effects = True
1527 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1528 StablePtr# a -> StablePtr# a -> Int#
1530 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1531 has_side_effects = True
1533 primop MakeStableNameOp "makeStableName#" GenPrimOp
1534 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1536 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1537 needs_wrapper = True
1538 has_side_effects = True
1541 primop EqStableNameOp "eqStableName#" GenPrimOp
1542 StableName# a -> StableName# a -> Int#
1544 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1546 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1547 StableName# a -> Int#
1549 usage = { mangle StableNameToIntOp [mkP] mkR }
1551 ------------------------------------------------------------------------
1552 section "Unsafe pointer equality"
1553 -- (#1 Bad Guy: Alistair Reid :)
1554 ------------------------------------------------------------------------
1556 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1559 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
1561 ------------------------------------------------------------------------
1562 section "Parallelism"
1563 ------------------------------------------------------------------------
1565 primop ParOp "par#" GenPrimOp
1568 usage = { mangle ParOp [mkO] mkR }
1569 -- Note that Par is lazy to avoid that the sparked thing
1570 -- gets evaluted strictly, which it should *not* be
1571 has_side_effects = True
1573 -- HWL: The first 4 Int# in all par... annotations denote:
1574 -- name, granularity info, size of result, degree of parallelism
1575 -- Same structure as _seq_ i.e. returns Int#
1576 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1577 -- `the processor containing the expression v'; it is not evaluated
1579 primop ParGlobalOp "parGlobal#" GenPrimOp
1580 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1582 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1583 has_side_effects = True
1585 primop ParLocalOp "parLocal#" GenPrimOp
1586 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1588 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1589 has_side_effects = True
1591 primop ParAtOp "parAt#" GenPrimOp
1592 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1594 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1595 has_side_effects = True
1597 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1598 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1600 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1601 has_side_effects = True
1603 primop ParAtRelOp "parAtRel#" GenPrimOp
1604 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1606 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1607 has_side_effects = True
1609 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1610 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1612 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1613 has_side_effects = True
1615 -- copyable# and noFollow# are yet to be implemented (for GpH)
1617 --primop CopyableOp "copyable#" GenPrimOp
1620 -- usage = { mangle CopyableOp [mkZ] mkR }
1621 -- has_side_effects = True
1623 --primop NoFollowOp "noFollow#" GenPrimOp
1626 -- usage = { mangle NoFollowOp [mkZ] mkR }
1627 -- has_side_effects = True
1630 ------------------------------------------------------------------------
1631 section "Tag to enum stuff"
1632 {Convert back and forth between values of enumerated types
1633 and small integers.}
1634 ------------------------------------------------------------------------
1636 primop DataToTagOp "dataToTag#" GenPrimOp
1639 strictness = { \ arity -> mkStrictSig (mkTopDmdType [seqDmd] TopRes) }
1640 -- dataToTag# must have an evaluated argument
1642 primop TagToEnumOp "tagToEnum#" GenPrimOp
1645 ------------------------------------------------------------------------
1646 section "Bytecode operations"
1647 {Support for the bytecode interpreter and linker.}
1648 ------------------------------------------------------------------------
1651 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1653 {Convert an Addr\# to a followable type.}
1655 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1660 primop NewBCOOp "newBCO#" GenPrimOp
1661 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> Int# -> ByteArr# -> State# s -> (# State# s, BCO# #)
1663 has_side_effects = True
1666 ------------------------------------------------------------------------
1668 {{\tt unsafeCoerce\# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1670 ------------------------------------------------------------------------
1673 ------------------------------------------------------------------------
1675 ------------------------------------------------------------------------