summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Trommler <ptrommler@acm.org>2020-07-10 12:10:33 +0200
committerPeter Trommler <ptrommler@acm.org>2020-07-10 12:10:33 +0200
commit9a5b3775b70f2144dd2e68db98937d3ea024216f (patch)
tree7934fd9e85051c941a95b35956a19b5f1f368a19
parentcf6aaf1eb4b13b19baf36cdb855bc41ebb6fde62 (diff)
downloadhaskell-wip/T18431.tar.gz
PPC and X86: Portable printing of IEEE floatswip/T18431
GNU as and the AIX assembler support floating point literals. SPARC seems to have support too but I cannot test on SPARC. Curiously, `doubleToBytes` is also used in the LLVM backend. To avoid endianness issues when cross-compiling float and double literals are printed as C-style floating point values. The assembler then takes care of memory layout and endianness.
-rw-r--r--compiler/GHC/CmmToAsm/PPC/Ppr.hs14
-rw-r--r--compiler/GHC/CmmToAsm/Ppr.hs5
-rw-r--r--compiler/GHC/CmmToAsm/X86/Ppr.hs17
3 files changed, 9 insertions, 27 deletions
diff --git a/compiler/GHC/CmmToAsm/PPC/Ppr.hs b/compiler/GHC/CmmToAsm/PPC/Ppr.hs
index bb8d412f52..eef37f0db7 100644
--- a/compiler/GHC/CmmToAsm/PPC/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/PPC/Ppr.hs
@@ -238,9 +238,8 @@ pprImm (ImmInteger i) = integer i
pprImm (ImmCLbl l) = ppr l
pprImm (ImmIndex l i) = ppr l <> char '+' <> int i
pprImm (ImmLit s) = s
-
-pprImm (ImmFloat _) = text "naughty float immediate"
-pprImm (ImmDouble _) = text "naughty double immediate"
+pprImm (ImmFloat f) = float $ fromRational f
+pprImm (ImmDouble d) = double $ fromRational d
pprImm (ImmConstantSum a b) = pprImm a <> char '+' <> pprImm b
pprImm (ImmConstantDiff a b) = pprImm a <> char '-'
@@ -338,13 +337,8 @@ pprDataItem platform lit
<> int (fromIntegral (fromIntegral x :: Word32))]
- ppr_item FF32 (CmmFloat r _)
- = let bs = floatToBytes (fromRational r)
- in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs
-
- ppr_item FF64 (CmmFloat r _)
- = let bs = doubleToBytes (fromRational r)
- in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs
+ ppr_item FF32 _ = [text "\t.float\t" <> pprImm imm]
+ ppr_item FF64 _ = [text "\t.double\t" <> pprImm imm]
ppr_item _ _
= panic "PPC.Ppr.pprDataItem: no match"
diff --git a/compiler/GHC/CmmToAsm/Ppr.hs b/compiler/GHC/CmmToAsm/Ppr.hs
index 405bab9fff..9c8a19cee7 100644
--- a/compiler/GHC/CmmToAsm/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/Ppr.hs
@@ -9,8 +9,6 @@
-----------------------------------------------------------------------------
module GHC.CmmToAsm.Ppr (
- castFloatToWord8Array,
- castDoubleToWord8Array,
floatToBytes,
doubleToBytes,
pprASCII,
@@ -43,8 +41,6 @@ import qualified Data.ByteString as BS
import GHC.Exts
import GHC.Word
-
-
-- -----------------------------------------------------------------------------
-- Converting floating-point literals to integrals for printing
@@ -92,6 +88,7 @@ doubleToBytes d
return (map fromIntegral [i0,i1,i2,i3,i4,i5,i6,i7])
)
+
-- ---------------------------------------------------------------------------
-- Printing ASCII strings.
--
diff --git a/compiler/GHC/CmmToAsm/X86/Ppr.hs b/compiler/GHC/CmmToAsm/X86/Ppr.hs
index 49e4de8ad5..942e7a0858 100644
--- a/compiler/GHC/CmmToAsm/X86/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/X86/Ppr.hs
@@ -426,9 +426,8 @@ pprImm (ImmInteger i) = integer i
pprImm (ImmCLbl l) = ppr l
pprImm (ImmIndex l i) = ppr l <> char '+' <> int i
pprImm (ImmLit s) = s
-
-pprImm (ImmFloat _) = text "naughty float immediate"
-pprImm (ImmDouble _) = text "naughty double immediate"
+pprImm (ImmFloat f) = float $ fromRational f
+pprImm (ImmDouble d) = double $ fromRational d
pprImm (ImmConstantSum a b) = pprImm a <> char '+' <> pprImm b
pprImm (ImmConstantDiff a b) = pprImm a <> char '-'
@@ -517,13 +516,8 @@ pprDataItem config lit
ppr_item II16 _ = [text "\t.word\t" <> pprImm imm]
ppr_item II32 _ = [text "\t.long\t" <> pprImm imm]
- ppr_item FF32 (CmmFloat r _)
- = let bs = floatToBytes (fromRational r)
- in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs
-
- ppr_item FF64 (CmmFloat r _)
- = let bs = doubleToBytes (fromRational r)
- in map (\b -> text "\t.byte\t" <> pprImm (ImmInt b)) bs
+ ppr_item FF32 _ = [text "\t.float\t" <> pprImm imm]
+ ppr_item FF64 _ = [text "\t.double\t" <> pprImm imm]
ppr_item II64 _
= case platformOS platform of
@@ -561,9 +555,6 @@ pprDataItem config lit
_ ->
[text "\t.quad\t" <> pprImm imm]
- ppr_item _ _
- = panic "X86.Ppr.ppr_item: no match"
-
asmComment :: SDoc -> SDoc
asmComment c = whenPprDebug $ text "# " <> c