904a9ce99c62b79a4074ebe5c5ce0083ff650f55
[ghc.git] / compiler / nativeGen / X86 / Cond.hs
1
2 {-# OPTIONS -fno-warn-tabs #-}
3 -- The above warning supression flag is a temporary kludge.
4 -- While working on this module you are encouraged to remove it and
5 -- detab the module (please do the detabbing in a separate patch). See
6 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
7 -- for details
8
9 module X86.Cond (
10 Cond(..),
11 condUnsigned,
12 condToSigned,
13 condToUnsigned,
14 maybeFlipCond
15 )
16
17 where
18
19 data Cond
20 = ALWAYS -- What's really used? ToDo
21 | EQQ
22 | GE
23 | GEU
24 | GTT
25 | GU
26 | LE
27 | LEU
28 | LTT
29 | LU
30 | NE
31 | NEG
32 | POS
33 | CARRY
34 | OFLO
35 | PARITY
36 | NOTPARITY
37 deriving Eq
38
39 condUnsigned :: Cond -> Bool
40 condUnsigned GU = True
41 condUnsigned LU = True
42 condUnsigned GEU = True
43 condUnsigned LEU = True
44 condUnsigned _ = False
45
46
47 condToSigned :: Cond -> Cond
48 condToSigned GU = GTT
49 condToSigned LU = LTT
50 condToSigned GEU = GE
51 condToSigned LEU = LE
52 condToSigned x = x
53
54
55 condToUnsigned :: Cond -> Cond
56 condToUnsigned GTT = GU
57 condToUnsigned LTT = LU
58 condToUnsigned GE = GEU
59 condToUnsigned LE = LEU
60 condToUnsigned x = x
61
62 -- | @maybeFlipCond c@ returns @Just c'@ if it is possible to flip the
63 -- arguments to the conditional @c@, and the new condition should be @c'@.
64 maybeFlipCond :: Cond -> Maybe Cond
65 maybeFlipCond cond = case cond of
66 EQQ -> Just EQQ
67 NE -> Just NE
68 LU -> Just GU
69 GU -> Just LU
70 LEU -> Just GEU
71 GEU -> Just LEU
72 LTT -> Just GTT
73 GTT -> Just LTT
74 LE -> Just GE
75 GE -> Just LE
76 _other -> Nothing