diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2021-07-07 18:47:25 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-07-15 23:29:09 -0400 |
commit | 41d6cfc4d36ba93d82f16f9a83ea69f4e02c3810 (patch) | |
tree | 067308ecd598d42523238a96ac400a40edbe9f28 /libraries/ghc-prim | |
parent | de98a0ce8f184c9653477ee41602f999c7a381e1 (diff) | |
download | haskell-41d6cfc4d36ba93d82f16f9a83ea69f4e02c3810.tar.gz |
Add Word64#/Int64# primops
Word64#/Int64# are only used on 32-bit architectures. Before this patch,
operations on these types were directly using the FFI. Now we use real
primops that are then lowered into ccalls.
The advantage of doing this is that we can now perform constant folding on
Word64#/Int64# (#19024).
Most of this work was done by John Ericson in !3658. However this patch
doesn't go as far as e.g. changing Word64 to always be using Word64#.
Noticeable performance improvements
T9203(normal) run/alloc 89870808.0 66662456.0 -25.8% GOOD
haddock.Cabal(normal) run/alloc 14215777340.8 12780374172.0 -10.1% GOOD
haddock.base(normal) run/alloc 15420020877.6 13643834480.0 -11.5% GOOD
Metric Decrease:
T9203
haddock.Cabal
haddock.base
Diffstat (limited to 'libraries/ghc-prim')
-rw-r--r-- | libraries/ghc-prim/GHC/Classes.hs | 1 | ||||
-rw-r--r-- | libraries/ghc-prim/GHC/IntWord64.hs | 74 | ||||
-rw-r--r-- | libraries/ghc-prim/cbits/longlong.c | 20 | ||||
-rw-r--r-- | libraries/ghc-prim/ghc-prim.cabal | 1 |
4 files changed, 9 insertions, 87 deletions
diff --git a/libraries/ghc-prim/GHC/Classes.hs b/libraries/ghc-prim/GHC/Classes.hs index dfd707bd8c..a81cb12e8c 100644 --- a/libraries/ghc-prim/GHC/Classes.hs +++ b/libraries/ghc-prim/GHC/Classes.hs @@ -58,7 +58,6 @@ module GHC.Classes( -- GHC.Magic is used in some derived instances import GHC.Magic () -import GHC.IntWord64 import GHC.Prim import GHC.Tuple import GHC.CString (unpackCString#) diff --git a/libraries/ghc-prim/GHC/IntWord64.hs b/libraries/ghc-prim/GHC/IntWord64.hs deleted file mode 100644 index 15a878ccd6..0000000000 --- a/libraries/ghc-prim/GHC/IntWord64.hs +++ /dev/null @@ -1,74 +0,0 @@ -{-# LANGUAGE CPP, MagicHash, NoImplicitPrelude, UnliftedFFITypes #-} -{-# OPTIONS_HADDOCK not-home #-} ------------------------------------------------------------------------------ --- | --- Module : GHC.IntWord64 --- Copyright : (c) The University of Glasgow, 1997-2008 --- License : see libraries/ghc-prim/LICENSE --- --- Maintainer : cvs-ghc@haskell.org --- Stability : internal --- Portability : non-portable (GHC Extensions) --- --- Primitive operations on Int64# and Word64# on platforms where --- WORD_SIZE_IN_BITS < 64. --- ------------------------------------------------------------------------------ - -#include "MachDeps.h" - -module GHC.IntWord64 ( -#if WORD_SIZE_IN_BITS < 64 - Int64#, Word64#, module GHC.IntWord64 -#endif - ) where - -import GHC.Types () -- Make implicit dependency known to build system - -#if WORD_SIZE_IN_BITS < 64 - -import GHC.Prim - -foreign import ccall unsafe "hs_eqWord64" eqWord64# :: Word64# -> Word64# -> Int# -foreign import ccall unsafe "hs_neWord64" neWord64# :: Word64# -> Word64# -> Int# -foreign import ccall unsafe "hs_ltWord64" ltWord64# :: Word64# -> Word64# -> Int# -foreign import ccall unsafe "hs_leWord64" leWord64# :: Word64# -> Word64# -> Int# -foreign import ccall unsafe "hs_gtWord64" gtWord64# :: Word64# -> Word64# -> Int# -foreign import ccall unsafe "hs_geWord64" geWord64# :: Word64# -> Word64# -> Int# - -foreign import ccall unsafe "hs_eqInt64" eqInt64# :: Int64# -> Int64# -> Int# -foreign import ccall unsafe "hs_neInt64" neInt64# :: Int64# -> Int64# -> Int# -foreign import ccall unsafe "hs_ltInt64" ltInt64# :: Int64# -> Int64# -> Int# -foreign import ccall unsafe "hs_leInt64" leInt64# :: Int64# -> Int64# -> Int# -foreign import ccall unsafe "hs_gtInt64" gtInt64# :: Int64# -> Int64# -> Int# -foreign import ccall unsafe "hs_geInt64" geInt64# :: Int64# -> Int64# -> Int# -foreign import ccall unsafe "hs_quotInt64" quotInt64# :: Int64# -> Int64# -> Int64# -foreign import ccall unsafe "hs_remInt64" remInt64# :: Int64# -> Int64# -> Int64# - -foreign import ccall unsafe "hs_plusInt64" plusInt64# :: Int64# -> Int64# -> Int64# -foreign import ccall unsafe "hs_minusInt64" minusInt64# :: Int64# -> Int64# -> Int64# -foreign import ccall unsafe "hs_timesInt64" timesInt64# :: Int64# -> Int64# -> Int64# -foreign import ccall unsafe "hs_negateInt64" negateInt64# :: Int64# -> Int64# -foreign import ccall unsafe "hs_quotWord64" quotWord64# :: Word64# -> Word64# -> Word64# -foreign import ccall unsafe "hs_remWord64" remWord64# :: Word64# -> Word64# -> Word64# - -foreign import ccall unsafe "hs_and64" and64# :: Word64# -> Word64# -> Word64# -foreign import ccall unsafe "hs_or64" or64# :: Word64# -> Word64# -> Word64# -foreign import ccall unsafe "hs_xor64" xor64# :: Word64# -> Word64# -> Word64# -foreign import ccall unsafe "hs_not64" not64# :: Word64# -> Word64# - -foreign import ccall unsafe "hs_uncheckedShiftL64" uncheckedShiftL64# :: Word64# -> Int# -> Word64# -foreign import ccall unsafe "hs_uncheckedShiftRL64" uncheckedShiftRL64# :: Word64# -> Int# -> Word64# -foreign import ccall unsafe "hs_uncheckedIShiftL64" uncheckedIShiftL64# :: Int64# -> Int# -> Int64# -foreign import ccall unsafe "hs_uncheckedIShiftRA64" uncheckedIShiftRA64# :: Int64# -> Int# -> Int64# -foreign import ccall unsafe "hs_uncheckedIShiftRL64" uncheckedIShiftRL64# :: Int64# -> Int# -> Int64# - -foreign import ccall unsafe "hs_int64ToWord64" int64ToWord64# :: Int64# -> Word64# -foreign import ccall unsafe "hs_word64ToInt64" word64ToInt64# :: Word64# -> Int64# -foreign import ccall unsafe "hs_intToInt64" intToInt64# :: Int# -> Int64# -foreign import ccall unsafe "hs_int64ToInt" int64ToInt# :: Int64# -> Int# -foreign import ccall unsafe "hs_wordToWord64" wordToWord64# :: Word# -> Word64# -foreign import ccall unsafe "hs_word64ToWord" word64ToWord# :: Word64# -> Word# - -#endif - diff --git a/libraries/ghc-prim/cbits/longlong.c b/libraries/ghc-prim/cbits/longlong.c index 7f3554b930..0631bdad58 100644 --- a/libraries/ghc-prim/cbits/longlong.c +++ b/libraries/ghc-prim/cbits/longlong.c @@ -32,31 +32,32 @@ The exceptions to the rule are primops that cast to and from /* Relational operators */ +HsInt hs_eq64 (HsWord64 a, HsWord64 b) {return a == b;} +HsInt hs_ne64 (HsWord64 a, HsWord64 b) {return a != b;} + HsInt hs_gtWord64 (HsWord64 a, HsWord64 b) {return a > b;} HsInt hs_geWord64 (HsWord64 a, HsWord64 b) {return a >= b;} -HsInt hs_eqWord64 (HsWord64 a, HsWord64 b) {return a == b;} -HsInt hs_neWord64 (HsWord64 a, HsWord64 b) {return a != b;} HsInt hs_ltWord64 (HsWord64 a, HsWord64 b) {return a < b;} HsInt hs_leWord64 (HsWord64 a, HsWord64 b) {return a <= b;} HsInt hs_gtInt64 (HsInt64 a, HsInt64 b) {return a > b;} HsInt hs_geInt64 (HsInt64 a, HsInt64 b) {return a >= b;} -HsInt hs_eqInt64 (HsInt64 a, HsInt64 b) {return a == b;} -HsInt hs_neInt64 (HsInt64 a, HsInt64 b) {return a != b;} HsInt hs_ltInt64 (HsInt64 a, HsInt64 b) {return a < b;} HsInt hs_leInt64 (HsInt64 a, HsInt64 b) {return a <= b;} /* Arithmetic operators */ +HsInt64 hs_neg64 (HsInt64 a) {return - a;} + +HsWord64 hs_add64 (HsWord64 a, HsWord64 b) {return a + b;} +HsWord64 hs_sub64 (HsWord64 a, HsWord64 b) {return a - b;} +HsWord64 hs_mul64 (HsWord64 a, HsWord64 b) {return a * b;} + HsWord64 hs_remWord64 (HsWord64 a, HsWord64 b) {return a % b;} HsWord64 hs_quotWord64 (HsWord64 a, HsWord64 b) {return a / b;} HsInt64 hs_remInt64 (HsInt64 a, HsInt64 b) {return a % b;} HsInt64 hs_quotInt64 (HsInt64 a, HsInt64 b) {return a / b;} -HsInt64 hs_negateInt64 (HsInt64 a) {return -a;} -HsInt64 hs_plusInt64 (HsInt64 a, HsInt64 b) {return a + b;} -HsInt64 hs_minusInt64 (HsInt64 a, HsInt64 b) {return a - b;} -HsInt64 hs_timesInt64 (HsInt64 a, HsInt64 b) {return a * b;} /* Logical operators: */ @@ -71,10 +72,7 @@ HsWord64 hs_uncheckedShiftRL64 (HsWord64 a, HsInt b) {return a >> b;} the behaviour you'll get from using these primops depends on the whatever your C compiler is doing. ToDo: fix. -- sof 8/98 */ -HsInt64 hs_uncheckedIShiftL64 (HsInt64 a, HsInt b) {return a << b;} HsInt64 hs_uncheckedIShiftRA64 (HsInt64 a, HsInt b) {return a >> b;} -HsInt64 hs_uncheckedIShiftRL64 (HsInt64 a, HsInt b) - {return (HsInt64) ((HsWord64) a >> b);} /* Casting between longs and longer longs. */ diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal index 61840021c1..812324e117 100644 --- a/libraries/ghc-prim/ghc-prim.cabal +++ b/libraries/ghc-prim/ghc-prim.cabal @@ -43,7 +43,6 @@ Library GHC.CString GHC.Classes GHC.Debug - GHC.IntWord64 GHC.Magic GHC.Magic.Dict GHC.Prim.Ext |