From dcf1dbdc1d885130136b28f70dc7548ec10f07b5 Mon Sep 17 00:00:00 2001 From: Duncan Coutts Date: Fri, 12 Jun 2009 14:29:51 +0000 Subject: [PATCH] Redefine gcdInt to use gcdInteger rather than gcdInt# primop The gcdInt# primop uses gmp internally, even though the interface is just Int#. Since we want to get gmp out of the rts we cannot keep gcdInt#, however it's also a bit odd for the integer package to export something that doesn't actually use Integer in its interface. Using gcdInteger is still not terribly satisfactory aesthetically. However in the short-term it works and it is no slower since gcdInteger calls gcdInt# for the special case of two small Integers. --- GHC/Base.lhs | 13 +------------ GHC/Real.lhs | 4 ++++ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/GHC/Base.lhs b/GHC/Base.lhs index 4c47992..3806d78 100644 --- a/GHC/Base.lhs +++ b/GHC/Base.lhs @@ -773,7 +773,7 @@ used in the case of partial applications, etc. {-# INLINE remInt #-} {-# INLINE negateInt #-} -plusInt, minusInt, timesInt, quotInt, remInt, divInt, modInt, gcdInt :: Int -> Int -> Int +plusInt, minusInt, timesInt, quotInt, remInt, divInt, modInt :: Int -> Int -> Int (I# x) `plusInt` (I# y) = I# (x +# y) (I# x) `minusInt` (I# y) = I# (x -# y) (I# x) `timesInt` (I# y) = I# (x *# y) @@ -793,17 +793,6 @@ plusInt, minusInt, timesInt, quotInt, remInt, divInt, modInt, gcdInt :: Int -> I "1# *# x#" forall x#. 1# *# x# = x# #-} -gcdInt (I# a) (I# b) = g a b - where g 0# 0# = error "GHC.Base.gcdInt: gcd 0 0 is undefined" - g 0# _ = I# absB - g _ 0# = I# absA - g _ _ = I# (gcdInt# absA absB) - - absInt x = if x <# 0# then negateInt# x else x - - !absA = absInt a - !absB = absInt b - negateInt :: Int -> Int negateInt (I# x) = I# (negateInt# x) diff --git a/GHC/Real.lhs b/GHC/Real.lhs index eca9974..6a3f335 100644 --- a/GHC/Real.lhs +++ b/GHC/Real.lhs @@ -462,6 +462,10 @@ gcdInteger' :: Integer -> Integer -> Integer gcdInteger' 0 0 = error "GHC.Real.gcdInteger': gcd 0 0 is undefined" gcdInteger' a b = gcdInteger a b +gcdInt :: Int -> Int -> Int +gcdInt 0 0 = error "GHC.Real.gcdInt: gcd 0 0 is undefined" +gcdInt a b = fromIntegral (gcdInteger (fromIntegral a) (fromIntegral b)) + integralEnumFrom :: (Integral a, Bounded a) => a -> [a] integralEnumFrom n = map fromInteger [toInteger n .. toInteger (maxBound `asTypeOf` n)] -- 1.7.10.4