Commit d9bdff60 authored by KevinBuhr's avatar KevinBuhr Committed by Marge Bot

stg_floatToWord32zh: zero-extend the Word32 (#16617)

The primop stgFloatToWord32 was sign-extending the 32-bit word, resulting
in weird negative Word32s.  Zero-extend them instead.

Closes #16617.
parent ed5f858b
Pipeline #5602 passed with stages
in 344 minutes and 23 seconds
......@@ -159,14 +159,19 @@
#define BYTES_TO_WDS(n) ((n) / SIZEOF_W)
#define ROUNDUP_BYTES_TO_WDS(n) (((n) + SIZEOF_W - 1) / SIZEOF_W)
/* TO_W_(n) converts n to W_ type from a smaller type */
/*
* TO_W_(n) and TO_ZXW_(n) convert n to W_ type from a smaller type,
* with and without sign extension respectively
*/
#if SIZEOF_W == 4
#define TO_I64(x) %sx64(x)
#define TO_W_(x) %sx32(x)
#define TO_ZXW_(x) %zx32(x)
#define HALF_W_(x) %lobits16(x)
#elif SIZEOF_W == 8
#define TO_I64(x) (x)
#define TO_W_(x) %sx64(x)
#define TO_ZXW_(x) %zx64(x)
#define HALF_W_(x) %lobits32(x)
#endif
......
......@@ -61,7 +61,8 @@ stg_floatToWord32zh(F_ f)
reserve 1 = ptr {
F_[ptr] = f;
w = TO_W_(I32[ptr]);
// Fix #16617: use zero-extending (TO_ZXW_) here
w = TO_ZXW_(I32[ptr]);
}
return (w);
......
import GHC.Float
main :: IO ()
main = do
-- As per #16617, Word32s should be non-negative
print $ castFloatToWord32 (-1)
print $ toInteger (castFloatToWord32 (-1)) > 0
-- For completeness, so should Word64s
print $ castDoubleToWord64 (-1)
print $ toInteger (castDoubleToWord64 (-1)) > 0
3212836864
True
13830554455654793216
True
......@@ -194,3 +194,4 @@ test('T15892',
# happen, so -G1 -A32k:
extra_run_opts('+RTS -G1 -A32k -RTS') ],
compile_and_run, ['-O'])
test('T16617', normal, compile_and_run, [''])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment