[project @ 2003-06-19 10:42:24 by simonmar]
[ghc-hetmet.git] / ghc / compiler / prelude / primops.txt.pp
index 40b737c..37c6c6f 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------
--- $Id: primops.txt.pp,v 1.14 2001/12/14 15:26:16 sewardj Exp $
+-- $Id: primops.txt.pp,v 1.27 2003/06/19 10:42:26 simonmar Exp $
 --
 -- Primitive Operations
 --
 --       strictness attributes, whether it is defined as a macro
 --       or as out-of-line code, etc.)
 --
---     - ghc/lib/std/PrelGHC.hi-boot, to declare the primop
---
 --     - if the primop is inline (i.e. a macro), then:
---             ghc/includes/PrimOps.h
---             ghc/compiler/nativeGen/StixPrim.lhs 
---              ghc/compiler/nativeGen/MachCode.lhs (if implementation is machine-dependent)
+--             ghc/compiler/AbsCUtils.lhs (dscCOpStmt)
+--               defines the translation of the primop into simpler
+--               abstract C operations.
 --             
 --     - or, for an out-of-line primop:
 --             ghc/includes/PrimOps.h (just add the declaration)
 --             ghc/rts/PrimOps.hc     (define it here)
+--             ghc/rts/Linker.c       (declare the symbol for GHCi)
 --
 --     - the User's Guide 
 --
@@ -184,14 +183,15 @@ primop   IntMulOp    "*#"
    with commutable = True
 
 primop   IntMulMayOfloOp  "mulIntMayOflo#" 
-   GenPrimOp   Int# -> Int# -> Bool
-   {Return True if there is any possibility that the upper word of a
+   Dyadic   Int# -> Int# -> Int#
+   {Return non-zero if there is any possibility that the upper word of a
     signed integer multiply might contain useful information.  Return
-    False only if you are completely sure that no overflow can occur.
+    zero only if you are completely sure that no overflow can occur.
     On a 32-bit platform, the recommmended implementation is to do a 
-    32 x 32 -> 64 signed multiply, and compare result[63:32] with 
-    (result[31] >>signed 31).  If they are identical, meaning that the 
-    upper word is merely a sign extension of the lower one, return 0, else 1.
+    32 x 32 -> 64 signed multiply, and subtract result[63:32] from
+    (result[31] >>signed 31).  If this is zero, meaning that the 
+    upper word is merely a sign extension of the lower one, no
+    overflow can occur.
 
     On a 64-bit platform it is not always possible to 
     acquire the top 64 bits of the result.  Therefore, a recommended 
@@ -1274,6 +1274,18 @@ primop  SameMutVarOp "sameMutVar#" GenPrimOp
    with
    usage = { mangle SameMutVarOp [mkP, mkP] mkM }
 
+-- not really the right type, but we don't know about pairs here.  The
+-- correct type is
+--
+--   MutVar# s a -> (a -> (a,b)) -> State# s -> (# State# s, b #)
+--
+primop  AtomicModifyMutVarOp "atomicModifyMutVar#" GenPrimOp
+   MutVar# s a -> (a -> b) -> State# s -> (# State# s, c #)
+   with
+   usage = { mangle AtomicModifyMutVarOp [mkP, mkM, mkP] mkM }
+   has_side_effects = True
+   out_of_line = True
+
 ------------------------------------------------------------------------
 section "Exceptions"
 ------------------------------------------------------------------------
@@ -1300,6 +1312,15 @@ primop  RaiseOp "raise#" GenPrimOp
    usage       = { mangle RaiseOp [mkM] mkM }
    out_of_line = True
 
+-- raiseIO# needs to be a primop, because exceptions in the IO monad
+-- must be *precise* - we don't want the strictness analyser turning
+-- one kind of bottom into another, as it is allowed to do in pure code.
+
+primop  RaiseIOOp "raiseIO#" GenPrimOp
+   a -> State# RealWorld -> (# State# RealWorld, b #)
+   with
+   out_of_line = True
+
 primop  BlockAsyncExceptionsOp "blockAsyncExceptions#" GenPrimOp
         (State# RealWorld -> (# State# RealWorld, a #))
      -> (State# RealWorld -> (# State# RealWorld, a #))
@@ -1403,6 +1424,24 @@ primop  WaitWriteOp "waitWrite#" GenPrimOp
    has_side_effects = True
    out_of_line      = True
 
+#ifdef mingw32_TARGET_OS
+primop  AsyncReadOp "asyncRead#" GenPrimOp
+   Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
+   {Asynchronously read bytes from specified file descriptor.}
+   with
+   needs_wrapper    = True
+   has_side_effects = True
+   out_of_line      = True
+
+primop  AsyncWriteOp "asyncWrite#" GenPrimOp
+   Int# -> Int# -> Int# -> Addr# -> State# RealWorld-> (# State# RealWorld, Int#, Int# #)
+   {Asynchronously write bytes from specified file descriptor.}
+   with
+   needs_wrapper    = True
+   has_side_effects = True
+   out_of_line      = True
+#endif
+
 ------------------------------------------------------------------------
 section "Concurrency primitives"
        {(In a non-concurrent implementation, ThreadId\# can be as singleton
@@ -1417,6 +1456,12 @@ primop  ForkOp "fork#" GenPrimOp
    has_side_effects = True
    out_of_line      = True
 
+primop ForkProcessOp "forkProcess#" GenPrimOp
+   State# RealWorld -> (# State# RealWorld, Int#  #)
+   with
+   has_side_effects = True
+   out_of_line      = True
+
 primop  KillThreadOp "killThread#"  GenPrimOp
    ThreadId# -> a -> State# RealWorld -> State# RealWorld
    with
@@ -1435,6 +1480,12 @@ primop  MyThreadIdOp "myThreadId#" GenPrimOp
    with
    out_of_line = True
 
+primop LabelThreadOp "labelThread#" GenPrimOp
+   ThreadId# -> Addr# -> State# RealWorld -> State# RealWorld
+   with
+   has_side_effects = True
+   out_of_line      = True
+
 ------------------------------------------------------------------------
 section "Weak pointers"
 ------------------------------------------------------------------------
@@ -1457,7 +1508,7 @@ primop  DeRefWeakOp "deRefWeak#" GenPrimOp
 
 primop  FinalizeWeakOp "finalizeWeak#" GenPrimOp
    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, 
-              (State# RealWorld -> (# State# RealWorld, Unit #)) #)
+              (State# RealWorld -> (# State# RealWorld, () #)) #)
    with
    usage            = { mangle FinalizeWeakOp [mkM, mkP] 
                                (mkR . (inUB FinalizeWeakOp 
@@ -1509,16 +1560,18 @@ primop  StableNameToIntOp "stableNameToInt#" GenPrimOp
    usage = { mangle StableNameToIntOp [mkP] mkR }
 
 ------------------------------------------------------------------------
-section "Parallelism"
+section "Unsafe pointer equality"
+--  (#1 Bad Guy: Alistair Reid :)   
 ------------------------------------------------------------------------
 
-primop  SeqOp "seq#" GenPrimOp
-   a -> Int#
+primop  ReallyUnsafePtrEqualityOp "reallyUnsafePtrEquality#" GenPrimOp
+   a -> a -> Int#
    with
-   usage            = { mangle  SeqOp [mkO] mkR }
-   strictness       = { \ arity -> mkStrictSig (mkTopDmdType [evalDmd] TopRes) }
-      -- Seq is strict in its argument; see notes in ConFold.lhs
-   has_side_effects = True
+   usage = { mangle ReallyUnsafePtrEqualityOp [mkZ, mkZ] mkR }
+
+------------------------------------------------------------------------
+section "Parallelism"
+------------------------------------------------------------------------
 
 primop  ParOp "par#" GenPrimOp
    a -> Int#
@@ -1608,19 +1661,19 @@ primop   AddrToHValueOp "addrToHValue#" GenPrimOp
    {Convert an Addr\# to a followable type.}
 
 primop   MkApUpd0_Op "mkApUpd0#" GenPrimOp
-   a -> (# a #)
+   BCO# -> (# a #)
    with
    out_of_line = True
 
 primop  NewBCOOp "newBCO#" GenPrimOp
-   ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> State# s -> (# State# s, BCO# #)
+   ByteArr# -> ByteArr# -> Array# a -> ByteArr# -> Int# -> ByteArr# -> State# s -> (# State# s, BCO# #)
    with
    has_side_effects = True
    out_of_line      = True
 
 ------------------------------------------------------------------------
 section "Coercion" 
-       {{\tt unsafeCoerce# :: a -> b} is not a primop, but is defined in MkId.lhs.}
+       {{\tt unsafeCoerce\# :: a -> b} is not a primop, but is defined in MkId.lhs.}
 
 ------------------------------------------------------------------------