GHC issueshttps://gitlab.haskell.org/ghc/ghc/-/issues2019-07-07T19:16:17Zhttps://gitlab.haskell.org/ghc/ghc/-/issues/921Floating point with -O and -fasm is broken2019-07-07T19:16:17ZguestFloating point with -O and -fasm is brokenI have some simple floating-point code that fails badly when you compile it with -O and -fasm on x86_64. Here is the program:
log2 x = ceiling log_x
<table><tr><th>where log_x </th>
<td>Double</td></tr>
<tr><td></td>
<td>log_x = logBas...I have some simple floating-point code that fails badly when you compile it with -O and -fasm on x86_64. Here is the program:
log2 x = ceiling log_x
<table><tr><th>where log_x </th>
<td>Double</td></tr>
<tr><td></td>
<td>log_x = logBase 2 (fromIntegral (max 1 x))</td></tr></table>
vals = \[1, 2, 17, 259, 1000, 10000,
2\^30 + 9000, 2\^31 - 1, 2\^31, 2\^31 + 1,
> 2\^32 - 1, 2\^32, 2\^32 + 1\]
main :: IO ()
main = putStrLn (show (map log2 vals))
The result should be: \[0,1,5,9,10,14,31,31,32,32,32,32,33\]
With -O and -fasm on x86_64 the last five values are corrupted (four very large numbers I'm not going to paste here, followed by 0).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ----------------- |
| Version | 6.4.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (NCG) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | ravi@bluespec.com |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Floating point with -O and -fasm is broken","status":"New","operating_system":"","component":"Compiler (NCG)","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"6.4.1","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":["ravi@bluespec.com"],"type":"Bug","description":"I have some simple floating-point code that fails badly when you compile it with -O and -fasm on x86_64. Here is the program:\r\n\r\nlog2 x = ceiling log_x\r\n where log_x :: Double\r\n log_x = logBase 2 (fromIntegral (max 1 x))\r\n\r\nvals = [1, 2, 17, 259, 1000, 10000, \r\n 2^30 + 9000, 2^31 - 1, 2^31, 2^31 + 1,\r\n 2^32 - 1, 2^32, 2^32 + 1]\r\n\r\nmain :: IO ()\r\nmain = putStrLn (show (map log2 vals))\r\n\r\nThe result should be: [0,1,5,9,10,14,31,31,32,32,32,32,33]\r\n\r\nWith -O and -fasm on x86_64 the last five values are corrupted (four very large numbers I'm not going to paste here, followed by 0).","type_of_failure":"OtherFailure","blocking":[]} -->6.6.1Ian Lynagh <igloo@earth.li>Ian Lynagh <igloo@earth.li>