[GHC] #9431: integer-gmp small Integer multiplication does two multiplications on x86
GHC
ghc-devs at haskell.org
Mon Aug 11 01:01:45 UTC 2014
#9431: integer-gmp small Integer multiplication does two multiplications on x86
-------------------------------------+-------------------------------------
Reporter: rwbarton | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.9
Keywords: | Operating System:
Architecture: Unknown/Multiple | Unknown/Multiple
Difficulty: Unknown | Type of failure:
Blocked By: | None/Unknown
Related Tickets: | Test Case:
| Blocking:
| Differential Revisions:
-------------------------------------+-------------------------------------
`timesInteger` begins thusly:
{{{
timesInteger :: Integer -> Integer -> Integer
timesInteger (S# i) (S# j) = if isTrue# (mulIntMayOflo# i j ==#
0#)
then S# (i *# j)
else -- ...
}}}
The x86 backend implements `mulIntMayOflo#` as a (word, word) -> double
word multiplication, followed by bit manipulation to test for overflow of
the low word. Then, if there was no overflow, on the next line we multiply
the operands again.
We should be able to do better here. We need a new primop that combines
`mulIntMayOflo#` with the actual multiplication result, at least in the
non-overflow case (though with some more work we might be able to turn the
double word result directly into a large Integer), and then we need to
update `timesInteger` to use it.
The LLVM backend probably has the same behavior, though it might be smart
enough to notice that the multiplication is repeated; I haven't checked
its assembly output.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9431>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list