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
186 A special ``trap-door'' to use in making calls direct to C functions:
189 FAST_STRING -- Left fn => An "unboxed" ccall# to `fn'.
190 Unique) -- Right u => first argument (an Addr#) is the function pointer
191 -- (unique is used to generate a 'typedef' to cast
192 -- the function pointer if compiling the ccall# down to
193 -- .hc code - can't do this inline for tedious reasons.)
195 Bool -- True <=> really a "casm"
196 Bool -- True <=> might invoke Haskell GC
197 CallConv -- calling convention to use.
199 -- (... to be continued ... )
202 The ``type'' of @CCallOp foo [t1, ... tm] r@ is @t1 -> ... tm -> r@.
203 (See @primOpInfo@ for details.)
205 Note: that first arg and part of the result should be the system state
206 token (which we carry around to fool over-zealous optimisers) but
207 which isn't actually passed.
209 For example, we represent
211 ((ccall# foo [StablePtr# a, Int] Float) sp# i#) :: (Float, IoWorld)
217 (CCallOp "foo" [Universe#, StablePtr# a, Int#] FloatPrimAndUniverse False)
218 -- :: Universe# -> StablePtr# a -> Int# -> FloatPrimAndUniverse
222 (AlgAlts [ ( FloatPrimAndIoWorld,
224 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
230 Nota Bene: there are some people who find the empty list of types in
231 the @Prim@ somewhat puzzling and would represent the above by
235 (CCallOp "foo" [alpha1, alpha2, alpha3] alpha4 False)
236 -- :: /\ alpha1, alpha2 alpha3, alpha4.
237 -- alpha1 -> alpha2 -> alpha3 -> alpha4
238 [Universe#, StablePtr# a, Int#, FloatPrimAndIoWorld]
241 (AlgAlts [ ( FloatPrimAndIoWorld,
243 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
249 But, this is a completely different way of using @CCallOp@. The most
250 major changes required if we switch to this are in @primOpInfo@, and
251 the desugarer. The major difficulty is in moving the HeapRequirement
252 stuff somewhere appropriate. (The advantage is that we could simplify
253 @CCallOp@ and record just the number of arguments with corresponding
254 simplifications in reading pragma unfoldings, the simplifier,
255 instantiation (etc) of core expressions, ... . Maybe we should think
256 about using it this way?? ADR)
259 -- (... continued from above ... )
261 -- Operation to test two closure addresses for equality (yes really!)
262 -- BLAME ALASTAIR REID FOR THIS! THE REST OF US ARE INNOCENT!
263 | ReallyUnsafePtrEqualityOp
276 | ParGlobalOp -- named global par
277 | ParLocalOp -- named local par
278 | ParAtOp -- specifies destination of local par
279 | ParAtAbsOp -- specifies destination of local par (abs processor)
280 | ParAtRelOp -- specifies destination of local par (rel processor)
281 | ParAtForNowOp -- specifies initial destination of global par
282 | CopyableOp -- marks copyable code
283 | NoFollowOp -- marks non-followup expression
286 Used for the Ord instance
289 tagOf_PrimOp CharGtOp = (ILIT( 1) :: FAST_INT)
290 tagOf_PrimOp CharGeOp = ILIT( 2)
291 tagOf_PrimOp CharEqOp = ILIT( 3)
292 tagOf_PrimOp CharNeOp = ILIT( 4)
293 tagOf_PrimOp CharLtOp = ILIT( 5)
294 tagOf_PrimOp CharLeOp = ILIT( 6)
295 tagOf_PrimOp IntGtOp = ILIT( 7)
296 tagOf_PrimOp IntGeOp = ILIT( 8)
297 tagOf_PrimOp IntEqOp = ILIT( 9)
298 tagOf_PrimOp IntNeOp = ILIT( 10)
299 tagOf_PrimOp IntLtOp = ILIT( 11)
300 tagOf_PrimOp IntLeOp = ILIT( 12)
301 tagOf_PrimOp WordGtOp = ILIT( 13)
302 tagOf_PrimOp WordGeOp = ILIT( 14)
303 tagOf_PrimOp WordEqOp = ILIT( 15)
304 tagOf_PrimOp WordNeOp = ILIT( 16)
305 tagOf_PrimOp WordLtOp = ILIT( 17)
306 tagOf_PrimOp WordLeOp = ILIT( 18)
307 tagOf_PrimOp AddrGtOp = ILIT( 19)
308 tagOf_PrimOp AddrGeOp = ILIT( 20)
309 tagOf_PrimOp AddrEqOp = ILIT( 21)
310 tagOf_PrimOp AddrNeOp = ILIT( 22)
311 tagOf_PrimOp AddrLtOp = ILIT( 23)
312 tagOf_PrimOp AddrLeOp = ILIT( 24)
313 tagOf_PrimOp FloatGtOp = ILIT( 25)
314 tagOf_PrimOp FloatGeOp = ILIT( 26)
315 tagOf_PrimOp FloatEqOp = ILIT( 27)
316 tagOf_PrimOp FloatNeOp = ILIT( 28)
317 tagOf_PrimOp FloatLtOp = ILIT( 29)
318 tagOf_PrimOp FloatLeOp = ILIT( 30)
319 tagOf_PrimOp DoubleGtOp = ILIT( 31)
320 tagOf_PrimOp DoubleGeOp = ILIT( 32)
321 tagOf_PrimOp DoubleEqOp = ILIT( 33)
322 tagOf_PrimOp DoubleNeOp = ILIT( 34)
323 tagOf_PrimOp DoubleLtOp = ILIT( 35)
324 tagOf_PrimOp DoubleLeOp = ILIT( 36)
325 tagOf_PrimOp OrdOp = ILIT( 37)
326 tagOf_PrimOp ChrOp = ILIT( 38)
327 tagOf_PrimOp IntAddOp = ILIT( 39)
328 tagOf_PrimOp IntSubOp = ILIT( 40)
329 tagOf_PrimOp IntMulOp = ILIT( 41)
330 tagOf_PrimOp IntQuotOp = ILIT( 42)
331 tagOf_PrimOp IntRemOp = ILIT( 43)
332 tagOf_PrimOp IntNegOp = ILIT( 44)
333 tagOf_PrimOp IntAbsOp = ILIT( 45)
334 tagOf_PrimOp WordQuotOp = ILIT( 46)
335 tagOf_PrimOp WordRemOp = ILIT( 47)
336 tagOf_PrimOp AndOp = ILIT( 48)
337 tagOf_PrimOp OrOp = ILIT( 49)
338 tagOf_PrimOp NotOp = ILIT( 50)
339 tagOf_PrimOp XorOp = ILIT( 51)
340 tagOf_PrimOp SllOp = ILIT( 52)
341 tagOf_PrimOp SrlOp = ILIT( 53)
342 tagOf_PrimOp ISllOp = ILIT( 54)
343 tagOf_PrimOp ISraOp = ILIT( 55)
344 tagOf_PrimOp ISrlOp = ILIT( 56)
345 tagOf_PrimOp Int2WordOp = ILIT( 57)
346 tagOf_PrimOp Word2IntOp = ILIT( 58)
347 tagOf_PrimOp Int2AddrOp = ILIT( 59)
348 tagOf_PrimOp Addr2IntOp = ILIT( 60)
350 tagOf_PrimOp FloatAddOp = ILIT( 61)
351 tagOf_PrimOp FloatSubOp = ILIT( 62)
352 tagOf_PrimOp FloatMulOp = ILIT( 63)
353 tagOf_PrimOp FloatDivOp = ILIT( 64)
354 tagOf_PrimOp FloatNegOp = ILIT( 65)
355 tagOf_PrimOp Float2IntOp = ILIT( 66)
356 tagOf_PrimOp Int2FloatOp = ILIT( 67)
357 tagOf_PrimOp FloatExpOp = ILIT( 68)
358 tagOf_PrimOp FloatLogOp = ILIT( 69)
359 tagOf_PrimOp FloatSqrtOp = ILIT( 70)
360 tagOf_PrimOp FloatSinOp = ILIT( 71)
361 tagOf_PrimOp FloatCosOp = ILIT( 72)
362 tagOf_PrimOp FloatTanOp = ILIT( 73)
363 tagOf_PrimOp FloatAsinOp = ILIT( 74)
364 tagOf_PrimOp FloatAcosOp = ILIT( 75)
365 tagOf_PrimOp FloatAtanOp = ILIT( 76)
366 tagOf_PrimOp FloatSinhOp = ILIT( 77)
367 tagOf_PrimOp FloatCoshOp = ILIT( 78)
368 tagOf_PrimOp FloatTanhOp = ILIT( 79)
369 tagOf_PrimOp FloatPowerOp = ILIT( 80)
371 tagOf_PrimOp DoubleAddOp = ILIT( 81)
372 tagOf_PrimOp DoubleSubOp = ILIT( 82)
373 tagOf_PrimOp DoubleMulOp = ILIT( 83)
374 tagOf_PrimOp DoubleDivOp = ILIT( 84)
375 tagOf_PrimOp DoubleNegOp = ILIT( 85)
376 tagOf_PrimOp Double2IntOp = ILIT( 86)
377 tagOf_PrimOp Int2DoubleOp = ILIT( 87)
378 tagOf_PrimOp Double2FloatOp = ILIT( 88)
379 tagOf_PrimOp Float2DoubleOp = ILIT( 89)
380 tagOf_PrimOp DoubleExpOp = ILIT( 90)
381 tagOf_PrimOp DoubleLogOp = ILIT( 91)
382 tagOf_PrimOp DoubleSqrtOp = ILIT( 92)
383 tagOf_PrimOp DoubleSinOp = ILIT( 93)
384 tagOf_PrimOp DoubleCosOp = ILIT( 94)
385 tagOf_PrimOp DoubleTanOp = ILIT( 95)
386 tagOf_PrimOp DoubleAsinOp = ILIT( 96)
387 tagOf_PrimOp DoubleAcosOp = ILIT( 97)
388 tagOf_PrimOp DoubleAtanOp = ILIT( 98)
389 tagOf_PrimOp DoubleSinhOp = ILIT( 99)
390 tagOf_PrimOp DoubleCoshOp = ILIT(100)
391 tagOf_PrimOp DoubleTanhOp = ILIT(101)
392 tagOf_PrimOp DoublePowerOp = ILIT(102)
394 tagOf_PrimOp IntegerAddOp = ILIT(103)
395 tagOf_PrimOp IntegerSubOp = ILIT(104)
396 tagOf_PrimOp IntegerMulOp = ILIT(105)
397 tagOf_PrimOp IntegerGcdOp = ILIT(106)
398 tagOf_PrimOp IntegerQuotRemOp = ILIT(107)
399 tagOf_PrimOp IntegerDivModOp = ILIT(108)
400 tagOf_PrimOp IntegerNegOp = ILIT(109)
401 tagOf_PrimOp IntegerCmpOp = ILIT(110)
402 tagOf_PrimOp Integer2IntOp = ILIT(111)
403 tagOf_PrimOp Integer2WordOp = ILIT(112)
404 tagOf_PrimOp Int2IntegerOp = ILIT(113)
405 tagOf_PrimOp Word2IntegerOp = ILIT(114)
406 tagOf_PrimOp Addr2IntegerOp = ILIT(115)
407 tagOf_PrimOp IntegerToInt64Op = ILIT(116)
408 tagOf_PrimOp Int64ToIntegerOp = ILIT(117)
409 tagOf_PrimOp IntegerToWord64Op = ILIT(118)
410 tagOf_PrimOp Word64ToIntegerOp = ILIT(119)
412 tagOf_PrimOp FloatEncodeOp = ILIT(120)
413 tagOf_PrimOp FloatDecodeOp = ILIT(121)
414 tagOf_PrimOp DoubleEncodeOp = ILIT(122)
415 tagOf_PrimOp DoubleDecodeOp = ILIT(123)
417 tagOf_PrimOp NewArrayOp = ILIT(124)
418 tagOf_PrimOp (NewByteArrayOp CharRep) = ILIT(125)
419 tagOf_PrimOp (NewByteArrayOp IntRep) = ILIT(126)
420 tagOf_PrimOp (NewByteArrayOp WordRep) = ILIT(127)
421 tagOf_PrimOp (NewByteArrayOp AddrRep) = ILIT(128)
422 tagOf_PrimOp (NewByteArrayOp FloatRep) = ILIT(129)
423 tagOf_PrimOp (NewByteArrayOp DoubleRep) = ILIT(130)
424 tagOf_PrimOp (NewByteArrayOp StablePtrRep) = ILIT(131)
425 tagOf_PrimOp SameMutableArrayOp = ILIT(132)
426 tagOf_PrimOp SameMutableByteArrayOp = ILIT(133)
427 tagOf_PrimOp ReadArrayOp = ILIT(134)
428 tagOf_PrimOp WriteArrayOp = ILIT(135)
429 tagOf_PrimOp IndexArrayOp = ILIT(136)
431 tagOf_PrimOp (ReadByteArrayOp CharRep) = ILIT(137)
432 tagOf_PrimOp (ReadByteArrayOp IntRep) = ILIT(138)
433 tagOf_PrimOp (ReadByteArrayOp WordRep) = ILIT(139)
434 tagOf_PrimOp (ReadByteArrayOp AddrRep) = ILIT(140)
435 tagOf_PrimOp (ReadByteArrayOp FloatRep) = ILIT(141)
436 tagOf_PrimOp (ReadByteArrayOp DoubleRep) = ILIT(142)
437 tagOf_PrimOp (ReadByteArrayOp StablePtrRep) = ILIT(143)
438 tagOf_PrimOp (ReadByteArrayOp Int64Rep) = ILIT(144)
439 tagOf_PrimOp (ReadByteArrayOp Word64Rep) = ILIT(145)
441 tagOf_PrimOp (WriteByteArrayOp CharRep) = ILIT(146)
442 tagOf_PrimOp (WriteByteArrayOp IntRep) = ILIT(147)
443 tagOf_PrimOp (WriteByteArrayOp WordRep) = ILIT(148)
444 tagOf_PrimOp (WriteByteArrayOp AddrRep) = ILIT(149)
445 tagOf_PrimOp (WriteByteArrayOp FloatRep) = ILIT(150)
446 tagOf_PrimOp (WriteByteArrayOp DoubleRep) = ILIT(151)
447 tagOf_PrimOp (WriteByteArrayOp StablePtrRep) = ILIT(152)
448 tagOf_PrimOp (WriteByteArrayOp Int64Rep) = ILIT(153)
449 tagOf_PrimOp (WriteByteArrayOp Word64Rep) = ILIT(154)
451 tagOf_PrimOp (IndexByteArrayOp CharRep) = ILIT(155)
452 tagOf_PrimOp (IndexByteArrayOp IntRep) = ILIT(156)
453 tagOf_PrimOp (IndexByteArrayOp WordRep) = ILIT(157)
454 tagOf_PrimOp (IndexByteArrayOp AddrRep) = ILIT(158)
455 tagOf_PrimOp (IndexByteArrayOp FloatRep) = ILIT(159)
456 tagOf_PrimOp (IndexByteArrayOp DoubleRep) = ILIT(160)
457 tagOf_PrimOp (IndexByteArrayOp StablePtrRep) = ILIT(161)
458 tagOf_PrimOp (IndexByteArrayOp Int64Rep) = ILIT(162)
459 tagOf_PrimOp (IndexByteArrayOp Word64Rep) = ILIT(163)
461 tagOf_PrimOp (IndexOffAddrOp CharRep) = ILIT(164)
462 tagOf_PrimOp (IndexOffAddrOp IntRep) = ILIT(165)
463 tagOf_PrimOp (IndexOffAddrOp WordRep) = ILIT(166)
464 tagOf_PrimOp (IndexOffAddrOp AddrRep) = ILIT(167)
465 tagOf_PrimOp (IndexOffAddrOp FloatRep) = ILIT(168)
466 tagOf_PrimOp (IndexOffAddrOp DoubleRep) = ILIT(169)
467 tagOf_PrimOp (IndexOffAddrOp StablePtrRep) = ILIT(170)
468 tagOf_PrimOp (IndexOffAddrOp Int64Rep) = ILIT(171)
469 tagOf_PrimOp (IndexOffAddrOp Word64Rep) = ILIT(172)
470 tagOf_PrimOp (IndexOffForeignObjOp CharRep) = ILIT(173)
471 tagOf_PrimOp (IndexOffForeignObjOp IntRep) = ILIT(174)
472 tagOf_PrimOp (IndexOffForeignObjOp WordRep) = ILIT(175)
473 tagOf_PrimOp (IndexOffForeignObjOp AddrRep) = ILIT(176)
474 tagOf_PrimOp (IndexOffForeignObjOp FloatRep) = ILIT(177)
475 tagOf_PrimOp (IndexOffForeignObjOp DoubleRep) = ILIT(178)
476 tagOf_PrimOp (IndexOffForeignObjOp StablePtrRep) = ILIT(179)
477 tagOf_PrimOp (IndexOffForeignObjOp Int64Rep) = ILIT(180)
478 tagOf_PrimOp (IndexOffForeignObjOp Word64Rep) = ILIT(181)
480 tagOf_PrimOp (WriteOffAddrOp CharRep) = ILIT(182)
481 tagOf_PrimOp (WriteOffAddrOp IntRep) = ILIT(183)
482 tagOf_PrimOp (WriteOffAddrOp WordRep) = ILIT(184)
483 tagOf_PrimOp (WriteOffAddrOp AddrRep) = ILIT(185)
484 tagOf_PrimOp (WriteOffAddrOp FloatRep) = ILIT(186)
485 tagOf_PrimOp (WriteOffAddrOp DoubleRep) = ILIT(187)
486 tagOf_PrimOp (WriteOffAddrOp StablePtrRep) = ILIT(188)
487 tagOf_PrimOp (WriteOffAddrOp ForeignObjRep) = ILIT(189)
488 tagOf_PrimOp (WriteOffAddrOp Int64Rep) = ILIT(190)
489 tagOf_PrimOp (WriteOffAddrOp Word64Rep) = ILIT(191)
491 tagOf_PrimOp UnsafeFreezeArrayOp = ILIT(192)
492 tagOf_PrimOp UnsafeFreezeByteArrayOp = ILIT(193)
493 tagOf_PrimOp SizeofByteArrayOp = ILIT(194)
494 tagOf_PrimOp SizeofMutableByteArrayOp = ILIT(195)
495 tagOf_PrimOp NewMVarOp = ILIT(196)
496 tagOf_PrimOp TakeMVarOp = ILIT(197)
497 tagOf_PrimOp PutMVarOp = ILIT(198)
498 tagOf_PrimOp SameMVarOp = ILIT(199)
499 tagOf_PrimOp IsEmptyMVarOp = ILIT(200)
500 tagOf_PrimOp MakeForeignObjOp = ILIT(201)
501 tagOf_PrimOp WriteForeignObjOp = ILIT(202)
502 tagOf_PrimOp MkWeakOp = ILIT(203)
503 tagOf_PrimOp DeRefWeakOp = ILIT(204)
504 tagOf_PrimOp FinaliseWeakOp = ILIT(205)
505 tagOf_PrimOp MakeStableNameOp = ILIT(206)
506 tagOf_PrimOp EqStableNameOp = ILIT(207)
507 tagOf_PrimOp StableNameToIntOp = ILIT(208)
508 tagOf_PrimOp MakeStablePtrOp = ILIT(209)
509 tagOf_PrimOp DeRefStablePtrOp = ILIT(210)
510 tagOf_PrimOp EqStablePtrOp = ILIT(211)
511 tagOf_PrimOp (CCallOp _ _ _ _) = ILIT(212)
512 tagOf_PrimOp ReallyUnsafePtrEqualityOp = ILIT(213)
513 tagOf_PrimOp SeqOp = ILIT(214)
514 tagOf_PrimOp ParOp = ILIT(215)
515 tagOf_PrimOp ForkOp = ILIT(216)
516 tagOf_PrimOp KillThreadOp = ILIT(217)
517 tagOf_PrimOp DelayOp = ILIT(218)
518 tagOf_PrimOp WaitReadOp = ILIT(219)
519 tagOf_PrimOp WaitWriteOp = ILIT(220)
520 tagOf_PrimOp ParGlobalOp = ILIT(221)
521 tagOf_PrimOp ParLocalOp = ILIT(222)
522 tagOf_PrimOp ParAtOp = ILIT(223)
523 tagOf_PrimOp ParAtAbsOp = ILIT(224)
524 tagOf_PrimOp ParAtRelOp = ILIT(225)
525 tagOf_PrimOp ParAtForNowOp = ILIT(226)
526 tagOf_PrimOp CopyableOp = ILIT(227)
527 tagOf_PrimOp NoFollowOp = ILIT(228)
528 tagOf_PrimOp NewMutVarOp = ILIT(229)
529 tagOf_PrimOp ReadMutVarOp = ILIT(230)
530 tagOf_PrimOp WriteMutVarOp = ILIT(231)
531 tagOf_PrimOp SameMutVarOp = ILIT(232)
532 tagOf_PrimOp CatchOp = ILIT(233)
533 tagOf_PrimOp RaiseOp = ILIT(234)
535 tagOf_PrimOp op = pprPanic# "tagOf_PrimOp: pattern-match" (ppr op)
536 --panic# "tagOf_PrimOp: pattern-match"
538 instance Eq PrimOp where
539 op1 == op2 = tagOf_PrimOp op1 _EQ_ tagOf_PrimOp op2
541 instance Ord PrimOp where
542 op1 < op2 = tagOf_PrimOp op1 _LT_ tagOf_PrimOp op2
543 op1 <= op2 = tagOf_PrimOp op1 _LE_ tagOf_PrimOp op2
544 op1 >= op2 = tagOf_PrimOp op1 _GE_ tagOf_PrimOp op2
545 op1 > op2 = tagOf_PrimOp op1 _GT_ tagOf_PrimOp op2
546 op1 `compare` op2 | op1 < op2 = LT
550 instance Outputable PrimOp where
551 ppr op = pprPrimOp op
553 instance Show PrimOp where
554 showsPrec p op = showsPrecSDoc p (pprPrimOp op)
557 An @Enum@-derived list would be better; meanwhile... (ToDo)
684 NewByteArrayOp CharRep,
685 NewByteArrayOp IntRep,
686 NewByteArrayOp WordRep,
687 NewByteArrayOp AddrRep,
688 NewByteArrayOp FloatRep,
689 NewByteArrayOp DoubleRep,
690 NewByteArrayOp StablePtrRep,
692 SameMutableByteArrayOp,
696 ReadByteArrayOp CharRep,
697 ReadByteArrayOp IntRep,
698 ReadByteArrayOp WordRep,
699 ReadByteArrayOp AddrRep,
700 ReadByteArrayOp FloatRep,
701 ReadByteArrayOp DoubleRep,
702 ReadByteArrayOp StablePtrRep,
703 ReadByteArrayOp Int64Rep,
704 ReadByteArrayOp Word64Rep,
705 WriteByteArrayOp CharRep,
706 WriteByteArrayOp IntRep,
707 WriteByteArrayOp WordRep,
708 WriteByteArrayOp AddrRep,
709 WriteByteArrayOp FloatRep,
710 WriteByteArrayOp DoubleRep,
711 WriteByteArrayOp StablePtrRep,
712 WriteByteArrayOp Int64Rep,
713 WriteByteArrayOp Word64Rep,
714 IndexByteArrayOp CharRep,
715 IndexByteArrayOp IntRep,
716 IndexByteArrayOp WordRep,
717 IndexByteArrayOp AddrRep,
718 IndexByteArrayOp FloatRep,
719 IndexByteArrayOp DoubleRep,
720 IndexByteArrayOp StablePtrRep,
721 IndexByteArrayOp Int64Rep,
722 IndexByteArrayOp Word64Rep,
723 IndexOffForeignObjOp CharRep,
724 IndexOffForeignObjOp AddrRep,
725 IndexOffForeignObjOp IntRep,
726 IndexOffForeignObjOp WordRep,
727 IndexOffForeignObjOp FloatRep,
728 IndexOffForeignObjOp DoubleRep,
729 IndexOffForeignObjOp StablePtrRep,
730 IndexOffForeignObjOp Int64Rep,
731 IndexOffForeignObjOp Word64Rep,
732 IndexOffAddrOp CharRep,
733 IndexOffAddrOp IntRep,
734 IndexOffAddrOp WordRep,
735 IndexOffAddrOp AddrRep,
736 IndexOffAddrOp FloatRep,
737 IndexOffAddrOp DoubleRep,
738 IndexOffAddrOp StablePtrRep,
739 IndexOffAddrOp Int64Rep,
740 IndexOffAddrOp Word64Rep,
741 WriteOffAddrOp CharRep,
742 WriteOffAddrOp IntRep,
743 WriteOffAddrOp WordRep,
744 WriteOffAddrOp AddrRep,
745 WriteOffAddrOp FloatRep,
746 WriteOffAddrOp DoubleRep,
747 WriteOffAddrOp ForeignObjRep,
748 WriteOffAddrOp StablePtrRep,
749 WriteOffAddrOp Int64Rep,
750 WriteOffAddrOp Word64Rep,
752 UnsafeFreezeByteArrayOp,
754 SizeofMutableByteArrayOp,
777 ReallyUnsafePtrEqualityOp,
796 %************************************************************************
798 \subsection[PrimOp-info]{The essential info about each @PrimOp@}
800 %************************************************************************
802 The @String@ in the @PrimOpInfos@ is the ``base name'' by which the user may
803 refer to the primitive operation. The conventional \tr{#}-for-
804 unboxed ops is added on later.
806 The reason for the funny characters in the names is so we do not
807 interfere with the programmer's Haskell name spaces.
809 We use @PrimKinds@ for the ``type'' information, because they're
810 (slightly) more convenient to use than @TyCons@.
813 = Dyadic OccName -- string :: T -> T -> T
815 | Monadic OccName -- string :: T -> T
817 | Compare OccName -- string :: T -> T -> Bool
820 | GenPrimOp OccName -- string :: \/a1..an . T1 -> .. -> Tk -> T
825 mkDyadic str ty = Dyadic (mkSrcVarOcc str) ty
826 mkMonadic str ty = Monadic (mkSrcVarOcc str) ty
827 mkCompare str ty = Compare (mkSrcVarOcc str) ty
828 mkGenPrimOp str tvs tys ty = GenPrimOp (mkSrcVarOcc str) tvs tys ty
833 one_Integer_ty = [intPrimTy, intPrimTy, byteArrayPrimTy]
835 = [intPrimTy, intPrimTy, byteArrayPrimTy, -- first Integer pieces
836 intPrimTy, intPrimTy, byteArrayPrimTy] -- second '' pieces
837 an_Integer_and_Int_tys
838 = [intPrimTy, intPrimTy, byteArrayPrimTy, -- Integer
841 unboxedPair = mkUnboxedTupleTy 2
842 unboxedTriple = mkUnboxedTupleTy 3
843 unboxedQuadruple = mkUnboxedTupleTy 4
844 unboxedSexTuple = mkUnboxedTupleTy 6
846 integerMonadic name = mkGenPrimOp name [] one_Integer_ty
847 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
849 integerDyadic name = mkGenPrimOp name [] two_Integer_tys
850 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
852 integerDyadic2Results name = mkGenPrimOp name [] two_Integer_tys
853 (unboxedSexTuple [intPrimTy, intPrimTy, byteArrayPrimTy,
854 intPrimTy, intPrimTy, byteArrayPrimTy])
856 integerCompare name = mkGenPrimOp name [] two_Integer_tys intPrimTy
859 %************************************************************************
861 \subsubsection{Strictness}
863 %************************************************************************
865 Not all primops are strict!
868 primOpStrictness :: PrimOp -> ([Demand], Bool)
869 -- See IdInfo.StrictnessInfo for discussion of what the results
870 -- **NB** as a cheap hack, to avoid having to look up the PrimOp's arity,
871 -- the list of demands may be infinite!
872 -- Use only the ones you ned.
874 primOpStrictness SeqOp = ([wwLazy], False)
875 primOpStrictness ParOp = ([wwLazy], False)
876 primOpStrictness ForkOp = ([wwLazy, wwPrim], False)
878 primOpStrictness NewArrayOp = ([wwPrim, wwLazy, wwPrim], False)
879 primOpStrictness WriteArrayOp = ([wwPrim, wwPrim, wwLazy, wwPrim], False)
881 primOpStrictness NewMutVarOp = ([wwLazy, wwPrim], False)
882 primOpStrictness WriteMutVarOp = ([wwPrim, wwLazy, wwPrim], False)
884 primOpStrictness PutMVarOp = ([wwPrim, wwLazy, wwPrim], False)
886 primOpStrictness CatchOp = ([wwLazy, wwLazy], False)
887 primOpStrictness RaiseOp = ([wwLazy], True) -- NB: True => result is bottom
889 primOpStrictness MkWeakOp = ([wwLazy, wwLazy, wwLazy, wwPrim], False)
890 primOpStrictness MakeStableNameOp = ([wwLazy, wwPrim], False)
891 primOpStrictness MakeStablePtrOp = ([wwLazy, wwPrim], False)
893 -- The rest all have primitive-typed arguments
894 primOpStrictness other = (repeat wwPrim, False)
897 %************************************************************************
899 \subsubsection[PrimOp-comparison]{PrimOpInfo basic comparison ops}
901 %************************************************************************
903 @primOpInfo@ gives all essential information (from which everything
904 else, notably a type, can be constructed) for each @PrimOp@.
907 primOpInfo :: PrimOp -> PrimOpInfo
910 There's plenty of this stuff!
913 primOpInfo CharGtOp = mkCompare SLIT("gtChar#") charPrimTy
914 primOpInfo CharGeOp = mkCompare SLIT("geChar#") charPrimTy
915 primOpInfo CharEqOp = mkCompare SLIT("eqChar#") charPrimTy
916 primOpInfo CharNeOp = mkCompare SLIT("neChar#") charPrimTy
917 primOpInfo CharLtOp = mkCompare SLIT("ltChar#") charPrimTy
918 primOpInfo CharLeOp = mkCompare SLIT("leChar#") charPrimTy
920 primOpInfo IntGtOp = mkCompare SLIT(">#") intPrimTy
921 primOpInfo IntGeOp = mkCompare SLIT(">=#") intPrimTy
922 primOpInfo IntEqOp = mkCompare SLIT("==#") intPrimTy
923 primOpInfo IntNeOp = mkCompare SLIT("/=#") intPrimTy
924 primOpInfo IntLtOp = mkCompare SLIT("<#") intPrimTy
925 primOpInfo IntLeOp = mkCompare SLIT("<=#") intPrimTy
927 primOpInfo WordGtOp = mkCompare SLIT("gtWord#") wordPrimTy
928 primOpInfo WordGeOp = mkCompare SLIT("geWord#") wordPrimTy
929 primOpInfo WordEqOp = mkCompare SLIT("eqWord#") wordPrimTy
930 primOpInfo WordNeOp = mkCompare SLIT("neWord#") wordPrimTy
931 primOpInfo WordLtOp = mkCompare SLIT("ltWord#") wordPrimTy
932 primOpInfo WordLeOp = mkCompare SLIT("leWord#") wordPrimTy
934 primOpInfo AddrGtOp = mkCompare SLIT("gtAddr#") addrPrimTy
935 primOpInfo AddrGeOp = mkCompare SLIT("geAddr#") addrPrimTy
936 primOpInfo AddrEqOp = mkCompare SLIT("eqAddr#") addrPrimTy
937 primOpInfo AddrNeOp = mkCompare SLIT("neAddr#") addrPrimTy
938 primOpInfo AddrLtOp = mkCompare SLIT("ltAddr#") addrPrimTy
939 primOpInfo AddrLeOp = mkCompare SLIT("leAddr#") addrPrimTy
941 primOpInfo FloatGtOp = mkCompare SLIT("gtFloat#") floatPrimTy
942 primOpInfo FloatGeOp = mkCompare SLIT("geFloat#") floatPrimTy
943 primOpInfo FloatEqOp = mkCompare SLIT("eqFloat#") floatPrimTy
944 primOpInfo FloatNeOp = mkCompare SLIT("neFloat#") floatPrimTy
945 primOpInfo FloatLtOp = mkCompare SLIT("ltFloat#") floatPrimTy
946 primOpInfo FloatLeOp = mkCompare SLIT("leFloat#") floatPrimTy
948 primOpInfo DoubleGtOp = mkCompare SLIT(">##") doublePrimTy
949 primOpInfo DoubleGeOp = mkCompare SLIT(">=##") doublePrimTy
950 primOpInfo DoubleEqOp = mkCompare SLIT("==##") doublePrimTy
951 primOpInfo DoubleNeOp = mkCompare SLIT("/=##") doublePrimTy
952 primOpInfo DoubleLtOp = mkCompare SLIT("<##") doublePrimTy
953 primOpInfo DoubleLeOp = mkCompare SLIT("<=##") doublePrimTy
957 %************************************************************************
959 \subsubsection[PrimOp-Char]{PrimOpInfo for @Char#@s}
961 %************************************************************************
964 primOpInfo OrdOp = mkGenPrimOp SLIT("ord#") [] [charPrimTy] intPrimTy
965 primOpInfo ChrOp = mkGenPrimOp SLIT("chr#") [] [intPrimTy] charPrimTy
968 %************************************************************************
970 \subsubsection[PrimOp-Int]{PrimOpInfo for @Int#@s}
972 %************************************************************************
975 primOpInfo IntAddOp = mkDyadic SLIT("+#") intPrimTy
976 primOpInfo IntSubOp = mkDyadic SLIT("-#") intPrimTy
977 primOpInfo IntMulOp = mkDyadic SLIT("*#") intPrimTy
978 primOpInfo IntQuotOp = mkDyadic SLIT("quotInt#") intPrimTy
979 primOpInfo IntRemOp = mkDyadic SLIT("remInt#") intPrimTy
981 primOpInfo IntNegOp = mkMonadic SLIT("negateInt#") intPrimTy
982 primOpInfo IntAbsOp = mkMonadic SLIT("absInt#") intPrimTy
985 %************************************************************************
987 \subsubsection[PrimOp-Word]{PrimOpInfo for @Word#@s}
989 %************************************************************************
991 A @Word#@ is an unsigned @Int#@.
994 primOpInfo WordQuotOp = mkDyadic SLIT("quotWord#") wordPrimTy
995 primOpInfo WordRemOp = mkDyadic SLIT("remWord#") wordPrimTy
997 primOpInfo AndOp = mkDyadic SLIT("and#") wordPrimTy
998 primOpInfo OrOp = mkDyadic SLIT("or#") wordPrimTy
999 primOpInfo XorOp = mkDyadic SLIT("xor#") wordPrimTy
1000 primOpInfo NotOp = mkMonadic SLIT("not#") wordPrimTy
1003 = mkGenPrimOp SLIT("shiftL#") [] [wordPrimTy, intPrimTy] wordPrimTy
1005 = mkGenPrimOp SLIT("shiftRL#") [] [wordPrimTy, intPrimTy] wordPrimTy
1008 = mkGenPrimOp SLIT("iShiftL#") [] [intPrimTy, intPrimTy] intPrimTy
1010 = mkGenPrimOp SLIT("iShiftRA#") [] [intPrimTy, intPrimTy] intPrimTy
1012 = mkGenPrimOp SLIT("iShiftRL#") [] [intPrimTy, intPrimTy] intPrimTy
1014 primOpInfo Int2WordOp = mkGenPrimOp SLIT("int2Word#") [] [intPrimTy] wordPrimTy
1015 primOpInfo Word2IntOp = mkGenPrimOp SLIT("word2Int#") [] [wordPrimTy] intPrimTy
1018 %************************************************************************
1020 \subsubsection[PrimOp-Addr]{PrimOpInfo for @Addr#@s}
1022 %************************************************************************
1025 primOpInfo Int2AddrOp = mkGenPrimOp SLIT("int2Addr#") [] [intPrimTy] addrPrimTy
1026 primOpInfo Addr2IntOp = mkGenPrimOp SLIT("addr2Int#") [] [addrPrimTy] intPrimTy
1030 %************************************************************************
1032 \subsubsection[PrimOp-Float]{PrimOpInfo for @Float#@s}
1034 %************************************************************************
1036 @encodeFloat#@ and @decodeFloat#@ are given w/ Integer-stuff (it's
1040 primOpInfo FloatAddOp = mkDyadic SLIT("plusFloat#") floatPrimTy
1041 primOpInfo FloatSubOp = mkDyadic SLIT("minusFloat#") floatPrimTy
1042 primOpInfo FloatMulOp = mkDyadic SLIT("timesFloat#") floatPrimTy
1043 primOpInfo FloatDivOp = mkDyadic SLIT("divideFloat#") floatPrimTy
1044 primOpInfo FloatNegOp = mkMonadic SLIT("negateFloat#") floatPrimTy
1046 primOpInfo Float2IntOp = mkGenPrimOp SLIT("float2Int#") [] [floatPrimTy] intPrimTy
1047 primOpInfo Int2FloatOp = mkGenPrimOp SLIT("int2Float#") [] [intPrimTy] floatPrimTy
1049 primOpInfo FloatExpOp = mkMonadic SLIT("expFloat#") floatPrimTy
1050 primOpInfo FloatLogOp = mkMonadic SLIT("logFloat#") floatPrimTy
1051 primOpInfo FloatSqrtOp = mkMonadic SLIT("sqrtFloat#") floatPrimTy
1052 primOpInfo FloatSinOp = mkMonadic SLIT("sinFloat#") floatPrimTy
1053 primOpInfo FloatCosOp = mkMonadic SLIT("cosFloat#") floatPrimTy
1054 primOpInfo FloatTanOp = mkMonadic SLIT("tanFloat#") floatPrimTy
1055 primOpInfo FloatAsinOp = mkMonadic SLIT("asinFloat#") floatPrimTy
1056 primOpInfo FloatAcosOp = mkMonadic SLIT("acosFloat#") floatPrimTy
1057 primOpInfo FloatAtanOp = mkMonadic SLIT("atanFloat#") floatPrimTy
1058 primOpInfo FloatSinhOp = mkMonadic SLIT("sinhFloat#") floatPrimTy
1059 primOpInfo FloatCoshOp = mkMonadic SLIT("coshFloat#") floatPrimTy
1060 primOpInfo FloatTanhOp = mkMonadic SLIT("tanhFloat#") floatPrimTy
1061 primOpInfo FloatPowerOp = mkDyadic SLIT("powerFloat#") floatPrimTy
1064 %************************************************************************
1066 \subsubsection[PrimOp-Double]{PrimOpInfo for @Double#@s}
1068 %************************************************************************
1070 @encodeDouble#@ and @decodeDouble#@ are given w/ Integer-stuff (it's
1074 primOpInfo DoubleAddOp = mkDyadic SLIT("+##") doublePrimTy
1075 primOpInfo DoubleSubOp = mkDyadic SLIT("-##") doublePrimTy
1076 primOpInfo DoubleMulOp = mkDyadic SLIT("*##") doublePrimTy
1077 primOpInfo DoubleDivOp = mkDyadic SLIT("/##") doublePrimTy
1078 primOpInfo DoubleNegOp = mkMonadic SLIT("negateDouble#") doublePrimTy
1080 primOpInfo Double2IntOp = mkGenPrimOp SLIT("double2Int#") [] [doublePrimTy] intPrimTy
1081 primOpInfo Int2DoubleOp = mkGenPrimOp SLIT("int2Double#") [] [intPrimTy] doublePrimTy
1083 primOpInfo Double2FloatOp = mkGenPrimOp SLIT("double2Float#") [] [doublePrimTy] floatPrimTy
1084 primOpInfo Float2DoubleOp = mkGenPrimOp SLIT("float2Double#") [] [floatPrimTy] doublePrimTy
1086 primOpInfo DoubleExpOp = mkMonadic SLIT("expDouble#") doublePrimTy
1087 primOpInfo DoubleLogOp = mkMonadic SLIT("logDouble#") doublePrimTy
1088 primOpInfo DoubleSqrtOp = mkMonadic SLIT("sqrtDouble#") doublePrimTy
1089 primOpInfo DoubleSinOp = mkMonadic SLIT("sinDouble#") doublePrimTy
1090 primOpInfo DoubleCosOp = mkMonadic SLIT("cosDouble#") doublePrimTy
1091 primOpInfo DoubleTanOp = mkMonadic SLIT("tanDouble#") doublePrimTy
1092 primOpInfo DoubleAsinOp = mkMonadic SLIT("asinDouble#") doublePrimTy
1093 primOpInfo DoubleAcosOp = mkMonadic SLIT("acosDouble#") doublePrimTy
1094 primOpInfo DoubleAtanOp = mkMonadic SLIT("atanDouble#") doublePrimTy
1095 primOpInfo DoubleSinhOp = mkMonadic SLIT("sinhDouble#") doublePrimTy
1096 primOpInfo DoubleCoshOp = mkMonadic SLIT("coshDouble#") doublePrimTy
1097 primOpInfo DoubleTanhOp = mkMonadic SLIT("tanhDouble#") doublePrimTy
1098 primOpInfo DoublePowerOp= mkDyadic SLIT("**##") doublePrimTy
1101 %************************************************************************
1103 \subsubsection[PrimOp-Integer]{PrimOpInfo for @Integer@ (and related!)}
1105 %************************************************************************
1108 primOpInfo IntegerNegOp = integerMonadic SLIT("negateInteger#")
1110 primOpInfo IntegerAddOp = integerDyadic SLIT("plusInteger#")
1111 primOpInfo IntegerSubOp = integerDyadic SLIT("minusInteger#")
1112 primOpInfo IntegerMulOp = integerDyadic SLIT("timesInteger#")
1113 primOpInfo IntegerGcdOp = integerDyadic SLIT("gcdInteger#")
1115 primOpInfo IntegerCmpOp = integerCompare SLIT("cmpInteger#")
1117 primOpInfo IntegerQuotRemOp = integerDyadic2Results SLIT("quotRemInteger#")
1118 primOpInfo IntegerDivModOp = integerDyadic2Results SLIT("divModInteger#")
1120 primOpInfo Integer2IntOp
1121 = mkGenPrimOp SLIT("integer2Int#") [] one_Integer_ty intPrimTy
1123 primOpInfo Integer2WordOp
1124 = mkGenPrimOp SLIT("integer2Word#") [] one_Integer_ty wordPrimTy
1126 primOpInfo Int2IntegerOp
1127 = mkGenPrimOp SLIT("int2Integer#") [] [intPrimTy]
1128 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1130 primOpInfo Word2IntegerOp
1131 = mkGenPrimOp SLIT("word2Integer#") [] [wordPrimTy]
1132 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1134 primOpInfo Addr2IntegerOp
1135 = mkGenPrimOp SLIT("addr2Integer#") [] [addrPrimTy]
1136 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1138 primOpInfo IntegerToInt64Op
1139 = mkGenPrimOp SLIT("integerToInt64#") [] one_Integer_ty int64PrimTy
1141 primOpInfo Int64ToIntegerOp
1142 = mkGenPrimOp SLIT("int64ToInteger#") [] [int64PrimTy]
1143 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1145 primOpInfo Word64ToIntegerOp
1146 = mkGenPrimOp SLIT("word64ToInteger#") [] [word64PrimTy]
1147 (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
1149 primOpInfo IntegerToWord64Op
1150 = mkGenPrimOp SLIT("integerToWord64#") [] one_Integer_ty word64PrimTy
1153 Encoding and decoding of floating-point numbers is sorta
1157 primOpInfo FloatEncodeOp
1158 = mkGenPrimOp SLIT("encodeFloat#") [] an_Integer_and_Int_tys floatPrimTy
1160 primOpInfo DoubleEncodeOp
1161 = mkGenPrimOp SLIT("encodeDouble#") [] an_Integer_and_Int_tys doublePrimTy
1163 primOpInfo FloatDecodeOp
1164 = mkGenPrimOp SLIT("decodeFloat#") [] [floatPrimTy]
1165 (unboxedQuadruple [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy])
1166 primOpInfo DoubleDecodeOp
1167 = mkGenPrimOp SLIT("decodeDouble#") [] [doublePrimTy]
1168 (unboxedQuadruple [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy])
1171 %************************************************************************
1173 \subsubsection[PrimOp-Arrays]{PrimOpInfo for primitive arrays}
1175 %************************************************************************
1178 primOpInfo NewArrayOp
1180 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1181 state = mkStatePrimTy s
1183 mkGenPrimOp SLIT("newArray#") [s_tv, elt_tv]
1184 [intPrimTy, elt, state]
1185 (unboxedPair [state, mkMutableArrayPrimTy s elt])
1187 primOpInfo (NewByteArrayOp kind)
1189 s = alphaTy; s_tv = alphaTyVar
1191 op_str = _PK_ ("new" ++ primRepString kind ++ "Array#")
1192 state = mkStatePrimTy s
1194 mkGenPrimOp op_str [s_tv]
1196 (unboxedPair [state, mkMutableByteArrayPrimTy s])
1198 ---------------------------------------------------------------------------
1200 primOpInfo SameMutableArrayOp
1202 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1203 mut_arr_ty = mkMutableArrayPrimTy s elt
1205 mkGenPrimOp SLIT("sameMutableArray#") [s_tv, elt_tv] [mut_arr_ty, mut_arr_ty]
1208 primOpInfo SameMutableByteArrayOp
1210 s = alphaTy; s_tv = alphaTyVar;
1211 mut_arr_ty = mkMutableByteArrayPrimTy s
1213 mkGenPrimOp SLIT("sameMutableByteArray#") [s_tv] [mut_arr_ty, mut_arr_ty]
1216 ---------------------------------------------------------------------------
1217 -- Primitive arrays of Haskell pointers:
1219 primOpInfo ReadArrayOp
1221 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1222 state = mkStatePrimTy s
1224 mkGenPrimOp SLIT("readArray#") [s_tv, elt_tv]
1225 [mkMutableArrayPrimTy s elt, intPrimTy, state]
1226 (unboxedPair [state, elt])
1229 primOpInfo WriteArrayOp
1231 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1233 mkGenPrimOp SLIT("writeArray#") [s_tv, elt_tv]
1234 [mkMutableArrayPrimTy s elt, intPrimTy, elt, mkStatePrimTy s]
1237 primOpInfo IndexArrayOp
1238 = let { elt = alphaTy; elt_tv = alphaTyVar } in
1239 mkGenPrimOp SLIT("indexArray#") [elt_tv] [mkArrayPrimTy elt, intPrimTy]
1240 (unboxedPair [realWorldStatePrimTy, elt])
1242 ---------------------------------------------------------------------------
1243 -- Primitive arrays full of unboxed bytes:
1245 primOpInfo (ReadByteArrayOp kind)
1247 s = alphaTy; s_tv = alphaTyVar
1249 op_str = _PK_ ("read" ++ primRepString kind ++ "Array#")
1250 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1251 state = mkStatePrimTy s
1253 mkGenPrimOp op_str (s_tv:tvs)
1254 [mkMutableByteArrayPrimTy s, intPrimTy, state]
1255 (unboxedPair [state, prim_ty])
1257 primOpInfo (WriteByteArrayOp kind)
1259 s = alphaTy; s_tv = alphaTyVar
1260 op_str = _PK_ ("write" ++ primRepString kind ++ "Array#")
1261 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1263 mkGenPrimOp op_str (s_tv:tvs)
1264 [mkMutableByteArrayPrimTy s, intPrimTy, prim_ty, mkStatePrimTy s]
1267 primOpInfo (IndexByteArrayOp kind)
1269 op_str = _PK_ ("index" ++ primRepString kind ++ "Array#")
1270 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1272 mkGenPrimOp op_str tvs [byteArrayPrimTy, intPrimTy] prim_ty
1274 primOpInfo (IndexOffForeignObjOp kind)
1276 op_str = _PK_ ("index" ++ primRepString kind ++ "OffForeignObj#")
1277 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1279 mkGenPrimOp op_str tvs [foreignObjPrimTy, intPrimTy] prim_ty
1281 primOpInfo (IndexOffAddrOp kind)
1283 op_str = _PK_ ("index" ++ primRepString kind ++ "OffAddr#")
1284 (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
1286 mkGenPrimOp op_str tvs [addrPrimTy, intPrimTy] prim_ty
1288 primOpInfo (WriteOffAddrOp kind)
1290 s = alphaTy; s_tv = alphaTyVar
1291 op_str = _PK_ ("write" ++ primRepString kind ++ "OffAddr#")
1292 (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
1294 mkGenPrimOp op_str (s_tv:tvs)
1295 [addrPrimTy, intPrimTy, prim_ty, mkStatePrimTy s]
1298 ---------------------------------------------------------------------------
1299 primOpInfo UnsafeFreezeArrayOp
1301 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1302 state = mkStatePrimTy s
1304 mkGenPrimOp SLIT("unsafeFreezeArray#") [s_tv, elt_tv]
1305 [mkMutableArrayPrimTy s elt, state]
1306 (unboxedPair [state, mkArrayPrimTy elt])
1308 primOpInfo UnsafeFreezeByteArrayOp
1310 s = alphaTy; s_tv = alphaTyVar;
1311 state = mkStatePrimTy s
1313 mkGenPrimOp SLIT("unsafeFreezeByteArray#") [s_tv]
1314 [mkMutableByteArrayPrimTy s, state]
1315 (unboxedPair [state, byteArrayPrimTy])
1317 ---------------------------------------------------------------------------
1318 primOpInfo SizeofByteArrayOp
1320 SLIT("sizeofByteArray#") []
1324 primOpInfo SizeofMutableByteArrayOp
1325 = let { s = alphaTy; s_tv = alphaTyVar } in
1327 SLIT("sizeofMutableByteArray#") [s_tv]
1328 [mkMutableByteArrayPrimTy s]
1333 %************************************************************************
1335 \subsubsection[PrimOp-MutVars]{PrimOpInfo for mutable variable ops}
1337 %************************************************************************
1340 primOpInfo NewMutVarOp
1342 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1343 state = mkStatePrimTy s
1345 mkGenPrimOp SLIT("newMutVar#") [s_tv, elt_tv]
1347 (unboxedPair [state, mkMutVarPrimTy s elt])
1349 primOpInfo ReadMutVarOp
1351 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1352 state = mkStatePrimTy s
1354 mkGenPrimOp SLIT("readMutVar#") [s_tv, elt_tv]
1355 [mkMutVarPrimTy s elt, state]
1356 (unboxedPair [state, elt])
1359 primOpInfo WriteMutVarOp
1361 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1363 mkGenPrimOp SLIT("writeMutVar#") [s_tv, elt_tv]
1364 [mkMutVarPrimTy s elt, elt, mkStatePrimTy s]
1367 primOpInfo SameMutVarOp
1369 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
1370 mut_var_ty = mkMutVarPrimTy s elt
1372 mkGenPrimOp SLIT("sameMutVar#") [s_tv, elt_tv] [mut_var_ty, mut_var_ty]
1376 %************************************************************************
1378 \subsubsection[PrimOp-Exceptions]{PrimOpInfo for exceptions}
1380 %************************************************************************
1382 catch :: IO a -> (IOError -> IO a) -> IO a
1383 catch :: a -> (b -> a) -> a
1388 a = alphaTy; a_tv = alphaTyVar
1389 b = betaTy; b_tv = betaTyVar;
1391 mkGenPrimOp SLIT("catch#") [a_tv, b_tv] [a, mkFunTy b a] a
1395 a = alphaTy; a_tv = alphaTyVar
1396 b = betaTy; b_tv = betaTyVar;
1398 mkGenPrimOp SLIT("raise#") [a_tv, b_tv] [a] b
1401 %************************************************************************
1403 \subsubsection[PrimOp-MVars]{PrimOpInfo for synchronizing Variables}
1405 %************************************************************************
1408 primOpInfo NewMVarOp
1410 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1411 state = mkStatePrimTy s
1413 mkGenPrimOp SLIT("newMVar#") [s_tv, elt_tv] [state]
1414 (unboxedPair [state, mkMVarPrimTy s elt])
1416 primOpInfo TakeMVarOp
1418 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1419 state = mkStatePrimTy s
1421 mkGenPrimOp SLIT("takeMVar#") [s_tv, elt_tv]
1422 [mkMVarPrimTy s elt, state]
1423 (unboxedPair [state, elt])
1425 primOpInfo PutMVarOp
1427 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1429 mkGenPrimOp SLIT("putMVar#") [s_tv, elt_tv]
1430 [mkMVarPrimTy s elt, elt, mkStatePrimTy s]
1433 primOpInfo SameMVarOp
1435 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1436 mvar_ty = mkMVarPrimTy s elt
1438 mkGenPrimOp SLIT("sameMVar#") [s_tv, elt_tv] [mvar_ty, mvar_ty] boolTy
1440 primOpInfo IsEmptyMVarOp
1442 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1443 state = mkStatePrimTy s
1445 mkGenPrimOp SLIT("isEmptyMVar#") [s_tv, elt_tv]
1446 [mkMVarPrimTy s elt, mkStatePrimTy s]
1447 (unboxedPair [state, intPrimTy])
1451 %************************************************************************
1453 \subsubsection[PrimOp-Wait]{PrimOpInfo for delay/wait operations}
1455 %************************************************************************
1461 s = alphaTy; s_tv = alphaTyVar
1463 mkGenPrimOp SLIT("delay#") [s_tv]
1464 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1466 primOpInfo WaitReadOp
1468 s = alphaTy; s_tv = alphaTyVar
1470 mkGenPrimOp SLIT("waitRead#") [s_tv]
1471 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1473 primOpInfo WaitWriteOp
1475 s = alphaTy; s_tv = alphaTyVar
1477 mkGenPrimOp SLIT("waitWrite#") [s_tv]
1478 [intPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1481 %************************************************************************
1483 \subsubsection[PrimOp-Concurrency]{Concurrency Primitives}
1485 %************************************************************************
1488 -- fork# :: a -> State# RealWorld -> (# State# RealWorld, ThreadId# #)
1490 = mkGenPrimOp SLIT("fork#") [alphaTyVar]
1491 [alphaTy, realWorldStatePrimTy]
1492 (unboxedPair [realWorldStatePrimTy, threadIdPrimTy])
1494 -- killThread# :: ThreadId# -> State# RealWorld -> State# RealWorld
1495 primOpInfo KillThreadOp
1496 = mkGenPrimOp SLIT("killThread#") []
1497 [threadIdPrimTy, realWorldStatePrimTy]
1498 realWorldStatePrimTy
1501 ************************************************************************
1503 \subsubsection[PrimOps-Foreign]{PrimOpInfo for Foreign Objects}
1505 %************************************************************************
1508 primOpInfo MakeForeignObjOp
1509 = mkGenPrimOp SLIT("makeForeignObj#") []
1510 [addrPrimTy, realWorldStatePrimTy]
1511 (unboxedPair [realWorldStatePrimTy, foreignObjPrimTy])
1513 primOpInfo WriteForeignObjOp
1515 s = alphaTy; s_tv = alphaTyVar
1517 mkGenPrimOp SLIT("writeForeignObj#") [s_tv]
1518 [foreignObjPrimTy, addrPrimTy, mkStatePrimTy s] (mkStatePrimTy s)
1521 ************************************************************************
1523 \subsubsection[PrimOps-Weak]{PrimOpInfo for Weak Pointers}
1525 %************************************************************************
1527 A @Weak@ Pointer is created by the @mkWeak#@ primitive:
1529 mkWeak# :: k -> v -> f -> State# RealWorld
1530 -> (# State# RealWorld, Weak# v #)
1532 In practice, you'll use the higher-level
1534 data Weak v = Weak# v
1535 mkWeak :: k -> v -> IO () -> IO (Weak v)
1539 = mkGenPrimOp SLIT("mkWeak#") [alphaTyVar, betaTyVar, gammaTyVar]
1540 [alphaTy, betaTy, gammaTy, realWorldStatePrimTy]
1541 (unboxedPair [realWorldStatePrimTy, mkWeakPrimTy betaTy])
1544 The following operation dereferences a weak pointer. The weak pointer
1545 may have been finalised, so the operation returns a result code which
1546 must be inspected before looking at the dereferenced value.
1548 deRefWeak# :: Weak# v -> State# RealWorld ->
1549 (# State# RealWorld, v, Int# #)
1551 Only look at v if the Int# returned is /= 0 !!
1553 The higher-level op is
1555 deRefWeak :: Weak v -> IO (Maybe v)
1558 primOpInfo DeRefWeakOp
1559 = mkGenPrimOp SLIT("deRefWeak#") [alphaTyVar]
1560 [mkWeakPrimTy alphaTy, realWorldStatePrimTy]
1561 (unboxedTriple [realWorldStatePrimTy, intPrimTy, alphaTy])
1564 Weak pointers can be finalised early by using the finalise# operation:
1566 finalise# :: Weak# v -> State# RealWorld -> State# RealWorld
1569 primOpInfo FinaliseWeakOp
1570 = mkGenPrimOp SLIT("finaliseWeak#") [alphaTyVar]
1571 [mkWeakPrimTy alphaTy, realWorldStatePrimTy]
1572 realWorldStatePrimTy
1575 %************************************************************************
1577 \subsubsection[PrimOp-stable-pointers]{PrimOpInfo for stable pointers and stable names}
1579 %************************************************************************
1581 A {\em stable name/pointer} is an index into a table of stable name
1582 entries. Since the garbage collector is told about stable pointers,
1583 it is safe to pass a stable pointer to external systems such as C
1587 makeStablePtr# :: a -> State# RealWorld -> (# State# RealWorld, a #)
1588 freeStablePtr :: StablePtr# a -> State# RealWorld -> State# RealWorld
1589 deRefStablePtr# :: StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
1590 eqStablePtr# :: StablePtr# a -> StablePtr# a -> Int#
1593 It may seem a bit surprising that @makeStablePtr#@ is a @IO@
1594 operation since it doesn't (directly) involve IO operations. The
1595 reason is that if some optimisation pass decided to duplicate calls to
1596 @makeStablePtr#@ and we only pass one of the stable pointers over, a
1597 massive space leak can result. Putting it into the IO monad
1598 prevents this. (Another reason for putting them in a monad is to
1599 ensure correct sequencing wrt the side-effecting @freeStablePtr@
1602 An important property of stable pointers is that if you call
1603 makeStablePtr# twice on the same object you get the same stable
1606 Note that we can implement @freeStablePtr#@ using @_ccall_@ (and,
1607 besides, it's not likely to be used from Haskell) so it's not a
1610 Question: Why @RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
1615 A stable name is like a stable pointer, but with three important differences:
1617 (a) You can't deRef one to get back to the original object.
1618 (b) You can convert one to an Int.
1619 (c) You don't need to 'freeStableName'
1621 The existence of a stable name doesn't guarantee to keep the object it
1622 points to alive (unlike a stable pointer), hence (a).
1626 (a) makeStableName always returns the same value for a given
1627 object (same as stable pointers).
1629 (b) if two stable names are equal, it implies that the objects
1630 from which they were created were the same.
1632 (c) stableNameToInt always returns the same Int for a given
1636 primOpInfo MakeStablePtrOp
1637 = mkGenPrimOp SLIT("makeStablePtr#") [alphaTyVar]
1638 [alphaTy, realWorldStatePrimTy]
1639 (unboxedPair [realWorldStatePrimTy,
1640 mkTyConApp stablePtrPrimTyCon [alphaTy]])
1642 primOpInfo DeRefStablePtrOp
1643 = mkGenPrimOp SLIT("deRefStablePtr#") [alphaTyVar]
1644 [mkStablePtrPrimTy alphaTy, realWorldStatePrimTy]
1645 (unboxedPair [realWorldStatePrimTy, alphaTy])
1647 primOpInfo EqStablePtrOp
1648 = mkGenPrimOp SLIT("eqStablePtr#") [alphaTyVar, betaTyVar]
1649 [mkStablePtrPrimTy alphaTy, mkStablePtrPrimTy betaTy]
1652 primOpInfo MakeStableNameOp
1653 = mkGenPrimOp SLIT("makeStableName#") [alphaTyVar]
1654 [alphaTy, realWorldStatePrimTy]
1655 (unboxedPair [realWorldStatePrimTy,
1656 mkTyConApp stableNamePrimTyCon [alphaTy]])
1658 primOpInfo EqStableNameOp
1659 = mkGenPrimOp SLIT("eqStableName#") [alphaTyVar, betaTyVar]
1660 [mkStableNamePrimTy alphaTy, mkStableNamePrimTy betaTy]
1663 primOpInfo StableNameToIntOp
1664 = mkGenPrimOp SLIT("stableNameToInt#") [alphaTyVar]
1665 [mkStableNamePrimTy alphaTy]
1669 %************************************************************************
1671 \subsubsection[PrimOp-unsafePointerEquality]{PrimOpInfo for Pointer Equality}
1673 %************************************************************************
1675 [Alastair Reid is to blame for this!]
1677 These days, (Glasgow) Haskell seems to have a bit of everything from
1678 other languages: strict operations, mutable variables, sequencing,
1679 pointers, etc. About the only thing left is LISP's ability to test
1680 for pointer equality. So, let's add it in!
1683 reallyUnsafePtrEquality :: a -> a -> Int#
1686 which tests any two closures (of the same type) to see if they're the
1687 same. (Returns $0$ for @False@, $\neq 0$ for @True@ - to avoid
1688 difficulties of trying to box up the result.)
1690 NB This is {\em really unsafe\/} because even something as trivial as
1691 a garbage collection might change the answer by removing indirections.
1692 Still, no-one's forcing you to use it. If you're worried about little
1693 things like loss of referential transparency, you might like to wrap
1694 it all up in a monad-like thing as John O'Donnell and John Hughes did
1695 for non-determinism (1989 (Fraserburgh) Glasgow FP Workshop
1698 I'm thinking of using it to speed up a critical equality test in some
1699 graphics stuff in a context where the possibility of saying that
1700 denotationally equal things aren't isn't a problem (as long as it
1701 doesn't happen too often.) ADR
1703 To Will: Jim said this was already in, but I can't see it so I'm
1704 adding it. Up to you whether you add it. (Note that this could have
1705 been readily implemented using a @veryDangerousCCall@ before they were
1709 primOpInfo ReallyUnsafePtrEqualityOp
1710 = mkGenPrimOp SLIT("reallyUnsafePtrEquality#") [alphaTyVar]
1711 [alphaTy, alphaTy] intPrimTy
1714 %************************************************************************
1716 \subsubsection[PrimOp-parallel]{PrimOpInfo for parallelism op(s)}
1718 %************************************************************************
1721 primOpInfo SeqOp -- seq# :: a -> Int#
1722 = mkGenPrimOp SLIT("seq#") [alphaTyVar] [alphaTy] intPrimTy
1724 primOpInfo ParOp -- par# :: a -> Int#
1725 = mkGenPrimOp SLIT("par#") [alphaTyVar] [alphaTy] intPrimTy
1729 -- HWL: The first 4 Int# in all par... annotations denote:
1730 -- name, granularity info, size of result, degree of parallelism
1731 -- Same structure as _seq_ i.e. returns Int#
1733 primOpInfo ParGlobalOp -- parGlobal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1734 = mkGenPrimOp SLIT("parGlobal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1736 primOpInfo ParLocalOp -- parLocal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1737 = mkGenPrimOp SLIT("parLocal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1739 primOpInfo ParAtOp -- parAt# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1740 = mkGenPrimOp SLIT("parAt#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
1742 primOpInfo ParAtAbsOp -- parAtAbs# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1743 = mkGenPrimOp SLIT("parAtAbs#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1745 primOpInfo ParAtRelOp -- parAtRel# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1746 = mkGenPrimOp SLIT("parAtRel#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
1748 primOpInfo ParAtForNowOp -- parAtForNow# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1749 = mkGenPrimOp SLIT("parAtForNow#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
1751 primOpInfo CopyableOp -- copyable# :: a -> a
1752 = mkGenPrimOp SLIT("copyable#") [alphaTyVar] [alphaTy] intPrimTy
1754 primOpInfo NoFollowOp -- noFollow# :: a -> a
1755 = mkGenPrimOp SLIT("noFollow#") [alphaTyVar] [alphaTy] intPrimTy
1758 %************************************************************************
1760 \subsubsection[PrimOp-IO-etc]{PrimOpInfo for C calls, and I/O-ish things}
1762 %************************************************************************
1765 primOpInfo (CCallOp _ _ _ _)
1766 = mkGenPrimOp SLIT("ccall#") [alphaTyVar] [] alphaTy
1769 primOpInfo (CCallOp _ _ _ _ arg_tys result_ty)
1770 = mkGenPrimOp SLIT("ccall#") [] arg_tys result_tycon tys_applied
1772 (result_tycon, tys_applied, _) = splitAlgTyConApp result_ty
1775 primOpInfo op = panic ("primOpInfo:"++ show (I# (tagOf_PrimOp op)))
1779 Some PrimOps need to be called out-of-line because they either need to
1780 perform a heap check or they block.
1793 NewByteArrayOp _ -> True
1794 IntegerAddOp -> True
1795 IntegerSubOp -> True
1796 IntegerMulOp -> True
1797 IntegerGcdOp -> True
1798 IntegerQuotRemOp -> True
1799 IntegerDivModOp -> True
1800 Int2IntegerOp -> True
1801 Word2IntegerOp -> True
1802 Addr2IntegerOp -> True
1803 Word64ToIntegerOp -> True
1804 Int64ToIntegerOp -> True
1805 FloatDecodeOp -> True
1806 DoubleDecodeOp -> True
1808 FinaliseWeakOp -> True
1809 MakeStableNameOp -> True
1810 MakeForeignObjOp -> True
1814 KillThreadOp -> True
1815 CCallOp _ _ may_gc@True _ -> True -- _ccall_GC_
1819 Sometimes we may choose to execute a PrimOp even though it isn't
1820 certain that its result will be required; ie execute them
1821 ``speculatively''. The same thing as ``cheap eagerness.'' Usually
1822 this is OK, because PrimOps are usually cheap, but it isn't OK for
1823 (a)~expensive PrimOps and (b)~PrimOps which can fail.
1825 See also @primOpIsCheap@ (below).
1827 PrimOps that have side effects also should not be executed speculatively
1828 or by data dependencies.
1831 primOpOkForSpeculation :: PrimOp -> Bool
1832 primOpOkForSpeculation op
1833 = not (primOpCanFail op || primOpHasSideEffects op || primOpOutOfLine op)
1836 @primOpIsCheap@, as used in \tr{SimplUtils.lhs}. For now (HACK
1837 WARNING), we just borrow some other predicates for a
1838 what-should-be-good-enough test. "Cheap" means willing to call it more
1839 than once. Evaluation order is unaffected.
1842 primOpIsCheap op = not (primOpHasSideEffects op || primOpOutOfLine op)
1846 primOpCanFail :: PrimOp -> Bool
1848 primOpCanFail IntQuotOp = True -- Divide by zero
1849 primOpCanFail IntRemOp = True -- Divide by zero
1852 primOpCanFail IntegerQuotRemOp = True -- Divide by zero
1853 primOpCanFail IntegerDivModOp = True -- Divide by zero
1855 -- Float. ToDo: tan? tanh?
1856 primOpCanFail FloatDivOp = True -- Divide by zero
1857 primOpCanFail FloatLogOp = True -- Log of zero
1858 primOpCanFail FloatAsinOp = True -- Arg out of domain
1859 primOpCanFail FloatAcosOp = True -- Arg out of domain
1861 -- Double. ToDo: tan? tanh?
1862 primOpCanFail DoubleDivOp = True -- Divide by zero
1863 primOpCanFail DoubleLogOp = True -- Log of zero
1864 primOpCanFail DoubleAsinOp = True -- Arg out of domain
1865 primOpCanFail DoubleAcosOp = True -- Arg out of domain
1867 primOpCanFail other_op = False
1870 And some primops have side-effects and so, for example, must not be
1874 primOpHasSideEffects :: PrimOp -> Bool
1876 primOpHasSideEffects TakeMVarOp = True
1877 primOpHasSideEffects DelayOp = True
1878 primOpHasSideEffects WaitReadOp = True
1879 primOpHasSideEffects WaitWriteOp = True
1881 primOpHasSideEffects ParOp = True
1882 primOpHasSideEffects ForkOp = True
1883 primOpHasSideEffects KillThreadOp = True
1884 primOpHasSideEffects SeqOp = True
1886 primOpHasSideEffects MakeForeignObjOp = True
1887 primOpHasSideEffects WriteForeignObjOp = True
1888 primOpHasSideEffects MkWeakOp = True
1889 primOpHasSideEffects DeRefWeakOp = True
1890 primOpHasSideEffects FinaliseWeakOp = True
1891 primOpHasSideEffects MakeStablePtrOp = True
1892 primOpHasSideEffects MakeStableNameOp = True
1893 primOpHasSideEffects EqStablePtrOp = True -- SOF
1894 primOpHasSideEffects DeRefStablePtrOp = True -- ??? JSM & ADR
1896 primOpHasSideEffects ParGlobalOp = True
1897 primOpHasSideEffects ParLocalOp = True
1898 primOpHasSideEffects ParAtOp = True
1899 primOpHasSideEffects ParAtAbsOp = True
1900 primOpHasSideEffects ParAtRelOp = True
1901 primOpHasSideEffects ParAtForNowOp = True
1902 primOpHasSideEffects CopyableOp = True -- Possibly not. ASP
1903 primOpHasSideEffects NoFollowOp = True -- Possibly not. ASP
1906 primOpHasSideEffects (CCallOp _ _ _ _) = True
1908 primOpHasSideEffects other = False
1911 Inline primitive operations that perform calls need wrappers to save
1912 any live variables that are stored in caller-saves registers.
1915 primOpNeedsWrapper :: PrimOp -> Bool
1917 primOpNeedsWrapper (CCallOp _ _ _ _) = True
1919 primOpNeedsWrapper Integer2IntOp = True
1920 primOpNeedsWrapper Integer2WordOp = True
1921 primOpNeedsWrapper IntegerCmpOp = True
1923 primOpNeedsWrapper FloatExpOp = True
1924 primOpNeedsWrapper FloatLogOp = True
1925 primOpNeedsWrapper FloatSqrtOp = True
1926 primOpNeedsWrapper FloatSinOp = True
1927 primOpNeedsWrapper FloatCosOp = True
1928 primOpNeedsWrapper FloatTanOp = True
1929 primOpNeedsWrapper FloatAsinOp = True
1930 primOpNeedsWrapper FloatAcosOp = True
1931 primOpNeedsWrapper FloatAtanOp = True
1932 primOpNeedsWrapper FloatSinhOp = True
1933 primOpNeedsWrapper FloatCoshOp = True
1934 primOpNeedsWrapper FloatTanhOp = True
1935 primOpNeedsWrapper FloatPowerOp = True
1936 primOpNeedsWrapper FloatEncodeOp = True
1938 primOpNeedsWrapper DoubleExpOp = True
1939 primOpNeedsWrapper DoubleLogOp = True
1940 primOpNeedsWrapper DoubleSqrtOp = True
1941 primOpNeedsWrapper DoubleSinOp = True
1942 primOpNeedsWrapper DoubleCosOp = True
1943 primOpNeedsWrapper DoubleTanOp = True
1944 primOpNeedsWrapper DoubleAsinOp = True
1945 primOpNeedsWrapper DoubleAcosOp = True
1946 primOpNeedsWrapper DoubleAtanOp = True
1947 primOpNeedsWrapper DoubleSinhOp = True
1948 primOpNeedsWrapper DoubleCoshOp = True
1949 primOpNeedsWrapper DoubleTanhOp = True
1950 primOpNeedsWrapper DoublePowerOp = True
1951 primOpNeedsWrapper DoubleEncodeOp = True
1953 primOpNeedsWrapper MakeStableNameOp = True
1954 primOpNeedsWrapper DeRefStablePtrOp = True
1956 primOpNeedsWrapper DelayOp = True
1957 primOpNeedsWrapper WaitReadOp = True
1958 primOpNeedsWrapper WaitWriteOp = True
1960 primOpNeedsWrapper other_op = False
1965 = case (primOpInfo op) of
1967 Monadic occ _ -> occ
1968 Compare occ _ -> occ
1969 GenPrimOp occ _ _ _ -> occ
1973 primOpUniq :: PrimOp -> Unique
1974 primOpUniq op = mkPrimOpIdUnique (IBOX(tagOf_PrimOp op))
1976 primOpType :: PrimOp -> Type
1978 = case (primOpInfo op) of
1979 Dyadic occ ty -> dyadic_fun_ty ty
1980 Monadic occ ty -> monadic_fun_ty ty
1981 Compare occ ty -> compare_fun_ty ty
1983 GenPrimOp occ tyvars arg_tys res_ty ->
1984 mkForAllTys tyvars (mkFunTys arg_tys res_ty)
1988 data PrimOpResultInfo
1989 = ReturnsPrim PrimRep
1992 -- Some PrimOps need not return a manifest primitive or algebraic value
1993 -- (i.e. they might return a polymorphic value). These PrimOps *must*
1994 -- be out of line, or the code generator won't work.
1996 getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo
1998 getPrimOpResultInfo op
1999 = case (primOpInfo op) of
2000 Dyadic _ ty -> ReturnsPrim (typePrimRep ty)
2001 Monadic _ ty -> ReturnsPrim (typePrimRep ty)
2002 Compare _ ty -> ReturnsAlg boolTyCon
2003 GenPrimOp _ _ _ ty ->
2004 let rep = typePrimRep ty in
2006 PtrRep -> case splitAlgTyConApp_maybe ty of
2007 Nothing -> panic "getPrimOpResultInfo"
2008 Just (tc,_,_) -> ReturnsAlg tc
2009 other -> ReturnsPrim other
2011 isCompareOp :: PrimOp -> Bool
2014 = case primOpInfo op of
2019 The commutable ops are those for which we will try to move constants
2020 to the right hand side for strength reduction.
2023 commutableOp :: PrimOp -> Bool
2025 commutableOp CharEqOp = True
2026 commutableOp CharNeOp = True
2027 commutableOp IntAddOp = True
2028 commutableOp IntMulOp = True
2029 commutableOp AndOp = True
2030 commutableOp OrOp = True
2031 commutableOp XorOp = True
2032 commutableOp IntEqOp = True
2033 commutableOp IntNeOp = True
2034 commutableOp IntegerAddOp = True
2035 commutableOp IntegerMulOp = True
2036 commutableOp IntegerGcdOp = True
2037 commutableOp FloatAddOp = True
2038 commutableOp FloatMulOp = True
2039 commutableOp FloatEqOp = True
2040 commutableOp FloatNeOp = True
2041 commutableOp DoubleAddOp = True
2042 commutableOp DoubleMulOp = True
2043 commutableOp DoubleEqOp = True
2044 commutableOp DoubleNeOp = True
2045 commutableOp _ = False
2050 mkPrimTyApp :: [TyVar] -> PrimRep -> ([TyVar], Type)
2051 -- CharRep --> ([], Char#)
2052 -- StablePtrRep --> ([a], StablePtr# a)
2053 mkPrimTyApp tvs kind
2054 = (forall_tvs, mkTyConApp tycon (mkTyVarTys forall_tvs))
2056 tycon = primRepTyCon kind
2057 forall_tvs = take (tyConArity tycon) tvs
2059 dyadic_fun_ty ty = mkFunTys [ty, ty] ty
2060 monadic_fun_ty ty = mkFunTy ty ty
2061 compare_fun_ty ty = mkFunTys [ty, ty] boolTy
2066 pprPrimOp :: PrimOp -> SDoc
2068 pprPrimOp (CCallOp fun is_casm may_gc cconv)
2070 callconv = text "{-" <> pprCallConv cconv <> text "-}"
2073 | is_casm && may_gc = "casm_GC ``"
2074 | is_casm = "casm ``"
2075 | may_gc = "ccall_GC "
2076 | otherwise = "ccall "
2079 | is_casm = text "''"
2084 Right _ -> text "dyn_"
2089 Right _ -> text "\"\""
2093 hcat [ ifPprDebug callconv
2094 , text "__", ppr_dyn
2095 , text before , ppr_fun , after]
2098 = getPprStyle $ \ sty ->
2099 if ifaceStyle sty then -- For interfaces Print it qualified with PrelGHC.
2100 ptext SLIT("PrelGHC.") <> pprOccName occ
2104 occ = primOpOcc other_op