cb4164e
From 35a897782b6b0a252da7fdcf4921198ad4e1d96c Mon Sep 17 00:00:00 2001
cb4164e
From: James Clarke <jrtc27@jrtc27.com>
cb4164e
Date: Thu, 22 Nov 2018 11:55:17 -0500
cb4164e
Subject: [PATCH] UNREG: PprC: Add support for adjacent floats
cb4164e
cb4164e
When two 32-bit floats are adjacent for a 64-bit target, there is no
cb4164e
padding between them to force alignment, so we must combine their bit
cb4164e
representations into a single word.
cb4164e
cb4164e
Reviewers: bgamari, simonmar
cb4164e
cb4164e
Reviewed By: simonmar
cb4164e
cb4164e
Subscribers: rwbarton, carter
cb4164e
cb4164e
GHC Trac Issues: #15853
cb4164e
cb4164e
Differential Revision: https://phabricator.haskell.org/D5306
cb4164e
---
cb4164e
 compiler/cmm/PprC.hs | 24 +++++++++++++++++++++++-
cb4164e
 1 file changed, 23 insertions(+), 1 deletion(-)
cb4164e
cb4164e
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
cb4164e
index 17fef7fc97..6ebfd20291 100644
cb4164e
--- a/compiler/cmm/PprC.hs
cb4164e
+++ b/compiler/cmm/PprC.hs
cb4164e
@@ -512,9 +512,12 @@ pprLit1 other = pprLit other
cb4164e
 pprStatics :: DynFlags -> [CmmStatic] -> [SDoc]
cb4164e
 pprStatics _ [] = []
cb4164e
 pprStatics dflags (CmmStaticLit (CmmFloat f W32) : rest)
cb4164e
-  -- floats are padded to a word by padLitToWord, see #1852
cb4164e
+  -- odd numbers of floats are padded to a word by mkVirtHeapOffsetsWithPadding
cb4164e
   | wORD_SIZE dflags == 8, CmmStaticLit (CmmInt 0 W32) : rest' <- rest
cb4164e
   = pprLit1 (floatToWord dflags f) : pprStatics dflags rest'
cb4164e
+  -- adjacent floats aren't padded but combined into a single word
cb4164e
+  | wORD_SIZE dflags == 8, CmmStaticLit (CmmFloat g W32) : rest' <- rest
cb4164e
+  = pprLit1 (floatPairToWord dflags f g) : pprStatics dflags rest'
cb4164e
   | wORD_SIZE dflags == 4
cb4164e
   = pprLit1 (floatToWord dflags f) : pprStatics dflags rest
cb4164e
   | otherwise
cb4164e
@@ -1270,6 +1273,25 @@ floatToWord dflags r
cb4164e
              , wORDS_BIGENDIAN dflags    = 32
cb4164e
              | otherwise                 = 0
cb4164e
 
cb4164e
+floatPairToWord :: DynFlags -> Rational -> Rational -> CmmLit
cb4164e
+floatPairToWord dflags r1 r2
cb4164e
+  = runST (do
cb4164e
+        arr <- newArray_ ((0::Int),1)
cb4164e
+        writeArray arr 0 (fromRational r1)
cb4164e
+        writeArray arr 1 (fromRational r2)
cb4164e
+        arr' <- castFloatToWord32Array arr
cb4164e
+        w32_1 <- readArray arr' 0
cb4164e
+        w32_2 <- readArray arr' 1
cb4164e
+        return (pprWord32Pair w32_1 w32_2)
cb4164e
+    )
cb4164e
+    where pprWord32Pair w32_1 w32_2
cb4164e
+              | wORDS_BIGENDIAN dflags =
cb4164e
+                  CmmInt ((shiftL i1 32) .|. i2) W64
cb4164e
+              | otherwise =
cb4164e
+                  CmmInt ((shiftL i2 32) .|. i1) W64
cb4164e
+              where i1 = toInteger w32_1
cb4164e
+                    i2 = toInteger w32_2
cb4164e
+
cb4164e
 doubleToWords :: DynFlags -> Rational -> [CmmLit]
cb4164e
 doubleToWords dflags r
cb4164e
   = runST (do
cb4164e
-- 
cb4164e
2.19.2
cb4164e