Pad static literals to word size in the code generator
authorSimon Marlow <simonmar@microsoft.com>
Thu, 8 Nov 2007 13:28:42 +0000 (13:28 +0000)
committerSimon Marlow <simonmar@microsoft.com>
Thu, 8 Nov 2007 13:28:42 +0000 (13:28 +0000)
compiler/cmm/PprC.hs
compiler/codeGen/CgHeapery.lhs

index 47a2315..c7d0cf1 100644 (file)
@@ -145,7 +145,6 @@ pprTop top@(CmmData _section (CmmDataLabel lbl : lits)) =
 -- these shouldn't appear?
 pprTop (CmmData _ _) = panic "PprC.pprTop: can't handle this data"
 
-
 -- --------------------------------------------------------------------------
 -- BasicBlocks are self-contained entities: they always end in a jump.
 --
@@ -426,7 +425,13 @@ pprLit1 other = pprLit other
 pprStatics :: [CmmStatic] -> [SDoc]
 pprStatics [] = []
 pprStatics (CmmStaticLit (CmmFloat f F32) : rest) 
+  -- floats are padded to a word, see #1852
+  | wORD_SIZE == 8, CmmStaticLit (CmmInt 0 I32) : rest' <- rest
+  = pprLit1 (floatToWord f) : pprStatics rest'
+  | wORD_SIZE == 4
   = pprLit1 (floatToWord f) : pprStatics rest
+  | otherwise
+  = pprPanic "pprStatics: float" (vcat (map (\(CmmStaticLit l) -> ppr (cmmLitRep l)) rest))
 pprStatics (CmmStaticLit (CmmFloat f F64) : rest)
   = map pprLit1 (doubleToWords f) ++ pprStatics rest
 pprStatics (CmmStaticLit (CmmInt i I64) : rest)
index cef14cf..9cb1bb4 100644 (file)
@@ -231,7 +231,7 @@ mkStaticClosure :: CLabel -> CostCentreStack -> [CmmLit]
 mkStaticClosure info_lbl ccs payload padding_wds static_link_field saved_info_field
   =  [CmmLabel info_lbl]
   ++ variable_header_words
-  ++ payload
+  ++ concatMap padLitToWord payload
   ++ padding_wds
   ++ static_link_field
   ++ saved_info_field
@@ -241,6 +241,17 @@ mkStaticClosure info_lbl ccs payload padding_wds static_link_field saved_info_fi
        ++ staticParHdr
        ++ staticProfHdr ccs
        ++ staticTickyHdr
+
+padLitToWord :: CmmLit -> [CmmLit]
+padLitToWord lit = lit : padding pad_length
+  where rep = cmmLitRep lit
+        pad_length = wORD_SIZE - machRepByteWidth rep :: Int
+
+        padding n | n <= 0 = []
+                  | n `rem` 2 /= 0 = CmmInt 0 I8  : padding (n-1)
+                  | n `rem` 4 /= 0 = CmmInt 0 I16 : padding (n-2)
+                  | n `rem` 8 /= 0 = CmmInt 0 I32 : padding (n-4)
+                  | otherwise      = CmmInt 0 I64 : padding (n-8)
 \end{code}
 
 %************************************************************************