More CPP removal: pprDynamicLinkerAsmLabel in CLabel
[ghc.git] / compiler / nativeGen / SPARC / CodeGen / CondCode.hs
1
2 module SPARC.CodeGen.CondCode (
3 getCondCode,
4 condIntCode,
5 condFltCode
6 )
7
8 where
9
10 import {-# SOURCE #-} SPARC.CodeGen.Gen32
11 import SPARC.CodeGen.Base
12 import SPARC.Instr
13 import SPARC.Regs
14 import SPARC.Cond
15 import SPARC.Imm
16 import SPARC.Base
17 import NCGMonad
18 import Size
19
20 import OldCmm
21
22 import DynFlags
23 import OrdList
24 import Outputable
25
26
27 getCondCode :: CmmExpr -> NatM CondCode
28 getCondCode (CmmMachOp mop [x, y])
29 =
30 case mop of
31 MO_F_Eq W32 -> condFltCode EQQ x y
32 MO_F_Ne W32 -> condFltCode NE x y
33 MO_F_Gt W32 -> condFltCode GTT x y
34 MO_F_Ge W32 -> condFltCode GE x y
35 MO_F_Lt W32 -> condFltCode LTT x y
36 MO_F_Le W32 -> condFltCode LE x y
37
38 MO_F_Eq W64 -> condFltCode EQQ x y
39 MO_F_Ne W64 -> condFltCode NE x y
40 MO_F_Gt W64 -> condFltCode GTT x y
41 MO_F_Ge W64 -> condFltCode GE x y
42 MO_F_Lt W64 -> condFltCode LTT x y
43 MO_F_Le W64 -> condFltCode LE x y
44
45 MO_Eq _ -> condIntCode EQQ x y
46 MO_Ne _ -> condIntCode NE x y
47
48 MO_S_Gt _ -> condIntCode GTT x y
49 MO_S_Ge _ -> condIntCode GE x y
50 MO_S_Lt _ -> condIntCode LTT x y
51 MO_S_Le _ -> condIntCode LE x y
52
53 MO_U_Gt _ -> condIntCode GU x y
54 MO_U_Ge _ -> condIntCode GEU x y
55 MO_U_Lt _ -> condIntCode LU x y
56 MO_U_Le _ -> condIntCode LEU x y
57
58 _ -> do dflags <- getDynFlagsNat
59 pprPanic "SPARC.CodeGen.CondCode.getCondCode" (pprPlatform (targetPlatform dflags) (CmmMachOp mop [x,y]))
60
61 getCondCode other = do dflags <- getDynFlagsNat
62 pprPanic "SPARC.CodeGen.CondCode.getCondCode" (pprPlatform (targetPlatform dflags) other)
63
64
65
66
67
68 -- @cond(Int|Flt)Code@: Turn a boolean expression into a condition, to be
69 -- passed back up the tree.
70
71 condIntCode :: Cond -> CmmExpr -> CmmExpr -> NatM CondCode
72 condIntCode cond x (CmmLit (CmmInt y _))
73 | fits13Bits y
74 = do
75 (src1, code) <- getSomeReg x
76 let
77 src2 = ImmInt (fromInteger y)
78 code' = code `snocOL` SUB False True src1 (RIImm src2) g0
79 return (CondCode False cond code')
80
81 condIntCode cond x y = do
82 (src1, code1) <- getSomeReg x
83 (src2, code2) <- getSomeReg y
84 let
85 code__2 = code1 `appOL` code2 `snocOL`
86 SUB False True src1 (RIReg src2) g0
87 return (CondCode False cond code__2)
88
89
90 condFltCode :: Cond -> CmmExpr -> CmmExpr -> NatM CondCode
91 condFltCode cond x y = do
92 (src1, code1) <- getSomeReg x
93 (src2, code2) <- getSomeReg y
94 tmp <- getNewRegNat FF64
95 let
96 promote x = FxTOy FF32 FF64 x tmp
97
98 pk1 = cmmExprType x
99 pk2 = cmmExprType y
100
101 code__2 =
102 if pk1 `cmmEqType` pk2 then
103 code1 `appOL` code2 `snocOL`
104 FCMP True (cmmTypeSize pk1) src1 src2
105 else if typeWidth pk1 == W32 then
106 code1 `snocOL` promote src1 `appOL` code2 `snocOL`
107 FCMP True FF64 tmp src2
108 else
109 code1 `appOL` code2 `snocOL` promote src2 `snocOL`
110 FCMP True FF64 src1 tmp
111 return (CondCode True cond code__2)