[project @ 2001-08-08 10:50:36 by simonmar]
[ghc-hetmet.git] / ghc / includes / PrimOps.h
index e6d1d40..a33db9c 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: PrimOps.h,v 1.75 2001/02/28 00:01:03 qrczak Exp $
+ * $Id: PrimOps.h,v 1.80 2001/08/08 10:50:37 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -99,8 +99,8 @@
  * plugging into a new J#.  
  */
 #define addIntCzh(r,c,a,b)                     \
-{ r = a + b;                                   \
-  c = ((StgWord)(~(a^b) & (a^r)))              \
+{ r = (I_)a + (I_)b;                           \
+  c = ((StgWord)(~((I_)a^(I_)b) & ((I_)a^r)))  \
     >> (BITS_IN (I_) - 1);                     \
 }
 
@@ -171,13 +171,13 @@ typedef union {
 
 #else
 
-#define HALF_INT  (1 << (BITS_IN (I_) / 2))
+#define HALF_INT  (1LL << (BITS_IN (I_) / 2))
 
 #define stg_abs(a) ((a) < 0 ? -(a) : (a))
 
 #define mulIntCzh(r,c,a,b)                     \
 {                                              \
-  if (stg_abs(a) >= HALF_INT                   \
+  if (stg_abs(a) >= HALF_INT ||                        \
       stg_abs(b) >= HALF_INT) {                        \
     c = 1;                                     \
   } else {                                     \
@@ -664,8 +664,13 @@ EXTFUN_RTS(unsafeThawArrayzh_fast);
 /* and the out-of-line ones... */
 
 EXTFUN_RTS(newByteArrayzh_fast);
+EXTFUN_RTS(newPinnedByteArrayzh_fast);
 EXTFUN_RTS(newArrayzh_fast);
 
+// Highly unsafe, for use with a pinned ByteArray 
+// being kept alive with touch# 
+#define byteArrayContentszh(r,a) r = BYTE_ARR_CTS(a)
+
 /* encoding and decoding of floats/doubles. */
 
 /* We only support IEEE floating point format */
@@ -742,8 +747,6 @@ extern void stg_exit(I_ n)  __attribute__ ((noreturn));
    Stable Name / Stable Pointer  PrimOps
    -------------------------------------------------------------------------- */
 
-#ifndef PAR
-
 EXTFUN_RTS(makeStableNamezh_fast);
 
 #define stableNameToIntzh(r,s)   (r = ((StgStableName *)s)->sn)
@@ -762,8 +765,6 @@ EXTFUN_RTS(makeStableNamezh_fast);
 #define eqStablePtrzh(r,sp1,sp2) \
     (r = ((stgCast(StgWord,sp1) & ~STABLEPTR_WEIGHT_MASK) == (stgCast(StgWord,sp2) & ~STABLEPTR_WEIGHT_MASK)))
 
-#endif
-
 /* -----------------------------------------------------------------------------
    Concurrency/Exception PrimOps.
    -------------------------------------------------------------------------- */
@@ -793,7 +794,7 @@ extern int cmp_thread(const StgTSO *tso1, const StgTSO *tso2);
 
 #if defined(GRAN)
 //@cindex _par_
-#define parzh(r,node)             PAR(r,node,1,0,0,0,0,0)
+#define parzh(r,node)             parAny(r,node,1,0,0,0,0,0)
 
 //@cindex _parAt_
 #define parAtzh(r,node,where,identifier,gran_info,size_info,par_info,rest) \
@@ -833,13 +834,13 @@ extern int cmp_thread(const StgTSO *tso1, const StgTSO *tso2);
 
 //@cindex _parLocal_
 #define parLocalzh(r,node,identifier,gran_info,size_info,par_info,rest)        \
-       PAR(r,node,rest,identifier,gran_info,size_info,par_info,1)
+       parAny(r,node,rest,identifier,gran_info,size_info,par_info,1)
 
 //@cindex _parGlobal_
 #define parGlobalzh(r,node,identifier,gran_info,size_info,par_info,rest) \
-       PAR(r,node,rest,identifier,gran_info,size_info,par_info,0)
+       parAny(r,node,rest,identifier,gran_info,size_info,par_info,0)
 
-#define PAR(r,node,rest,identifier,gran_info,size_info,par_info,local) \
+#define parAny(r,node,rest,identifier,gran_info,size_info,par_info,local) \
 {                                                                        \
   if (closure_SHOULD_SPARK((StgClosure*)node)) {                         \
     rtsSpark *result;                                                   \
@@ -887,8 +888,6 @@ extern int cmp_thread(const StgTSO *tso1, const StgTSO *tso2);
    Weak Pointer PrimOps.
    -------------------------------------------------------------------------- */
 
-#ifndef PAR
-
 EXTFUN_RTS(mkWeakzh_fast);
 EXTFUN_RTS(finalizzeWeakzh_fast);
 
@@ -903,14 +902,11 @@ EXTFUN_RTS(finalizzeWeakzh_fast);
 
 #define sameWeakzh(w1,w2)  ((w1)==(w2))
 
-#endif
 
 /* -----------------------------------------------------------------------------
    Foreign Object PrimOps.
    -------------------------------------------------------------------------- */
 
-#ifndef PAR
-
 #define ForeignObj_CLOSURE_DATA(c)  (((StgForeignObj *)c)->data)
 
 #define foreignObjToAddrzh(r,fo)    r=ForeignObj_CLOSURE_DATA(fo)
@@ -921,8 +917,7 @@ EXTFUN_RTS(mkForeignObjzh_fast);
 #define writeForeignObjzh(res,datum) \
    (ForeignObj_CLOSURE_DATA(res) = (P_)(datum))
 
-#define eqForeignObj(f1,f2)  ((f1)==(f2))
-
+#define eqForeignObjzh(r,f1,f2)                 r=(f1)==(f2)
 #define indexCharOffForeignObjzh(r,fo,i)       indexCharOffAddrzh(r,ForeignObj_CLOSURE_DATA(fo),i)
 #define indexWideCharOffForeignObjzh(r,fo,i)   indexWideCharOffAddrzh(r,ForeignObj_CLOSURE_DATA(fo),i)
 #define indexIntOffForeignObjzh(r,fo,i)                indexIntOffAddrzh(r,ForeignObj_CLOSURE_DATA(fo),i)
@@ -942,9 +937,6 @@ EXTFUN_RTS(mkForeignObjzh_fast);
 #define indexWord64OffForeignObjzh(r,fo,i)     indexWord64OffAddrzh(r,ForeignObj_CLOSURE_DATA(fo),i)
 #endif
 
-#endif
-
-
 /* -----------------------------------------------------------------------------
    Constructor tags
    -------------------------------------------------------------------------- */