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}
78 | WordQuotOp | WordRemOp
79 | AndOp | OrOp | NotOp | XorOp
80 | SllOp | SrlOp -- shift {left,right} {logical}
81 | Int2WordOp | Word2IntOp -- casts
84 | Int2AddrOp | Addr2IntOp -- casts
86 -- Float#-related ops:
87 | FloatAddOp | FloatSubOp | FloatMulOp | FloatDivOp | FloatNegOp
88 | Float2IntOp | Int2FloatOp
90 | FloatExpOp | FloatLogOp | FloatSqrtOp
91 | FloatSinOp | FloatCosOp | FloatTanOp
92 | FloatAsinOp | FloatAcosOp | FloatAtanOp
93 | FloatSinhOp | FloatCoshOp | FloatTanhOp
94 -- not all machines have these available conveniently:
95 -- | FloatAsinhOp | FloatAcoshOp | FloatAtanhOp
96 | FloatPowerOp -- ** op
98 -- Double#-related ops:
99 | DoubleAddOp | DoubleSubOp | DoubleMulOp | DoubleDivOp | DoubleNegOp
100 | Double2IntOp | Int2DoubleOp
101 | Double2FloatOp | Float2DoubleOp
103 | DoubleExpOp | DoubleLogOp | DoubleSqrtOp
104 | DoubleSinOp | DoubleCosOp | DoubleTanOp
105 | DoubleAsinOp | DoubleAcosOp | DoubleAtanOp
106 | DoubleSinhOp | DoubleCoshOp | DoubleTanhOp
107 -- not all machines have these available conveniently:
108 -- | DoubleAsinhOp | DoubleAcoshOp | DoubleAtanhOp
109 | DoublePowerOp -- ** op
111 -- Integer (and related...) ops:
112 -- slightly weird -- to match GMP package.
113 | IntegerAddOp | IntegerSubOp | IntegerMulOp | IntegerGcdOp
114 | IntegerQuotRemOp | IntegerDivModOp | IntegerNegOp
118 | Integer2IntOp | Integer2WordOp
119 | Int2IntegerOp | Word2IntegerOp
121 -- casting to/from Integer and 64-bit (un)signed quantities.
122 | IntegerToInt64Op | Int64ToIntegerOp
123 | IntegerToWord64Op | Word64ToIntegerOp
126 | FloatEncodeOp | FloatDecodeOp
127 | DoubleEncodeOp | DoubleDecodeOp
129 -- primitive ops for primitive arrays
132 | NewByteArrayOp PrimRep
135 | SameMutableByteArrayOp
137 | ReadArrayOp | WriteArrayOp | IndexArrayOp -- for arrays of Haskell ptrs
139 | ReadByteArrayOp PrimRep
140 | WriteByteArrayOp PrimRep
141 | IndexByteArrayOp PrimRep
142 | IndexOffAddrOp PrimRep
143 | WriteOffAddrOp PrimRep
144 -- PrimRep can be one of {Char,Int,Addr,Float,Double}Kind.
145 -- This is just a cheesy encoding of a bunch of ops.
146 -- Note that ForeignObjRep is not included -- the only way of
147 -- creating a ForeignObj is with a ccall or casm.
148 | IndexOffForeignObjOp PrimRep
150 | UnsafeFreezeArrayOp | UnsafeFreezeByteArrayOp
151 | SizeofByteArrayOp | SizeofMutableByteArrayOp
185 A special ``trap-door'' to use in making calls direct to C functions:
188 FAST_STRING -- Left fn => An "unboxed" ccall# to `fn'.
189 Unique) -- Right u => first argument (an Addr#) is the function pointer
190 -- (unique is used to generate a 'typedef' to cast
191 -- the function pointer if compiling the ccall# down to
192 -- .hc code - can't do this inline for tedious reasons.)
194 Bool -- True <=> really a "casm"
195 Bool -- True <=> might invoke Haskell GC
196 CallConv -- calling convention to use.
198 -- (... to be continued ... )
201 The ``type'' of @CCallOp foo [t1, ... tm] r@ is @t1 -> ... tm -> r@.
202 (See @primOpInfo@ for details.)
204 Note: that first arg and part of the result should be the system state
205 token (which we carry around to fool over-zealous optimisers) but
206 which isn't actually passed.
208 For example, we represent
210 ((ccall# foo [StablePtr# a, Int] Float) sp# i#) :: (Float, IoWorld)
216 (CCallOp "foo" [Universe#, StablePtr# a, Int#] FloatPrimAndUniverse False)
217 -- :: Universe# -> StablePtr# a -> Int# -> FloatPrimAndUniverse
221 (AlgAlts [ ( FloatPrimAndIoWorld,
223 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
229 Nota Bene: there are some people who find the empty list of types in
230 the @Prim@ somewhat puzzling and would represent the above by
234 (CCallOp "foo" [alpha1, alpha2, alpha3] alpha4 False)
235 -- :: /\ alpha1, alpha2 alpha3, alpha4.
236 -- alpha1 -> alpha2 -> alpha3 -> alpha4
237 [Universe#, StablePtr# a, Int#, FloatPrimAndIoWorld]
240 (AlgAlts [ ( FloatPrimAndIoWorld,
242 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
248 But, this is a completely different way of using @CCallOp@. The most
249 major changes required if we switch to this are in @primOpInfo@, and
250 the desugarer. The major difficulty is in moving the HeapRequirement
251 stuff somewhere appropriate. (The advantage is that we could simplify
252 @CCallOp@ and record just the number of arguments with corresponding
253 simplifications in reading pragma unfoldings, the simplifier,
254 instantiation (etc) of core expressions, ... . Maybe we should think
255 about using it this way?? ADR)
258 -- (... continued from above ... )
260 -- Operation to test two closure addresses for equality (yes really!)
261 -- BLAME ALASTAIR REID FOR THIS! THE REST OF US ARE INNOCENT!
262 | ReallyUnsafePtrEqualityOp
275 | ParGlobalOp -- named global par
276 | ParLocalOp -- named local par
277 | ParAtOp -- specifies destination of local par
278 | ParAtAbsOp -- specifies destination of local par (abs processor)
279 | ParAtRelOp -- specifies destination of local par (rel processor)
280 | ParAtForNowOp -- specifies initial destination of global par
281 | CopyableOp -- marks copyable code
282 | NoFollowOp -- marks non-followup expression
285 Used for the Ord instance
288 tagOf_PrimOp CharGtOp = (ILIT( 1) :: FAST_INT)
289 tagOf_PrimOp CharGeOp = ILIT( 2)
290 tagOf_PrimOp CharEqOp = ILIT( 3)
291 tagOf_PrimOp CharNeOp = ILIT( 4)
292 tagOf_PrimOp CharLtOp = ILIT( 5)
293 tagOf_PrimOp CharLeOp = ILIT( 6)
294 tagOf_PrimOp IntGtOp = ILIT( 7)
295 tagOf_PrimOp IntGeOp = ILIT( 8)
296 tagOf_PrimOp IntEqOp = ILIT( 9)
297 tagOf_PrimOp IntNeOp = ILIT( 10)
298 tagOf_PrimOp IntLtOp = ILIT( 11)
299 tagOf_PrimOp IntLeOp = ILIT( 12)
300 tagOf_PrimOp WordGtOp = ILIT( 13)
301 tagOf_PrimOp WordGeOp = ILIT( 14)
302 tagOf_PrimOp WordEqOp = ILIT( 15)
303 tagOf_PrimOp WordNeOp = ILIT( 16)
304 tagOf_PrimOp WordLtOp = ILIT( 17)
305 tagOf_PrimOp WordLeOp = ILIT( 18)
306 tagOf_PrimOp AddrGtOp = ILIT( 19)
307 tagOf_PrimOp AddrGeOp = ILIT( 20)
308 tagOf_PrimOp AddrEqOp = ILIT( 21)
309 tagOf_PrimOp AddrNeOp = ILIT( 22)
310 tagOf_PrimOp AddrLtOp = ILIT( 23)
311 tagOf_PrimOp AddrLeOp = ILIT( 24)
312 tagOf_PrimOp FloatGtOp = ILIT( 25)
313 tagOf_PrimOp FloatGeOp = ILIT( 26)
314 tagOf_PrimOp FloatEqOp = ILIT( 27)
315 tagOf_PrimOp FloatNeOp = ILIT( 28)
316 tagOf_PrimOp FloatLtOp = ILIT( 29)
317 tagOf_PrimOp FloatLeOp = ILIT( 30)
318 tagOf_PrimOp DoubleGtOp = ILIT( 31)
319 tagOf_PrimOp DoubleGeOp = ILIT( 32)
320 tagOf_PrimOp DoubleEqOp = ILIT( 33)
321 tagOf_PrimOp DoubleNeOp = ILIT( 34)
322 tagOf_PrimOp DoubleLtOp = ILIT( 35)
323 tagOf_PrimOp DoubleLeOp = ILIT( 36)
324 tagOf_PrimOp OrdOp = ILIT( 37)
325 tagOf_PrimOp ChrOp = ILIT( 38)
326 tagOf_PrimOp IntAddOp = ILIT( 39)
327 tagOf_PrimOp IntSubOp = ILIT( 40)
328 tagOf_PrimOp IntMulOp = ILIT( 41)
329 tagOf_PrimOp IntQuotOp = ILIT( 42)
330 tagOf_PrimOp IntRemOp = ILIT( 43)
331 tagOf_PrimOp IntNegOp = ILIT( 44)
332 tagOf_PrimOp IntAbsOp = ILIT( 45)
333 tagOf_PrimOp WordQuotOp = ILIT( 46)
334 tagOf_PrimOp WordRemOp = ILIT( 47)
335 tagOf_PrimOp AndOp = ILIT( 48)
336 tagOf_PrimOp OrOp = ILIT( 49)
337 tagOf_PrimOp NotOp = ILIT( 50)
338 tagOf_PrimOp XorOp = ILIT( 51)
339 tagOf_PrimOp SllOp = ILIT( 52)
340 tagOf_PrimOp SrlOp = ILIT( 53)
341 tagOf_PrimOp ISllOp = ILIT( 54)
342 tagOf_PrimOp ISraOp = ILIT( 55)
343 tagOf_PrimOp ISrlOp = ILIT( 56)
344 tagOf_PrimOp Int2WordOp = ILIT( 57)
345 tagOf_PrimOp Word2IntOp = ILIT( 58)
346 tagOf_PrimOp Int2AddrOp = ILIT( 59)
347 tagOf_PrimOp Addr2IntOp = ILIT( 60)
349 tagOf_PrimOp FloatAddOp = ILIT( 61)
350 tagOf_PrimOp FloatSubOp = ILIT( 62)
351 tagOf_PrimOp FloatMulOp = ILIT( 63)
352 tagOf_PrimOp FloatDivOp = ILIT( 64)
353 tagOf_PrimOp FloatNegOp = ILIT( 65)
354 tagOf_PrimOp Float2IntOp = ILIT( 66)
355 tagOf_PrimOp Int2FloatOp = ILIT( 67)
356 tagOf_PrimOp FloatExpOp = ILIT( 68)
357 tagOf_PrimOp FloatLogOp = ILIT( 69)
358 tagOf_PrimOp FloatSqrtOp = ILIT( 70)
359 tagOf_PrimOp FloatSinOp = ILIT( 71)
360 tagOf_PrimOp FloatCosOp = ILIT( 72)
361 tagOf_PrimOp FloatTanOp = ILIT( 73)
362 tagOf_PrimOp FloatAsinOp = ILIT( 74)
363 tagOf_PrimOp FloatAcosOp = ILIT( 75)
364 tagOf_PrimOp FloatAtanOp = ILIT( 76)
365 tagOf_PrimOp FloatSinhOp = ILIT( 77)
366 tagOf_PrimOp FloatCoshOp = ILIT( 78)
367 tagOf_PrimOp FloatTanhOp = ILIT( 79)
368 tagOf_PrimOp FloatPowerOp = ILIT( 80)
370 tagOf_PrimOp DoubleAddOp = ILIT( 81)
371 tagOf_PrimOp DoubleSubOp = ILIT( 82)
372 tagOf_PrimOp DoubleMulOp = ILIT( 83)
373 tagOf_PrimOp DoubleDivOp = ILIT( 84)
374 tagOf_PrimOp DoubleNegOp = ILIT( 85)
375 tagOf_PrimOp Double2IntOp = ILIT( 86)
376 tagOf_PrimOp Int2DoubleOp = ILIT( 87)
377 tagOf_PrimOp Double2FloatOp = ILIT( 88)
378 tagOf_PrimOp Float2DoubleOp = ILIT( 89)
379 tagOf_PrimOp DoubleExpOp = ILIT( 90)
380 tagOf_PrimOp DoubleLogOp = ILIT( 91)
381 tagOf_PrimOp DoubleSqrtOp = ILIT( 92)
382 tagOf_PrimOp DoubleSinOp = ILIT( 93)
383 tagOf_PrimOp DoubleCosOp = ILIT( 94)
384 tagOf_PrimOp DoubleTanOp = ILIT( 95)
385 tagOf_PrimOp DoubleAsinOp = ILIT( 96)
386 tagOf_PrimOp DoubleAcosOp = ILIT( 97)
387 tagOf_PrimOp DoubleAtanOp = ILIT( 98)
388 tagOf_PrimOp DoubleSinhOp = ILIT( 99)
389 tagOf_PrimOp DoubleCoshOp = ILIT(100)
390 tagOf_PrimOp DoubleTanhOp = ILIT(101)
391 tagOf_PrimOp DoublePowerOp = ILIT(102)
393 tagOf_PrimOp IntegerAddOp = ILIT(103)
394 tagOf_PrimOp IntegerSubOp = ILIT(104)
395 tagOf_PrimOp IntegerMulOp = ILIT(105)
396 tagOf_PrimOp IntegerGcdOp = ILIT(106)
397 tagOf_PrimOp IntegerQuotRemOp = ILIT(107)
398 tagOf_PrimOp IntegerDivModOp = ILIT(108)
399 tagOf_PrimOp IntegerNegOp = ILIT(109)
400 tagOf_PrimOp IntegerCmpOp = ILIT(110)
401 tagOf_PrimOp Integer2IntOp = ILIT(111)
402 tagOf_PrimOp Integer2WordOp = ILIT(112)
403 tagOf_PrimOp Int2IntegerOp = ILIT(113)
404 tagOf_PrimOp Word2IntegerOp = ILIT(114)
405 tagOf_PrimOp Addr2IntegerOp = ILIT(115)
406 tagOf_PrimOp IntegerToInt64Op = ILIT(116)
407 tagOf_PrimOp Int64ToIntegerOp = ILIT(117)
408 tagOf_PrimOp IntegerToWord64Op = ILIT(118)
409 tagOf_PrimOp Word64ToIntegerOp = ILIT(119)
411 tagOf_PrimOp FloatEncodeOp = ILIT(120)
412 tagOf_PrimOp FloatDecodeOp = ILIT(121)
413 tagOf_PrimOp DoubleEncodeOp = ILIT(122)
414 tagOf_PrimOp DoubleDecodeOp = ILIT(123)
416 tagOf_PrimOp NewArrayOp = ILIT(124)
417 tagOf_PrimOp (NewByteArrayOp CharRep) = ILIT(125)
418 tagOf_PrimOp (NewByteArrayOp IntRep) = ILIT(126)
419 tagOf_PrimOp (NewByteArrayOp WordRep) = ILIT(127)
420 tagOf_PrimOp (NewByteArrayOp AddrRep) = ILIT(128)
421 tagOf_PrimOp (NewByteArrayOp FloatRep) = ILIT(129)
422 tagOf_PrimOp (NewByteArrayOp DoubleRep) = ILIT(130)
423 tagOf_PrimOp (NewByteArrayOp StablePtrRep) = ILIT(131)
424 tagOf_PrimOp SameMutableArrayOp = ILIT(132)
425 tagOf_PrimOp SameMutableByteArrayOp = ILIT(133)
426 tagOf_PrimOp ReadArrayOp = ILIT(134)
427 tagOf_PrimOp WriteArrayOp = ILIT(135)
428 tagOf_PrimOp IndexArrayOp = ILIT(136)
430 tagOf_PrimOp (ReadByteArrayOp CharRep) = ILIT(137)
431 tagOf_PrimOp (ReadByteArrayOp IntRep) = ILIT(138)
432 tagOf_PrimOp (ReadByteArrayOp WordRep) = ILIT(139)
433 tagOf_PrimOp (ReadByteArrayOp AddrRep) = ILIT(140)
434 tagOf_PrimOp (ReadByteArrayOp FloatRep) = ILIT(141)
435 tagOf_PrimOp (ReadByteArrayOp DoubleRep) = ILIT(142)
436 tagOf_PrimOp (ReadByteArrayOp StablePtrRep) = ILIT(143)
437 tagOf_PrimOp (ReadByteArrayOp Int64Rep) = ILIT(144)
438 tagOf_PrimOp (ReadByteArrayOp Word64Rep) = ILIT(145)
440 tagOf_PrimOp (WriteByteArrayOp CharRep) = ILIT(146)
441 tagOf_PrimOp (WriteByteArrayOp IntRep) = ILIT(147)
442 tagOf_PrimOp (WriteByteArrayOp WordRep) = ILIT(148)
443 tagOf_PrimOp (WriteByteArrayOp AddrRep) = ILIT(149)
444 tagOf_PrimOp (WriteByteArrayOp FloatRep) = ILIT(150)
445 tagOf_PrimOp (WriteByteArrayOp DoubleRep) = ILIT(151)
446 tagOf_PrimOp (WriteByteArrayOp StablePtrRep) = ILIT(152)
447 tagOf_PrimOp (WriteByteArrayOp Int64Rep) = ILIT(153)
448 tagOf_PrimOp (WriteByteArrayOp Word64Rep) = ILIT(154)
450 tagOf_PrimOp (IndexByteArrayOp CharRep) = ILIT(155)
451 tagOf_PrimOp (IndexByteArrayOp IntRep) = ILIT(156)
452 tagOf_PrimOp (IndexByteArrayOp WordRep) = ILIT(157)
453 tagOf_PrimOp (IndexByteArrayOp AddrRep) = ILIT(158)
454 tagOf_PrimOp (IndexByteArrayOp FloatRep) = ILIT(159)
455 tagOf_PrimOp (IndexByteArrayOp DoubleRep) = ILIT(160)
456 tagOf_PrimOp (IndexByteArrayOp StablePtrRep) = ILIT(161)
457 tagOf_PrimOp (IndexByteArrayOp Int64Rep) = ILIT(162)
458 tagOf_PrimOp (IndexByteArrayOp Word64Rep) = ILIT(163)
460 tagOf_PrimOp (IndexOffAddrOp CharRep) = ILIT(164)
461 tagOf_PrimOp (IndexOffAddrOp IntRep) = ILIT(165)
462 tagOf_PrimOp (IndexOffAddrOp WordRep) = ILIT(166)
463 tagOf_PrimOp (IndexOffAddrOp AddrRep) = ILIT(167)
464 tagOf_PrimOp (IndexOffAddrOp FloatRep) = ILIT(168)
465 tagOf_PrimOp (IndexOffAddrOp DoubleRep) = ILIT(169)
466 tagOf_PrimOp (IndexOffAddrOp StablePtrRep) = ILIT(170)
467 tagOf_PrimOp (IndexOffAddrOp Int64Rep) = ILIT(171)
468 tagOf_PrimOp (IndexOffAddrOp Word64Rep) = ILIT(172)
469 tagOf_PrimOp (IndexOffForeignObjOp CharRep) = ILIT(173)
470 tagOf_PrimOp (IndexOffForeignObjOp IntRep) = ILIT(174)
471 tagOf_PrimOp (IndexOffForeignObjOp WordRep) = ILIT(175)
472 tagOf_PrimOp (IndexOffForeignObjOp AddrRep) = ILIT(176)
473 tagOf_PrimOp (IndexOffForeignObjOp FloatRep) = ILIT(177)
474 tagOf_PrimOp (IndexOffForeignObjOp DoubleRep) = ILIT(178)
475 tagOf_PrimOp (IndexOffForeignObjOp StablePtrRep) = ILIT(179)
476 tagOf_PrimOp (IndexOffForeignObjOp Int64Rep) = ILIT(180)
477 tagOf_PrimOp (IndexOffForeignObjOp Word64Rep) = ILIT(181)
479 tagOf_PrimOp (WriteOffAddrOp CharRep) = ILIT(182)
480 tagOf_PrimOp (WriteOffAddrOp IntRep) = ILIT(183)
481 tagOf_PrimOp (WriteOffAddrOp WordRep) = ILIT(184)
482 tagOf_PrimOp (WriteOffAddrOp AddrRep) = ILIT(185)
483 tagOf_PrimOp (WriteOffAddrOp FloatRep) = ILIT(186)
484 tagOf_PrimOp (WriteOffAddrOp DoubleRep) = ILIT(187)
485 tagOf_PrimOp (WriteOffAddrOp StablePtrRep) = ILIT(188)
486 tagOf_PrimOp (WriteOffAddrOp ForeignObjRep) = ILIT(189)
487 tagOf_PrimOp (WriteOffAddrOp Int64Rep) = ILIT(190)
488 tagOf_PrimOp (WriteOffAddrOp Word64Rep) = ILIT(191)
490 tagOf_PrimOp UnsafeFreezeArrayOp = ILIT(192)
491 tagOf_PrimOp UnsafeFreezeByteArrayOp = ILIT(193)
492 tagOf_PrimOp SizeofByteArrayOp = ILIT(194)
493 tagOf_PrimOp SizeofMutableByteArrayOp = ILIT(195)
494 tagOf_PrimOp NewMVarOp = ILIT(196)
495 tagOf_PrimOp TakeMVarOp = ILIT(197)
496 tagOf_PrimOp PutMVarOp = ILIT(198)
497 tagOf_PrimOp SameMVarOp = ILIT(199)
498 tagOf_PrimOp IsEmptyMVarOp = ILIT(200)
499 tagOf_PrimOp MakeForeignObjOp = ILIT(201)
500 tagOf_PrimOp WriteForeignObjOp = ILIT(202)
501 tagOf_PrimOp MkWeakOp = ILIT(203)
502 tagOf_PrimOp DeRefWeakOp = ILIT(204)
503 tagOf_PrimOp MakeStableNameOp = ILIT(205)
504 tagOf_PrimOp EqStableNameOp = ILIT(206)
505 tagOf_PrimOp StableNameToIntOp = ILIT(207)
506 tagOf_PrimOp MakeStablePtrOp = ILIT(208)
507 tagOf_PrimOp DeRefStablePtrOp = ILIT(209)
508 tagOf_PrimOp EqStablePtrOp = ILIT(210)
509 tagOf_PrimOp (CCallOp _ _ _ _) = ILIT(211)
510 tagOf_PrimOp ReallyUnsafePtrEqualityOp = ILIT(212)
511 tagOf_PrimOp SeqOp = ILIT(213)
512 tagOf_PrimOp ParOp = ILIT(214)
513 tagOf_PrimOp ForkOp = ILIT(215)
514 tagOf_PrimOp KillThreadOp = ILIT(216)
515 tagOf_PrimOp DelayOp = ILIT(217)
516 tagOf_PrimOp WaitReadOp = ILIT(218)
517 tagOf_PrimOp WaitWriteOp = ILIT(219)
518 tagOf_PrimOp ParGlobalOp = ILIT(220)
519 tagOf_PrimOp ParLocalOp = ILIT(221)
520 tagOf_PrimOp ParAtOp = ILIT(222)
521 tagOf_PrimOp ParAtAbsOp = ILIT(223)
522 tagOf_PrimOp ParAtRelOp = ILIT(224)
523 tagOf_PrimOp ParAtForNowOp = ILIT(225)
524 tagOf_PrimOp CopyableOp = ILIT(226)
525 tagOf_PrimOp NoFollowOp = ILIT(227)
526 tagOf_PrimOp NewMutVarOp = ILIT(228)
527 tagOf_PrimOp ReadMutVarOp = ILIT(229)
528 tagOf_PrimOp WriteMutVarOp = ILIT(230)
529 tagOf_PrimOp SameMutVarOp = ILIT(231)
530 tagOf_PrimOp CatchOp = ILIT(232)
531 tagOf_PrimOp RaiseOp = ILIT(233)
533 tagOf_PrimOp op = pprPanic# "tagOf_PrimOp: pattern-match" (ppr op)
534 --panic# "tagOf_PrimOp: pattern-match"
536 instance Eq PrimOp where
537 op1 == op2 = tagOf_PrimOp op1 _EQ_ tagOf_PrimOp op2
539 instance Ord PrimOp where
540 op1 < op2 = tagOf_PrimOp op1 _LT_ tagOf_PrimOp op2
541 op1 <= op2 = tagOf_PrimOp op1 _LE_ tagOf_PrimOp op2
542 op1 >= op2 = tagOf_PrimOp op1 _GE_ tagOf_PrimOp op2
543 op1 > op2 = tagOf_PrimOp op1 _GT_ tagOf_PrimOp op2
544 op1 `compare` op2 | op1 < op2 = LT
548 instance Outputable PrimOp where
549 ppr op = pprPrimOp op
551 instance Show PrimOp where
552 showsPrec p op = showsPrecSDoc p (pprPrimOp op)
555 An @Enum@-derived list would be better; meanwhile... (ToDo)
682 NewByteArrayOp CharRep,
683 NewByteArrayOp IntRep,
684 NewByteArrayOp WordRep,
685 NewByteArrayOp AddrRep,
686 NewByteArrayOp FloatRep,
687 NewByteArrayOp DoubleRep,
688 NewByteArrayOp StablePtrRep,
690 SameMutableByteArrayOp,
694 ReadByteArrayOp CharRep,
695 ReadByteArrayOp IntRep,
696 ReadByteArrayOp WordRep,
697 ReadByteArrayOp AddrRep,
698 ReadByteArrayOp FloatRep,
699 ReadByteArrayOp DoubleRep,
700 ReadByteArrayOp StablePtrRep,
701 ReadByteArrayOp Int64Rep,
702 ReadByteArrayOp Word64Rep,
703 WriteByteArrayOp CharRep,
704 WriteByteArrayOp IntRep,
705 WriteByteArrayOp WordRep,
706 WriteByteArrayOp AddrRep,
707 WriteByteArrayOp FloatRep,
708 WriteByteArrayOp DoubleRep,
709 WriteByteArrayOp StablePtrRep,
710 WriteByteArrayOp Int64Rep,
711 WriteByteArrayOp Word64Rep,
712 IndexByteArrayOp CharRep,
713 IndexByteArrayOp IntRep,
714 IndexByteArrayOp WordRep,
715 IndexByteArrayOp AddrRep,
716 IndexByteArrayOp FloatRep,
717 IndexByteArrayOp DoubleRep,
718 IndexByteArrayOp StablePtrRep,
719 IndexByteArrayOp Int64Rep,
720 IndexByteArrayOp Word64Rep,
721 IndexOffForeignObjOp CharRep,
722 IndexOffForeignObjOp AddrRep,
723 IndexOffForeignObjOp IntRep,
724 IndexOffForeignObjOp WordRep,
725 IndexOffForeignObjOp FloatRep,
726 IndexOffForeignObjOp DoubleRep,
727 IndexOffForeignObjOp StablePtrRep,
728 IndexOffForeignObjOp Int64Rep,
729 IndexOffForeignObjOp Word64Rep,
730 IndexOffAddrOp CharRep,
731 IndexOffAddrOp IntRep,
732 IndexOffAddrOp WordRep,
733 IndexOffAddrOp AddrRep,
734 IndexOffAddrOp FloatRep,
735 IndexOffAddrOp DoubleRep,
736 IndexOffAddrOp StablePtrRep,
737 IndexOffAddrOp Int64Rep,
738 IndexOffAddrOp Word64Rep,
739 WriteOffAddrOp CharRep,
740 WriteOffAddrOp IntRep,
741 WriteOffAddrOp WordRep,
742 WriteOffAddrOp AddrRep,
743 WriteOffAddrOp FloatRep,
744 WriteOffAddrOp DoubleRep,
745 WriteOffAddrOp ForeignObjRep,
746 WriteOffAddrOp StablePtrRep,
747 WriteOffAddrOp Int64Rep,
748 WriteOffAddrOp Word64Rep,
750 UnsafeFreezeByteArrayOp,
752 SizeofMutableByteArrayOp,
774 ReallyUnsafePtrEqualityOp,
793 %************************************************************************
795 \subsection[PrimOp-info]{The essential info about each @PrimOp@}
797 %************************************************************************
799 The @String@ in the @PrimOpInfos@ is the ``base name'' by which the user may
800 refer to the primitive operation. The conventional \tr{#}-for-
801 unboxed ops is added on later.
803 The reason for the funny characters in the names is so we do not
804 interfere with the programmer's Haskell name spaces.
806 We use @PrimKinds@ for the ``type'' information, because they're
807 (slightly) more convenient to use than @TyCons@.
810 = Dyadic OccName -- string :: T -> T -> T
812 | Monadic OccName -- string :: T -> T
814 | Compare OccName -- string :: T -> T -> Bool
817 | GenPrimOp OccName -- string :: \/a1..an . T1 -> .. -> Tk -> T
822 mkDyadic str ty = Dyadic (mkSrcVarOcc str) ty
823 mkMonadic str ty = Monadic (mkSrcVarOcc str) ty
824 mkCompare str ty = Compare (mkSrcVarOcc str) ty
825 mkGenPrimOp str tvs tys ty = GenPrimOp (mkSrcVarOcc str) tvs tys ty
830 one_Integer_ty = [intPrimTy, intPrimTy, byteArrayPrimTy]
832 = [intPrimTy, intPrimTy, byteArrayPrimTy, -- first Integer pieces
833 intPrimTy, intPrimTy, byteArrayPrimTy] -- second '' pieces
834 an_Integer_and_Int_tys
835 = [intPrimTy, intPrimTy, byteArrayPrimTy, -- Integer
838 unboxedPair = mkUnboxedTupleTy 2
839 unboxedTriple = mkUnboxedTupleTy 3
840 unboxedQuadruple = mkUnboxedTupleTy 4
841 unboxedSexTuple = mkUnboxedTupleTy 6
843 integerMonadic name = mkGenPrimOp name [] one_Integer_ty
844 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
846 integerDyadic name = mkGenPrimOp name [] two_Integer_tys
847 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
849 integerDyadic2Results name = mkGenPrimOp name [] two_Integer_tys
850 (unboxedSexTuple [intPrimTy, intPrimTy, byteArrayPrimTy,
851 intPrimTy, intPrimTy, byteArrayPrimTy])
853 integerCompare name = mkGenPrimOp name [] two_Integer_tys intPrimTy
856 %************************************************************************
858 \subsubsection{Strictness}
860 %************************************************************************
862 Not all primops are strict!
865 primOpStrictness :: PrimOp -> ([Demand], Bool)
866 -- See IdInfo.StrictnessInfo for discussion of what the results
867 -- **NB** as a cheap hack, to avoid having to look up the PrimOp's arity,
868 -- the list of demands may be infinite!
869 -- Use only the ones you ned.
871 primOpStrictness SeqOp = ([wwLazy], False)
872 primOpStrictness ParOp = ([wwLazy], False)
873 primOpStrictness ForkOp = ([wwLazy, wwPrim], False)
875 primOpStrictness NewArrayOp = ([wwPrim, wwLazy, wwPrim], False)
876 primOpStrictness WriteArrayOp = ([wwPrim, wwPrim, wwLazy, wwPrim], False)
878 primOpStrictness NewMutVarOp = ([wwLazy, wwPrim], False)
879 primOpStrictness WriteMutVarOp = ([wwPrim, wwLazy, wwPrim], False)
881 primOpStrictness PutMVarOp = ([wwPrim, wwLazy, wwPrim], False)
883 primOpStrictness CatchOp = ([wwLazy, wwLazy], False)
884 primOpStrictness RaiseOp = ([wwLazy], True) -- NB: True => result is bottom
886 primOpStrictness MkWeakOp = ([wwLazy, wwLazy, wwLazy, wwPrim], False)
887 primOpStrictness MakeStableNameOp = ([wwLazy, wwPrim], False)
888 primOpStrictness MakeStablePtrOp = ([wwLazy, wwPrim], False)
890 -- The rest all have primitive-typed arguments
891 primOpStrictness other = (repeat wwPrim, False)
894 %************************************************************************
896 \subsubsection[PrimOp-comparison]{PrimOpInfo basic comparison ops}
898 %************************************************************************
900 @primOpInfo@ gives all essential information (from which everything
901 else, notably a type, can be constructed) for each @PrimOp@.
904 primOpInfo :: PrimOp -> PrimOpInfo
907 There's plenty of this stuff!
910 primOpInfo CharGtOp = mkCompare SLIT("gtChar#") charPrimTy
911 primOpInfo CharGeOp = mkCompare SLIT("geChar#") charPrimTy
912 primOpInfo CharEqOp = mkCompare SLIT("eqChar#") charPrimTy
913 primOpInfo CharNeOp = mkCompare SLIT("neChar#") charPrimTy
914 primOpInfo CharLtOp = mkCompare SLIT("ltChar#") charPrimTy
915 primOpInfo CharLeOp = mkCompare SLIT("leChar#") charPrimTy
917 primOpInfo IntGtOp = mkCompare SLIT(">#") intPrimTy
918 primOpInfo IntGeOp = mkCompare SLIT(">=#") intPrimTy
919 primOpInfo IntEqOp = mkCompare SLIT("==#") intPrimTy
920 primOpInfo IntNeOp = mkCompare SLIT("/=#") intPrimTy
921 primOpInfo IntLtOp = mkCompare SLIT("<#") intPrimTy
922 primOpInfo IntLeOp = mkCompare SLIT("<=#") intPrimTy
924 primOpInfo WordGtOp = mkCompare SLIT("gtWord#") wordPrimTy
925 primOpInfo WordGeOp = mkCompare SLIT("geWord#") wordPrimTy
926 primOpInfo WordEqOp = mkCompare SLIT("eqWord#") wordPrimTy
927 primOpInfo WordNeOp = mkCompare SLIT("neWord#") wordPrimTy
928 primOpInfo WordLtOp = mkCompare SLIT("ltWord#") wordPrimTy
929 primOpInfo WordLeOp = mkCompare SLIT("leWord#") wordPrimTy
931 primOpInfo AddrGtOp = mkCompare SLIT("gtAddr#") addrPrimTy
932 primOpInfo AddrGeOp = mkCompare SLIT("geAddr#") addrPrimTy
933 primOpInfo AddrEqOp = mkCompare SLIT("eqAddr#") addrPrimTy
934 primOpInfo AddrNeOp = mkCompare SLIT("neAddr#") addrPrimTy
935 primOpInfo AddrLtOp = mkCompare SLIT("ltAddr#") addrPrimTy
936 primOpInfo AddrLeOp = mkCompare SLIT("leAddr#") addrPrimTy
938 primOpInfo FloatGtOp = mkCompare SLIT("gtFloat#") floatPrimTy
939 primOpInfo FloatGeOp = mkCompare SLIT("geFloat#") floatPrimTy
940 primOpInfo FloatEqOp = mkCompare SLIT("eqFloat#") floatPrimTy
941 primOpInfo FloatNeOp = mkCompare SLIT("neFloat#") floatPrimTy
942 primOpInfo FloatLtOp = mkCompare SLIT("ltFloat#") floatPrimTy
943 primOpInfo FloatLeOp = mkCompare SLIT("leFloat#") floatPrimTy
945 primOpInfo DoubleGtOp = mkCompare SLIT(">##") doublePrimTy
946 primOpInfo DoubleGeOp = mkCompare SLIT(">=##") doublePrimTy
947 primOpInfo DoubleEqOp = mkCompare SLIT("==##") doublePrimTy
948 primOpInfo DoubleNeOp = mkCompare SLIT("/=##") doublePrimTy
949 primOpInfo DoubleLtOp = mkCompare SLIT("<##") doublePrimTy
950 primOpInfo DoubleLeOp = mkCompare SLIT("<=##") doublePrimTy
954 %************************************************************************
956 \subsubsection[PrimOp-Char]{PrimOpInfo for @Char#@s}
958 %************************************************************************
961 primOpInfo OrdOp = mkGenPrimOp SLIT("ord#") [] [charPrimTy] intPrimTy
962 primOpInfo ChrOp = mkGenPrimOp SLIT("chr#") [] [intPrimTy] charPrimTy
965 %************************************************************************
967 \subsubsection[PrimOp-Int]{PrimOpInfo for @Int#@s}
969 %************************************************************************
972 primOpInfo IntAddOp = mkDyadic SLIT("+#") intPrimTy
973 primOpInfo IntSubOp = mkDyadic SLIT("-#") intPrimTy
974 primOpInfo IntMulOp = mkDyadic SLIT("*#") intPrimTy
975 primOpInfo IntQuotOp = mkDyadic SLIT("quotInt#") intPrimTy
976 primOpInfo IntRemOp = mkDyadic SLIT("remInt#") intPrimTy
978 primOpInfo IntNegOp = mkMonadic SLIT("negateInt#") intPrimTy
979 primOpInfo IntAbsOp = mkMonadic SLIT("absInt#") intPrimTy
982 %************************************************************************
984 \subsubsection[PrimOp-Word]{PrimOpInfo for @Word#@s}
986 %************************************************************************
988 A @Word#@ is an unsigned @Int#@.
991 primOpInfo WordQuotOp = mkDyadic SLIT("quotWord#") wordPrimTy
992 primOpInfo WordRemOp = mkDyadic SLIT("remWord#") wordPrimTy
994 primOpInfo AndOp = mkDyadic SLIT("and#") wordPrimTy
995 primOpInfo OrOp = mkDyadic SLIT("or#") wordPrimTy
996 primOpInfo XorOp = mkDyadic SLIT("xor#") wordPrimTy
997 primOpInfo NotOp = mkMonadic SLIT("not#") wordPrimTy
1000 = mkGenPrimOp SLIT("shiftL#") [] [wordPrimTy, intPrimTy] wordPrimTy
1002 = mkGenPrimOp SLIT("shiftRL#") [] [wordPrimTy, intPrimTy] wordPrimTy
1005 = mkGenPrimOp SLIT("iShiftL#") [] [intPrimTy, intPrimTy] intPrimTy
1007 = mkGenPrimOp SLIT("iShiftRA#") [] [intPrimTy, intPrimTy] intPrimTy
1009 = mkGenPrimOp SLIT("iShiftRL#") [] [intPrimTy, intPrimTy] intPrimTy
1011 primOpInfo Int2WordOp = mkGenPrimOp SLIT("int2Word#") [] [intPrimTy] wordPrimTy
1012 primOpInfo Word2IntOp = mkGenPrimOp SLIT("word2Int#") [] [wordPrimTy] intPrimTy
1015 %************************************************************************
1017 \subsubsection[PrimOp-Addr]{PrimOpInfo for @Addr#@s}
1019 %************************************************************************
1022 primOpInfo Int2AddrOp = mkGenPrimOp SLIT("int2Addr#") [] [intPrimTy] addrPrimTy
1023 primOpInfo Addr2IntOp = mkGenPrimOp SLIT("addr2Int#") [] [addrPrimTy] intPrimTy
1027 %************************************************************************
1029 \subsubsection[PrimOp-Float]{PrimOpInfo for @Float#@s}
1031 %************************************************************************
1033 @encodeFloat#@ and @decodeFloat#@ are given w/ Integer-stuff (it's
1037 primOpInfo FloatAddOp = mkDyadic SLIT("plusFloat#") floatPrimTy
1038 primOpInfo FloatSubOp = mkDyadic SLIT("minusFloat#") floatPrimTy
1039 primOpInfo FloatMulOp = mkDyadic SLIT("timesFloat#") floatPrimTy
1040 primOpInfo FloatDivOp = mkDyadic SLIT("divideFloat#") floatPrimTy
1041 primOpInfo FloatNegOp = mkMonadic SLIT("negateFloat#") floatPrimTy
1043 primOpInfo Float2IntOp = mkGenPrimOp SLIT("float2Int#") [] [floatPrimTy] intPrimTy
1044 primOpInfo Int2FloatOp = mkGenPrimOp SLIT("int2Float#") [] [intPrimTy] floatPrimTy
1046 primOpInfo FloatExpOp = mkMonadic SLIT("expFloat#") floatPrimTy
1047 primOpInfo FloatLogOp = mkMonadic SLIT("logFloat#") floatPrimTy
1048 primOpInfo FloatSqrtOp = mkMonadic SLIT("sqrtFloat#") floatPrimTy
1049 primOpInfo FloatSinOp = mkMonadic SLIT("sinFloat#") floatPrimTy
1050 primOpInfo FloatCosOp = mkMonadic SLIT("cosFloat#") floatPrimTy
1051 primOpInfo FloatTanOp = mkMonadic SLIT("tanFloat#") floatPrimTy
1052 primOpInfo FloatAsinOp = mkMonadic SLIT("asinFloat#") floatPrimTy
1053 primOpInfo FloatAcosOp = mkMonadic SLIT("acosFloat#") floatPrimTy
1054 primOpInfo FloatAtanOp = mkMonadic SLIT("atanFloat#") floatPrimTy
1055 primOpInfo FloatSinhOp = mkMonadic SLIT("sinhFloat#") floatPrimTy
1056 primOpInfo FloatCoshOp = mkMonadic SLIT("coshFloat#") floatPrimTy
1057 primOpInfo FloatTanhOp = mkMonadic SLIT("tanhFloat#") floatPrimTy
1058 primOpInfo FloatPowerOp = mkDyadic SLIT("powerFloat#") floatPrimTy
1061 %************************************************************************
1063 \subsubsection[PrimOp-Double]{PrimOpInfo for @Double#@s}
1065 %************************************************************************
1067 @encodeDouble#@ and @decodeDouble#@ are given w/ Integer-stuff (it's
1071 primOpInfo DoubleAddOp = mkDyadic SLIT("+##") doublePrimTy
1072 primOpInfo DoubleSubOp = mkDyadic SLIT("-##") doublePrimTy
1073 primOpInfo DoubleMulOp = mkDyadic SLIT("*##") doublePrimTy
1074 primOpInfo DoubleDivOp = mkDyadic SLIT("/##") doublePrimTy
1075 primOpInfo DoubleNegOp = mkMonadic SLIT("negateDouble#") doublePrimTy
1077 primOpInfo Double2IntOp = mkGenPrimOp SLIT("double2Int#") [] [doublePrimTy] intPrimTy
1078 primOpInfo Int2DoubleOp = mkGenPrimOp SLIT("int2Double#") [] [intPrimTy] doublePrimTy
1080 primOpInfo Double2FloatOp = mkGenPrimOp SLIT("double2Float#") [] [doublePrimTy] floatPrimTy
1081 primOpInfo Float2DoubleOp = mkGenPrimOp SLIT("float2Double#") [] [floatPrimTy] doublePrimTy
1083 primOpInfo DoubleExpOp = mkMonadic SLIT("expDouble#") doublePrimTy
1084 primOpInfo DoubleLogOp = mkMonadic SLIT("logDouble#") doublePrimTy
1085 primOpInfo DoubleSqrtOp = mkMonadic SLIT("sqrtDouble#") doublePrimTy
1086 primOpInfo DoubleSinOp = mkMonadic SLIT("sinDouble#") doublePrimTy
1087 primOpInfo DoubleCosOp = mkMonadic SLIT("cosDouble#") doublePrimTy
1088 primOpInfo DoubleTanOp = mkMonadic SLIT("tanDouble#") doublePrimTy
1089 primOpInfo DoubleAsinOp = mkMonadic SLIT("asinDouble#") doublePrimTy
1090 primOpInfo DoubleAcosOp = mkMonadic SLIT("acosDouble#") doublePrimTy
1091 primOpInfo DoubleAtanOp = mkMonadic SLIT("atanDouble#") doublePrimTy
1092 primOpInfo DoubleSinhOp = mkMonadic SLIT("sinhDouble#") doublePrimTy
1093 primOpInfo DoubleCoshOp = mkMonadic SLIT("coshDouble#") doublePrimTy
1094 primOpInfo DoubleTanhOp = mkMonadic SLIT("tanhDouble#") doublePrimTy
1095 primOpInfo DoublePowerOp= mkDyadic SLIT("**##") doublePrimTy
1098 %************************************************************************
1100 \subsubsection[PrimOp-Integer]{PrimOpInfo for @Integer@ (and related!)}
1102 %************************************************************************
1105 primOpInfo IntegerNegOp = integerMonadic SLIT("negateInteger#")
1107 primOpInfo IntegerAddOp = integerDyadic SLIT("plusInteger#")
1108 primOpInfo IntegerSubOp = integerDyadic SLIT("minusInteger#")
1109 primOpInfo IntegerMulOp = integerDyadic SLIT("timesInteger#")
1110 primOpInfo IntegerGcdOp = integerDyadic SLIT("gcdInteger#")
1112 primOpInfo IntegerCmpOp = integerCompare SLIT("cmpInteger#")
1114 primOpInfo IntegerQuotRemOp = integerDyadic2Results SLIT("quotRemInteger#")
1115 primOpInfo IntegerDivModOp = integerDyadic2Results SLIT("divModInteger#")
1117 primOpInfo Integer2IntOp
1118 = mkGenPrimOp SLIT("integer2Int#") [] one_Integer_ty intPrimTy
1120 primOpInfo Integer2WordOp
1121 = mkGenPrimOp SLIT("integer2Word#") [] one_Integer_ty wordPrimTy
1123 primOpInfo Int2IntegerOp
1124 = mkGenPrimOp SLIT("int2Integer#") [] [intPrimTy]
1125 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1127 primOpInfo Word2IntegerOp
1128 = mkGenPrimOp SLIT("word2Integer#") [] [wordPrimTy]
1129 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1131 primOpInfo Addr2IntegerOp
1132 = mkGenPrimOp SLIT("addr2Integer#") [] [addrPrimTy]
1133 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1135 primOpInfo IntegerToInt64Op
1136 = mkGenPrimOp SLIT("integerToInt64#") [] one_Integer_ty int64PrimTy
1138 primOpInfo Int64ToIntegerOp
1139 = mkGenPrimOp SLIT("int64ToInteger#") [] [int64PrimTy]
1140 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1142 primOpInfo Word64ToIntegerOp
1143 = mkGenPrimOp SLIT("word64ToInteger#") [] [word64PrimTy]
1144 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1146 primOpInfo IntegerToWord64Op
1147 = mkGenPrimOp SLIT("integerToWord64#") [] one_Integer_ty word64PrimTy
1150 Encoding and decoding of floating-point numbers is sorta
1154 primOpInfo FloatEncodeOp
1155 = mkGenPrimOp SLIT("encodeFloat#") [] an_Integer_and_Int_tys floatPrimTy
1157 primOpInfo DoubleEncodeOp
1158 = mkGenPrimOp SLIT("encodeDouble#") [] an_Integer_and_Int_tys doublePrimTy
1160 primOpInfo FloatDecodeOp
1161 = mkGenPrimOp SLIT("decodeFloat#") [] [floatPrimTy]
1162 (unboxedQuadruple [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy])
1163 primOpInfo DoubleDecodeOp
1164 = mkGenPrimOp SLIT("decodeDouble#") [] [doublePrimTy]
1165 (unboxedQuadruple [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy])
1168 %************************************************************************
1170 \subsubsection[PrimOp-Arrays]{PrimOpInfo for primitive arrays}
1172 %************************************************************************
1175 primOpInfo NewArrayOp
1177 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1178 state = mkStatePrimTy s
1180 mkGenPrimOp SLIT("newArray#") [s_tv, elt_tv]
1181 [intPrimTy, elt, state]
1182 (unboxedPair [state, mkMutableArrayPrimTy s elt])
1184 primOpInfo (NewByteArrayOp kind)
1186 s = alphaTy; s_tv = alphaTyVar
1188 op_str = _PK_ ("new" ++ primRepString kind ++ "Array#")
1189 state = mkStatePrimTy s
1191 mkGenPrimOp op_str [s_tv]
1193 (unboxedPair [state, mkMutableByteArrayPrimTy s])
1195 ---------------------------------------------------------------------------
1197 primOpInfo SameMutableArrayOp
1199 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1200 mut_arr_ty = mkMutableArrayPrimTy s elt
1202 mkGenPrimOp SLIT("sameMutableArray#") [s_tv, elt_tv] [mut_arr_ty, mut_arr_ty]
1205 primOpInfo SameMutableByteArrayOp
1207 s = alphaTy; s_tv = alphaTyVar;
1208 mut_arr_ty = mkMutableByteArrayPrimTy s
1210 mkGenPrimOp SLIT("sameMutableByteArray#") [s_tv] [mut_arr_ty, mut_arr_ty]
1213 ---------------------------------------------------------------------------
1214 -- Primitive arrays of Haskell pointers:
1216 primOpInfo ReadArrayOp
1218 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1219 state = mkStatePrimTy s
1221 mkGenPrimOp SLIT("readArray#") [s_tv, elt_tv]
1222 [mkMutableArrayPrimTy s elt, intPrimTy, state]
1223 (unboxedPair [state, elt])
1226 primOpInfo WriteArrayOp
1228 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1230 mkGenPrimOp SLIT("writeArray#") [s_tv, elt_tv]
1231 [mkMutableArrayPrimTy s elt, intPrimTy, elt, mkStatePrimTy s]
1234 primOpInfo IndexArrayOp
1235 = let { elt = alphaTy; elt_tv = alphaTyVar } in
1236 mkGenPrimOp SLIT("indexArray#") [elt_tv] [mkArrayPrimTy elt, intPrimTy]
1237 (unboxedPair [realWorldStatePrimTy, elt])
1239 ---------------------------------------------------------------------------
1240 -- Primitive arrays full of unboxed bytes:
1242 primOpInfo (ReadByteArrayOp kind)
1244 s = alphaTy; s_tv = alphaTyVar
1246 op_str = _PK_ ("read" ++ primRepString kind ++ "Array#")
1247 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1248 state = mkStatePrimTy s
1250 mkGenPrimOp op_str (s_tv:tvs)
1251 [mkMutableByteArrayPrimTy s, intPrimTy, state]
1252 (unboxedPair [state, prim_ty])
1254 primOpInfo (WriteByteArrayOp kind)
1256 s = alphaTy; s_tv = alphaTyVar
1257 op_str = _PK_ ("write" ++ primRepString kind ++ "Array#")
1258 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1260 mkGenPrimOp op_str (s_tv:tvs)
1261 [mkMutableByteArrayPrimTy s, intPrimTy, prim_ty, mkStatePrimTy s]
1264 primOpInfo (IndexByteArrayOp kind)
1266 op_str = _PK_ ("index" ++ primRepString kind ++ "Array#")
1267 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1269 mkGenPrimOp op_str tvs [byteArrayPrimTy, intPrimTy] prim_ty
1271 primOpInfo (IndexOffForeignObjOp kind)
1273 op_str = _PK_ ("index" ++ primRepString kind ++ "OffForeignObj#")
1274 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1276 mkGenPrimOp op_str tvs [foreignObjPrimTy, intPrimTy] prim_ty
1278 primOpInfo (IndexOffAddrOp kind)
1280 op_str = _PK_ ("index" ++ primRepString kind ++ "OffAddr#")
1281 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1283 mkGenPrimOp op_str tvs [addrPrimTy, intPrimTy] prim_ty
1285 primOpInfo (WriteOffAddrOp kind)
1287 s = alphaTy; s_tv = alphaTyVar
1288 op_str = _PK_ ("write" ++ primRepString kind ++ "OffAddr#")
1289 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1291 mkGenPrimOp op_str (s_tv:tvs)
1292 [addrPrimTy, intPrimTy, prim_ty, mkStatePrimTy s]
1295 ---------------------------------------------------------------------------
1296 primOpInfo UnsafeFreezeArrayOp
1298 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1299 state = mkStatePrimTy s
1301 mkGenPrimOp SLIT("unsafeFreezeArray#") [s_tv, elt_tv]
1302 [mkMutableArrayPrimTy s elt, state]
1303 (unboxedPair [state, mkArrayPrimTy elt])
1305 primOpInfo UnsafeFreezeByteArrayOp
1307 s = alphaTy; s_tv = alphaTyVar;
1308 state = mkStatePrimTy s
1310 mkGenPrimOp SLIT("unsafeFreezeByteArray#") [s_tv]
1311 [mkMutableByteArrayPrimTy s, state]
1312 (unboxedPair [state, byteArrayPrimTy])
1314 ---------------------------------------------------------------------------
1315 primOpInfo SizeofByteArrayOp
1317 SLIT("sizeofByteArray#") []
1321 primOpInfo SizeofMutableByteArrayOp
1322 = let { s = alphaTy; s_tv = alphaTyVar } in
1324 SLIT("sizeofMutableByteArray#") [s_tv]
1325 [mkMutableByteArrayPrimTy s]
1330 %************************************************************************
1332 \subsubsection[PrimOp-MutVars]{PrimOpInfo for mutable variable ops}
1334 %************************************************************************
1337 primOpInfo NewMutVarOp
1339 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1340 state = mkStatePrimTy s
1342 mkGenPrimOp SLIT("newMutVar#") [s_tv, elt_tv]
1344 (unboxedPair [state, mkMutVarPrimTy s elt])
1346 primOpInfo ReadMutVarOp
1348 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1349 state = mkStatePrimTy s
1351 mkGenPrimOp SLIT("readMutVar#") [s_tv, elt_tv]
1352 [mkMutVarPrimTy s elt, state]
1353 (unboxedPair [state, elt])
1356 primOpInfo WriteMutVarOp
1358 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1360 mkGenPrimOp SLIT("writeMutVar#") [s_tv, elt_tv]
1361 [mkMutVarPrimTy s elt, elt, mkStatePrimTy s]
1364 primOpInfo SameMutVarOp
1366 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1367 mut_var_ty = mkMutVarPrimTy s elt
1369 mkGenPrimOp SLIT("sameMutVar#") [s_tv, elt_tv] [mut_var_ty, mut_var_ty]
1373 %************************************************************************
1375 \subsubsection[PrimOp-Exceptions]{PrimOpInfo for exceptions}
1377 %************************************************************************
1379 catch :: IO a -> (IOError -> IO a) -> IO a
1380 catch :: a -> (b -> a) -> a
1385 a = alphaTy; a_tv = alphaTyVar
1386 b = betaTy; b_tv = betaTyVar;
1388 mkGenPrimOp SLIT("catch#") [a_tv, b_tv] [a, mkFunTy b a] a
1392 a = alphaTy; a_tv = alphaTyVar
1393 b = betaTy; b_tv = betaTyVar;
1395 mkGenPrimOp SLIT("raise#") [a_tv, b_tv] [a] b
1398 %************************************************************************
1400 \subsubsection[PrimOp-MVars]{PrimOpInfo for synchronizing Variables}
1402 %************************************************************************
1405 primOpInfo NewMVarOp
1407 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1408 state = mkStatePrimTy s
1410 mkGenPrimOp SLIT("newMVar#") [s_tv, elt_tv] [state]
1411 (unboxedPair [state, mkMVarPrimTy s elt])
1413 primOpInfo TakeMVarOp
1415 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1416 state = mkStatePrimTy s
1418 mkGenPrimOp SLIT("takeMVar#") [s_tv, elt_tv]
1419 [mkMVarPrimTy s elt, state]
1420 (unboxedPair [state, elt])
1422 primOpInfo PutMVarOp
1424 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1426 mkGenPrimOp SLIT("putMVar#") [s_tv, elt_tv]
1427 [mkMVarPrimTy s elt, elt, mkStatePrimTy s]
1430 primOpInfo SameMVarOp
1432 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1433 mvar_ty = mkMVarPrimTy s elt
1435 mkGenPrimOp SLIT("sameMVar#") [s_tv, elt_tv] [mvar_ty, mvar_ty] boolTy
1437 primOpInfo IsEmptyMVarOp
1439 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1440 state = mkStatePrimTy s
1442 mkGenPrimOp SLIT("isEmptyMVar#") [s_tv, elt_tv]
1443 [mkMVarPrimTy s elt, mkStatePrimTy s]
1444 (unboxedPair [state, intPrimTy])
1448 %************************************************************************
1450 \subsubsection[PrimOp-Wait]{PrimOpInfo for delay/wait operations}
1452 %************************************************************************
1458 s = alphaTy; s_tv = alphaTyVar
1460 mkGenPrimOp SLIT("delay#") [s_tv]
1461 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1463 primOpInfo WaitReadOp
1465 s = alphaTy; s_tv = alphaTyVar
1467 mkGenPrimOp SLIT("waitRead#") [s_tv]
1468 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1470 primOpInfo WaitWriteOp
1472 s = alphaTy; s_tv = alphaTyVar
1474 mkGenPrimOp SLIT("waitWrite#") [s_tv]
1475 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1478 %************************************************************************
1480 \subsubsection[PrimOp-Concurrency]{Concurrency Primitives}
1482 %************************************************************************
1485 -- fork# :: a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1487 = mkGenPrimOp SLIT("fork#") [alphaTyVar]
1488 [alphaTy, realWorldStatePrimTy]
1489 (unboxedPair [realWorldStatePrimTy, threadIdPrimTy])
1491 -- killThread# :: ThreadId# -> State# RealWorld -> State# RealWorld
1492 primOpInfo KillThreadOp
1493 = mkGenPrimOp SLIT("killThread#") []
1494 [threadIdPrimTy, realWorldStatePrimTy]
1495 realWorldStatePrimTy
1498 ************************************************************************
1500 \subsubsection[PrimOps-Foreign]{PrimOpInfo for Foreign Objects}
1502 %************************************************************************
1505 primOpInfo MakeForeignObjOp
1506 = mkGenPrimOp SLIT("makeForeignObj#") []
1507 [addrPrimTy, realWorldStatePrimTy]
1508 (unboxedPair [realWorldStatePrimTy, foreignObjPrimTy])
1510 primOpInfo WriteForeignObjOp
1512 s = alphaTy; s_tv = alphaTyVar
1514 mkGenPrimOp SLIT("writeForeignObj#") [s_tv]
1515 [foreignObjPrimTy, addrPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1518 ************************************************************************
1520 \subsubsection[PrimOps-Weak]{PrimOpInfo for Weak Pointers}
1522 %************************************************************************
1524 A @Weak@ Pointer is created by the @mkWeak#@ primitive:
1526 mkWeak# :: k -> v -> f -> State# RealWorld
1527 -> (# State# RealWorld, Weak# v #)
1529 In practice, you'll use the higher-level
1531 data Weak v = Weak# v
1532 mkWeak :: k -> v -> IO () -> IO (Weak v)
1536 = mkGenPrimOp SLIT("mkWeak#") [alphaTyVar, betaTyVar, gammaTyVar]
1537 [alphaTy, betaTy, gammaTy, realWorldStatePrimTy]
1538 (unboxedPair [realWorldStatePrimTy, mkWeakPrimTy betaTy])
1541 The following operation dereferences a weak pointer. The weak pointer
1542 may have been finalised, so the operation returns a result code which
1543 must be inspected before looking at the dereferenced value.
1545 deRefWeak# :: Weak# v -> State# RealWorld ->
1546 (# State# RealWorld, v, Int# #)
1548 Only look at v if the Int# returned is /= 0 !!
1550 The higher-level op is
1552 deRefWeak :: Weak v -> IO (Maybe v)
1555 primOpInfo DeRefWeakOp
1556 = mkGenPrimOp SLIT("deRefWeak#") [alphaTyVar]
1557 [mkWeakPrimTy alphaTy, realWorldStatePrimTy]
1558 (unboxedTriple [realWorldStatePrimTy, intPrimTy, alphaTy])
1561 %************************************************************************
1563 \subsubsection[PrimOp-stable-pointers]{PrimOpInfo for stable pointers and stable names}
1565 %************************************************************************
1567 A {\em stable name/pointer} is an index into a table of stable name
1568 entries. Since the garbage collector is told about stable pointers,
1569 it is safe to pass a stable pointer to external systems such as C
1573 makeStablePtr# :: a -> State# RealWorld -> (# State# RealWorld, a #)
1574 freeStablePtr :: StablePtr# a -> State# RealWorld -> State# RealWorld
1575 deRefStablePtr# :: StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1576 eqStablePtr# :: StablePtr# a -> StablePtr# a -> Int#
1579 It may seem a bit surprising that @makeStablePtr#@ is a @IO@
1580 operation since it doesn't (directly) involve IO operations. The
1581 reason is that if some optimisation pass decided to duplicate calls to
1582 @makeStablePtr#@ and we only pass one of the stable pointers over, a
1583 massive space leak can result. Putting it into the IO monad
1584 prevents this. (Another reason for putting them in a monad is to
1585 ensure correct sequencing wrt the side-effecting @freeStablePtr@
1588 An important property of stable pointers is that if you call
1589 makeStablePtr# twice on the same object you get the same stable
1592 Note that we can implement @freeStablePtr#@ using @_ccall_@ (and,
1593 besides, it's not likely to be used from Haskell) so it's not a
1596 Question: Why @RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
1601 A stable name is like a stable pointer, but with three important differences:
1603 (a) You can't deRef one to get back to the original object.
1604 (b) You can convert one to an Int.
1605 (c) You don't need to 'freeStableName'
1607 The existence of a stable name doesn't guarantee to keep the object it
1608 points to alive (unlike a stable pointer), hence (a).
1612 (a) makeStableName always returns the same value for a given
1613 object (same as stable pointers).
1615 (b) if two stable names are equal, it implies that the objects
1616 from which they were created were the same.
1618 (c) stableNameToInt always returns the same Int for a given
1622 primOpInfo MakeStablePtrOp
1623 = mkGenPrimOp SLIT("makeStablePtr#") [alphaTyVar]
1624 [alphaTy, realWorldStatePrimTy]
1625 (unboxedPair [realWorldStatePrimTy,
1626 mkTyConApp stablePtrPrimTyCon [alphaTy]])
1628 primOpInfo DeRefStablePtrOp
1629 = mkGenPrimOp SLIT("deRefStablePtr#") [alphaTyVar]
1630 [mkStablePtrPrimTy alphaTy, realWorldStatePrimTy]
1631 (unboxedPair [realWorldStatePrimTy, alphaTy])
1633 primOpInfo EqStablePtrOp
1634 = mkGenPrimOp SLIT("eqStablePtr#") [alphaTyVar, betaTyVar]
1635 [mkStablePtrPrimTy alphaTy, mkStablePtrPrimTy betaTy]
1638 primOpInfo MakeStableNameOp
1639 = mkGenPrimOp SLIT("makeStableName#") [alphaTyVar]
1640 [alphaTy, realWorldStatePrimTy]
1641 (unboxedPair [realWorldStatePrimTy,
1642 mkTyConApp stableNamePrimTyCon [alphaTy]])
1644 primOpInfo EqStableNameOp
1645 = mkGenPrimOp SLIT("eqStableName#") [alphaTyVar, betaTyVar]
1646 [mkStableNamePrimTy alphaTy, mkStableNamePrimTy betaTy]
1649 primOpInfo StableNameToIntOp
1650 = mkGenPrimOp SLIT("stableNameToInt#") [alphaTyVar]
1651 [mkStableNamePrimTy alphaTy]
1655 %************************************************************************
1657 \subsubsection[PrimOp-unsafePointerEquality]{PrimOpInfo for Pointer Equality}
1659 %************************************************************************
1661 [Alastair Reid is to blame for this!]
1663 These days, (Glasgow) Haskell seems to have a bit of everything from
1664 other languages: strict operations, mutable variables, sequencing,
1665 pointers, etc. About the only thing left is LISP's ability to test
1666 for pointer equality. So, let's add it in!
1669 reallyUnsafePtrEquality :: a -> a -> Int#
1672 which tests any two closures (of the same type) to see if they're the
1673 same. (Returns $0$ for @False@, $\neq 0$ for @True@ - to avoid
1674 difficulties of trying to box up the result.)
1676 NB This is {\em really unsafe\/} because even something as trivial as
1677 a garbage collection might change the answer by removing indirections.
1678 Still, no-one's forcing you to use it. If you're worried about little
1679 things like loss of referential transparency, you might like to wrap
1680 it all up in a monad-like thing as John O'Donnell and John Hughes did
1681 for non-determinism (1989 (Fraserburgh) Glasgow FP Workshop
1684 I'm thinking of using it to speed up a critical equality test in some
1685 graphics stuff in a context where the possibility of saying that
1686 denotationally equal things aren't isn't a problem (as long as it
1687 doesn't happen too often.) ADR
1689 To Will: Jim said this was already in, but I can't see it so I'm
1690 adding it. Up to you whether you add it. (Note that this could have
1691 been readily implemented using a @veryDangerousCCall@ before they were
1695 primOpInfo ReallyUnsafePtrEqualityOp
1696 = mkGenPrimOp SLIT("reallyUnsafePtrEquality#") [alphaTyVar]
1697 [alphaTy, alphaTy] intPrimTy
1700 %************************************************************************
1702 \subsubsection[PrimOp-parallel]{PrimOpInfo for parallelism op(s)}
1704 %************************************************************************
1707 primOpInfo SeqOp -- seq# :: a -> Int#
1708 = mkGenPrimOp SLIT("seq#") [alphaTyVar] [alphaTy] intPrimTy
1710 primOpInfo ParOp -- par# :: a -> Int#
1711 = mkGenPrimOp SLIT("par#") [alphaTyVar] [alphaTy] intPrimTy
1715 -- HWL: The first 4 Int# in all par... annotations denote:
1716 -- name, granularity info, size of result, degree of parallelism
1717 -- Same structure as _seq_ i.e. returns Int#
1719 primOpInfo ParGlobalOp -- parGlobal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1720 = mkGenPrimOp SLIT("parGlobal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1722 primOpInfo ParLocalOp -- parLocal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1723 = mkGenPrimOp SLIT("parLocal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1725 primOpInfo ParAtOp -- parAt# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1726 = mkGenPrimOp SLIT("parAt#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
1728 primOpInfo ParAtAbsOp -- parAtAbs# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1729 = mkGenPrimOp SLIT("parAtAbs#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1731 primOpInfo ParAtRelOp -- parAtRel# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1732 = mkGenPrimOp SLIT("parAtRel#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1734 primOpInfo ParAtForNowOp -- parAtForNow# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1735 = mkGenPrimOp SLIT("parAtForNow#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
1737 primOpInfo CopyableOp -- copyable# :: a -> a
1738 = mkGenPrimOp SLIT("copyable#") [alphaTyVar] [alphaTy] intPrimTy
1740 primOpInfo NoFollowOp -- noFollow# :: a -> a
1741 = mkGenPrimOp SLIT("noFollow#") [alphaTyVar] [alphaTy] intPrimTy
1744 %************************************************************************
1746 \subsubsection[PrimOp-IO-etc]{PrimOpInfo for C calls, and I/O-ish things}
1748 %************************************************************************
1751 primOpInfo (CCallOp _ _ _ _)
1752 = mkGenPrimOp SLIT("ccall#") [alphaTyVar] [] alphaTy
1755 primOpInfo (CCallOp _ _ _ _ arg_tys result_ty)
1756 = mkGenPrimOp SLIT("ccall#") [] arg_tys result_tycon tys_applied
1758 (result_tycon, tys_applied, _) = splitAlgTyConApp result_ty
1761 primOpInfo op = panic ("primOpInfo:"++ show (I# (tagOf_PrimOp op)))
1765 Some PrimOps need to be called out-of-line because they either need to
1766 perform a heap check or they block.
1779 NewByteArrayOp _ -> True
1780 IntegerAddOp -> True
1781 IntegerSubOp -> True
1782 IntegerMulOp -> True
1783 IntegerGcdOp -> True
1784 IntegerQuotRemOp -> True
1785 IntegerDivModOp -> True
1786 Int2IntegerOp -> True
1787 Word2IntegerOp -> True
1788 Addr2IntegerOp -> True
1789 Word64ToIntegerOp -> True
1790 Int64ToIntegerOp -> True
1791 FloatDecodeOp -> True
1792 DoubleDecodeOp -> True
1795 MakeStableNameOp -> True
1796 MakeForeignObjOp -> True
1800 KillThreadOp -> True
1801 CCallOp _ _ may_gc@True _ -> True -- _ccall_GC_
1805 Sometimes we may choose to execute a PrimOp even though it isn't
1806 certain that its result will be required; ie execute them
1807 ``speculatively''. The same thing as ``cheap eagerness.'' Usually
1808 this is OK, because PrimOps are usually cheap, but it isn't OK for
1809 (a)~expensive PrimOps and (b)~PrimOps which can fail.
1811 See also @primOpIsCheap@ (below).
1813 PrimOps that have side effects also should not be executed speculatively
1814 or by data dependencies.
1817 primOpOkForSpeculation :: PrimOp -> Bool
1818 primOpOkForSpeculation op
1819 = not (primOpCanFail op || primOpHasSideEffects op || primOpOutOfLine op)
1822 @primOpIsCheap@, as used in \tr{SimplUtils.lhs}. For now (HACK
1823 WARNING), we just borrow some other predicates for a
1824 what-should-be-good-enough test. "Cheap" means willing to call it more
1825 than once. Evaluation order is unaffected.
1828 primOpIsCheap op = not (primOpHasSideEffects op || primOpOutOfLine op)
1832 primOpCanFail :: PrimOp -> Bool
1834 primOpCanFail IntQuotOp = True -- Divide by zero
1835 primOpCanFail IntRemOp = True -- Divide by zero
1838 primOpCanFail IntegerQuotRemOp = True -- Divide by zero
1839 primOpCanFail IntegerDivModOp = True -- Divide by zero
1841 -- Float. ToDo: tan? tanh?
1842 primOpCanFail FloatDivOp = True -- Divide by zero
1843 primOpCanFail FloatLogOp = True -- Log of zero
1844 primOpCanFail FloatAsinOp = True -- Arg out of domain
1845 primOpCanFail FloatAcosOp = True -- Arg out of domain
1847 -- Double. ToDo: tan? tanh?
1848 primOpCanFail DoubleDivOp = True -- Divide by zero
1849 primOpCanFail DoubleLogOp = True -- Log of zero
1850 primOpCanFail DoubleAsinOp = True -- Arg out of domain
1851 primOpCanFail DoubleAcosOp = True -- Arg out of domain
1853 primOpCanFail other_op = False
1856 And some primops have side-effects and so, for example, must not be
1860 primOpHasSideEffects :: PrimOp -> Bool
1862 primOpHasSideEffects TakeMVarOp = True
1863 primOpHasSideEffects DelayOp = True
1864 primOpHasSideEffects WaitReadOp = True
1865 primOpHasSideEffects WaitWriteOp = True
1867 primOpHasSideEffects ParOp = True
1868 primOpHasSideEffects ForkOp = True
1869 primOpHasSideEffects KillThreadOp = True
1870 primOpHasSideEffects SeqOp = True
1872 primOpHasSideEffects MakeForeignObjOp = True
1873 primOpHasSideEffects WriteForeignObjOp = True
1874 primOpHasSideEffects MkWeakOp = True
1875 primOpHasSideEffects DeRefWeakOp = True
1876 primOpHasSideEffects MakeStablePtrOp = True
1877 primOpHasSideEffects MakeStableNameOp = True
1878 primOpHasSideEffects EqStablePtrOp = True -- SOF
1879 primOpHasSideEffects DeRefStablePtrOp = True -- ??? JSM & ADR
1881 primOpHasSideEffects ParGlobalOp = True
1882 primOpHasSideEffects ParLocalOp = True
1883 primOpHasSideEffects ParAtOp = True
1884 primOpHasSideEffects ParAtAbsOp = True
1885 primOpHasSideEffects ParAtRelOp = True
1886 primOpHasSideEffects ParAtForNowOp = True
1887 primOpHasSideEffects CopyableOp = True -- Possibly not. ASP
1888 primOpHasSideEffects NoFollowOp = True -- Possibly not. ASP
1891 primOpHasSideEffects (CCallOp _ _ _ _) = True
1893 primOpHasSideEffects other = False
1896 Inline primitive operations that perform calls need wrappers to save
1897 any live variables that are stored in caller-saves registers.
1900 primOpNeedsWrapper :: PrimOp -> Bool
1902 primOpNeedsWrapper (CCallOp _ _ _ _) = True
1904 primOpNeedsWrapper Integer2IntOp = True
1905 primOpNeedsWrapper Integer2WordOp = True
1906 primOpNeedsWrapper IntegerCmpOp = True
1908 primOpNeedsWrapper FloatExpOp = True
1909 primOpNeedsWrapper FloatLogOp = True
1910 primOpNeedsWrapper FloatSqrtOp = True
1911 primOpNeedsWrapper FloatSinOp = True
1912 primOpNeedsWrapper FloatCosOp = True
1913 primOpNeedsWrapper FloatTanOp = True
1914 primOpNeedsWrapper FloatAsinOp = True
1915 primOpNeedsWrapper FloatAcosOp = True
1916 primOpNeedsWrapper FloatAtanOp = True
1917 primOpNeedsWrapper FloatSinhOp = True
1918 primOpNeedsWrapper FloatCoshOp = True
1919 primOpNeedsWrapper FloatTanhOp = True
1920 primOpNeedsWrapper FloatPowerOp = True
1921 primOpNeedsWrapper FloatEncodeOp = True
1923 primOpNeedsWrapper DoubleExpOp = True
1924 primOpNeedsWrapper DoubleLogOp = True
1925 primOpNeedsWrapper DoubleSqrtOp = True
1926 primOpNeedsWrapper DoubleSinOp = True
1927 primOpNeedsWrapper DoubleCosOp = True
1928 primOpNeedsWrapper DoubleTanOp = True
1929 primOpNeedsWrapper DoubleAsinOp = True
1930 primOpNeedsWrapper DoubleAcosOp = True
1931 primOpNeedsWrapper DoubleAtanOp = True
1932 primOpNeedsWrapper DoubleSinhOp = True
1933 primOpNeedsWrapper DoubleCoshOp = True
1934 primOpNeedsWrapper DoubleTanhOp = True
1935 primOpNeedsWrapper DoublePowerOp = True
1936 primOpNeedsWrapper DoubleEncodeOp = True
1938 primOpNeedsWrapper MakeStableNameOp = True
1939 primOpNeedsWrapper DeRefStablePtrOp = True
1941 primOpNeedsWrapper DelayOp = True
1942 primOpNeedsWrapper WaitReadOp = True
1943 primOpNeedsWrapper WaitWriteOp = True
1945 primOpNeedsWrapper other_op = False
1950 = case (primOpInfo op) of
1952 Monadic occ _ -> occ
1953 Compare occ _ -> occ
1954 GenPrimOp occ _ _ _ -> occ
1958 primOpUniq :: PrimOp -> Unique
1959 primOpUniq op = mkPrimOpIdUnique (IBOX(tagOf_PrimOp op))
1961 primOpType :: PrimOp -> Type
1963 = case (primOpInfo op) of
1964 Dyadic occ ty -> dyadic_fun_ty ty
1965 Monadic occ ty -> monadic_fun_ty ty
1966 Compare occ ty -> compare_fun_ty ty
1968 GenPrimOp occ tyvars arg_tys res_ty ->
1969 mkForAllTys tyvars (mkFunTys arg_tys res_ty)
1973 data PrimOpResultInfo
1974 = ReturnsPrim PrimRep
1977 -- Some PrimOps need not return a manifest primitive or algebraic value
1978 -- (i.e. they might return a polymorphic value). These PrimOps *must*
1979 -- be out of line, or the code generator won't work.
1981 getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo
1983 getPrimOpResultInfo op
1984 = case (primOpInfo op) of
1985 Dyadic _ ty -> ReturnsPrim (typePrimRep ty)
1986 Monadic _ ty -> ReturnsPrim (typePrimRep ty)
1987 Compare _ ty -> ReturnsAlg boolTyCon
1988 GenPrimOp _ _ _ ty ->
1989 let rep = typePrimRep ty in
1991 PtrRep -> case splitAlgTyConApp_maybe ty of
1992 Nothing -> panic "getPrimOpResultInfo"
1993 Just (tc,_,_) -> ReturnsAlg tc
1994 other -> ReturnsPrim other
1996 isCompareOp :: PrimOp -> Bool
1999 = case primOpInfo op of
2004 The commutable ops are those for which we will try to move constants
2005 to the right hand side for strength reduction.
2008 commutableOp :: PrimOp -> Bool
2010 commutableOp CharEqOp = True
2011 commutableOp CharNeOp = True
2012 commutableOp IntAddOp = True
2013 commutableOp IntMulOp = True
2014 commutableOp AndOp = True
2015 commutableOp OrOp = True
2016 commutableOp XorOp = True
2017 commutableOp IntEqOp = True
2018 commutableOp IntNeOp = True
2019 commutableOp IntegerAddOp = True
2020 commutableOp IntegerMulOp = True
2021 commutableOp IntegerGcdOp = True
2022 commutableOp FloatAddOp = True
2023 commutableOp FloatMulOp = True
2024 commutableOp FloatEqOp = True
2025 commutableOp FloatNeOp = True
2026 commutableOp DoubleAddOp = True
2027 commutableOp DoubleMulOp = True
2028 commutableOp DoubleEqOp = True
2029 commutableOp DoubleNeOp = True
2030 commutableOp _ = False
2035 mkPrimTyApp :: [TyVar] -> PrimRep -> ([TyVar], Type)
2036 -- CharRep --> ([], Char#)
2037 -- StablePtrRep --> ([a], StablePtr# a)
2038 mkPrimTyApp tvs kind
2039 = (forall_tvs, mkTyConApp tycon (mkTyVarTys forall_tvs))
2041 tycon = primRepTyCon kind
2042 forall_tvs = take (tyConArity tycon) tvs
2044 dyadic_fun_ty ty = mkFunTys [ty, ty] ty
2045 monadic_fun_ty ty = mkFunTy ty ty
2046 compare_fun_ty ty = mkFunTys [ty, ty] boolTy
2051 pprPrimOp :: PrimOp -> SDoc
2053 pprPrimOp (CCallOp fun is_casm may_gc cconv)
2055 callconv = text "{-" <> pprCallConv cconv <> text "-}"
2058 | is_casm && may_gc = "casm_GC ``"
2059 | is_casm = "casm ``"
2060 | may_gc = "ccall_GC "
2061 | otherwise = "ccall "
2064 | is_casm = text "''"
2069 Right _ -> text "dyn_"
2074 Right _ -> text "\"\""
2078 hcat [ ifPprDebug callconv
2079 , text "__", ppr_dyn
2080 , text before , ppr_fun , after]
2083 = getPprStyle $ \ sty ->
2084 if ifaceStyle sty then -- For interfaces Print it qualified with PrelGHC.
2085 ptext SLIT("PrelGHC.") <> pprOccName occ
2089 occ = primOpOcc other_op