summaryrefslogtreecommitdiff
path: root/testsuite/tests/codeGen
diff options
context:
space:
mode:
authorPeter Trommler <ptrommler@acm.org>2015-04-07 09:08:29 -0500
committerAustin Seipp <austin@well-typed.com>2015-04-07 09:13:09 -0500
commit4f8e34822f18cf3d31414676f900b3714367d38e (patch)
tree73f8266e3acfd3b9d2366fa57c79bed1eb6c7418 /testsuite/tests/codeGen
parent553c5182156c5e4c15e3bd1c17c6d83a95a6c408 (diff)
downloadhaskell-4f8e34822f18cf3d31414676f900b3714367d38e.tar.gz
Replace endian test by 64-bit word access in T7600
In commit 3f30912f an include `ghcconfig.h` was added for `WORDS_BIGENDIAN`. Converting the floating point array to a `Word64` array avoids using the preprocessor altogether and leads to smaller code. Fixes #10239 Reviewed By: rwbarton, austin Differential Revision: https://phabricator.haskell.org/D795 GHC Trac Issues: #10239
Diffstat (limited to 'testsuite/tests/codeGen')
-rw-r--r--testsuite/tests/codeGen/should_run/T7600_A.hs46
1 files changed, 12 insertions, 34 deletions
diff --git a/testsuite/tests/codeGen/should_run/T7600_A.hs b/testsuite/tests/codeGen/should_run/T7600_A.hs
index df31b839ee..6338c9d013 100644
--- a/testsuite/tests/codeGen/should_run/T7600_A.hs
+++ b/testsuite/tests/codeGen/should_run/T7600_A.hs
@@ -1,6 +1,5 @@
-- !!! Bug # 7600.
-- See file T7600 for main description.
-{-# LANGUAGE CPP #-}
module T7600_A (test_run) where
import Control.Monad.ST
@@ -12,8 +11,6 @@ import Numeric
import GHC.Float
-#include "ghcconfig.h"
-
-- Test run
test_run :: Float -> Double -> IO ()
test_run float_number double_number = do
@@ -41,45 +38,26 @@ widen' :: Float -> Double
{-# NOINLINE widen' #-}
widen' = float2Double
-doubleToBytes :: Double -> [Int]
-doubleToBytes d
+doubleToWord64 :: Double -> Word64
+doubleToWord64 d
= runST (do
- arr <- newArray_ ((0::Int),7)
+ arr <- newArray_ ((0::Int),0)
writeArray arr 0 d
- arr <- castDoubleToWord8Array arr
- i0 <- readArray arr 0
- i1 <- readArray arr 1
- i2 <- readArray arr 2
- i3 <- readArray arr 3
- i4 <- readArray arr 4
- i5 <- readArray arr 5
- i6 <- readArray arr 6
- i7 <- readArray arr 7
- return (map fromIntegral [i0,i1,i2,i3,i4,i5,i6,i7])
+ arr <- castDoubleToWord64Array arr
+ readArray arr 0
)
-castFloatToWord8Array :: STUArray s Int Float -> ST s (STUArray s Int Word8)
-castFloatToWord8Array = castSTUArray
+castFloatToWord64Array :: STUArray s Int Float -> ST s (STUArray s Int Word64)
+castFloatToWord64Array = castSTUArray
-castDoubleToWord8Array :: STUArray s Int Double -> ST s (STUArray s Int Word8)
-castDoubleToWord8Array = castSTUArray
+castDoubleToWord64Array :: STUArray s Int Double -> ST s (STUArray s Int Word64)
+castDoubleToWord64Array = castSTUArray
dToStr :: Double -> String
dToStr d
- = let bs = doubleToBytes d
- hex d' = case showHex d' "" of
- [] -> error "dToStr: too few hex digits for float"
- [x] -> ['0',x]
- [x,y] -> [x,y]
- _ -> error "dToStr: too many hex digits for float"
+ = let bs = doubleToWord64 d
+ hex d' = showHex d' ""
- str = map toUpper $ concat . fixEndian . (map hex) $ bs
+ str = map toUpper $ hex bs
in "0x" ++ str
-fixEndian :: [a] -> [a]
-#ifdef WORDS_BIGENDIAN
-fixEndian = id
-#else
-fixEndian = reverse
-#endif
-