[commit: ghc] master: Add gcd/Word RULE-based optimisation (5ea3ee0)
git at git.haskell.org
git at git.haskell.org
Sat Nov 22 13:00:44 UTC 2014
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/5ea3ee02c7e616235508f1829f8ccfd6047eaf98/ghc
>---------------------------------------------------------------
commit 5ea3ee02c7e616235508f1829f8ccfd6047eaf98
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Sat Nov 22 13:28:25 2014 +0100
Add gcd/Word RULE-based optimisation
This makes use of the `gcdWord` primitive provided by
be7fb7e58c70cd9b0a933fb26cd5f2607d6dc4b2 which should make the
`Word`-variant of `gcd` as performant as the `Int`-variant.
>---------------------------------------------------------------
5ea3ee02c7e616235508f1829f8ccfd6047eaf98
libraries/base/GHC/Real.hs | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/libraries/base/GHC/Real.hs b/libraries/base/GHC/Real.hs
index a5a35db..c301325 100644
--- a/libraries/base/GHC/Real.hs
+++ b/libraries/base/GHC/Real.hs
@@ -634,6 +634,15 @@ lcm x y = abs ((x `quot` (gcd x y)) * y)
gcdInt' :: Int -> Int -> Int
gcdInt' (I# x) (I# y) = I# (gcdInt x y)
+
+#if MIN_VERSION_integer_gmp(1,0,0)
+{-# RULES
+"gcd/Word->Word->Word" gcd = gcdWord'
+ #-}
+
+gcdWord' :: Word -> Word -> Word
+gcdWord' (W# x) (W# y) = W# (gcdWord x y)
+#endif
#endif
integralEnumFrom :: (Integral a, Bounded a) => a -> [a]
More information about the ghc-commits
mailing list