1 -----------------------------------------------------------------------
2 -- $Id: primops.txt.pp,v 1.31 2004/11/18 09:56:15 tharris 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 section "The word size story."
69 {Haskell98 specifies that signed integers (type {\tt Int})
70 must contain at least 30 bits. GHC always implements {\tt
71 Int} using the primitive type {\tt Int\#}, whose size equals
72 the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
73 This is normally set based on the {\tt config.h} parameter
74 {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
75 bits on 64-bit machines. However, it can also be explicitly
76 set to a smaller number, e.g., 31 bits, to allow the
77 possibility of using tag bits. Currently GHC itself has only
78 32-bit and 64-bit variants, but 30 or 31-bit code can be
79 exported as an external core file for use in other back ends.
81 GHC also implements a primitive unsigned integer type {\tt
82 Word\#} which always has the same number of bits as {\tt
85 In addition, GHC supports families of explicit-sized integers
86 and words at 8, 16, 32, and 64 bits, with the usual
87 arithmetic operations, comparisons, and a range of
88 conversions. The 8-bit and 16-bit sizes are always
89 represented as {\tt Int\#} and {\tt Word\#}, and the
90 operations implemented in terms of the the primops on these
91 types, with suitable range restrictions on the results (using
92 the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
93 of primops. The 32-bit sizes are represented using {\tt
94 Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
95 $\geq$ 32; otherwise, these are represented using distinct
96 primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
97 needed) have a complete set of corresponding operations;
98 however, nearly all of these are implemented as external C
99 functions rather than as primops. Exactly the same story
100 applies to the 64-bit sizes. All of these details are hidden
101 under the {\tt PrelInt} and {\tt PrelWord} modules, which use
102 {\tt \#if}-defs to invoke the appropriate types and
105 Word size also matters for the families of primops for
106 indexing/reading/writing fixed-size quantities at offsets
107 from an array base, address, or foreign pointer. Here, a
108 slightly different approach is taken. The names of these
109 primops are fixed, but their {\it types} vary according to
110 the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
111 size is at least 32 bits then an operator like
112 \texttt{indexInt32Array\#} has type {\tt ByteArr\# -> Int\#
113 -> Int\#}; otherwise it has type {\tt ByteArr\# -> Int\# ->
114 Int32\#}. This approach confines the necessary {\tt
115 \#if}-defs to this file; no conditional compilation is needed
116 in the files that expose these primops, namely
117 \texttt{lib/std/PrelStorable.lhs},
118 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated
119 fashion) in \texttt{hslibs/lang/ForeignObj.lhs} and
120 \texttt{hslibs/lang/Addr.lhs}.
122 Finally, there are strongly deprecated primops for coercing
123 between {\tt Addr\#}, the primitive type of machine
124 addresses, and {\tt Int\#}. These are pretty bogus anyway,
125 but will work on existing 32-bit and 64-bit GHC targets; they
126 are completely bogus when tag bits are used in {\tt Int\#},
127 so are not available in this case. }
129 -- Define synonyms for indexing ops.
131 #if WORD_SIZE_IN_BITS < 32
133 #define WORD32 Word32#
139 #if WORD_SIZE_IN_BITS < 64
141 #define WORD64 Word64#
147 ------------------------------------------------------------------------
149 {Operations on 31-bit characters.}
150 ------------------------------------------------------------------------
153 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
154 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
156 primop CharEqOp "eqChar#" Compare
157 Char# -> Char# -> Bool
158 with commutable = True
160 primop CharNeOp "neChar#" Compare
161 Char# -> Char# -> Bool
162 with commutable = True
164 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
165 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
167 primop OrdOp "ord#" GenPrimOp Char# -> Int#
169 ------------------------------------------------------------------------
171 {Operations on native-size integers (30+ bits).}
172 ------------------------------------------------------------------------
174 primop IntAddOp "+#" Dyadic
176 with commutable = True
178 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
181 Dyadic Int# -> Int# -> Int#
182 {Low word of signed integer multiply.}
183 with commutable = True
185 primop IntMulMayOfloOp "mulIntMayOflo#"
186 Dyadic Int# -> Int# -> Int#
187 {Return non-zero if there is any possibility that the upper word of a
188 signed integer multiply might contain useful information. Return
189 zero only if you are completely sure that no overflow can occur.
190 On a 32-bit platform, the recommmended implementation is to do a
191 32 x 32 -> 64 signed multiply, and subtract result[63:32] from
192 (result[31] >>signed 31). If this is zero, meaning that the
193 upper word is merely a sign extension of the lower one, no
196 On a 64-bit platform it is not always possible to
197 acquire the top 64 bits of the result. Therefore, a recommended
198 implementation is to take the absolute value of both operands, and
199 return 0 iff bits[63:31] of them are zero, since that means that their
200 magnitudes fit within 31 bits, so the magnitude of the product must fit
203 If in doubt, return non-zero, but do make an effort to create the
204 correct answer for small args, since otherwise the performance of
205 (*) :: Integer -> Integer -> Integer will be poor.
207 with commutable = True
209 primop IntQuotOp "quotInt#" Dyadic
211 {Rounds towards zero.}
214 primop IntRemOp "remInt#" Dyadic
216 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
219 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
220 with out_of_line = True
222 primop IntNegOp "negateInt#" Monadic Int# -> Int#
223 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
224 {Add with carry. First member of result is (wrapped) sum;
225 second member is 0 iff no overflow occured.}
226 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
227 {Subtract with carry. First member of result is (wrapped) difference;
228 second member is 0 iff no overflow occured.}
230 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
231 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
233 primop IntEqOp "==#" Compare
235 with commutable = True
237 primop IntNeOp "/=#" Compare
239 with commutable = True
241 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
242 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
244 primop ChrOp "chr#" GenPrimOp Int# -> Char#
246 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
247 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
248 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
250 primop Int2IntegerOp "int2Integer#"
251 GenPrimOp Int# -> (# Int#, ByteArr# #)
252 with out_of_line = True
254 primop ISllOp "uncheckedIShiftL#" GenPrimOp Int# -> Int# -> Int#
255 {Shift left. Result undefined if shift amount is not
256 in the range 0 to word size - 1 inclusive.}
257 primop ISraOp "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
258 {Shift right arithmetic. Result undefined if shift amount is not
259 in the range 0 to word size - 1 inclusive.}
260 primop ISrlOp "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
261 {Shift right logical. Result undefined if shift amount is not
262 in the range 0 to word size - 1 inclusive.}
264 ------------------------------------------------------------------------
266 {Operations on native-sized unsigned words (30+ bits).}
267 ------------------------------------------------------------------------
269 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
270 with commutable = True
272 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
274 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
275 with commutable = True
277 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
280 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
283 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
284 with commutable = True
286 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
287 with commutable = True
289 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
290 with commutable = True
292 primop NotOp "not#" Monadic Word# -> Word#
294 primop SllOp "uncheckedShiftL#" GenPrimOp Word# -> Int# -> Word#
295 {Shift left logical. Result undefined if shift amount is not
296 in the range 0 to word size - 1 inclusive.}
297 primop SrlOp "uncheckedShiftRL#" GenPrimOp Word# -> Int# -> Word#
298 {Shift right logical. Result undefined if shift amount is not
299 in the range 0 to word size - 1 inclusive.}
301 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
303 primop Word2IntegerOp "word2Integer#" GenPrimOp
304 Word# -> (# Int#, ByteArr# #)
305 with out_of_line = True
307 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
308 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
309 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
310 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
311 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
312 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
314 ------------------------------------------------------------------------
316 {Explicit narrowing of native-sized ints or words.}
317 ------------------------------------------------------------------------
319 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
320 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
321 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
322 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
323 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
324 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
327 #if WORD_SIZE_IN_BITS < 32
328 ------------------------------------------------------------------------
330 {Operations on 32-bit integers (Int32\#). This type is only used
331 if plain Int\# has less than 32 bits. In any case, the operations
332 are not primops; they are implemented (if needed) as ccalls instead.}
333 ------------------------------------------------------------------------
335 primop Int32ToIntegerOp "int32ToInteger#" GenPrimOp
336 Int32# -> (# Int#, ByteArr# #)
337 with out_of_line = True
340 ------------------------------------------------------------------------
342 {Operations on 32-bit unsigned words. This type is only used
343 if plain Word\# has less than 32 bits. In any case, the operations
344 are not primops; they are implemented (if needed) as ccalls instead.}
345 ------------------------------------------------------------------------
347 primop Word32ToIntegerOp "word32ToInteger#" GenPrimOp
348 Word32# -> (# Int#, ByteArr# #)
349 with out_of_line = True
355 #if WORD_SIZE_IN_BITS < 64
356 ------------------------------------------------------------------------
358 {Operations on 64-bit unsigned words. This type is only used
359 if plain Int\# has less than 64 bits. In any case, the operations
360 are not primops; they are implemented (if needed) as ccalls instead.}
361 ------------------------------------------------------------------------
363 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
364 Int64# -> (# Int#, ByteArr# #)
365 with out_of_line = True
367 ------------------------------------------------------------------------
369 {Operations on 64-bit unsigned words. This type is only used
370 if plain Word\# has less than 64 bits. In any case, the operations
371 are not primops; they are implemented (if needed) as ccalls instead.}
372 ------------------------------------------------------------------------
374 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
375 Word64# -> (# Int#, ByteArr# #)
376 with out_of_line = True
380 ------------------------------------------------------------------------
382 {Operations on arbitrary-precision integers. These operations are
383 implemented via the GMP package. An integer is represented as a pair
384 consisting of an Int\# representing the number of 'limbs' in use and
385 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
386 are returned as unboxed pairs, but must be passed as separate
389 For .NET these operations are implemented by foreign imports, so the
390 primops are omitted.}
391 ------------------------------------------------------------------------
395 primop IntegerAddOp "plusInteger#" GenPrimOp
396 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
397 with commutable = True
400 primop IntegerSubOp "minusInteger#" GenPrimOp
401 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
402 with out_of_line = True
404 primop IntegerMulOp "timesInteger#" GenPrimOp
405 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
406 with commutable = True
409 primop IntegerGcdOp "gcdInteger#" GenPrimOp
410 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
411 {Greatest common divisor.}
412 with commutable = True
415 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
416 Int# -> ByteArr# -> Int# -> Int#
417 {Greatest common divisor, where second argument is an ordinary Int\#.}
418 with out_of_line = True
420 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
421 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
422 {Divisor is guaranteed to be a factor of dividend.}
423 with out_of_line = True
425 primop IntegerQuotOp "quotInteger#" GenPrimOp
426 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
427 {Rounds towards zero.}
428 with out_of_line = True
430 primop IntegerRemOp "remInteger#" GenPrimOp
431 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
432 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
433 with out_of_line = True
435 primop IntegerCmpOp "cmpInteger#" GenPrimOp
436 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
437 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
438 with needs_wrapper = True
441 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
442 Int# -> ByteArr# -> Int# -> Int#
443 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
444 is an ordinary Int\#.}
445 with needs_wrapper = True
448 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
449 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
450 {Compute quot and rem simulaneously.}
454 primop IntegerDivModOp "divModInteger#" GenPrimOp
455 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
456 {Compute div and mod simultaneously, where div rounds towards negative infinity
457 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
461 primop Integer2IntOp "integer2Int#" GenPrimOp
462 Int# -> ByteArr# -> Int#
463 with needs_wrapper = True
466 primop Integer2WordOp "integer2Word#" GenPrimOp
467 Int# -> ByteArr# -> Word#
468 with needs_wrapper = True
471 #if WORD_SIZE_IN_BITS < 32
472 primop IntegerToInt32Op "integerToInt32#" GenPrimOp
473 Int# -> ByteArr# -> Int32#
475 primop IntegerToWord32Op "integerToWord32#" GenPrimOp
476 Int# -> ByteArr# -> Word32#
479 primop IntegerAndOp "andInteger#" GenPrimOp
480 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
481 with out_of_line = True
483 primop IntegerOrOp "orInteger#" GenPrimOp
484 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
485 with out_of_line = True
487 primop IntegerXorOp "xorInteger#" GenPrimOp
488 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
489 with out_of_line = True
491 primop IntegerComplementOp "complementInteger#" GenPrimOp
492 Int# -> ByteArr# -> (# Int#, ByteArr# #)
493 with out_of_line = True
495 #endif /* ndef ILX */
497 ------------------------------------------------------------------------
499 {Operations on double-precision (64 bit) floating-point numbers.}
500 ------------------------------------------------------------------------
502 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
503 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
505 primop DoubleEqOp "==##" Compare
506 Double# -> Double# -> Bool
507 with commutable = True
509 primop DoubleNeOp "/=##" Compare
510 Double# -> Double# -> Bool
511 with commutable = True
513 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
514 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
516 primop DoubleAddOp "+##" Dyadic
517 Double# -> Double# -> Double#
518 with commutable = True
520 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
522 primop DoubleMulOp "*##" Dyadic
523 Double# -> Double# -> Double#
524 with commutable = True
526 primop DoubleDivOp "/##" Dyadic
527 Double# -> Double# -> Double#
530 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
532 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
533 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
535 primop DoubleExpOp "expDouble#" Monadic
537 with needs_wrapper = True
539 primop DoubleLogOp "logDouble#" Monadic
545 primop DoubleSqrtOp "sqrtDouble#" Monadic
547 with needs_wrapper = True
549 primop DoubleSinOp "sinDouble#" Monadic
551 with needs_wrapper = True
553 primop DoubleCosOp "cosDouble#" Monadic
555 with needs_wrapper = True
557 primop DoubleTanOp "tanDouble#" Monadic
559 with needs_wrapper = True
561 primop DoubleAsinOp "asinDouble#" Monadic
567 primop DoubleAcosOp "acosDouble#" Monadic
573 primop DoubleAtanOp "atanDouble#" Monadic
578 primop DoubleSinhOp "sinhDouble#" Monadic
580 with needs_wrapper = True
582 primop DoubleCoshOp "coshDouble#" Monadic
584 with needs_wrapper = True
586 primop DoubleTanhOp "tanhDouble#" Monadic
588 with needs_wrapper = True
590 primop DoublePowerOp "**##" Dyadic
591 Double# -> Double# -> Double#
593 with needs_wrapper = True
595 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
596 Double# -> (# Int#, Int#, ByteArr# #)
597 {Convert to arbitrary-precision integer.
598 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
599 holding the mantissa.}
600 with out_of_line = True
602 ------------------------------------------------------------------------
604 {Operations on single-precision (32-bit) floating-point numbers.}
605 ------------------------------------------------------------------------
607 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
608 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
610 primop FloatEqOp "eqFloat#" Compare
611 Float# -> Float# -> Bool
612 with commutable = True
614 primop FloatNeOp "neFloat#" Compare
615 Float# -> Float# -> Bool
616 with commutable = True
618 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
619 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
621 primop FloatAddOp "plusFloat#" Dyadic
622 Float# -> Float# -> Float#
623 with commutable = True
625 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
627 primop FloatMulOp "timesFloat#" Dyadic
628 Float# -> Float# -> Float#
629 with commutable = True
631 primop FloatDivOp "divideFloat#" Dyadic
632 Float# -> Float# -> Float#
635 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
637 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
639 primop FloatExpOp "expFloat#" Monadic
641 with needs_wrapper = True
643 primop FloatLogOp "logFloat#" Monadic
645 with needs_wrapper = True
648 primop FloatSqrtOp "sqrtFloat#" Monadic
650 with needs_wrapper = True
652 primop FloatSinOp "sinFloat#" Monadic
654 with needs_wrapper = True
656 primop FloatCosOp "cosFloat#" Monadic
658 with needs_wrapper = True
660 primop FloatTanOp "tanFloat#" Monadic
662 with needs_wrapper = True
664 primop FloatAsinOp "asinFloat#" Monadic
666 with needs_wrapper = True
669 primop FloatAcosOp "acosFloat#" Monadic
671 with needs_wrapper = True
674 primop FloatAtanOp "atanFloat#" Monadic
676 with needs_wrapper = True
678 primop FloatSinhOp "sinhFloat#" Monadic
680 with needs_wrapper = True
682 primop FloatCoshOp "coshFloat#" Monadic
684 with needs_wrapper = True
686 primop FloatTanhOp "tanhFloat#" Monadic
688 with needs_wrapper = True
690 primop FloatPowerOp "powerFloat#" Dyadic
691 Float# -> Float# -> Float#
692 with needs_wrapper = True
694 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
696 primop FloatDecodeOp "decodeFloat#" GenPrimOp
697 Float# -> (# Int#, Int#, ByteArr# #)
698 {Convert to arbitrary-precision integer.
699 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
700 holding the mantissa.}
701 with out_of_line = True
703 ------------------------------------------------------------------------
705 {Operations on Array\#.}
706 ------------------------------------------------------------------------
708 primop NewArrayOp "newArray#" GenPrimOp
709 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
710 {Create a new mutable array of specified size (in bytes),
711 in the specified state thread,
712 with each element containing the specified initial value.}
714 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
717 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
718 MutArr# s a -> MutArr# s a -> Bool
720 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
722 primop ReadArrayOp "readArray#" GenPrimOp
723 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
724 {Read from specified index of mutable array. Result is not yet evaluated.}
726 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
728 primop WriteArrayOp "writeArray#" GenPrimOp
729 MutArr# s a -> Int# -> a -> State# s -> State# s
730 {Write to specified index of mutable array.}
732 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
733 has_side_effects = True
735 primop IndexArrayOp "indexArray#" GenPrimOp
736 Array# a -> Int# -> (# a #)
737 {Read from specified index of immutable array. Result is packaged into
738 an unboxed singleton; the result itself is not yet evaluated.}
740 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
742 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
743 MutArr# s a -> State# s -> (# State# s, Array# a #)
744 {Make a mutable array immutable, without copying.}
746 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
747 has_side_effects = True
749 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
750 Array# a -> State# s -> (# State# s, MutArr# s a #)
751 {Make an immutable array mutable, without copying.}
753 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
756 ------------------------------------------------------------------------
757 section "Byte Arrays"
758 {Operations on ByteArray\#. A ByteArray\# is a just a region of
759 raw memory in the garbage-collected heap, which is not scanned
760 for pointers. It carries its own size (in bytes). There are
761 three sets of operations for accessing byte array contents:
762 index for reading from immutable byte arrays, and read/write
763 for mutable byte arrays. Each set contains operations for
764 a range of useful primitive data types. Each operation takes
765 an offset measured in terms of the size fo the primitive type
766 being read or written.}
768 ------------------------------------------------------------------------
770 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
771 Int# -> State# s -> (# State# s, MutByteArr# s #)
772 {Create a new mutable byte array of specified size (in bytes), in
773 the specified state thread.}
774 with out_of_line = True
776 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
777 Int# -> State# s -> (# State# s, MutByteArr# s #)
778 {Create a mutable byte array that the GC guarantees not to move.}
779 with out_of_line = True
781 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
783 {Intended for use with pinned arrays; otherwise very unsafe!}
785 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
786 MutByteArr# s -> MutByteArr# s -> Bool
788 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
789 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
790 {Make a mutable byte array immutable, without copying.}
792 has_side_effects = True
794 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
797 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
798 MutByteArr# s -> Int#
801 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
802 ByteArr# -> Int# -> Char#
803 {Read 8-bit character; offset in bytes.}
805 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
806 ByteArr# -> Int# -> Char#
807 {Read 31-bit character; offset in 4-byte words.}
809 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
810 ByteArr# -> Int# -> Int#
812 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
813 ByteArr# -> Int# -> Word#
815 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
816 ByteArr# -> Int# -> Addr#
818 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
819 ByteArr# -> Int# -> Float#
821 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
822 ByteArr# -> Int# -> Double#
824 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
825 ByteArr# -> Int# -> StablePtr# a
827 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
828 ByteArr# -> Int# -> Int#
830 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
831 ByteArr# -> Int# -> Int#
833 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
834 ByteArr# -> Int# -> INT32
836 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
837 ByteArr# -> Int# -> INT64
839 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
840 ByteArr# -> Int# -> Word#
842 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
843 ByteArr# -> Int# -> Word#
845 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
846 ByteArr# -> Int# -> WORD32
848 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
849 ByteArr# -> Int# -> WORD64
851 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
852 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
853 {Read 8-bit character; offset in bytes.}
855 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
856 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
857 {Read 31-bit character; offset in 4-byte words.}
859 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
860 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
862 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
863 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
865 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
866 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
868 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
869 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
871 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
872 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
874 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
875 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
877 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
878 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
880 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
881 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
883 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
884 MutByteArr# s -> Int# -> State# s -> (# State# s, INT32 #)
886 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
887 MutByteArr# s -> Int# -> State# s -> (# State# s, INT64 #)
889 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
890 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
892 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
893 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
895 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
896 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD32 #)
898 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
899 MutByteArr# s -> Int# -> State# s -> (# State# s, WORD64 #)
901 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
902 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
903 {Write 8-bit character; offset in bytes.}
904 with has_side_effects = True
906 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
907 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
908 {Write 31-bit character; offset in 4-byte words.}
909 with has_side_effects = True
911 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
912 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
913 with has_side_effects = True
915 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
916 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
917 with has_side_effects = True
919 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
920 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
921 with has_side_effects = True
923 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
924 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
925 with has_side_effects = True
927 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
928 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
929 with has_side_effects = True
931 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
932 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
933 with has_side_effects = True
935 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
936 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
937 with has_side_effects = True
939 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
940 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
941 with has_side_effects = True
943 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
944 MutByteArr# s -> Int# -> INT32 -> State# s -> State# s
945 with has_side_effects = True
947 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
948 MutByteArr# s -> Int# -> INT64 -> State# s -> State# s
949 with has_side_effects = True
951 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
952 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
953 with has_side_effects = True
955 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
956 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
957 with has_side_effects = True
959 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
960 MutByteArr# s -> Int# -> WORD32 -> State# s -> State# s
961 with has_side_effects = True
963 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
964 MutByteArr# s -> Int# -> WORD64 -> State# s -> State# s
965 with has_side_effects = True
967 ------------------------------------------------------------------------
969 {Addr\# is an arbitrary machine address assumed to point outside
970 the garbage-collected heap.
972 NB: {\tt nullAddr\#::Addr\#} is not a primop, but is defined in MkId.lhs.
973 It is the null address.}
974 ------------------------------------------------------------------------
976 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
977 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
978 {Result is meaningless if two Addr\#s are so far apart that their
979 difference doesn't fit in an Int\#.}
980 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
981 {Return the remainder when the Addr\# arg, treated like an Int\#,
982 is divided by the Int\# arg.}
983 #if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
984 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
985 {Coerce directly from address to int. Strongly deprecated.}
986 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
987 {Coerce directly from int to address. Strongly deprecated.}
990 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
991 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
992 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
993 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
994 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
995 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
997 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
998 Addr# -> Int# -> Char#
999 {Reads 8-bit character; offset in bytes.}
1001 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
1002 Addr# -> Int# -> Char#
1003 {Reads 31-bit character; offset in 4-byte words.}
1005 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
1006 Addr# -> Int# -> Int#
1008 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
1009 Addr# -> Int# -> Word#
1011 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
1012 Addr# -> Int# -> Addr#
1014 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
1015 Addr# -> Int# -> Float#
1017 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
1018 Addr# -> Int# -> Double#
1020 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
1021 Addr# -> Int# -> StablePtr# a
1023 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
1024 Addr# -> Int# -> Int#
1026 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1027 Addr# -> Int# -> Int#
1029 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
1030 Addr# -> Int# -> INT32
1032 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
1033 Addr# -> Int# -> INT64
1035 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
1036 Addr# -> Int# -> Word#
1038 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
1039 Addr# -> Int# -> Word#
1041 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
1042 Addr# -> Int# -> WORD32
1044 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
1045 Addr# -> Int# -> WORD64
1047 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
1048 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1049 {Reads 8-bit character; offset in bytes.}
1051 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
1052 Addr# -> Int# -> State# s -> (# State# s, Char# #)
1053 {Reads 31-bit character; offset in 4-byte words.}
1055 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
1056 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1058 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
1059 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1061 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
1062 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
1064 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
1065 Addr# -> Int# -> State# s -> (# State# s, Float# #)
1067 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
1068 Addr# -> Int# -> State# s -> (# State# s, Double# #)
1070 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
1071 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
1073 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
1074 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1076 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
1077 Addr# -> Int# -> State# s -> (# State# s, Int# #)
1079 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
1080 Addr# -> Int# -> State# s -> (# State# s, INT32 #)
1082 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
1083 Addr# -> Int# -> State# s -> (# State# s, INT64 #)
1085 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
1086 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1088 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
1089 Addr# -> Int# -> State# s -> (# State# s, Word# #)
1091 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
1092 Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1094 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
1095 Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1098 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
1099 Addr# -> Int# -> Char# -> State# s -> State# s
1100 with has_side_effects = True
1102 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
1103 Addr# -> Int# -> Char# -> State# s -> State# s
1104 with has_side_effects = True
1106 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
1107 Addr# -> Int# -> Int# -> State# s -> State# s
1108 with has_side_effects = True
1110 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
1111 Addr# -> Int# -> Word# -> State# s -> State# s
1112 with has_side_effects = True
1114 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
1115 Addr# -> Int# -> Addr# -> State# s -> State# s
1116 with has_side_effects = True
1118 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
1119 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
1120 with has_side_effects = True
1122 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
1123 Addr# -> Int# -> Float# -> State# s -> State# s
1124 with has_side_effects = True
1126 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
1127 Addr# -> Int# -> Double# -> State# s -> State# s
1128 with has_side_effects = True
1130 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
1131 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
1132 with has_side_effects = True
1134 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
1135 Addr# -> Int# -> Int# -> State# s -> State# s
1136 with has_side_effects = True
1138 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
1139 Addr# -> Int# -> Int# -> State# s -> State# s
1140 with has_side_effects = True
1142 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
1143 Addr# -> Int# -> INT32 -> State# s -> State# s
1144 with has_side_effects = True
1146 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
1147 Addr# -> Int# -> INT64 -> State# s -> State# s
1148 with has_side_effects = True
1150 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
1151 Addr# -> Int# -> Word# -> State# s -> State# s
1152 with has_side_effects = True
1154 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1155 Addr# -> Int# -> Word# -> State# s -> State# s
1156 with has_side_effects = True
1158 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
1159 Addr# -> Int# -> WORD32 -> State# s -> State# s
1160 with has_side_effects = True
1162 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
1163 Addr# -> Int# -> WORD64 -> State# s -> State# s
1164 with has_side_effects = True
1166 ------------------------------------------------------------------------
1167 section "ForeignObj#"
1168 {Operations on ForeignObj\#. The indexing operations are
1170 ------------------------------------------------------------------------
1172 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
1173 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
1175 has_side_effects = True
1178 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
1179 ForeignObj# -> Addr# -> State# s -> State# s
1181 has_side_effects = True
1183 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
1184 ForeignObj# -> Addr#
1186 primop TouchOp "touch#" GenPrimOp
1187 o -> State# RealWorld -> State# RealWorld
1189 has_side_effects = True
1191 primop EqForeignObj "eqForeignObj#" GenPrimOp
1192 ForeignObj# -> ForeignObj# -> Bool
1193 with commutable = True
1195 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
1196 ForeignObj# -> Int# -> Char#
1197 {Read 8-bit character; offset in bytes.}
1199 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
1200 ForeignObj# -> Int# -> Char#
1201 {Read 31-bit character; offset in 4-byte words.}
1203 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
1204 ForeignObj# -> Int# -> Int#
1206 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
1207 ForeignObj# -> Int# -> Word#
1209 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
1210 ForeignObj# -> Int# -> Addr#
1212 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
1213 ForeignObj# -> Int# -> Float#
1215 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
1216 ForeignObj# -> Int# -> Double#
1218 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
1219 ForeignObj# -> Int# -> StablePtr# a
1221 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
1222 ForeignObj# -> Int# -> Int#
1224 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
1225 ForeignObj# -> Int# -> Int#
1227 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
1228 ForeignObj# -> Int# -> INT32
1230 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
1231 ForeignObj# -> Int# -> INT64
1233 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
1234 ForeignObj# -> Int# -> Word#
1236 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
1237 ForeignObj# -> Int# -> Word#
1239 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
1240 ForeignObj# -> Int# -> WORD32
1242 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
1243 ForeignObj# -> Int# -> WORD64
1247 ------------------------------------------------------------------------
1248 section "Mutable variables"
1249 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
1250 ------------------------------------------------------------------------
1252 primop NewMutVarOp "newMutVar#" GenPrimOp
1253 a -> State# s -> (# State# s, MutVar# s a #)
1254 {Create MutVar\# with specified initial value in specified state thread.}
1256 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
1259 primop ReadMutVarOp "readMutVar#" GenPrimOp
1260 MutVar# s a -> State# s -> (# State# s, a #)
1261 {Read contents of MutVar\#. Result is not yet evaluated.}
1263 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
1265 primop WriteMutVarOp "writeMutVar#" GenPrimOp
1266 MutVar# s a -> a -> State# s -> State# s
1267 {Write contents of MutVar\#.}
1269 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
1270 has_side_effects = True
1272 primop SameMutVarOp "sameMutVar#" GenPrimOp
1273 MutVar# s a -> MutVar# s a -> Bool
1275 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
1277 -- not really the right type, but we don't know about pairs here. The
1280 -- MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
1282 primop AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp
1283 MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #)
1285 usage = { mangle AtomicModifyMutVarOp [mkP, mkM, mkP] mkM }
1286 has_side_effects = True
1289 ------------------------------------------------------------------------
1290 section "Exceptions"
1291 ------------------------------------------------------------------------
1293 primop CatchOp "catch#" GenPrimOp
1294 (State# RealWorld -> (# State# RealWorld, a #) )
1295 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1297 -> (# State# RealWorld, a #)
1299 -- Catch is actually strict in its first argument
1300 -- but we don't want to tell the strictness
1301 -- analyser about that!
1302 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
1303 -- [mkO, mkO . (inFun mkM mkO)] mkO
1304 -- might use caught action multiply
1307 primop RaiseOp "raise#" GenPrimOp
1310 strictness = { \ arity -> mkStrictSig (mkTopDmdType [lazyDmd] BotRes) }
1311 -- NB: result is bottom
1312 usage = { mangle RaiseOp [mkM] mkM }
1315 -- raiseIO# needs to be a primop, because exceptions in the IO monad
1316 -- must be *precise* - we don't want the strictness analyser turning
1317 -- one kind of bottom into another, as it is allowed to do in pure code.
1319 primop RaiseIOOp "raiseIO#" GenPrimOp
1320 a -> State# RealWorld -> (# State# RealWorld, b #)
1324 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
1325 (State# RealWorld -> (# State# RealWorld, a #))
1326 -> (State# RealWorld -> (# State# RealWorld, a #))
1330 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
1331 (State# RealWorld -> (# State# RealWorld, a #))
1332 -> (State# RealWorld -> (# State# RealWorld, a #))
1336 ------------------------------------------------------------------------
1337 section "STM-accessible Mutable Variables"
1338 ------------------------------------------------------------------------
1340 primop AtomicallyOp "atomically#" GenPrimOp
1341 (State# RealWorld -> (# State# RealWorld, a #) )
1342 -> State# RealWorld -> (# State# RealWorld, a #)
1345 has_side_effects = True
1347 primop RetryOp "retry#" GenPrimOp
1348 State# RealWorld -> (# State# RealWorld, a #)
1351 has_side_effects = True
1353 primop CatchRetryOp "catchRetry#" GenPrimOp
1354 (State# RealWorld -> (# State# RealWorld, a #) )
1355 -> (State# RealWorld -> (# State# RealWorld, a #) )
1356 -> (State# RealWorld -> (# State# RealWorld, a #) )
1359 has_side_effects = True
1361 primop CatchSTMOp "catchSTM#" GenPrimOp
1362 (State# RealWorld -> (# State# RealWorld, a #) )
1363 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
1364 -> (State# RealWorld -> (# State# RealWorld, a #) )
1367 has_side_effects = True
1369 primop NewTVarOp "newTVar#" GenPrimOp
1371 -> State# s -> (# State# s, TVar# s a #)
1372 {Create a new Tar\# holding a specified initial value.}
1376 primop ReadTVarOp "readTVar#" GenPrimOp
1378 -> State# s -> (# State# s, a #)
1379 {Read contents of TVar\#. Result is not yet evaluated.}
1383 primop WriteTVarOp "writeTVar#" GenPrimOp
1386 -> State# s -> State# s
1387 {Write contents of TVar\#.}
1390 has_side_effects = True
1392 primop SameTVarOp "sameTVar#" GenPrimOp
1393 TVar# s a -> TVar# s a -> Bool
1396 ------------------------------------------------------------------------
1397 section "Synchronized Mutable Variables"
1398 {Operations on MVar\#s, which are shared mutable variables
1399 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
1400 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
1401 ------------------------------------------------------------------------
1404 primop NewMVarOp "newMVar#" GenPrimOp
1405 State# s -> (# State# s, MVar# s a #)
1406 {Create new mvar; initially empty.}
1408 usage = { mangle NewMVarOp [mkP] mkR }
1411 primop TakeMVarOp "takeMVar#" GenPrimOp
1412 MVar# s a -> State# s -> (# State# s, a #)
1413 {If mvar is empty, block until it becomes full.
1414 Then remove and return its contents, and set it empty.}
1416 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
1417 has_side_effects = True
1420 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
1421 MVar# s a -> State# s -> (# State# s, Int#, a #)
1422 {If mvar is empty, immediately return with integer 0 and value undefined.
1423 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
1425 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
1426 has_side_effects = True
1429 primop PutMVarOp "putMVar#" GenPrimOp
1430 MVar# s a -> a -> State# s -> State# s
1431 {If mvar is full, block until it becomes empty.
1432 Then store value arg as its new contents.}
1434 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
1435 has_side_effects = True
1438 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
1439 MVar# s a -> a -> State# s -> (# State# s, Int# #)
1440 {If mvar is full, immediately return with integer 0.
1441 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
1443 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
1444 has_side_effects = True
1447 primop SameMVarOp "sameMVar#" GenPrimOp
1448 MVar# s a -> MVar# s a -> Bool
1450 usage = { mangle SameMVarOp [mkP, mkP] mkM }
1452 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
1453 MVar# s a -> State# s -> (# State# s, Int# #)
1454 {Return 1 if mvar is empty; 0 otherwise.}
1456 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
1459 ------------------------------------------------------------------------
1460 section "Delay/wait operations"
1461 ------------------------------------------------------------------------
1463 primop DelayOp "delay#" GenPrimOp
1464 Int# -> State# s -> State# s
1465 {Sleep specified number of microseconds.}
1467 needs_wrapper = True
1468 has_side_effects = True
1471 primop WaitReadOp "waitRead#" GenPrimOp
1472 Int# -> State# s -> State# s
1473 {Block until input is available on specified file descriptor.}
1475 needs_wrapper = True
1476 has_side_effects = True
1479 primop WaitWriteOp "waitWrite#" GenPrimOp
1480 Int# -> State# s -> State# s
1481 {Block until output is possible on specified file descriptor.}
1483 needs_wrapper = True
1484 has_side_effects = True
1487 #ifdef mingw32_TARGET_OS
1488 primop AsyncReadOp "asyncRead#" GenPrimOp
1489 Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1490 {Asynchronously read bytes from specified file descriptor.}
1492 needs_wrapper = True
1493 has_side_effects = True
1496 primop AsyncWriteOp "asyncWrite#" GenPrimOp
1497 Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1498 {Asynchronously write bytes from specified file descriptor.}
1500 needs_wrapper = True
1501 has_side_effects = True
1504 primop AsyncDoProcOp "asyncDoProc#" GenPrimOp
1505 Addr# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
1506 {Asynchronously perform procedure (first arg), passing it 2nd arg.}
1508 needs_wrapper = True
1509 has_side_effects = True
1514 ------------------------------------------------------------------------
1515 section "Concurrency primitives"
1516 {(In a non-concurrent implementation, ThreadId\# can be as singleton
1517 type, whose (unique) value is returned by myThreadId\#. The
1518 other operations can be omitted.)}
1519 ------------------------------------------------------------------------
1521 primop ForkOp "fork#" GenPrimOp
1522 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1524 usage = { mangle ForkOp [mkO, mkP] mkR }
1525 has_side_effects = True
1528 primop KillThreadOp "killThread#" GenPrimOp
1529 ThreadId# -> a -> State# RealWorld -> State# RealWorld
1531 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
1532 has_side_effects = True
1535 primop YieldOp "yield#" GenPrimOp
1536 State# RealWorld -> State# RealWorld
1538 has_side_effects = True
1541 primop MyThreadIdOp "myThreadId#" GenPrimOp
1542 State# RealWorld -> (# State# RealWorld, ThreadId# #)
1546 primop LabelThreadOp "labelThread#" GenPrimOp
1547 ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
1549 has_side_effects = True
1552 primop IsCurrentThreadBoundOp "isCurrentThreadBound#" GenPrimOp
1553 State# RealWorld -> (# State# RealWorld, Int# #)
1557 ------------------------------------------------------------------------
1558 section "Weak pointers"
1559 ------------------------------------------------------------------------
1561 -- note that tyvar "o" denotes openAlphaTyVar
1563 primop MkWeakOp "mkWeak#" GenPrimOp
1564 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
1566 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
1567 has_side_effects = True
1570 primop DeRefWeakOp "deRefWeak#" GenPrimOp
1571 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
1573 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
1574 has_side_effects = True
1577 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
1578 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
1579 (State# RealWorld -> (# State# RealWorld, () #)) #)
1581 usage = { mangle FinalizeWeakOp [mkM, mkP]
1582 (mkR . (inUB FinalizeWeakOp
1583 [id,id,inFun FinalizeWeakOp mkR mkM])) }
1584 has_side_effects = True
1587 ------------------------------------------------------------------------
1588 section "Stable pointers and names"
1589 ------------------------------------------------------------------------
1591 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
1592 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
1594 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
1595 has_side_effects = True
1598 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
1599 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1601 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
1602 needs_wrapper = True
1603 has_side_effects = True
1606 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
1607 StablePtr# a -> StablePtr# a -> Int#
1609 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
1610 has_side_effects = True
1612 primop MakeStableNameOp "makeStableName#" GenPrimOp
1613 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
1615 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
1616 needs_wrapper = True
1617 has_side_effects = True
1620 primop EqStableNameOp "eqStableName#" GenPrimOp
1621 StableName# a -> StableName# a -> Int#
1623 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
1625 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
1626 StableName# a -> Int#
1628 usage = { mangle StableNameToIntOp [mkP] mkR }
1630 ------------------------------------------------------------------------
1631 section "Unsafe pointer equality"
1632 -- (#1 Bad Guy: Alistair Reid :)
1633 ------------------------------------------------------------------------
1635 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
1638 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
1640 ------------------------------------------------------------------------
1641 section "Parallelism"
1642 ------------------------------------------------------------------------
1644 primop ParOp "par#" GenPrimOp
1647 usage = { mangle ParOp [mkO] mkR }
1648 -- Note that Par is lazy to avoid that the sparked thing
1649 -- gets evaluted strictly, which it should *not* be
1650 has_side_effects = True
1652 -- HWL: The first 4 Int# in all par... annotations denote:
1653 -- name, granularity info, size of result, degree of parallelism
1654 -- Same structure as _seq_ i.e. returns Int#
1655 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
1656 -- `the processor containing the expression v'; it is not evaluated
1658 primop ParGlobalOp "parGlobal#" GenPrimOp
1659 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1661 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1662 has_side_effects = True
1664 primop ParLocalOp "parLocal#" GenPrimOp
1665 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1667 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1668 has_side_effects = True
1670 primop ParAtOp "parAt#" GenPrimOp
1671 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1673 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1674 has_side_effects = True
1676 primop ParAtAbsOp "parAtAbs#" GenPrimOp
1677 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1679 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1680 has_side_effects = True
1682 primop ParAtRelOp "parAtRel#" GenPrimOp
1683 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
1685 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
1686 has_side_effects = True
1688 primop ParAtForNowOp "parAtForNow#" GenPrimOp
1689 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
1691 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
1692 has_side_effects = True
1694 -- copyable# and noFollow# are yet to be implemented (for GpH)
1696 --primop CopyableOp "copyable#" GenPrimOp
1699 -- usage = { mangle CopyableOp [mkZ] mkR }
1700 -- has_side_effects = True
1702 --primop NoFollowOp "noFollow#" GenPrimOp
1705 -- usage = { mangle NoFollowOp [mkZ] mkR }
1706 -- has_side_effects = True
1709 ------------------------------------------------------------------------
1710 section "Tag to enum stuff"
1711 {Convert back and forth between values of enumerated types
1712 and small integers.}
1713 ------------------------------------------------------------------------
1715 primop DataToTagOp "dataToTag#" GenPrimOp
1718 primop TagToEnumOp "tagToEnum#" GenPrimOp
1721 ------------------------------------------------------------------------
1722 section "Bytecode operations"
1723 {Support for the bytecode interpreter and linker.}
1724 ------------------------------------------------------------------------
1727 primop AddrToHValueOp "addrToHValue#" GenPrimOp
1729 {Convert an Addr\# to a followable type.}
1731 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
1736 primop NewBCOOp "newBCO#" GenPrimOp
1737 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> Int# -> ByteArr# -> State# s -> (# State# s, BCO# #)
1739 has_side_effects = True
1742 ------------------------------------------------------------------------
1744 {{\tt unsafeCoerce\# :: a -> b} is not a primop, but is defined in MkId.lhs.}
1746 ------------------------------------------------------------------------
1749 ------------------------------------------------------------------------
1751 ------------------------------------------------------------------------