Redefine gcdInt to use gcdInteger rather than gcdInt# primop
authorDuncan Coutts <duncan@well-typed.com>
Fri, 12 Jun 2009 14:29:51 +0000 (14:29 +0000)
committerDuncan Coutts <duncan@well-typed.com>
Fri, 12 Jun 2009 14:29:51 +0000 (14:29 +0000)
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
GHC/Real.lhs

index 4c47992..3806d78 100644 (file)
@@ -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)
 
index eca9974..6a3f335 100644 (file)
@@ -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)]