2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[PrimOp]{Primitive operations (machine-level)}
8 PrimOp(..), allThePrimOps,
9 tagOf_PrimOp, -- ToDo: rm
11 primOpUniq, primOpOcc,
15 primOpOutOfLine, primOpNeedsWrapper, primOpStrictness,
16 primOpOkForSpeculation, primOpIsCheap,
19 getPrimOpResultInfo, PrimOpResultInfo(..),
24 #include "HsVersions.h"
26 import PrimRep -- most of it
30 import Demand ( Demand, wwLazy, wwPrim, wwStrict )
32 import CallConv ( CallConv, pprCallConv )
33 import PprType ( pprParendType )
34 import OccName ( OccName, pprOccName, mkSrcVarOcc )
35 import TyCon ( TyCon, tyConArity )
36 import Type ( mkForAllTys, mkForAllTy, mkFunTy, mkFunTys, mkTyVarTys,
37 mkTyConTy, mkTyConApp, typePrimRep,
38 splitAlgTyConApp, Type, isUnboxedTupleType,
39 splitAlgTyConApp_maybe
41 import Unique ( Unique, mkPrimOpIdUnique )
44 import GlaExts ( Int(..), Int#, (==#) )
47 %************************************************************************
49 \subsection[PrimOp-datatype]{Datatype for @PrimOp@ (an enumeration)}
51 %************************************************************************
53 These are in \tr{state-interface.verb} order.
57 -- dig the FORTRAN/C influence on the names...
61 = CharGtOp | CharGeOp | CharEqOp | CharNeOp | CharLtOp | CharLeOp
62 | IntGtOp | IntGeOp | IntEqOp | IntNeOp | IntLtOp | IntLeOp
63 | WordGtOp | WordGeOp | WordEqOp | WordNeOp | WordLtOp | WordLeOp
64 | AddrGtOp | AddrGeOp | AddrEqOp | AddrNeOp | AddrLtOp | AddrLeOp
65 | FloatGtOp | FloatGeOp | FloatEqOp | FloatNeOp | FloatLtOp | FloatLeOp
66 | DoubleGtOp | DoubleGeOp | DoubleEqOp | DoubleNeOp | DoubleLtOp | DoubleLeOp
72 -- IntAbsOp unused?? ADR
73 | IntAddOp | IntSubOp | IntMulOp | IntQuotOp
74 | IntRemOp | IntNegOp | IntAbsOp
75 | ISllOp | ISraOp | ISrlOp -- shift {left,right} {arithmetic,logical}
81 | WordQuotOp | WordRemOp
82 | AndOp | OrOp | NotOp | XorOp
83 | SllOp | SrlOp -- shift {left,right} {logical}
84 | Int2WordOp | Word2IntOp -- casts
87 | Int2AddrOp | Addr2IntOp -- casts
89 -- Float#-related ops:
90 | FloatAddOp | FloatSubOp | FloatMulOp | FloatDivOp | FloatNegOp
91 | Float2IntOp | Int2FloatOp
93 | FloatExpOp | FloatLogOp | FloatSqrtOp
94 | FloatSinOp | FloatCosOp | FloatTanOp
95 | FloatAsinOp | FloatAcosOp | FloatAtanOp
96 | FloatSinhOp | FloatCoshOp | FloatTanhOp
97 -- not all machines have these available conveniently:
98 -- | FloatAsinhOp | FloatAcoshOp | FloatAtanhOp
99 | FloatPowerOp -- ** op
101 -- Double#-related ops:
102 | DoubleAddOp | DoubleSubOp | DoubleMulOp | DoubleDivOp | DoubleNegOp
103 | Double2IntOp | Int2DoubleOp
104 | Double2FloatOp | Float2DoubleOp
106 | DoubleExpOp | DoubleLogOp | DoubleSqrtOp
107 | DoubleSinOp | DoubleCosOp | DoubleTanOp
108 | DoubleAsinOp | DoubleAcosOp | DoubleAtanOp
109 | DoubleSinhOp | DoubleCoshOp | DoubleTanhOp
110 -- not all machines have these available conveniently:
111 -- | DoubleAsinhOp | DoubleAcoshOp | DoubleAtanhOp
112 | DoublePowerOp -- ** op
114 -- Integer (and related...) ops:
115 -- slightly weird -- to match GMP package.
116 | IntegerAddOp | IntegerSubOp | IntegerMulOp | IntegerGcdOp
117 | IntegerQuotRemOp | IntegerDivModOp | IntegerNegOp
122 | Integer2IntOp | Integer2WordOp
123 | Int2IntegerOp | Word2IntegerOp
125 -- casting to/from Integer and 64-bit (un)signed quantities.
126 | IntegerToInt64Op | Int64ToIntegerOp
127 | IntegerToWord64Op | Word64ToIntegerOp
133 -- primitive ops for primitive arrays
136 | NewByteArrayOp PrimRep
139 | SameMutableByteArrayOp
141 | ReadArrayOp | WriteArrayOp | IndexArrayOp -- for arrays of Haskell ptrs
143 | ReadByteArrayOp PrimRep
144 | WriteByteArrayOp PrimRep
145 | IndexByteArrayOp PrimRep
146 | IndexOffAddrOp PrimRep
147 | WriteOffAddrOp PrimRep
148 -- PrimRep can be one of {Char,Int,Addr,Float,Double}Kind.
149 -- This is just a cheesy encoding of a bunch of ops.
150 -- Note that ForeignObjRep is not included -- the only way of
151 -- creating a ForeignObj is with a ccall or casm.
152 | IndexOffForeignObjOp PrimRep
154 | UnsafeFreezeArrayOp | UnsafeFreezeByteArrayOp
155 | UnsafeThawArrayOp | UnsafeThawByteArrayOp
156 | SizeofByteArrayOp | SizeofMutableByteArrayOp
191 A special ``trap-door'' to use in making calls direct to C functions:
194 FAST_STRING -- Left fn => An "unboxed" ccall# to `fn'.
195 Unique) -- Right u => first argument (an Addr#) is the function pointer
196 -- (unique is used to generate a 'typedef' to cast
197 -- the function pointer if compiling the ccall# down to
198 -- .hc code - can't do this inline for tedious reasons.)
200 Bool -- True <=> really a "casm"
201 Bool -- True <=> might invoke Haskell GC
202 CallConv -- calling convention to use.
204 -- (... to be continued ... )
207 The ``type'' of @CCallOp foo [t1, ... tm] r@ is @t1 -> ... tm -> r@.
208 (See @primOpInfo@ for details.)
210 Note: that first arg and part of the result should be the system state
211 token (which we carry around to fool over-zealous optimisers) but
212 which isn't actually passed.
214 For example, we represent
216 ((ccall# foo [StablePtr# a, Int] Float) sp# i#) :: (Float, IoWorld)
222 (CCallOp "foo" [Universe#, StablePtr# a, Int#] FloatPrimAndUniverse False)
223 -- :: Universe# -> StablePtr# a -> Int# -> FloatPrimAndUniverse
227 (AlgAlts [ ( FloatPrimAndIoWorld,
229 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
235 Nota Bene: there are some people who find the empty list of types in
236 the @Prim@ somewhat puzzling and would represent the above by
240 (CCallOp "foo" [alpha1, alpha2, alpha3] alpha4 False)
241 -- :: /\ alpha1, alpha2 alpha3, alpha4.
242 -- alpha1 -> alpha2 -> alpha3 -> alpha4
243 [Universe#, StablePtr# a, Int#, FloatPrimAndIoWorld]
246 (AlgAlts [ ( FloatPrimAndIoWorld,
248 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
254 But, this is a completely different way of using @CCallOp@. The most
255 major changes required if we switch to this are in @primOpInfo@, and
256 the desugarer. The major difficulty is in moving the HeapRequirement
257 stuff somewhere appropriate. (The advantage is that we could simplify
258 @CCallOp@ and record just the number of arguments with corresponding
259 simplifications in reading pragma unfoldings, the simplifier,
260 instantiation (etc) of core expressions, ... . Maybe we should think
261 about using it this way?? ADR)
264 -- (... continued from above ... )
266 -- Operation to test two closure addresses for equality (yes really!)
267 -- BLAME ALASTAIR REID FOR THIS! THE REST OF US ARE INNOCENT!
268 | ReallyUnsafePtrEqualityOp
281 | ParGlobalOp -- named global par
282 | ParLocalOp -- named local par
283 | ParAtOp -- specifies destination of local par
284 | ParAtAbsOp -- specifies destination of local par (abs processor)
285 | ParAtRelOp -- specifies destination of local par (rel processor)
286 | ParAtForNowOp -- specifies initial destination of global par
287 | CopyableOp -- marks copyable code
288 | NoFollowOp -- marks non-followup expression
291 Used for the Ord instance
294 tagOf_PrimOp CharGtOp = (ILIT( 1) :: FAST_INT)
295 tagOf_PrimOp CharGeOp = ILIT( 2)
296 tagOf_PrimOp CharEqOp = ILIT( 3)
297 tagOf_PrimOp CharNeOp = ILIT( 4)
298 tagOf_PrimOp CharLtOp = ILIT( 5)
299 tagOf_PrimOp CharLeOp = ILIT( 6)
300 tagOf_PrimOp IntGtOp = ILIT( 7)
301 tagOf_PrimOp IntGeOp = ILIT( 8)
302 tagOf_PrimOp IntEqOp = ILIT( 9)
303 tagOf_PrimOp IntNeOp = ILIT( 10)
304 tagOf_PrimOp IntLtOp = ILIT( 11)
305 tagOf_PrimOp IntLeOp = ILIT( 12)
306 tagOf_PrimOp WordGtOp = ILIT( 13)
307 tagOf_PrimOp WordGeOp = ILIT( 14)
308 tagOf_PrimOp WordEqOp = ILIT( 15)
309 tagOf_PrimOp WordNeOp = ILIT( 16)
310 tagOf_PrimOp WordLtOp = ILIT( 17)
311 tagOf_PrimOp WordLeOp = ILIT( 18)
312 tagOf_PrimOp AddrGtOp = ILIT( 19)
313 tagOf_PrimOp AddrGeOp = ILIT( 20)
314 tagOf_PrimOp AddrEqOp = ILIT( 21)
315 tagOf_PrimOp AddrNeOp = ILIT( 22)
316 tagOf_PrimOp AddrLtOp = ILIT( 23)
317 tagOf_PrimOp AddrLeOp = ILIT( 24)
318 tagOf_PrimOp FloatGtOp = ILIT( 25)
319 tagOf_PrimOp FloatGeOp = ILIT( 26)
320 tagOf_PrimOp FloatEqOp = ILIT( 27)
321 tagOf_PrimOp FloatNeOp = ILIT( 28)
322 tagOf_PrimOp FloatLtOp = ILIT( 29)
323 tagOf_PrimOp FloatLeOp = ILIT( 30)
324 tagOf_PrimOp DoubleGtOp = ILIT( 31)
325 tagOf_PrimOp DoubleGeOp = ILIT( 32)
326 tagOf_PrimOp DoubleEqOp = ILIT( 33)
327 tagOf_PrimOp DoubleNeOp = ILIT( 34)
328 tagOf_PrimOp DoubleLtOp = ILIT( 35)
329 tagOf_PrimOp DoubleLeOp = ILIT( 36)
330 tagOf_PrimOp OrdOp = ILIT( 37)
331 tagOf_PrimOp ChrOp = ILIT( 38)
332 tagOf_PrimOp IntAddOp = ILIT( 39)
333 tagOf_PrimOp IntSubOp = ILIT( 40)
334 tagOf_PrimOp IntMulOp = ILIT( 41)
335 tagOf_PrimOp IntQuotOp = ILIT( 42)
336 tagOf_PrimOp IntRemOp = ILIT( 43)
337 tagOf_PrimOp IntNegOp = ILIT( 44)
338 tagOf_PrimOp IntAbsOp = ILIT( 45)
339 tagOf_PrimOp WordQuotOp = ILIT( 46)
340 tagOf_PrimOp WordRemOp = ILIT( 47)
341 tagOf_PrimOp AndOp = ILIT( 48)
342 tagOf_PrimOp OrOp = ILIT( 49)
343 tagOf_PrimOp NotOp = ILIT( 50)
344 tagOf_PrimOp XorOp = ILIT( 51)
345 tagOf_PrimOp SllOp = ILIT( 52)
346 tagOf_PrimOp SrlOp = ILIT( 53)
347 tagOf_PrimOp ISllOp = ILIT( 54)
348 tagOf_PrimOp ISraOp = ILIT( 55)
349 tagOf_PrimOp ISrlOp = ILIT( 56)
350 tagOf_PrimOp IntAddCOp = ILIT( 57)
351 tagOf_PrimOp IntSubCOp = ILIT( 58)
352 tagOf_PrimOp IntMulCOp = ILIT( 59)
353 tagOf_PrimOp Int2WordOp = ILIT( 60)
354 tagOf_PrimOp Word2IntOp = ILIT( 61)
355 tagOf_PrimOp Int2AddrOp = ILIT( 62)
356 tagOf_PrimOp Addr2IntOp = ILIT( 63)
358 tagOf_PrimOp FloatAddOp = ILIT( 64)
359 tagOf_PrimOp FloatSubOp = ILIT( 65)
360 tagOf_PrimOp FloatMulOp = ILIT( 66)
361 tagOf_PrimOp FloatDivOp = ILIT( 67)
362 tagOf_PrimOp FloatNegOp = ILIT( 68)
363 tagOf_PrimOp Float2IntOp = ILIT( 69)
364 tagOf_PrimOp Int2FloatOp = ILIT( 70)
365 tagOf_PrimOp FloatExpOp = ILIT( 71)
366 tagOf_PrimOp FloatLogOp = ILIT( 72)
367 tagOf_PrimOp FloatSqrtOp = ILIT( 73)
368 tagOf_PrimOp FloatSinOp = ILIT( 74)
369 tagOf_PrimOp FloatCosOp = ILIT( 75)
370 tagOf_PrimOp FloatTanOp = ILIT( 76)
371 tagOf_PrimOp FloatAsinOp = ILIT( 77)
372 tagOf_PrimOp FloatAcosOp = ILIT( 78)
373 tagOf_PrimOp FloatAtanOp = ILIT( 79)
374 tagOf_PrimOp FloatSinhOp = ILIT( 80)
375 tagOf_PrimOp FloatCoshOp = ILIT( 81)
376 tagOf_PrimOp FloatTanhOp = ILIT( 82)
377 tagOf_PrimOp FloatPowerOp = ILIT( 83)
379 tagOf_PrimOp DoubleAddOp = ILIT( 84)
380 tagOf_PrimOp DoubleSubOp = ILIT( 85)
381 tagOf_PrimOp DoubleMulOp = ILIT( 86)
382 tagOf_PrimOp DoubleDivOp = ILIT( 87)
383 tagOf_PrimOp DoubleNegOp = ILIT( 88)
384 tagOf_PrimOp Double2IntOp = ILIT( 89)
385 tagOf_PrimOp Int2DoubleOp = ILIT( 90)
386 tagOf_PrimOp Double2FloatOp = ILIT( 91)
387 tagOf_PrimOp Float2DoubleOp = ILIT( 92)
388 tagOf_PrimOp DoubleExpOp = ILIT( 93)
389 tagOf_PrimOp DoubleLogOp = ILIT( 94)
390 tagOf_PrimOp DoubleSqrtOp = ILIT( 95)
391 tagOf_PrimOp DoubleSinOp = ILIT( 96)
392 tagOf_PrimOp DoubleCosOp = ILIT( 97)
393 tagOf_PrimOp DoubleTanOp = ILIT( 98)
394 tagOf_PrimOp DoubleAsinOp = ILIT( 99)
395 tagOf_PrimOp DoubleAcosOp = ILIT(100)
396 tagOf_PrimOp DoubleAtanOp = ILIT(101)
397 tagOf_PrimOp DoubleSinhOp = ILIT(102)
398 tagOf_PrimOp DoubleCoshOp = ILIT(103)
399 tagOf_PrimOp DoubleTanhOp = ILIT(104)
400 tagOf_PrimOp DoublePowerOp = ILIT(105)
402 tagOf_PrimOp IntegerAddOp = ILIT(106)
403 tagOf_PrimOp IntegerSubOp = ILIT(107)
404 tagOf_PrimOp IntegerMulOp = ILIT(108)
405 tagOf_PrimOp IntegerGcdOp = ILIT(109)
406 tagOf_PrimOp IntegerQuotRemOp = ILIT(110)
407 tagOf_PrimOp IntegerDivModOp = ILIT(111)
408 tagOf_PrimOp IntegerNegOp = ILIT(112)
409 tagOf_PrimOp IntegerCmpOp = ILIT(113)
410 tagOf_PrimOp IntegerCmpIntOp = ILIT(114)
411 tagOf_PrimOp Integer2IntOp = ILIT(115)
412 tagOf_PrimOp Integer2WordOp = ILIT(116)
413 tagOf_PrimOp Int2IntegerOp = ILIT(117)
414 tagOf_PrimOp Word2IntegerOp = ILIT(118)
415 tagOf_PrimOp Addr2IntegerOp = ILIT(119)
416 tagOf_PrimOp IntegerToInt64Op = ILIT(120)
417 tagOf_PrimOp Int64ToIntegerOp = ILIT(121)
418 tagOf_PrimOp IntegerToWord64Op = ILIT(122)
419 tagOf_PrimOp Word64ToIntegerOp = ILIT(123)
420 tagOf_PrimOp FloatDecodeOp = ILIT(125)
421 tagOf_PrimOp DoubleDecodeOp = ILIT(127)
423 tagOf_PrimOp NewArrayOp = ILIT(128)
424 tagOf_PrimOp (NewByteArrayOp CharRep) = ILIT(129)
425 tagOf_PrimOp (NewByteArrayOp IntRep) = ILIT(130)
426 tagOf_PrimOp (NewByteArrayOp WordRep) = ILIT(131)
427 tagOf_PrimOp (NewByteArrayOp AddrRep) = ILIT(132)
428 tagOf_PrimOp (NewByteArrayOp FloatRep) = ILIT(133)
429 tagOf_PrimOp (NewByteArrayOp DoubleRep) = ILIT(134)
430 tagOf_PrimOp (NewByteArrayOp StablePtrRep) = ILIT(135)
432 tagOf_PrimOp SameMutableArrayOp = ILIT(136)
433 tagOf_PrimOp SameMutableByteArrayOp = ILIT(137)
434 tagOf_PrimOp ReadArrayOp = ILIT(138)
435 tagOf_PrimOp WriteArrayOp = ILIT(139)
436 tagOf_PrimOp IndexArrayOp = ILIT(140)
438 tagOf_PrimOp (ReadByteArrayOp CharRep) = ILIT(141)
439 tagOf_PrimOp (ReadByteArrayOp IntRep) = ILIT(142)
440 tagOf_PrimOp (ReadByteArrayOp WordRep) = ILIT(143)
441 tagOf_PrimOp (ReadByteArrayOp AddrRep) = ILIT(144)
442 tagOf_PrimOp (ReadByteArrayOp FloatRep) = ILIT(145)
443 tagOf_PrimOp (ReadByteArrayOp DoubleRep) = ILIT(146)
444 tagOf_PrimOp (ReadByteArrayOp StablePtrRep) = ILIT(147)
445 tagOf_PrimOp (ReadByteArrayOp Int64Rep) = ILIT(148)
446 tagOf_PrimOp (ReadByteArrayOp Word64Rep) = ILIT(149)
448 tagOf_PrimOp (WriteByteArrayOp CharRep) = ILIT(150)
449 tagOf_PrimOp (WriteByteArrayOp IntRep) = ILIT(151)
450 tagOf_PrimOp (WriteByteArrayOp WordRep) = ILIT(152)
451 tagOf_PrimOp (WriteByteArrayOp AddrRep) = ILIT(153)
452 tagOf_PrimOp (WriteByteArrayOp FloatRep) = ILIT(154)
453 tagOf_PrimOp (WriteByteArrayOp DoubleRep) = ILIT(155)
454 tagOf_PrimOp (WriteByteArrayOp StablePtrRep) = ILIT(156)
455 tagOf_PrimOp (WriteByteArrayOp Int64Rep) = ILIT(157)
456 tagOf_PrimOp (WriteByteArrayOp Word64Rep) = ILIT(158)
458 tagOf_PrimOp (IndexByteArrayOp CharRep) = ILIT(159)
459 tagOf_PrimOp (IndexByteArrayOp IntRep) = ILIT(160)
460 tagOf_PrimOp (IndexByteArrayOp WordRep) = ILIT(161)
461 tagOf_PrimOp (IndexByteArrayOp AddrRep) = ILIT(162)
462 tagOf_PrimOp (IndexByteArrayOp FloatRep) = ILIT(163)
463 tagOf_PrimOp (IndexByteArrayOp DoubleRep) = ILIT(164)
464 tagOf_PrimOp (IndexByteArrayOp StablePtrRep) = ILIT(165)
465 tagOf_PrimOp (IndexByteArrayOp Int64Rep) = ILIT(166)
466 tagOf_PrimOp (IndexByteArrayOp Word64Rep) = ILIT(167)
468 tagOf_PrimOp (IndexOffAddrOp CharRep) = ILIT(168)
469 tagOf_PrimOp (IndexOffAddrOp IntRep) = ILIT(169)
470 tagOf_PrimOp (IndexOffAddrOp WordRep) = ILIT(170)
471 tagOf_PrimOp (IndexOffAddrOp AddrRep) = ILIT(171)
472 tagOf_PrimOp (IndexOffAddrOp FloatRep) = ILIT(172)
473 tagOf_PrimOp (IndexOffAddrOp DoubleRep) = ILIT(173)
474 tagOf_PrimOp (IndexOffAddrOp StablePtrRep) = ILIT(174)
475 tagOf_PrimOp (IndexOffAddrOp Int64Rep) = ILIT(175)
476 tagOf_PrimOp (IndexOffAddrOp Word64Rep) = ILIT(176)
478 tagOf_PrimOp (IndexOffForeignObjOp CharRep) = ILIT(177)
479 tagOf_PrimOp (IndexOffForeignObjOp IntRep) = ILIT(178)
480 tagOf_PrimOp (IndexOffForeignObjOp WordRep) = ILIT(179)
481 tagOf_PrimOp (IndexOffForeignObjOp AddrRep) = ILIT(180)
482 tagOf_PrimOp (IndexOffForeignObjOp FloatRep) = ILIT(181)
483 tagOf_PrimOp (IndexOffForeignObjOp DoubleRep) = ILIT(182)
484 tagOf_PrimOp (IndexOffForeignObjOp StablePtrRep) = ILIT(183)
485 tagOf_PrimOp (IndexOffForeignObjOp Int64Rep) = ILIT(184)
486 tagOf_PrimOp (IndexOffForeignObjOp Word64Rep) = ILIT(185)
488 tagOf_PrimOp (WriteOffAddrOp CharRep) = ILIT(186)
489 tagOf_PrimOp (WriteOffAddrOp IntRep) = ILIT(187)
490 tagOf_PrimOp (WriteOffAddrOp WordRep) = ILIT(188)
491 tagOf_PrimOp (WriteOffAddrOp AddrRep) = ILIT(189)
492 tagOf_PrimOp (WriteOffAddrOp FloatRep) = ILIT(190)
493 tagOf_PrimOp (WriteOffAddrOp DoubleRep) = ILIT(191)
494 tagOf_PrimOp (WriteOffAddrOp StablePtrRep) = ILIT(192)
495 tagOf_PrimOp (WriteOffAddrOp ForeignObjRep) = ILIT(193)
496 tagOf_PrimOp (WriteOffAddrOp Int64Rep) = ILIT(194)
497 tagOf_PrimOp (WriteOffAddrOp Word64Rep) = ILIT(195)
499 tagOf_PrimOp UnsafeFreezeArrayOp = ILIT(196)
500 tagOf_PrimOp UnsafeFreezeByteArrayOp = ILIT(197)
501 tagOf_PrimOp UnsafeThawArrayOp = ILIT(198)
502 tagOf_PrimOp UnsafeThawByteArrayOp = ILIT(199)
503 tagOf_PrimOp SizeofByteArrayOp = ILIT(200)
504 tagOf_PrimOp SizeofMutableByteArrayOp = ILIT(201)
506 tagOf_PrimOp NewMVarOp = ILIT(202)
507 tagOf_PrimOp TakeMVarOp = ILIT(203)
508 tagOf_PrimOp PutMVarOp = ILIT(204)
509 tagOf_PrimOp SameMVarOp = ILIT(205)
510 tagOf_PrimOp IsEmptyMVarOp = ILIT(206)
511 tagOf_PrimOp MakeForeignObjOp = ILIT(207)
512 tagOf_PrimOp WriteForeignObjOp = ILIT(208)
513 tagOf_PrimOp MkWeakOp = ILIT(209)
514 tagOf_PrimOp DeRefWeakOp = ILIT(210)
515 tagOf_PrimOp FinalizeWeakOp = ILIT(211)
516 tagOf_PrimOp MakeStableNameOp = ILIT(212)
517 tagOf_PrimOp EqStableNameOp = ILIT(213)
518 tagOf_PrimOp StableNameToIntOp = ILIT(214)
519 tagOf_PrimOp MakeStablePtrOp = ILIT(215)
520 tagOf_PrimOp DeRefStablePtrOp = ILIT(216)
521 tagOf_PrimOp EqStablePtrOp = ILIT(217)
522 tagOf_PrimOp (CCallOp _ _ _ _) = ILIT(218)
523 tagOf_PrimOp ReallyUnsafePtrEqualityOp = ILIT(219)
524 tagOf_PrimOp SeqOp = ILIT(220)
525 tagOf_PrimOp ParOp = ILIT(221)
526 tagOf_PrimOp ForkOp = ILIT(222)
527 tagOf_PrimOp KillThreadOp = ILIT(223)
528 tagOf_PrimOp DelayOp = ILIT(224)
529 tagOf_PrimOp WaitReadOp = ILIT(225)
530 tagOf_PrimOp WaitWriteOp = ILIT(226)
531 tagOf_PrimOp ParGlobalOp = ILIT(227)
532 tagOf_PrimOp ParLocalOp = ILIT(228)
533 tagOf_PrimOp ParAtOp = ILIT(229)
534 tagOf_PrimOp ParAtAbsOp = ILIT(230)
535 tagOf_PrimOp ParAtRelOp = ILIT(231)
536 tagOf_PrimOp ParAtForNowOp = ILIT(232)
537 tagOf_PrimOp CopyableOp = ILIT(233)
538 tagOf_PrimOp NoFollowOp = ILIT(234)
539 tagOf_PrimOp NewMutVarOp = ILIT(235)
540 tagOf_PrimOp ReadMutVarOp = ILIT(236)
541 tagOf_PrimOp WriteMutVarOp = ILIT(237)
542 tagOf_PrimOp SameMutVarOp = ILIT(238)
543 tagOf_PrimOp CatchOp = ILIT(239)
544 tagOf_PrimOp RaiseOp = ILIT(240)
546 tagOf_PrimOp op = pprPanic# "tagOf_PrimOp: pattern-match" (ppr op)
547 --panic# "tagOf_PrimOp: pattern-match"
549 instance Eq PrimOp where
550 op1 == op2 = tagOf_PrimOp op1 _EQ_ tagOf_PrimOp op2
552 instance Ord PrimOp where
553 op1 < op2 = tagOf_PrimOp op1 _LT_ tagOf_PrimOp op2
554 op1 <= op2 = tagOf_PrimOp op1 _LE_ tagOf_PrimOp op2
555 op1 >= op2 = tagOf_PrimOp op1 _GE_ tagOf_PrimOp op2
556 op1 > op2 = tagOf_PrimOp op1 _GT_ tagOf_PrimOp op2
557 op1 `compare` op2 | op1 < op2 = LT
561 instance Outputable PrimOp where
562 ppr op = pprPrimOp op
564 instance Show PrimOp where
565 showsPrec p op = showsPrecSDoc p (pprPrimOp op)
568 An @Enum@-derived list would be better; meanwhile... (ToDo)
697 NewByteArrayOp CharRep,
698 NewByteArrayOp IntRep,
699 NewByteArrayOp WordRep,
700 NewByteArrayOp AddrRep,
701 NewByteArrayOp FloatRep,
702 NewByteArrayOp DoubleRep,
703 NewByteArrayOp StablePtrRep,
705 SameMutableByteArrayOp,
709 ReadByteArrayOp CharRep,
710 ReadByteArrayOp IntRep,
711 ReadByteArrayOp WordRep,
712 ReadByteArrayOp AddrRep,
713 ReadByteArrayOp FloatRep,
714 ReadByteArrayOp DoubleRep,
715 ReadByteArrayOp StablePtrRep,
716 ReadByteArrayOp Int64Rep,
717 ReadByteArrayOp Word64Rep,
718 WriteByteArrayOp CharRep,
719 WriteByteArrayOp IntRep,
720 WriteByteArrayOp WordRep,
721 WriteByteArrayOp AddrRep,
722 WriteByteArrayOp FloatRep,
723 WriteByteArrayOp DoubleRep,
724 WriteByteArrayOp StablePtrRep,
725 WriteByteArrayOp Int64Rep,
726 WriteByteArrayOp Word64Rep,
727 IndexByteArrayOp CharRep,
728 IndexByteArrayOp IntRep,
729 IndexByteArrayOp WordRep,
730 IndexByteArrayOp AddrRep,
731 IndexByteArrayOp FloatRep,
732 IndexByteArrayOp DoubleRep,
733 IndexByteArrayOp StablePtrRep,
734 IndexByteArrayOp Int64Rep,
735 IndexByteArrayOp Word64Rep,
736 IndexOffForeignObjOp CharRep,
737 IndexOffForeignObjOp AddrRep,
738 IndexOffForeignObjOp IntRep,
739 IndexOffForeignObjOp WordRep,
740 IndexOffForeignObjOp FloatRep,
741 IndexOffForeignObjOp DoubleRep,
742 IndexOffForeignObjOp StablePtrRep,
743 IndexOffForeignObjOp Int64Rep,
744 IndexOffForeignObjOp Word64Rep,
745 IndexOffAddrOp CharRep,
746 IndexOffAddrOp IntRep,
747 IndexOffAddrOp WordRep,
748 IndexOffAddrOp AddrRep,
749 IndexOffAddrOp FloatRep,
750 IndexOffAddrOp DoubleRep,
751 IndexOffAddrOp StablePtrRep,
752 IndexOffAddrOp Int64Rep,
753 IndexOffAddrOp Word64Rep,
754 WriteOffAddrOp CharRep,
755 WriteOffAddrOp IntRep,
756 WriteOffAddrOp WordRep,
757 WriteOffAddrOp AddrRep,
758 WriteOffAddrOp FloatRep,
759 WriteOffAddrOp DoubleRep,
760 WriteOffAddrOp ForeignObjRep,
761 WriteOffAddrOp StablePtrRep,
762 WriteOffAddrOp Int64Rep,
763 WriteOffAddrOp Word64Rep,
765 UnsafeFreezeByteArrayOp,
767 UnsafeThawByteArrayOp,
769 SizeofMutableByteArrayOp,
792 ReallyUnsafePtrEqualityOp,
811 %************************************************************************
813 \subsection[PrimOp-info]{The essential info about each @PrimOp@}
815 %************************************************************************
817 The @String@ in the @PrimOpInfos@ is the ``base name'' by which the user may
818 refer to the primitive operation. The conventional \tr{#}-for-
819 unboxed ops is added on later.
821 The reason for the funny characters in the names is so we do not
822 interfere with the programmer's Haskell name spaces.
824 We use @PrimKinds@ for the ``type'' information, because they're
825 (slightly) more convenient to use than @TyCons@.
828 = Dyadic OccName -- string :: T -> T -> T
830 | Monadic OccName -- string :: T -> T
832 | Compare OccName -- string :: T -> T -> Bool
835 | GenPrimOp OccName -- string :: \/a1..an . T1 -> .. -> Tk -> T
840 mkDyadic str ty = Dyadic (mkSrcVarOcc str) ty
841 mkMonadic str ty = Monadic (mkSrcVarOcc str) ty
842 mkCompare str ty = Compare (mkSrcVarOcc str) ty
843 mkGenPrimOp str tvs tys ty = GenPrimOp (mkSrcVarOcc str) tvs tys ty
848 one_Integer_ty = [intPrimTy, byteArrayPrimTy]
850 = [intPrimTy, byteArrayPrimTy, -- first Integer pieces
851 intPrimTy, byteArrayPrimTy] -- second '' pieces
852 an_Integer_and_Int_tys
853 = [intPrimTy, byteArrayPrimTy, -- Integer
856 unboxedPair = mkUnboxedTupleTy 2
857 unboxedTriple = mkUnboxedTupleTy 3
858 unboxedQuadruple = mkUnboxedTupleTy 4
860 integerMonadic name = mkGenPrimOp name [] one_Integer_ty
861 (unboxedPair one_Integer_ty)
863 integerDyadic name = mkGenPrimOp name [] two_Integer_tys
864 (unboxedPair one_Integer_ty)
866 integerDyadic2Results name = mkGenPrimOp name [] two_Integer_tys
867 (unboxedQuadruple two_Integer_tys)
869 integerCompare name = mkGenPrimOp name [] two_Integer_tys intPrimTy
872 %************************************************************************
874 \subsubsection{Strictness}
876 %************************************************************************
878 Not all primops are strict!
881 primOpStrictness :: PrimOp -> ([Demand], Bool)
882 -- See IdInfo.StrictnessInfo for discussion of what the results
883 -- **NB** as a cheap hack, to avoid having to look up the PrimOp's arity,
884 -- the list of demands may be infinite!
885 -- Use only the ones you ned.
887 primOpStrictness SeqOp = ([wwLazy], False)
888 primOpStrictness ParOp = ([wwLazy], False)
889 primOpStrictness ForkOp = ([wwLazy, wwPrim], False)
891 primOpStrictness NewArrayOp = ([wwPrim, wwLazy, wwPrim], False)
892 primOpStrictness WriteArrayOp = ([wwPrim, wwPrim, wwLazy, wwPrim], False)
894 primOpStrictness NewMutVarOp = ([wwLazy, wwPrim], False)
895 primOpStrictness WriteMutVarOp = ([wwPrim, wwLazy, wwPrim], False)
897 primOpStrictness PutMVarOp = ([wwPrim, wwLazy, wwPrim], False)
899 primOpStrictness CatchOp = ([wwLazy, wwLazy], False)
900 primOpStrictness RaiseOp = ([wwLazy], True) -- NB: True => result is bottom
902 primOpStrictness MkWeakOp = ([wwLazy, wwLazy, wwLazy, wwPrim], False)
903 primOpStrictness MakeStableNameOp = ([wwLazy, wwPrim], False)
904 primOpStrictness MakeStablePtrOp = ([wwLazy, wwPrim], False)
906 -- The rest all have primitive-typed arguments
907 primOpStrictness other = (repeat wwPrim, False)
910 %************************************************************************
912 \subsubsection[PrimOp-comparison]{PrimOpInfo basic comparison ops}
914 %************************************************************************
916 @primOpInfo@ gives all essential information (from which everything
917 else, notably a type, can be constructed) for each @PrimOp@.
920 primOpInfo :: PrimOp -> PrimOpInfo
923 There's plenty of this stuff!
926 primOpInfo CharGtOp = mkCompare SLIT("gtChar#") charPrimTy
927 primOpInfo CharGeOp = mkCompare SLIT("geChar#") charPrimTy
928 primOpInfo CharEqOp = mkCompare SLIT("eqChar#") charPrimTy
929 primOpInfo CharNeOp = mkCompare SLIT("neChar#") charPrimTy
930 primOpInfo CharLtOp = mkCompare SLIT("ltChar#") charPrimTy
931 primOpInfo CharLeOp = mkCompare SLIT("leChar#") charPrimTy
933 primOpInfo IntGtOp = mkCompare SLIT(">#") intPrimTy
934 primOpInfo IntGeOp = mkCompare SLIT(">=#") intPrimTy
935 primOpInfo IntEqOp = mkCompare SLIT("==#") intPrimTy
936 primOpInfo IntNeOp = mkCompare SLIT("/=#") intPrimTy
937 primOpInfo IntLtOp = mkCompare SLIT("<#") intPrimTy
938 primOpInfo IntLeOp = mkCompare SLIT("<=#") intPrimTy
940 primOpInfo WordGtOp = mkCompare SLIT("gtWord#") wordPrimTy
941 primOpInfo WordGeOp = mkCompare SLIT("geWord#") wordPrimTy
942 primOpInfo WordEqOp = mkCompare SLIT("eqWord#") wordPrimTy
943 primOpInfo WordNeOp = mkCompare SLIT("neWord#") wordPrimTy
944 primOpInfo WordLtOp = mkCompare SLIT("ltWord#") wordPrimTy
945 primOpInfo WordLeOp = mkCompare SLIT("leWord#") wordPrimTy
947 primOpInfo AddrGtOp = mkCompare SLIT("gtAddr#") addrPrimTy
948 primOpInfo AddrGeOp = mkCompare SLIT("geAddr#") addrPrimTy
949 primOpInfo AddrEqOp = mkCompare SLIT("eqAddr#") addrPrimTy
950 primOpInfo AddrNeOp = mkCompare SLIT("neAddr#") addrPrimTy
951 primOpInfo AddrLtOp = mkCompare SLIT("ltAddr#") addrPrimTy
952 primOpInfo AddrLeOp = mkCompare SLIT("leAddr#") addrPrimTy
954 primOpInfo FloatGtOp = mkCompare SLIT("gtFloat#") floatPrimTy
955 primOpInfo FloatGeOp = mkCompare SLIT("geFloat#") floatPrimTy
956 primOpInfo FloatEqOp = mkCompare SLIT("eqFloat#") floatPrimTy
957 primOpInfo FloatNeOp = mkCompare SLIT("neFloat#") floatPrimTy
958 primOpInfo FloatLtOp = mkCompare SLIT("ltFloat#") floatPrimTy
959 primOpInfo FloatLeOp = mkCompare SLIT("leFloat#") floatPrimTy
961 primOpInfo DoubleGtOp = mkCompare SLIT(">##") doublePrimTy
962 primOpInfo DoubleGeOp = mkCompare SLIT(">=##") doublePrimTy
963 primOpInfo DoubleEqOp = mkCompare SLIT("==##") doublePrimTy
964 primOpInfo DoubleNeOp = mkCompare SLIT("/=##") doublePrimTy
965 primOpInfo DoubleLtOp = mkCompare SLIT("<##") doublePrimTy
966 primOpInfo DoubleLeOp = mkCompare SLIT("<=##") doublePrimTy
970 %************************************************************************
972 \subsubsection[PrimOp-Char]{PrimOpInfo for @Char#@s}
974 %************************************************************************
977 primOpInfo OrdOp = mkGenPrimOp SLIT("ord#") [] [charPrimTy] intPrimTy
978 primOpInfo ChrOp = mkGenPrimOp SLIT("chr#") [] [intPrimTy] charPrimTy
981 %************************************************************************
983 \subsubsection[PrimOp-Int]{PrimOpInfo for @Int#@s}
985 %************************************************************************
988 primOpInfo IntAddOp = mkDyadic SLIT("+#") intPrimTy
989 primOpInfo IntSubOp = mkDyadic SLIT("-#") intPrimTy
990 primOpInfo IntMulOp = mkDyadic SLIT("*#") intPrimTy
991 primOpInfo IntQuotOp = mkDyadic SLIT("quotInt#") intPrimTy
992 primOpInfo IntRemOp = mkDyadic SLIT("remInt#") intPrimTy
994 primOpInfo IntNegOp = mkMonadic SLIT("negateInt#") intPrimTy
995 primOpInfo IntAbsOp = mkMonadic SLIT("absInt#") intPrimTy
997 primOpInfo IntAddCOp =
998 mkGenPrimOp SLIT("addIntC#") [] [intPrimTy, intPrimTy]
999 (unboxedPair [intPrimTy, intPrimTy])
1001 primOpInfo IntSubCOp =
1002 mkGenPrimOp SLIT("subIntC#") [] [intPrimTy, intPrimTy]
1003 (unboxedPair [intPrimTy, intPrimTy])
1005 primOpInfo IntMulCOp =
1006 mkGenPrimOp SLIT("mulIntC#") [] [intPrimTy, intPrimTy]
1007 (unboxedPair [intPrimTy, intPrimTy])
1010 %************************************************************************
1012 \subsubsection[PrimOp-Word]{PrimOpInfo for @Word#@s}
1014 %************************************************************************
1016 A @Word#@ is an unsigned @Int#@.
1019 primOpInfo WordQuotOp = mkDyadic SLIT("quotWord#") wordPrimTy
1020 primOpInfo WordRemOp = mkDyadic SLIT("remWord#") wordPrimTy
1022 primOpInfo AndOp = mkDyadic SLIT("and#") wordPrimTy
1023 primOpInfo OrOp = mkDyadic SLIT("or#") wordPrimTy
1024 primOpInfo XorOp = mkDyadic SLIT("xor#") wordPrimTy
1025 primOpInfo NotOp = mkMonadic SLIT("not#") wordPrimTy
1028 = mkGenPrimOp SLIT("shiftL#") [] [wordPrimTy, intPrimTy] wordPrimTy
1030 = mkGenPrimOp SLIT("shiftRL#") [] [wordPrimTy, intPrimTy] wordPrimTy
1033 = mkGenPrimOp SLIT("iShiftL#") [] [intPrimTy, intPrimTy] intPrimTy
1035 = mkGenPrimOp SLIT("iShiftRA#") [] [intPrimTy, intPrimTy] intPrimTy
1037 = mkGenPrimOp SLIT("iShiftRL#") [] [intPrimTy, intPrimTy] intPrimTy
1039 primOpInfo Int2WordOp = mkGenPrimOp SLIT("int2Word#") [] [intPrimTy] wordPrimTy
1040 primOpInfo Word2IntOp = mkGenPrimOp SLIT("word2Int#") [] [wordPrimTy] intPrimTy
1043 %************************************************************************
1045 \subsubsection[PrimOp-Addr]{PrimOpInfo for @Addr#@s}
1047 %************************************************************************
1050 primOpInfo Int2AddrOp = mkGenPrimOp SLIT("int2Addr#") [] [intPrimTy] addrPrimTy
1051 primOpInfo Addr2IntOp = mkGenPrimOp SLIT("addr2Int#") [] [addrPrimTy] intPrimTy
1055 %************************************************************************
1057 \subsubsection[PrimOp-Float]{PrimOpInfo for @Float#@s}
1059 %************************************************************************
1061 @decodeFloat#@ is given w/ Integer-stuff (it's similar).
1064 primOpInfo FloatAddOp = mkDyadic SLIT("plusFloat#") floatPrimTy
1065 primOpInfo FloatSubOp = mkDyadic SLIT("minusFloat#") floatPrimTy
1066 primOpInfo FloatMulOp = mkDyadic SLIT("timesFloat#") floatPrimTy
1067 primOpInfo FloatDivOp = mkDyadic SLIT("divideFloat#") floatPrimTy
1068 primOpInfo FloatNegOp = mkMonadic SLIT("negateFloat#") floatPrimTy
1070 primOpInfo Float2IntOp = mkGenPrimOp SLIT("float2Int#") [] [floatPrimTy] intPrimTy
1071 primOpInfo Int2FloatOp = mkGenPrimOp SLIT("int2Float#") [] [intPrimTy] floatPrimTy
1073 primOpInfo FloatExpOp = mkMonadic SLIT("expFloat#") floatPrimTy
1074 primOpInfo FloatLogOp = mkMonadic SLIT("logFloat#") floatPrimTy
1075 primOpInfo FloatSqrtOp = mkMonadic SLIT("sqrtFloat#") floatPrimTy
1076 primOpInfo FloatSinOp = mkMonadic SLIT("sinFloat#") floatPrimTy
1077 primOpInfo FloatCosOp = mkMonadic SLIT("cosFloat#") floatPrimTy
1078 primOpInfo FloatTanOp = mkMonadic SLIT("tanFloat#") floatPrimTy
1079 primOpInfo FloatAsinOp = mkMonadic SLIT("asinFloat#") floatPrimTy
1080 primOpInfo FloatAcosOp = mkMonadic SLIT("acosFloat#") floatPrimTy
1081 primOpInfo FloatAtanOp = mkMonadic SLIT("atanFloat#") floatPrimTy
1082 primOpInfo FloatSinhOp = mkMonadic SLIT("sinhFloat#") floatPrimTy
1083 primOpInfo FloatCoshOp = mkMonadic SLIT("coshFloat#") floatPrimTy
1084 primOpInfo FloatTanhOp = mkMonadic SLIT("tanhFloat#") floatPrimTy
1085 primOpInfo FloatPowerOp = mkDyadic SLIT("powerFloat#") floatPrimTy
1088 %************************************************************************
1090 \subsubsection[PrimOp-Double]{PrimOpInfo for @Double#@s}
1092 %************************************************************************
1094 @decodeDouble#@ is given w/ Integer-stuff (it's similar).
1097 primOpInfo DoubleAddOp = mkDyadic SLIT("+##") doublePrimTy
1098 primOpInfo DoubleSubOp = mkDyadic SLIT("-##") doublePrimTy
1099 primOpInfo DoubleMulOp = mkDyadic SLIT("*##") doublePrimTy
1100 primOpInfo DoubleDivOp = mkDyadic SLIT("/##") doublePrimTy
1101 primOpInfo DoubleNegOp = mkMonadic SLIT("negateDouble#") doublePrimTy
1103 primOpInfo Double2IntOp = mkGenPrimOp SLIT("double2Int#") [] [doublePrimTy] intPrimTy
1104 primOpInfo Int2DoubleOp = mkGenPrimOp SLIT("int2Double#") [] [intPrimTy] doublePrimTy
1106 primOpInfo Double2FloatOp = mkGenPrimOp SLIT("double2Float#") [] [doublePrimTy] floatPrimTy
1107 primOpInfo Float2DoubleOp = mkGenPrimOp SLIT("float2Double#") [] [floatPrimTy] doublePrimTy
1109 primOpInfo DoubleExpOp = mkMonadic SLIT("expDouble#") doublePrimTy
1110 primOpInfo DoubleLogOp = mkMonadic SLIT("logDouble#") doublePrimTy
1111 primOpInfo DoubleSqrtOp = mkMonadic SLIT("sqrtDouble#") doublePrimTy
1112 primOpInfo DoubleSinOp = mkMonadic SLIT("sinDouble#") doublePrimTy
1113 primOpInfo DoubleCosOp = mkMonadic SLIT("cosDouble#") doublePrimTy
1114 primOpInfo DoubleTanOp = mkMonadic SLIT("tanDouble#") doublePrimTy
1115 primOpInfo DoubleAsinOp = mkMonadic SLIT("asinDouble#") doublePrimTy
1116 primOpInfo DoubleAcosOp = mkMonadic SLIT("acosDouble#") doublePrimTy
1117 primOpInfo DoubleAtanOp = mkMonadic SLIT("atanDouble#") doublePrimTy
1118 primOpInfo DoubleSinhOp = mkMonadic SLIT("sinhDouble#") doublePrimTy
1119 primOpInfo DoubleCoshOp = mkMonadic SLIT("coshDouble#") doublePrimTy
1120 primOpInfo DoubleTanhOp = mkMonadic SLIT("tanhDouble#") doublePrimTy
1121 primOpInfo DoublePowerOp= mkDyadic SLIT("**##") doublePrimTy
1124 %************************************************************************
1126 \subsubsection[PrimOp-Integer]{PrimOpInfo for @Integer@ (and related!)}
1128 %************************************************************************
1131 primOpInfo IntegerNegOp = integerMonadic SLIT("negateInteger#")
1133 primOpInfo IntegerAddOp = integerDyadic SLIT("plusInteger#")
1134 primOpInfo IntegerSubOp = integerDyadic SLIT("minusInteger#")
1135 primOpInfo IntegerMulOp = integerDyadic SLIT("timesInteger#")
1136 primOpInfo IntegerGcdOp = integerDyadic SLIT("gcdInteger#")
1138 primOpInfo IntegerCmpOp = integerCompare SLIT("cmpInteger#")
1139 primOpInfo IntegerCmpIntOp
1140 = mkGenPrimOp SLIT("cmpIntegerInt#") [] an_Integer_and_Int_tys intPrimTy
1142 primOpInfo IntegerQuotRemOp = integerDyadic2Results SLIT("quotRemInteger#")
1143 primOpInfo IntegerDivModOp = integerDyadic2Results SLIT("divModInteger#")
1145 primOpInfo Integer2IntOp
1146 = mkGenPrimOp SLIT("integer2Int#") [] one_Integer_ty intPrimTy
1148 primOpInfo Integer2WordOp
1149 = mkGenPrimOp SLIT("integer2Word#") [] one_Integer_ty wordPrimTy
1151 primOpInfo Int2IntegerOp
1152 = mkGenPrimOp SLIT("int2Integer#") [] [intPrimTy]
1153 (unboxedPair one_Integer_ty)
1155 primOpInfo Word2IntegerOp
1156 = mkGenPrimOp SLIT("word2Integer#") [] [wordPrimTy]
1157 (unboxedPair one_Integer_ty)
1159 primOpInfo Addr2IntegerOp
1160 = mkGenPrimOp SLIT("addr2Integer#") [] [addrPrimTy]
1161 (unboxedPair one_Integer_ty)
1163 primOpInfo IntegerToInt64Op
1164 = mkGenPrimOp SLIT("integerToInt64#") [] one_Integer_ty int64PrimTy
1166 primOpInfo Int64ToIntegerOp
1167 = mkGenPrimOp SLIT("int64ToInteger#") [] [int64PrimTy]
1168 (unboxedPair one_Integer_ty)
1170 primOpInfo Word64ToIntegerOp
1171 = mkGenPrimOp SLIT("word64ToInteger#") [] [word64PrimTy]
1172 (unboxedPair one_Integer_ty)
1174 primOpInfo IntegerToWord64Op
1175 = mkGenPrimOp SLIT("integerToWord64#") [] one_Integer_ty word64PrimTy
1178 Decoding of floating-point numbers is sorta Integer-related. Encoding
1179 is done with plain ccalls now (see PrelNumExtra.lhs).
1182 primOpInfo FloatDecodeOp
1183 = mkGenPrimOp SLIT("decodeFloat#") [] [floatPrimTy]
1184 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1185 primOpInfo DoubleDecodeOp
1186 = mkGenPrimOp SLIT("decodeDouble#") [] [doublePrimTy]
1187 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1190 %************************************************************************
1192 \subsubsection[PrimOp-Arrays]{PrimOpInfo for primitive arrays}
1194 %************************************************************************
1197 primOpInfo NewArrayOp
1199 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1200 state = mkStatePrimTy s
1202 mkGenPrimOp SLIT("newArray#") [s_tv, elt_tv]
1203 [intPrimTy, elt, state]
1204 (unboxedPair [state, mkMutableArrayPrimTy s elt])
1206 primOpInfo (NewByteArrayOp kind)
1208 s = alphaTy; s_tv = alphaTyVar
1210 op_str = _PK_ ("new" ++ primRepString kind ++ "Array#")
1211 state = mkStatePrimTy s
1213 mkGenPrimOp op_str [s_tv]
1215 (unboxedPair [state, mkMutableByteArrayPrimTy s])
1217 ---------------------------------------------------------------------------
1219 primOpInfo SameMutableArrayOp
1221 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1222 mut_arr_ty = mkMutableArrayPrimTy s elt
1224 mkGenPrimOp SLIT("sameMutableArray#") [s_tv, elt_tv] [mut_arr_ty, mut_arr_ty]
1227 primOpInfo SameMutableByteArrayOp
1229 s = alphaTy; s_tv = alphaTyVar;
1230 mut_arr_ty = mkMutableByteArrayPrimTy s
1232 mkGenPrimOp SLIT("sameMutableByteArray#") [s_tv] [mut_arr_ty, mut_arr_ty]
1235 ---------------------------------------------------------------------------
1236 -- Primitive arrays of Haskell pointers:
1238 primOpInfo ReadArrayOp
1240 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1241 state = mkStatePrimTy s
1243 mkGenPrimOp SLIT("readArray#") [s_tv, elt_tv]
1244 [mkMutableArrayPrimTy s elt, intPrimTy, state]
1245 (unboxedPair [state, elt])
1248 primOpInfo WriteArrayOp
1250 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1252 mkGenPrimOp SLIT("writeArray#") [s_tv, elt_tv]
1253 [mkMutableArrayPrimTy s elt, intPrimTy, elt, mkStatePrimTy s]
1256 primOpInfo IndexArrayOp
1257 = let { elt = alphaTy; elt_tv = alphaTyVar } in
1258 mkGenPrimOp SLIT("indexArray#") [elt_tv] [mkArrayPrimTy elt, intPrimTy]
1259 (unboxedPair [realWorldStatePrimTy, elt])
1261 ---------------------------------------------------------------------------
1262 -- Primitive arrays full of unboxed bytes:
1264 primOpInfo (ReadByteArrayOp kind)
1266 s = alphaTy; s_tv = alphaTyVar
1268 op_str = _PK_ ("read" ++ primRepString kind ++ "Array#")
1269 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1270 state = mkStatePrimTy s
1272 mkGenPrimOp op_str (s_tv:tvs)
1273 [mkMutableByteArrayPrimTy s, intPrimTy, state]
1274 (unboxedPair [state, prim_ty])
1276 primOpInfo (WriteByteArrayOp kind)
1278 s = alphaTy; s_tv = alphaTyVar
1279 op_str = _PK_ ("write" ++ primRepString kind ++ "Array#")
1280 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1282 mkGenPrimOp op_str (s_tv:tvs)
1283 [mkMutableByteArrayPrimTy s, intPrimTy, prim_ty, mkStatePrimTy s]
1286 primOpInfo (IndexByteArrayOp kind)
1288 op_str = _PK_ ("index" ++ primRepString kind ++ "Array#")
1289 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1291 mkGenPrimOp op_str tvs [byteArrayPrimTy, intPrimTy] prim_ty
1293 primOpInfo (IndexOffForeignObjOp kind)
1295 op_str = _PK_ ("index" ++ primRepString kind ++ "OffForeignObj#")
1296 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1298 mkGenPrimOp op_str tvs [foreignObjPrimTy, intPrimTy] prim_ty
1300 primOpInfo (IndexOffAddrOp kind)
1302 op_str = _PK_ ("index" ++ primRepString kind ++ "OffAddr#")
1303 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1305 mkGenPrimOp op_str tvs [addrPrimTy, intPrimTy] prim_ty
1307 primOpInfo (WriteOffAddrOp kind)
1309 s = alphaTy; s_tv = alphaTyVar
1310 op_str = _PK_ ("write" ++ primRepString kind ++ "OffAddr#")
1311 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1313 mkGenPrimOp op_str (s_tv:tvs)
1314 [addrPrimTy, intPrimTy, prim_ty, mkStatePrimTy s]
1317 ---------------------------------------------------------------------------
1318 primOpInfo UnsafeFreezeArrayOp
1320 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1321 state = mkStatePrimTy s
1323 mkGenPrimOp SLIT("unsafeFreezeArray#") [s_tv, elt_tv]
1324 [mkMutableArrayPrimTy s elt, state]
1325 (unboxedPair [state, mkArrayPrimTy elt])
1327 primOpInfo UnsafeFreezeByteArrayOp
1329 s = alphaTy; s_tv = alphaTyVar;
1330 state = mkStatePrimTy s
1332 mkGenPrimOp SLIT("unsafeFreezeByteArray#") [s_tv]
1333 [mkMutableByteArrayPrimTy s, state]
1334 (unboxedPair [state, byteArrayPrimTy])
1336 primOpInfo UnsafeThawArrayOp
1338 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1339 state = mkStatePrimTy s
1341 mkGenPrimOp SLIT("unsafeThawArray#") [s_tv, elt_tv]
1342 [mkArrayPrimTy elt, state]
1343 (unboxedPair [state, mkMutableArrayPrimTy s elt])
1345 primOpInfo UnsafeThawByteArrayOp
1347 s = alphaTy; s_tv = alphaTyVar;
1348 state = mkStatePrimTy s
1350 mkGenPrimOp SLIT("unsafeThawByteArray#") [s_tv]
1351 [byteArrayPrimTy, state]
1352 (unboxedPair [state, mkMutableByteArrayPrimTy s])
1354 ---------------------------------------------------------------------------
1355 primOpInfo SizeofByteArrayOp
1357 SLIT("sizeofByteArray#") []
1361 primOpInfo SizeofMutableByteArrayOp
1362 = let { s = alphaTy; s_tv = alphaTyVar } in
1364 SLIT("sizeofMutableByteArray#") [s_tv]
1365 [mkMutableByteArrayPrimTy s]
1370 %************************************************************************
1372 \subsubsection[PrimOp-MutVars]{PrimOpInfo for mutable variable ops}
1374 %************************************************************************
1377 primOpInfo NewMutVarOp
1379 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1380 state = mkStatePrimTy s
1382 mkGenPrimOp SLIT("newMutVar#") [s_tv, elt_tv]
1384 (unboxedPair [state, mkMutVarPrimTy s elt])
1386 primOpInfo ReadMutVarOp
1388 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1389 state = mkStatePrimTy s
1391 mkGenPrimOp SLIT("readMutVar#") [s_tv, elt_tv]
1392 [mkMutVarPrimTy s elt, state]
1393 (unboxedPair [state, elt])
1396 primOpInfo WriteMutVarOp
1398 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1400 mkGenPrimOp SLIT("writeMutVar#") [s_tv, elt_tv]
1401 [mkMutVarPrimTy s elt, elt, mkStatePrimTy s]
1404 primOpInfo SameMutVarOp
1406 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1407 mut_var_ty = mkMutVarPrimTy s elt
1409 mkGenPrimOp SLIT("sameMutVar#") [s_tv, elt_tv] [mut_var_ty, mut_var_ty]
1413 %************************************************************************
1415 \subsubsection[PrimOp-Exceptions]{PrimOpInfo for exceptions}
1417 %************************************************************************
1419 catch :: IO a -> (IOError -> IO a) -> IO a
1420 catch :: a -> (b -> a) -> a
1425 a = alphaTy; a_tv = alphaTyVar
1426 b = betaTy; b_tv = betaTyVar;
1428 mkGenPrimOp SLIT("catch#") [a_tv, b_tv] [a, mkFunTy b a] a
1432 a = alphaTy; a_tv = alphaTyVar
1433 b = betaTy; b_tv = betaTyVar;
1435 mkGenPrimOp SLIT("raise#") [a_tv, b_tv] [a] b
1438 %************************************************************************
1440 \subsubsection[PrimOp-MVars]{PrimOpInfo for synchronizing Variables}
1442 %************************************************************************
1445 primOpInfo NewMVarOp
1447 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1448 state = mkStatePrimTy s
1450 mkGenPrimOp SLIT("newMVar#") [s_tv, elt_tv] [state]
1451 (unboxedPair [state, mkMVarPrimTy s elt])
1453 primOpInfo TakeMVarOp
1455 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1456 state = mkStatePrimTy s
1458 mkGenPrimOp SLIT("takeMVar#") [s_tv, elt_tv]
1459 [mkMVarPrimTy s elt, state]
1460 (unboxedPair [state, elt])
1462 primOpInfo PutMVarOp
1464 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1466 mkGenPrimOp SLIT("putMVar#") [s_tv, elt_tv]
1467 [mkMVarPrimTy s elt, elt, mkStatePrimTy s]
1470 primOpInfo SameMVarOp
1472 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1473 mvar_ty = mkMVarPrimTy s elt
1475 mkGenPrimOp SLIT("sameMVar#") [s_tv, elt_tv] [mvar_ty, mvar_ty] boolTy
1477 primOpInfo IsEmptyMVarOp
1479 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1480 state = mkStatePrimTy s
1482 mkGenPrimOp SLIT("isEmptyMVar#") [s_tv, elt_tv]
1483 [mkMVarPrimTy s elt, mkStatePrimTy s]
1484 (unboxedPair [state, intPrimTy])
1488 %************************************************************************
1490 \subsubsection[PrimOp-Wait]{PrimOpInfo for delay/wait operations}
1492 %************************************************************************
1498 s = alphaTy; s_tv = alphaTyVar
1500 mkGenPrimOp SLIT("delay#") [s_tv]
1501 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1503 primOpInfo WaitReadOp
1505 s = alphaTy; s_tv = alphaTyVar
1507 mkGenPrimOp SLIT("waitRead#") [s_tv]
1508 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1510 primOpInfo WaitWriteOp
1512 s = alphaTy; s_tv = alphaTyVar
1514 mkGenPrimOp SLIT("waitWrite#") [s_tv]
1515 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1518 %************************************************************************
1520 \subsubsection[PrimOp-Concurrency]{Concurrency Primitives}
1522 %************************************************************************
1525 -- fork# :: a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1527 = mkGenPrimOp SLIT("fork#") [alphaTyVar]
1528 [alphaTy, realWorldStatePrimTy]
1529 (unboxedPair [realWorldStatePrimTy, threadIdPrimTy])
1531 -- killThread# :: ThreadId# -> State# RealWorld -> State# RealWorld
1532 primOpInfo KillThreadOp
1533 = mkGenPrimOp SLIT("killThread#") []
1534 [threadIdPrimTy, realWorldStatePrimTy]
1535 realWorldStatePrimTy
1538 ************************************************************************
1540 \subsubsection[PrimOps-Foreign]{PrimOpInfo for Foreign Objects}
1542 %************************************************************************
1545 primOpInfo MakeForeignObjOp
1546 = mkGenPrimOp SLIT("makeForeignObj#") []
1547 [addrPrimTy, realWorldStatePrimTy]
1548 (unboxedPair [realWorldStatePrimTy, foreignObjPrimTy])
1550 primOpInfo WriteForeignObjOp
1552 s = alphaTy; s_tv = alphaTyVar
1554 mkGenPrimOp SLIT("writeForeignObj#") [s_tv]
1555 [foreignObjPrimTy, addrPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1558 ************************************************************************
1560 \subsubsection[PrimOps-Weak]{PrimOpInfo for Weak Pointers}
1562 %************************************************************************
1564 A @Weak@ Pointer is created by the @mkWeak#@ primitive:
1566 mkWeak# :: k -> v -> f -> State# RealWorld
1567 -> (# State# RealWorld, Weak# v #)
1569 In practice, you'll use the higher-level
1571 data Weak v = Weak# v
1572 mkWeak :: k -> v -> IO () -> IO (Weak v)
1576 = mkGenPrimOp SLIT("mkWeak#") [alphaTyVar, betaTyVar, gammaTyVar]
1577 [alphaTy, betaTy, gammaTy, realWorldStatePrimTy]
1578 (unboxedPair [realWorldStatePrimTy, mkWeakPrimTy betaTy])
1581 The following operation dereferences a weak pointer. The weak pointer
1582 may have been finalized, so the operation returns a result code which
1583 must be inspected before looking at the dereferenced value.
1585 deRefWeak# :: Weak# v -> State# RealWorld ->
1586 (# State# RealWorld, v, Int# #)
1588 Only look at v if the Int# returned is /= 0 !!
1590 The higher-level op is
1592 deRefWeak :: Weak v -> IO (Maybe v)
1595 primOpInfo DeRefWeakOp
1596 = mkGenPrimOp SLIT("deRefWeak#") [alphaTyVar]
1597 [mkWeakPrimTy alphaTy, realWorldStatePrimTy]
1598 (unboxedTriple [realWorldStatePrimTy, intPrimTy, alphaTy])
1601 Weak pointers can be finalized early by using the finalize# operation:
1603 finalizeWeak# :: Weak# v -> State# RealWorld ->
1604 (# State# RealWorld, Int#, IO () #)
1606 The Int# returned is either
1608 0 if the weak pointer has already been finalized, or it has no
1609 finalizer (the third component is then invalid).
1611 1 if the weak pointer is still alive, with the finalizer returned
1612 as the third component.
1615 primOpInfo FinalizeWeakOp
1616 = mkGenPrimOp SLIT("finalizeWeak#") [alphaTyVar]
1617 [mkWeakPrimTy alphaTy, realWorldStatePrimTy]
1618 (unboxedTriple [realWorldStatePrimTy, intPrimTy,
1619 mkFunTy realWorldStatePrimTy
1620 (unboxedPair [realWorldStatePrimTy,unitTy])])
1623 %************************************************************************
1625 \subsubsection[PrimOp-stable-pointers]{PrimOpInfo for stable pointers and stable names}
1627 %************************************************************************
1629 A {\em stable name/pointer} is an index into a table of stable name
1630 entries. Since the garbage collector is told about stable pointers,
1631 it is safe to pass a stable pointer to external systems such as C
1635 makeStablePtr# :: a -> State# RealWorld -> (# State# RealWorld, a #)
1636 freeStablePtr :: StablePtr# a -> State# RealWorld -> State# RealWorld
1637 deRefStablePtr# :: StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1638 eqStablePtr# :: StablePtr# a -> StablePtr# a -> Int#
1641 It may seem a bit surprising that @makeStablePtr#@ is a @IO@
1642 operation since it doesn't (directly) involve IO operations. The
1643 reason is that if some optimisation pass decided to duplicate calls to
1644 @makeStablePtr#@ and we only pass one of the stable pointers over, a
1645 massive space leak can result. Putting it into the IO monad
1646 prevents this. (Another reason for putting them in a monad is to
1647 ensure correct sequencing wrt the side-effecting @freeStablePtr@
1650 An important property of stable pointers is that if you call
1651 makeStablePtr# twice on the same object you get the same stable
1654 Note that we can implement @freeStablePtr#@ using @_ccall_@ (and,
1655 besides, it's not likely to be used from Haskell) so it's not a
1658 Question: Why @RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
1663 A stable name is like a stable pointer, but with three important differences:
1665 (a) You can't deRef one to get back to the original object.
1666 (b) You can convert one to an Int.
1667 (c) You don't need to 'freeStableName'
1669 The existence of a stable name doesn't guarantee to keep the object it
1670 points to alive (unlike a stable pointer), hence (a).
1674 (a) makeStableName always returns the same value for a given
1675 object (same as stable pointers).
1677 (b) if two stable names are equal, it implies that the objects
1678 from which they were created were the same.
1680 (c) stableNameToInt always returns the same Int for a given
1684 primOpInfo MakeStablePtrOp
1685 = mkGenPrimOp SLIT("makeStablePtr#") [alphaTyVar]
1686 [alphaTy, realWorldStatePrimTy]
1687 (unboxedPair [realWorldStatePrimTy,
1688 mkTyConApp stablePtrPrimTyCon [alphaTy]])
1690 primOpInfo DeRefStablePtrOp
1691 = mkGenPrimOp SLIT("deRefStablePtr#") [alphaTyVar]
1692 [mkStablePtrPrimTy alphaTy, realWorldStatePrimTy]
1693 (unboxedPair [realWorldStatePrimTy, alphaTy])
1695 primOpInfo EqStablePtrOp
1696 = mkGenPrimOp SLIT("eqStablePtr#") [alphaTyVar, betaTyVar]
1697 [mkStablePtrPrimTy alphaTy, mkStablePtrPrimTy betaTy]
1700 primOpInfo MakeStableNameOp
1701 = mkGenPrimOp SLIT("makeStableName#") [alphaTyVar]
1702 [alphaTy, realWorldStatePrimTy]
1703 (unboxedPair [realWorldStatePrimTy,
1704 mkTyConApp stableNamePrimTyCon [alphaTy]])
1706 primOpInfo EqStableNameOp
1707 = mkGenPrimOp SLIT("eqStableName#") [alphaTyVar, betaTyVar]
1708 [mkStableNamePrimTy alphaTy, mkStableNamePrimTy betaTy]
1711 primOpInfo StableNameToIntOp
1712 = mkGenPrimOp SLIT("stableNameToInt#") [alphaTyVar]
1713 [mkStableNamePrimTy alphaTy]
1717 %************************************************************************
1719 \subsubsection[PrimOp-unsafePointerEquality]{PrimOpInfo for Pointer Equality}
1721 %************************************************************************
1723 [Alastair Reid is to blame for this!]
1725 These days, (Glasgow) Haskell seems to have a bit of everything from
1726 other languages: strict operations, mutable variables, sequencing,
1727 pointers, etc. About the only thing left is LISP's ability to test
1728 for pointer equality. So, let's add it in!
1731 reallyUnsafePtrEquality :: a -> a -> Int#
1734 which tests any two closures (of the same type) to see if they're the
1735 same. (Returns $0$ for @False@, $\neq 0$ for @True@ - to avoid
1736 difficulties of trying to box up the result.)
1738 NB This is {\em really unsafe\/} because even something as trivial as
1739 a garbage collection might change the answer by removing indirections.
1740 Still, no-one's forcing you to use it. If you're worried about little
1741 things like loss of referential transparency, you might like to wrap
1742 it all up in a monad-like thing as John O'Donnell and John Hughes did
1743 for non-determinism (1989 (Fraserburgh) Glasgow FP Workshop
1746 I'm thinking of using it to speed up a critical equality test in some
1747 graphics stuff in a context where the possibility of saying that
1748 denotationally equal things aren't isn't a problem (as long as it
1749 doesn't happen too often.) ADR
1751 To Will: Jim said this was already in, but I can't see it so I'm
1752 adding it. Up to you whether you add it. (Note that this could have
1753 been readily implemented using a @veryDangerousCCall@ before they were
1757 primOpInfo ReallyUnsafePtrEqualityOp
1758 = mkGenPrimOp SLIT("reallyUnsafePtrEquality#") [alphaTyVar]
1759 [alphaTy, alphaTy] intPrimTy
1762 %************************************************************************
1764 \subsubsection[PrimOp-parallel]{PrimOpInfo for parallelism op(s)}
1766 %************************************************************************
1769 primOpInfo SeqOp -- seq# :: a -> Int#
1770 = mkGenPrimOp SLIT("seq#") [alphaTyVar] [alphaTy] intPrimTy
1772 primOpInfo ParOp -- par# :: a -> Int#
1773 = mkGenPrimOp SLIT("par#") [alphaTyVar] [alphaTy] intPrimTy
1777 -- HWL: The first 4 Int# in all par... annotations denote:
1778 -- name, granularity info, size of result, degree of parallelism
1779 -- Same structure as _seq_ i.e. returns Int#
1781 primOpInfo ParGlobalOp -- parGlobal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1782 = mkGenPrimOp SLIT("parGlobal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1784 primOpInfo ParLocalOp -- parLocal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1785 = mkGenPrimOp SLIT("parLocal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1787 primOpInfo ParAtOp -- parAt# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1788 = mkGenPrimOp SLIT("parAt#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
1790 primOpInfo ParAtAbsOp -- parAtAbs# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1791 = mkGenPrimOp SLIT("parAtAbs#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1793 primOpInfo ParAtRelOp -- parAtRel# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1794 = mkGenPrimOp SLIT("parAtRel#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1796 primOpInfo ParAtForNowOp -- parAtForNow# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1797 = mkGenPrimOp SLIT("parAtForNow#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
1799 primOpInfo CopyableOp -- copyable# :: a -> a
1800 = mkGenPrimOp SLIT("copyable#") [alphaTyVar] [alphaTy] intPrimTy
1802 primOpInfo NoFollowOp -- noFollow# :: a -> a
1803 = mkGenPrimOp SLIT("noFollow#") [alphaTyVar] [alphaTy] intPrimTy
1806 %************************************************************************
1808 \subsubsection[PrimOp-IO-etc]{PrimOpInfo for C calls, and I/O-ish things}
1810 %************************************************************************
1813 primOpInfo (CCallOp _ _ _ _)
1814 = mkGenPrimOp SLIT("ccall#") [alphaTyVar] [] alphaTy
1817 primOpInfo (CCallOp _ _ _ _ arg_tys result_ty)
1818 = mkGenPrimOp SLIT("ccall#") [] arg_tys result_tycon tys_applied
1820 (result_tycon, tys_applied, _) = splitAlgTyConApp result_ty
1823 primOpInfo op = panic ("primOpInfo:"++ show (I# (tagOf_PrimOp op)))
1827 Some PrimOps need to be called out-of-line because they either need to
1828 perform a heap check or they block.
1841 NewByteArrayOp _ -> True
1842 IntegerAddOp -> True
1843 IntegerSubOp -> True
1844 IntegerMulOp -> True
1845 IntegerGcdOp -> True
1846 IntegerQuotRemOp -> True
1847 IntegerDivModOp -> True
1848 Int2IntegerOp -> True
1849 Word2IntegerOp -> True
1850 Addr2IntegerOp -> True
1851 Word64ToIntegerOp -> True
1852 Int64ToIntegerOp -> True
1853 FloatDecodeOp -> True
1854 DoubleDecodeOp -> True
1856 FinalizeWeakOp -> True
1857 MakeStableNameOp -> True
1858 MakeForeignObjOp -> True
1862 KillThreadOp -> True
1863 CCallOp _ _ may_gc@True _ -> True -- _ccall_GC_
1864 -- the next one doesn't perform any heap checks,
1865 -- but it is of such an esoteric nature that
1866 -- it is done out-of-line rather than require
1867 -- the NCG to implement it.
1868 UnsafeThawArrayOp -> True
1872 Sometimes we may choose to execute a PrimOp even though it isn't
1873 certain that its result will be required; ie execute them
1874 ``speculatively''. The same thing as ``cheap eagerness.'' Usually
1875 this is OK, because PrimOps are usually cheap, but it isn't OK for
1876 (a)~expensive PrimOps and (b)~PrimOps which can fail.
1878 See also @primOpIsCheap@ (below).
1880 PrimOps that have side effects also should not be executed speculatively
1881 or by data dependencies.
1884 primOpOkForSpeculation :: PrimOp -> Bool
1885 primOpOkForSpeculation op
1886 = not (primOpCanFail op || primOpHasSideEffects op || primOpOutOfLine op)
1889 @primOpIsCheap@, as used in \tr{SimplUtils.lhs}. For now (HACK
1890 WARNING), we just borrow some other predicates for a
1891 what-should-be-good-enough test. "Cheap" means willing to call it more
1892 than once. Evaluation order is unaffected.
1895 primOpIsCheap op = not (primOpHasSideEffects op || primOpOutOfLine op)
1899 primOpCanFail :: PrimOp -> Bool
1901 primOpCanFail IntQuotOp = True -- Divide by zero
1902 primOpCanFail IntRemOp = True -- Divide by zero
1905 primOpCanFail IntegerQuotRemOp = True -- Divide by zero
1906 primOpCanFail IntegerDivModOp = True -- Divide by zero
1908 -- Float. ToDo: tan? tanh?
1909 primOpCanFail FloatDivOp = True -- Divide by zero
1910 primOpCanFail FloatLogOp = True -- Log of zero
1911 primOpCanFail FloatAsinOp = True -- Arg out of domain
1912 primOpCanFail FloatAcosOp = True -- Arg out of domain
1914 -- Double. ToDo: tan? tanh?
1915 primOpCanFail DoubleDivOp = True -- Divide by zero
1916 primOpCanFail DoubleLogOp = True -- Log of zero
1917 primOpCanFail DoubleAsinOp = True -- Arg out of domain
1918 primOpCanFail DoubleAcosOp = True -- Arg out of domain
1920 primOpCanFail other_op = False
1923 And some primops have side-effects and so, for example, must not be
1927 primOpHasSideEffects :: PrimOp -> Bool
1929 primOpHasSideEffects TakeMVarOp = True
1930 primOpHasSideEffects DelayOp = True
1931 primOpHasSideEffects WaitReadOp = True
1932 primOpHasSideEffects WaitWriteOp = True
1934 primOpHasSideEffects ParOp = True
1935 primOpHasSideEffects ForkOp = True
1936 primOpHasSideEffects KillThreadOp = True
1937 primOpHasSideEffects SeqOp = True
1939 primOpHasSideEffects MakeForeignObjOp = True
1940 primOpHasSideEffects WriteForeignObjOp = True
1941 primOpHasSideEffects MkWeakOp = True
1942 primOpHasSideEffects DeRefWeakOp = True
1943 primOpHasSideEffects FinalizeWeakOp = True
1944 primOpHasSideEffects MakeStablePtrOp = True
1945 primOpHasSideEffects MakeStableNameOp = True
1946 primOpHasSideEffects EqStablePtrOp = True -- SOF
1947 primOpHasSideEffects DeRefStablePtrOp = True -- ??? JSM & ADR
1949 primOpHasSideEffects ParGlobalOp = True
1950 primOpHasSideEffects ParLocalOp = True
1951 primOpHasSideEffects ParAtOp = True
1952 primOpHasSideEffects ParAtAbsOp = True
1953 primOpHasSideEffects ParAtRelOp = True
1954 primOpHasSideEffects ParAtForNowOp = True
1955 primOpHasSideEffects CopyableOp = True -- Possibly not. ASP
1956 primOpHasSideEffects NoFollowOp = True -- Possibly not. ASP
1959 primOpHasSideEffects (CCallOp _ _ _ _) = True
1961 primOpHasSideEffects other = False
1964 Inline primitive operations that perform calls need wrappers to save
1965 any live variables that are stored in caller-saves registers.
1968 primOpNeedsWrapper :: PrimOp -> Bool
1970 primOpNeedsWrapper (CCallOp _ _ _ _) = True
1972 primOpNeedsWrapper Integer2IntOp = True
1973 primOpNeedsWrapper Integer2WordOp = True
1974 primOpNeedsWrapper IntegerCmpOp = True
1975 primOpNeedsWrapper IntegerCmpIntOp = True
1977 primOpNeedsWrapper FloatExpOp = True
1978 primOpNeedsWrapper FloatLogOp = True
1979 primOpNeedsWrapper FloatSqrtOp = True
1980 primOpNeedsWrapper FloatSinOp = True
1981 primOpNeedsWrapper FloatCosOp = True
1982 primOpNeedsWrapper FloatTanOp = True
1983 primOpNeedsWrapper FloatAsinOp = True
1984 primOpNeedsWrapper FloatAcosOp = True
1985 primOpNeedsWrapper FloatAtanOp = True
1986 primOpNeedsWrapper FloatSinhOp = True
1987 primOpNeedsWrapper FloatCoshOp = True
1988 primOpNeedsWrapper FloatTanhOp = True
1989 primOpNeedsWrapper FloatPowerOp = True
1991 primOpNeedsWrapper DoubleExpOp = True
1992 primOpNeedsWrapper DoubleLogOp = True
1993 primOpNeedsWrapper DoubleSqrtOp = True
1994 primOpNeedsWrapper DoubleSinOp = True
1995 primOpNeedsWrapper DoubleCosOp = True
1996 primOpNeedsWrapper DoubleTanOp = True
1997 primOpNeedsWrapper DoubleAsinOp = True
1998 primOpNeedsWrapper DoubleAcosOp = True
1999 primOpNeedsWrapper DoubleAtanOp = True
2000 primOpNeedsWrapper DoubleSinhOp = True
2001 primOpNeedsWrapper DoubleCoshOp = True
2002 primOpNeedsWrapper DoubleTanhOp = True
2003 primOpNeedsWrapper DoublePowerOp = True
2005 primOpNeedsWrapper MakeStableNameOp = True
2006 primOpNeedsWrapper DeRefStablePtrOp = True
2008 primOpNeedsWrapper DelayOp = True
2009 primOpNeedsWrapper WaitReadOp = True
2010 primOpNeedsWrapper WaitWriteOp = True
2012 primOpNeedsWrapper other_op = False
2017 = case (primOpInfo op) of
2019 Monadic occ _ -> occ
2020 Compare occ _ -> occ
2021 GenPrimOp occ _ _ _ -> occ
2025 primOpUniq :: PrimOp -> Unique
2026 primOpUniq op = mkPrimOpIdUnique (IBOX(tagOf_PrimOp op))
2028 primOpType :: PrimOp -> Type
2030 = case (primOpInfo op) of
2031 Dyadic occ ty -> dyadic_fun_ty ty
2032 Monadic occ ty -> monadic_fun_ty ty
2033 Compare occ ty -> compare_fun_ty ty
2035 GenPrimOp occ tyvars arg_tys res_ty ->
2036 mkForAllTys tyvars (mkFunTys arg_tys res_ty)
2040 data PrimOpResultInfo
2041 = ReturnsPrim PrimRep
2044 -- Some PrimOps need not return a manifest primitive or algebraic value
2045 -- (i.e. they might return a polymorphic value). These PrimOps *must*
2046 -- be out of line, or the code generator won't work.
2048 getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo
2050 getPrimOpResultInfo op
2051 = case (primOpInfo op) of
2052 Dyadic _ ty -> ReturnsPrim (typePrimRep ty)
2053 Monadic _ ty -> ReturnsPrim (typePrimRep ty)
2054 Compare _ ty -> ReturnsAlg boolTyCon
2055 GenPrimOp _ _ _ ty ->
2056 let rep = typePrimRep ty in
2058 PtrRep -> case splitAlgTyConApp_maybe ty of
2059 Nothing -> panic "getPrimOpResultInfo"
2060 Just (tc,_,_) -> ReturnsAlg tc
2061 other -> ReturnsPrim other
2063 isCompareOp :: PrimOp -> Bool
2066 = case primOpInfo op of
2071 The commutable ops are those for which we will try to move constants
2072 to the right hand side for strength reduction.
2075 commutableOp :: PrimOp -> Bool
2077 commutableOp CharEqOp = True
2078 commutableOp CharNeOp = True
2079 commutableOp IntAddOp = True
2080 commutableOp IntMulOp = True
2081 commutableOp AndOp = True
2082 commutableOp OrOp = True
2083 commutableOp XorOp = True
2084 commutableOp IntEqOp = True
2085 commutableOp IntNeOp = True
2086 commutableOp IntegerAddOp = True
2087 commutableOp IntegerMulOp = True
2088 commutableOp IntegerGcdOp = True
2089 commutableOp FloatAddOp = True
2090 commutableOp FloatMulOp = True
2091 commutableOp FloatEqOp = True
2092 commutableOp FloatNeOp = True
2093 commutableOp DoubleAddOp = True
2094 commutableOp DoubleMulOp = True
2095 commutableOp DoubleEqOp = True
2096 commutableOp DoubleNeOp = True
2097 commutableOp _ = False
2102 mkPrimTyApp :: [TyVar] -> PrimRep -> ([TyVar], Type)
2103 -- CharRep --> ([], Char#)
2104 -- StablePtrRep --> ([a], StablePtr# a)
2105 mkPrimTyApp tvs kind
2106 = (forall_tvs, mkTyConApp tycon (mkTyVarTys forall_tvs))
2108 tycon = primRepTyCon kind
2109 forall_tvs = take (tyConArity tycon) tvs
2111 dyadic_fun_ty ty = mkFunTys [ty, ty] ty
2112 monadic_fun_ty ty = mkFunTy ty ty
2113 compare_fun_ty ty = mkFunTys [ty, ty] boolTy
2118 pprPrimOp :: PrimOp -> SDoc
2120 pprPrimOp (CCallOp fun is_casm may_gc cconv)
2122 callconv = text "{-" <> pprCallConv cconv <> text "-}"
2125 | is_casm && may_gc = "casm_GC ``"
2126 | is_casm = "casm ``"
2127 | may_gc = "ccall_GC "
2128 | otherwise = "ccall "
2131 | is_casm = text "''"
2136 Right _ -> text "dyn_"
2141 Right _ -> text "\"\""
2145 hcat [ ifPprDebug callconv
2146 , text "__", ppr_dyn
2147 , text before , ppr_fun , after]
2150 = getPprStyle $ \ sty ->
2151 if ifaceStyle sty then -- For interfaces Print it qualified with PrelGHC.
2152 ptext SLIT("PrelGHC.") <> pprOccName occ
2156 occ = primOpOcc other_op