1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.35 2005/03/07 15:16:41 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, namely
122 \texttt{lib/std/PrelStorable.lhs},
123 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated
124 fashion) in \texttt{hslibs/lang/ForeignObj.lhs} and
125 \texttt{hslibs/lang/Addr.lhs}.
127 Finally, there are strongly deprecated primops for coercing
128 between {\tt Addr\#}, the primitive type of machine
129 addresses, and {\tt Int\#}. These are pretty bogus anyway,
130 but will work on existing 32-bit and 64-bit GHC targets; they
131 are completely bogus when tag bits are used in {\tt Int\#},
132 so are not available in this case. }
134 -- Define synonyms for indexing ops.
136 #if WORD_SIZE_IN_BITS < 32
138 #define WORD32 Word32#
144 #if WORD_SIZE_IN_BITS < 64
146 #define WORD64 Word64#
152 ------------------------------------------------------------------------
154 {Operations on 31-bit characters.}
155 ------------------------------------------------------------------------
158 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
159 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
161 primop CharEqOp "eqChar#" Compare
162 Char# -> Char# -> Bool
163 with commutable = True
165 primop CharNeOp "neChar#" Compare
166 Char# -> Char# -> Bool
167 with commutable = True
169 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
170 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
172 primop OrdOp "ord#" GenPrimOp Char# -> Int#
174 ------------------------------------------------------------------------
176 {Operations on native-size integers (30+ bits).}
177 ------------------------------------------------------------------------
179 primop IntAddOp "+#" Dyadic
181 with commutable = True
183 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
186 Dyadic Int# -> Int# -> Int#
187 {Low word of signed integer multiply.}
188 with commutable = True
190 primop IntMulMayOfloOp "mulIntMayOflo#"
191 Dyadic Int# -> Int# -> Int#
192 {Return non-zero if there is any possibility that the upper word of a
193 signed integer multiply might contain useful information. Return
194 zero only if you are completely sure that no overflow can occur.
195 On a 32-bit platform, the recommmended implementation is to do a
196 32 x 32 -> 64 signed multiply, and subtract result[63:32] from
197 (result[31] >>signed 31). If this is zero, meaning that the
198 upper word is merely a sign extension of the lower one, no
201 On a 64-bit platform it is not always possible to
202 acquire the top 64 bits of the result. Therefore, a recommended
203 implementation is to take the absolute value of both operands, and
204 return 0 iff bits[63:31] of them are zero, since that means that their
205 magnitudes fit within 31 bits, so the magnitude of the product must fit
208 If in doubt, return non-zero, but do make an effort to create the
209 correct answer for small args, since otherwise the performance of
210 (*) :: Integer -> Integer -> Integer will be poor.
212 with commutable = True
214 primop IntQuotOp "quotInt#" Dyadic
216 {Rounds towards zero.}
219 primop IntRemOp "remInt#" Dyadic
221 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
224 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
225 with out_of_line = True
227 primop IntNegOp "negateInt#" Monadic Int# -> Int#
228 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
229 {Add with carry. First member of result is (wrapped) sum;
230 second member is 0 iff no overflow occured.}
231 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
232 {Subtract with carry. First member of result is (wrapped) difference;
233 second member is 0 iff no overflow occured.}
235 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
236 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
238 primop IntEqOp "==#" Compare
240 with commutable = True
242 primop IntNeOp "/=#" Compare
244 with commutable = True
246 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
247 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
249 primop ChrOp "chr#" GenPrimOp Int# -> Char#
251 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
252 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
253 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
255 primop Int2IntegerOp "int2Integer#"
256 GenPrimOp Int# -> (# Int#, ByteArr# #)
257 with out_of_line = True
259 primop ISllOp "uncheckedIShiftL#" GenPrimOp Int# -> Int# -> Int#
260 {Shift left. Result undefined if shift amount is not
261 in the range 0 to word size - 1 inclusive.}
262 primop ISraOp "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
263 {Shift right arithmetic. Result undefined if shift amount is not
264 in the range 0 to word size - 1 inclusive.}
265 primop ISrlOp "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
266 {Shift right logical. Result undefined if shift amount is not
267 in the range 0 to word size - 1 inclusive.}
269 ------------------------------------------------------------------------
271 {Operations on native-sized unsigned words (30+ bits).}
272 ------------------------------------------------------------------------
274 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
275 with commutable = True
277 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
279 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
280 with commutable = True
282 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
285 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
288 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
289 with commutable = True
291 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
292 with commutable = True
294 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
295 with commutable = True
297 primop NotOp "not#" Monadic Word# -> Word#
299 primop SllOp "uncheckedShiftL#" GenPrimOp Word# -> Int# -> Word#
300 {Shift left logical. Result undefined if shift amount is not
301 in the range 0 to word size - 1 inclusive.}
302 primop SrlOp "uncheckedShiftRL#" GenPrimOp Word# -> Int# -> Word#
303 {Shift right logical. Result undefined if shift amount is not
304 in the range 0 to word size - 1 inclusive.}
306 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
308 primop Word2IntegerOp "word2Integer#" GenPrimOp
309 Word# -> (# Int#, ByteArr# #)
310 with out_of_line = True
312 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
313 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
314 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
315 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
316 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
317 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
319 ------------------------------------------------------------------------
321 {Explicit narrowing of native-sized ints or words.}
322 ------------------------------------------------------------------------
324 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
325 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
326 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
327 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
328 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
329 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
332 #if WORD_SIZE_IN_BITS < 32
333 ------------------------------------------------------------------------
335 {Operations on 32-bit integers (Int32\#). This type is only used
336 if plain Int\# has less than 32 bits. In any case, the operations
337 are not primops; they are implemented (if needed) as ccalls instead.}
338 ------------------------------------------------------------------------
340 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
341 Int32# -> (# Int#, ByteArr# #)
342 with out_of_line = True
345 ------------------------------------------------------------------------
347 {Operations on 32-bit unsigned words. This type is only used
348 if plain Word\# has less than 32 bits. In any case, the operations
349 are not primops; they are implemented (if needed) as ccalls instead.}
350 ------------------------------------------------------------------------
352 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
353 Word32# -> (# Int#, ByteArr# #)
354 with out_of_line = True
360 #if WORD_SIZE_IN_BITS < 64
361 ------------------------------------------------------------------------
363 {Operations on 64-bit unsigned words. This type is only used
364 if plain Int\# has less than 64 bits. In any case, the operations
365 are not primops; they are implemented (if needed) as ccalls instead.}
366 ------------------------------------------------------------------------
368 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
369 Int64# -> (# Int#, ByteArr# #)
370 with out_of_line = True
372 ------------------------------------------------------------------------
374 {Operations on 64-bit unsigned words. This type is only used
375 if plain Word\# has less than 64 bits. In any case, the operations
376 are not primops; they are implemented (if needed) as ccalls instead.}
377 ------------------------------------------------------------------------
379 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
380 Word64# -> (# Int#, ByteArr# #)
381 with out_of_line = True
385 ------------------------------------------------------------------------
387 {Operations on arbitrary-precision integers. These operations are
388 implemented via the GMP package. An integer is represented as a pair
389 consisting of an Int\# representing the number of 'limbs' in use and
390 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
391 are returned as unboxed pairs, but must be passed as separate
394 For .NET these operations are implemented by foreign imports, so the
395 primops are omitted.}
396 ------------------------------------------------------------------------
400 primop IntegerAddOp "plusInteger#" GenPrimOp
401 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
402 with commutable = True
405 primop IntegerSubOp "minusInteger#" GenPrimOp
406 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
407 with out_of_line = True
409 primop IntegerMulOp "timesInteger#" GenPrimOp
410 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
411 with commutable = True
414 primop IntegerGcdOp "gcdInteger#" GenPrimOp
415 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
416 {Greatest common divisor.}
417 with commutable = True
420 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
421 Int# -> ByteArr# -> Int# -> Int#
422 {Greatest common divisor, where second argument is an ordinary Int\#.}
423 with out_of_line = True
425 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
426 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
427 {Divisor is guaranteed to be a factor of dividend.}
428 with out_of_line = True
430 primop IntegerQuotOp "quotInteger#" GenPrimOp
431 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
432 {Rounds towards zero.}
433 with out_of_line = True
435 primop IntegerRemOp "remInteger#" GenPrimOp
436 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
437 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
438 with out_of_line = True
440 primop IntegerCmpOp "cmpInteger#" GenPrimOp
441 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
442 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
443 with needs_wrapper = True
446 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
447 Int# -> ByteArr# -> Int# -> Int#
448 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
449 is an ordinary Int\#.}
450 with needs_wrapper = True
453 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
454 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
455 {Compute quot and rem simulaneously.}
459 primop IntegerDivModOp "divModInteger#" GenPrimOp
460 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
461 {Compute div and mod simultaneously, where div rounds towards negative infinity
462 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
466 primop Integer2IntOp "integer2Int#" GenPrimOp
467 Int# -> ByteArr# -> Int#
468 with needs_wrapper = True
471 primop Integer2WordOp "integer2Word#" GenPrimOp
472 Int# -> ByteArr# -> Word#
473 with needs_wrapper = True
476 #if WORD_SIZE_IN_BITS < 32
477 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
478 Int# -> ByteArr# -> Int32#
480 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
481 Int# -> ByteArr# -> Word32#
484 primop IntegerAndOp "andInteger#" GenPrimOp
485 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
486 with out_of_line = True
488 primop IntegerOrOp "orInteger#" GenPrimOp
489 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
490 with out_of_line = True
492 primop IntegerXorOp "xorInteger#" GenPrimOp
493 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
494 with out_of_line = True
496 primop IntegerComplementOp "complementInteger#" GenPrimOp
497 Int# -> ByteArr# -> (# Int#, ByteArr# #)
498 with out_of_line = True
500 #endif /* ndef ILX */
502 ------------------------------------------------------------------------
504 {Operations on double-precision (64 bit) floating-point numbers.}
505 ------------------------------------------------------------------------
507 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
508 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
510 primop DoubleEqOp "==##" Compare
511 Double# -> Double# -> Bool
512 with commutable = True
514 primop DoubleNeOp "/=##" Compare
515 Double# -> Double# -> Bool
516 with commutable = True
518 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
519 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
521 primop DoubleAddOp "+##" Dyadic
522 Double# -> Double# -> Double#
523 with commutable = True
525 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
527 primop DoubleMulOp "*##" Dyadic
528 Double# -> Double# -> Double#
529 with commutable = True
531 primop DoubleDivOp "/##" Dyadic
532 Double# -> Double# -> Double#
535 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
537 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
538 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
540 primop DoubleExpOp "expDouble#" Monadic
542 with needs_wrapper = True
544 primop DoubleLogOp "logDouble#" Monadic
550 primop DoubleSqrtOp "sqrtDouble#" Monadic
552 with needs_wrapper = True
554 primop DoubleSinOp "sinDouble#" Monadic
556 with needs_wrapper = True
558 primop DoubleCosOp "cosDouble#" Monadic
560 with needs_wrapper = True
562 primop DoubleTanOp "tanDouble#" Monadic
564 with needs_wrapper = True
566 primop DoubleAsinOp "asinDouble#" Monadic
572 primop DoubleAcosOp "acosDouble#" Monadic
578 primop DoubleAtanOp "atanDouble#" Monadic
583 primop DoubleSinhOp "sinhDouble#" Monadic
585 with needs_wrapper = True
587 primop DoubleCoshOp "coshDouble#" Monadic
589 with needs_wrapper = True
591 primop DoubleTanhOp "tanhDouble#" Monadic
593 with needs_wrapper = True
595 primop DoublePowerOp "**##" Dyadic
596 Double# -> Double# -> Double#
598 with needs_wrapper = True
600 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
601 Double# -> (# Int#, Int#, ByteArr# #)
602 {Convert to arbitrary-precision integer.
603 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
604 holding the mantissa.}
605 with out_of_line = True
607 ------------------------------------------------------------------------
609 {Operations on single-precision (32-bit) floating-point numbers.}
610 ------------------------------------------------------------------------
612 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
613 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
615 primop FloatEqOp "eqFloat#" Compare
616 Float# -> Float# -> Bool
617 with commutable = True
619 primop FloatNeOp "neFloat#" Compare
620 Float# -> Float# -> Bool
621 with commutable = True
623 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
624 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
626 primop FloatAddOp "plusFloat#" Dyadic
627 Float# -> Float# -> Float#
628 with commutable = True
630 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
632 primop FloatMulOp "timesFloat#" Dyadic
633 Float# -> Float# -> Float#
634 with commutable = True
636 primop FloatDivOp "divideFloat#" Dyadic
637 Float# -> Float# -> Float#
640 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
642 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
644 primop FloatExpOp "expFloat#" Monadic
646 with needs_wrapper = True
648 primop FloatLogOp "logFloat#" Monadic
650 with needs_wrapper = True
653 primop FloatSqrtOp "sqrtFloat#" Monadic
655 with needs_wrapper = True
657 primop FloatSinOp "sinFloat#" Monadic
659 with needs_wrapper = True
661 primop FloatCosOp "cosFloat#" Monadic
663 with needs_wrapper = True
665 primop FloatTanOp "tanFloat#" Monadic
667 with needs_wrapper = True
669 primop FloatAsinOp "asinFloat#" Monadic
671 with needs_wrapper = True
674 primop FloatAcosOp "acosFloat#" Monadic
676 with needs_wrapper = True
679 primop FloatAtanOp "atanFloat#" Monadic
681 with needs_wrapper = True
683 primop FloatSinhOp "sinhFloat#" Monadic
685 with needs_wrapper = True
687 primop FloatCoshOp "coshFloat#" Monadic
689 with needs_wrapper = True
691 primop FloatTanhOp "tanhFloat#" Monadic
693 with needs_wrapper = True
695 primop FloatPowerOp "powerFloat#" Dyadic
696 Float# -> Float# -> Float#
697 with needs_wrapper = True
699 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
701 primop FloatDecodeOp "decodeFloat#" GenPrimOp
702 Float# -> (# Int#, Int#, ByteArr# #)
703 {Convert to arbitrary-precision integer.
704 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
705 holding the mantissa.}
706 with out_of_line = True
708 ------------------------------------------------------------------------
710 {Operations on Array\#.}
711 ------------------------------------------------------------------------
713 primop NewArrayOp "newArray#" GenPrimOp
714 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
715 {Create a new mutable array of specified size (in bytes),
716 in the specified state thread,
717 with each element containing the specified initial value.}
719 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
722 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
723 MutArr# s a -> MutArr# s a -> Bool
725 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
727 primop ReadArrayOp "readArray#" GenPrimOp
728 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
729 {Read from specified index of mutable array. Result is not yet evaluated.}
731 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
733 primop WriteArrayOp "writeArray#" GenPrimOp
734 MutArr# s a -> Int# -> a -> State# s -> State# s
735 {Write to specified index of mutable array.}
737 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
738 has_side_effects = True
740 primop IndexArrayOp "indexArray#" GenPrimOp
741 Array# a -> Int# -> (# a #)
742 {Read from specified index of immutable array. Result is packaged into
743 an unboxed singleton; the result itself is not yet evaluated.}
745 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
747 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
748 MutArr# s a -> State# s -> (# State# s, Array# a #)
749 {Make a mutable array immutable, without copying.}
751 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
752 has_side_effects = True
754 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
755 Array# a -> State# s -> (# State# s, MutArr# s a #)
756 {Make an immutable array mutable, without copying.}
758 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
761 ------------------------------------------------------------------------
762 section "Byte Arrays"
763 {Operations on ByteArray\#. A ByteArray\# is a just a region of
764 raw memory in the garbage-collected heap, which is not scanned
765 for pointers. It carries its own size (in bytes). There are
766 three sets of operations for accessing byte array contents:
767 index for reading from immutable byte arrays, and read/write
768 for mutable byte arrays. Each set contains operations for
769 a range of useful primitive data types. Each operation takes
770 an offset measured in terms of the size fo the primitive type
771 being read or written.}
773 ------------------------------------------------------------------------
775 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
776 Int# -> State# s -> (# State# s, MutByteArr# s #)
777 {Create a new mutable byte array of specified size (in bytes), in
778 the specified state thread.}
779 with out_of_line = True
781 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
782 Int# -> State# s -> (# State# s, MutByteArr# s #)
783 {Create a mutable byte array that the GC guarantees not to move.}
784 with out_of_line = True
786 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
788 {Intended for use with pinned arrays; otherwise very unsafe!}
790 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
791 MutByteArr# s -> MutByteArr# s -> Bool
793 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
794 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
795 {Make a mutable byte array immutable, without copying.}
797 has_side_effects = True
799 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
802 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
803 MutByteArr# s -> Int#
806 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
807 ByteArr# -> Int# -> Char#
808 {Read 8-bit character; offset in bytes.}
810 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
811 ByteArr# -> Int# -> Char#
812 {Read 31-bit character; offset in 4-byte words.}
814 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
815 ByteArr# -> Int# -> Int#
817 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
818 ByteArr# -> Int# -> Word#
820 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
821 ByteArr# -> Int# -> Addr#
823 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
824 ByteArr# -> Int# -> Float#
826 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
827 ByteArr# -> Int# -> Double#
829 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
830 ByteArr# -> Int# -> StablePtr# a
832 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
833 ByteArr# -> Int# -> Int#
835 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
836 ByteArr# -> Int# -> Int#
838 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
839 ByteArr# -> Int# -> INT32
841 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
842 ByteArr# -> Int# -> INT64
844 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
845 ByteArr# -> Int# -> Word#
847 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
848 ByteArr# -> Int# -> Word#
850 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
851 ByteArr# -> Int# -> WORD32
853 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
854 ByteArr# -> Int# -> WORD64
856 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
857 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
858 {Read 8-bit character; offset in bytes.}
860 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
861 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
862 {Read 31-bit character; offset in 4-byte words.}
864 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
865 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
867 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
868 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
870 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
871 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
873 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
874 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
876 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
877 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
879 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
880 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
882 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
883 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
885 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
886 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
888 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
889 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
891 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
892 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
894 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
895 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
897 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
898 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
900 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
901 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
903 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
904 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
906 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
907 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
908 {Write 8-bit character; offset in bytes.}
909 with has_side_effects = True
911 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
912 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
913 {Write 31-bit character; offset in 4-byte words.}
914 with has_side_effects = True
916 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
917 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
918 with has_side_effects = True
920 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
921 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
922 with has_side_effects = True
924 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
925 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
926 with has_side_effects = True
928 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
929 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
930 with has_side_effects = True
932 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
933 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
934 with has_side_effects = True
936 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
937 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
938 with has_side_effects = True
940 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
941 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
942 with has_side_effects = True
944 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
945 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
946 with has_side_effects = True
948 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
949 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
950 with has_side_effects = True
952 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
953 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
954 with has_side_effects = True
956 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
957 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
958 with has_side_effects = True
960 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
961 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
962 with has_side_effects = True
964 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
965 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
966 with has_side_effects = True
968 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
969 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
970 with has_side_effects = True
972 ------------------------------------------------------------------------
974 {Addr\# is an arbitrary machine address assumed to point outside
975 the garbage-collected heap.
977 NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
978 It is the null address.}
979 ------------------------------------------------------------------------
981 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
982 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
983 {Result is meaningless if two Addr\#s are so far apart that their
984 difference doesn't fit in an Int\#.}
985 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
986 {Return the remainder when the Addr\# arg, treated like an Int\#,
987 is divided by the Int\# arg.}
988 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
989 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
990 {Coerce directly from address to int. Strongly deprecated.}
991 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
992 {Coerce directly from int to address. Strongly deprecated.}
995 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
996 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
997 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
998 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
999 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
1000 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
1002 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
1003 Addr# -> Int# -> Char#
1004 {Reads 8-bit character; offset in bytes.}
1006 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
1007 Addr# -> Int# -> Char#
1008 {Reads 31-bit character; offset in 4-byte words.}
1010 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
1011 Addr# -> Int# -> Int#
1013 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
1014 Addr# -> Int# -> Word#
1016 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
1017 Addr# -> Int# -> Addr#
1019 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
1020 Addr# -> Int# -> Float#
1022 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
1023 Addr# -> Int# -> Double#
1025 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
1026 Addr# -> Int# -> StablePtr# a
1028 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
1029 Addr# -> Int# -> Int#
1031 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1032 Addr# -> Int# -> Int#
1034 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1035 Addr# -> Int# -> INT32
1037 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1038 Addr# -> Int# -> INT64
1040 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1041 Addr# -> Int# -> Word#
1043 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1044 Addr# -> Int# -> Word#
1046 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1047 Addr# -> Int# -> WORD32
1049 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1050 Addr# -> Int# -> WORD64
1052 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1053 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1054 {Reads 8-bit character; offset in bytes.}
1056 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1057 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1058 {Reads 31-bit character; offset in 4-byte words.}
1060 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1061 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1063 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1064 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1066 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1067 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1069 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1070 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1072 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1073 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1075 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1076 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1078 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1079 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1081 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1082 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1084 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1085 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1087 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1088 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1090 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1091 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1093 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1094 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1096 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1097 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1099 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1100 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1103 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1104 Addr# -> Int# -> Char# -> State# s -> State# s
1105 with has_side_effects = True
1107 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1108 Addr# -> Int# -> Char# -> State# s -> State# s
1109 with has_side_effects = True
1111 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1112 Addr# -> Int# -> Int# -> State# s -> State# s
1113 with has_side_effects = True
1115 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1116 Addr# -> Int# -> Word# -> State# s -> State# s
1117 with has_side_effects = True
1119 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1120 Addr# -> Int# -> Addr# -> State# s -> State# s
1121 with has_side_effects = True
1123 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1124 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1125 with has_side_effects = True
1127 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1128 Addr# -> Int# -> Float# -> State# s -> State# s
1129 with has_side_effects = True
1131 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1132 Addr# -> Int# -> Double# -> State# s -> State# s
1133 with has_side_effects = True
1135 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1136 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1137 with has_side_effects = True
1139 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1140 Addr# -> Int# -> Int# -> State# s -> State# s
1141 with has_side_effects = True
1143 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1144 Addr# -> Int# -> Int# -> State# s -> State# s
1145 with has_side_effects = True
1147 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1148 Addr# -> Int# -> INT32 -> State# s -> State# s
1149 with has_side_effects = True
1151 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1152 Addr# -> Int# -> INT64 -> State# s -> State# s
1153 with has_side_effects = True
1155 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1156 Addr# -> Int# -> Word# -> State# s -> State# s
1157 with has_side_effects = True
1159 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1160 Addr# -> Int# -> Word# -> State# s -> State# s
1161 with has_side_effects = True
1163 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1164 Addr# -> Int# -> WORD32 -> State# s -> State# s
1165 with has_side_effects = True
1167 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1168 Addr# -> Int# -> WORD64 -> State# s -> State# s
1169 with has_side_effects = True
1171 ------------------------------------------------------------------------
1172 section "ForeignObj#"
1173 {Operations on ForeignObj\#. The indexing operations are
1175 ------------------------------------------------------------------------
1177 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1178 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1180 has_side_effects = True
1183 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1184 ForeignObj# -> Addr# -> State# s -> State# s
1186 has_side_effects = True
1188 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1189 ForeignObj# -> Addr#
1191 primop TouchOp "touch#" GenPrimOp
1192 o -> State# RealWorld -> State# RealWorld
1194 has_side_effects = True
1196 primop EqForeignObj "eqForeignObj#" GenPrimOp
1197 ForeignObj# -> ForeignObj# -> Bool
1198 with commutable = True
1200 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1201 ForeignObj# -> Int# -> Char#
1202 {Read 8-bit character; offset in bytes.}
1204 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1205 ForeignObj# -> Int# -> Char#
1206 {Read 31-bit character; offset in 4-byte words.}
1208 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1209 ForeignObj# -> Int# -> Int#
1211 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1212 ForeignObj# -> Int# -> Word#
1214 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1215 ForeignObj# -> Int# -> Addr#
1217 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1218 ForeignObj# -> Int# -> Float#
1220 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1221 ForeignObj# -> Int# -> Double#
1223 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1224 ForeignObj# -> Int# -> StablePtr# a
1226 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1227 ForeignObj# -> Int# -> Int#
1229 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1230 ForeignObj# -> Int# -> Int#
1232 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1233 ForeignObj# -> Int# -> INT32
1235 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1236 ForeignObj# -> Int# -> INT64
1238 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1239 ForeignObj# -> Int# -> Word#
1241 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1242 ForeignObj# -> Int# -> Word#
1244 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1245 ForeignObj# -> Int# -> WORD32
1247 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1248 ForeignObj# -> Int# -> WORD64
1252 ------------------------------------------------------------------------
1253 section "Mutable variables"
1254 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1255 ------------------------------------------------------------------------
1257 primop NewMutVarOp "newMutVar#" GenPrimOp
1258 a -> State# s -> (# State# s, MutVar# s a #)
1259 {Create MutVar\# with specified initial value in specified state thread.}
1261 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1264 primop ReadMutVarOp "readMutVar#" GenPrimOp
1265 MutVar# s a -> State# s -> (# State# s, a #)
1266 {Read contents of MutVar\#. Result is not yet evaluated.}
1268 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1270 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1271 MutVar# s a -> a -> State# s -> State# s
1272 {Write contents of MutVar\#.}
1274 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1275 has_side_effects = True
1277 primop SameMutVarOp "sameMutVar#" GenPrimOp
1278 MutVar# s a -> MutVar# s a -> Bool
1280 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1282 -- not really the right type, but we don't know about pairs here. The
1285 -- MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
1287 primop AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp
1288 MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #)
1290 usage = { mangle AtomicModifyMutVarOp [mkP, mkM, mkP] mkM }
1291 has_side_effects = True
1294 ------------------------------------------------------------------------
1295 section "Exceptions"
1296 ------------------------------------------------------------------------
1298 primop CatchOp "catch#" GenPrimOp
1299 (State# RealWorld -> (# State# RealWorld, a #) )
1300 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1302 -> (# State# RealWorld, a #)
1304 -- Catch is actually strict in its first argument
1305 -- but we don't want to tell the strictness
1306 -- analyser about that!
1307 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1308 -- [mkO, mkO . (inFun mkM mkO)] mkO
1309 -- might use caught action multiply
1312 primop RaiseOp "raise#" GenPrimOp
1315 strictness = { \ arity -> mkStrictSig (mkTopDmdType [lazyDmd] BotRes) }
1316 -- NB: result is bottom
1317 usage = { mangle RaiseOp [mkM] mkM }
1320 -- raiseIO# needs to be a primop, because exceptions in the IO monad
1321 -- must be *precise* - we don't want the strictness analyser turning
1322 -- one kind of bottom into another, as it is allowed to do in pure code.
1324 primop RaiseIOOp "raiseIO#" GenPrimOp
1325 a -> State# RealWorld -> (# State# RealWorld, b #)
1329 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1330 (State# RealWorld -> (# State# RealWorld, a #))
1331 -> (State# RealWorld -> (# State# RealWorld, a #))
1335 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1336 (State# RealWorld -> (# State# RealWorld, a #))
1337 -> (State# RealWorld -> (# State# RealWorld, a #))
1341 ------------------------------------------------------------------------
1342 section "STM-accessible Mutable Variables"
1343 ------------------------------------------------------------------------
1345 primop AtomicallyOp "atomically#" GenPrimOp
1346 (State# RealWorld -> (# State# RealWorld, a #) )
1347 -> State# RealWorld -> (# State# RealWorld, a #)
1350 has_side_effects = True
1352 primop RetryOp "retry#" GenPrimOp
1353 State# RealWorld -> (# State# RealWorld, a #)
1356 has_side_effects = True
1358 primop CatchRetryOp "catchRetry#" GenPrimOp
1359 (State# RealWorld -> (# State# RealWorld, a #) )
1360 -> (State# RealWorld -> (# State# RealWorld, a #) )
1361 -> (State# RealWorld -> (# State# RealWorld, a #) )
1364 has_side_effects = True
1366 primop CatchSTMOp "catchSTM#" GenPrimOp
1367 (State# RealWorld -> (# State# RealWorld, a #) )
1368 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1369 -> (State# RealWorld -> (# State# RealWorld, a #) )
1372 has_side_effects = True
1374 primop NewTVarOp "newTVar#" GenPrimOp
1376 -> State# s -> (# State# s, TVar# s a #)
1377 {Create a new Tar\# holding a specified initial value.}
1381 primop ReadTVarOp "readTVar#" GenPrimOp
1383 -> State# s -> (# State# s, a #)
1384 {Read contents of TVar\#. Result is not yet evaluated.}
1388 primop WriteTVarOp "writeTVar#" GenPrimOp
1391 -> State# s -> State# s
1392 {Write contents of TVar\#.}
1395 has_side_effects = True
1397 primop SameTVarOp "sameTVar#" GenPrimOp
1398 TVar# s a -> TVar# s a -> Bool
1401 ------------------------------------------------------------------------
1402 section "Synchronized Mutable Variables"
1403 {Operations on MVar\#s, which are shared mutable variables
1404 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1405 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1406 ------------------------------------------------------------------------
1409 primop NewMVarOp "newMVar#" GenPrimOp
1410 State# s -> (# State# s, MVar# s a #)
1411 {Create new mvar; initially empty.}
1413 usage = { mangle NewMVarOp [mkP] mkR }
1416 primop TakeMVarOp "takeMVar#" GenPrimOp
1417 MVar# s a -> State# s -> (# State# s, a #)
1418 {If mvar is empty, block until it becomes full.
1419 Then remove and return its contents, and set it empty.}
1421 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1422 has_side_effects = True
1425 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1426 MVar# s a -> State# s -> (# State# s, Int#, a #)
1427 {If mvar is empty, immediately return with integer 0 and value undefined.
1428 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1430 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1431 has_side_effects = True
1434 primop PutMVarOp "putMVar#" GenPrimOp
1435 MVar# s a -> a -> State# s -> State# s
1436 {If mvar is full, block until it becomes empty.
1437 Then store value arg as its new contents.}
1439 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1440 has_side_effects = True
1443 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1444 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1445 {If mvar is full, immediately return with integer 0.
1446 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1448 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1449 has_side_effects = True
1452 primop SameMVarOp "sameMVar#" GenPrimOp
1453 MVar# s a -> MVar# s a -> Bool
1455 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1457 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1458 MVar# s a -> State# s -> (# State# s, Int# #)
1459 {Return 1 if mvar is empty; 0 otherwise.}
1461 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1464 ------------------------------------------------------------------------
1465 section "Delay/wait operations"
1466 ------------------------------------------------------------------------
1468 primop DelayOp "delay#" GenPrimOp
1469 Int# -> State# s -> State# s
1470 {Sleep specified number of microseconds.}
1472 needs_wrapper = True
1473 has_side_effects = True
1476 primop WaitReadOp "waitRead#" GenPrimOp
1477 Int# -> State# s -> State# s
1478 {Block until input is available on specified file descriptor.}
1480 needs_wrapper = True
1481 has_side_effects = True
1484 primop WaitWriteOp "waitWrite#" GenPrimOp
1485 Int# -> State# s -> State# s
1486 {Block until output is possible on specified file descriptor.}
1488 needs_wrapper = True
1489 has_side_effects = True
1492 #ifdef mingw32_TARGET_OS
1493 primop AsyncReadOp "asyncRead#" GenPrimOp
1494 Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1495 {Asynchronously read bytes from specified file descriptor.}
1497 needs_wrapper = True
1498 has_side_effects = True
1501 primop AsyncWriteOp "asyncWrite#" GenPrimOp
1502 Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1503 {Asynchronously write bytes from specified file descriptor.}
1505 needs_wrapper = True
1506 has_side_effects = True
1509 primop AsyncDoProcOp "asyncDoProc#" GenPrimOp
1510 Addr# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1511 {Asynchronously perform procedure (first arg), passing it 2nd arg.}
1513 needs_wrapper = True
1514 has_side_effects = True
1519 ------------------------------------------------------------------------
1520 section "Concurrency primitives"
1521 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1522 type, whose (unique) value is returned by myThreadId\#. The
1523 other operations can be omitted.)}
1524 ------------------------------------------------------------------------
1526 primop ForkOp "fork#" GenPrimOp
1527 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1529 usage = { mangle ForkOp [mkO, mkP] mkR }
1530 has_side_effects = True
1533 primop KillThreadOp "killThread#" GenPrimOp
1534 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1536 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1537 has_side_effects = True
1540 primop YieldOp "yield#" GenPrimOp
1541 State# RealWorld -> State# RealWorld
1543 has_side_effects = True
1546 primop MyThreadIdOp "myThreadId#" GenPrimOp
1547 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1551 primop LabelThreadOp "labelThread#" GenPrimOp
1552 ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
1554 has_side_effects = True
1557 primop IsCurrentThreadBoundOp "isCurrentThreadBound#" GenPrimOp
1558 State# RealWorld -> (# State# RealWorld, Int# #)
1562 ------------------------------------------------------------------------
1563 section "Weak pointers"
1564 ------------------------------------------------------------------------
1566 -- note that tyvar "o" denotes openAlphaTyVar
1568 primop MkWeakOp "mkWeak#" GenPrimOp
1569 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1571 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1572 has_side_effects = True
1575 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1576 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1578 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1579 has_side_effects = True
1582 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1583 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1584 (State# RealWorld -> (# State# RealWorld, () #)) #)
1586 usage = { mangle FinalizeWeakOp [mkM, mkP]
1587 (mkR . (inUB FinalizeWeakOp
1588 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1589 has_side_effects = True
1592 ------------------------------------------------------------------------
1593 section "Stable pointers and names"
1594 ------------------------------------------------------------------------
1596 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1597 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1599 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1600 has_side_effects = True
1603 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1604 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1606 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1607 needs_wrapper = True
1608 has_side_effects = True
1611 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1612 StablePtr# a -> StablePtr# a -> Int#
1614 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1615 has_side_effects = True
1617 primop MakeStableNameOp "makeStableName#" GenPrimOp
1618 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1620 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1621 needs_wrapper = True
1622 has_side_effects = True
1625 primop EqStableNameOp "eqStableName#" GenPrimOp
1626 StableName# a -> StableName# a -> Int#
1628 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1630 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1631 StableName# a -> Int#
1633 usage = { mangle StableNameToIntOp [mkP] mkR }
1635 ------------------------------------------------------------------------
1636 section "Unsafe pointer equality"
1637 -- (#1 Bad Guy: Alistair Reid :)
1638 ------------------------------------------------------------------------
1640 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1643 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
1645 ------------------------------------------------------------------------
1646 section "Parallelism"
1647 ------------------------------------------------------------------------
1649 primop ParOp "par#" GenPrimOp
1652 usage = { mangle ParOp [mkO] mkR }
1653 -- Note that Par is lazy to avoid that the sparked thing
1654 -- gets evaluted strictly, which it should *not* be
1655 has_side_effects = True
1657 -- HWL: The first 4 Int# in all par... annotations denote:
1658 -- name, granularity info, size of result, degree of parallelism
1659 -- Same structure as _seq_ i.e. returns Int#
1660 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1661 -- `the processor containing the expression v'; it is not evaluated
1663 primop ParGlobalOp "parGlobal#" GenPrimOp
1664 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1666 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1667 has_side_effects = True
1669 primop ParLocalOp "parLocal#" GenPrimOp
1670 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1672 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1673 has_side_effects = True
1675 primop ParAtOp "parAt#" GenPrimOp
1676 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1678 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1679 has_side_effects = True
1681 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1682 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1684 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1685 has_side_effects = True
1687 primop ParAtRelOp "parAtRel#" GenPrimOp
1688 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1690 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1691 has_side_effects = True
1693 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1694 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1696 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1697 has_side_effects = True
1699 -- copyable# and noFollow# are yet to be implemented (for GpH)
1701 --primop CopyableOp "copyable#" GenPrimOp
1704 -- usage = { mangle CopyableOp [mkZ] mkR }
1705 -- has_side_effects = True
1707 --primop NoFollowOp "noFollow#" GenPrimOp
1710 -- usage = { mangle NoFollowOp [mkZ] mkR }
1711 -- has_side_effects = True
1714 ------------------------------------------------------------------------
1715 section "Tag to enum stuff"
1716 {Convert back and forth between values of enumerated types
1717 and small integers.}
1718 ------------------------------------------------------------------------
1720 primop DataToTagOp "dataToTag#" GenPrimOp
1723 strictness = { \ arity -> mkStrictSig (mkTopDmdType [seqDmd] TopRes) }
1724 -- dataToTag# must have an evaluated argument
1726 primop TagToEnumOp "tagToEnum#" GenPrimOp
1729 ------------------------------------------------------------------------
1730 section "Bytecode operations"
1731 {Support for the bytecode interpreter and linker.}
1732 ------------------------------------------------------------------------
1735 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1737 {Convert an Addr\# to a followable type.}
1739 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1744 primop NewBCOOp "newBCO#" GenPrimOp
1745 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> Int# -> ByteArr# -> State# s -> (# State# s, BCO# #)
1747 has_side_effects = True
1750 ------------------------------------------------------------------------
1752 {{\tt unsafeCoerce\# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1754 ------------------------------------------------------------------------
1757 ------------------------------------------------------------------------
1759 ------------------------------------------------------------------------