X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FBits.hs;h=cbf7b37015b3d1b8f732ee8a048dad9b9dd9a843;hb=HEAD;hp=890909c03ee7455630b6e006b897acbd6ae5865b;hpb=21081676e9c7d88912a98ce6424b75200a6699b9;p=ghc-base.git diff --git a/Data/Bits.hs b/Data/Bits.hs index 890909c..cbf7b37 100644 --- a/Data/Bits.hs +++ b/Data/Bits.hs @@ -1,4 +1,5 @@ -{-# OPTIONS_GHC -XNoImplicitPrelude #-} +{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns, MagicHash #-} + ----------------------------------------------------------------------------- -- | -- Module : Data.Bits @@ -126,7 +127,7 @@ class Num a => Bits a where | i>0 = (x `shift` i) .|. (x `shift` (i-bitSize x)) -} - -- | @bit i@ is a value with the @i@th bit set + -- | @bit i@ is a value with the @i@th bit set and all other bits clear bit :: Int -> a -- | @x \`setBit\` i@ is the same as @x .|. bit i@ @@ -151,6 +152,11 @@ class Num a => Bits a where value of the argument is ignored -} isSigned :: a -> Bool + {-# INLINE bit #-} + {-# INLINE setBit #-} + {-# INLINE clearBit #-} + {-# INLINE complementBit #-} + {-# INLINE testBit #-} bit i = 1 `shiftL` i x `setBit` i = x .|. bit i x `clearBit` i = x .&. complement (bit i) @@ -164,6 +170,7 @@ class Num a => Bits a where 'shift', depending on which is more convenient for the type in question. -} shiftL :: a -> Int -> a + {-# INLINE shiftL #-} x `shiftL` i = x `shift` i {-| Shift the first argument right by the specified number of bits @@ -176,6 +183,7 @@ class Num a => Bits a where 'shift', depending on which is more convenient for the type in question. -} shiftR :: a -> Int -> a + {-# INLINE shiftR #-} x `shiftR` i = x `shift` (-i) {-| Rotate the argument left by the specified number of bits @@ -185,6 +193,7 @@ class Num a => Bits a where 'rotate', depending on which is more convenient for the type in question. -} rotateL :: a -> Int -> a + {-# INLINE rotateL #-} x `rotateL` i = x `rotate` i {-| Rotate the argument right by the specified number of bits @@ -194,6 +203,7 @@ class Num a => Bits a where 'rotate', depending on which is more convenient for the type in question. -} rotateR :: a -> Int -> a + {-# INLINE rotateR #-} x `rotateR` i = x `rotate` (-i) instance Bits Int where @@ -222,9 +232,6 @@ instance Bits Int where !wsib = WORD_SIZE_IN_BITS# {- work around preprocessor problem (??) -} bitSize _ = WORD_SIZE_IN_BITS - {-# INLINE shiftR #-} - -- same as the default definition, but we want it inlined (#2376) - x `shiftR` i = x `shift` (-i) #else /* !__GLASGOW_HASKELL__ */ #ifdef __HUGS__