Skip to content

Floating point with -O and -fasm is broken

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

where log_x Double
log_x = logBase 2 (fromIntegral (max 1 x))

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).

Trac metadata
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
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information