From d75ca3bcfb7a37b42570754be7ba671321d57770 Mon Sep 17 00:00:00 2001 From: Jan Stolarek Date: Mon, 16 Sep 2013 15:16:46 +0100 Subject: Follow changes in comparison primops (see #6135) --- .../GHC/Integer/Logarithms/Internals.hs | 22 ++++---- libraries/integer-simple/GHC/Integer/Type.hs | 65 +++++++++++----------- 2 files changed, 43 insertions(+), 44 deletions(-) (limited to 'libraries/integer-simple') diff --git a/libraries/integer-simple/GHC/Integer/Logarithms/Internals.hs b/libraries/integer-simple/GHC/Integer/Logarithms/Internals.hs index baf0afa575..fea7f7941a 100644 --- a/libraries/integer-simple/GHC/Integer/Logarithms/Internals.hs +++ b/libraries/integer-simple/GHC/Integer/Logarithms/Internals.hs @@ -18,8 +18,8 @@ module GHC.Integer.Logarithms.Internals ) where import GHC.Prim -import GHC.PrimWrappers import GHC.Integer.Type +import GHC.Types default () @@ -51,38 +51,38 @@ wordLog2# w = #if WORD_SIZE_IN_BITS == 64 case uncheckedShiftRL# w 56# of a -> - if a `neWord#` 0## + if isTrue# (a `neWord#` 0##) then 64# -# zeros a else case uncheckedShiftRL# w 48# of b -> - if b `neWord#` 0## + if isTrue# (b `neWord#` 0##) then 56# -# zeros b else case uncheckedShiftRL# w 40# of c -> - if c `neWord#` 0## + if isTrue# (c `neWord#` 0##) then 48# -# zeros c else case uncheckedShiftRL# w 32# of d -> - if d `neWord#` 0## + if isTrue# (d `neWord#` 0##) then 40# -# zeros d else #endif case uncheckedShiftRL# w 24# of e -> - if e `neWord#` 0## + if isTrue# (e `neWord#` 0##) then 32# -# zeros e else case uncheckedShiftRL# w 16# of f -> - if f `neWord#` 0## + if isTrue# (f `neWord#` 0##) then 24# -# zeros f else case uncheckedShiftRL# w 8# of g -> - if g `neWord#` 0## + if isTrue# (g `neWord#` 0##) then 16# -# zeros g else 8# -# zeros w @@ -107,7 +107,7 @@ integerLog2IsPowerOf2# (Positive digits) = couldBe 0# digits couldBe acc (Some dig None) = (# acc +# wordLog2# dig, word2Int# (and# dig (minusWord# dig 1##)) #) couldBe acc (Some dig digs) = - if eqWord# dig 0## + if isTrue# (eqWord# dig 0##) then couldBe (acc +# WORD_SIZE_IN_BITS#) digs else noPower (acc +# WORD_SIZE_IN_BITS#) digs couldBe acc None = (# acc, 1# #) -- should be impossible, error? @@ -153,9 +153,9 @@ leadingZeros = case writeInt8Array# mba 0# 9# s1 of s2 -> let fillA lim val idx st = - if idx ==# 256# + if isTrue# (idx ==# 256#) then st - else if idx <# lim + else if isTrue# (idx <# lim) then case writeInt8Array# mba idx val st of nx -> fillA lim val (idx +# 1#) nx else fillA (2# *# lim) (val -# 1#) idx st diff --git a/libraries/integer-simple/GHC/Integer/Type.hs b/libraries/integer-simple/GHC/Integer/Type.hs index 88b1c4c450..387b8e20e3 100644 --- a/libraries/integer-simple/GHC/Integer/Type.hs +++ b/libraries/integer-simple/GHC/Integer/Type.hs @@ -28,7 +28,6 @@ module GHC.Integer.Type where import GHC.Prim -import GHC.PrimWrappers import GHC.Classes import GHC.Types import GHC.Tuple () @@ -75,13 +74,13 @@ errorPositive = Some 47## None -- Random number {-# NOINLINE smallInteger #-} smallInteger :: Int# -> Integer -smallInteger i = if i >=# 0# then wordToInteger (int2Word# i) +smallInteger i = if isTrue# (i >=# 0#) then wordToInteger (int2Word# i) else -- XXX is this right for -minBound? negateInteger (wordToInteger (int2Word# (negateInt# i))) {-# NOINLINE wordToInteger #-} wordToInteger :: Word# -> Integer -wordToInteger w = if w `eqWord#` 0## +wordToInteger w = if isTrue# (w `eqWord#` 0##) then Naught else Positive (Some w None) @@ -105,7 +104,7 @@ integerToWord64 i = int64ToWord64# (integerToInt64 i) {-# NOINLINE word64ToInteger #-} word64ToInteger:: Word64# -> Integer -word64ToInteger w = if w `eqWord64#` wordToWord64# 0## +word64ToInteger w = if isTrue# (w `eqWord64#` wordToWord64# 0##) then Naught else Positive (word64ToPositive w) @@ -119,9 +118,9 @@ integerToInt64 (Negative p) {-# NOINLINE int64ToInteger #-} int64ToInteger :: Int64# -> Integer int64ToInteger i - = if i `eqInt64#` intToInt64# 0# + = if isTrue# (i `eqInt64#` intToInt64# 0#) then Naught - else if i `gtInt64#` intToInt64# 0# + else if isTrue# (i `gtInt64#` intToInt64# 0#) then Positive (word64ToPositive (int64ToWord64# i)) else Negative (word64ToPositive (int64ToWord64# (negateInt64# i))) #else @@ -445,8 +444,8 @@ x `neqInteger#` y = case x `compareInteger` y of {-# INLINE eqInteger #-} {-# INLINE neqInteger #-} eqInteger, neqInteger :: Integer -> Integer -> Bool -eqInteger a b = tagToEnum# (a `eqInteger#` b) -neqInteger a b = tagToEnum# (a `neqInteger#` b) +eqInteger a b = isTrue# (a `eqInteger#` b) +neqInteger a b = isTrue# (a `neqInteger#` b) instance Eq Integer where (==) = eqInteger @@ -481,10 +480,10 @@ x `geInteger#` y = case x `compareInteger` y of {-# INLINE geInteger #-} {-# INLINE gtInteger #-} leInteger, gtInteger, ltInteger, geInteger :: Integer -> Integer -> Bool -leInteger a b = tagToEnum# (a `leInteger#` b) -gtInteger a b = tagToEnum# (a `gtInteger#` b) -ltInteger a b = tagToEnum# (a `ltInteger#` b) -geInteger a b = tagToEnum# (a `geInteger#` b) +leInteger a b = isTrue# (a `leInteger#` b) +gtInteger a b = isTrue# (a `gtInteger#` b) +ltInteger a b = isTrue# (a `ltInteger#` b) +geInteger a b = isTrue# (a `geInteger#` b) instance Ord Integer where (<=) = leInteger @@ -550,7 +549,7 @@ digitsToNegativeInteger ds = case removeZeroTails ds of ds' -> Negative ds' removeZeroTails :: Digits -> Digits -removeZeroTails (Some w ds) = if w `eqWord#` 0## +removeZeroTails (Some w ds) = if isTrue# (w `eqWord#` 0##) then case removeZeroTails ds of None -> None ds' -> Some w ds' @@ -560,7 +559,7 @@ removeZeroTails None = None #if WORD_SIZE_IN_BITS < 64 word64ToPositive :: Word64# -> Positive word64ToPositive w - = if w `eqWord64#` wordToWord64# 0## + = if isTrue# (w `eqWord64#` wordToWord64# 0##) then None else Some (word64ToWord# w) (word64ToPositive (w `uncheckedShiftRL64#` 32#)) @@ -574,9 +573,9 @@ positiveToWord64 (Some low (Some high _)) -- Note [Avoid patError] comparePositive :: Positive -> Positive -> Ordering Some x xs `comparePositive` Some y ys = case xs `comparePositive` ys of - EQ -> if x `ltWord#` y then LT - else if x `gtWord#` y then GT - else EQ + EQ -> if isTrue# (x `ltWord#` y) then LT + else if isTrue# (x `gtWord#` y) then GT + else EQ res -> res None `comparePositive` None = EQ (Some {}) `comparePositive` None = GT @@ -591,9 +590,9 @@ plusPositive x0 y0 = addWithCarry 0## x0 y0 addWithCarry c xs@(Some {}) None = addOnCarry c xs addWithCarry c None ys@(Some {}) = addOnCarry c ys addWithCarry c xs@(Some x xs') ys@(Some y ys') - = if x `ltWord#` y then addWithCarry c ys xs + = if isTrue# (x `ltWord#` y) then addWithCarry c ys xs -- Now x >= y - else if y `geWord#` halfBoundUp () + else if isTrue# (y `geWord#` halfBoundUp ()) -- So they are both at least halfBoundUp, so we subtract -- halfBoundUp from each and thus carry 1 then case x `minusWord#` halfBoundUp () of @@ -603,14 +602,14 @@ plusPositive x0 y0 = addWithCarry 0## x0 y0 case x' `plusWord#` y' `plusWord#` c of this -> Some this withCarry - else if x `geWord#` halfBoundUp () + else if isTrue# (x `geWord#` halfBoundUp ()) then case x `minusWord#` halfBoundUp () of x' -> case x' `plusWord#` y `plusWord#` c of z -> -- We've taken off halfBoundUp, so now we need to -- add it back on - if z `ltWord#` halfBoundUp () + if isTrue# (z `ltWord#` halfBoundUp ()) then Some (z `plusWord#` halfBoundUp ()) withoutCarry else Some (z `minusWord#` halfBoundUp ()) withCarry else Some (x `plusWord#` y `plusWord#` c) withoutCarry @@ -619,14 +618,14 @@ plusPositive x0 y0 = addWithCarry 0## x0 y0 -- digit `elem` [0, 1] addOnCarry :: Digit -> Positive -> Positive - addOnCarry (!c) (!ws) = if c `eqWord#` 0## + addOnCarry (!c) (!ws) = if isTrue# (c `eqWord#` 0##) then ws else succPositive ws -- digit `elem` [0, 1] succPositive :: Positive -> Positive succPositive None = Some 1## None -succPositive (Some w ws) = if w `eqWord#` fullBound () +succPositive (Some w ws) = if isTrue# (w `eqWord#` fullBound ()) then Some 0## (succPositive ws) else Some (w `plusWord#` 1##) ws @@ -635,11 +634,11 @@ succPositive (Some w ws) = if w `eqWord#` fullBound () -- Note [Avoid patError] minusPositive :: Positive -> Positive -> Positive Some x xs `minusPositive` Some y ys - = if x `eqWord#` y + = if isTrue# (x `eqWord#` y) then case xs `minusPositive` ys of None -> None s -> Some 0## s - else if x `gtWord#` y then + else if isTrue# (x `gtWord#` y) then Some (x `minusWord#` y) (xs `minusPositive` ys) else case (fullBound () `minusWord#` y) `plusWord#` 1## of z -> -- z = 2^n - y, calculated without overflow @@ -673,7 +672,7 @@ xs@(Some x xs') `timesPositive` ys@(Some y ys') let zs = Some 0## (xs' `timesPositive` ys) in -- We could actually skip this test, and everything would -- turn out OK. We already play tricks like that in timesPositive. - if x `eqWord#` 0## + if isTrue# (x `eqWord#` 0##) then zs else (x `timesDigit` y) `plusPositive` zs Some {} -> @@ -724,7 +723,7 @@ timesDigit (!x) (!y) let low = Some xhyll' None `plusPositive` Some xlyhl' None `plusPositive` Some xlyl None - in if high `eqWord#` 0## + in if isTrue# (high `eqWord#` 0##) then low else Some 0## (Some high None) `plusPositive` low @@ -735,7 +734,7 @@ splitHalves (!x) = (# x `uncheckedShiftRL#` highHalfShift (), -- Assumes 0 <= i shiftLPositive :: Positive -> Int# -> Positive shiftLPositive p i - = if i >=# WORD_SIZE_IN_BITS# + = if isTrue# (i >=# WORD_SIZE_IN_BITS#) then shiftLPositive (Some 0## p) (i -# WORD_SIZE_IN_BITS#) else smallShiftLPositive p i @@ -744,7 +743,7 @@ smallShiftLPositive :: Positive -> Int# -> Positive smallShiftLPositive (!p) 0# = p smallShiftLPositive (!p) (!i) = case WORD_SIZE_IN_BITS# -# i of - j -> let f carry None = if carry `eqWord#` 0## + j -> let f carry None = if isTrue# (carry `eqWord#` 0##) then None else Some carry None f carry (Some w ws) = case w `uncheckedShiftRL#` j of @@ -758,14 +757,14 @@ smallShiftLPositive (!p) (!i) = shiftRPositive :: Positive -> Int# -> Integer shiftRPositive None _ = Naught shiftRPositive p@(Some _ q) i - = if i >=# WORD_SIZE_IN_BITS# + = if isTrue# (i >=# WORD_SIZE_IN_BITS#) then shiftRPositive q (i -# WORD_SIZE_IN_BITS#) else smallShiftRPositive p i -- Assumes 0 <= i < WORD_SIZE_IN_BITS# smallShiftRPositive :: Positive -> Int# -> Integer smallShiftRPositive (!p) (!i) = - if i ==# 0# + if isTrue# (i ==# 0#) then Positive p else case smallShiftLPositive p (WORD_SIZE_IN_BITS# -# i) of Some _ p'@(Some _ _) -> Positive p' @@ -781,7 +780,7 @@ quotRemPositive :: Positive -> Positive -> (# Integer, Integer #) subtractors :: Positives subtractors = mkSubtractors (WORD_SIZE_IN_BITS# -# 1#) - mkSubtractors (!n) = if n ==# 0# + mkSubtractors (!n) = if isTrue# (n ==# 0#) then Cons ys Nil else Cons (ys `smallShiftLPositive` n) (mkSubtractors (n -# 1#)) @@ -811,7 +810,7 @@ quotRemPositive :: Positive -> Positive -> (# Integer, Integer #) (m `minusPositive` sub) some :: Digit -> Digits -> Digits -some (!w) None = if w `eqWord#` 0## then None else Some w None +some (!w) None = if isTrue# (w `eqWord#` 0##) then None else Some w None some (!w) (!ws) = Some w ws -- Note [Avoid patError] -- cgit v1.2.1