summaryrefslogtreecommitdiff
path: root/compiler/GHC/CmmToAsm/X86/Ppr.hs
diff options
context:
space:
mode:
authorPeter Trommler <ptrommler@acm.org>2020-07-10 12:10:33 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-08-26 10:42:30 -0400
commitfcb10b6c69e388d8c6e777baf39920e2cc694501 (patch)
tree833e6acb1b94c4a5000d3f9030ce6e5713e9eb80 /compiler/GHC/CmmToAsm/X86/Ppr.hs
parentdc476a5040cdc64c177de0f78edaafec0972cff4 (diff)
downloadhaskell-fcb10b6c69e388d8c6e777baf39920e2cc694501.tar.gz
PPC and X86: Portable printing of IEEE floats
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. This was brought up in #18431 by @hsyl20.
Diffstat (limited to 'compiler/GHC/CmmToAsm/X86/Ppr.hs')
-rw-r--r--compiler/GHC/CmmToAsm/X86/Ppr.hs17
1 files changed, 4 insertions, 13 deletions
diff --git a/compiler/GHC/CmmToAsm/X86/Ppr.hs b/compiler/GHC/CmmToAsm/X86/Ppr.hs
index b5fb852512..22a8e66f2f 100644
--- a/compiler/GHC/CmmToAsm/X86/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/X86/Ppr.hs
@@ -423,9 +423,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 '-'
@@ -514,13 +513,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
@@ -558,9 +552,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