[Git][ghc/ghc][wip/improve-Word32ToInteger-on-64bit] Improve toInteger @Word32 on 64-bit platforms
Matthew Craven (@clyring)
gitlab at gitlab.haskell.org
Thu Mar 14 00:12:24 UTC 2024
Matthew Craven pushed to branch wip/improve-Word32ToInteger-on-64bit at Glasgow Haskell Compiler / GHC
Commits:
5c7c67e9 by Matthew Craven at 2024-03-13T20:11:38-04:00
Improve toInteger @Word32 on 64-bit platforms
On 64-bit platforms, every Word32 fits in an Int, so we can
convert to Int# without having to perform the overflow check
integerFromWord# uses internally.
- - - - -
2 changed files:
- libraries/base/changelog.md
- libraries/ghc-internal/src/GHC/Internal/Word.hs
Changes:
=====================================
libraries/base/changelog.md
=====================================
@@ -1,5 +1,8 @@
# Changelog for [`base` package](http://hackage.haskell.org/package/base)
+## 4.21.0.0 *TBA*
+ * Improve `toInteger :: Word32 -> Integer` on 64-bit platforms ([CLC proposal #259](https://github.com/haskell/core-libraries-committee/issues/259))
+
## 4.20.0.0 *TBA*
* Export `foldl'` from `Prelude` ([CLC proposal #167](https://github.com/haskell/core-libraries-committee/issues/167))
* The top-level handler for uncaught exceptions now displays the output of `displayException` rather than `show` ([CLC proposal #198](https://github.com/haskell/core-libraries-committee/issues/198))
=====================================
libraries/ghc-internal/src/GHC/Internal/Word.hs
=====================================
@@ -592,7 +592,13 @@ instance Integral Word32 where
mod x y = rem x y
divMod x y = quotRem x y
- toInteger (W32# x#) = integerFromWord# (word32ToWord# x#)
+ toInteger (W32# x#) =
+#if WORD_SIZE_IN_BITS > 32
+ -- In this case the conversion to Int# cannot overflow.
+ IS (word2Int# (word32ToWord# x#))
+#else
+ integerFromWord# (word32ToWord# x#)
+#endif
-- | @since base-2.01
instance Bits Word32 where
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5c7c67e9a9dcea2e0293c68224e3fad12a08afc6
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5c7c67e9a9dcea2e0293c68224e3fad12a08afc6
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240313/b0c48f00/attachment-0001.html>
More information about the ghc-commits
mailing list