summaryrefslogtreecommitdiff
path: root/libraries/base/GHC/Word.hs
Commit message (Collapse)AuthorAgeFilesLines
* Use Word64# primops in Word64 Num instanceSylvain Henry2022-03-031-3/+3
| | | | Taken froù!3658
* Make most shifts branchlessSylvain Henry2022-01-281-38/+38
|
* bitReverse functions in GHC.Word are since base-4.14.0.0, not 4.12.0.0ARATA Mizuki2021-11-171-4/+4
| | | | They were added in 33173a51c77d9960d5009576ad9b67b646dfda3c, which constitutes GHC 8.10.1 / base-4.14.0.0
* Fix Int64/Word64's Enum instance fusionSylvain Henry2021-11-061-0/+19
| | | | | | | | Performance improvement: T15185(normal) run/alloc 51112.0 41032.0 -19.7% GOOD Metric Decrease: T15185
* Make Word64 use Word64# on every architectureSylvain Henry2021-11-061-186/+6
|
* Remove target dependent CPP for Word64/Int64 (#11470)Sylvain Henry2021-11-061-16/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Primops types were dependent on the target word-size at *compiler* compilation time. It's an issue for multi-target as GHC may not have the correct primops types for the target. This patch fixes some primops types: if they take or return fixed 64-bit values they now always use `Int64#/Word64#`, even on 64-bit architectures (where they used `Int#/Word#` before). Users of these primops may now need to convert from Int64#/Word64# to Int#/Word# (a no-op at runtime). This is a stripped down version of !3658 which goes the all way of changing the underlying primitive types of Word64/Int64. This is left for future work. T12545 allocations increase ~4% on some CI platforms and decrease ~3% on AArch64. Metric Increase: T12545 Metric Decrease: T12545
* Add more INLINABLE and INLINE pragmas to `Enum Int*` instancesSebastian Graf2021-10-291-4/+32
| | | | | Otherwise the instances aren't good list producers. See Note [Stable Unfolding for list producers].
* Make Int64#/Word64# unconditionally availableJohn Ericson2021-08-191-1/+3
| | | | | | | | This prepares us to actually use them when the native size is 64 bits too. I more than saitisfied my curiosity finding they were gated since 47774449c9d66b768a70851fe82c5222c1f60689.
* Remove ad-hoc fromIntegral rulesSylvain Henry2021-08-091-79/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fromIntegral is defined as: {-# NOINLINE [1] fromIntegral #-} fromIntegral :: (Integral a, Num b) => a -> b fromIntegral = fromInteger . toInteger Before this patch, we had a lot of rewrite rules for fromIntegral, to avoid passing through Integer when there is a faster way, e.g.: "fromIntegral/Int->Word" fromIntegral = \(I# x#) -> W# (int2Word# x#) "fromIntegral/Word->Int" fromIntegral = \(W# x#) -> I# (word2Int# x#) "fromIntegral/Word->Word" fromIntegral = id :: Word -> Word Since we have added sized types and primops (Word8#, Int16#, etc.) and Natural, this approach didn't really scale as there is a combinatorial explosion of types. In addition, we really want these conversions to be optimized for all these types and in every case (not only when fromIntegral is explicitly used). This patch removes all those ad-hoc fromIntegral rules. Instead we rely on inlining and built-in constant-folding rules. There are not too many native conversions between Integer/Natural and fixed size types, so we can handle them all explicitly. Foreign.C.Types was using rules to ensure that fromIntegral rules "sees" through the newtype wrappers,e.g.: {-# RULES "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x) "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x #-} But they aren't necessary because coercions due to newtype deriving are pushed out of the way. So this patch removes these rules (as fromIntegral is now inlined, they won't match anymore anyway). Summary: * INLINE `fromIntegral` * Add some missing constant-folding rules * Remove every fromIntegral ad-hoc rules (fix #19907) Fix #20062 (missing fromIntegral rules for sized primitives) Performance: - T12545 wiggles (tracked by #19414) Metric Decrease: T12545 T10359 Metric Increase: T12545
* Use fix-sized equality primops for fixed size boxed typesJohn Ericson2021-07-211-6/+6
| | | | These are the last to be converted.
* Add Word64#/Int64# primopsSylvain Henry2021-07-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | Word64#/Int64# are only used on 32-bit architectures. Before this patch, operations on these types were directly using the FFI. Now we use real primops that are then lowered into ccalls. The advantage of doing this is that we can now perform constant folding on Word64#/Int64# (#19024). Most of this work was done by John Ericson in !3658. However this patch doesn't go as far as e.g. changing Word64 to always be using Word64#. Noticeable performance improvements T9203(normal) run/alloc 89870808.0 66662456.0 -25.8% GOOD haddock.Cabal(normal) run/alloc 14215777340.8 12780374172.0 -10.1% GOOD haddock.base(normal) run/alloc 15420020877.6 13643834480.0 -11.5% GOOD Metric Decrease: T9203 haddock.Cabal haddock.base
* Fix Integral instances for WordsSylvain Henry2021-06-041-55/+72
| | | | | | | | | | | | * ensure that division wrappers are INLINE * make div/mod/divMod call quot/rem/quotRem (same code) * this ensures that the quotRemWordN# primitive is used to implement divMod (it wasn't the case for sized Words) * make first argument strict for Natural and Integer (similarly to other numeric types)
* Use fix-sized order primops for fixed size boxed typesJohn Ericson2021-05-131-12/+12
| | | | Progress towards #19026
* Use fix-sized arithmetic primops for fixed size boxed typesJohn Ericson2021-05-061-32/+29
| | | | | | | | | | | We think the compiler is ready, so we can do this for all over the 8-, 16-, and 32-bit boxed types. We are holding off on doing all the primops at once so things are easier to investigate. Metric Decrease: T12545
* Move shift ops out of GHC.BaseSylvain Henry2021-05-031-0/+25
| | | | | | | With a quick flavour I get: before T12545(normal) ghc/alloc 8628109152 after T12545(normal) ghc/alloc 8559741088
* Use fix-sized bit-fiddling primops for fixed size boxed typesJohn Ericson2021-05-031-45/+44
| | | | | Like !5572, this is switching over a portion of the primops which seems safe to use.
* Fix array and cleanup conversion primops (#19026)Sylvain Henry2021-03-031-128/+128
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The first change makes the array ones use the proper fixed-size types, which also means that just like before, they can be used without explicit conversions with the boxed sized types. (Before, it was Int# / Word# on both sides, now it is fixed sized on both sides). For the second change, don't use "extend" or "narrow" in some of the user-facing primops names for conversions. - Names like `narrowInt32#` are misleading when `Int` is 32-bits. - Names like `extendInt64#` are flat-out wrong when `Int is 32-bits. - `narrow{Int,Word}<N>#` however map a type to itself, and so don't suffer from this problem. They are left as-is. These changes are batched together because Alex happend to use the array ops. We can only use released versions of Alex at this time, sadly, and I don't want to have to have a release thatwon't work for the final GHC 9.2. So by combining these we get all the changes for Alex done at once. Bump hackage state in a few places, and also make that workflow slightly easier for the future. Bump minimum Alex version Bump Cabal, array, bytestring, containers, text, and binary submodules
* Implement #15993Koz Ross2021-01-231-1/+1
|
* [Sized Cmm] properly retain sizes.Moritz Angermann2020-11-261-133/+135
| | | | | | | | | | | | | | | | | | | | | | | | | | | This replaces all Word<N> = W<N># Word# and Int<N> = I<N># Int# with Word<N> = W<N># Word<N># and Int<N> = I<N># Int<N>#, thus providing us with properly sized primitives in the codegenerator instead of pretending they are all full machine words. This came up when implementing darwinpcs for arm64. The darwinpcs reqires us to pack function argugments in excess of registers on the stack. While most procedure call standards (pcs) assume arguments are just passed in 8 byte slots; and thus the caller does not know the exact signature to make the call, darwinpcs requires us to adhere to the prototype, and thus have the correct sizes. If we specify CInt in the FFI call, it should correspond to the C int, and not just be Word sized, when it's only half the size. This does change the expected output of T16402 but the new result is no less correct as it eliminates the narrowing (instead of the `and` as was previously done). Bumps the array, bytestring, text, and binary submodules. Co-Authored-By: Ben Gamari <ben@well-typed.com> Metric Increase: T13701 T14697
* Update `base` packageSylvain Henry2020-06-171-17/+17
| | | | | | | | | | | | | | | * GHC.Natural isn't implemented in `base` anymore. It is provided by ghc-bignum in GHC.Num.Natural. It means that we can safely use Natural primitives in `base` without fearing issues with built-in rewrite rules (cf #15286) * `base` doesn't conditionally depend on an integer-* package anymore, it depends on ghc-bignum * Some duplicated code in integer-* can now be factored in GHC.Float * ghc-bignum tries to use a uniform naming convention so most of the other changes are renaming
* Piggyback on Enum Word methods for Word64buggymcbugfix2020-05-211-4/+38
| | | | | If we are on a 64 bit platform, we can use the efficient Enum Word methods for the Enum Word64 instance.
* Make documentation for byteSwap16 consistent with byteSwap32 (impl is same, ↵Brian Wignall2019-10-251-1/+1
| | | | with s/16/32)
* base: Move Ix typeclass to GHC.IxBen Gamari2019-09-251-1/+1
| | | | | The `Ix` class seems rather orthogonal to its original home in `GHC.Arr`.
* Add support for bitreverse primopAlexandre2019-04-011-0/+35
| | | | | | This commit includes the necessary changes in code and documentation to support a primop that reverses a word's bits. It also includes a test.
* Compile count{Leading,Trailing}Zeros to corresponding x86_64 instructions ↵Dmitry Ivanov2019-01-301-0/+13
| | | | | | | under -mbmi2 This works similarly to existing implementation for popCount. Trac ticket: #16086.
* Revert "Batch merge"Ben Gamari2019-01-301-13/+0
| | | | This reverts commit 76c8fd674435a652c75a96c85abbf26f1f221876.
* Batch mergeBen Gamari2019-01-301-0/+13
|
* Error out of invalid Int/Word bit shiftsAlec Theriault2019-01-231-10/+30
| | | | | | | | | | | | | Although the Haddock's for `shiftL` and `shiftR` do require the number of bits to be non-negative, we should still check this before calling out to primitives (which also have undefined behaviour for negative bit shifts). If a user _really_ wants to bypass checks that the number of bits is sensible, they already have the aptly-named `unsafeShiftL`/`unsafeShiftR` at their disposal. See #16111.
* Remove OPTIONS_HADDOCK hide in favour for not-homeAdam Sandberg Eriksson2019-01-061-1/+1
| | | | GHC Trac Issues: #15447
* Built-in Natural literals in CoreSylvain Henry2018-06-151-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for built-in Natural literals in Core. - Replace MachInt,MachWord, LitInteger, etc. with a single LitNumber constructor with a LitNumType field - Support built-in Natural literals - Add desugar warning for negative literals - Move Maybe(..) from GHC.Base to GHC.Maybe for module dependency reasons This patch introduces only a few rules for Natural literals (compared to Integer's rules). Factorization of the built-in rules for numeric literals will be done in another patch as this one is already big to review. Test Plan: validate test build with integer-simple Reviewers: hvr, bgamari, goldfire, Bodigrim, simonmar Reviewed By: bgamari Subscribers: phadej, simonpj, RyanGlScott, carter, hsyl20, rwbarton, thomie GHC Trac Issues: #14170, #14465 Differential Revision: https://phabricator.haskell.org/D4212
* GHC.Word: Move Read instances to GHC.ReadErik de Castro Lopo2017-03-171-21/+0
| | | | | | | | | | | | Test Plan: Validate Reviewers: hvr, austin, bgamari Reviewed By: hvr Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3353
* Add @since annotations to base instancesSeraphime Kirkovski2016-06-061-0/+54
| | | | | | | | | | | | | | | | | | Add @since annotations to instances in `base`. Test Plan: * ./validate # some commets shouldn't break the build * review the annotations for absurdities. Reviewers: ekmett, goldfire, RyanGlScott, austin, hvr, bgamari Reviewed By: RyanGlScott, hvr, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2277 GHC Trac Issues: #11767
* Defer inlining of Ord methodsBen Gamari2016-03-301-13/+87
| | | | | | This performs the same refactoring performed in D1980 for Eq on Ord, rewriting the class operations in terms of monomorphic helpers than can be reliably matched in rewrite rules.
* base: Fix GHC.Word and GHC.Int on 32-bit platformsBen Gamari2016-03-251-2/+2
| | | | | | | Due to a cut-and-paste error D1980 (#11688) broke 32-bit platforms. This should fix it. See #11750.
* Defer inlining of Eq for primitive typesBen Gamari2016-03-241-7/+70
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This is one solution to #11688, wherein (==) was inlined to soon defeating a rewrite rule provided by bytestring. Since the RHSs of Eq's methods are simple, there is little to be gained and much to be lost by inlining them early. For instance, the bytestring library provides, ```lang=haskell break :: (Word8 -> Bool) -> ByteString -> (ByteString, ByteString) breakByte :: Word8 -> ByteString -> (ByteString, ByteString) ``` and a rule ``` forall x. break ((==) x) = breakByte x ``` since `breakByte` implments an optimized version of `break (== x)` for known `x :: Word8`. If we allow `(==)` to be inlined too early, we will prevent this rule from firing. This was the cause of #11688. This patch just defers the `Eq` methods, although it's likely worthwhile giving `Ord` this same treatment. This regresses compiler allocations for T9661 by about 8% due to the additional inlining that we now require the simplifier to perform. Updates the `bytestring` submodule to include updated rewrite rules which match on `eqWord8` instead of `(==)`. Test Plan: * Validate, examine performance impact Reviewers: simonpj, hvr, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1980 GHC Trac Issues: #11688
* Convert `/Since: .../` to new `@since ...` syntaxHerbert Valerio Riedel2014-12-161-3/+3
| | | | | | Starting with Haddock 2.16 there's a new built-in support for since-annotations Note: This exposes a bug in the `@since` implementation (see e.g. `Data.Bits`)
* Refactor module imports in baseHerbert Valerio Riedel2014-10-191-1/+0
| | | | | | | | | | This commit removes a couple of {-# OPTIONS_GHC -fno-warn-unused-imports #-} by cleaning up the imports, as well as ensuring that all modules in the GHC.* hierarchy avoid importing the `Prelude` module to clean-up the import graph a bit.
* Remove a few redundant `.hs-boot` filesHerbert Valerio Riedel2014-10-111-1/+0
| | | | | | | | There don't seem to be any corresponding `{-# SOURCE #-}` for the removed `.hs-boot`-files anymore (if there ever was any in the first place). This also removes a commented out `{-# SOURCE #-}` import which turns up when grepping the source for `{-# SOURCE #-}` occurences.
* Add `FiniteBits(count{Leading,Trailing}Zeros)`Herbert Valerio Riedel2014-08-311-0/+8
| | | | | | | | | | | | | | | | | | | This exposes the newly added CLZ/CTZ primops from e0c1767d0ea8d12e0a4badf43682a08784e379c6 (re #9340) via two new methods `countLeadingZeros` and `countTrailingZeros` in the `Data.Bits.FiniteBits` class. The original proposal can be found at http://www.haskell.org/pipermail/libraries/2014-August/023567.html Test Plan: successful validate Reviewers: ekmett, tibbe GHC Trac Issues: #9532 Differential Revision: https://phabricator.haskell.org/D158
* Remove obsolete pre-Haddock-2 `#hide` pragmasHerbert Valerio Riedel2013-09-231-1/+0
| | | | | | | | | | | | The now obsolete (and redundant) `#hide` pragmas have been superseded by `{-# OPTIONS_HADDOCK hide #-}` pragmas which are used by most of the affected modules anyway. This commit also adds proper `{-# OPTIONS_HADDOCK hide #-}` pragmas to `GHC.Desugar` and `GHC.IO.Encoding.Iconv` which had only the ineffective `#hide` annotation. Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Add Haddock `/Since: 4.7.0.0/` comments to new symbolsHerbert Valerio Riedel2013-09-211-0/+9
| | | | | | | | | | | | | | | | | | These annotations were added in such a way, that the line {{{ /Since: 4.7.0.0/ }}} represents the last paragraph of the Haddock comment. Maybe Haddock will have support for this meta-syntax at some point, and be able to inherited the since-version property to the children of an annotated symbol and display the since-version property in the rendered documentation only in cases when it's not visually obvious (for instance, when re-exporting documentation strings). Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
* Follow changes in comparison primops (see #6135)Jan Stolarek2013-09-181-40/+40
|
* byteSwap16/32: Narrow the result to 16/32 bitsReid Barton2013-09-151-2/+2
| | | | | | | | According to primops.txt.pp, the BSwap16Op and BSwap32Op primops leave the higher bytes of their results undefined. We must clear those higher bytes here before storing the result in a Word16/32. Signed-off-by: Austin Seipp <austin@well-typed.com>
* Expose new Word operation to swap endianness for Word{16,32,64}Austin Seipp2013-07-171-1/+17
| | | | | Authored-by: Vincent Hanquez <tab@snarc.org> Signed-off-by: Austin Seipp <aseipp@pobox.com>
* Revert "expose new Word operation to swap endianness for Word{16,32,64}"Simon Peyton Jones2013-06-111-17/+1
| | | | This reverts commit 3ef0f91d4e9a3649581557ec4ba663db4306d7d5.
* expose new Word operation to swap endianness for Word{16,32,64}Ian Lynagh2013-06-091-1/+17
| | | | Patch from Vincent Hanquez.
* Re-jig SOURCE importsSimon Peyton Jones2013-06-061-1/+1
| | | | | | | | | | | | | | * Do not have have an hs-boot file for Data.Typeable * Instead make all the loops go through GHC.Err (just a couple of magic functions) GHC.Exception (some non-exceptional functions) The main idea is a) don't involve classes in the hs-boot world b) loop through error cases where performance doesn't matter c) be careful not to SOURCE import things that are bottom, unless MkCore knows about them in eRROR_IDS, so that we see their strictness
* Change rules for RealFrac methods to pointfree, so that they can also fire ↵Daniel Fischer2013-02-131-38/+38
| | | | in pointfree use.
* Add bitSizeMaybe to Bits, and add FiniteBits classIan Lynagh2012-09-231-5/+23
|
* Move the Word type from base to ghc-primIan Lynagh2012-05-211-134/+0
|