[GHC] #2269: Word type to Double or Float conversions are slower than Int conversions
GHC
ghc-devs at haskell.org
Mon Nov 24 19:10:37 UTC 2014
#2269: Word type to Double or Float conversions are slower than Int conversions
-------------------------------------+-------------------------------------
Reporter: dons | Owner: dons@…
Type: feature | Status: new
request | Milestone: 7.10.1
Priority: lowest | Version: 6.8.2
Component: Compiler | Keywords: rules,
Resolution: | performance, double
Operating System: | Architecture: Unknown/Multiple
Unknown/Multiple | Difficulty: Unknown
Type of failure: Runtime | Blocked By:
performance bug | Related Tickets:
Test Case: |
Blocking: |
Differential Revisions: |
-------------------------------------+-------------------------------------
Comment (by thomie):
Primops for word2Double and word2Float were added 2 years ago.
commit 2e8c769422740c001e0a247bfec61d4f78598582
{{{
Author: Johan Tibell <>
Date: Wed Dec 5 19:08:48 2012 -0800
Implement word2Float# and word2Double#
}}}
commit cd01e48fbc548ff8d81ab547108bfdde8a113cd7
{{{
Author: Johan Tibell <>
Date: Thu Dec 13 12:03:40 2012 -0800
Add test for word2Double# and word2Float#
}}}
commit a18cf9cbdfec08732f5b7e0c886a5d899a6a5998
{{{
Author: Johan Tibell <>
Date: Thu Dec 13 14:49:58 2012 -0800
Add fromIntegral/Word->Double and fromIntegral/Word-Float rules
}}}
commit 8cd4ced57dccc1f4f54d242982209ec61e145700
{{{
Author: Johan Tibell <>
Date: Tue Dec 18 14:40:02 2012 +0100
perf test for Word->Float/Double conversion
}}}
commit 6d5f25f5e0b33173fb2e7983cab40808c723f220
{{{
Author: Geoffrey Mainland <>
Date: Thu Jan 3 16:59:03 2013 +0000
Fix LLVM code generated for word2Float# and word2Double#.
}}}
commit 744035fdd4b882c17ef7c6e4439b9e7099e7ec3d
{{{
Author: Johan Tibell <>
Date: Mon Jan 7 21:35:07 2013 -0800
Fix Word2Float# test on 32-bit
}}}
The resulting core of the example from the description now looks the same
for `Word->Double` as for `Int->Double`.
{{{
$ cabal install vector
$ cat test.hs
{-# LANGUAGE CPP #-}
import Data.Vector as V
import Data.Word
main = print . V.sum
#ifdef WORD
. V.map (fromIntegral::Word->Double)
#else
. V.map (fromIntegral::Int->Double)
#endif
$ V.enumFromTo 0 100000000
$ ghc -ddump-simpl -dsuppress-all -O2 -fforce-recomp -DWORD test.hs -o
testWord
...
main_$s$wfoldlM'_loop
main_$s$wfoldlM'_loop =
\ sc_s5G6 sc1_s5G7 ->
case tagToEnum# (leWord# sc1_s5G7 (__word 100000000)) of _ {
False -> sc_s5G6;
True ->
main_$s$wfoldlM'_loop
(+## sc_s5G6 (word2Double# sc1_s5G7))
(plusWord# sc1_s5G7 (__word 1))
}
...
$ ghc -ddump-simpl -dsuppress-all -O2 -fforce-recomp -DINT test.hs -o
testInt
...
main_$s$wfoldlM'_loop
main_$s$wfoldlM'_loop =
\ sc_s5GQ sc1_s5GR ->
case tagToEnum# (<=# sc1_s5GR 100000000) of _ {
False -> sc_s5GQ;
True ->
main_$s$wfoldlM'_loop
(+## sc_s5GQ (int2Double# sc1_s5GR)) (+# sc1_s5GR 1)
}
}}}
But `testWord` is still 3 times slower than `testInt`.
{{{
$ time ./testWord
5.00000005e15
real 0m0.579s
user 0m0.575s
sys 0m0.003s
$ time ./testInt
5.00000005e15
real 0m0.196s
user 0m0.191s
sys 0m0.004s
}}}
As I can not easily explain this difference, I'll leave this ticket open
for now.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/2269#comment:16>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list