primops.txt.pp 62.3 KB
Newer Older
1
-----------------------------------------------------------------------
2
3
-- 
-- (c) 2010 The University of Glasgow
4
--
5
-- Primitive Operations and Types
6
--
7
8
9
-- For more information on PrimOps, see
--   http://hackage.haskell.org/trac/ghc/wiki/Commentary/PrimOps
--
10
11
-----------------------------------------------------------------------

apt's avatar
apt committed
12
13
14
15
16
17
-- This file is processed by the utility program genprimopcode to produce
-- a number of include files within the compiler and optionally to produce
-- human-readable documentation.
--
-- It should first be preprocessed.
--
18
19
-- Information on how PrimOps are implemented and the steps necessary to
-- add a new one can be found in the Commentary:
apt's avatar
apt committed
20
--
21
--  http://hackage.haskell.org/trac/ghc/wiki/Commentary/PrimOps
apt's avatar
apt committed
22

23
24
-- This file is divided into named sections, each containing or more
-- primop entries. Section headers have the format:
apt's avatar
apt committed
25
26
27
--
--	section "section-name" {description}
--
28
29
-- This information is used solely when producing documentation; it is
-- otherwise ignored.  The description is optional.
apt's avatar
apt committed
30
31
--
-- The format of each primop entry is as follows:
32
--
apt's avatar
apt committed
33
--	primop internal-name "name-in-program-text" type category {description} attributes
34

apt's avatar
apt committed
35
-- The default attribute values which apply if you don't specify
36
37
38
39
-- other ones.  Attribute values can be True, False, or arbitrary
-- text between curly brackets.  This is a kludge to enable 
-- processors of this file to easily get hold of simple info
-- (eg, out_of_line), whilst avoiding parsing complex expressions
40
-- needed for strictness info.
41
42
43
44
45
46
47

defaults
   has_side_effects = False
   out_of_line      = False
   commutable       = False
   needs_wrapper    = False
   can_fail         = False
48
   strictness       = { \ arity -> mkStrictSig (mkTopDmdType (replicate arity lazyDmd) TopRes) }
49

50
51
52
-- Currently, documentation is produced using latex, so contents of
-- description fields should be legal latex. Descriptions can contain
-- matched pairs of embedded curly brackets.
apt's avatar
apt committed
53
54

#include "MachDeps.h"
55
56
57
58
59

-- We need platform defines (tests for mingw32 below).  However, we only
-- test the TARGET platform, which doesn't vary between stages, so the
-- stage1 platform defines are fine:
#include "../stage1/ghc_boot_platform.h"
apt's avatar
apt committed
60
61

section "The word size story."
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
	{Haskell98 specifies that signed integers (type {\tt Int})
	 must contain at least 30 bits. GHC always implements {\tt
	 Int} using the primitive type {\tt Int\#}, whose size equals
	 the {\tt MachDeps.h} constant {\tt WORD\_SIZE\_IN\_BITS}.
	 This is normally set based on the {\tt config.h} parameter
	 {\tt SIZEOF\_HSWORD}, i.e., 32 bits on 32-bit machines, 64
	 bits on 64-bit machines.  However, it can also be explicitly
	 set to a smaller number, e.g., 31 bits, to allow the
	 possibility of using tag bits. Currently GHC itself has only
	 32-bit and 64-bit variants, but 30 or 31-bit code can be
	 exported as an external core file for use in other back ends.

	 GHC also implements a primitive unsigned integer type {\tt
	 Word\#} which always has the same number of bits as {\tt
	 Int\#}.
apt's avatar
apt committed
77
	
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
	 In addition, GHC supports families of explicit-sized integers
	 and words at 8, 16, 32, and 64 bits, with the usual
	 arithmetic operations, comparisons, and a range of
	 conversions.  The 8-bit and 16-bit sizes are always
	 represented as {\tt Int\#} and {\tt Word\#}, and the
	 operations implemented in terms of the the primops on these
	 types, with suitable range restrictions on the results (using
	 the {\tt narrow$n$Int\#} and {\tt narrow$n$Word\#} families
	 of primops.  The 32-bit sizes are represented using {\tt
	 Int\#} and {\tt Word\#} when {\tt WORD\_SIZE\_IN\_BITS}
	 $\geq$ 32; otherwise, these are represented using distinct
	 primitive types {\tt Int32\#} and {\tt Word32\#}. These (when
	 needed) have a complete set of corresponding operations;
	 however, nearly all of these are implemented as external C
	 functions rather than as primops.  Exactly the same story
	 applies to the 64-bit sizes.  All of these details are hidden
	 under the {\tt PrelInt} and {\tt PrelWord} modules, which use
	 {\tt \#if}-defs to invoke the appropriate types and
	 operators.

	 Word size also matters for the families of primops for
	 indexing/reading/writing fixed-size quantities at offsets
	 from an array base, address, or foreign pointer.  Here, a
	 slightly different approach is taken.  The names of these
	 primops are fixed, but their {\it types} vary according to
	 the value of {\tt WORD\_SIZE\_IN\_BITS}. For example, if word
	 size is at least 32 bits then an operator like
105
106
	 \texttt{indexInt32Array\#} has type {\tt ByteArray\# -> Int\#
	 -> Int\#}; otherwise it has type {\tt ByteArray\# -> Int\# ->
107
108
	 Int32\#}.  This approach confines the necessary {\tt
	 \#if}-defs to this file; no conditional compilation is needed
109
	 in the files that expose these primops.
110
111
112
113
114
115
116

	 Finally, there are strongly deprecated primops for coercing
         between {\tt Addr\#}, the primitive type of machine
         addresses, and {\tt Int\#}.  These are pretty bogus anyway,
         but will work on existing 32-bit and 64-bit GHC targets; they
         are completely bogus when tag bits are used in {\tt Int\#},
         so are not available in this case.  }
apt's avatar
apt committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
	
-- Define synonyms for indexing ops. 

#if WORD_SIZE_IN_BITS < 32 
#define INT32 Int32#
#define WORD32 Word32#
#else
#define INT32 Int#
#define WORD32 Word#
#endif

#if WORD_SIZE_IN_BITS < 64
#define INT64 Int64#
#define WORD64 Word64#
#else
#define INT64 Int#
#define WORD64 Word#
#endif
135
136

------------------------------------------------------------------------
apt's avatar
apt committed
137
138
section "Char#" 
	{Operations on 31-bit characters.}
139
140
------------------------------------------------------------------------

141
primtype Char#
142

apt's avatar
apt committed
143
144
primop   CharGtOp  "gtChar#"   Compare   Char# -> Char# -> Bool
primop   CharGeOp  "geChar#"   Compare   Char# -> Char# -> Bool
145

apt's avatar
apt committed
146
147
148
primop   CharEqOp  "eqChar#"   Compare
   Char# -> Char# -> Bool
   with commutable = True
149

apt's avatar
apt committed
150
151
152
153
154
155
156
157
primop   CharNeOp  "neChar#"   Compare
   Char# -> Char# -> Bool
   with commutable = True

primop   CharLtOp  "ltChar#"   Compare   Char# -> Char# -> Bool
primop   CharLeOp  "leChar#"   Compare   Char# -> Char# -> Bool

primop   OrdOp   "ord#"  GenPrimOp   Char# -> Int#
158

159
------------------------------------------------------------------------
apt's avatar
apt committed
160
161
section "Int#"
	{Operations on native-size integers (30+ bits).}
162
163
------------------------------------------------------------------------

164
165
primtype Int#

apt's avatar
apt committed
166
167
168
primop   IntAddOp    "+#"    Dyadic
   Int# -> Int# -> Int#
   with commutable = True
169

apt's avatar
apt committed
170
primop   IntSubOp    "-#"    Dyadic   Int# -> Int# -> Int#
171

apt's avatar
apt committed
172
173
primop   IntMulOp    "*#" 
   Dyadic   Int# -> Int# -> Int#
174
175
176
177
   {Low word of signed integer multiply.}
   with commutable = True

primop   IntMulMayOfloOp  "mulIntMayOflo#" 
178
179
   Dyadic   Int# -> Int# -> Int#
   {Return non-zero if there is any possibility that the upper word of a
180
    signed integer multiply might contain useful information.  Return
181
    zero only if you are completely sure that no overflow can occur.
182
    On a 32-bit platform, the recommmended implementation is to do a 
183
184
185
186
    32 x 32 -> 64 signed multiply, and subtract result[63:32] from
    (result[31] >>signed 31).  If this is zero, meaning that the 
    upper word is merely a sign extension of the lower one, no
    overflow can occur.
187
188
189
190
191
192
193
194
195
196

    On a 64-bit platform it is not always possible to 
    acquire the top 64 bits of the result.  Therefore, a recommended 
    implementation is to take the absolute value of both operands, and 
    return 0 iff bits[63:31] of them are zero, since that means that their 
    magnitudes fit within 31 bits, so the magnitude of the product must fit 
    into 62 bits.

    If in doubt, return non-zero, but do make an effort to create the
    correct answer for small args, since otherwise the performance of
197
    \texttt{(*) :: Integer -> Integer -> Integer} will be poor.
198
   }
apt's avatar
apt committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
   with commutable = True

primop   IntQuotOp    "quotInt#"    Dyadic
   Int# -> Int# -> Int#
   {Rounds towards zero.}
   with can_fail = True

primop   IntRemOp    "remInt#"    Dyadic
   Int# -> Int# -> Int#
   {Satisfies \texttt{(quotInt\# x y) *\# y +\# (remInt\# x y) == x}.}
   with can_fail = True

primop   IntNegOp    "negateInt#"    Monadic   Int# -> Int#
primop   IntAddCOp   "addIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
213
214
	 {Add with carry.  First member of result is (wrapped) sum; 
          second member is 0 iff no overflow occured.}
apt's avatar
apt committed
215
primop   IntSubCOp   "subIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
216
217
218
	 {Subtract with carry.  First member of result is (wrapped) difference; 
          second member is 0 iff no overflow occured.}

apt's avatar
apt committed
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
primop   IntGtOp  ">#"   Compare   Int# -> Int# -> Bool
primop   IntGeOp  ">=#"   Compare   Int# -> Int# -> Bool

primop   IntEqOp  "==#"   Compare
   Int# -> Int# -> Bool
   with commutable = True

primop   IntNeOp  "/=#"   Compare
   Int# -> Int# -> Bool
   with commutable = True

primop   IntLtOp  "<#"   Compare   Int# -> Int# -> Bool
primop   IntLeOp  "<=#"   Compare   Int# -> Int# -> Bool

primop   ChrOp   "chr#"   GenPrimOp   Int# -> Char#

primop   Int2WordOp "int2Word#" GenPrimOp Int# -> Word#
primop   Int2FloatOp   "int2Float#"      GenPrimOp  Int# -> Float#
primop   Int2DoubleOp   "int2Double#"          GenPrimOp  Int# -> Double#

239
primop   ISllOp   "uncheckedIShiftL#" GenPrimOp  Int# -> Int# -> Int#
240
241
	 {Shift left.  Result undefined if shift amount is not
          in the range 0 to word size - 1 inclusive.}
242
primop   ISraOp   "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
243
244
	 {Shift right arithmetic.  Result undefined if shift amount is not
          in the range 0 to word size - 1 inclusive.}
245
primop   ISrlOp   "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
246
247
	 {Shift right logical.  Result undefined if shift amount is not
          in the range 0 to word size - 1 inclusive.}
248
249

------------------------------------------------------------------------
apt's avatar
apt committed
250
251
section "Word#"
	{Operations on native-sized unsigned words (30+ bits).}
252
253
------------------------------------------------------------------------

254
255
primtype Word#

apt's avatar
apt committed
256
257
primop   WordAddOp   "plusWord#"   Dyadic   Word# -> Word# -> Word#
   with commutable = True
258

apt's avatar
apt committed
259
260
261
primop   WordSubOp   "minusWord#"   Dyadic   Word# -> Word# -> Word#

primop   WordMulOp   "timesWord#"   Dyadic   Word# -> Word# -> Word#
262
263
   with commutable = True

apt's avatar
apt committed
264
265
266
267
268
269
270
primop   WordQuotOp   "quotWord#"   Dyadic   Word# -> Word# -> Word#
   with can_fail = True

primop   WordRemOp   "remWord#"   Dyadic   Word# -> Word# -> Word#
   with can_fail = True

primop   AndOp   "and#"   Dyadic   Word# -> Word# -> Word#
271
272
   with commutable = True

apt's avatar
apt committed
273
274
275
276
277
278
279
280
primop   OrOp   "or#"   Dyadic   Word# -> Word# -> Word#
   with commutable = True

primop   XorOp   "xor#"   Dyadic   Word# -> Word# -> Word#
   with commutable = True

primop   NotOp   "not#"   Monadic   Word# -> Word#

281
primop   SllOp   "uncheckedShiftL#"   GenPrimOp   Word# -> Int# -> Word#
282
283
	 {Shift left logical.   Result undefined if shift amount is not
          in the range 0 to word size - 1 inclusive.}
284
primop   SrlOp   "uncheckedShiftRL#"   GenPrimOp   Word# -> Int# -> Word#
285
286
	 {Shift right logical.   Result undefined if shift  amount is not
          in the range 0 to word size - 1 inclusive.}
apt's avatar
apt committed
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312

primop   Word2IntOp   "word2Int#"   GenPrimOp   Word# -> Int#

primop   WordGtOp   "gtWord#"   Compare   Word# -> Word# -> Bool
primop   WordGeOp   "geWord#"   Compare   Word# -> Word# -> Bool
primop   WordEqOp   "eqWord#"   Compare   Word# -> Word# -> Bool
primop   WordNeOp   "neWord#"   Compare   Word# -> Word# -> Bool
primop   WordLtOp   "ltWord#"   Compare   Word# -> Word# -> Bool
primop   WordLeOp   "leWord#"   Compare   Word# -> Word# -> Bool

------------------------------------------------------------------------
section "Narrowings" 
	{Explicit narrowing of native-sized ints or words.}
------------------------------------------------------------------------

primop   Narrow8IntOp      "narrow8Int#"      Monadic   Int# -> Int#
primop   Narrow16IntOp     "narrow16Int#"     Monadic   Int# -> Int#
primop   Narrow32IntOp     "narrow32Int#"     Monadic   Int# -> Int#
primop   Narrow8WordOp     "narrow8Word#"     Monadic   Word# -> Word#
primop   Narrow16WordOp    "narrow16Word#"    Monadic   Word# -> Word#
primop   Narrow32WordOp    "narrow32Word#"    Monadic   Word# -> Word#


#if WORD_SIZE_IN_BITS < 32
------------------------------------------------------------------------
section "Int32#"
313
314
	{Operations on 32-bit integers ({\tt Int32\#}).  This type is only used
         if plain {\tt Int\#} has less than 32 bits.  In any case, the operations
apt's avatar
apt committed
315
316
317
	 are not primops; they are implemented (if needed) as ccalls instead.}
------------------------------------------------------------------------

318
319
primtype Int32#

apt's avatar
apt committed
320
321
322
------------------------------------------------------------------------
section "Word32#"
	{Operations on 32-bit unsigned words. This type is only used 
323
	 if plain {\tt Word\#} has less than 32 bits. In any case, the operations
apt's avatar
apt committed
324
325
326
	 are not primops; they are implemented (if needed) as ccalls instead.}
------------------------------------------------------------------------

327
328
primtype Word32#

apt's avatar
apt committed
329
330
331
332
333
334
335
#endif 


#if WORD_SIZE_IN_BITS < 64
------------------------------------------------------------------------
section "Int64#"
	{Operations on 64-bit unsigned words. This type is only used 
336
	 if plain {\tt Int\#} has less than 64 bits. In any case, the operations
apt's avatar
apt committed
337
338
339
	 are not primops; they are implemented (if needed) as ccalls instead.}
------------------------------------------------------------------------

340
341
primtype Int64#

apt's avatar
apt committed
342
343
344
------------------------------------------------------------------------
section "Word64#"
	{Operations on 64-bit unsigned words. This type is only used 
345
	 if plain {\tt Word\#} has less than 64 bits. In any case, the operations
apt's avatar
apt committed
346
347
348
	 are not primops; they are implemented (if needed) as ccalls instead.}
------------------------------------------------------------------------

349
350
primtype Word64#

apt's avatar
apt committed
351
352
#endif

353
------------------------------------------------------------------------
apt's avatar
apt committed
354
355
section "Double#"
	{Operations on double-precision (64 bit) floating-point numbers.}
356
357
------------------------------------------------------------------------

358
359
primtype Double#

360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
primop   DoubleGtOp ">##"   Compare   Double# -> Double# -> Bool
primop   DoubleGeOp ">=##"   Compare   Double# -> Double# -> Bool

primop DoubleEqOp "==##"   Compare
   Double# -> Double# -> Bool
   with commutable = True

primop DoubleNeOp "/=##"   Compare
   Double# -> Double# -> Bool
   with commutable = True

primop   DoubleLtOp "<##"   Compare   Double# -> Double# -> Bool
primop   DoubleLeOp "<=##"   Compare   Double# -> Double# -> Bool

primop   DoubleAddOp   "+##"   Dyadic
   Double# -> Double# -> Double#
   with commutable = True

primop   DoubleSubOp   "-##"   Dyadic   Double# -> Double# -> Double#

primop   DoubleMulOp   "*##"   Dyadic
   Double# -> Double# -> Double#
   with commutable = True

primop   DoubleDivOp   "/##"   Dyadic
   Double# -> Double# -> Double#
   with can_fail = True

primop   DoubleNegOp   "negateDouble#"  Monadic   Double# -> Double#

primop   Double2IntOp   "double2Int#"          GenPrimOp  Double# -> Int#
391
392
393
394
   {Truncates a {\tt Double#} value to the nearest {\tt Int#}.
    Results are undefined if the truncation if truncation yields
    a value outside the range of {\tt Int#}.}

395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
primop   Double2FloatOp   "double2Float#" GenPrimOp Double# -> Float#

primop   DoubleExpOp   "expDouble#"      Monadic
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleLogOp   "logDouble#"      Monadic         
   Double# -> Double#
   with
   needs_wrapper = True
   can_fail = True

primop   DoubleSqrtOp   "sqrtDouble#"      Monadic  
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleSinOp   "sinDouble#"      Monadic          
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleCosOp   "cosDouble#"      Monadic          
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleTanOp   "tanDouble#"      Monadic          
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleAsinOp   "asinDouble#"      Monadic 
   Double# -> Double#
   with
   needs_wrapper = True
   can_fail = True

primop   DoubleAcosOp   "acosDouble#"      Monadic  
   Double# -> Double#
   with
   needs_wrapper = True
   can_fail = True

primop   DoubleAtanOp   "atanDouble#"      Monadic  
   Double# -> Double#
   with
   needs_wrapper = True

primop   DoubleSinhOp   "sinhDouble#"      Monadic  
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleCoshOp   "coshDouble#"      Monadic  
   Double# -> Double#
   with needs_wrapper = True

primop   DoubleTanhOp   "tanhDouble#"      Monadic  
   Double# -> Double#
   with needs_wrapper = True

primop   DoublePowerOp   "**##" Dyadic  
   Double# -> Double# -> Double#
apt's avatar
apt committed
454
   {Exponentiation.}
455
456
   with needs_wrapper = True

457
primop   DoubleDecode_2IntOp   "decodeDouble_2Int#" GenPrimOp    
458
   Double# -> (# Int#, Word#, Word#, Int# #)
459
   {Convert to integer.
460
461
462
    First component of the result is -1 or 1, indicating the sign of the
    mantissa. The next two are the high and low 32 bits of the mantissa
    respectively, and the last is the exponent.}
463
464
   with out_of_line = True

465
------------------------------------------------------------------------
apt's avatar
apt committed
466
467
section "Float#" 
	{Operations on single-precision (32-bit) floating-point numbers.}
468
469
------------------------------------------------------------------------

470
471
primtype Float#

472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
primop   FloatGtOp  "gtFloat#"   Compare   Float# -> Float# -> Bool
primop   FloatGeOp  "geFloat#"   Compare   Float# -> Float# -> Bool

primop   FloatEqOp  "eqFloat#"   Compare
   Float# -> Float# -> Bool
   with commutable = True

primop   FloatNeOp  "neFloat#"   Compare
   Float# -> Float# -> Bool
   with commutable = True

primop   FloatLtOp  "ltFloat#"   Compare   Float# -> Float# -> Bool
primop   FloatLeOp  "leFloat#"   Compare   Float# -> Float# -> Bool

primop   FloatAddOp   "plusFloat#"      Dyadic            
   Float# -> Float# -> Float#
   with commutable = True

primop   FloatSubOp   "minusFloat#"      Dyadic      Float# -> Float# -> Float#

primop   FloatMulOp   "timesFloat#"      Dyadic    
   Float# -> Float# -> Float#
   with commutable = True

primop   FloatDivOp   "divideFloat#"      Dyadic  
   Float# -> Float# -> Float#
   with can_fail = True

primop   FloatNegOp   "negateFloat#"      Monadic    Float# -> Float#

primop   Float2IntOp   "float2Int#"      GenPrimOp  Float# -> Int#
503
504
505
   {Truncates a {\tt Float#} value to the nearest {\tt Int#}.
    Results are undefined if the truncation if truncation yields
    a value outside the range of {\tt Int#}.}
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563

primop   FloatExpOp   "expFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatLogOp   "logFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True
        can_fail = True

primop   FloatSqrtOp   "sqrtFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatSinOp   "sinFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatCosOp   "cosFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatTanOp   "tanFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatAsinOp   "asinFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True
        can_fail = True

primop   FloatAcosOp   "acosFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True
        can_fail = True

primop   FloatAtanOp   "atanFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatSinhOp   "sinhFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatCoshOp   "coshFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatTanhOp   "tanhFloat#"      Monadic          
   Float# -> Float#
   with needs_wrapper = True

primop   FloatPowerOp   "powerFloat#"      Dyadic   
   Float# -> Float# -> Float#
   with needs_wrapper = True

primop   Float2DoubleOp   "float2Double#" GenPrimOp  Float# -> Double#

564
565
primop   FloatDecode_IntOp   "decodeFloat_Int#" GenPrimOp
   Float# -> (# Int#, Int# #)
566
   {Convert to integers.
567
568
569
    First {\tt Int\#} in result is the mantissa; second is the exponent.}
   with out_of_line = True

570
------------------------------------------------------------------------
apt's avatar
apt committed
571
section "Arrays"
572
	{Operations on {\tt Array\#}.}
573
574
------------------------------------------------------------------------

575
576
primtype Array# a

577
primtype MutableArray# s a
578

apt's avatar
apt committed
579
primop  NewArrayOp "newArray#" GenPrimOp
580
   Int# -> a -> State# s -> (# State# s, MutableArray# s a #)
apt's avatar
apt committed
581
582
583
584
585
   {Create a new mutable array of specified size (in bytes),
    in the specified state thread,
    with each element containing the specified initial value.}
   with
   out_of_line = True
586
   has_side_effects = True
587

apt's avatar
apt committed
588
primop  SameMutableArrayOp "sameMutableArray#" GenPrimOp
589
   MutableArray# s a -> MutableArray# s a -> Bool
590

apt's avatar
apt committed
591
primop  ReadArrayOp "readArray#" GenPrimOp
592
   MutableArray# s a -> Int# -> State# s -> (# State# s, a #)
apt's avatar
apt committed
593
   {Read from specified index of mutable array. Result is not yet evaluated.}
594
595
   with
   has_side_effects = True
596

apt's avatar
apt committed
597
primop  WriteArrayOp "writeArray#" GenPrimOp
598
   MutableArray# s a -> Int# -> a -> State# s -> State# s
apt's avatar
apt committed
599
600
601
   {Write to specified index of mutable array.}
   with
   has_side_effects = True
602

apt's avatar
apt committed
603
604
605
606
primop  IndexArrayOp "indexArray#" GenPrimOp
   Array# a -> Int# -> (# a #)
   {Read from specified index of immutable array. Result is packaged into
    an unboxed singleton; the result itself is not yet evaluated.}
607

apt's avatar
apt committed
608
primop  UnsafeFreezeArrayOp "unsafeFreezeArray#" GenPrimOp
609
   MutableArray# s a -> State# s -> (# State# s, Array# a #)
apt's avatar
apt committed
610
611
612
   {Make a mutable array immutable, without copying.}
   with
   has_side_effects = True
613

apt's avatar
apt committed
614
primop  UnsafeThawArrayOp  "unsafeThawArray#" GenPrimOp
615
   Array# a -> State# s -> (# State# s, MutableArray# s a #)
apt's avatar
apt committed
616
617
618
   {Make an immutable array mutable, without copying.}
   with
   out_of_line = True
619
   has_side_effects = True
620

621
------------------------------------------------------------------------
apt's avatar
apt committed
622
section "Byte Arrays"
623
	{Operations on {\tt ByteArray\#}. A {\tt ByteArray\#} is a just a region of
624
         raw memory in the garbage-collected heap, which is not
625
626
         scanned for pointers. It carries its own size (in bytes).
         There are
627
628
629
630
631
632
         three sets of operations for accessing byte array contents:
         index for reading from immutable byte arrays, and read/write
         for mutable byte arrays.  Each set contains operations for a
         range of useful primitive data types.  Each operation takes
         an offset measured in terms of the size fo the primitive type
         being read or written.}
633

634
635
------------------------------------------------------------------------

636
primtype ByteArray#
637

638
primtype MutableByteArray# s
639

640
primop  NewByteArrayOp_Char "newByteArray#" GenPrimOp
641
   Int# -> State# s -> (# State# s, MutableByteArray# s #)
apt's avatar
apt committed
642
643
   {Create a new mutable byte array of specified size (in bytes), in
    the specified state thread.}
644
   with out_of_line = True
645
        has_side_effects = True
646

647
primop  NewPinnedByteArrayOp_Char "newPinnedByteArray#" GenPrimOp
648
   Int# -> State# s -> (# State# s, MutableByteArray# s #)
apt's avatar
apt committed
649
   {Create a mutable byte array that the GC guarantees not to move.}
650
   with out_of_line = True
651
        has_side_effects = True
652

Simon Marlow's avatar
Simon Marlow committed
653
654
655
656
primop  NewAlignedPinnedByteArrayOp_Char "newAlignedPinnedByteArray#" GenPrimOp
   Int# -> Int# -> State# s -> (# State# s, MutableByteArray# s #)
   {Create a mutable byte array, aligned by the specified amount, that the GC guarantees not to move.}
   with out_of_line = True
657
        has_side_effects = True
Simon Marlow's avatar
Simon Marlow committed
658

659
primop  ByteArrayContents_Char "byteArrayContents#" GenPrimOp
660
   ByteArray# -> Addr#
apt's avatar
apt committed
661
662
663
   {Intended for use with pinned arrays; otherwise very unsafe!}

primop  SameMutableByteArrayOp "sameMutableByteArray#" GenPrimOp
664
   MutableByteArray# s -> MutableByteArray# s -> Bool
apt's avatar
apt committed
665
666

primop  UnsafeFreezeByteArrayOp "unsafeFreezeByteArray#" GenPrimOp
667
   MutableByteArray# s -> State# s -> (# State# s, ByteArray# #)
apt's avatar
apt committed
668
669
670
671
672
   {Make a mutable byte array immutable, without copying.}
   with
   has_side_effects = True

primop  SizeofByteArrayOp "sizeofByteArray#" GenPrimOp  
673
   ByteArray# -> Int#
674
   {Return the size of the array in bytes.}
apt's avatar
apt committed
675
676

primop  SizeofMutableByteArrayOp "sizeofMutableByteArray#" GenPrimOp
677
   MutableByteArray# s -> Int#
678
   {Return the size of the array in bytes.}
679

680
primop IndexByteArrayOp_Char "indexCharArray#" GenPrimOp
681
   ByteArray# -> Int# -> Char#
apt's avatar
apt committed
682
   {Read 8-bit character; offset in bytes.}
683
684

primop IndexByteArrayOp_WideChar "indexWideCharArray#" GenPrimOp
685
   ByteArray# -> Int# -> Char#
apt's avatar
apt committed
686
   {Read 31-bit character; offset in 4-byte words.}
687
688

primop IndexByteArrayOp_Int "indexIntArray#" GenPrimOp
689
   ByteArray# -> Int# -> Int#
690
691

primop IndexByteArrayOp_Word "indexWordArray#" GenPrimOp
692
   ByteArray# -> Int# -> Word#
693
694

primop IndexByteArrayOp_Addr "indexAddrArray#" GenPrimOp
695
   ByteArray# -> Int# -> Addr#
696
697

primop IndexByteArrayOp_Float "indexFloatArray#" GenPrimOp
698
   ByteArray# -> Int# -> Float#
699
700

primop IndexByteArrayOp_Double "indexDoubleArray#" GenPrimOp
701
   ByteArray# -> Int# -> Double#
702
703

primop IndexByteArrayOp_StablePtr "indexStablePtrArray#" GenPrimOp
704
   ByteArray# -> Int# -> StablePtr# a
705
706

primop IndexByteArrayOp_Int8 "indexInt8Array#" GenPrimOp
707
   ByteArray# -> Int# -> Int#
708
709

primop IndexByteArrayOp_Int16 "indexInt16Array#" GenPrimOp
710
   ByteArray# -> Int# -> Int#
711
712

primop IndexByteArrayOp_Int32 "indexInt32Array#" GenPrimOp
713
   ByteArray# -> Int# -> INT32
714
715

primop IndexByteArrayOp_Int64 "indexInt64Array#" GenPrimOp
716
   ByteArray# -> Int# -> INT64
717
718

primop IndexByteArrayOp_Word8 "indexWord8Array#" GenPrimOp
719
   ByteArray# -> Int# -> Word#
720
721

primop IndexByteArrayOp_Word16 "indexWord16Array#" GenPrimOp
722
   ByteArray# -> Int# -> Word#
723
724

primop IndexByteArrayOp_Word32 "indexWord32Array#" GenPrimOp
725
   ByteArray# -> Int# -> WORD32
726
727

primop IndexByteArrayOp_Word64 "indexWord64Array#" GenPrimOp
728
   ByteArray# -> Int# -> WORD64
729

730
primop  ReadByteArrayOp_Char "readCharArray#" GenPrimOp
731
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
apt's avatar
apt committed
732
   {Read 8-bit character; offset in bytes.}
733
   with has_side_effects = True
734

735
primop  ReadByteArrayOp_WideChar "readWideCharArray#" GenPrimOp
736
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Char# #)
apt's avatar
apt committed
737
   {Read 31-bit character; offset in 4-byte words.}
738
   with has_side_effects = True
739

740
primop  ReadByteArrayOp_Int "readIntArray#" GenPrimOp
741
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
742
   with has_side_effects = True
743
744

primop  ReadByteArrayOp_Word "readWordArray#" GenPrimOp
745
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
746
   with has_side_effects = True
747
748

primop  ReadByteArrayOp_Addr "readAddrArray#" GenPrimOp
749
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Addr# #)
750
   with has_side_effects = True
751
752

primop  ReadByteArrayOp_Float "readFloatArray#" GenPrimOp
753
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Float# #)
754
   with has_side_effects = True
755
756

primop  ReadByteArrayOp_Double "readDoubleArray#" GenPrimOp
757
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Double# #)
758
   with has_side_effects = True
759
760

primop  ReadByteArrayOp_StablePtr "readStablePtrArray#" GenPrimOp
761
   MutableByteArray# s -> Int# -> State# s -> (# State# s, StablePtr# a #)
762
   with has_side_effects = True
763

764
primop  ReadByteArrayOp_Int8 "readInt8Array#" GenPrimOp
765
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
766
   with has_side_effects = True
767
768

primop  ReadByteArrayOp_Int16 "readInt16Array#" GenPrimOp
769
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Int# #)
770
   with has_side_effects = True
771
772

primop  ReadByteArrayOp_Int32 "readInt32Array#" GenPrimOp
773
   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT32 #)
774
   with has_side_effects = True
775

776
primop  ReadByteArrayOp_Int64 "readInt64Array#" GenPrimOp
777
   MutableByteArray# s -> Int# -> State# s -> (# State# s, INT64 #)
778
   with has_side_effects = True
779

780
primop  ReadByteArrayOp_Word8 "readWord8Array#" GenPrimOp
781
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
782
   with has_side_effects = True
783
784

primop  ReadByteArrayOp_Word16 "readWord16Array#" GenPrimOp
785
   MutableByteArray# s -> Int# -> State# s -> (# State# s, Word# #)
786
   with has_side_effects = True
787
788

primop  ReadByteArrayOp_Word32 "readWord32Array#" GenPrimOp
789
   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD32 #)
790
   with has_side_effects = True
791

792
primop  ReadByteArrayOp_Word64 "readWord64Array#" GenPrimOp
793
   MutableByteArray# s -> Int# -> State# s -> (# State# s, WORD64 #)
794
   with has_side_effects = True
795
796

primop  WriteByteArrayOp_Char "writeCharArray#" GenPrimOp
797
   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
apt's avatar
apt committed
798
   {Write 8-bit character; offset in bytes.}
799
800
   with has_side_effects = True

801
primop  WriteByteArrayOp_WideChar "writeWideCharArray#" GenPrimOp
802
   MutableByteArray# s -> Int# -> Char# -> State# s -> State# s
apt's avatar
apt committed
803
   {Write 31-bit character; offset in 4-byte words.}
804
805
   with has_side_effects = True

806
primop  WriteByteArrayOp_Int "writeIntArray#" GenPrimOp
807
   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
808
809
810
   with has_side_effects = True

primop  WriteByteArrayOp_Word "writeWordArray#" GenPrimOp
811
   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
812
813
814
   with has_side_effects = True

primop  WriteByteArrayOp_Addr "writeAddrArray#" GenPrimOp
815
   MutableByteArray# s -> Int# -> Addr# -> State# s -> State# s
816
817
818
   with has_side_effects = True

primop  WriteByteArrayOp_Float "writeFloatArray#" GenPrimOp
819
   MutableByteArray# s -> Int# -> Float# -> State# s -> State# s
820
821
822
   with has_side_effects = True

primop  WriteByteArrayOp_Double "writeDoubleArray#" GenPrimOp
823
   MutableByteArray# s -> Int# -> Double# -> State# s -> State# s
824
825
826
   with has_side_effects = True

primop  WriteByteArrayOp_StablePtr "writeStablePtrArray#" GenPrimOp
827
   MutableByteArray# s -> Int# -> StablePtr# a -> State# s -> State# s
828
829
   with has_side_effects = True

830
primop  WriteByteArrayOp_Int8 "writeInt8Array#" GenPrimOp
831
   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
832
833
   with has_side_effects = True

834
primop  WriteByteArrayOp_Int16 "writeInt16Array#" GenPrimOp
835
   MutableByteArray# s -> Int# -> Int# -> State# s -> State# s
836
837
   with has_side_effects = True

838
primop  WriteByteArrayOp_Int32 "writeInt32Array#" GenPrimOp
839
   MutableByteArray# s -> Int# -> INT32 -> State# s -> State# s
840
841
   with has_side_effects = True

842
primop  WriteByteArrayOp_Int64 "writeInt64Array#" GenPrimOp
843
   MutableByteArray# s -> Int# -> INT64 -> State# s -> State# s
844
845
   with has_side_effects = True

846
primop  WriteByteArrayOp_Word8 "writeWord8Array#" GenPrimOp
847
   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
848
849
   with has_side_effects = True

850
primop  WriteByteArrayOp_Word16 "writeWord16Array#" GenPrimOp
851
   MutableByteArray# s -> Int# -> Word# -> State# s -> State# s
852
853
   with has_side_effects = True

854
primop  WriteByteArrayOp_Word32 "writeWord32Array#" GenPrimOp
855
   MutableByteArray# s -> Int# -> WORD32 -> State# s -> State# s
856
857
858
   with has_side_effects = True

primop  WriteByteArrayOp_Word64 "writeWord64Array#" GenPrimOp
859
   MutableByteArray# s -> Int# -> WORD64 -> State# s -> State# s
860
   with has_side_effects = True
apt's avatar
apt committed
861
862
863
864
865

------------------------------------------------------------------------
section "Addr#"
------------------------------------------------------------------------

866
867
868
869
870
871
872
primtype Addr#
	{ An arbitrary machine address assumed to point outside
	 the garbage-collected heap. }

pseudoop "nullAddr#" Addr#
	{ The null address. }

apt's avatar
apt committed
873
874
primop	 AddrAddOp "plusAddr#" GenPrimOp Addr# -> Int# -> Addr#
primop	 AddrSubOp "minusAddr#" GenPrimOp Addr# -> Addr# -> Int#
875
876
	 {Result is meaningless if two {\tt Addr\#}s are so far apart that their
	 difference doesn't fit in an {\tt Int\#}.}
apt's avatar
apt committed
877
primop	 AddrRemOp "remAddr#" GenPrimOp Addr# -> Int# -> Int#
878
879
	 {Return the remainder when the {\tt Addr\#} arg, treated like an {\tt Int\#},
	  is divided by the {\tt Int\#} arg.}
apt's avatar
apt committed
880
881
882
883
884
#if (WORD_SIZE_IN_BITS == 32 || WORD_SIZE_IN_BITS == 64)
primop   Addr2IntOp  "addr2Int#"     GenPrimOp   Addr# -> Int#
	{Coerce directly from address to int. Strongly deprecated.}
primop   Int2AddrOp   "int2Addr#"    GenPrimOp  Int# -> Addr#
	{Coerce directly from int to address. Strongly deprecated.}
ken's avatar
ken committed
885
#endif
886

apt's avatar
apt committed
887
888
889
890
891
892
primop   AddrGtOp  "gtAddr#"   Compare   Addr# -> Addr# -> Bool
primop   AddrGeOp  "geAddr#"   Compare   Addr# -> Addr# -> Bool
primop   AddrEqOp  "eqAddr#"   Compare   Addr# -> Addr# -> Bool
primop   AddrNeOp  "neAddr#"   Compare   Addr# -> Addr# -> Bool
primop   AddrLtOp  "ltAddr#"   Compare   Addr# -> Addr# -> Bool
primop   AddrLeOp  "leAddr#"   Compare   Addr# -> Addr# -> Bool
893
894
895

primop IndexOffAddrOp_Char "indexCharOffAddr#" GenPrimOp
   Addr# -> Int# -> Char#
apt's avatar
apt committed
896
   {Reads 8-bit character; offset in bytes.}
897

898
899
primop IndexOffAddrOp_WideChar "indexWideCharOffAddr#" GenPrimOp
   Addr# -> Int# -> Char#
apt's avatar
apt committed
900
   {Reads 31-bit character; offset in 4-byte words.}
901

902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
primop IndexOffAddrOp_Int "indexIntOffAddr#" GenPrimOp
   Addr# -> Int# -> Int#

primop IndexOffAddrOp_Word "indexWordOffAddr#" GenPrimOp
   Addr# -> Int# -> Word#

primop IndexOffAddrOp_Addr "indexAddrOffAddr#" GenPrimOp
   Addr# -> Int# -> Addr#

primop IndexOffAddrOp_Float "indexFloatOffAddr#" GenPrimOp
   Addr# -> Int# -> Float#

primop IndexOffAddrOp_Double "indexDoubleOffAddr#" GenPrimOp
   Addr# -> Int# -> Double#

primop IndexOffAddrOp_StablePtr "indexStablePtrOffAddr#" GenPrimOp
   Addr# -> Int# -> StablePtr# a

920
921
922
923
924
925
926
primop IndexOffAddrOp_Int8 "indexInt8OffAddr#" GenPrimOp
   Addr# -> Int# -> Int#

primop IndexOffAddrOp_Int16 "indexInt16OffAddr#" GenPrimOp
   Addr# -> Int# -> Int#

primop IndexOffAddrOp_Int32 "indexInt32OffAddr#" GenPrimOp
apt's avatar
apt committed
927
   Addr# -> Int# -> INT32
928

929
primop IndexOffAddrOp_Int64 "indexInt64OffAddr#" GenPrimOp
apt's avatar
apt committed
930
   Addr# -> Int# -> INT64
931

932
933
934
935
936
937
938
primop IndexOffAddrOp_Word8 "indexWord8OffAddr#" GenPrimOp
   Addr# -> Int# -> Word#

primop IndexOffAddrOp_Word16 "indexWord16OffAddr#" GenPrimOp
   Addr# -> Int# -> Word#

primop IndexOffAddrOp_Word32 "indexWord32OffAddr#" GenPrimOp
apt's avatar
apt committed
939
   Addr# -> Int# -> WORD32
940

941
primop IndexOffAddrOp_Word64 "indexWord64OffAddr#" GenPrimOp
apt's avatar
apt committed
942
   Addr# -> Int# -> WORD64
943
944
945

primop ReadOffAddrOp_Char "readCharOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Char# #)
apt's avatar
apt committed
946
   {Reads 8-bit character; offset in bytes.}
947
   with has_side_effects = True
948

949
950
primop ReadOffAddrOp_WideChar "readWideCharOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Char# #)
apt's avatar
apt committed
951
   {Reads 31-bit character; offset in 4-byte words.}
952
   with has_side_effects = True
953

954
955
primop ReadOffAddrOp_Int "readIntOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Int# #)
956
   with has_side_effects = True
957
958
959

primop ReadOffAddrOp_Word "readWordOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Word# #)
960
   with has_side_effects = True
961
962
963

primop ReadOffAddrOp_Addr "readAddrOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Addr# #)
964
   with has_side_effects = True
965
966
967

primop ReadOffAddrOp_Float "readFloatOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Float# #)
968
   with has_side_effects = True
969
970
971

primop ReadOffAddrOp_Double "readDoubleOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Double# #)
972
   with has_side_effects = True
973
974
975

primop ReadOffAddrOp_StablePtr "readStablePtrOffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, StablePtr# a #)
976
   with has_side_effects = True
977

978
979
primop ReadOffAddrOp_Int8 "readInt8OffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Int# #)
980
   with has_side_effects = True
981
982
983

primop ReadOffAddrOp_Int16 "readInt16OffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Int# #)
984
   with has_side_effects = True
985
986

primop ReadOffAddrOp_Int32 "readInt32OffAddr#" GenPrimOp
apt's avatar
apt committed
987
   Addr# -> Int# -> State# s -> (# State# s, INT32 #)
988
   with has_side_effects = True
989

990
primop ReadOffAddrOp_Int64 "readInt64OffAddr#" GenPrimOp
apt's avatar
apt committed
991
   Addr# -> Int# -> State# s -> (# State# s, INT64 #)
992
   with has_side_effects = True
993

994
995
primop ReadOffAddrOp_Word8 "readWord8OffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Word# #)
996
   with has_side_effects = True
997
998
999

primop ReadOffAddrOp_Word16 "readWord16OffAddr#" GenPrimOp
   Addr# -> Int# -> State# s -> (# State# s, Word# #)
1000
   with has_side_effects = True
1001
1002

primop ReadOffAddrOp_Word32 "readWord32OffAddr#" GenPrimOp
apt's avatar
apt committed
1003
   Addr# -> Int# -> State# s -> (# State# s, WORD32 #)
1004
   with has_side_effects = True
1005

1006
primop ReadOffAddrOp_Word64 "readWord64OffAddr#" GenPrimOp
apt's avatar
apt committed
1007
   Addr# -> Int# -> State# s -> (# State# s, WORD64 #)
1008
   with has_side_effects = True
1009
1010
1011
1012
1013
1014


primop  WriteOffAddrOp_Char "writeCharOffAddr#" GenPrimOp
   Addr# -> Int# -> Char# -> State# s -> State# s
   with has_side_effects = True

1015
1016
1017
1018
primop  WriteOffAddrOp_WideChar "writeWideCharOffAddr#" GenPrimOp
   Addr# -> Int# -> Char# -> State# s -> State# s
   with has_side_effects = True

1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
primop  WriteOffAddrOp_Int "writeIntOffAddr#" GenPrimOp
   Addr# -> Int# -> Int# -> State# s -> State# s
   with has_side_effects = True

primop  WriteOffAddrOp_Word "writeWordOffAddr#" GenPrimOp
   Addr# -> Int# -> Word# -> State# s -> State# s
   with has_side_effects = True

primop  WriteOffAddrOp_Addr "writeAddrOffAddr#" GenPrimOp
   Addr# -> Int# -> Addr# -> State# s -> State# s
   with has_side_effects = True

primop  WriteOffAddrOp_Float "writeFloatOffAddr#" GenPrimOp
   Addr# -> Int# -> Float# -> State# s -> State# s
   with has_side_effects = True

primop  WriteOffAddrOp_Double "writeDoubleOffAddr#" GenPrimOp
   Addr# -> Int# -> Double# -> State# s -> State# s
   with has_side_effects = True

primop  WriteOffAddrOp_StablePtr "writeStablePtrOffAddr#" GenPrimOp
   Addr# -> Int# -> StablePtr# a -> State# s -> State# s
   with has_side_effects = True

1043
1044
1045
1046
primop  WriteOffAddrOp_Int8 "writeInt8OffAddr#" GenPrimOp
   Addr# -> Int# -> Int# -> State# s -> State# s
   with has_side_effects = True

1047
1048
primop  WriteOffAddrOp_Int16 "writeInt16OffAddr#" GenPrimOp
   Addr# -> Int# -> Int# -> State# s -> State# s
1049
1050
   with has_side_effects = True

1051
primop  WriteOffAddrOp_Int32 "writeInt32OffAddr#" GenPrimOp
apt's avatar
apt committed
1052
   Addr# -> Int# -> INT32 -> State# s -> State# s
1053
1054
   with has_side_effects = True

1055
primop  WriteOffAddrOp_Int64 "writeInt64OffAddr#" GenPrimOp
apt's avatar
apt committed
1056
   Addr# -> Int# -> INT64 -> State# s -> State# s
1057
1058
   with has_side_effects = True

1059
1060
primop  WriteOffAddrOp_Word8 "writeWord8OffAddr#" GenPrimOp
   Addr# -> Int# -> Word# -> State# s -> State# s
1061
1062
   with has_side_effects = True

1063
primop  WriteOffAddrOp_Word16 "writeWord16OffAddr#" GenPrimOp
1064
1065
1066
   Addr# -> Int# -> Word# -> State# s -> State# s
   with has_side_effects = True

1067
primop  WriteOffAddrOp_Word32 "writeWord32OffAddr#" GenPrimOp
apt's avatar
apt committed
1068
   Addr# -> Int# -> WORD32 -> State# s -> State# s
1069
1070
1071
   with has_side_effects = True

primop  WriteOffAddrOp_Word64 "writeWord64OffAddr#" GenPrimOp
apt's avatar
apt committed
1072
   Addr# -> Int# -> WORD64 -> State# s -> State# s
1073
1074
1075
   with has_side_effects = True

------------------------------------------------------------------------
apt's avatar
apt committed
1076
section "Mutable variables"
1077
	{Operations on MutVar\#s.}
1078
1079
------------------------------------------------------------------------

1080
1081
1082
primtype MutVar# s a
	{A {\tt MutVar\#} behaves like a single-element mutable array.}

1083
1084
primop  NewMutVarOp "newMutVar#" GenPrimOp
   a -> State# s -> (# State# s, MutVar# s a #)
1085
   {Create {\tt MutVar\#} with specified initial value in specified state thread.}
1086
1087
   with
   out_of_line = True
1088
   has_side_effects = True
1089
1090
1091

primop  ReadMutVarOp "readMutVar#" GenPrimOp
   MutVar# s a -> State# s -> (# State# s, a #)
1092