[GHC] #10521: Wrong results in strict Word8 storage on x64
GHC
ghc-devs at haskell.org
Mon Jun 15 12:43:33 UTC 2015
#10521: Wrong results in strict Word8 storage on x64
-------------------------------------+-------------------------------------
Reporter: VincentBerthoux2 | Owner:
Type: bug | Status: new
Priority: high | Milestone: 7.10.2
Component: Compiler | Version: 7.10.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: x86_64
Type of failure: Incorrect result | (amd64)
at runtime | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Revisions:
-------------------------------------+-------------------------------------
Changes (by VincentBerthoux2):
* priority: normal => high
* milestone: => 7.10.2
Old description:
> The following snippet produce two different results in function of the
> compiler platform used:
>
> {{{#!hs
> import Data.Word( Word8 )
>
> -- removing the bang patterns on V definition makes
> -- the problem go away.
> data V = V !Word8 !Word8 deriving Show
>
> toV :: Float -> V
> toV d = V (truncate $ d * coeff) (fromIntegral $ exponent d + 128) where
> coeff = significand d * 255.9999 / d
>
> main :: IO ()
> main =
> print $ map toV [ 3.56158e-2, 0.7415215, 0.5383201, 0.1289829,
> 0.45520145 ]
> }}}
>
> On GHC 7.10.1 x86 (under windows and Linux) the output is:
> {{{
> [V 145 124,V 189 128,V 137 128,V 132 126,V 233 127]
> }}}
>
> On GHC 7.10.1 x64 (under windows and Linux), the (invalid) output is:
> {{{
> [V 0 124,V 0 128,V 0 128,V 0 126,V 0 127]
> }}}
>
> The bug appear at the following optimisation levels:
>
> - {{{-O1}}}
> - {{{-O2}}}
> - {{{-O3}}}
>
> the results are the same at {{{-O0}}}
>
> This bug was discovered in a bug report in the library JuicyPixels
> [https://github.com/Twinside/Juicy.Pixels/issues/98].
New description:
The following snippet produce two different results in function of the
compiler platform used:
{{{#!hs
import Data.Word( Word8 )
-- removing the bang patterns on V definition makes
-- the problem go away.
data V = V !Word8 !Word8 deriving Show
toV :: Float -> V
toV d = V (truncate $ d * coeff) (fromIntegral $ exponent d + 128) where
coeff = significand d * 255.9999 / d
main :: IO ()
main =
print $ map toV [ 3.56158e-2, 0.7415215, 0.5383201, 0.1289829,
0.45520145 ]
}}}
On GHC 7.10.1 x86 (under windows and Linux) the output is:
{{{
[V 145 124,V 189 128,V 137 128,V 132 126,V 233 127]
}}}
On GHC 7.10.1 x64 (under windows and Linux), the (invalid) output is:
{{{
[V 0 124,V 0 128,V 0 128,V 0 126,V 0 127]
}}}
The bug appear at the following optimisation levels:
- {{{-O1}}}
- {{{-O2}}}
- {{{-O3}}}
the results are the same at {{{-O0}}}
This bug was discovered in a bug report in the library JuicyPixels
[https://github.com/Twinside/Juicy.Pixels/issues/98].
The same problem has been seen with GHC 7.10.2 RC1
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10521#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list