summaryrefslogtreecommitdiff
path: root/ghc/lib/std
diff options
context:
space:
mode:
authorsewardj <unknown>2001-12-05 17:35:15 +0000
committersewardj <unknown>2001-12-05 17:35:15 +0000
commitd11e681f219f6e38c2e5bc87adfb66f82de5ea65 (patch)
treec85c4bf1beac4d7150c6a95c42839273b688f315 /ghc/lib/std
parentc967a54e648292f79d9480a95ff1e9e87323530c (diff)
downloadhaskell-d11e681f219f6e38c2e5bc87adfb66f82de5ea65.tar.gz
[project @ 2001-12-05 17:35:12 by sewardj]
-------------------------------------------- Translate out PrimOps at the AbstractC level -------------------------------------------- This is the first in what might be a series of changes intended to make GHC less dependent on its C back end. The main change is to translate PrimOps into vanilla abstract C inside the compiler, rather than having to duplicate that work in each code generation route. The main changes are: * A new type, MachOp, in compiler/absCSyn/MachOp.hs. A MachOp is a primitive operation which we can reasonably expect the native code generators to implement. The set is quite small and unlikely to change much, if at all. * Translations from PrimOps to MachOps, at the end of absCSyn/AbsCUtils. This should perhaps be moved to a different module, but it is hard to see how to do this without creating a circular dep between it and AbsCUtils. * The x86 insn selector has been updated to track these changes. The sparc insn selector remains to be done. As a result of this, it is possible to compile much more code via the NCG than before. Almost all the Prelude can be compiled with it. Currently it does not know how to do 64-bit code generation. Once this is fixed, the entire Prelude should be compilable that way. I also took the opportunity to clean up the NCG infrastructure. The old Stix data type has been split into StixStmt (statements) and StixExpr (now denoting values only). This removes a class of impossible constructions and clarifies the NCG. Still to do, in no particular order: * String and literal lifting, currently done in the NCG at the top of nativeGen/MachCode, should be done in the AbstractC flattener, for the benefit of all targets. * Further cleaning up of Stix assignments. * Remove word-size dependency from Abstract C. (should be easy). * Translate out MagicIds in the AbsC -> Stix translation, not in the Stix constant folder. (!) Testsuite failures caused by this: * memo001 - fails (segfaults) for some unknown reason now. * arith003 - wrong answer in gcdInt boundary cases. * arith011 - wrong answer for shifts >= word size. * cg044 - wrong answer for some FP boundary cases. These should be fixed, but I don't think they are mission-critical for anyone.
Diffstat (limited to 'ghc/lib/std')
-rw-r--r--ghc/lib/std/PrelGHC.hi-boot.pp4
-rw-r--r--ghc/lib/std/PrelInt.lhs2
-rw-r--r--ghc/lib/std/PrelWord.lhs3
-rw-r--r--ghc/lib/std/cbits/longlong.c42
4 files changed, 44 insertions, 7 deletions
diff --git a/ghc/lib/std/PrelGHC.hi-boot.pp b/ghc/lib/std/PrelGHC.hi-boot.pp
index d478480cea..d9ae78120b 100644
--- a/ghc/lib/std/PrelGHC.hi-boot.pp
+++ b/ghc/lib/std/PrelGHC.hi-boot.pp
@@ -238,8 +238,6 @@ __export PrelGHC
word32ToIntegerzh
#endif
#if WORD_SIZE_IN_BITS < 64
- integerToInt64zh
- integerToWord64zh
int64ToIntegerzh
word64ToIntegerzh
#endif
@@ -422,8 +420,6 @@ __export PrelGHC
eqStableNamezh
stableNameToIntzh
- reallyUnsafePtrEqualityzh
-
newBCOzh
BCOzh
mkApUpd0zh
diff --git a/ghc/lib/std/PrelInt.lhs b/ghc/lib/std/PrelInt.lhs
index e28271685b..13f7c4a391 100644
--- a/ghc/lib/std/PrelInt.lhs
+++ b/ghc/lib/std/PrelInt.lhs
@@ -648,6 +648,8 @@ foreign import "stg_iShiftRA64" unsafe iShiftRA64# :: Int64# -> Int# -> In
foreign import "stg_shiftL64" unsafe shiftL64# :: Word64# -> Int# -> Word64#
foreign import "stg_shiftRL64" unsafe shiftRL64# :: Word64# -> Int# -> Word64#
+foreign import "stg_integerToInt64" unsafe integerToInt64# :: Int# -> ByteArray# -> Int64#
+
{-# RULES
"fromIntegral/Int->Int64" fromIntegral = \(I# x#) -> I64# (intToInt64# x#)
"fromIntegral/Word->Int64" fromIntegral = \(W# x#) -> I64# (word64ToInt64# (wordToWord64# x#))
diff --git a/ghc/lib/std/PrelWord.lhs b/ghc/lib/std/PrelWord.lhs
index fb12ea1186..30af9fcd20 100644
--- a/ghc/lib/std/PrelWord.lhs
+++ b/ghc/lib/std/PrelWord.lhs
@@ -746,6 +746,9 @@ foreign import "stg_not64" unsafe not64# :: Word64# -> Word64#
foreign import "stg_shiftL64" unsafe shiftL64# :: Word64# -> Int# -> Word64#
foreign import "stg_shiftRL64" unsafe shiftRL64# :: Word64# -> Int# -> Word64#
+foreign import "stg_integerToWord64" unsafe integerToWord64# :: Int# -> ByteArray# -> Word64#
+
+
{-# RULES
"fromIntegral/Int->Word64" fromIntegral = \(I# x#) -> W64# (int64ToWord64# (intToInt64# x#))
"fromIntegral/Word->Word64" fromIntegral = \(W# x#) -> W64# (wordToWord64# x#)
diff --git a/ghc/lib/std/cbits/longlong.c b/ghc/lib/std/cbits/longlong.c
index 5a7bd55108..fdc7603bde 100644
--- a/ghc/lib/std/cbits/longlong.c
+++ b/ghc/lib/std/cbits/longlong.c
@@ -1,5 +1,5 @@
/* -----------------------------------------------------------------------------
- * $Id: longlong.c,v 1.3 2001/07/23 15:11:55 simonmar Exp $
+ * $Id: longlong.c,v 1.4 2001/12/05 17:35:15 sewardj Exp $
*
* (c) The GHC Team, 1998-1999
*
@@ -74,8 +74,8 @@ StgInt64 stg_iShiftRA64 (StgInt64 a, StgInt b) {return a >> b;}
StgInt64 stg_iShiftRL64 (StgInt64 a, StgInt b)
{return (StgInt64) ((StgWord64) a >> b);}
-/* Casting between longs and longer longs:
- (the primops that cast between Integers and long longs are
+/* Casting between longs and longer longs.
+ (the primops that cast from long longs to Integers
expressed as macros, since these may cause some heap allocation).
*/
@@ -86,4 +86,40 @@ StgWord64 stg_wordToWord64 (StgWord w) {return (StgWord64) w;}
StgWord stg_word64ToWord (StgWord64 w) {return (StgWord) w;}
StgInt64 stg_word64ToInt64 (StgWord64 w) {return (StgInt64) w;}
+StgWord64 stg_integerToWord64 (I_ sa, StgByteArray /* Really: mp_limb_t* */ da)
+{
+ mp_limb_t* d;
+ I_ s;
+ StgWord64 res;
+ d = (mp_limb_t *)da;
+ s = sa;
+ switch (s) {
+ case 0: res = 0; break;
+ case 1: res = d[0]; break;
+ case -1: res = -d[0]; break;
+ default:
+ res = d[0] + ((StgWord64) d[1] << (BITS_IN (mp_limb_t)));
+ if (s < 0) res = -res;
+ }
+ return res;
+}
+
+StgInt64 stg_integerToInt64 (StgInt sa, StgByteArray /* Really: mp_limb_t* */ da)
+{
+ mp_limb_t* d;
+ I_ s;
+ StgInt64 res;
+ d = (mp_limb_t *)da;
+ s = (sa);
+ switch (s) {
+ case 0: res = 0; break;
+ case 1: res = d[0]; break;
+ case -1: res = -d[0]; break;
+ default:
+ res = d[0] + ((StgWord64) d[1] << (BITS_IN (mp_limb_t)));
+ if (s < 0) res = -res;
+ }
+ return res;
+}
+
#endif /* SUPPORT_LONG_LONGS */