1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.15 2001/12/18 15:23:16 sewardj Exp $
4 -- Primitive Operations
6 -----------------------------------------------------------------------
8 -- This file is processed by the utility program genprimopcode to produce
9 -- a number of include files within the compiler and optionally to produce
10 -- human-readable documentation.
12 -- It should first be preprocessed.
14 -- To add a new primop, you currently need to update the following files:
16 -- - this file (ghc/compiler/prelude/primops.txt.pp), which includes
17 -- the type of the primop, and various other properties (its
18 -- strictness attributes, whether it is defined as a macro
19 -- or as out-of-line code, etc.)
21 -- - ghc/lib/std/PrelGHC.hi-boot, to declare the primop
23 -- - if the primop is inline (i.e. a macro), then:
24 -- ghc/includes/PrimOps.h
25 -- ghc/compiler/nativeGen/StixPrim.lhs
26 -- ghc/compiler/nativeGen/MachCode.lhs (if implementation is machine-dependent)
28 -- - or, for an out-of-line primop:
29 -- ghc/includes/PrimOps.h (just add the declaration)
30 -- ghc/rts/PrimOps.hc (define it here)
35 -- This file is divided into named sections, each containing or more
36 -- primop entries. Section headers have the format:
38 -- section "section-name" {description}
40 -- This information is used solely when producing documentation; it is
41 -- otherwise ignored. The description is optional.
43 -- The format of each primop entry is as follows:
45 -- primop internal-name "name-in-program-text" type category {description} attributes
47 -- The default attribute values which apply if you don't specify
48 -- other ones. Attribute values can be True, False, or arbitrary
49 -- text between curly brackets. This is a kludge to enable
50 -- processors of this file to easily get hold of simple info
51 -- (eg, out_of_line), whilst avoiding parsing complex expressions
52 -- needed for strictness and usage info.
55 has_side_effects = False
60 strictness = { \ arity -> mkStrictSig (mkTopDmdType (replicate arity lazyDmd) TopRes) }
61 usage = { nomangle other }
63 -- Currently, documentation is produced using latex, so contents of
64 -- description fields should be legal latex. Descriptions can contain
65 -- matched pairs of embedded curly brackets.
69 section "The word size story."
70 {Haskell98 specifies that signed integers (type {\tt Int})
71 must contain at least 30 bits. GHC always implements {\tt
72 Int} using the primitive type {\tt Int\#}, whose size equals
73 the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
74 This is normally set based on the {\tt config.h} parameter
75 {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
76 bits on 64-bit machines. However, it can also be explicitly
77 set to a smaller number, e.g., 31 bits, to allow the
78 possibility of using tag bits. Currently GHC itself has only
79 32-bit and 64-bit variants, but 30 or 31-bit code can be
80 exported as an external core file for use in other back ends.
82 GHC also implements a primitive unsigned integer type {\tt
83 Word\#} which always has the same number of bits as {\tt
86 In addition, GHC supports families of explicit-sized integers
87 and words at 8, 16, 32, and 64 bits, with the usual
88 arithmetic operations, comparisons, and a range of
89 conversions. The 8-bit and 16-bit sizes are always
90 represented as {\tt Int\#} and {\tt Word\#}, and the
91 operations implemented in terms of the the primops on these
92 types, with suitable range restrictions on the results (using
93 the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
94 of primops. The 32-bit sizes are represented using {\tt
95 Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
96 $\geq$ 32; otherwise, these are represented using distinct
97 primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
98 needed) have a complete set of corresponding operations;
99 however, nearly all of these are implemented as external C
100 functions rather than as primops. Exactly the same story
101 applies to the 64-bit sizes. All of these details are hidden
102 under the {\tt PrelInt} and {\tt PrelWord} modules, which use
103 {\tt \#if}-defs to invoke the appropriate types and
106 Word size also matters for the families of primops for
107 indexing/reading/writing fixed-size quantities at offsets
108 from an array base, address, or foreign pointer. Here, a
109 slightly different approach is taken. The names of these
110 primops are fixed, but their {\it types} vary according to
111 the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
112 size is at least 32 bits then an operator like
113 \texttt{indexInt32Array\#} has type {\tt ByteArr\# -> Int\#
114 -> Int\#}; otherwise it has type {\tt ByteArr\# -> Int\# ->
115 Int32\#}. This approach confines the necessary {\tt
116 \#if}-defs to this file; no conditional compilation is needed
117 in the files that expose these primops, namely
118 \texttt{lib/std/PrelStorable.lhs},
119 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated
120 fashion) in \texttt{hslibs/lang/ForeignObj.lhs} and
121 \texttt{hslibs/lang/Addr.lhs}.
123 Finally, there are strongly deprecated primops for coercing
124 between {\tt Addr\#}, the primitive type of machine
125 addresses, and {\tt Int\#}. These are pretty bogus anyway,
126 but will work on existing 32-bit and 64-bit GHC targets; they
127 are completely bogus when tag bits are used in {\tt Int\#},
128 so are not available in this case. }
130 -- Define synonyms for indexing ops.
132 #if WORD_SIZE_IN_BITS < 32
134 #define WORD32 Word32#
140 #if WORD_SIZE_IN_BITS < 64
142 #define WORD64 Word64#
148 ------------------------------------------------------------------------
150 {Operations on 31-bit characters.}
151 ------------------------------------------------------------------------
154 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
155 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
157 primop CharEqOp "eqChar#" Compare
158 Char# -> Char# -> Bool
159 with commutable = True
161 primop CharNeOp "neChar#" Compare
162 Char# -> Char# -> Bool
163 with commutable = True
165 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
166 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
168 primop OrdOp "ord#" GenPrimOp Char# -> Int#
170 ------------------------------------------------------------------------
172 {Operations on native-size integers (30+ bits).}
173 ------------------------------------------------------------------------
175 primop IntAddOp "+#" Dyadic
177 with commutable = True
179 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
182 Dyadic Int# -> Int# -> Int#
183 {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_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1120 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1121 with has_side_effects = True
1123 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1124 Addr# -> Int# -> Float# -> State# s -> State# s
1125 with has_side_effects = True
1127 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1128 Addr# -> Int# -> Double# -> State# s -> State# s
1129 with has_side_effects = True
1131 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1132 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1133 with has_side_effects = True
1135 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1136 Addr# -> Int# -> Int# -> State# s -> State# s
1137 with has_side_effects = True
1139 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1140 Addr# -> Int# -> Int# -> State# s -> State# s
1141 with has_side_effects = True
1143 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1144 Addr# -> Int# -> INT32 -> State# s -> State# s
1145 with has_side_effects = True
1147 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1148 Addr# -> Int# -> INT64 -> State# s -> State# s
1149 with has_side_effects = True
1151 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1152 Addr# -> Int# -> Word# -> State# s -> State# s
1153 with has_side_effects = True
1155 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1156 Addr# -> Int# -> Word# -> State# s -> State# s
1157 with has_side_effects = True
1159 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1160 Addr# -> Int# -> WORD32 -> State# s -> State# s
1161 with has_side_effects = True
1163 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1164 Addr# -> Int# -> WORD64 -> State# s -> State# s
1165 with has_side_effects = True
1167 ------------------------------------------------------------------------
1168 section "ForeignObj#"
1169 {Operations on ForeignObj\#. The indexing operations are
1171 ------------------------------------------------------------------------
1173 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1174 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1176 has_side_effects = True
1179 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1180 ForeignObj# -> Addr# -> State# s -> State# s
1182 has_side_effects = True
1184 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1185 ForeignObj# -> Addr#
1187 primop TouchOp "touch#" GenPrimOp
1188 o -> State# RealWorld -> State# RealWorld
1190 has_side_effects = True
1192 primop EqForeignObj "eqForeignObj#" GenPrimOp
1193 ForeignObj# -> ForeignObj# -> Bool
1194 with commutable = True
1196 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1197 ForeignObj# -> Int# -> Char#
1198 {Read 8-bit character; offset in bytes.}
1200 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1201 ForeignObj# -> Int# -> Char#
1202 {Read 31-bit character; offset in 4-byte words.}
1204 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1205 ForeignObj# -> Int# -> Int#
1207 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1208 ForeignObj# -> Int# -> Word#
1210 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1211 ForeignObj# -> Int# -> Addr#
1213 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1214 ForeignObj# -> Int# -> Float#
1216 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1217 ForeignObj# -> Int# -> Double#
1219 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1220 ForeignObj# -> Int# -> StablePtr# a
1222 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1223 ForeignObj# -> Int# -> Int#
1225 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1226 ForeignObj# -> Int# -> Int#
1228 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1229 ForeignObj# -> Int# -> INT32
1231 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1232 ForeignObj# -> Int# -> INT64
1234 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1235 ForeignObj# -> Int# -> Word#
1237 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1238 ForeignObj# -> Int# -> Word#
1240 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1241 ForeignObj# -> Int# -> WORD32
1243 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1244 ForeignObj# -> Int# -> WORD64
1248 ------------------------------------------------------------------------
1249 section "Mutable variables"
1250 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1251 ------------------------------------------------------------------------
1253 primop NewMutVarOp "newMutVar#" GenPrimOp
1254 a -> State# s -> (# State# s, MutVar# s a #)
1255 {Create MutVar\# with specified initial value in specified state thread.}
1257 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1260 primop ReadMutVarOp "readMutVar#" GenPrimOp
1261 MutVar# s a -> State# s -> (# State# s, a #)
1262 {Read contents of MutVar\#. Result is not yet evaluated.}
1264 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1266 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1267 MutVar# s a -> a -> State# s -> State# s
1268 {Write contents of MutVar\#.}
1270 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1271 has_side_effects = True
1273 primop SameMutVarOp "sameMutVar#" GenPrimOp
1274 MutVar# s a -> MutVar# s a -> Bool
1276 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1278 ------------------------------------------------------------------------
1279 section "Exceptions"
1280 ------------------------------------------------------------------------
1282 primop CatchOp "catch#" GenPrimOp
1283 (State# RealWorld -> (# State# RealWorld, a #) )
1284 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1286 -> (# State# RealWorld, a #)
1288 -- Catch is actually strict in its first argument
1289 -- but we don't want to tell the strictness
1290 -- analyser about that!
1291 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1292 -- [mkO, mkO . (inFun mkM mkO)] mkO
1293 -- might use caught action multiply
1296 primop RaiseOp "raise#" GenPrimOp
1299 strictness = { \ arity -> mkStrictSig (mkTopDmdType [lazyDmd] BotRes) }
1300 -- NB: result is bottom
1301 usage = { mangle RaiseOp [mkM] mkM }
1304 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1305 (State# RealWorld -> (# State# RealWorld, a #))
1306 -> (State# RealWorld -> (# State# RealWorld, a #))
1310 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1311 (State# RealWorld -> (# State# RealWorld, a #))
1312 -> (State# RealWorld -> (# State# RealWorld, a #))
1316 ------------------------------------------------------------------------
1317 section "Synchronized Mutable Variables"
1318 {Operations on MVar\#s, which are shared mutable variables
1319 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1320 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1321 ------------------------------------------------------------------------
1324 primop NewMVarOp "newMVar#" GenPrimOp
1325 State# s -> (# State# s, MVar# s a #)
1326 {Create new mvar; initially empty.}
1328 usage = { mangle NewMVarOp [mkP] mkR }
1331 primop TakeMVarOp "takeMVar#" GenPrimOp
1332 MVar# s a -> State# s -> (# State# s, a #)
1333 {If mvar is empty, block until it becomes full.
1334 Then remove and return its contents, and set it empty.}
1336 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1337 has_side_effects = True
1340 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1341 MVar# s a -> State# s -> (# State# s, Int#, a #)
1342 {If mvar is empty, immediately return with integer 0 and value undefined.
1343 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1345 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1346 has_side_effects = True
1349 primop PutMVarOp "putMVar#" GenPrimOp
1350 MVar# s a -> a -> State# s -> State# s
1351 {If mvar is full, block until it becomes empty.
1352 Then store value arg as its new contents.}
1354 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1355 has_side_effects = True
1358 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1359 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1360 {If mvar is full, immediately return with integer 0.
1361 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1363 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1364 has_side_effects = True
1367 primop SameMVarOp "sameMVar#" GenPrimOp
1368 MVar# s a -> MVar# s a -> Bool
1370 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1372 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1373 MVar# s a -> State# s -> (# State# s, Int# #)
1374 {Return 1 if mvar is empty; 0 otherwise.}
1376 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1379 ------------------------------------------------------------------------
1380 section "Delay/wait operations"
1381 ------------------------------------------------------------------------
1383 primop DelayOp "delay#" GenPrimOp
1384 Int# -> State# s -> State# s
1385 {Sleep specified number of microseconds.}
1387 needs_wrapper = True
1388 has_side_effects = True
1391 primop WaitReadOp "waitRead#" GenPrimOp
1392 Int# -> State# s -> State# s
1393 {Block until input is available on specified file descriptor.}
1395 needs_wrapper = True
1396 has_side_effects = True
1399 primop WaitWriteOp "waitWrite#" GenPrimOp
1400 Int# -> State# s -> State# s
1401 {Block until output is possible on specified file descriptor.}
1403 needs_wrapper = True
1404 has_side_effects = True
1407 ------------------------------------------------------------------------
1408 section "Concurrency primitives"
1409 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1410 type, whose (unique) value is returned by myThreadId\#. The
1411 other operations can be omitted.)}
1412 ------------------------------------------------------------------------
1414 primop ForkOp "fork#" GenPrimOp
1415 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1417 usage = { mangle ForkOp [mkO, mkP] mkR }
1418 has_side_effects = True
1421 primop KillThreadOp "killThread#" GenPrimOp
1422 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1424 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1425 has_side_effects = True
1428 primop YieldOp "yield#" GenPrimOp
1429 State# RealWorld -> State# RealWorld
1431 has_side_effects = True
1434 primop MyThreadIdOp "myThreadId#" GenPrimOp
1435 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1439 ------------------------------------------------------------------------
1440 section "Weak pointers"
1441 ------------------------------------------------------------------------
1443 -- note that tyvar "o" denotes openAlphaTyVar
1445 primop MkWeakOp "mkWeak#" GenPrimOp
1446 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1448 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1449 has_side_effects = True
1452 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1453 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1455 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1456 has_side_effects = True
1459 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1460 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1461 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
1463 usage = { mangle FinalizeWeakOp [mkM, mkP]
1464 (mkR . (inUB FinalizeWeakOp
1465 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1466 has_side_effects = True
1469 ------------------------------------------------------------------------
1470 section "Stable pointers and names"
1471 ------------------------------------------------------------------------
1473 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1474 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1476 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1477 has_side_effects = True
1480 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1481 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1483 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1484 needs_wrapper = True
1485 has_side_effects = True
1488 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1489 StablePtr# a -> StablePtr# a -> Int#
1491 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1492 has_side_effects = True
1494 primop MakeStableNameOp "makeStableName#" GenPrimOp
1495 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1497 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1498 needs_wrapper = True
1499 has_side_effects = True
1502 primop EqStableNameOp "eqStableName#" GenPrimOp
1503 StableName# a -> StableName# a -> Int#
1505 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1507 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1508 StableName# a -> Int#
1510 usage = { mangle StableNameToIntOp [mkP] mkR }
1512 ------------------------------------------------------------------------
1513 section "Parallelism"
1514 ------------------------------------------------------------------------
1516 primop SeqOp "seq#" GenPrimOp
1519 usage = { mangle SeqOp [mkO] mkR }
1520 strictness = { \ arity -> mkStrictSig (mkTopDmdType [evalDmd] TopRes) }
1521 -- Seq is strict in its argument; see notes in ConFold.lhs
1522 has_side_effects = True
1524 primop ParOp "par#" GenPrimOp
1527 usage = { mangle ParOp [mkO] mkR }
1528 -- Note that Par is lazy to avoid that the sparked thing
1529 -- gets evaluted strictly, which it should *not* be
1530 has_side_effects = True
1532 -- HWL: The first 4 Int# in all par... annotations denote:
1533 -- name, granularity info, size of result, degree of parallelism
1534 -- Same structure as _seq_ i.e. returns Int#
1535 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1536 -- `the processor containing the expression v'; it is not evaluated
1538 primop ParGlobalOp "parGlobal#" GenPrimOp
1539 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1541 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1542 has_side_effects = True
1544 primop ParLocalOp "parLocal#" GenPrimOp
1545 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1547 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1548 has_side_effects = True
1550 primop ParAtOp "parAt#" GenPrimOp
1551 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1553 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1554 has_side_effects = True
1556 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1557 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1559 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1560 has_side_effects = True
1562 primop ParAtRelOp "parAtRel#" GenPrimOp
1563 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1565 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1566 has_side_effects = True
1568 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1569 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1571 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1572 has_side_effects = True
1574 -- copyable# and noFollow# are yet to be implemented (for GpH)
1576 --primop CopyableOp "copyable#" GenPrimOp
1579 -- usage = { mangle CopyableOp [mkZ] mkR }
1580 -- has_side_effects = True
1582 --primop NoFollowOp "noFollow#" GenPrimOp
1585 -- usage = { mangle NoFollowOp [mkZ] mkR }
1586 -- has_side_effects = True
1589 ------------------------------------------------------------------------
1590 section "Tag to enum stuff"
1591 {Convert back and forth between values of enumerated types
1592 and small integers.}
1593 ------------------------------------------------------------------------
1595 primop DataToTagOp "dataToTag#" GenPrimOp
1598 primop TagToEnumOp "tagToEnum#" GenPrimOp
1601 ------------------------------------------------------------------------
1602 section "Bytecode operations"
1603 {Support for the bytecode interpreter and linker.}
1604 ------------------------------------------------------------------------
1607 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1609 {Convert an Addr\# to a followable type.}
1611 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1616 primop NewBCOOp "newBCO#" GenPrimOp
1617 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
1619 has_side_effects = True
1622 ------------------------------------------------------------------------
1624 {{\tt unsafeCoerce# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1626 ------------------------------------------------------------------------
1629 ------------------------------------------------------------------------
1631 ------------------------------------------------------------------------