[commit: ghc] master: Use {bit, popCount}Integer for `Bits Integer` (ed56c02)

git at git.haskell.org git at git.haskell.org
Wed Nov 26 17:10:00 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/ed56c023e3e2e3d2a9fe18a17e2131d9a55c69a5/ghc

>---------------------------------------------------------------

commit ed56c023e3e2e3d2a9fe18a17e2131d9a55c69a5
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date:   Wed Nov 26 18:07:05 2014 +0100

    Use {bit,popCount}Integer for `Bits Integer`
    
    The primops are implemented in the `integer-gmp2` (#9281) backend and
    are already used for the `Bits Natural` instance but aren't used yet for
    the `Bits Integer` instace.  This commit fixes that.


>---------------------------------------------------------------

ed56c023e3e2e3d2a9fe18a17e2131d9a55c69a5
 libraries/base/Data/Bits.hs | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs
index b4ab912..69a0377 100644
--- a/libraries/base/Data/Bits.hs
+++ b/libraries/base/Data/Bits.hs
@@ -57,12 +57,20 @@ module Data.Bits (
 
 #include "MachDeps.h"
 
+#ifdef MIN_VERSION_integer_gmp
+# define HAVE_INTEGER_GMP1 MIN_VERSION_integer_gmp(1,0,0)
+#endif
+
 import Data.Maybe
 import GHC.Enum
 import GHC.Num
 import GHC.Base
 import GHC.Real
 
+#if HAVE_INTEGER_GMP1
+import GHC.Integer.GMP.Internals (bitInteger, popCountInteger)
+#endif
+
 infixl 8 `shift`, `rotate`, `shiftL`, `shiftR`, `rotateL`, `rotateR`
 infixl 7 .&.
 infixl 6 `xor`
@@ -513,8 +521,14 @@ instance Bits Integer where
    testBit x (I# i) = testBitInteger x i
 
    zeroBits   = 0
+
+#if HAVE_INTEGER_GMP1
+   bit (I# i#) = bitInteger i#
+   popCount x  = I# (popCountInteger x)
+#else
    bit        = bitDefault
    popCount   = popCountDefault
+#endif
 
    rotate x i = shift x i   -- since an Integer never wraps around
 



More information about the ghc-commits mailing list