[Git][ghc/ghc][master] stg_floatToWord32zh: zero-extend the Word32 (#16617)

Marge Bot gitlab at gitlab.haskell.org
Wed May 8 19:41:12 UTC 2019



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
d9bdff60 by Kevin Buhr at 2019-05-08T19:35:13Z
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.

- - - - -


5 changed files:

- includes/Cmm.h
- libraries/base/cbits/CastFloatWord.cmm
- + testsuite/tests/codeGen/should_run/T16617.hs
- + testsuite/tests/codeGen/should_run/T16617.stdout
- testsuite/tests/codeGen/should_run/all.T


Changes:

=====================================
includes/Cmm.h
=====================================
@@ -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
 


=====================================
libraries/base/cbits/CastFloatWord.cmm
=====================================
@@ -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);


=====================================
testsuite/tests/codeGen/should_run/T16617.hs
=====================================
@@ -0,0 +1,10 @@
+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


=====================================
testsuite/tests/codeGen/should_run/T16617.stdout
=====================================
@@ -0,0 +1,4 @@
+3212836864
+True
+13830554455654793216
+True


=====================================
testsuite/tests/codeGen/should_run/all.T
=====================================
@@ -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, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/d9bdff607e79a605197a13203ca9421153e8dd37

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/d9bdff607e79a605197a13203ca9421153e8dd37
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190508/43decbc4/attachment-0001.html>


More information about the ghc-commits mailing list