1 -----------------------------------------------------------------------
2 -- $Id: primops.txt,v 1.25 2001/08/17 17:18:53 apt Exp $
4 -- Primitive Operations
6 -----------------------------------------------------------------------
8 -- This file is processed by the utility program genprimopcode to produce
9 -- a number of include files within the compiler and optionally to produce
10 -- human-readable documentation.
12 -- It should first be preprocessed.
14 -- To add a new primop, you currently need to update the following files:
16 -- - this file (ghc/compiler/prelude/primops.txt), which includes
17 -- the type of the primop, and various other properties (its
18 -- strictness attributes, whether it is defined as a macro
19 -- or as out-of-line code, etc.)
21 -- - ghc/lib/std/PrelGHC.hi-boot, to declare the primop
23 -- - if the primop is inline (i.e. a macro), then:
24 -- ghc/includes/PrimOps.h
25 -- ghc/compiler/nativeGen/StixPrim.lhs
26 -- ghc/compiler/nativeGen/MachCode.lhs (if implementation is machine-dependent)
28 -- - or, for an out-of-line primop:
29 -- ghc/includes/PrimOps.h (just add the declaration)
30 -- ghc/rts/PrimOps.hc (define it here)
35 -- This file is divided into named sections, each containing or more primop entries.
36 -- Section headers have the format:
38 -- section "section-name" {description}
40 -- This information is used solely when producing documentation; it is otherwise ignored.
41 -- The description is optional.
43 -- The format of each primop entry is as follows:
45 -- primop internal-name "name-in-program-text" type category {description} attributes
47 -- The description is optional.
49 -- The default attribute values which apply if you don't specify
50 -- other ones. Attribute values can be True, False, or arbitrary
51 -- text between curly brackets. This is a kludge to enable
52 -- processors of this file to easily get hold of simple info
53 -- (eg, out_of_line), whilst avoiding parsing complex expressions
54 -- needed for strictness and usage info.
57 has_side_effects = False
62 strictness = { \ arity -> StrictnessInfo (replicate arity wwPrim) False }
63 usage = { nomangle other }
65 -- Currently, documentation is produced using latex, so contents of description fields
66 -- should be legal latex. Descriptions can contain matched pairs of embedded curly brackets.
1111 section "The word size story."
1112 {Haskell98 specifies that signed integers (type {\tt Int}) must contain at least 30
1113 bits. GHC always implements {\tt Int} using the primitive type {\tt Int\#}, whose
1114 size equals the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}. This
1115 is normally set based on the {\tt config.h} parameter {\tt 4},
1116 i.e., 32 bits on 32-bit machines, 64 bits on 64-bit machines. However, it can
1117 also be explicitly set to a smaller number, e.g., 31 bits, to allow the possibility
1118 of using tag bits. Currently GHC itself has only 32-bit and 64-bit variants,
1119 but 30 or 31-bit code can be exported as an external core file for use in
1122 GHC also implements a primitive unsigned integer type {\tt Word\#} which always
1123 has the same number of bits as {\tt Int\#}.
1125 In addition, GHC supports families of explicit-sized integers and words at
1126 8, 16, 32, and 64 bits, with the usual arithmetic operations, comparisons,
1127 and a range of conversions. The 8-bit and 16-bit sizes are always represented as
1128 {\tt Int\#} and {\tt Word\#}, and the operations implemented in terms of the
1129 the primops on these types, with suitable range restrictions on the results
1130 (using the {\tt Narrow$n$Int\#} and {\tt Narrow$n$Word\#} families of primops.
1131 The 32-bit sizes are represented using {\tt Int\#} and {\tt Word\#} when
1132 {\tt WORD\_SIZE\_IN\_BITS} $\geq$ 32;
1133 otherwise, these are represented using distinct primitive types {\tt Int32\#}
1134 and {\tt Word32\#}. These (when needed) have a complete set of corresponding
1135 operations; however, nearly all of these are implemented as external C functions
1136 rather than as primops. Exactly the same story applies to the 64-bit sizes.
1137 All of these details are hidden under the {\tt PrelInt} and {\tt PrelWord} modules,
1138 which use {\tt \#if}-defs to invoke the appropriate types and operators.
1140 Word size also matters for the families of primops
1141 for indexing/reading/writing fixed-size quantities at offsets from
1142 an array base, address, or foreign pointer. Here, a slightly different approach is taken.
1143 The names of these primops are fixed, but their
1144 {\it types} vary according to the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if
1145 word size is at least 32 bits then an operator like \texttt{indexInt32Array\#}
1146 has type {\tt ByteArr\# -> Int\# -> Int\#}; otherwise it has type
1147 {\tt ByteArr\# -> Int\# -> Int32\#}. This approach confines the necessary {\tt \#if}-defs to this file;
1148 no conditional compilation is needed in the files that expose these primops, namely \texttt{lib/std/PrelStorable.lhs},
1149 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated fashion) in \texttt{hslibs/lang/ForeignObj.lhs}
1150 and \texttt{hslibs/lang/Addr.lhs}.
1152 Finally, there are strongly deprecated primops for coercing between {\tt Addr\#}, the primitive
1153 type of machine addresses, and {\tt Int\#}. These are pretty bogus anyway, but will work on
1154 existing 32-bit and 64-bit GHC targets; they are completely bogus when tag bits are used in
1155 {\tt Int\#}, so are not available in this case.
1158 -- Define synonyms for indexing ops.
1176 ------------------------------------------------------------------------
1178 {Operations on 31-bit characters.}
1179 ------------------------------------------------------------------------
1182 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
1183 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
1185 primop CharEqOp "eqChar#" Compare
1186 Char# -> Char# -> Bool
1187 with commutable = True
1189 primop CharNeOp "neChar#" Compare
1190 Char# -> Char# -> Bool
1191 with commutable = True
1193 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
1194 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
1196 primop OrdOp "ord#" GenPrimOp Char# -> Int#
1198 ------------------------------------------------------------------------
1200 {Operations on native-size integers (30+ bits).}
1201 ------------------------------------------------------------------------
1203 primop IntAddOp "+#" Dyadic
1204 Int# -> Int# -> Int#
1205 with commutable = True
1207 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
1209 primop IntMulOp "*#"
1210 Dyadic Int# -> Int# -> Int#
1211 with commutable = True
1213 primop IntQuotOp "quotInt#" Dyadic
1214 Int# -> Int# -> Int#
1215 {Rounds towards zero.}
1216 with can_fail = True
1218 primop IntRemOp "remInt#" Dyadic
1219 Int# -> Int# -> Int#
1220 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
1221 with can_fail = True
1223 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
1224 primop IntNegOp "negateInt#" Monadic Int# -> Int#
1225 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1226 {Add with carry. First member of result is (wrapped) sum; second member is 0 iff no overflow occured.}
1227 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1228 {Subtract with carry. First member of result is (wrapped) difference; second member is 0 iff no overflow occured.}
1229 primop IntMulCOp "mulIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1230 {Multiply with carry. First member of result is (wrapped) product; second member is 0 iff no overflow occured.}
1231 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
1232 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
1234 primop IntEqOp "==#" Compare
1235 Int# -> Int# -> Bool
1236 with commutable = True
1238 primop IntNeOp "/=#" Compare
1239 Int# -> Int# -> Bool
1240 with commutable = True
1242 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
1243 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
1245 primop ChrOp "chr#" GenPrimOp Int# -> Char#
1247 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
1248 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
1249 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
1251 primop Int2IntegerOp "int2Integer#"
1252 GenPrimOp Int# -> (# Int#, ByteArr# #)
1253 with out_of_line = True
1255 primop ISllOp "iShiftL#" GenPrimOp Int# -> Int# -> Int#
1256 {Shift left. Return 0 if shifted by more than size of an Int\#.}
1257 primop ISraOp "iShiftRA#" GenPrimOp Int# -> Int# -> Int#
1258 {Shift right arithemetic. Return 0 if shifted by more than size of an Int\#.}
1259 primop ISrlOp "iShiftRL#" GenPrimOp Int# -> Int# -> Int#
1260 {Shift right logical. Return 0 if shifted by more than size of an Int\#.}
1262 ------------------------------------------------------------------------
1264 {Operations on native-sized unsigned words (30+ bits).}
1265 ------------------------------------------------------------------------
1267 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
1268 with commutable = True
1270 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
1272 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
1273 with commutable = True
1275 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
1276 with can_fail = True
1278 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
1279 with can_fail = True
1281 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
1282 with commutable = True
1284 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
1285 with commutable = True
1287 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
1288 with commutable = True
1290 primop NotOp "not#" Monadic Word# -> Word#
1292 primop SllOp "shiftL#" GenPrimOp Word# -> Int# -> Word#
1293 {Shift left logical. Return 0 if shifted by more than number of bits in a Word\#.}
1294 primop SrlOp "shiftRL#" GenPrimOp Word# -> Int# -> Word#
1295 {Shift right logical. Return 0 if shifted by more than number of bits in a Word\#.}
1297 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
1299 primop Word2IntegerOp "word2Integer#" GenPrimOp
1300 Word# -> (# Int#, ByteArr# #)
1301 with out_of_line = True
1303 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
1304 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
1305 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
1306 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
1307 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
1308 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
1310 ------------------------------------------------------------------------
1311 section "Narrowings"
1312 {Explicit narrowing of native-sized ints or words.}
1313 ------------------------------------------------------------------------
1315 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
1316 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
1317 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
1318 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
1319 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
1320 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
1327 ------------------------------------------------------------------------
1329 {Operations on 64-bit unsigned words. This type is only used
1330 if plain Int\# has less than 64 bits. In any case, the operations
1331 are not primops; they are implemented (if needed) as ccalls instead.}
1332 ------------------------------------------------------------------------
1334 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
1335 Int64# -> (# Int#, ByteArr# #)
1336 with out_of_line = True
1338 ------------------------------------------------------------------------
1340 {Operations on 64-bit unsigned words. This type is only used
1341 if plain Word\# has less than 64 bits. In any case, the operations
1342 are not primops; they are implemented (if needed) as ccalls instead.}
1343 ------------------------------------------------------------------------
1345 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
1346 Word64# -> (# Int#, ByteArr# #)
1347 with out_of_line = True
1351 ------------------------------------------------------------------------
1353 {Operations on arbitrary-precision integers. These operations are
1354 implemented via the GMP package. An integer is represented as a pair
1355 consisting of an Int\# representing the number of 'limbs' in use and
1356 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
1357 are returned as unboxed pairs, but must be passed as separate components.}
1358 ------------------------------------------------------------------------
1360 primop IntegerAddOp "plusInteger#" GenPrimOp
1361 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1362 with commutable = True
1365 primop IntegerSubOp "minusInteger#" GenPrimOp
1366 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1367 with out_of_line = True
1369 primop IntegerMulOp "timesInteger#" GenPrimOp
1370 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1371 with commutable = True
1374 primop IntegerGcdOp "gcdInteger#" GenPrimOp
1375 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1376 {Greatest common divisor.}
1377 with commutable = True
1380 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
1381 Int# -> ByteArr# -> Int# -> Int#
1382 {Greatest common divisor, where second argument is an ordinary Int\#.}
1383 -- with commutable = True (surely not? APT 8/01)
1385 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
1386 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1387 {Divisor is guaranteed to be a factor of dividend.}
1388 with out_of_line = True
1390 primop IntegerQuotOp "quotInteger#" GenPrimOp
1391 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1392 {Rounds towards zero.}
1393 with out_of_line = True
1395 primop IntegerRemOp "remInteger#" GenPrimOp
1396 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1397 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
1398 with out_of_line = True
1400 primop IntegerCmpOp "cmpInteger#" GenPrimOp
1401 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
1402 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
1403 with needs_wrapper = True
1405 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
1406 Int# -> ByteArr# -> Int# -> Int#
1407 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
1408 is an ordinary Int\#.}
1409 with needs_wrapper = True
1411 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
1412 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
1413 {Compute quot and rem simulaneously.}
1414 with can_fail = True
1417 primop IntegerDivModOp "divModInteger#" GenPrimOp
1418 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
1419 {Compute div and mod simultaneously, where div rounds towards negative infinity
1420 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
1421 with can_fail = True
1424 primop Integer2IntOp "integer2Int#" GenPrimOp
1425 Int# -> ByteArr# -> Int#
1426 with needs_wrapper = True
1428 primop Integer2WordOp "integer2Word#" GenPrimOp
1429 Int# -> ByteArr# -> Word#
1430 with needs_wrapper = True
1441 primop IntegerToInt64Op "integerToInt64#" GenPrimOp
1442 Int# -> ByteArr# -> Int64#
1444 primop IntegerToWord64Op "integerToWord64#" GenPrimOp
1445 Int# -> ByteArr# -> Word64#
1448 primop IntegerAndOp "andInteger#" GenPrimOp
1449 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1450 with out_of_line = True
1452 primop IntegerOrOp "orInteger#" GenPrimOp
1453 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1454 with out_of_line = True
1456 primop IntegerXorOp "xorInteger#" GenPrimOp
1457 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1458 with out_of_line = True
1460 primop IntegerComplementOp "complementInteger#" GenPrimOp
1461 Int# -> ByteArr# -> (# Int#, ByteArr# #)
1462 with out_of_line = True
1465 ------------------------------------------------------------------------
1467 {Operations on double-precision (64 bit) floating-point numbers.}
1468 ------------------------------------------------------------------------
1470 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
1471 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
1473 primop DoubleEqOp "==##" Compare
1474 Double# -> Double# -> Bool
1475 with commutable = True
1477 primop DoubleNeOp "/=##" Compare
1478 Double# -> Double# -> Bool
1479 with commutable = True
1481 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
1482 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
1484 primop DoubleAddOp "+##" Dyadic
1485 Double# -> Double# -> Double#
1486 with commutable = True
1488 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
1490 primop DoubleMulOp "*##" Dyadic
1491 Double# -> Double# -> Double#
1492 with commutable = True
1494 primop DoubleDivOp "/##" Dyadic
1495 Double# -> Double# -> Double#
1496 with can_fail = True
1498 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
1500 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
1501 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
1503 primop DoubleExpOp "expDouble#" Monadic
1505 with needs_wrapper = True
1507 primop DoubleLogOp "logDouble#" Monadic
1510 needs_wrapper = True
1513 primop DoubleSqrtOp "sqrtDouble#" Monadic
1515 with needs_wrapper = True
1517 primop DoubleSinOp "sinDouble#" Monadic
1519 with needs_wrapper = True
1521 primop DoubleCosOp "cosDouble#" Monadic
1523 with needs_wrapper = True
1525 primop DoubleTanOp "tanDouble#" Monadic
1527 with needs_wrapper = True
1529 primop DoubleAsinOp "asinDouble#" Monadic
1532 needs_wrapper = True
1535 primop DoubleAcosOp "acosDouble#" Monadic
1538 needs_wrapper = True
1541 primop DoubleAtanOp "atanDouble#" Monadic
1544 needs_wrapper = True
1546 primop DoubleSinhOp "sinhDouble#" Monadic
1548 with needs_wrapper = True
1550 primop DoubleCoshOp "coshDouble#" Monadic
1552 with needs_wrapper = True
1554 primop DoubleTanhOp "tanhDouble#" Monadic
1556 with needs_wrapper = True
1558 primop DoublePowerOp "**##" Dyadic
1559 Double# -> Double# -> Double#
1561 with needs_wrapper = True
1563 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
1564 Double# -> (# Int#, Int#, ByteArr# #)
1565 {Convert to arbitrary-precision integer.
1566 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
1567 holding the mantissa.}
1568 with out_of_line = True
1570 ------------------------------------------------------------------------
1572 {Operations on single-precision (32-bit) floating-point numbers.}
1573 ------------------------------------------------------------------------
1575 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
1576 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
1578 primop FloatEqOp "eqFloat#" Compare
1579 Float# -> Float# -> Bool
1580 with commutable = True
1582 primop FloatNeOp "neFloat#" Compare
1583 Float# -> Float# -> Bool
1584 with commutable = True
1586 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
1587 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
1589 primop FloatAddOp "plusFloat#" Dyadic
1590 Float# -> Float# -> Float#
1591 with commutable = True
1593 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
1595 primop FloatMulOp "timesFloat#" Dyadic
1596 Float# -> Float# -> Float#
1597 with commutable = True
1599 primop FloatDivOp "divideFloat#" Dyadic
1600 Float# -> Float# -> Float#
1601 with can_fail = True
1603 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
1605 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
1607 primop FloatExpOp "expFloat#" Monadic
1609 with needs_wrapper = True
1611 primop FloatLogOp "logFloat#" Monadic
1613 with needs_wrapper = True
1616 primop FloatSqrtOp "sqrtFloat#" Monadic
1618 with needs_wrapper = True
1620 primop FloatSinOp "sinFloat#" Monadic
1622 with needs_wrapper = True
1624 primop FloatCosOp "cosFloat#" Monadic
1626 with needs_wrapper = True
1628 primop FloatTanOp "tanFloat#" Monadic
1630 with needs_wrapper = True
1632 primop FloatAsinOp "asinFloat#" Monadic
1634 with needs_wrapper = True
1637 primop FloatAcosOp "acosFloat#" Monadic
1639 with needs_wrapper = True
1642 primop FloatAtanOp "atanFloat#" Monadic
1644 with needs_wrapper = True
1646 primop FloatSinhOp "sinhFloat#" Monadic
1648 with needs_wrapper = True
1650 primop FloatCoshOp "coshFloat#" Monadic
1652 with needs_wrapper = True
1654 primop FloatTanhOp "tanhFloat#" Monadic
1656 with needs_wrapper = True
1658 primop FloatPowerOp "powerFloat#" Dyadic
1659 Float# -> Float# -> Float#
1660 with needs_wrapper = True
1662 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
1664 primop FloatDecodeOp "decodeFloat#" GenPrimOp
1665 Float# -> (# Int#, Int#, ByteArr# #)
1666 {Convert to arbitrary-precision integer.
1667 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
1668 holding the mantissa.}
1669 with out_of_line = True
1671 ------------------------------------------------------------------------
1673 {Operations on Array\#.}
1674 ------------------------------------------------------------------------
1676 primop NewArrayOp "newArray#" GenPrimOp
1677 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
1678 {Create a new mutable array of specified size (in bytes),
1679 in the specified state thread,
1680 with each element containing the specified initial value.}
1682 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1683 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
1686 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
1687 MutArr# s a -> MutArr# s a -> Bool
1689 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
1691 primop ReadArrayOp "readArray#" GenPrimOp
1692 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
1693 {Read from specified index of mutable array. Result is not yet evaluated.}
1695 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
1697 primop WriteArrayOp "writeArray#" GenPrimOp
1698 MutArr# s a -> Int# -> a -> State# s -> State# s
1699 {Write to specified index of mutable array.}
1701 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
1702 strictness = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
1703 has_side_effects = True
1705 primop IndexArrayOp "indexArray#" GenPrimOp
1706 Array# a -> Int# -> (# a #)
1707 {Read from specified index of immutable array. Result is packaged into
1708 an unboxed singleton; the result itself is not yet evaluated.}
1710 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
1712 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
1713 MutArr# s a -> State# s -> (# State# s, Array# a #)
1714 {Make a mutable array immutable, without copying.}
1716 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
1717 has_side_effects = True
1719 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
1720 Array# a -> State# s -> (# State# s, MutArr# s a #)
1721 {Make an immutable array mutable, without copying.}
1723 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
1726 ------------------------------------------------------------------------
1727 section "Byte Arrays"
1728 {Operations on ByteArray\#. A ByteArray\# is a just a region of
1729 raw memory in the garbage-collected heap, which is not scanned
1730 for pointers. It carries its own size (in bytes). There are
1731 three sets of operations for accessing byte array contents:
1732 index for reading from immutable byte arrays, and read/write
1733 for mutable byte arrays. Each set contains operations for
1734 a range of useful primitive data types. Each operation takes
1735 an offset measured in terms of the size fo the primitive type
1736 being read or written.}
1738 ------------------------------------------------------------------------
1740 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
1741 Int# -> State# s -> (# State# s, MutByteArr# s #)
1742 {Create a new mutable byte array of specified size (in bytes), in
1743 the specified state thread.}
1744 with out_of_line = True
1746 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
1747 Int# -> State# s -> (# State# s, MutByteArr# s #)
1748 {Create a mutable byte array that the GC guarantees not to move.}
1749 with out_of_line = True
1751 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
1753 {Intended for use with pinned arrays; otherwise very unsafe!}
1755 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
1756 MutByteArr# s -> MutByteArr# s -> Bool
1758 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
1759 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
1760 {Make a mutable byte array immutable, without copying.}
1762 has_side_effects = True
1764 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
1767 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
1768 MutByteArr# s -> Int#
1771 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
1772 ByteArr# -> Int# -> Char#
1773 {Read 8-bit character; offset in bytes.}
1775 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
1776 ByteArr# -> Int# -> Char#
1777 {Read 31-bit character; offset in 4-byte words.}
1779 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
1780 ByteArr# -> Int# -> Int#
1782 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
1783 ByteArr# -> Int# -> Word#
1785 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
1786 ByteArr# -> Int# -> Addr#
1788 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
1789 ByteArr# -> Int# -> Float#
1791 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
1792 ByteArr# -> Int# -> Double#
1794 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
1795 ByteArr# -> Int# -> StablePtr# a
1797 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
1798 ByteArr# -> Int# -> Int#
1800 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
1801 ByteArr# -> Int# -> Int#
1803 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
1804 ByteArr# -> Int# -> Int#
1806 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
1807 ByteArr# -> Int# -> Int64#
1809 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
1810 ByteArr# -> Int# -> Word#
1812 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
1813 ByteArr# -> Int# -> Word#
1815 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
1816 ByteArr# -> Int# -> Word#
1818 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
1819 ByteArr# -> Int# -> Word64#
1821 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
1822 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
1823 {Read 8-bit character; offset in bytes.}
1825 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
1826 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
1827 {Read 31-bit character; offset in 4-byte words.}
1829 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
1830 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1832 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
1833 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1835 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
1836 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
1838 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
1839 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
1841 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
1842 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
1844 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
1845 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
1847 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
1848 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1850 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
1851 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1853 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
1854 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1856 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
1857 MutByteArr# s -> Int# -> State# s -> (# State# s, Int64# #)
1859 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
1860 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1862 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
1863 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1865 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
1866 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1868 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
1869 MutByteArr# s -> Int# -> State# s -> (# State# s, Word64# #)
1871 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
1872 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
1873 {Write 8-bit character; offset in bytes.}
1874 with has_side_effects = True
1876 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
1877 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
1878 {Write 31-bit character; offset in 4-byte words.}
1879 with has_side_effects = True
1881 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
1882 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1883 with has_side_effects = True
1885 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
1886 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1887 with has_side_effects = True
1889 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
1890 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
1891 with has_side_effects = True
1893 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
1894 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
1895 with has_side_effects = True
1897 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
1898 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
1899 with has_side_effects = True
1901 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
1902 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
1903 with has_side_effects = True
1905 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
1906 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1907 with has_side_effects = True
1909 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
1910 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1911 with has_side_effects = True
1913 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
1914 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1915 with has_side_effects = True
1917 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
1918 MutByteArr# s -> Int# -> Int64# -> State# s -> State# s
1919 with has_side_effects = True
1921 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
1922 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1923 with has_side_effects = True
1925 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
1926 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1927 with has_side_effects = True
1929 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
1930 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1931 with has_side_effects = True
1933 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
1934 MutByteArr# s -> Int# -> Word64# -> State# s -> State# s
1935 with has_side_effects = True
1937 ------------------------------------------------------------------------
1939 {Addr\# is an arbitrary machine address assumed to point outside
1940 the garbage-collected heap.}
1941 ------------------------------------------------------------------------
1943 primop AddrNullOp "nullAddr#" GenPrimOp Int# -> Addr#
1944 {Returns null address. Argument is ignored (nullary primops
1946 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
1947 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
1948 {Result is meaningless if two Addr\#s are so far apart that their
1949 difference doesn't fit in an Int\#.}
1950 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
1951 {Return the remainder when the Addr\# arg, treated like an Int\#,
1952 is divided by the Int\# arg.}
1954 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
1955 {Coerce directly from address to int. Strongly deprecated.}
1956 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
1957 {Coerce directly from int to address. Strongly deprecated.}
1960 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
1961 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
1962 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
1963 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
1964 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
1965 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
1967 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
1968 Addr# -> Int# -> Char#
1969 {Reads 8-bit character; offset in bytes.}
1971 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
1972 Addr# -> Int# -> Char#
1973 {Reads 31-bit character; offset in 4-byte words.}
1975 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
1976 Addr# -> Int# -> Int#
1978 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
1979 Addr# -> Int# -> Word#
1981 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
1982 Addr# -> Int# -> Addr#
1984 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
1985 Addr# -> Int# -> Float#
1987 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
1988 Addr# -> Int# -> Double#
1990 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
1991 Addr# -> Int# -> StablePtr# a
1993 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
1994 Addr# -> Int# -> Int#
1996 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
1997 Addr# -> Int# -> Int#
1999 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
2000 Addr# -> Int# -> Int#
2002 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
2003 Addr# -> Int# -> Int64#
2005 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
2006 Addr# -> Int# -> Word#
2008 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
2009 Addr# -> Int# -> Word#
2011 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
2012 Addr# -> Int# -> Word#
2014 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
2015 Addr# -> Int# -> Word64#
2017 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
2018 Addr# -> Int# -> State# s -> (# State# s, Char# #)
2019 {Reads 8-bit character; offset in bytes.}
2021 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
2022 Addr# -> Int# -> State# s -> (# State# s, Char# #)
2023 {Reads 31-bit character; offset in 4-byte words.}
2025 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
2026 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2028 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
2029 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2031 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
2032 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
2034 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
2035 Addr# -> Int# -> State# s -> (# State# s, Float# #)
2037 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
2038 Addr# -> Int# -> State# s -> (# State# s, Double# #)
2040 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
2041 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
2043 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
2044 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2046 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
2047 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2049 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
2050 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2052 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
2053 Addr# -> Int# -> State# s -> (# State# s, Int64# #)
2055 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
2056 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2058 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
2059 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2061 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
2062 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2064 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
2065 Addr# -> Int# -> State# s -> (# State# s, Word64# #)
2068 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
2069 Addr# -> Int# -> Char# -> State# s -> State# s
2070 with has_side_effects = True
2072 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
2073 Addr# -> Int# -> Char# -> State# s -> State# s
2074 with has_side_effects = True
2076 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
2077 Addr# -> Int# -> Int# -> State# s -> State# s
2078 with has_side_effects = True
2080 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
2081 Addr# -> Int# -> Word# -> State# s -> State# s
2082 with has_side_effects = True
2084 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
2085 Addr# -> Int# -> Addr# -> State# s -> State# s
2086 with has_side_effects = True
2088 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
2089 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
2090 with has_side_effects = True
2092 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
2093 Addr# -> Int# -> Float# -> State# s -> State# s
2094 with has_side_effects = True
2096 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
2097 Addr# -> Int# -> Double# -> State# s -> State# s
2098 with has_side_effects = True
2100 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
2101 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
2102 with has_side_effects = True
2104 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
2105 Addr# -> Int# -> Int# -> State# s -> State# s
2106 with has_side_effects = True
2108 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
2109 Addr# -> Int# -> Int# -> State# s -> State# s
2110 with has_side_effects = True
2112 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
2113 Addr# -> Int# -> Int# -> State# s -> State# s
2114 with has_side_effects = True
2116 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
2117 Addr# -> Int# -> Int64# -> State# s -> State# s
2118 with has_side_effects = True
2120 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
2121 Addr# -> Int# -> Word# -> State# s -> State# s
2122 with has_side_effects = True
2124 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
2125 Addr# -> Int# -> Word# -> State# s -> State# s
2126 with has_side_effects = True
2128 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
2129 Addr# -> Int# -> Word# -> State# s -> State# s
2130 with has_side_effects = True
2132 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
2133 Addr# -> Int# -> Word64# -> State# s -> State# s
2134 with has_side_effects = True
2136 ------------------------------------------------------------------------
2137 section "ForeignObj#"
2138 {Operations on ForeignObj\#. The indexing operations are
2140 ------------------------------------------------------------------------
2142 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
2143 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
2145 has_side_effects = True
2148 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
2149 ForeignObj# -> Addr# -> State# s -> State# s
2151 has_side_effects = True
2153 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
2154 ForeignObj# -> Addr#
2156 primop TouchOp "touch#" GenPrimOp
2157 o -> State# RealWorld -> State# RealWorld
2159 has_side_effects = True
2160 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2162 primop EqForeignObj "eqForeignObj#" GenPrimOp
2163 ForeignObj# -> ForeignObj# -> Bool
2164 with commutable = True
2166 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
2167 ForeignObj# -> Int# -> Char#
2168 {Read 8-bit character; offset in bytes.}
2170 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
2171 ForeignObj# -> Int# -> Char#
2172 {Read 31-bit character; offset in 4-byte words.}
2174 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
2175 ForeignObj# -> Int# -> Int#
2177 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
2178 ForeignObj# -> Int# -> Word#
2180 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
2181 ForeignObj# -> Int# -> Addr#
2183 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
2184 ForeignObj# -> Int# -> Float#
2186 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
2187 ForeignObj# -> Int# -> Double#
2189 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
2190 ForeignObj# -> Int# -> StablePtr# a
2192 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
2193 ForeignObj# -> Int# -> Int#
2195 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
2196 ForeignObj# -> Int# -> Int#
2198 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
2199 ForeignObj# -> Int# -> Int#
2201 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
2202 ForeignObj# -> Int# -> Int64#
2204 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
2205 ForeignObj# -> Int# -> Word#
2207 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
2208 ForeignObj# -> Int# -> Word#
2210 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
2211 ForeignObj# -> Int# -> Word#
2213 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
2214 ForeignObj# -> Int# -> Word64#
2218 ------------------------------------------------------------------------
2219 section "Mutable variables"
2220 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
2221 ------------------------------------------------------------------------
2223 primop NewMutVarOp "newMutVar#" GenPrimOp
2224 a -> State# s -> (# State# s, MutVar# s a #)
2225 {Create MutVar\# with specified initial value in specified state thread.}
2227 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
2228 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2231 primop ReadMutVarOp "readMutVar#" GenPrimOp
2232 MutVar# s a -> State# s -> (# State# s, a #)
2233 {Read contents of MutVar\#. Result is not yet evaluated.}
2235 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
2237 primop WriteMutVarOp "writeMutVar#" GenPrimOp
2238 MutVar# s a -> a -> State# s -> State# s
2239 {Write contents of MutVar\#.}
2241 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
2242 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
2243 has_side_effects = True
2245 primop SameMutVarOp "sameMutVar#" GenPrimOp
2246 MutVar# s a -> MutVar# s a -> Bool
2248 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
2250 ------------------------------------------------------------------------
2251 section "Exceptions"
2252 ------------------------------------------------------------------------
2254 primop CatchOp "catch#" GenPrimOp
2255 (State# RealWorld -> (# State# RealWorld, a #) )
2256 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
2258 -> (# State# RealWorld, a #)
2260 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
2261 -- Catch is actually strict in its first argument
2262 -- but we don't want to tell the strictness
2263 -- analyser about that!
2264 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
2265 -- [mkO, mkO . (inFun mkM mkO)] mkO
2266 -- might use caught action multiply
2269 primop RaiseOp "raise#" GenPrimOp
2272 strictness = { \ arity -> StrictnessInfo [wwLazy] True }
2273 -- NB: True => result is bottom
2274 usage = { mangle RaiseOp [mkM] mkM }
2277 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
2278 (State# RealWorld -> (# State# RealWorld, a #))
2279 -> (State# RealWorld -> (# State# RealWorld, a #))
2281 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
2284 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
2285 (State# RealWorld -> (# State# RealWorld, a #))
2286 -> (State# RealWorld -> (# State# RealWorld, a #))
2288 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
2291 ------------------------------------------------------------------------
2292 section "Synchronized Mutable Variables"
2293 {Operations on MVar\#s, which are shared mutable variables
2294 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
2295 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
2296 ------------------------------------------------------------------------
2299 primop NewMVarOp "newMVar#" GenPrimOp
2300 State# s -> (# State# s, MVar# s a #)
2301 {Create new mvar; initially empty.}
2303 usage = { mangle NewMVarOp [mkP] mkR }
2306 primop TakeMVarOp "takeMVar#" GenPrimOp
2307 MVar# s a -> State# s -> (# State# s, a #)
2308 {If mvar is empty, block until it becomes full.
2309 Then remove and return its contents, and set it empty.}
2311 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
2312 has_side_effects = True
2315 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
2316 MVar# s a -> State# s -> (# State# s, Int#, a #)
2317 {If mvar is empty, immediately return with integer 0 and value undefined.
2318 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
2320 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
2321 has_side_effects = True
2324 primop PutMVarOp "putMVar#" GenPrimOp
2325 MVar# s a -> a -> State# s -> State# s
2326 {If mvar is full, block until it becomes empty.
2327 Then store value arg as its new contents.}
2329 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
2330 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
2331 has_side_effects = True
2334 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
2335 MVar# s a -> a -> State# s -> (# State# s, Int# #)
2336 {If mvar is full, immediately return with integer 0.
2337 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
2339 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
2340 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
2341 has_side_effects = True
2344 primop SameMVarOp "sameMVar#" GenPrimOp
2345 MVar# s a -> MVar# s a -> Bool
2347 usage = { mangle SameMVarOp [mkP, mkP] mkM }
2349 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
2350 MVar# s a -> State# s -> (# State# s, Int# #)
2351 {Return 1 if mvar is empty; 0 otherwise.}
2353 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
2356 ------------------------------------------------------------------------
2357 section "Delay/wait operations"
2358 ------------------------------------------------------------------------
2360 primop DelayOp "delay#" GenPrimOp
2361 Int# -> State# s -> State# s
2362 {Sleep specified number of microseconds.}
2364 needs_wrapper = True
2365 has_side_effects = True
2368 primop WaitReadOp "waitRead#" GenPrimOp
2369 Int# -> State# s -> State# s
2370 {Block until input is available on specified file descriptor.}
2372 needs_wrapper = True
2373 has_side_effects = True
2376 primop WaitWriteOp "waitWrite#" GenPrimOp
2377 Int# -> State# s -> State# s
2378 {Block until output is possible on specified file descriptor.}
2380 needs_wrapper = True
2381 has_side_effects = True
2384 ------------------------------------------------------------------------
2385 section "Concurrency primitives"
2386 {(In a non-concurrent implementation, ThreadId\# can be as singleton
2387 type, whose (unique) value is returned by myThreadId\#. The
2388 other operations can be omitted.)}
2389 ------------------------------------------------------------------------
2391 primop ForkOp "fork#" GenPrimOp
2392 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
2394 usage = { mangle ForkOp [mkO, mkP] mkR }
2395 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2396 has_side_effects = True
2399 primop KillThreadOp "killThread#" GenPrimOp
2400 ThreadId# -> a -> State# RealWorld -> State# RealWorld
2402 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
2403 has_side_effects = True
2406 primop YieldOp "yield#" GenPrimOp
2407 State# RealWorld -> State# RealWorld
2409 has_side_effects = True
2412 primop MyThreadIdOp "myThreadId#" GenPrimOp
2413 State# RealWorld -> (# State# RealWorld, ThreadId# #)
2415 ------------------------------------------------------------------------
2416 section "Weak pointers"
2417 ------------------------------------------------------------------------
2419 -- note that tyvar "o" denotes openAlphaTyVar
2421 primop MkWeakOp "mkWeak#" GenPrimOp
2422 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
2424 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
2425 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
2426 has_side_effects = True
2429 primop DeRefWeakOp "deRefWeak#" GenPrimOp
2430 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
2432 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
2433 has_side_effects = True
2435 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
2436 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
2437 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
2439 usage = { mangle FinalizeWeakOp [mkM, mkP]
2440 (mkR . (inUB FinalizeWeakOp
2441 [id,id,inFun FinalizeWeakOp mkR mkM])) }
2442 has_side_effects = True
2445 ------------------------------------------------------------------------
2446 section "Stable pointers and names"
2447 ------------------------------------------------------------------------
2449 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
2450 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
2452 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2453 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
2454 has_side_effects = True
2456 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
2457 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
2459 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
2460 needs_wrapper = True
2461 has_side_effects = True
2463 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
2464 StablePtr# a -> StablePtr# a -> Int#
2466 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
2467 has_side_effects = True
2469 primop MakeStableNameOp "makeStableName#" GenPrimOp
2470 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
2472 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
2473 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2474 needs_wrapper = True
2475 has_side_effects = True
2478 primop EqStableNameOp "eqStableName#" GenPrimOp
2479 StableName# a -> StableName# a -> Int#
2481 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
2483 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
2484 StableName# a -> Int#
2486 usage = { mangle StableNameToIntOp [mkP] mkR }
2488 ------------------------------------------------------------------------
2489 section "Unsafe pointer equality"
2490 -- (#1 Bad Guy: Alistair Reid :)
2491 ------------------------------------------------------------------------
2493 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
2496 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
2498 ------------------------------------------------------------------------
2499 section "Parallelism"
2500 ------------------------------------------------------------------------
2502 primop SeqOp "seq#" GenPrimOp
2505 usage = { mangle SeqOp [mkO] mkR }
2506 strictness = { \ arity -> StrictnessInfo [wwStrict] False }
2507 -- Seq is strict in its argument; see notes in ConFold.lhs
2508 has_side_effects = True
2510 primop ParOp "par#" GenPrimOp
2513 usage = { mangle ParOp [mkO] mkR }
2514 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
2515 -- Note that Par is lazy to avoid that the sparked thing
2516 -- gets evaluted strictly, which it should *not* be
2517 has_side_effects = True
2519 -- HWL: The first 4 Int# in all par... annotations denote:
2520 -- name, granularity info, size of result, degree of parallelism
2521 -- Same structure as _seq_ i.e. returns Int#
2522 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
2523 -- `the processor containing the expression v'; it is not evaluated
2525 primop ParGlobalOp "parGlobal#" GenPrimOp
2526 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2528 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2529 has_side_effects = True
2531 primop ParLocalOp "parLocal#" GenPrimOp
2532 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2534 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2535 has_side_effects = True
2537 primop ParAtOp "parAt#" GenPrimOp
2538 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
2540 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
2541 has_side_effects = True
2543 primop ParAtAbsOp "parAtAbs#" GenPrimOp
2544 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2546 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2547 has_side_effects = True
2549 primop ParAtRelOp "parAtRel#" GenPrimOp
2550 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2552 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2553 has_side_effects = True
2555 primop ParAtForNowOp "parAtForNow#" GenPrimOp
2556 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
2558 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
2559 has_side_effects = True
2561 -- copyable# and noFollow# are yet to be implemented (for GpH)
2563 --primop CopyableOp "copyable#" GenPrimOp
2566 -- usage = { mangle CopyableOp [mkZ] mkR }
2567 -- has_side_effects = True
2569 --primop NoFollowOp "noFollow#" GenPrimOp
2572 -- usage = { mangle NoFollowOp [mkZ] mkR }
2573 -- has_side_effects = True
2576 ------------------------------------------------------------------------
2577 section "Tag to enum stuff"
2578 {Convert back and forth between values of enumerated types
2579 and small integers.}
2580 ------------------------------------------------------------------------
2582 primop DataToTagOp "dataToTag#" GenPrimOp
2585 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
2587 primop TagToEnumOp "tagToEnum#" GenPrimOp
2590 ------------------------------------------------------------------------
2591 section "Bytecode operations"
2592 {Support for the bytecode interpreter and linker.}
2593 ------------------------------------------------------------------------
2596 primop AddrToHValueOp "addrToHValue#" GenPrimOp
2598 {Convert an Addr\# to a followable type.}
2600 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
2605 primop NewBCOOp "newBCO#" GenPrimOp
2606 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
2608 has_side_effects = True
2611 ------------------------------------------------------------------------
2613 ------------------------------------------------------------------------