summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-11-03 11:01:15 +0100
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-11-06 04:07:28 +0000
commit2d6c5027a3ec8e66affced44a7d35567b4b236a9 (patch)
tree6f1f3a9d7bd6b451dd1e7af3b6106dec572dfbbc
parent0871a7094a94fbc722a137d4ccef9b0be4a6c26e (diff)
downloadhaskell-wip/hsyl20/word64-primops.tar.gz
Fix Int64/Word64's Enum instance fusionwip/hsyl20/word64-primops
Performance improvement: T15185(normal) run/alloc 51112.0 41032.0 -19.7% GOOD Metric Decrease: T15185
-rw-r--r--libraries/base/GHC/Int.hs9
-rw-r--r--libraries/base/GHC/Word.hs19
2 files changed, 28 insertions, 0 deletions
diff --git a/libraries/base/GHC/Int.hs b/libraries/base/GHC/Int.hs
index d0ab7d055e..b5c5530688 100644
--- a/libraries/base/GHC/Int.hs
+++ b/libraries/base/GHC/Int.hs
@@ -753,6 +753,7 @@ instance Enum Int64 where
| x >= fromIntegral (minBound::Int) && x <= fromIntegral (maxBound::Int)
= I# (int64ToInt# x#)
| otherwise = fromEnumError "Int64" x
+#if WORD_SIZE_IN_BITS < 64
-- See Note [Stable Unfolding for list producers] in GHC.Enum
{-# INLINE enumFrom #-}
enumFrom = integralEnumFrom
@@ -765,6 +766,14 @@ instance Enum Int64 where
-- See Note [Stable Unfolding for list producers] in GHC.Enum
{-# INLINE enumFromThenTo #-}
enumFromThenTo = integralEnumFromThenTo
+#else
+ -- See Note [Stable Unfolding for list producers] in GHC.Enum
+ {-# INLINE enumFrom #-}
+ enumFrom = boundedEnumFrom
+ -- See Note [Stable Unfolding for list producers] in GHC.Enum
+ {-# INLINE enumFromThen #-}
+ enumFromThen = boundedEnumFromThen
+#endif
-- | @since 2.01
instance Integral Int64 where
diff --git a/libraries/base/GHC/Word.hs b/libraries/base/GHC/Word.hs
index be1921df05..408dede2d3 100644
--- a/libraries/base/GHC/Word.hs
+++ b/libraries/base/GHC/Word.hs
@@ -730,6 +730,7 @@ instance Enum Word64 where
| x <= fromIntegral (maxBound::Int)
= I# (word2Int# (word64ToWord# x#))
| otherwise = fromEnumError "Word64" x
+#if WORD_SIZE_IN_BITS < 64
-- See Note [Stable Unfolding for list producers] in GHC.Enum
{-# INLINE enumFrom #-}
enumFrom = integralEnumFrom
@@ -742,6 +743,24 @@ instance Enum Word64 where
-- See Note [Stable Unfolding for list producers] in GHC.Enum
{-# INLINE enumFromThenTo #-}
enumFromThenTo = integralEnumFromThenTo
+#else
+ -- use Word's Enum as it has better support for fusion. We can't use
+ -- `boundedEnumFrom` and `boundedEnumFromThen` -- which use Int's Enum
+ -- instance -- because Word64 isn't compatible with Int/Int64's domain.
+ --
+ -- See Note [Stable Unfolding for list producers] in GHC.Enum
+ {-# INLINE enumFrom #-}
+ enumFrom x = map fromIntegral (enumFrom (fromIntegral x :: Word))
+ -- See Note [Stable Unfolding for list producers] in GHC.Enum
+ {-# INLINE enumFromThen #-}
+ enumFromThen x y = map fromIntegral (enumFromThen (fromIntegral x :: Word) (fromIntegral y))
+ -- See Note [Stable Unfolding for list producers] in GHC.Enum
+ {-# INLINE enumFromTo #-}
+ enumFromTo x y = map fromIntegral (enumFromTo (fromIntegral x :: Word) (fromIntegral y))
+ -- See Note [Stable Unfolding for list producers] in GHC.Enum
+ {-# INLINE enumFromThenTo #-}
+ enumFromThenTo x y z = map fromIntegral (enumFromThenTo (fromIntegral x :: Word) (fromIntegral y) (fromIntegral z))
+#endif
-- | @since 2.01
instance Integral Word64 where