2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[PrimOp]{Primitive operations (machine-level)}
7 #include "HsVersions.h"
10 PrimOp(..), allThePrimOps,
11 tagOf_PrimOp, -- ToDo: rm
13 primOpType, isCompareOp,
19 primOpCanTriggerGC, primOpNeedsWrapper,
20 primOpOkForSpeculation, primOpIsCheap,
22 HeapRequirement(..), primOpHeapReq,
23 StackRequirement(..), primOpStackRequired,
25 -- export for the Native Code Generator
26 primOpInfo, -- needed for primOpNameInfo
34 import PrimRep -- most of it
38 import CStrings ( identToC )
39 import Constants ( mIN_MP_INT_SIZE, mP_STRUCT_SIZE )
40 import HeapOffs ( addOff, intOff, totHdrSize, HeapOffset )
41 import Outputable ( PprStyle, Outputable(..), codeStyle, ifaceStyle )
42 import PprType ( pprParendGenType, GenTyVar{-instance Outputable-} )
44 import SMRep ( SMRep(..), SMSpecRepKind(..), SMUpdateKind(..) )
45 import TyCon ( TyCon{-instances-} )
46 import Type ( mkForAllTys, mkFunTy, mkFunTys, applyTyCon, typePrimRep,
47 getAppDataTyConExpandingDicts, SYN_IE(Type)
49 import TyVar --( alphaTyVar, betaTyVar, gammaTyVar, GenTyVar{-instance Eq-} )
50 import Unique ( Unique{-instance Eq-} )
51 import Util ( panic#, assoc, panic{-ToDo:rm-} )
54 %************************************************************************
56 \subsection[PrimOp-datatype]{Datatype for @PrimOp@ (an enumeration)}
58 %************************************************************************
60 These are in \tr{state-interface.verb} order.
64 -- dig the FORTRAN/C influence on the names...
68 = CharGtOp | CharGeOp | CharEqOp | CharNeOp | CharLtOp | CharLeOp
69 | IntGtOp | IntGeOp | IntEqOp | IntNeOp | IntLtOp | IntLeOp
70 | WordGtOp | WordGeOp | WordEqOp | WordNeOp | WordLtOp | WordLeOp
71 | AddrGtOp | AddrGeOp | AddrEqOp | AddrNeOp | AddrLtOp | AddrLeOp
72 | FloatGtOp | FloatGeOp | FloatEqOp | FloatNeOp | FloatLtOp | FloatLeOp
73 | DoubleGtOp | DoubleGeOp | DoubleEqOp | DoubleNeOp | DoubleLtOp | DoubleLeOp
79 -- IntAbsOp unused?? ADR
80 | IntAddOp | IntSubOp | IntMulOp | IntQuotOp
81 | IntRemOp | IntNegOp | IntAbsOp
84 | AndOp | OrOp | NotOp
85 | SllOp | SraOp | SrlOp -- shift {left,right} {arithmetic,logical}
86 | ISllOp | ISraOp | ISrlOp -- equivs on Int#s
87 | Int2WordOp | Word2IntOp -- casts
90 | Int2AddrOp | Addr2IntOp -- casts
92 -- Float#-related ops:
93 | FloatAddOp | FloatSubOp | FloatMulOp | FloatDivOp | FloatNegOp
94 | Float2IntOp | Int2FloatOp
96 | FloatExpOp | FloatLogOp | FloatSqrtOp
97 | FloatSinOp | FloatCosOp | FloatTanOp
98 | FloatAsinOp | FloatAcosOp | FloatAtanOp
99 | FloatSinhOp | FloatCoshOp | FloatTanhOp
100 -- not all machines have these available conveniently:
101 -- | FloatAsinhOp | FloatAcoshOp | FloatAtanhOp
102 | FloatPowerOp -- ** op
104 -- Double#-related ops:
105 | DoubleAddOp | DoubleSubOp | DoubleMulOp | DoubleDivOp | DoubleNegOp
106 | Double2IntOp | Int2DoubleOp
107 | Double2FloatOp | Float2DoubleOp
109 | DoubleExpOp | DoubleLogOp | DoubleSqrtOp
110 | DoubleSinOp | DoubleCosOp | DoubleTanOp
111 | DoubleAsinOp | DoubleAcosOp | DoubleAtanOp
112 | DoubleSinhOp | DoubleCoshOp | DoubleTanhOp
113 -- not all machines have these available conveniently:
114 -- | DoubleAsinhOp | DoubleAcoshOp | DoubleAtanhOp
115 | DoublePowerOp -- ** op
117 -- Integer (and related...) ops:
118 -- slightly weird -- to match GMP package.
119 | IntegerAddOp | IntegerSubOp | IntegerMulOp
120 | IntegerQuotRemOp | IntegerDivModOp | IntegerNegOp
124 | Integer2IntOp | Int2IntegerOp
126 | Addr2IntegerOp -- "Addr" is *always* a literal string
129 | FloatEncodeOp | FloatDecodeOp
130 | DoubleEncodeOp | DoubleDecodeOp
132 -- primitive ops for primitive arrays
135 | NewByteArrayOp PrimRep
138 | SameMutableByteArrayOp
140 | ReadArrayOp | WriteArrayOp | IndexArrayOp -- for arrays of Haskell ptrs
142 | ReadByteArrayOp PrimRep
143 | WriteByteArrayOp PrimRep
144 | IndexByteArrayOp PrimRep
145 | IndexOffAddrOp PrimRep
146 -- PrimRep can be one of {Char,Int,Addr,Float,Double}Kind.
147 -- This is just a cheesy encoding of a bunch of ops.
148 -- Note that ForeignObjRep is not included -- the only way of
149 -- creating a ForeignObj is with a ccall or casm.
151 | UnsafeFreezeArrayOp | UnsafeFreezeByteArrayOp
153 | NewSynchVarOp -- for MVars and IVars
154 | TakeMVarOp | PutMVarOp
155 | ReadIVarOp | WriteIVarOp
157 | MakeForeignObjOp -- foreign objects (malloc pointers or any old URL)
158 | WriteForeignObjOp -- modifying foreign objects [obscuro factor: 200]
159 | MakeStablePtrOp | DeRefStablePtrOp
162 A special ``trap-door'' to use in making calls direct to C functions:
164 | CCallOp FAST_STRING -- An "unboxed" ccall# to this named function
165 Bool -- True <=> really a "casm"
166 Bool -- True <=> might invoke Haskell GC
167 [Type] -- Unboxed argument; the state-token
168 -- argument will have been put *first*
169 Type -- Return type; one of the "StateAnd<blah>#" types
171 -- (... to be continued ... )
174 The ``type'' of @CCallOp foo [t1, ... tm] r@ is @t1 -> ... tm -> r@.
175 (See @primOpInfo@ for details.)
177 Note: that first arg and part of the result should be the system state
178 token (which we carry around to fool over-zealous optimisers) but
179 which isn't actually passed.
181 For example, we represent
183 ((ccall# foo [StablePtr# a, Int] Float) sp# i#) :: (Float, IoWorld)
189 (CCallOp "foo" [Universe#, StablePtr# a, Int#] FloatPrimAndUniverse False)
190 -- :: Universe# -> StablePtr# a -> Int# -> FloatPrimAndUniverse
194 (AlgAlts [ ( FloatPrimAndIoWorld,
196 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
202 Nota Bene: there are some people who find the empty list of types in
203 the @Prim@ somewhat puzzling and would represent the above by
207 (CCallOp "foo" [alpha1, alpha2, alpha3] alpha4 False)
208 -- :: /\ alpha1, alpha2 alpha3, alpha4.
209 -- alpha1 -> alpha2 -> alpha3 -> alpha4
210 [Universe#, StablePtr# a, Int#, FloatPrimAndIoWorld]
213 (AlgAlts [ ( FloatPrimAndIoWorld,
215 Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
221 But, this is a completely different way of using @CCallOp@. The most
222 major changes required if we switch to this are in @primOpInfo@, and
223 the desugarer. The major difficulty is in moving the HeapRequirement
224 stuff somewhere appropriate. (The advantage is that we could simplify
225 @CCallOp@ and record just the number of arguments with corresponding
226 simplifications in reading pragma unfoldings, the simplifier,
227 instantiation (etc) of core expressions, ... . Maybe we should think
228 about using it this way?? ADR)
231 -- (... continued from above ... )
233 -- one to support "errorIO" (and, thereby, "error")
236 -- Operation to test two closure addresses for equality (yes really!)
237 -- BLAME ALASTAIR REID FOR THIS! THE REST OF US ARE INNOCENT!
238 | ReallyUnsafePtrEqualityOp
240 -- three for parallel stuff
245 -- three for concurrency
250 | ParGlobalOp -- named global par
251 | ParLocalOp -- named local par
252 | ParAtOp -- specifies destination of local par
253 | ParAtAbsOp -- specifies destination of local par (abs processor)
254 | ParAtRelOp -- specifies destination of local par (rel processor)
255 | ParAtForNowOp -- specifies initial destination of global par
256 | CopyableOp -- marks copyable code
257 | NoFollowOp -- marks non-followup expression
260 Deriving Ix is what we really want! ToDo
261 (Chk around before deleting...)
263 tagOf_PrimOp CharGtOp = (ILIT(1) :: FAST_INT)
264 tagOf_PrimOp CharGeOp = ILIT( 2)
265 tagOf_PrimOp CharEqOp = ILIT( 3)
266 tagOf_PrimOp CharNeOp = ILIT( 4)
267 tagOf_PrimOp CharLtOp = ILIT( 5)
268 tagOf_PrimOp CharLeOp = ILIT( 6)
269 tagOf_PrimOp IntGtOp = ILIT( 7)
270 tagOf_PrimOp IntGeOp = ILIT( 8)
271 tagOf_PrimOp IntEqOp = ILIT( 9)
272 tagOf_PrimOp IntNeOp = ILIT( 10)
273 tagOf_PrimOp IntLtOp = ILIT( 11)
274 tagOf_PrimOp IntLeOp = ILIT( 12)
275 tagOf_PrimOp WordGtOp = ILIT( 13)
276 tagOf_PrimOp WordGeOp = ILIT( 14)
277 tagOf_PrimOp WordEqOp = ILIT( 15)
278 tagOf_PrimOp WordNeOp = ILIT( 16)
279 tagOf_PrimOp WordLtOp = ILIT( 17)
280 tagOf_PrimOp WordLeOp = ILIT( 18)
281 tagOf_PrimOp AddrGtOp = ILIT( 19)
282 tagOf_PrimOp AddrGeOp = ILIT( 20)
283 tagOf_PrimOp AddrEqOp = ILIT( 21)
284 tagOf_PrimOp AddrNeOp = ILIT( 22)
285 tagOf_PrimOp AddrLtOp = ILIT( 23)
286 tagOf_PrimOp AddrLeOp = ILIT( 24)
287 tagOf_PrimOp FloatGtOp = ILIT( 25)
288 tagOf_PrimOp FloatGeOp = ILIT( 26)
289 tagOf_PrimOp FloatEqOp = ILIT( 27)
290 tagOf_PrimOp FloatNeOp = ILIT( 28)
291 tagOf_PrimOp FloatLtOp = ILIT( 29)
292 tagOf_PrimOp FloatLeOp = ILIT( 30)
293 tagOf_PrimOp DoubleGtOp = ILIT( 31)
294 tagOf_PrimOp DoubleGeOp = ILIT( 32)
295 tagOf_PrimOp DoubleEqOp = ILIT( 33)
296 tagOf_PrimOp DoubleNeOp = ILIT( 34)
297 tagOf_PrimOp DoubleLtOp = ILIT( 35)
298 tagOf_PrimOp DoubleLeOp = ILIT( 36)
299 tagOf_PrimOp OrdOp = ILIT( 37)
300 tagOf_PrimOp ChrOp = ILIT( 38)
301 tagOf_PrimOp IntAddOp = ILIT( 39)
302 tagOf_PrimOp IntSubOp = ILIT( 40)
303 tagOf_PrimOp IntMulOp = ILIT( 41)
304 tagOf_PrimOp IntQuotOp = ILIT( 42)
305 tagOf_PrimOp IntRemOp = ILIT( 44)
306 tagOf_PrimOp IntNegOp = ILIT( 45)
307 tagOf_PrimOp IntAbsOp = ILIT( 46)
308 tagOf_PrimOp AndOp = ILIT( 47)
309 tagOf_PrimOp OrOp = ILIT( 48)
310 tagOf_PrimOp NotOp = ILIT( 49)
311 tagOf_PrimOp SllOp = ILIT( 50)
312 tagOf_PrimOp SraOp = ILIT( 51)
313 tagOf_PrimOp SrlOp = ILIT( 52)
314 tagOf_PrimOp ISllOp = ILIT( 53)
315 tagOf_PrimOp ISraOp = ILIT( 54)
316 tagOf_PrimOp ISrlOp = ILIT( 55)
317 tagOf_PrimOp Int2WordOp = ILIT( 56)
318 tagOf_PrimOp Word2IntOp = ILIT( 57)
319 tagOf_PrimOp Int2AddrOp = ILIT( 58)
320 tagOf_PrimOp Addr2IntOp = ILIT( 59)
321 tagOf_PrimOp FloatAddOp = ILIT( 60)
322 tagOf_PrimOp FloatSubOp = ILIT( 61)
323 tagOf_PrimOp FloatMulOp = ILIT( 62)
324 tagOf_PrimOp FloatDivOp = ILIT( 63)
325 tagOf_PrimOp FloatNegOp = ILIT( 64)
326 tagOf_PrimOp Float2IntOp = ILIT( 65)
327 tagOf_PrimOp Int2FloatOp = ILIT( 66)
328 tagOf_PrimOp FloatExpOp = ILIT( 67)
329 tagOf_PrimOp FloatLogOp = ILIT( 68)
330 tagOf_PrimOp FloatSqrtOp = ILIT( 69)
331 tagOf_PrimOp FloatSinOp = ILIT( 70)
332 tagOf_PrimOp FloatCosOp = ILIT( 71)
333 tagOf_PrimOp FloatTanOp = ILIT( 72)
334 tagOf_PrimOp FloatAsinOp = ILIT( 73)
335 tagOf_PrimOp FloatAcosOp = ILIT( 74)
336 tagOf_PrimOp FloatAtanOp = ILIT( 75)
337 tagOf_PrimOp FloatSinhOp = ILIT( 76)
338 tagOf_PrimOp FloatCoshOp = ILIT( 77)
339 tagOf_PrimOp FloatTanhOp = ILIT( 78)
340 tagOf_PrimOp FloatPowerOp = ILIT( 79)
341 tagOf_PrimOp DoubleAddOp = ILIT( 80)
342 tagOf_PrimOp DoubleSubOp = ILIT( 81)
343 tagOf_PrimOp DoubleMulOp = ILIT( 82)
344 tagOf_PrimOp DoubleDivOp = ILIT( 83)
345 tagOf_PrimOp DoubleNegOp = ILIT( 84)
346 tagOf_PrimOp Double2IntOp = ILIT( 85)
347 tagOf_PrimOp Int2DoubleOp = ILIT( 86)
348 tagOf_PrimOp Double2FloatOp = ILIT( 87)
349 tagOf_PrimOp Float2DoubleOp = ILIT( 88)
350 tagOf_PrimOp DoubleExpOp = ILIT( 89)
351 tagOf_PrimOp DoubleLogOp = ILIT( 90)
352 tagOf_PrimOp DoubleSqrtOp = ILIT( 91)
353 tagOf_PrimOp DoubleSinOp = ILIT( 92)
354 tagOf_PrimOp DoubleCosOp = ILIT( 93)
355 tagOf_PrimOp DoubleTanOp = ILIT( 94)
356 tagOf_PrimOp DoubleAsinOp = ILIT( 95)
357 tagOf_PrimOp DoubleAcosOp = ILIT( 96)
358 tagOf_PrimOp DoubleAtanOp = ILIT( 97)
359 tagOf_PrimOp DoubleSinhOp = ILIT( 98)
360 tagOf_PrimOp DoubleCoshOp = ILIT( 99)
361 tagOf_PrimOp DoubleTanhOp = ILIT(100)
362 tagOf_PrimOp DoublePowerOp = ILIT(101)
363 tagOf_PrimOp IntegerAddOp = ILIT(102)
364 tagOf_PrimOp IntegerSubOp = ILIT(103)
365 tagOf_PrimOp IntegerMulOp = ILIT(104)
366 tagOf_PrimOp IntegerQuotRemOp = ILIT(105)
367 tagOf_PrimOp IntegerDivModOp = ILIT(106)
368 tagOf_PrimOp IntegerNegOp = ILIT(107)
369 tagOf_PrimOp IntegerCmpOp = ILIT(108)
370 tagOf_PrimOp Integer2IntOp = ILIT(109)
371 tagOf_PrimOp Int2IntegerOp = ILIT(110)
372 tagOf_PrimOp Word2IntegerOp = ILIT(111)
373 tagOf_PrimOp Addr2IntegerOp = ILIT(112)
374 tagOf_PrimOp FloatEncodeOp = ILIT(113)
375 tagOf_PrimOp FloatDecodeOp = ILIT(114)
376 tagOf_PrimOp DoubleEncodeOp = ILIT(115)
377 tagOf_PrimOp DoubleDecodeOp = ILIT(116)
378 tagOf_PrimOp NewArrayOp = ILIT(117)
379 tagOf_PrimOp (NewByteArrayOp CharRep) = ILIT(118)
380 tagOf_PrimOp (NewByteArrayOp IntRep) = ILIT(119)
381 tagOf_PrimOp (NewByteArrayOp AddrRep) = ILIT(120)
382 tagOf_PrimOp (NewByteArrayOp FloatRep) = ILIT(121)
383 tagOf_PrimOp (NewByteArrayOp DoubleRep)= ILIT(122)
384 tagOf_PrimOp SameMutableArrayOp = ILIT(123)
385 tagOf_PrimOp SameMutableByteArrayOp = ILIT(124)
386 tagOf_PrimOp ReadArrayOp = ILIT(125)
387 tagOf_PrimOp WriteArrayOp = ILIT(126)
388 tagOf_PrimOp IndexArrayOp = ILIT(127)
389 tagOf_PrimOp (ReadByteArrayOp CharRep) = ILIT(128)
390 tagOf_PrimOp (ReadByteArrayOp IntRep) = ILIT(129)
391 tagOf_PrimOp (ReadByteArrayOp AddrRep) = ILIT(130)
392 tagOf_PrimOp (ReadByteArrayOp FloatRep) = ILIT(131)
393 tagOf_PrimOp (ReadByteArrayOp DoubleRep) = ILIT(132)
394 tagOf_PrimOp (WriteByteArrayOp CharRep) = ILIT(133)
395 tagOf_PrimOp (WriteByteArrayOp IntRep) = ILIT(134)
396 tagOf_PrimOp (WriteByteArrayOp AddrRep) = ILIT(135)
397 tagOf_PrimOp (WriteByteArrayOp FloatRep) = ILIT(136)
398 tagOf_PrimOp (WriteByteArrayOp DoubleRep) = ILIT(137)
399 tagOf_PrimOp (IndexByteArrayOp CharRep) = ILIT(138)
400 tagOf_PrimOp (IndexByteArrayOp IntRep) = ILIT(139)
401 tagOf_PrimOp (IndexByteArrayOp AddrRep) = ILIT(140)
402 tagOf_PrimOp (IndexByteArrayOp FloatRep) = ILIT(141)
403 tagOf_PrimOp (IndexByteArrayOp DoubleRep) = ILIT(142)
404 tagOf_PrimOp (IndexOffAddrOp CharRep) = ILIT(143)
405 tagOf_PrimOp (IndexOffAddrOp IntRep) = ILIT(144)
406 tagOf_PrimOp (IndexOffAddrOp AddrRep) = ILIT(145)
407 tagOf_PrimOp (IndexOffAddrOp FloatRep) = ILIT(146)
408 tagOf_PrimOp (IndexOffAddrOp DoubleRep) = ILIT(147)
409 tagOf_PrimOp UnsafeFreezeArrayOp = ILIT(148)
410 tagOf_PrimOp UnsafeFreezeByteArrayOp = ILIT(149)
411 tagOf_PrimOp NewSynchVarOp = ILIT(150)
412 tagOf_PrimOp TakeMVarOp = ILIT(151)
413 tagOf_PrimOp PutMVarOp = ILIT(152)
414 tagOf_PrimOp ReadIVarOp = ILIT(153)
415 tagOf_PrimOp WriteIVarOp = ILIT(154)
416 tagOf_PrimOp MakeForeignObjOp = ILIT(155)
417 tagOf_PrimOp WriteForeignObjOp = ILIT(156)
418 tagOf_PrimOp MakeStablePtrOp = ILIT(157)
419 tagOf_PrimOp DeRefStablePtrOp = ILIT(158)
420 tagOf_PrimOp (CCallOp _ _ _ _ _) = ILIT(159)
421 tagOf_PrimOp ErrorIOPrimOp = ILIT(160)
422 tagOf_PrimOp ReallyUnsafePtrEqualityOp = ILIT(161)
423 tagOf_PrimOp SeqOp = ILIT(162)
424 tagOf_PrimOp ParOp = ILIT(163)
425 tagOf_PrimOp ForkOp = ILIT(164)
426 tagOf_PrimOp DelayOp = ILIT(165)
427 tagOf_PrimOp WaitReadOp = ILIT(166)
428 tagOf_PrimOp WaitWriteOp = ILIT(167)
430 tagOf_PrimOp ParGlobalOp = ILIT(168)
431 tagOf_PrimOp ParLocalOp = ILIT(169)
432 tagOf_PrimOp ParAtOp = ILIT(170)
433 tagOf_PrimOp ParAtAbsOp = ILIT(171)
434 tagOf_PrimOp ParAtRelOp = ILIT(172)
435 tagOf_PrimOp ParAtForNowOp = ILIT(173)
436 tagOf_PrimOp CopyableOp = ILIT(174)
437 tagOf_PrimOp NoFollowOp = ILIT(175)
439 tagOf_PrimOp _ = panic# "tagOf_PrimOp: pattern-match"
441 instance Eq PrimOp where
442 op == op2 = tagOf_PrimOp op _EQ_ tagOf_PrimOp op2
445 An @Enum@-derived list would be better; meanwhile... (ToDo)
563 NewByteArrayOp CharRep,
564 NewByteArrayOp IntRep,
565 NewByteArrayOp AddrRep,
566 NewByteArrayOp FloatRep,
567 NewByteArrayOp DoubleRep,
569 SameMutableByteArrayOp,
573 ReadByteArrayOp CharRep,
574 ReadByteArrayOp IntRep,
575 ReadByteArrayOp AddrRep,
576 ReadByteArrayOp FloatRep,
577 ReadByteArrayOp DoubleRep,
578 WriteByteArrayOp CharRep,
579 WriteByteArrayOp IntRep,
580 WriteByteArrayOp AddrRep,
581 WriteByteArrayOp FloatRep,
582 WriteByteArrayOp DoubleRep,
583 IndexByteArrayOp CharRep,
584 IndexByteArrayOp IntRep,
585 IndexByteArrayOp AddrRep,
586 IndexByteArrayOp FloatRep,
587 IndexByteArrayOp DoubleRep,
588 IndexOffAddrOp CharRep,
589 IndexOffAddrOp IntRep,
590 IndexOffAddrOp AddrRep,
591 IndexOffAddrOp FloatRep,
592 IndexOffAddrOp DoubleRep,
594 UnsafeFreezeByteArrayOp,
605 ReallyUnsafePtrEqualityOp,
624 %************************************************************************
626 \subsection[PrimOp-info]{The essential info about each @PrimOp@}
628 %************************************************************************
630 The @String@ in the @PrimOpInfos@ is the ``base name'' by which the user may
631 refer to the primitive operation. The conventional \tr{#}-for-
632 unboxed ops is added on later.
634 The reason for the funny characters in the names is so we do not
635 interfere with the programmer's Haskell name spaces.
637 We use @PrimKinds@ for the ``type'' information, because they're
638 (slightly) more convenient to use than @TyCons@.
641 = Dyadic FAST_STRING -- string :: T -> T -> T
643 | Monadic FAST_STRING -- string :: T -> T
645 | Compare FAST_STRING -- string :: T -> T -> Bool
647 | Coercing FAST_STRING -- string :: T1 -> T2
651 | PrimResult FAST_STRING
652 [TyVar] [Type] TyCon PrimRep [Type]
653 -- "PrimResult tvs [t1,..,tn] D# kind [s1,..,sm]"
654 -- has type Forall tvs. t1 -> ... -> tn -> (D# s1 ... sm)
655 -- D# is a primitive type constructor.
656 -- (the kind is the same info as D#, in another convenient form)
658 | AlgResult FAST_STRING
659 [TyVar] [Type] TyCon [Type]
660 -- "AlgResult tvs [t1,..,tn] T [s1,..,sm]"
661 -- has type Forall tvs. t1 -> ... -> tn -> (T s1 ... sm)
663 -- ToDo: Specialised calls to PrimOps are prohibited but may be desirable
668 one_Integer_ty = [intPrimTy, intPrimTy, byteArrayPrimTy]
670 = [intPrimTy, intPrimTy, byteArrayPrimTy, -- first Integer pieces
671 intPrimTy, intPrimTy, byteArrayPrimTy] -- second '' pieces
672 an_Integer_and_Int_tys
673 = [intPrimTy, intPrimTy, byteArrayPrimTy, -- Integer
676 integerMonadic name = AlgResult name [] one_Integer_ty integerTyCon []
678 integerDyadic name = AlgResult name [] two_Integer_tys integerTyCon []
680 integerDyadic2Results name = AlgResult name [] two_Integer_tys return2GMPsTyCon []
682 integerCompare name = PrimResult name [] two_Integer_tys intPrimTyCon IntRep []
685 @primOpInfo@ gives all essential information (from which everything
686 else, notably a type, can be constructed) for each @PrimOp@.
689 primOpInfo :: PrimOp -> PrimOpInfo
692 There's plenty of this stuff!
694 %************************************************************************
696 \subsubsection[PrimOp-comparison]{PrimOpInfo basic comparison ops}
698 %************************************************************************
701 primOpInfo CharGtOp = Compare SLIT("gtChar#") charPrimTy
702 primOpInfo CharGeOp = Compare SLIT("geChar#") charPrimTy
703 primOpInfo CharEqOp = Compare SLIT("eqChar#") charPrimTy
704 primOpInfo CharNeOp = Compare SLIT("neChar#") charPrimTy
705 primOpInfo CharLtOp = Compare SLIT("ltChar#") charPrimTy
706 primOpInfo CharLeOp = Compare SLIT("leChar#") charPrimTy
708 primOpInfo IntGtOp = Compare SLIT(">#") intPrimTy
709 primOpInfo IntGeOp = Compare SLIT(">=#") intPrimTy
710 primOpInfo IntEqOp = Compare SLIT("==#") intPrimTy
711 primOpInfo IntNeOp = Compare SLIT("/=#") intPrimTy
712 primOpInfo IntLtOp = Compare SLIT("<#") intPrimTy
713 primOpInfo IntLeOp = Compare SLIT("<=#") intPrimTy
715 primOpInfo WordGtOp = Compare SLIT("gtWord#") wordPrimTy
716 primOpInfo WordGeOp = Compare SLIT("geWord#") wordPrimTy
717 primOpInfo WordEqOp = Compare SLIT("eqWord#") wordPrimTy
718 primOpInfo WordNeOp = Compare SLIT("neWord#") wordPrimTy
719 primOpInfo WordLtOp = Compare SLIT("ltWord#") wordPrimTy
720 primOpInfo WordLeOp = Compare SLIT("leWord#") wordPrimTy
722 primOpInfo AddrGtOp = Compare SLIT("gtAddr#") addrPrimTy
723 primOpInfo AddrGeOp = Compare SLIT("geAddr#") addrPrimTy
724 primOpInfo AddrEqOp = Compare SLIT("eqAddr#") addrPrimTy
725 primOpInfo AddrNeOp = Compare SLIT("neAddr#") addrPrimTy
726 primOpInfo AddrLtOp = Compare SLIT("ltAddr#") addrPrimTy
727 primOpInfo AddrLeOp = Compare SLIT("leAddr#") addrPrimTy
729 primOpInfo FloatGtOp = Compare SLIT("gtFloat#") floatPrimTy
730 primOpInfo FloatGeOp = Compare SLIT("geFloat#") floatPrimTy
731 primOpInfo FloatEqOp = Compare SLIT("eqFloat#") floatPrimTy
732 primOpInfo FloatNeOp = Compare SLIT("neFloat#") floatPrimTy
733 primOpInfo FloatLtOp = Compare SLIT("ltFloat#") floatPrimTy
734 primOpInfo FloatLeOp = Compare SLIT("leFloat#") floatPrimTy
736 primOpInfo DoubleGtOp = Compare SLIT(">##") doublePrimTy
737 primOpInfo DoubleGeOp = Compare SLIT(">=##") doublePrimTy
738 primOpInfo DoubleEqOp = Compare SLIT("==##") doublePrimTy
739 primOpInfo DoubleNeOp = Compare SLIT("/=##") doublePrimTy
740 primOpInfo DoubleLtOp = Compare SLIT("<##") doublePrimTy
741 primOpInfo DoubleLeOp = Compare SLIT("<=##") doublePrimTy
744 %************************************************************************
746 \subsubsection[PrimOp-Char]{PrimOpInfo for @Char#@s}
748 %************************************************************************
751 primOpInfo OrdOp = Coercing SLIT("ord#") charPrimTy intPrimTy
752 primOpInfo ChrOp = Coercing SLIT("chr#") intPrimTy charPrimTy
755 %************************************************************************
757 \subsubsection[PrimOp-Int]{PrimOpInfo for @Int#@s}
759 %************************************************************************
762 primOpInfo IntAddOp = Dyadic SLIT("+#") intPrimTy
763 primOpInfo IntSubOp = Dyadic SLIT("-#") intPrimTy
764 primOpInfo IntMulOp = Dyadic SLIT("*#") intPrimTy
765 primOpInfo IntQuotOp = Dyadic SLIT("quotInt#") intPrimTy
766 primOpInfo IntRemOp = Dyadic SLIT("remInt#") intPrimTy
768 primOpInfo IntNegOp = Monadic SLIT("negateInt#") intPrimTy
769 primOpInfo IntAbsOp = Monadic SLIT("absInt#") intPrimTy
772 %************************************************************************
774 \subsubsection[PrimOp-Word]{PrimOpInfo for @Word#@s}
776 %************************************************************************
778 A @Word#@ is an unsigned @Int#@.
781 primOpInfo AndOp = Dyadic SLIT("and#") wordPrimTy
782 primOpInfo OrOp = Dyadic SLIT("or#") wordPrimTy
783 primOpInfo NotOp = Monadic SLIT("not#") wordPrimTy
786 = PrimResult SLIT("shiftL#") [] [wordPrimTy, intPrimTy] wordPrimTyCon WordRep []
788 = PrimResult SLIT("shiftRA#") [] [wordPrimTy, intPrimTy] wordPrimTyCon WordRep []
790 = PrimResult SLIT("shiftRL#") [] [wordPrimTy, intPrimTy] wordPrimTyCon WordRep []
793 = PrimResult SLIT("iShiftL#") [] [intPrimTy, intPrimTy] intPrimTyCon IntRep []
795 = PrimResult SLIT("iShiftRA#") [] [intPrimTy, intPrimTy] intPrimTyCon IntRep []
797 = PrimResult SLIT("iShiftRL#") [] [intPrimTy, intPrimTy] intPrimTyCon IntRep []
799 primOpInfo Int2WordOp = Coercing SLIT("int2Word#") intPrimTy wordPrimTy
800 primOpInfo Word2IntOp = Coercing SLIT("word2Int#") wordPrimTy intPrimTy
803 %************************************************************************
805 \subsubsection[PrimOp-Addr]{PrimOpInfo for @Addr#@s}
807 %************************************************************************
810 primOpInfo Int2AddrOp = Coercing SLIT("int2Addr#") intPrimTy addrPrimTy
811 primOpInfo Addr2IntOp = Coercing SLIT("addr2Int#") addrPrimTy intPrimTy
814 %************************************************************************
816 \subsubsection[PrimOp-Float]{PrimOpInfo for @Float#@s}
818 %************************************************************************
820 @encodeFloat#@ and @decodeFloat#@ are given w/ Integer-stuff (it's
824 primOpInfo FloatAddOp = Dyadic SLIT("plusFloat#") floatPrimTy
825 primOpInfo FloatSubOp = Dyadic SLIT("minusFloat#") floatPrimTy
826 primOpInfo FloatMulOp = Dyadic SLIT("timesFloat#") floatPrimTy
827 primOpInfo FloatDivOp = Dyadic SLIT("divideFloat#") floatPrimTy
828 primOpInfo FloatNegOp = Monadic SLIT("negateFloat#") floatPrimTy
830 primOpInfo Float2IntOp = Coercing SLIT("float2Int#") floatPrimTy intPrimTy
831 primOpInfo Int2FloatOp = Coercing SLIT("int2Float#") intPrimTy floatPrimTy
833 primOpInfo FloatExpOp = Monadic SLIT("expFloat#") floatPrimTy
834 primOpInfo FloatLogOp = Monadic SLIT("logFloat#") floatPrimTy
835 primOpInfo FloatSqrtOp = Monadic SLIT("sqrtFloat#") floatPrimTy
836 primOpInfo FloatSinOp = Monadic SLIT("sinFloat#") floatPrimTy
837 primOpInfo FloatCosOp = Monadic SLIT("cosFloat#") floatPrimTy
838 primOpInfo FloatTanOp = Monadic SLIT("tanFloat#") floatPrimTy
839 primOpInfo FloatAsinOp = Monadic SLIT("asinFloat#") floatPrimTy
840 primOpInfo FloatAcosOp = Monadic SLIT("acosFloat#") floatPrimTy
841 primOpInfo FloatAtanOp = Monadic SLIT("atanFloat#") floatPrimTy
842 primOpInfo FloatSinhOp = Monadic SLIT("sinhFloat#") floatPrimTy
843 primOpInfo FloatCoshOp = Monadic SLIT("coshFloat#") floatPrimTy
844 primOpInfo FloatTanhOp = Monadic SLIT("tanhFloat#") floatPrimTy
845 primOpInfo FloatPowerOp = Dyadic SLIT("powerFloat#") floatPrimTy
848 %************************************************************************
850 \subsubsection[PrimOp-Double]{PrimOpInfo for @Double#@s}
852 %************************************************************************
854 @encodeDouble#@ and @decodeDouble#@ are given w/ Integer-stuff (it's
858 primOpInfo DoubleAddOp = Dyadic SLIT("+##") doublePrimTy
859 primOpInfo DoubleSubOp = Dyadic SLIT("-##") doublePrimTy
860 primOpInfo DoubleMulOp = Dyadic SLIT("*##") doublePrimTy
861 primOpInfo DoubleDivOp = Dyadic SLIT("/##") doublePrimTy
862 primOpInfo DoubleNegOp = Monadic SLIT("negateDouble#") doublePrimTy
864 primOpInfo Double2IntOp = Coercing SLIT("double2Int#") doublePrimTy intPrimTy
865 primOpInfo Int2DoubleOp = Coercing SLIT("int2Double#") intPrimTy doublePrimTy
867 primOpInfo Double2FloatOp = Coercing SLIT("double2Float#") doublePrimTy floatPrimTy
868 primOpInfo Float2DoubleOp = Coercing SLIT("float2Double#") floatPrimTy doublePrimTy
870 primOpInfo DoubleExpOp = Monadic SLIT("expDouble#") doublePrimTy
871 primOpInfo DoubleLogOp = Monadic SLIT("logDouble#") doublePrimTy
872 primOpInfo DoubleSqrtOp = Monadic SLIT("sqrtDouble#") doublePrimTy
873 primOpInfo DoubleSinOp = Monadic SLIT("sinDouble#") doublePrimTy
874 primOpInfo DoubleCosOp = Monadic SLIT("cosDouble#") doublePrimTy
875 primOpInfo DoubleTanOp = Monadic SLIT("tanDouble#") doublePrimTy
876 primOpInfo DoubleAsinOp = Monadic SLIT("asinDouble#") doublePrimTy
877 primOpInfo DoubleAcosOp = Monadic SLIT("acosDouble#") doublePrimTy
878 primOpInfo DoubleAtanOp = Monadic SLIT("atanDouble#") doublePrimTy
879 primOpInfo DoubleSinhOp = Monadic SLIT("sinhDouble#") doublePrimTy
880 primOpInfo DoubleCoshOp = Monadic SLIT("coshDouble#") doublePrimTy
881 primOpInfo DoubleTanhOp = Monadic SLIT("tanhDouble#") doublePrimTy
882 primOpInfo DoublePowerOp= Dyadic SLIT("**##") doublePrimTy
885 %************************************************************************
887 \subsubsection[PrimOp-Integer]{PrimOpInfo for @Integer@ (and related!)}
889 %************************************************************************
892 primOpInfo IntegerNegOp = integerMonadic SLIT("negateInteger#")
894 primOpInfo IntegerAddOp = integerDyadic SLIT("plusInteger#")
895 primOpInfo IntegerSubOp = integerDyadic SLIT("minusInteger#")
896 primOpInfo IntegerMulOp = integerDyadic SLIT("timesInteger#")
898 primOpInfo IntegerCmpOp = integerCompare SLIT("cmpInteger#")
900 primOpInfo IntegerQuotRemOp = integerDyadic2Results SLIT("quotRemInteger#")
901 primOpInfo IntegerDivModOp = integerDyadic2Results SLIT("divModInteger#")
903 primOpInfo Integer2IntOp
904 = PrimResult SLIT("integer2Int#") [] one_Integer_ty intPrimTyCon IntRep []
906 primOpInfo Int2IntegerOp
907 = AlgResult SLIT("int2Integer#") [] [intPrimTy] integerTyCon []
909 primOpInfo Word2IntegerOp
910 = AlgResult SLIT("word2Integer#") [] [wordPrimTy] integerTyCon []
912 primOpInfo Addr2IntegerOp
913 = AlgResult SLIT("addr2Integer#") [] [addrPrimTy] integerTyCon []
916 Encoding and decoding of floating-point numbers is sorta
920 primOpInfo FloatEncodeOp
921 = PrimResult SLIT("encodeFloat#") [] an_Integer_and_Int_tys
922 floatPrimTyCon FloatRep []
924 primOpInfo DoubleEncodeOp
925 = PrimResult SLIT("encodeDouble#") [] an_Integer_and_Int_tys
926 doublePrimTyCon DoubleRep []
928 primOpInfo FloatDecodeOp
929 = AlgResult SLIT("decodeFloat#") [] [floatPrimTy] returnIntAndGMPTyCon []
931 primOpInfo DoubleDecodeOp
932 = AlgResult SLIT("decodeDouble#") [] [doublePrimTy] returnIntAndGMPTyCon []
935 %************************************************************************
937 \subsubsection[PrimOp-Arrays]{PrimOpInfo for primitive arrays}
939 %************************************************************************
942 primOpInfo NewArrayOp
944 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
946 AlgResult SLIT("newArray#") [s_tv, elt_tv] [intPrimTy, elt, mkStatePrimTy s]
947 stateAndMutableArrayPrimTyCon [s, elt]
949 primOpInfo (NewByteArrayOp kind)
951 s = alphaTy; s_tv = alphaTyVar
953 (str, _, prim_tycon) = getPrimRepInfo kind
955 op_str = _PK_ ("new" ++ str ++ "Array#")
957 AlgResult op_str [s_tv]
958 [intPrimTy, mkStatePrimTy s]
959 stateAndMutableByteArrayPrimTyCon [s]
961 ---------------------------------------------------------------------------
963 primOpInfo SameMutableArrayOp
965 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
966 mut_arr_ty = mkMutableArrayPrimTy s elt
968 AlgResult SLIT("sameMutableArray#") [s_tv, elt_tv] [mut_arr_ty, mut_arr_ty]
971 primOpInfo SameMutableByteArrayOp
973 s = alphaTy; s_tv = alphaTyVar;
974 mut_arr_ty = mkMutableByteArrayPrimTy s
976 AlgResult SLIT("sameMutableByteArray#") [s_tv] [mut_arr_ty, mut_arr_ty]
979 ---------------------------------------------------------------------------
980 -- Primitive arrays of Haskell pointers:
982 primOpInfo ReadArrayOp
984 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
986 AlgResult SLIT("readArray#") [s_tv, elt_tv]
987 [mkMutableArrayPrimTy s elt, intPrimTy, mkStatePrimTy s]
988 stateAndPtrPrimTyCon [s, elt]
991 primOpInfo WriteArrayOp
993 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
995 PrimResult SLIT("writeArray#") [s_tv, elt_tv]
996 [mkMutableArrayPrimTy s elt, intPrimTy, elt, mkStatePrimTy s]
997 statePrimTyCon VoidRep [s]
999 primOpInfo IndexArrayOp
1000 = let { elt = alphaTy; elt_tv = alphaTyVar } in
1001 AlgResult SLIT("indexArray#") [elt_tv] [mkArrayPrimTy elt, intPrimTy]
1004 ---------------------------------------------------------------------------
1005 -- Primitive arrays full of unboxed bytes:
1007 primOpInfo (ReadByteArrayOp kind)
1009 s = alphaTy; s_tv = alphaTyVar
1011 (str, _, prim_tycon) = getPrimRepInfo kind
1013 op_str = _PK_ ("read" ++ str ++ "Array#")
1014 relevant_tycon = assoc "primOpInfo" tbl kind
1016 AlgResult op_str [s_tv]
1017 [mkMutableByteArrayPrimTy s, intPrimTy, mkStatePrimTy s]
1020 tbl = [ (CharRep, stateAndCharPrimTyCon),
1021 (IntRep, stateAndIntPrimTyCon),
1022 (AddrRep, stateAndAddrPrimTyCon),
1023 (FloatRep, stateAndFloatPrimTyCon),
1024 (DoubleRep, stateAndDoublePrimTyCon) ]
1026 -- How come there's no Word byte arrays? ADR
1028 primOpInfo (WriteByteArrayOp kind)
1030 s = alphaTy; s_tv = alphaTyVar
1032 (str, prim_ty, _) = getPrimRepInfo kind
1033 op_str = _PK_ ("write" ++ str ++ "Array#")
1035 -- NB: *Prim*Result --
1036 PrimResult op_str [s_tv]
1037 [mkMutableByteArrayPrimTy s, intPrimTy, prim_ty, mkStatePrimTy s]
1038 statePrimTyCon VoidRep [s]
1040 primOpInfo (IndexByteArrayOp kind)
1042 (str, _, prim_tycon) = getPrimRepInfo kind
1043 op_str = _PK_ ("index" ++ str ++ "Array#")
1045 -- NB: *Prim*Result --
1046 PrimResult op_str [] [byteArrayPrimTy, intPrimTy] prim_tycon kind []
1048 primOpInfo (IndexOffAddrOp kind)
1050 (str, _, prim_tycon) = getPrimRepInfo kind
1051 op_str = _PK_ ("index" ++ str ++ "OffAddr#")
1053 PrimResult op_str [] [addrPrimTy, intPrimTy] prim_tycon kind []
1055 ---------------------------------------------------------------------------
1056 primOpInfo UnsafeFreezeArrayOp
1058 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1060 AlgResult SLIT("unsafeFreezeArray#") [s_tv, elt_tv]
1061 [mkMutableArrayPrimTy s elt, mkStatePrimTy s]
1062 stateAndArrayPrimTyCon [s, elt]
1064 primOpInfo UnsafeFreezeByteArrayOp
1065 = let { s = alphaTy; s_tv = alphaTyVar } in
1066 AlgResult SLIT("unsafeFreezeByteArray#") [s_tv]
1067 [mkMutableByteArrayPrimTy s, mkStatePrimTy s]
1068 stateAndByteArrayPrimTyCon [s]
1071 %************************************************************************
1073 \subsubsection[PrimOp-SynchVars]{PrimOpInfo for synchronizing Variables}
1075 %************************************************************************
1078 primOpInfo NewSynchVarOp
1080 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1082 AlgResult SLIT("newSynchVar#") [s_tv, elt_tv] [mkStatePrimTy s]
1083 stateAndSynchVarPrimTyCon [s, elt]
1085 primOpInfo TakeMVarOp
1087 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1089 AlgResult SLIT("takeMVar#") [s_tv, elt_tv]
1090 [mkSynchVarPrimTy s elt, mkStatePrimTy s]
1091 stateAndPtrPrimTyCon [s, elt]
1093 primOpInfo PutMVarOp
1095 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1097 AlgResult SLIT("putMVar#") [s_tv, elt_tv]
1098 [mkSynchVarPrimTy s elt, elt, mkStatePrimTy s]
1101 primOpInfo ReadIVarOp
1103 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1105 AlgResult SLIT("readIVar#") [s_tv, elt_tv]
1106 [mkSynchVarPrimTy s elt, mkStatePrimTy s]
1107 stateAndPtrPrimTyCon [s, elt]
1109 primOpInfo WriteIVarOp
1111 elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
1113 AlgResult SLIT("writeIVar#") [s_tv, elt_tv]
1114 [mkSynchVarPrimTy s elt, elt, mkStatePrimTy s]
1119 %************************************************************************
1121 \subsubsection[PrimOp-Wait]{PrimOpInfo for delay/wait operations}
1123 %************************************************************************
1129 s = alphaTy; s_tv = alphaTyVar
1131 PrimResult SLIT("delay#") [s_tv]
1132 [intPrimTy, mkStatePrimTy s]
1133 statePrimTyCon VoidRep [s]
1135 primOpInfo WaitReadOp
1137 s = alphaTy; s_tv = alphaTyVar
1139 PrimResult SLIT("waitRead#") [s_tv]
1140 [intPrimTy, mkStatePrimTy s]
1141 statePrimTyCon VoidRep [s]
1143 primOpInfo WaitWriteOp
1145 s = alphaTy; s_tv = alphaTyVar
1147 PrimResult SLIT("waitWrite#") [s_tv]
1148 [intPrimTy, mkStatePrimTy s]
1149 statePrimTyCon VoidRep [s]
1152 %************************************************************************
1154 \subsubsection[PrimOps-ForeignObj]{PrimOpInfo for Foreign Objects}
1156 %************************************************************************
1158 Not everything should/can be in the Haskell heap. As an example, in an
1159 image processing application written in Haskell, you really would like
1160 to avoid heaving huge images between different space or generations of
1161 a garbage collector. Instead use @ForeignObj@ (formerly known as @MallocPtr@),
1162 which refer to some externally allocated structure/value. Using @ForeignObj@,
1163 just a reference to an image is present in the heap, the image could then
1164 be stored outside the Haskell heap, i.e., as a malloc'ed structure or in
1165 a completely separate address space alltogether.
1167 When a @ForeignObj@ becomes garbage, a user-defined finalisation routine
1168 associated with the object is invoked (currently, each ForeignObj has a
1169 direct reference to its finaliser). -- SOF
1171 A @ForeignObj@ is created by the @makeForeignObj#@ primitive:
1174 makeForeignObj# :: Addr# -- foreign object
1175 -> Addr# -- ptr to its finaliser routine
1176 -> StateAndForeignObj# _RealWorld# ForeignObj#
1181 primOpInfo MakeForeignObjOp
1182 = AlgResult SLIT("makeForeignObj#") []
1183 [addrPrimTy, addrPrimTy, realWorldStatePrimTy]
1184 stateAndForeignObjPrimTyCon [realWorldTy]
1188 In addition, another @ForeignObj@ primitive is provided for destructively modifying
1189 the external object wrapped up inside a @ForeignObj@. This primitive is used
1190 when a mixed programming interface of implicit and explicit de-allocation is used,
1191 e.g., if @ForeignObj@s are used to implement @Handle@s, then @Handle@s can be
1192 released either explicitly (through @hClose@) or implicitly (via a finaliser).
1193 When releasing/closing the @Handle@ explicitly, care must be taken to avoid having
1194 the finaliser for the embedded @ForeignObj@ attempt the same thing later.
1195 We deal with this situation, by allowing the programmer to destructively modify
1196 the data field of the @ForeignObj@ to hold a special value the finaliser recognises,
1197 and does not attempt to free (e.g., filling the data slot with \tr{NULL}).
1200 writeForeignObj# :: ForeignObj# -- foreign object
1201 -> Addr# -- new data value
1202 -> StateAndForeignObj# _RealWorld# ForeignObj#
1206 primOpInfo WriteForeignObjOp
1208 s = alphaTy; s_tv = alphaTyVar
1210 PrimResult SLIT("writeForeignObj#") [s_tv]
1211 [foreignObjPrimTy, addrPrimTy, mkStatePrimTy s]
1212 statePrimTyCon VoidRep [s]
1215 %************************************************************************
1217 \subsubsection[PrimOp-stable-pointers]{PrimOpInfo for ``stable pointers''}
1219 %************************************************************************
1221 A {\em stable pointer} is an index into a table of pointers into the
1222 heap. Since the garbage collector is told about stable pointers, it
1223 is safe to pass a stable pointer to external systems such as C
1226 Here's what the operations and types are supposed to be (from
1227 state-interface document).
1230 makeStablePtr# :: a -> State# _RealWorld -> StateAndStablePtr# _RealWorld a
1231 freeStablePtr# :: StablePtr# a -> State# _RealWorld -> State# _RealWorld
1232 deRefStablePtr# :: StablePtr# a -> State# _RealWorld -> StateAndPtr _RealWorld a
1235 It may seem a bit surprising that @makeStablePtr#@ is a @PrimIO@
1236 operation since it doesn't (directly) involve IO operations. The
1237 reason is that if some optimisation pass decided to duplicate calls to
1238 @makeStablePtr#@ and we only pass one of the stable pointers over, a
1239 massive space leak can result. Putting it into the PrimIO monad
1240 prevents this. (Another reason for putting them in a monad is to
1241 ensure correct sequencing wrt the side-effecting @freeStablePtr#@
1244 Note that we can implement @freeStablePtr#@ using @_ccall_@ (and,
1245 besides, it's not likely to be used from Haskell) so it's not a
1248 Question: Why @_RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
1251 primOpInfo MakeStablePtrOp
1252 = AlgResult SLIT("makeStablePtr#") [alphaTyVar]
1253 [alphaTy, realWorldStatePrimTy]
1254 stateAndStablePtrPrimTyCon [realWorldTy, alphaTy]
1256 primOpInfo DeRefStablePtrOp
1257 = AlgResult SLIT("deRefStablePtr#") [alphaTyVar]
1258 [mkStablePtrPrimTy alphaTy, realWorldStatePrimTy]
1259 stateAndPtrPrimTyCon [realWorldTy, alphaTy]
1262 %************************************************************************
1264 \subsubsection[PrimOp-unsafePointerEquality]{PrimOpInfo for Pointer Equality}
1266 %************************************************************************
1268 [Alastair Reid is to blame for this!]
1270 These days, (Glasgow) Haskell seems to have a bit of everything from
1271 other languages: strict operations, mutable variables, sequencing,
1272 pointers, etc. About the only thing left is LISP's ability to test
1273 for pointer equality. So, let's add it in!
1276 reallyUnsafePtrEquality :: a -> a -> Int#
1279 which tests any two closures (of the same type) to see if they're the
1280 same. (Returns $0$ for @False@, $\neq 0$ for @True@ - to avoid
1281 difficulties of trying to box up the result.)
1283 NB This is {\em really unsafe\/} because even something as trivial as
1284 a garbage collection might change the answer by removing indirections.
1285 Still, no-one's forcing you to use it. If you're worried about little
1286 things like loss of referential transparency, you might like to wrap
1287 it all up in a monad-like thing as John O'Donnell and John Hughes did
1288 for non-determinism (1989 (Fraserburgh) Glasgow FP Workshop
1291 I'm thinking of using it to speed up a critical equality test in some
1292 graphics stuff in a context where the possibility of saying that
1293 denotationally equal things aren't isn't a problem (as long as it
1294 doesn't happen too often.) ADR
1296 To Will: Jim said this was already in, but I can't see it so I'm
1297 adding it. Up to you whether you add it. (Note that this could have
1298 been readily implemented using a @veryDangerousCCall@ before they were
1302 primOpInfo ReallyUnsafePtrEqualityOp
1303 = PrimResult SLIT("reallyUnsafePtrEquality#") [alphaTyVar]
1304 [alphaTy, alphaTy] intPrimTyCon IntRep []
1307 %************************************************************************
1309 \subsubsection[PrimOp-parallel]{PrimOpInfo for parallelism op(s)}
1311 %************************************************************************
1314 primOpInfo SeqOp -- seq# :: a -> Int#
1315 = PrimResult SLIT("seq#") [alphaTyVar] [alphaTy] intPrimTyCon IntRep []
1317 primOpInfo ParOp -- par# :: a -> Int#
1318 = PrimResult SLIT("par#") [alphaTyVar] [alphaTy] intPrimTyCon IntRep []
1320 primOpInfo ForkOp -- fork# :: a -> Int#
1321 = PrimResult SLIT("fork#") [alphaTyVar] [alphaTy] intPrimTyCon IntRep []
1326 -- HWL: The first 4 Int# in all par... annotations denote:
1327 -- name, granularity info, size of result, degree of parallelism
1328 -- Same structure as _seq_ i.e. returns Int#
1330 primOpInfo ParGlobalOp -- parGlobal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1331 = PrimResult SLIT("parGlobal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTyCon IntRep [] -- liftTyCon [betaTy]
1333 primOpInfo ParLocalOp -- parLocal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
1334 = PrimResult SLIT("parLocal#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTyCon IntRep [] -- liftTyCon [betaTy]
1336 primOpInfo ParAtOp -- parAt# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1337 = PrimResult SLIT("parAt#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTyCon IntRep [] -- liftTyCon [gammaTy]
1339 primOpInfo ParAtAbsOp -- parAtAbs# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1340 = PrimResult SLIT("parAtAbs#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTyCon IntRep [] -- liftTyCon [betaTy]
1342 primOpInfo ParAtRelOp -- parAtRel# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
1343 = PrimResult SLIT("parAtRel#") [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTyCon IntRep [] -- liftTyCon [betaTy]
1345 primOpInfo ParAtForNowOp -- parAtForNow# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
1346 = PrimResult SLIT("parAtForNow#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTyCon IntRep [] -- liftTyCon [gammaTy]
1348 primOpInfo CopyableOp -- copyable# :: a -> a
1349 = PrimResult SLIT("copyable#") [alphaTyVar] [alphaTy] intPrimTyCon IntRep [] -- liftTyCon [alphaTy]
1351 primOpInfo NoFollowOp -- noFollow# :: a -> a
1352 = PrimResult SLIT("noFollow#") [alphaTyVar] [alphaTy] intPrimTyCon IntRep [] -- liftTyCon [alphaTy]
1355 %************************************************************************
1357 \subsubsection[PrimOp-errorIO]{PrimOpInfo for @errorIO#@}
1359 %************************************************************************
1362 primOpInfo ErrorIOPrimOp -- errorIO# :: PrimIO () -> State# RealWorld#
1363 = PrimResult SLIT("errorIO#") []
1364 [primio_ish_ty unitTy]
1365 statePrimTyCon VoidRep [realWorldTy]
1367 primio_ish_ty result
1368 = mkFunTy (mkStateTy realWorldTy) (mkTupleTy 2 [result, mkStateTy realWorldTy])
1371 %************************************************************************
1373 \subsubsection[PrimOp-IO-etc]{PrimOpInfo for C calls, and I/O-ish things}
1375 %************************************************************************
1378 primOpInfo (CCallOp _ _ _ arg_tys result_ty)
1379 = AlgResult SLIT("ccall#") [] arg_tys result_tycon tys_applied
1381 (result_tycon, tys_applied, _) = getAppDataTyConExpandingDicts result_ty
1384 primOpInfo op = panic ("primOpInfo:"++ show (I# (tagOf_PrimOp op)))
1388 %************************************************************************
1390 \subsection[PrimOp-utils]{Utilities for @PrimitiveOps@}
1392 %************************************************************************
1394 The primitive-array-creation @PrimOps@ and {\em most} of those to do
1395 with @Integers@ can trigger GC. Here we describe the heap requirements
1396 of the various @PrimOps@. For most, no heap is required. For a few,
1397 a fixed amount of heap is required, and the needs of the @PrimOp@ can
1398 be combined with the rest of the heap usage in the basic block. For an
1399 unfortunate few, some unknown amount of heap is required (these are the
1400 ops which can trigger GC).
1403 data HeapRequirement
1405 | FixedHeapRequired HeapOffset
1406 | VariableHeapRequired
1408 primOpHeapReq :: PrimOp -> HeapRequirement
1410 primOpHeapReq NewArrayOp = VariableHeapRequired
1411 primOpHeapReq (NewByteArrayOp _)= VariableHeapRequired
1413 primOpHeapReq IntegerAddOp = VariableHeapRequired
1414 primOpHeapReq IntegerSubOp = VariableHeapRequired
1415 primOpHeapReq IntegerMulOp = VariableHeapRequired
1416 primOpHeapReq IntegerQuotRemOp = VariableHeapRequired
1417 primOpHeapReq IntegerDivModOp = VariableHeapRequired
1418 primOpHeapReq IntegerNegOp = VariableHeapRequired
1419 primOpHeapReq Int2IntegerOp = FixedHeapRequired
1420 (addOff (totHdrSize (DataRep mIN_MP_INT_SIZE))
1421 (intOff mIN_MP_INT_SIZE))
1422 primOpHeapReq Word2IntegerOp = FixedHeapRequired
1423 (addOff (totHdrSize (DataRep mIN_MP_INT_SIZE))
1424 (intOff mIN_MP_INT_SIZE))
1425 primOpHeapReq Addr2IntegerOp = VariableHeapRequired
1426 primOpHeapReq FloatDecodeOp = FixedHeapRequired
1427 (addOff (intOff (getPrimRepSize IntRep + mP_STRUCT_SIZE))
1428 (addOff (totHdrSize (DataRep mIN_MP_INT_SIZE))
1429 (intOff mIN_MP_INT_SIZE)))
1430 primOpHeapReq DoubleDecodeOp = FixedHeapRequired
1431 (addOff (intOff (getPrimRepSize IntRep + mP_STRUCT_SIZE))
1432 (addOff (totHdrSize (DataRep mIN_MP_INT_SIZE))
1433 (intOff mIN_MP_INT_SIZE)))
1436 ccall may allocate heap if it is explicitly allowed to (_ccall_gc_)
1437 or if it returns a ForeignObj.
1439 Hmm..the allocation for makeForeignObj# is known (and fixed), so
1440 why dod we need to be so indeterminate about it? --SOF
1442 primOpHeapReq (CCallOp _ _ mayGC@True _ _) = VariableHeapRequired
1443 primOpHeapReq (CCallOp _ _ mayGC@False _ _) = NoHeapRequired
1445 primOpHeapReq MakeForeignObjOp = VariableHeapRequired
1446 primOpHeapReq WriteForeignObjOp = NoHeapRequired
1448 -- this occasionally has to expand the Stable Pointer table
1449 primOpHeapReq MakeStablePtrOp = VariableHeapRequired
1451 -- These four only need heap space with the native code generator
1452 -- ToDo!: parameterize, so we know if native code generation is taking place(JSM)
1454 primOpHeapReq IntegerCmpOp = FixedHeapRequired (intOff (2 * mP_STRUCT_SIZE))
1455 primOpHeapReq Integer2IntOp = FixedHeapRequired (intOff mP_STRUCT_SIZE)
1456 primOpHeapReq FloatEncodeOp = FixedHeapRequired (intOff mP_STRUCT_SIZE)
1457 primOpHeapReq DoubleEncodeOp = FixedHeapRequired (intOff mP_STRUCT_SIZE)
1459 -- a NewSynchVarOp creates a three-word mutuple in the heap.
1460 primOpHeapReq NewSynchVarOp = FixedHeapRequired
1461 (addOff (totHdrSize (MuTupleRep 3)) (intOff 3))
1463 -- Sparking ops no longer allocate any heap; however, _fork_ may
1464 -- require a context switch to clear space in the required thread
1465 -- pool, and that requires liveness information.
1467 primOpHeapReq ParOp = NoHeapRequired
1468 primOpHeapReq ForkOp = VariableHeapRequired
1470 -- A SeqOp requires unknown space to evaluate its argument
1471 primOpHeapReq SeqOp = VariableHeapRequired
1473 -- GranSim sparks are stgMalloced i.e. no heap required
1474 primOpHeapReq ParGlobalOp = NoHeapRequired
1475 primOpHeapReq ParLocalOp = NoHeapRequired
1476 primOpHeapReq ParAtOp = NoHeapRequired
1477 primOpHeapReq ParAtAbsOp = NoHeapRequired
1478 primOpHeapReq ParAtRelOp = NoHeapRequired
1479 primOpHeapReq ParAtForNowOp = NoHeapRequired
1480 -- CopyableOp and NoFolowOp don't require heap; don't rely on default
1481 primOpHeapReq CopyableOp = NoHeapRequired
1482 primOpHeapReq NoFollowOp = NoHeapRequired
1484 primOpHeapReq other_op = NoHeapRequired
1487 The amount of stack required by primops.
1490 data StackRequirement
1492 | FixedStackRequired Int {-AStack-} Int {-BStack-}
1493 | VariableStackRequired
1495 primOpStackRequired SeqOp = FixedStackRequired 0 {-AStack-} 2 {-BStack-}
1496 primOpStackRequired _ = VariableStackRequired
1497 -- ToDo: be more specific for certain primops (currently only used for seq)
1500 Primops which can trigger GC have to be called carefully.
1501 In particular, their arguments are guaranteed to be in registers,
1502 and a liveness mask tells which regs are live.
1505 primOpCanTriggerGC op
1513 case primOpHeapReq op of
1514 VariableHeapRequired -> True
1518 Sometimes we may choose to execute a PrimOp even though it isn't
1519 certain that its result will be required; ie execute them
1520 ``speculatively''. The same thing as ``cheap eagerness.'' Usually
1521 this is OK, because PrimOps are usually cheap, but it isn't OK for
1522 (a)~expensive PrimOps and (b)~PrimOps which can fail.
1524 See also @primOpIsCheap@ (below).
1526 There should be no worries about side effects; that's all taken care
1527 of by data dependencies.
1530 primOpOkForSpeculation :: PrimOp -> Bool
1533 primOpOkForSpeculation IntQuotOp = False -- Divide by zero
1534 primOpOkForSpeculation IntRemOp = False -- Divide by zero
1537 primOpOkForSpeculation IntegerQuotRemOp = False -- Divide by zero
1538 primOpOkForSpeculation IntegerDivModOp = False -- Divide by zero
1540 -- Float. ToDo: tan? tanh?
1541 primOpOkForSpeculation FloatDivOp = False -- Divide by zero
1542 primOpOkForSpeculation FloatLogOp = False -- Log of zero
1543 primOpOkForSpeculation FloatAsinOp = False -- Arg out of domain
1544 primOpOkForSpeculation FloatAcosOp = False -- Arg out of domain
1546 -- Double. ToDo: tan? tanh?
1547 primOpOkForSpeculation DoubleDivOp = False -- Divide by zero
1548 primOpOkForSpeculation DoubleLogOp = False -- Log of zero
1549 primOpOkForSpeculation DoubleAsinOp = False -- Arg out of domain
1550 primOpOkForSpeculation DoubleAcosOp = False -- Arg out of domain
1553 primOpOkForSpeculation (CCallOp _ _ _ _ _)= False -- Could be expensive!
1556 primOpOkForSpeculation ErrorIOPrimOp = False -- Could be disastrous!
1559 primOpOkForSpeculation ParOp = False -- Could be expensive!
1560 primOpOkForSpeculation ForkOp = False -- Likewise
1561 primOpOkForSpeculation SeqOp = False -- Likewise
1563 primOpOkForSpeculation ParGlobalOp = False -- Could be expensive!
1564 primOpOkForSpeculation ParLocalOp = False -- Could be expensive!
1565 primOpOkForSpeculation ParAtOp = False -- Could be expensive!
1566 primOpOkForSpeculation ParAtAbsOp = False -- Could be expensive!
1567 primOpOkForSpeculation ParAtRelOp = False -- Could be expensive!
1568 primOpOkForSpeculation ParAtForNowOp = False -- Could be expensive!
1569 primOpOkForSpeculation CopyableOp = False -- only tags closure
1570 primOpOkForSpeculation NoFollowOp = False -- only tags closure
1572 -- The default is "yes it's ok for speculation"
1573 primOpOkForSpeculation other_op = True
1576 @primOpIsCheap@, as used in \tr{SimplUtils.lhs}. For now (HACK
1577 WARNING), we just borrow some other predicates for a
1578 what-should-be-good-enough test.
1581 = primOpOkForSpeculation op && not (primOpCanTriggerGC op)
1584 And some primops have side-effects and so, for example, must not be
1588 fragilePrimOp :: PrimOp -> Bool
1590 fragilePrimOp ParOp = True
1591 fragilePrimOp ForkOp = True
1592 fragilePrimOp SeqOp = True
1593 fragilePrimOp MakeForeignObjOp = True -- SOF
1594 fragilePrimOp WriteForeignObjOp = True -- SOF
1595 fragilePrimOp MakeStablePtrOp = True
1596 fragilePrimOp DeRefStablePtrOp = True -- ??? JSM & ADR
1598 fragilePrimOp ParGlobalOp = True
1599 fragilePrimOp ParLocalOp = True
1600 fragilePrimOp ParAtOp = True
1601 fragilePrimOp ParAtAbsOp = True
1602 fragilePrimOp ParAtRelOp = True
1603 fragilePrimOp ParAtForNowOp = True
1604 fragilePrimOp CopyableOp = True -- Possibly not. ASP
1605 fragilePrimOp NoFollowOp = True -- Possibly not. ASP
1607 fragilePrimOp other = False
1610 Primitive operations that perform calls need wrappers to save any live variables
1611 that are stored in caller-saves registers
1614 primOpNeedsWrapper :: PrimOp -> Bool
1616 primOpNeedsWrapper (CCallOp _ _ _ _ _) = True
1618 primOpNeedsWrapper NewArrayOp = True -- ToDo: for nativeGen only!(JSM)
1619 primOpNeedsWrapper (NewByteArrayOp _) = True
1621 primOpNeedsWrapper IntegerAddOp = True
1622 primOpNeedsWrapper IntegerSubOp = True
1623 primOpNeedsWrapper IntegerMulOp = True
1624 primOpNeedsWrapper IntegerQuotRemOp = True
1625 primOpNeedsWrapper IntegerDivModOp = True
1626 primOpNeedsWrapper IntegerNegOp = True
1627 primOpNeedsWrapper IntegerCmpOp = True
1628 primOpNeedsWrapper Integer2IntOp = True
1629 primOpNeedsWrapper Int2IntegerOp = True
1630 primOpNeedsWrapper Word2IntegerOp = True
1631 primOpNeedsWrapper Addr2IntegerOp = True
1633 primOpNeedsWrapper FloatExpOp = True
1634 primOpNeedsWrapper FloatLogOp = True
1635 primOpNeedsWrapper FloatSqrtOp = True
1636 primOpNeedsWrapper FloatSinOp = True
1637 primOpNeedsWrapper FloatCosOp = True
1638 primOpNeedsWrapper FloatTanOp = True
1639 primOpNeedsWrapper FloatAsinOp = True
1640 primOpNeedsWrapper FloatAcosOp = True
1641 primOpNeedsWrapper FloatAtanOp = True
1642 primOpNeedsWrapper FloatSinhOp = True
1643 primOpNeedsWrapper FloatCoshOp = True
1644 primOpNeedsWrapper FloatTanhOp = True
1645 primOpNeedsWrapper FloatPowerOp = True
1646 primOpNeedsWrapper FloatEncodeOp = True
1647 primOpNeedsWrapper FloatDecodeOp = True
1649 primOpNeedsWrapper DoubleExpOp = True
1650 primOpNeedsWrapper DoubleLogOp = True
1651 primOpNeedsWrapper DoubleSqrtOp = True
1652 primOpNeedsWrapper DoubleSinOp = True
1653 primOpNeedsWrapper DoubleCosOp = True
1654 primOpNeedsWrapper DoubleTanOp = True
1655 primOpNeedsWrapper DoubleAsinOp = True
1656 primOpNeedsWrapper DoubleAcosOp = True
1657 primOpNeedsWrapper DoubleAtanOp = True
1658 primOpNeedsWrapper DoubleSinhOp = True
1659 primOpNeedsWrapper DoubleCoshOp = True
1660 primOpNeedsWrapper DoubleTanhOp = True
1661 primOpNeedsWrapper DoublePowerOp = True
1662 primOpNeedsWrapper DoubleEncodeOp = True
1663 primOpNeedsWrapper DoubleDecodeOp = True
1665 primOpNeedsWrapper MakeForeignObjOp = True
1666 primOpNeedsWrapper WriteForeignObjOp = True
1667 primOpNeedsWrapper MakeStablePtrOp = True
1668 primOpNeedsWrapper DeRefStablePtrOp = True
1670 primOpNeedsWrapper TakeMVarOp = True
1671 primOpNeedsWrapper PutMVarOp = True
1672 primOpNeedsWrapper ReadIVarOp = True
1674 primOpNeedsWrapper DelayOp = True
1675 primOpNeedsWrapper WaitReadOp = True
1676 primOpNeedsWrapper WaitWriteOp = True
1678 primOpNeedsWrapper other_op = False
1683 = case (primOpInfo op) of
1685 Monadic str _ -> str
1686 Compare str _ -> str
1687 Coercing str _ _ -> str
1688 PrimResult str _ _ _ _ _ -> str
1689 AlgResult str _ _ _ _ -> str
1692 @primOpType@ duplicates some work of @primOpId@, but since we
1693 grab types pretty often...
1695 primOpType :: PrimOp -> Type
1698 = case (primOpInfo op) of
1699 Dyadic str ty -> dyadic_fun_ty ty
1700 Monadic str ty -> monadic_fun_ty ty
1701 Compare str ty -> compare_fun_ty ty
1702 Coercing str ty1 ty2 -> mkFunTy ty1 ty2
1704 PrimResult str tyvars arg_tys prim_tycon kind res_tys ->
1705 mkForAllTys tyvars (mkFunTys arg_tys (applyTyCon prim_tycon res_tys))
1707 AlgResult str tyvars arg_tys tycon res_tys ->
1708 mkForAllTys tyvars (mkFunTys arg_tys (applyTyCon tycon res_tys))
1712 data PrimOpResultInfo
1713 = ReturnsPrim PrimRep
1716 -- ToDo: Deal with specialised PrimOps
1717 -- Will need to return specialised tycon and data constructors
1719 getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo
1721 getPrimOpResultInfo op
1722 = case (primOpInfo op) of
1723 Dyadic _ ty -> ReturnsPrim (typePrimRep ty)
1724 Monadic _ ty -> ReturnsPrim (typePrimRep ty)
1725 Compare _ ty -> ReturnsAlg boolTyCon
1726 Coercing _ _ ty -> ReturnsPrim (typePrimRep ty)
1727 PrimResult _ _ _ _ kind _ -> ReturnsPrim kind
1728 AlgResult _ _ _ tycon _ -> ReturnsAlg tycon
1730 isCompareOp :: PrimOp -> Bool
1733 = case primOpInfo op of
1738 The commutable ops are those for which we will try to move constants
1739 to the right hand side for strength reduction.
1742 commutableOp :: PrimOp -> Bool
1744 commutableOp CharEqOp = True
1745 commutableOp CharNeOp = True
1746 commutableOp IntAddOp = True
1747 commutableOp IntMulOp = True
1748 commutableOp AndOp = True
1749 commutableOp OrOp = True
1750 commutableOp IntEqOp = True
1751 commutableOp IntNeOp = True
1752 commutableOp IntegerAddOp = True
1753 commutableOp IntegerMulOp = True
1754 commutableOp FloatAddOp = True
1755 commutableOp FloatMulOp = True
1756 commutableOp FloatEqOp = True
1757 commutableOp FloatNeOp = True
1758 commutableOp DoubleAddOp = True
1759 commutableOp DoubleMulOp = True
1760 commutableOp DoubleEqOp = True
1761 commutableOp DoubleNeOp = True
1762 commutableOp _ = False
1767 dyadic_fun_ty ty = mkFunTys [ty, ty] ty
1768 monadic_fun_ty ty = mkFunTy ty ty
1769 compare_fun_ty ty = mkFunTys [ty, ty] boolTy
1774 pprPrimOp :: PprStyle -> PrimOp -> Doc
1775 showPrimOp :: PprStyle -> PrimOp -> String
1777 showPrimOp sty op = render (pprPrimOp sty op)
1779 pprPrimOp sty (CCallOp fun is_casm may_gc arg_tys res_ty)
1783 if may_gc then "_casm_GC_ ``" else "_casm_ ``"
1785 if may_gc then "_ccall_GC_ " else "_ccall_ "
1788 = if is_casm then text "''" else empty
1791 = hsep (map (pprParendGenType sty) (res_ty:arg_tys))
1793 hcat [text before, ptext fun, after, space, brackets pp_tys]
1795 pprPrimOp sty other_op
1796 | codeStyle sty -- For C just print the primop itself
1799 | ifaceStyle sty -- For interfaces Print it qualified with GHC.
1800 = ptext SLIT("GHC.") <> ptext str
1802 | otherwise -- Unqualified is good enough
1805 str = primOp_str other_op
1809 instance Outputable PrimOp where
1810 ppr sty op = pprPrimOp sty op