[commit: packages/integer-gmp] master: Comparison primops return Int# (Fixes #6135) (770ba0d)
git at git.haskell.org
git at git.haskell.org
Wed Aug 14 17:16:55 CEST 2013
Repository : ssh://git@git.haskell.org/integer-gmp
On branch : master
Link : http://git.haskell.org/?p=packages/integer-gmp.git;a=commit;h=770ba0dcfe159186fafbf267c88c9182ec4ad60b
>---------------------------------------------------------------
commit 770ba0dcfe159186fafbf267c88c9182ec4ad60b
Author: Jan Stolarek <jan.stolarek at p.lodz.pl>
Date: Sun Apr 14 12:31:44 2013 +0200
Comparison primops return Int# (Fixes #6135)
For a deatiled discussion of this changes please visit the wiki page:
http://hackage.haskell.org/trac/ghc/wiki/PrimBool
>---------------------------------------------------------------
770ba0dcfe159186fafbf267c88c9182ec4ad60b
GHC/Integer.lhs | 2 +
GHC/Integer/GMP/Prim.hs | 1 +
GHC/Integer/Logarithms/Internals.hs | 1 +
GHC/Integer/Type.lhs | 108 +++++++++++++++++++++--------------
4 files changed, 69 insertions(+), 43 deletions(-)
diff --git a/GHC/Integer.lhs b/GHC/Integer.lhs
index 3802aed..fe3f89f 100644
--- a/GHC/Integer.lhs
+++ b/GHC/Integer.lhs
@@ -27,6 +27,8 @@ module GHC.Integer (
plusInteger, minusInteger, timesInteger, negateInteger,
eqInteger, neqInteger, absInteger, signumInteger,
leInteger, gtInteger, ltInteger, geInteger, compareInteger,
+ eqInteger#, neqInteger#,
+ leInteger#, gtInteger#, ltInteger#, geInteger#,
divModInteger, divInteger, modInteger,
quotRemInteger, quotInteger, remInteger,
encodeFloatInteger, floatFromInteger,
diff --git a/GHC/Integer/GMP/Prim.hs b/GHC/Integer/GMP/Prim.hs
index cf3b97e..45d1348 100644
--- a/GHC/Integer/GMP/Prim.hs
+++ b/GHC/Integer/GMP/Prim.hs
@@ -53,6 +53,7 @@ module GHC.Integer.GMP.Prim (
) where
import GHC.Prim
+import GHC.PrimWrappers
-- Double isn't available yet, and we shouldn't be using defaults anyway:
default ()
diff --git a/GHC/Integer/Logarithms/Internals.hs b/GHC/Integer/Logarithms/Internals.hs
index 2128c41..daa4ac9 100644
--- a/GHC/Integer/Logarithms/Internals.hs
+++ b/GHC/Integer/Logarithms/Internals.hs
@@ -18,6 +18,7 @@ module GHC.Integer.Logarithms.Internals
) where
import GHC.Prim
+import GHC.PrimWrappers
import GHC.Integer.Type
-- When larger word sizes become common, add support for those,
diff --git a/GHC/Integer/Type.lhs b/GHC/Integer/Type.lhs
index c953786..46d3c63 100644
--- a/GHC/Integer/Type.lhs
+++ b/GHC/Integer/Type.lhs
@@ -22,9 +22,15 @@ import GHC.Prim (
int2Word#, int2Double#, int2Float#, word2Int#,
-- Operations on Int# that we use for operations on S#
quotInt#, remInt#, negateInt#,
- (==#), (/=#), (<=#), (>=#), (<#), (>#), (*#), (-#),
+ (*#), (-#),
+ (==$#), (/=$#), (<=$#), (>=$#), (<$#), (>$#),
mulIntMayOflo#, addIntC#, subIntC#,
- and#, or#, xor#
+ and#, or#, xor#,
+ tagToEnum#
+ )
+
+import GHC.PrimWrappers (
+ (==#), (/=#), (<=#), (>=#), (<#), (>#)
)
import GHC.Integer.GMP.Prim (
@@ -301,19 +307,25 @@ divExact (J# sa a) (J# sb b)
%*********************************************************
\begin{code}
-{-# NOINLINE eqInteger #-}
-eqInteger :: Integer -> Integer -> Bool
-eqInteger (S# i) (S# j) = i ==# j
-eqInteger (S# i) (J# s d) = cmpIntegerInt# s d i ==# 0#
-eqInteger (J# s d) (S# i) = cmpIntegerInt# s d i ==# 0#
-eqInteger (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) ==# 0#
-
-{-# NOINLINE neqInteger #-}
-neqInteger :: Integer -> Integer -> Bool
-neqInteger (S# i) (S# j) = i /=# j
-neqInteger (S# i) (J# s d) = cmpIntegerInt# s d i /=# 0#
-neqInteger (J# s d) (S# i) = cmpIntegerInt# s d i /=# 0#
-neqInteger (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) /=# 0#
+{-# NOINLINE eqInteger# #-}
+eqInteger# :: Integer -> Integer -> Int#
+eqInteger# (S# i) (S# j) = i ==$# j
+eqInteger# (S# i) (J# s d) = cmpIntegerInt# s d i ==$# 0#
+eqInteger# (J# s d) (S# i) = cmpIntegerInt# s d i ==$# 0#
+eqInteger# (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) ==$# 0#
+
+{-# NOINLINE neqInteger# #-}
+neqInteger# :: Integer -> Integer -> Int#
+neqInteger# (S# i) (S# j) = i /=$# j
+neqInteger# (S# i) (J# s d) = cmpIntegerInt# s d i /=$# 0#
+neqInteger# (J# s d) (S# i) = cmpIntegerInt# s d i /=$# 0#
+neqInteger# (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) /=$# 0#
+
+{-# INLINE eqInteger #-}
+{-# INLINE neqInteger #-}
+eqInteger, neqInteger :: Integer -> Integer -> Bool
+eqInteger a b = tagToEnum# (a `eqInteger#` b)
+neqInteger a b = tagToEnum# (a `neqInteger#` b)
instance Eq Integer where
(==) = eqInteger
@@ -321,33 +333,43 @@ instance Eq Integer where
------------------------------------------------------------------------
-{-# NOINLINE leInteger #-}
-leInteger :: Integer -> Integer -> Bool
-leInteger (S# i) (S# j) = i <=# j
-leInteger (J# s d) (S# i) = cmpIntegerInt# s d i <=# 0#
-leInteger (S# i) (J# s d) = cmpIntegerInt# s d i >=# 0#
-leInteger (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <=# 0#
-
-{-# NOINLINE gtInteger #-}
-gtInteger :: Integer -> Integer -> Bool
-gtInteger (S# i) (S# j) = i ># j
-gtInteger (J# s d) (S# i) = cmpIntegerInt# s d i ># 0#
-gtInteger (S# i) (J# s d) = cmpIntegerInt# s d i <# 0#
-gtInteger (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) ># 0#
-
-{-# NOINLINE ltInteger #-}
-ltInteger :: Integer -> Integer -> Bool
-ltInteger (S# i) (S# j) = i <# j
-ltInteger (J# s d) (S# i) = cmpIntegerInt# s d i <# 0#
-ltInteger (S# i) (J# s d) = cmpIntegerInt# s d i ># 0#
-ltInteger (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <# 0#
-
-{-# NOINLINE geInteger #-}
-geInteger :: Integer -> Integer -> Bool
-geInteger (S# i) (S# j) = i >=# j
-geInteger (J# s d) (S# i) = cmpIntegerInt# s d i >=# 0#
-geInteger (S# i) (J# s d) = cmpIntegerInt# s d i <=# 0#
-geInteger (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) >=# 0#
+{-# NOINLINE leInteger# #-}
+leInteger# :: Integer -> Integer -> Int#
+leInteger# (S# i) (S# j) = i <=$# j
+leInteger# (J# s d) (S# i) = cmpIntegerInt# s d i <=$# 0#
+leInteger# (S# i) (J# s d) = cmpIntegerInt# s d i >=$# 0#
+leInteger# (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <=$# 0#
+
+{-# NOINLINE gtInteger# #-}
+gtInteger# :: Integer -> Integer -> Int#
+gtInteger# (S# i) (S# j) = i >$# j
+gtInteger# (J# s d) (S# i) = cmpIntegerInt# s d i >$# 0#
+gtInteger# (S# i) (J# s d) = cmpIntegerInt# s d i <$# 0#
+gtInteger# (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) >$# 0#
+
+{-# NOINLINE ltInteger# #-}
+ltInteger# :: Integer -> Integer -> Int#
+ltInteger# (S# i) (S# j) = i <$# j
+ltInteger# (J# s d) (S# i) = cmpIntegerInt# s d i <$# 0#
+ltInteger# (S# i) (J# s d) = cmpIntegerInt# s d i >$# 0#
+ltInteger# (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) <$# 0#
+
+{-# NOINLINE geInteger# #-}
+geInteger# :: Integer -> Integer -> Int#
+geInteger# (S# i) (S# j) = i >=$# j
+geInteger# (J# s d) (S# i) = cmpIntegerInt# s d i >=$# 0#
+geInteger# (S# i) (J# s d) = cmpIntegerInt# s d i <=$# 0#
+geInteger# (J# s1 d1) (J# s2 d2) = (cmpInteger# s1 d1 s2 d2) >=$# 0#
+
+{-# INLINE leInteger #-}
+{-# INLINE ltInteger #-}
+{-# 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)
{-# NOINLINE compareInteger #-}
compareInteger :: Integer -> Integer -> Ordering
@@ -373,8 +395,8 @@ compareInteger (J# s1 d1) (J# s2 d2)
instance Ord Integer where
(<=) = leInteger
- (>) = gtInteger
(<) = ltInteger
+ (>) = gtInteger
(>=) = geInteger
compare = compareInteger
\end{code}
More information about the ghc-commits
mailing list