diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2017-04-12 14:09:49 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-04-12 14:53:06 -0400 |
commit | aa206346e6f12c9f88fdf051185741761ea88fbb (patch) | |
tree | 3963e016c48662f00cf5c53cf3d75af05322092d /testsuite | |
parent | bb3712bf772fecb965f56a356ccf61437d324dcf (diff) | |
download | haskell-aa206346e6f12c9f88fdf051185741761ea88fbb.tar.gz |
base: Implement bit casts between word and float types
Test Plan: Test on x86 and x86_64
Reviewers: duncan, trofi, simonmar, tibbe, hvr, austin, rwbarton,
bgamari
Reviewed By: duncan
Subscribers: Phyx, DemiMarie, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3358
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/codeGen/should_run/all.T | 2 | ||||
-rw-r--r-- | testsuite/tests/codeGen/should_run/castFloatWord.hs | 28 | ||||
-rw-r--r-- | testsuite/tests/codeGen/should_run/castFloatWord.stdout | 204 |
3 files changed, 234 insertions, 0 deletions
diff --git a/testsuite/tests/codeGen/should_run/all.T b/testsuite/tests/codeGen/should_run/all.T index 9f334cf298..6318341abb 100644 --- a/testsuite/tests/codeGen/should_run/all.T +++ b/testsuite/tests/codeGen/should_run/all.T @@ -155,4 +155,6 @@ test('T9577', [ unless(arch('x86_64') or arch('i386'),skip), when(opsys('darwin'), expect_broken(12937)), when(opsys('mingw32'), expect_broken(12965)), only_ways(['normal']) ], compile_and_run, ['']) + test('T13425', normal, compile_and_run, ['-O']) +test('castFloatWord', normal, compile_and_run, ['-dcmm-lint']) diff --git a/testsuite/tests/codeGen/should_run/castFloatWord.hs b/testsuite/tests/codeGen/should_run/castFloatWord.hs new file mode 100644 index 0000000000..9c10aa84fc --- /dev/null +++ b/testsuite/tests/codeGen/should_run/castFloatWord.hs @@ -0,0 +1,28 @@ +import Data.Bits +import GHC.Float +import GHC.Word +import Numeric + +main :: IO () +main = do + putStrLn "Float" + mapM_ print floats + putStrLn "\nDouble" + mapM_ print doubles + putStrLn "\nWord32" + mapM_ (printHex32 . castFloatToWord32) floats + putStrLn "\nWord64" + mapM_ (printHex64 . castDoubleToWord64) doubles + putStrLn "Done!" + +floats :: [Float] +floats = map castWord32ToFloat $ 0 : map (2^) [ 0 .. 31 ] + +doubles :: [Double] +doubles = map castWord64ToDouble $ 0 : map (2^) [ 0 .. 63 ] + +printHex32 :: Word32 -> IO () +printHex32 w = putStrLn $ "0x" ++ showHex (0xffffffff .&. w) "" + +printHex64 :: Word64 -> IO () +printHex64 w = putStrLn $ "0x" ++ showHex w "" diff --git a/testsuite/tests/codeGen/should_run/castFloatWord.stdout b/testsuite/tests/codeGen/should_run/castFloatWord.stdout new file mode 100644 index 0000000000..930f2fec02 --- /dev/null +++ b/testsuite/tests/codeGen/should_run/castFloatWord.stdout @@ -0,0 +1,204 @@ +Float +0.0 +1.0e-45 +3.0e-45 +6.0e-45 +1.1e-44 +2.2e-44 +4.5e-44 +9.0e-44 +1.8e-43 +3.59e-43 +7.17e-43 +1.435e-42 +2.87e-42 +5.74e-42 +1.148e-41 +2.2959e-41 +4.5918e-41 +9.1835e-41 +1.83671e-40 +3.67342e-40 +7.34684e-40 +1.469368e-39 +2.938736e-39 +5.877472e-39 +1.1754944e-38 +2.3509887e-38 +9.403955e-38 +1.5046328e-36 +3.85186e-34 +2.524355e-29 +1.0842022e-19 +2.0 +-0.0 + +Double +0.0 +5.0e-324 +1.0e-323 +2.0e-323 +4.0e-323 +8.0e-323 +1.6e-322 +3.16e-322 +6.3e-322 +1.265e-321 +2.53e-321 +5.06e-321 +1.012e-320 +2.0237e-320 +4.0474e-320 +8.095e-320 +1.61895e-319 +3.2379e-319 +6.4758e-319 +1.295163e-318 +2.590327e-318 +5.180654e-318 +1.036131e-317 +2.0722615e-317 +4.144523e-317 +8.289046e-317 +1.6578092e-316 +3.3156184e-316 +6.63123685e-316 +1.32624737e-315 +2.65249474e-315 +5.304989477e-315 +1.0609978955e-314 +2.121995791e-314 +4.243991582e-314 +8.487983164e-314 +1.69759663277e-313 +3.39519326554e-313 +6.7903865311e-313 +1.35807730622e-312 +2.716154612436e-312 +5.43230922487e-312 +1.086461844974e-311 +2.1729236899484e-311 +4.345847379897e-311 +8.691694759794e-311 +1.73833895195875e-310 +3.4766779039175e-310 +6.953355807835e-310 +1.390671161567e-309 +2.781342323134e-309 +5.562684646268003e-309 +1.1125369292536007e-308 +2.2250738585072014e-308 +4.450147717014403e-308 +1.7800590868057611e-307 +2.848094538889218e-306 +7.291122019556398e-304 +4.778309726736481e-299 +2.0522684006491881e-289 +3.785766995733679e-270 +1.2882297539194267e-231 +1.4916681462400413e-154 +2.0 +-0.0 + +Word32 +0x0 +0x1 +0x2 +0x4 +0x8 +0x10 +0x20 +0x40 +0x80 +0x100 +0x200 +0x400 +0x800 +0x1000 +0x2000 +0x4000 +0x8000 +0x10000 +0x20000 +0x40000 +0x80000 +0x100000 +0x200000 +0x400000 +0x800000 +0x1000000 +0x2000000 +0x4000000 +0x8000000 +0x10000000 +0x20000000 +0x40000000 +0x80000000 + +Word64 +0x0 +0x1 +0x2 +0x4 +0x8 +0x10 +0x20 +0x40 +0x80 +0x100 +0x200 +0x400 +0x800 +0x1000 +0x2000 +0x4000 +0x8000 +0x10000 +0x20000 +0x40000 +0x80000 +0x100000 +0x200000 +0x400000 +0x800000 +0x1000000 +0x2000000 +0x4000000 +0x8000000 +0x10000000 +0x20000000 +0x40000000 +0x80000000 +0x100000000 +0x200000000 +0x400000000 +0x800000000 +0x1000000000 +0x2000000000 +0x4000000000 +0x8000000000 +0x10000000000 +0x20000000000 +0x40000000000 +0x80000000000 +0x100000000000 +0x200000000000 +0x400000000000 +0x800000000000 +0x1000000000000 +0x2000000000000 +0x4000000000000 +0x8000000000000 +0x10000000000000 +0x20000000000000 +0x40000000000000 +0x80000000000000 +0x100000000000000 +0x200000000000000 +0x400000000000000 +0x800000000000000 +0x1000000000000000 +0x2000000000000000 +0x4000000000000000 +0x8000000000000000 +Done! |