[project @ 2002-06-26 08:18:38 by stolz]
[ghc-hetmet.git] / ghc / compiler / prelude / primops.txt.pp
index 8228ebb..ade88b4 100644 (file)
@@ -1,5 +1,5 @@
 -----------------------------------------------------------------------
--- $Id: primops.txt.pp,v 1.12 2001/12/10 14:07:30 simonmar Exp $
+-- $Id: primops.txt.pp,v 1.21 2002/06/26 08:18:38 stolz 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 
 --
@@ -180,6 +179,31 @@ primop   IntSubOp    "-#"    Dyadic   Int# -> Int# -> Int#
 
 primop   IntMulOp    "*#" 
    Dyadic   Int# -> Int# -> Int#
+   {Low word of signed integer multiply.}
+   with commutable = True
+
+primop   IntMulMayOfloOp  "mulIntMayOflo#" 
+   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
+    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 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 
+    implementation is to take the absolute value of both operands, and 
+    return 0 iff bits[63:31] of them are zero, since that means that their 
+    magnitudes fit within 31 bits, so the magnitude of the product must fit 
+    into 62 bits.
+
+    If in doubt, return non-zero, but do make an effort to create the
+    correct answer for small args, since otherwise the performance of
+    (*) :: Integer -> Integer -> Integer will be poor.
+   }
    with commutable = True
 
 primop   IntQuotOp    "quotInt#"    Dyadic
@@ -197,11 +221,12 @@ primop   IntGcdOp    "gcdInt#"    Dyadic   Int# -> Int# -> Int#
 
 primop   IntNegOp    "negateInt#"    Monadic   Int# -> Int#
 primop   IntAddCOp   "addIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
-        {Add with carry.  First member of result is (wrapped) sum; second member is 0 iff no overflow occured.}
+        {Add with carry.  First member of result is (wrapped) sum; 
+          second member is 0 iff no overflow occured.}
 primop   IntSubCOp   "subIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
-        {Subtract with carry.  First member of result is (wrapped) difference; second member is 0 iff no overflow occured.}
-primop   IntMulCOp   "mulIntC#"    GenPrimOp   Int# -> Int# -> (# Int#, Int# #)
-        {Multiply with carry.  First member of result is (wrapped) product; second member is 0 iff no overflow occured.}
+        {Subtract with carry.  First member of result is (wrapped) difference; 
+          second member is 0 iff no overflow occured.}
+
 primop   IntGtOp  ">#"   Compare   Int# -> Int# -> Bool
 primop   IntGeOp  ">=#"   Compare   Int# -> Int# -> Bool
 
@@ -227,14 +252,14 @@ primop   Int2IntegerOp    "int2Integer#"
    with out_of_line = True
 
 primop   ISllOp   "uncheckedIShiftL#" GenPrimOp  Int# -> Int# -> Int#
-        {Shift left.  Result undefined if shift amount equals 
-          or exceeds word size.} 
+        {Shift left.  Result undefined if shift amount is not
+          in the range 0 to word size - 1 inclusive.}
 primop   ISraOp   "uncheckedIShiftRA#" GenPrimOp Int# -> Int# -> Int#
-        {Shift right arithmetic.  Result undefined if shift amount equals 
-          or exceeds word size.} 
+        {Shift right arithmetic.  Result undefined if shift amount is not
+          in the range 0 to word size - 1 inclusive.}
 primop   ISrlOp   "uncheckedIShiftRL#" GenPrimOp Int# -> Int# -> Int#
-        {Shift right logical.  Result undefined if shift amount equals 
-          or exceeds word size.} 
+        {Shift right logical.  Result undefined if shift amount is not
+          in the range 0 to word size - 1 inclusive.}
 
 ------------------------------------------------------------------------
 section "Word#"
@@ -267,11 +292,11 @@ primop   XorOp   "xor#"   Dyadic   Word# -> Word# -> Word#
 primop   NotOp   "not#"   Monadic   Word# -> Word#
 
 primop   SllOp   "uncheckedShiftL#"   GenPrimOp   Word# -> Int# -> Word#
-        {Shift left logical.   Result undefined if shift amount equals 
-          or exceeds word size.}
+        {Shift left logical.   Result undefined if shift amount is not
+          in the range 0 to word size - 1 inclusive.}
 primop   SrlOp   "uncheckedShiftRL#"   GenPrimOp   Word# -> Int# -> Word#
-        {Shift right logical.   Result undefined if shift amount equals 
-          or exceeds word size.}
+        {Shift right logical.   Result undefined if shift  amount is not
+          in the range 0 to word size - 1 inclusive.}
 
 primop   Word2IntOp   "word2Int#"   GenPrimOp   Word# -> Int#
 
@@ -1392,6 +1417,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
@@ -1410,6 +1441,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"
 ------------------------------------------------------------------------
@@ -1484,16 +1521,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#
@@ -1595,7 +1634,7 @@ primop  NewBCOOp "newBCO#" GenPrimOp
 
 ------------------------------------------------------------------------
 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.}
 
 ------------------------------------------------------------------------