From 3d5d85e00f2a81efb62bb17f8e5db63fe5a49a61 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Mon, 28 Aug 2017 14:34:24 +0200 Subject: Optimisations (and array shift) Array points at data, not size stack alignment cross-platform liblang fast strlen --- X64.hs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'X64.hs') diff --git a/X64.hs b/X64.hs index b71012a..26c35dd 100644 --- a/X64.hs +++ b/X64.hs @@ -184,26 +184,31 @@ instance Stringifiable XRef where stringify (XMem _ _ (mult, _) _ _) | not (mult `elem` [0,1,2,4,8]) = error $ "Register multiplier has invalid value " ++ show mult ++ " in XMem" - stringify (XMem sz mr pair lab off) = - let res = intercalate "+" (catMaybes [goR1 mr, goPair pair, goLab lab]) ++ goOff off - in szword sz ++ " " ++ if null res then "[0]" else "[" ++ res ++ "]" + stringify x@(XMem sz _ _ _ _) = szword sz ++ " " ++ stringify_only_xmem_brackets x where szword 1 = "byte" szword 2 = "word" szword 4 = "dword" szword 8 = "qword" szword _ = undefined - goR1 Nothing = Nothing - goR1 (Just r) = Just $ stringify (XReg 8 r) - goPair (0, _) = Nothing - goPair (mult, r) = Just $ show mult ++ "*" ++ stringify (XReg 8 r) - goLab = id - goOff o | o > 0 = '+' : show o - | o < 0 = show o - | otherwise = "" stringify (XImm imm) = show imm +stringify_only_xmem_brackets :: XRef -> String +stringify_only_xmem_brackets (XMem _ mr pair lab off) = + let res = intercalate "+" (catMaybes [goR1 mr, goPair pair, goLab lab]) ++ goOff off + in if null res then "[0]" else "[" ++ res ++ "]" + where + goR1 Nothing = Nothing + goR1 (Just r) = Just $ stringify (XReg 8 r) + goPair (0, _) = Nothing + goPair (mult, r) = Just $ show mult ++ "*" ++ stringify (XReg 8 r) + goLab = id + goOff o | o > 0 = '+' : show o + | o < 0 = show o + | otherwise = "" +stringify_only_xmem_brackets _ = undefined + instance Stringifiable Reg where stringify (Reg x) = stringify x instance Stringifiable Mem where stringify (Mem x) = stringify x instance Stringifiable Imm where stringify (Imm x) = stringify x @@ -235,7 +240,7 @@ instance Stringifiable CondCode where instance Stringifiable Ins where stringify (MOV a b) = "mov " ++ stringify a ++ ", " ++ stringify b stringify (MOVi a b) = "mov " ++ stringify a ++ ", " ++ stringify b - stringify (LEA a b) = "lea " ++ stringify a ++ ", " ++ stringify b + stringify (LEA a (Mem b)) = "lea " ++ stringify a ++ ", " ++ stringify_only_xmem_brackets b stringify (MOVSX a b@(RegMem bx)) = case compare (xrefGetSize bx) 4 of EQ -> "movsxd " ++ stringify a ++ ", " ++ stringify b LT -> "movsx " ++ stringify a ++ ", " ++ stringify b -- cgit v1.2.3-70-g09d2