1 -----------------------------------------------------------------------
2 -- $Id: primops.txt,v 1.26 2001/09/14 15:51:42 simonpj 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.
1143 section "The word size story."
1144 {Haskell98 specifies that signed integers (type {\tt Int}) must contain at least 30
1145 bits. GHC always implements {\tt Int} using the primitive type {\tt Int\#}, whose
1146 size equals the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}. This
1147 is normally set based on the {\tt config.h} parameter {\tt SIZEOF\_LONG},
1148 i.e., 32 bits on 32-bit machines, 64 bits on 64-bit machines. However, it can
1149 also be explicitly set to a smaller number, e.g., 31 bits, to allow the possibility
1150 of using tag bits. Currently GHC itself has only 32-bit and 64-bit variants,
1151 but 30 or 31-bit code can be exported as an external core file for use in
1154 GHC also implements a primitive unsigned integer type {\tt Word\#} which always
1155 has the same number of bits as {\tt Int\#}.
1157 In addition, GHC supports families of explicit-sized integers and words at
1158 8, 16, 32, and 64 bits, with the usual arithmetic operations, comparisons,
1159 and a range of conversions. The 8-bit and 16-bit sizes are always represented as
1160 {\tt Int\#} and {\tt Word\#}, and the operations implemented in terms of the
1161 the primops on these types, with suitable range restrictions on the results
1162 (using the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families of primops.
1163 The 32-bit sizes are represented using {\tt Int\#} and {\tt Word\#} when
1164 {\tt WORD\_SIZE\_IN\_BITS} $\geq$ 32;
1165 otherwise, these are represented using distinct primitive types {\tt Int32\#}
1166 and {\tt Word32\#}. These (when needed) have a complete set of corresponding
1167 operations; however, nearly all of these are implemented as external C functions
1168 rather than as primops. Exactly the same story applies to the 64-bit sizes.
1169 All of these details are hidden under the {\tt PrelInt} and {\tt PrelWord} modules,
1170 which use {\tt \#if}-defs to invoke the appropriate types and operators.
1172 Word size also matters for the families of primops
1173 for indexing/reading/writing fixed-size quantities at offsets from
1174 an array base, address, or foreign pointer. Here, a slightly different approach is taken.
1175 The names of these primops are fixed, but their
1176 {\it types} vary according to the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if
1177 word size is at least 32 bits then an operator like \texttt{indexInt32Array\#}
1178 has type {\tt ByteArr\# -> Int\# -> Int\#}; otherwise it has type
1179 {\tt ByteArr\# -> Int\# -> Int32\#}. This approach confines the necessary {\tt \#if}-defs to this file;
1180 no conditional compilation is needed in the files that expose these primops, namely \texttt{lib/std/PrelStorable.lhs},
1181 \texttt{hslibs/lang/ArrayBase.hs}, and (in deprecated fashion) in \texttt{hslibs/lang/ForeignObj.lhs}
1182 and \texttt{hslibs/lang/Addr.lhs}.
1184 Finally, there are strongly deprecated primops for coercing between {\tt Addr\#}, the primitive
1185 type of machine addresses, and {\tt Int\#}. These are pretty bogus anyway, but will work on
1186 existing 32-bit and 64-bit GHC targets; they are completely bogus when tag bits are used in
1187 {\tt Int\#}, so are not available in this case.
1190 -- Define synonyms for indexing ops.
1208 ------------------------------------------------------------------------
1210 {Operations on 31-bit characters.}
1211 ------------------------------------------------------------------------
1214 primop CharGtOp "gtChar#" Compare Char# -> Char# -> Bool
1215 primop CharGeOp "geChar#" Compare Char# -> Char# -> Bool
1217 primop CharEqOp "eqChar#" Compare
1218 Char# -> Char# -> Bool
1219 with commutable = True
1221 primop CharNeOp "neChar#" Compare
1222 Char# -> Char# -> Bool
1223 with commutable = True
1225 primop CharLtOp "ltChar#" Compare Char# -> Char# -> Bool
1226 primop CharLeOp "leChar#" Compare Char# -> Char# -> Bool
1228 primop OrdOp "ord#" GenPrimOp Char# -> Int#
1230 ------------------------------------------------------------------------
1232 {Operations on native-size integers (30+ bits).}
1233 ------------------------------------------------------------------------
1235 primop IntAddOp "+#" Dyadic
1236 Int# -> Int# -> Int#
1237 with commutable = True
1239 primop IntSubOp "-#" Dyadic Int# -> Int# -> Int#
1241 primop IntMulOp "*#"
1242 Dyadic Int# -> Int# -> Int#
1243 with commutable = True
1245 primop IntQuotOp "quotInt#" Dyadic
1246 Int# -> Int# -> Int#
1247 {Rounds towards zero.}
1248 with can_fail = True
1250 primop IntRemOp "remInt#" Dyadic
1251 Int# -> Int# -> Int#
1252 {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
1253 with can_fail = True
1255 primop IntGcdOp "gcdInt#" Dyadic Int# -> Int# -> Int#
1256 primop IntNegOp "negateInt#" Monadic Int# -> Int#
1257 primop IntAddCOp "addIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1258 {Add with carry. First member of result is (wrapped) sum; second member is 0 iff no overflow occured.}
1259 primop IntSubCOp "subIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1260 {Subtract with carry. First member of result is (wrapped) difference; second member is 0 iff no overflow occured.}
1261 primop IntMulCOp "mulIntC#" GenPrimOp Int# -> Int# -> (# Int#, Int# #)
1262 {Multiply with carry. First member of result is (wrapped) product; second member is 0 iff no overflow occured.}
1263 primop IntGtOp ">#" Compare Int# -> Int# -> Bool
1264 primop IntGeOp ">=#" Compare Int# -> Int# -> Bool
1266 primop IntEqOp "==#" Compare
1267 Int# -> Int# -> Bool
1268 with commutable = True
1270 primop IntNeOp "/=#" Compare
1271 Int# -> Int# -> Bool
1272 with commutable = True
1274 primop IntLtOp "<#" Compare Int# -> Int# -> Bool
1275 primop IntLeOp "<=#" Compare Int# -> Int# -> Bool
1277 primop ChrOp "chr#" GenPrimOp Int# -> Char#
1279 primop Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
1280 primop Int2FloatOp "int2Float#" GenPrimOp Int# -> Float#
1281 primop Int2DoubleOp "int2Double#" GenPrimOp Int# -> Double#
1283 primop Int2IntegerOp "int2Integer#"
1284 GenPrimOp Int# -> (# Int#, ByteArr# #)
1285 with out_of_line = True
1287 primop ISllOp "iShiftL#" GenPrimOp Int# -> Int# -> Int#
1288 {Shift left. Return 0 if shifted by more than size of an Int\#.}
1289 primop ISraOp "iShiftRA#" GenPrimOp Int# -> Int# -> Int#
1290 {Shift right arithemetic. Return 0 if shifted by more than size of an Int\#.}
1291 primop ISrlOp "iShiftRL#" GenPrimOp Int# -> Int# -> Int#
1292 {Shift right logical. Return 0 if shifted by more than size of an Int\#.}
1294 ------------------------------------------------------------------------
1296 {Operations on native-sized unsigned words (30+ bits).}
1297 ------------------------------------------------------------------------
1299 primop WordAddOp "plusWord#" Dyadic Word# -> Word# -> Word#
1300 with commutable = True
1302 primop WordSubOp "minusWord#" Dyadic Word# -> Word# -> Word#
1304 primop WordMulOp "timesWord#" Dyadic Word# -> Word# -> Word#
1305 with commutable = True
1307 primop WordQuotOp "quotWord#" Dyadic Word# -> Word# -> Word#
1308 with can_fail = True
1310 primop WordRemOp "remWord#" Dyadic Word# -> Word# -> Word#
1311 with can_fail = True
1313 primop AndOp "and#" Dyadic Word# -> Word# -> Word#
1314 with commutable = True
1316 primop OrOp "or#" Dyadic Word# -> Word# -> Word#
1317 with commutable = True
1319 primop XorOp "xor#" Dyadic Word# -> Word# -> Word#
1320 with commutable = True
1322 primop NotOp "not#" Monadic Word# -> Word#
1324 primop SllOp "shiftL#" GenPrimOp Word# -> Int# -> Word#
1325 {Shift left logical. Return 0 if shifted by more than number of bits in a Word\#.}
1326 primop SrlOp "shiftRL#" GenPrimOp Word# -> Int# -> Word#
1327 {Shift right logical. Return 0 if shifted by more than number of bits in a Word\#.}
1329 primop Word2IntOp "word2Int#" GenPrimOp Word# -> Int#
1331 primop Word2IntegerOp "word2Integer#" GenPrimOp
1332 Word# -> (# Int#, ByteArr# #)
1333 with out_of_line = True
1335 primop WordGtOp "gtWord#" Compare Word# -> Word# -> Bool
1336 primop WordGeOp "geWord#" Compare Word# -> Word# -> Bool
1337 primop WordEqOp "eqWord#" Compare Word# -> Word# -> Bool
1338 primop WordNeOp "neWord#" Compare Word# -> Word# -> Bool
1339 primop WordLtOp "ltWord#" Compare Word# -> Word# -> Bool
1340 primop WordLeOp "leWord#" Compare Word# -> Word# -> Bool
1342 ------------------------------------------------------------------------
1343 section "Narrowings"
1344 {Explicit narrowing of native-sized ints or words.}
1345 ------------------------------------------------------------------------
1347 primop Narrow8IntOp "narrow8Int#" Monadic Int# -> Int#
1348 primop Narrow16IntOp "narrow16Int#" Monadic Int# -> Int#
1349 primop Narrow32IntOp "narrow32Int#" Monadic Int# -> Int#
1350 primop Narrow8WordOp "narrow8Word#" Monadic Word# -> Word#
1351 primop Narrow16WordOp "narrow16Word#" Monadic Word# -> Word#
1352 primop Narrow32WordOp "narrow32Word#" Monadic Word# -> Word#
1359 ------------------------------------------------------------------------
1361 {Operations on 64-bit unsigned words. This type is only used
1362 if plain Int\# has less than 64 bits. In any case, the operations
1363 are not primops; they are implemented (if needed) as ccalls instead.}
1364 ------------------------------------------------------------------------
1366 primop Int64ToIntegerOp "int64ToInteger#" GenPrimOp
1367 Int64# -> (# Int#, ByteArr# #)
1368 with out_of_line = True
1370 ------------------------------------------------------------------------
1372 {Operations on 64-bit unsigned words. This type is only used
1373 if plain Word\# has less than 64 bits. In any case, the operations
1374 are not primops; they are implemented (if needed) as ccalls instead.}
1375 ------------------------------------------------------------------------
1377 primop Word64ToIntegerOp "word64ToInteger#" GenPrimOp
1378 Word64# -> (# Int#, ByteArr# #)
1379 with out_of_line = True
1383 ------------------------------------------------------------------------
1385 {Operations on arbitrary-precision integers. These operations are
1386 implemented via the GMP package. An integer is represented as a pair
1387 consisting of an Int\# representing the number of 'limbs' in use and
1388 the sign, and a ByteArr\# containing the 'limbs' themselves. Such pairs
1389 are returned as unboxed pairs, but must be passed as separate components.}
1390 ------------------------------------------------------------------------
1392 primop IntegerAddOp "plusInteger#" GenPrimOp
1393 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1394 with commutable = True
1397 primop IntegerSubOp "minusInteger#" GenPrimOp
1398 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1399 with out_of_line = True
1401 primop IntegerMulOp "timesInteger#" GenPrimOp
1402 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1403 with commutable = True
1406 primop IntegerGcdOp "gcdInteger#" GenPrimOp
1407 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1408 {Greatest common divisor.}
1409 with commutable = True
1412 primop IntegerIntGcdOp "gcdIntegerInt#" GenPrimOp
1413 Int# -> ByteArr# -> Int# -> Int#
1414 {Greatest common divisor, where second argument is an ordinary Int\#.}
1415 -- with commutable = True (surely not? APT 8/01)
1417 primop IntegerDivExactOp "divExactInteger#" GenPrimOp
1418 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1419 {Divisor is guaranteed to be a factor of dividend.}
1420 with out_of_line = True
1422 primop IntegerQuotOp "quotInteger#" GenPrimOp
1423 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1424 {Rounds towards zero.}
1425 with out_of_line = True
1427 primop IntegerRemOp "remInteger#" GenPrimOp
1428 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1429 {Satisfies \texttt{plusInteger\# (timesInteger\# (quotInteger\# x y) y) (remInteger\# x y) == x}.}
1430 with out_of_line = True
1432 primop IntegerCmpOp "cmpInteger#" GenPrimOp
1433 Int# -> ByteArr# -> Int# -> ByteArr# -> Int#
1434 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument.}
1435 with needs_wrapper = True
1437 primop IntegerCmpIntOp "cmpIntegerInt#" GenPrimOp
1438 Int# -> ByteArr# -> Int# -> Int#
1439 {Returns -1,0,1 according as first argument is less than, equal to, or greater than second argument, which
1440 is an ordinary Int\#.}
1441 with needs_wrapper = True
1443 primop IntegerQuotRemOp "quotRemInteger#" GenPrimOp
1444 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
1445 {Compute quot and rem simulaneously.}
1446 with can_fail = True
1449 primop IntegerDivModOp "divModInteger#" GenPrimOp
1450 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr#, Int#, ByteArr# #)
1451 {Compute div and mod simultaneously, where div rounds towards negative infinity
1452 and\texttt{(q,r) = divModInteger\#(x,y)} implies \texttt{plusInteger\# (timesInteger\# q y) r = x}.}
1453 with can_fail = True
1456 primop Integer2IntOp "integer2Int#" GenPrimOp
1457 Int# -> ByteArr# -> Int#
1458 with needs_wrapper = True
1460 primop Integer2WordOp "integer2Word#" GenPrimOp
1461 Int# -> ByteArr# -> Word#
1462 with needs_wrapper = True
1473 primop IntegerToInt64Op "integerToInt64#" GenPrimOp
1474 Int# -> ByteArr# -> Int64#
1476 primop IntegerToWord64Op "integerToWord64#" GenPrimOp
1477 Int# -> ByteArr# -> Word64#
1480 primop IntegerAndOp "andInteger#" GenPrimOp
1481 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1482 with out_of_line = True
1484 primop IntegerOrOp "orInteger#" GenPrimOp
1485 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1486 with out_of_line = True
1488 primop IntegerXorOp "xorInteger#" GenPrimOp
1489 Int# -> ByteArr# -> Int# -> ByteArr# -> (# Int#, ByteArr# #)
1490 with out_of_line = True
1492 primop IntegerComplementOp "complementInteger#" GenPrimOp
1493 Int# -> ByteArr# -> (# Int#, ByteArr# #)
1494 with out_of_line = True
1497 ------------------------------------------------------------------------
1499 {Operations on double-precision (64 bit) floating-point numbers.}
1500 ------------------------------------------------------------------------
1502 primop DoubleGtOp ">##" Compare Double# -> Double# -> Bool
1503 primop DoubleGeOp ">=##" Compare Double# -> Double# -> Bool
1505 primop DoubleEqOp "==##" Compare
1506 Double# -> Double# -> Bool
1507 with commutable = True
1509 primop DoubleNeOp "/=##" Compare
1510 Double# -> Double# -> Bool
1511 with commutable = True
1513 primop DoubleLtOp "<##" Compare Double# -> Double# -> Bool
1514 primop DoubleLeOp "<=##" Compare Double# -> Double# -> Bool
1516 primop DoubleAddOp "+##" Dyadic
1517 Double# -> Double# -> Double#
1518 with commutable = True
1520 primop DoubleSubOp "-##" Dyadic Double# -> Double# -> Double#
1522 primop DoubleMulOp "*##" Dyadic
1523 Double# -> Double# -> Double#
1524 with commutable = True
1526 primop DoubleDivOp "/##" Dyadic
1527 Double# -> Double# -> Double#
1528 with can_fail = True
1530 primop DoubleNegOp "negateDouble#" Monadic Double# -> Double#
1532 primop Double2IntOp "double2Int#" GenPrimOp Double# -> Int#
1533 primop Double2FloatOp "double2Float#" GenPrimOp Double# -> Float#
1535 primop DoubleExpOp "expDouble#" Monadic
1537 with needs_wrapper = True
1539 primop DoubleLogOp "logDouble#" Monadic
1542 needs_wrapper = True
1545 primop DoubleSqrtOp "sqrtDouble#" Monadic
1547 with needs_wrapper = True
1549 primop DoubleSinOp "sinDouble#" Monadic
1551 with needs_wrapper = True
1553 primop DoubleCosOp "cosDouble#" Monadic
1555 with needs_wrapper = True
1557 primop DoubleTanOp "tanDouble#" Monadic
1559 with needs_wrapper = True
1561 primop DoubleAsinOp "asinDouble#" Monadic
1564 needs_wrapper = True
1567 primop DoubleAcosOp "acosDouble#" Monadic
1570 needs_wrapper = True
1573 primop DoubleAtanOp "atanDouble#" Monadic
1576 needs_wrapper = True
1578 primop DoubleSinhOp "sinhDouble#" Monadic
1580 with needs_wrapper = True
1582 primop DoubleCoshOp "coshDouble#" Monadic
1584 with needs_wrapper = True
1586 primop DoubleTanhOp "tanhDouble#" Monadic
1588 with needs_wrapper = True
1590 primop DoublePowerOp "**##" Dyadic
1591 Double# -> Double# -> Double#
1593 with needs_wrapper = True
1595 primop DoubleDecodeOp "decodeDouble#" GenPrimOp
1596 Double# -> (# Int#, Int#, ByteArr# #)
1597 {Convert to arbitrary-precision integer.
1598 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
1599 holding the mantissa.}
1600 with out_of_line = True
1602 ------------------------------------------------------------------------
1604 {Operations on single-precision (32-bit) floating-point numbers.}
1605 ------------------------------------------------------------------------
1607 primop FloatGtOp "gtFloat#" Compare Float# -> Float# -> Bool
1608 primop FloatGeOp "geFloat#" Compare Float# -> Float# -> Bool
1610 primop FloatEqOp "eqFloat#" Compare
1611 Float# -> Float# -> Bool
1612 with commutable = True
1614 primop FloatNeOp "neFloat#" Compare
1615 Float# -> Float# -> Bool
1616 with commutable = True
1618 primop FloatLtOp "ltFloat#" Compare Float# -> Float# -> Bool
1619 primop FloatLeOp "leFloat#" Compare Float# -> Float# -> Bool
1621 primop FloatAddOp "plusFloat#" Dyadic
1622 Float# -> Float# -> Float#
1623 with commutable = True
1625 primop FloatSubOp "minusFloat#" Dyadic Float# -> Float# -> Float#
1627 primop FloatMulOp "timesFloat#" Dyadic
1628 Float# -> Float# -> Float#
1629 with commutable = True
1631 primop FloatDivOp "divideFloat#" Dyadic
1632 Float# -> Float# -> Float#
1633 with can_fail = True
1635 primop FloatNegOp "negateFloat#" Monadic Float# -> Float#
1637 primop Float2IntOp "float2Int#" GenPrimOp Float# -> Int#
1639 primop FloatExpOp "expFloat#" Monadic
1641 with needs_wrapper = True
1643 primop FloatLogOp "logFloat#" Monadic
1645 with needs_wrapper = True
1648 primop FloatSqrtOp "sqrtFloat#" Monadic
1650 with needs_wrapper = True
1652 primop FloatSinOp "sinFloat#" Monadic
1654 with needs_wrapper = True
1656 primop FloatCosOp "cosFloat#" Monadic
1658 with needs_wrapper = True
1660 primop FloatTanOp "tanFloat#" Monadic
1662 with needs_wrapper = True
1664 primop FloatAsinOp "asinFloat#" Monadic
1666 with needs_wrapper = True
1669 primop FloatAcosOp "acosFloat#" Monadic
1671 with needs_wrapper = True
1674 primop FloatAtanOp "atanFloat#" Monadic
1676 with needs_wrapper = True
1678 primop FloatSinhOp "sinhFloat#" Monadic
1680 with needs_wrapper = True
1682 primop FloatCoshOp "coshFloat#" Monadic
1684 with needs_wrapper = True
1686 primop FloatTanhOp "tanhFloat#" Monadic
1688 with needs_wrapper = True
1690 primop FloatPowerOp "powerFloat#" Dyadic
1691 Float# -> Float# -> Float#
1692 with needs_wrapper = True
1694 primop Float2DoubleOp "float2Double#" GenPrimOp Float# -> Double#
1696 primop FloatDecodeOp "decodeFloat#" GenPrimOp
1697 Float# -> (# Int#, Int#, ByteArr# #)
1698 {Convert to arbitrary-precision integer.
1699 First Int\# in result is the exponent; second Int\# and ByteArr\# represent an Integer\#
1700 holding the mantissa.}
1701 with out_of_line = True
1703 ------------------------------------------------------------------------
1705 {Operations on Array\#.}
1706 ------------------------------------------------------------------------
1708 primop NewArrayOp "newArray#" GenPrimOp
1709 Int# -> a -> State# s -> (# State# s, MutArr# s a #)
1710 {Create a new mutable array of specified size (in bytes),
1711 in the specified state thread,
1712 with each element containing the specified initial value.}
1714 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
1715 usage = { mangle NewArrayOp [mkP, mkM, mkP] mkM }
1718 primop SameMutableArrayOp "sameMutableArray#" GenPrimOp
1719 MutArr# s a -> MutArr# s a -> Bool
1721 usage = { mangle SameMutableArrayOp [mkP, mkP] mkM }
1723 primop ReadArrayOp "readArray#" GenPrimOp
1724 MutArr# s a -> Int# -> State# s -> (# State# s, a #)
1725 {Read from specified index of mutable array. Result is not yet evaluated.}
1727 usage = { mangle ReadArrayOp [mkM, mkP, mkP] mkM }
1729 primop WriteArrayOp "writeArray#" GenPrimOp
1730 MutArr# s a -> Int# -> a -> State# s -> State# s
1731 {Write to specified index of mutable array.}
1733 usage = { mangle WriteArrayOp [mkM, mkP, mkM, mkP] mkR }
1734 strictness = { \ arity -> StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False }
1735 has_side_effects = True
1737 primop IndexArrayOp "indexArray#" GenPrimOp
1738 Array# a -> Int# -> (# a #)
1739 {Read from specified index of immutable array. Result is packaged into
1740 an unboxed singleton; the result itself is not yet evaluated.}
1742 usage = { mangle IndexArrayOp [mkM, mkP] mkM }
1744 primop UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
1745 MutArr# s a -> State# s -> (# State# s, Array# a #)
1746 {Make a mutable array immutable, without copying.}
1748 usage = { mangle UnsafeFreezeArrayOp [mkM, mkP] mkM }
1749 has_side_effects = True
1751 primop UnsafeThawArrayOp "unsafeThawArray#" GenPrimOp
1752 Array# a -> State# s -> (# State# s, MutArr# s a #)
1753 {Make an immutable array mutable, without copying.}
1755 usage = { mangle UnsafeThawArrayOp [mkM, mkP] mkM }
1758 ------------------------------------------------------------------------
1759 section "Byte Arrays"
1760 {Operations on ByteArray\#. A ByteArray\# is a just a region of
1761 raw memory in the garbage-collected heap, which is not scanned
1762 for pointers. It carries its own size (in bytes). There are
1763 three sets of operations for accessing byte array contents:
1764 index for reading from immutable byte arrays, and read/write
1765 for mutable byte arrays. Each set contains operations for
1766 a range of useful primitive data types. Each operation takes
1767 an offset measured in terms of the size fo the primitive type
1768 being read or written.}
1770 ------------------------------------------------------------------------
1772 primop NewByteArrayOp_Char "newByteArray#" GenPrimOp
1773 Int# -> State# s -> (# State# s, MutByteArr# s #)
1774 {Create a new mutable byte array of specified size (in bytes), in
1775 the specified state thread.}
1776 with out_of_line = True
1778 primop NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
1779 Int# -> State# s -> (# State# s, MutByteArr# s #)
1780 {Create a mutable byte array that the GC guarantees not to move.}
1781 with out_of_line = True
1783 primop ByteArrayContents_Char "byteArrayContents#" GenPrimOp
1785 {Intended for use with pinned arrays; otherwise very unsafe!}
1787 primop SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
1788 MutByteArr# s -> MutByteArr# s -> Bool
1790 primop UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
1791 MutByteArr# s -> State# s -> (# State# s, ByteArr# #)
1792 {Make a mutable byte array immutable, without copying.}
1794 has_side_effects = True
1796 primop SizeofByteArrayOp "sizeofByteArray#" GenPrimOp
1799 primop SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
1800 MutByteArr# s -> Int#
1803 primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
1804 ByteArr# -> Int# -> Char#
1805 {Read 8-bit character; offset in bytes.}
1807 primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
1808 ByteArr# -> Int# -> Char#
1809 {Read 31-bit character; offset in 4-byte words.}
1811 primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
1812 ByteArr# -> Int# -> Int#
1814 primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
1815 ByteArr# -> Int# -> Word#
1817 primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
1818 ByteArr# -> Int# -> Addr#
1820 primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
1821 ByteArr# -> Int# -> Float#
1823 primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
1824 ByteArr# -> Int# -> Double#
1826 primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
1827 ByteArr# -> Int# -> StablePtr# a
1829 primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
1830 ByteArr# -> Int# -> Int#
1832 primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
1833 ByteArr# -> Int# -> Int#
1835 primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
1836 ByteArr# -> Int# -> Int#
1838 primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
1839 ByteArr# -> Int# -> Int64#
1841 primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
1842 ByteArr# -> Int# -> Word#
1844 primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
1845 ByteArr# -> Int# -> Word#
1847 primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
1848 ByteArr# -> Int# -> Word#
1850 primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
1851 ByteArr# -> Int# -> Word64#
1853 primop ReadByteArrayOp_Char "readCharArray#" GenPrimOp
1854 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
1855 {Read 8-bit character; offset in bytes.}
1857 primop ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
1858 MutByteArr# s -> Int# -> State# s -> (# State# s, Char# #)
1859 {Read 31-bit character; offset in 4-byte words.}
1861 primop ReadByteArrayOp_Int "readIntArray#" GenPrimOp
1862 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1864 primop ReadByteArrayOp_Word "readWordArray#" GenPrimOp
1865 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1867 primop ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
1868 MutByteArr# s -> Int# -> State# s -> (# State# s, Addr# #)
1870 primop ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
1871 MutByteArr# s -> Int# -> State# s -> (# State# s, Float# #)
1873 primop ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
1874 MutByteArr# s -> Int# -> State# s -> (# State# s, Double# #)
1876 primop ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
1877 MutByteArr# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
1879 primop ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
1880 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1882 primop ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
1883 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1885 primop ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
1886 MutByteArr# s -> Int# -> State# s -> (# State# s, Int# #)
1888 primop ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
1889 MutByteArr# s -> Int# -> State# s -> (# State# s, Int64# #)
1891 primop ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
1892 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1894 primop ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
1895 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1897 primop ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
1898 MutByteArr# s -> Int# -> State# s -> (# State# s, Word# #)
1900 primop ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
1901 MutByteArr# s -> Int# -> State# s -> (# State# s, Word64# #)
1903 primop WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
1904 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
1905 {Write 8-bit character; offset in bytes.}
1906 with has_side_effects = True
1908 primop WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
1909 MutByteArr# s -> Int# -> Char# -> State# s -> State# s
1910 {Write 31-bit character; offset in 4-byte words.}
1911 with has_side_effects = True
1913 primop WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
1914 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1915 with has_side_effects = True
1917 primop WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
1918 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1919 with has_side_effects = True
1921 primop WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
1922 MutByteArr# s -> Int# -> Addr# -> State# s -> State# s
1923 with has_side_effects = True
1925 primop WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
1926 MutByteArr# s -> Int# -> Float# -> State# s -> State# s
1927 with has_side_effects = True
1929 primop WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
1930 MutByteArr# s -> Int# -> Double# -> State# s -> State# s
1931 with has_side_effects = True
1933 primop WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
1934 MutByteArr# s -> Int# -> StablePtr# a -> State# s -> State# s
1935 with has_side_effects = True
1937 primop WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
1938 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1939 with has_side_effects = True
1941 primop WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
1942 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1943 with has_side_effects = True
1945 primop WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
1946 MutByteArr# s -> Int# -> Int# -> State# s -> State# s
1947 with has_side_effects = True
1949 primop WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
1950 MutByteArr# s -> Int# -> Int64# -> State# s -> State# s
1951 with has_side_effects = True
1953 primop WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
1954 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1955 with has_side_effects = True
1957 primop WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
1958 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1959 with has_side_effects = True
1961 primop WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
1962 MutByteArr# s -> Int# -> Word# -> State# s -> State# s
1963 with has_side_effects = True
1965 primop WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
1966 MutByteArr# s -> Int# -> Word64# -> State# s -> State# s
1967 with has_side_effects = True
1969 ------------------------------------------------------------------------
1971 {Addr\# is an arbitrary machine address assumed to point outside
1972 the garbage-collected heap.}
1973 ------------------------------------------------------------------------
1975 primop AddrNullOp "nullAddr#" GenPrimOp Int# -> Addr#
1976 {Returns null address. Argument is ignored (nullary primops
1978 primop AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
1979 primop AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
1980 {Result is meaningless if two Addr\#s are so far apart that their
1981 difference doesn't fit in an Int\#.}
1982 primop AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
1983 {Return the remainder when the Addr\# arg, treated like an Int\#,
1984 is divided by the Int\# arg.}
1986 primop Addr2IntOp "addr2Int#" GenPrimOp Addr# -> Int#
1987 {Coerce directly from address to int. Strongly deprecated.}
1988 primop Int2AddrOp "int2Addr#" GenPrimOp Int# -> Addr#
1989 {Coerce directly from int to address. Strongly deprecated.}
1992 primop AddrGtOp "gtAddr#" Compare Addr# -> Addr# -> Bool
1993 primop AddrGeOp "geAddr#" Compare Addr# -> Addr# -> Bool
1994 primop AddrEqOp "eqAddr#" Compare Addr# -> Addr# -> Bool
1995 primop AddrNeOp "neAddr#" Compare Addr# -> Addr# -> Bool
1996 primop AddrLtOp "ltAddr#" Compare Addr# -> Addr# -> Bool
1997 primop AddrLeOp "leAddr#" Compare Addr# -> Addr# -> Bool
1999 primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
2000 Addr# -> Int# -> Char#
2001 {Reads 8-bit character; offset in bytes.}
2003 primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
2004 Addr# -> Int# -> Char#
2005 {Reads 31-bit character; offset in 4-byte words.}
2007 primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
2008 Addr# -> Int# -> Int#
2010 primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
2011 Addr# -> Int# -> Word#
2013 primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
2014 Addr# -> Int# -> Addr#
2016 primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
2017 Addr# -> Int# -> Float#
2019 primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
2020 Addr# -> Int# -> Double#
2022 primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
2023 Addr# -> Int# -> StablePtr# a
2025 primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
2026 Addr# -> Int# -> Int#
2028 primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
2029 Addr# -> Int# -> Int#
2031 primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
2032 Addr# -> Int# -> Int#
2034 primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
2035 Addr# -> Int# -> Int64#
2037 primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
2038 Addr# -> Int# -> Word#
2040 primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
2041 Addr# -> Int# -> Word#
2043 primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
2044 Addr# -> Int# -> Word#
2046 primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
2047 Addr# -> Int# -> Word64#
2049 primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
2050 Addr# -> Int# -> State# s -> (# State# s, Char# #)
2051 {Reads 8-bit character; offset in bytes.}
2053 primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
2054 Addr# -> Int# -> State# s -> (# State# s, Char# #)
2055 {Reads 31-bit character; offset in 4-byte words.}
2057 primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
2058 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2060 primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
2061 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2063 primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
2064 Addr# -> Int# -> State# s -> (# State# s, Addr# #)
2066 primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
2067 Addr# -> Int# -> State# s -> (# State# s, Float# #)
2069 primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
2070 Addr# -> Int# -> State# s -> (# State# s, Double# #)
2072 primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
2073 Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
2075 primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
2076 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2078 primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
2079 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2081 primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
2082 Addr# -> Int# -> State# s -> (# State# s, Int# #)
2084 primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
2085 Addr# -> Int# -> State# s -> (# State# s, Int64# #)
2087 primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
2088 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2090 primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
2091 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2093 primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
2094 Addr# -> Int# -> State# s -> (# State# s, Word# #)
2096 primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
2097 Addr# -> Int# -> State# s -> (# State# s, Word64# #)
2100 primop WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
2101 Addr# -> Int# -> Char# -> State# s -> State# s
2102 with has_side_effects = True
2104 primop WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
2105 Addr# -> Int# -> Char# -> State# s -> State# s
2106 with has_side_effects = True
2108 primop WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
2109 Addr# -> Int# -> Int# -> State# s -> State# s
2110 with has_side_effects = True
2112 primop WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
2113 Addr# -> Int# -> Word# -> State# s -> State# s
2114 with has_side_effects = True
2116 primop WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
2117 Addr# -> Int# -> Addr# -> State# s -> State# s
2118 with has_side_effects = True
2120 primop WriteOffAddrOp_ForeignObj "writeForeignObjOffAddr#" GenPrimOp
2121 Addr# -> Int# -> ForeignObj# -> State# s -> State# s
2122 with has_side_effects = True
2124 primop WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
2125 Addr# -> Int# -> Float# -> State# s -> State# s
2126 with has_side_effects = True
2128 primop WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
2129 Addr# -> Int# -> Double# -> State# s -> State# s
2130 with has_side_effects = True
2132 primop WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
2133 Addr# -> Int# -> StablePtr# a -> State# s -> State# s
2134 with has_side_effects = True
2136 primop WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
2137 Addr# -> Int# -> Int# -> State# s -> State# s
2138 with has_side_effects = True
2140 primop WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
2141 Addr# -> Int# -> Int# -> State# s -> State# s
2142 with has_side_effects = True
2144 primop WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
2145 Addr# -> Int# -> Int# -> State# s -> State# s
2146 with has_side_effects = True
2148 primop WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
2149 Addr# -> Int# -> Int64# -> State# s -> State# s
2150 with has_side_effects = True
2152 primop WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
2153 Addr# -> Int# -> Word# -> State# s -> State# s
2154 with has_side_effects = True
2156 primop WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
2157 Addr# -> Int# -> Word# -> State# s -> State# s
2158 with has_side_effects = True
2160 primop WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
2161 Addr# -> Int# -> Word# -> State# s -> State# s
2162 with has_side_effects = True
2164 primop WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
2165 Addr# -> Int# -> Word64# -> State# s -> State# s
2166 with has_side_effects = True
2168 ------------------------------------------------------------------------
2169 section "ForeignObj#"
2170 {Operations on ForeignObj\#. The indexing operations are
2172 ------------------------------------------------------------------------
2174 primop MkForeignObjOp "mkForeignObj#" GenPrimOp
2175 Addr# -> State# RealWorld -> (# State# RealWorld, ForeignObj# #)
2177 has_side_effects = True
2180 primop WriteForeignObjOp "writeForeignObj#" GenPrimOp
2181 ForeignObj# -> Addr# -> State# s -> State# s
2183 has_side_effects = True
2185 primop ForeignObjToAddrOp "foreignObjToAddr#" GenPrimOp
2186 ForeignObj# -> Addr#
2188 primop TouchOp "touch#" GenPrimOp
2189 o -> State# RealWorld -> State# RealWorld
2191 has_side_effects = True
2192 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2194 primop EqForeignObj "eqForeignObj#" GenPrimOp
2195 ForeignObj# -> ForeignObj# -> Bool
2196 with commutable = True
2198 primop IndexOffForeignObjOp_Char "indexCharOffForeignObj#" GenPrimOp
2199 ForeignObj# -> Int# -> Char#
2200 {Read 8-bit character; offset in bytes.}
2202 primop IndexOffForeignObjOp_WideChar "indexWideCharOffForeignObj#" GenPrimOp
2203 ForeignObj# -> Int# -> Char#
2204 {Read 31-bit character; offset in 4-byte words.}
2206 primop IndexOffForeignObjOp_Int "indexIntOffForeignObj#" GenPrimOp
2207 ForeignObj# -> Int# -> Int#
2209 primop IndexOffForeignObjOp_Word "indexWordOffForeignObj#" GenPrimOp
2210 ForeignObj# -> Int# -> Word#
2212 primop IndexOffForeignObjOp_Addr "indexAddrOffForeignObj#" GenPrimOp
2213 ForeignObj# -> Int# -> Addr#
2215 primop IndexOffForeignObjOp_Float "indexFloatOffForeignObj#" GenPrimOp
2216 ForeignObj# -> Int# -> Float#
2218 primop IndexOffForeignObjOp_Double "indexDoubleOffForeignObj#" GenPrimOp
2219 ForeignObj# -> Int# -> Double#
2221 primop IndexOffForeignObjOp_StablePtr "indexStablePtrOffForeignObj#" GenPrimOp
2222 ForeignObj# -> Int# -> StablePtr# a
2224 primop IndexOffForeignObjOp_Int8 "indexInt8OffForeignObj#" GenPrimOp
2225 ForeignObj# -> Int# -> Int#
2227 primop IndexOffForeignObjOp_Int16 "indexInt16OffForeignObj#" GenPrimOp
2228 ForeignObj# -> Int# -> Int#
2230 primop IndexOffForeignObjOp_Int32 "indexInt32OffForeignObj#" GenPrimOp
2231 ForeignObj# -> Int# -> Int#
2233 primop IndexOffForeignObjOp_Int64 "indexInt64OffForeignObj#" GenPrimOp
2234 ForeignObj# -> Int# -> Int64#
2236 primop IndexOffForeignObjOp_Word8 "indexWord8OffForeignObj#" GenPrimOp
2237 ForeignObj# -> Int# -> Word#
2239 primop IndexOffForeignObjOp_Word16 "indexWord16OffForeignObj#" GenPrimOp
2240 ForeignObj# -> Int# -> Word#
2242 primop IndexOffForeignObjOp_Word32 "indexWord32OffForeignObj#" GenPrimOp
2243 ForeignObj# -> Int# -> Word#
2245 primop IndexOffForeignObjOp_Word64 "indexWord64OffForeignObj#" GenPrimOp
2246 ForeignObj# -> Int# -> Word64#
2250 ------------------------------------------------------------------------
2251 section "Mutable variables"
2252 {Operations on MutVar\#s, which behave like single-element mutable arrays.}
2253 ------------------------------------------------------------------------
2255 primop NewMutVarOp "newMutVar#" GenPrimOp
2256 a -> State# s -> (# State# s, MutVar# s a #)
2257 {Create MutVar\# with specified initial value in specified state thread.}
2259 usage = { mangle NewMutVarOp [mkM, mkP] mkM }
2260 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2263 primop ReadMutVarOp "readMutVar#" GenPrimOp
2264 MutVar# s a -> State# s -> (# State# s, a #)
2265 {Read contents of MutVar\#. Result is not yet evaluated.}
2267 usage = { mangle ReadMutVarOp [mkM, mkP] mkM }
2269 primop WriteMutVarOp "writeMutVar#" GenPrimOp
2270 MutVar# s a -> a -> State# s -> State# s
2271 {Write contents of MutVar\#.}
2273 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
2274 usage = { mangle WriteMutVarOp [mkM, mkM, mkP] mkR }
2275 has_side_effects = True
2277 primop SameMutVarOp "sameMutVar#" GenPrimOp
2278 MutVar# s a -> MutVar# s a -> Bool
2280 usage = { mangle SameMutVarOp [mkP, mkP] mkM }
2282 ------------------------------------------------------------------------
2283 section "Exceptions"
2284 ------------------------------------------------------------------------
2286 primop CatchOp "catch#" GenPrimOp
2287 (State# RealWorld -> (# State# RealWorld, a #) )
2288 -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
2290 -> (# State# RealWorld, a #)
2292 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwPrim] False }
2293 -- Catch is actually strict in its first argument
2294 -- but we don't want to tell the strictness
2295 -- analyser about that!
2296 usage = { mangle CatchOp [mkM, mkM . (inFun CatchOp mkM mkM), mkP] mkM }
2297 -- [mkO, mkO . (inFun mkM mkO)] mkO
2298 -- might use caught action multiply
2301 primop RaiseOp "raise#" GenPrimOp
2304 strictness = { \ arity -> StrictnessInfo [wwLazy] True }
2305 -- NB: True => result is bottom
2306 usage = { mangle RaiseOp [mkM] mkM }
2309 primop BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
2310 (State# RealWorld -> (# State# RealWorld, a #))
2311 -> (State# RealWorld -> (# State# RealWorld, a #))
2313 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2316 primop UnblockAsyncExceptionsOp "unblockAsyncExceptions#" GenPrimOp
2317 (State# RealWorld -> (# State# RealWorld, a #))
2318 -> (State# RealWorld -> (# State# RealWorld, a #))
2320 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2323 ------------------------------------------------------------------------
2324 section "Synchronized Mutable Variables"
2325 {Operations on MVar\#s, which are shared mutable variables
2326 ({\it not} the same as MutVar\#s!). (Note: in a non-concurrent implementation,
2327 (MVar\# a) can be represented by (MutVar\# (Maybe a)).)}
2328 ------------------------------------------------------------------------
2331 primop NewMVarOp "newMVar#" GenPrimOp
2332 State# s -> (# State# s, MVar# s a #)
2333 {Create new mvar; initially empty.}
2335 usage = { mangle NewMVarOp [mkP] mkR }
2338 primop TakeMVarOp "takeMVar#" GenPrimOp
2339 MVar# s a -> State# s -> (# State# s, a #)
2340 {If mvar is empty, block until it becomes full.
2341 Then remove and return its contents, and set it empty.}
2343 usage = { mangle TakeMVarOp [mkM, mkP] mkM }
2344 has_side_effects = True
2347 primop TryTakeMVarOp "tryTakeMVar#" GenPrimOp
2348 MVar# s a -> State# s -> (# State# s, Int#, a #)
2349 {If mvar is empty, immediately return with integer 0 and value undefined.
2350 Otherwise, return with integer 1 and contents of mvar, and set mvar empty.}
2352 usage = { mangle TryTakeMVarOp [mkM, mkP] mkM }
2353 has_side_effects = True
2356 primop PutMVarOp "putMVar#" GenPrimOp
2357 MVar# s a -> a -> State# s -> State# s
2358 {If mvar is full, block until it becomes empty.
2359 Then store value arg as its new contents.}
2361 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
2362 usage = { mangle PutMVarOp [mkM, mkM, mkP] mkR }
2363 has_side_effects = True
2366 primop TryPutMVarOp "tryPutMVar#" GenPrimOp
2367 MVar# s a -> a -> State# s -> (# State# s, Int# #)
2368 {If mvar is full, immediately return with integer 0.
2369 Otherwise, store value arg as mvar's new contents, and return with integer 1.}
2371 strictness = { \ arity -> StrictnessInfo [wwPrim, wwLazy, wwPrim] False }
2372 usage = { mangle TryPutMVarOp [mkM, mkM, mkP] mkR }
2373 has_side_effects = True
2376 primop SameMVarOp "sameMVar#" GenPrimOp
2377 MVar# s a -> MVar# s a -> Bool
2379 usage = { mangle SameMVarOp [mkP, mkP] mkM }
2381 primop IsEmptyMVarOp "isEmptyMVar#" GenPrimOp
2382 MVar# s a -> State# s -> (# State# s, Int# #)
2383 {Return 1 if mvar is empty; 0 otherwise.}
2385 usage = { mangle IsEmptyMVarOp [mkP, mkP] mkM }
2388 ------------------------------------------------------------------------
2389 section "Delay/wait operations"
2390 ------------------------------------------------------------------------
2392 primop DelayOp "delay#" GenPrimOp
2393 Int# -> State# s -> State# s
2394 {Sleep specified number of microseconds.}
2396 needs_wrapper = True
2397 has_side_effects = True
2400 primop WaitReadOp "waitRead#" GenPrimOp
2401 Int# -> State# s -> State# s
2402 {Block until input is available on specified file descriptor.}
2404 needs_wrapper = True
2405 has_side_effects = True
2408 primop WaitWriteOp "waitWrite#" GenPrimOp
2409 Int# -> State# s -> State# s
2410 {Block until output is possible on specified file descriptor.}
2412 needs_wrapper = True
2413 has_side_effects = True
2416 ------------------------------------------------------------------------
2417 section "Concurrency primitives"
2418 {(In a non-concurrent implementation, ThreadId\# can be as singleton
2419 type, whose (unique) value is returned by myThreadId\#. The
2420 other operations can be omitted.)}
2421 ------------------------------------------------------------------------
2423 primop ForkOp "fork#" GenPrimOp
2424 a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
2426 usage = { mangle ForkOp [mkO, mkP] mkR }
2427 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2428 has_side_effects = True
2431 primop KillThreadOp "killThread#" GenPrimOp
2432 ThreadId# -> a -> State# RealWorld -> State# RealWorld
2434 usage = { mangle KillThreadOp [mkP, mkM, mkP] mkR }
2435 has_side_effects = True
2438 primop YieldOp "yield#" GenPrimOp
2439 State# RealWorld -> State# RealWorld
2441 has_side_effects = True
2444 primop MyThreadIdOp "myThreadId#" GenPrimOp
2445 State# RealWorld -> (# State# RealWorld, ThreadId# #)
2447 ------------------------------------------------------------------------
2448 section "Weak pointers"
2449 ------------------------------------------------------------------------
2451 -- note that tyvar "o" denotes openAlphaTyVar
2453 primop MkWeakOp "mkWeak#" GenPrimOp
2454 o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #)
2456 strictness = { \ arity -> StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False }
2457 usage = { mangle MkWeakOp [mkZ, mkM, mkM, mkP] mkM }
2458 has_side_effects = True
2461 primop DeRefWeakOp "deRefWeak#" GenPrimOp
2462 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, a #)
2464 usage = { mangle DeRefWeakOp [mkM, mkP] mkM }
2465 has_side_effects = True
2467 primop FinalizeWeakOp "finalizeWeak#" GenPrimOp
2468 Weak# a -> State# RealWorld -> (# State# RealWorld, Int#,
2469 (State# RealWorld -> (# State# RealWorld, Unit #)) #)
2471 usage = { mangle FinalizeWeakOp [mkM, mkP]
2472 (mkR . (inUB FinalizeWeakOp
2473 [id,id,inFun FinalizeWeakOp mkR mkM])) }
2474 has_side_effects = True
2477 ------------------------------------------------------------------------
2478 section "Stable pointers and names"
2479 ------------------------------------------------------------------------
2481 primop MakeStablePtrOp "makeStablePtr#" GenPrimOp
2482 a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
2484 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2485 usage = { mangle MakeStablePtrOp [mkM, mkP] mkM }
2486 has_side_effects = True
2488 primop DeRefStablePtrOp "deRefStablePtr#" GenPrimOp
2489 StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
2491 usage = { mangle DeRefStablePtrOp [mkM, mkP] mkM }
2492 needs_wrapper = True
2493 has_side_effects = True
2495 primop EqStablePtrOp "eqStablePtr#" GenPrimOp
2496 StablePtr# a -> StablePtr# a -> Int#
2498 usage = { mangle EqStablePtrOp [mkP, mkP] mkR }
2499 has_side_effects = True
2501 primop MakeStableNameOp "makeStableName#" GenPrimOp
2502 a -> State# RealWorld -> (# State# RealWorld, StableName# a #)
2504 usage = { mangle MakeStableNameOp [mkZ, mkP] mkR }
2505 strictness = { \ arity -> StrictnessInfo [wwLazy, wwPrim] False }
2506 needs_wrapper = True
2507 has_side_effects = True
2510 primop EqStableNameOp "eqStableName#" GenPrimOp
2511 StableName# a -> StableName# a -> Int#
2513 usage = { mangle EqStableNameOp [mkP, mkP] mkR }
2515 primop StableNameToIntOp "stableNameToInt#" GenPrimOp
2516 StableName# a -> Int#
2518 usage = { mangle StableNameToIntOp [mkP] mkR }
2520 ------------------------------------------------------------------------
2521 section "Unsafe pointer equality"
2522 -- (#1 Bad Guy: Alistair Reid :)
2523 ------------------------------------------------------------------------
2525 primop ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
2528 usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
2530 ------------------------------------------------------------------------
2531 section "Parallelism"
2532 ------------------------------------------------------------------------
2534 primop SeqOp "seq#" GenPrimOp
2537 usage = { mangle SeqOp [mkO] mkR }
2538 strictness = { \ arity -> StrictnessInfo [wwStrict] False }
2539 -- Seq is strict in its argument; see notes in ConFold.lhs
2540 has_side_effects = True
2542 primop ParOp "par#" GenPrimOp
2545 usage = { mangle ParOp [mkO] mkR }
2546 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
2547 -- Note that Par is lazy to avoid that the sparked thing
2548 -- gets evaluted strictly, which it should *not* be
2549 has_side_effects = True
2551 -- HWL: The first 4 Int# in all par... annotations denote:
2552 -- name, granularity info, size of result, degree of parallelism
2553 -- Same structure as _seq_ i.e. returns Int#
2554 -- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
2555 -- `the processor containing the expression v'; it is not evaluated
2557 primop ParGlobalOp "parGlobal#" GenPrimOp
2558 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2560 usage = { mangle ParGlobalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2561 has_side_effects = True
2563 primop ParLocalOp "parLocal#" GenPrimOp
2564 a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2566 usage = { mangle ParLocalOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2567 has_side_effects = True
2569 primop ParAtOp "parAt#" GenPrimOp
2570 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
2572 usage = { mangle ParAtOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
2573 has_side_effects = True
2575 primop ParAtAbsOp "parAtAbs#" GenPrimOp
2576 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2578 usage = { mangle ParAtAbsOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2579 has_side_effects = True
2581 primop ParAtRelOp "parAtRel#" GenPrimOp
2582 a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
2584 usage = { mangle ParAtRelOp [mkO, mkP, mkP, mkP, mkP, mkM] mkM }
2585 has_side_effects = True
2587 primop ParAtForNowOp "parAtForNow#" GenPrimOp
2588 b -> a -> Int# -> Int# -> Int# -> Int# -> c -> Int#
2590 usage = { mangle ParAtForNowOp [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM }
2591 has_side_effects = True
2593 -- copyable# and noFollow# are yet to be implemented (for GpH)
2595 --primop CopyableOp "copyable#" GenPrimOp
2598 -- usage = { mangle CopyableOp [mkZ] mkR }
2599 -- has_side_effects = True
2601 --primop NoFollowOp "noFollow#" GenPrimOp
2604 -- usage = { mangle NoFollowOp [mkZ] mkR }
2605 -- has_side_effects = True
2608 ------------------------------------------------------------------------
2609 section "Tag to enum stuff"
2610 {Convert back and forth between values of enumerated types
2611 and small integers.}
2612 ------------------------------------------------------------------------
2614 primop DataToTagOp "dataToTag#" GenPrimOp
2617 strictness = { \ arity -> StrictnessInfo [wwLazy] False }
2619 primop TagToEnumOp "tagToEnum#" GenPrimOp
2622 ------------------------------------------------------------------------
2623 section "Bytecode operations"
2624 {Support for the bytecode interpreter and linker.}
2625 ------------------------------------------------------------------------
2628 primop AddrToHValueOp "addrToHValue#" GenPrimOp
2630 {Convert an Addr\# to a followable type.}
2632 primop MkApUpd0_Op "mkApUpd0#" GenPrimOp
2637 primop NewBCOOp "newBCO#" GenPrimOp
2638 ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
2640 has_side_effects = True
2643 ------------------------------------------------------------------------
2645 ------------------------------------------------------------------------