diff options
Diffstat (limited to 'ghc/lib/std')
| -rw-r--r-- | ghc/lib/std/PrelGHC.hi-boot.pp | 4 | ||||
| -rw-r--r-- | ghc/lib/std/PrelInt.lhs | 2 | ||||
| -rw-r--r-- | ghc/lib/std/PrelWord.lhs | 3 | ||||
| -rw-r--r-- | ghc/lib/std/cbits/longlong.c | 42 |
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 */ |
