never executed always true always false
    1 module GHC.CmmToAsm.X86.Cond (
    2         Cond(..),
    3         condToUnsigned,
    4         maybeFlipCond,
    5         maybeInvertCond
    6 )
    7 
    8 where
    9 
   10 import GHC.Prelude
   11 
   12 data Cond
   13         = ALWAYS        -- What's really used? ToDo
   14         | EQQ           -- je/jz -> zf = 1
   15         | GE            -- jge
   16         | GEU           -- ae
   17         | GTT           -- jg
   18         | GU            -- ja
   19         | LE            -- jle
   20         | LEU           -- jbe
   21         | LTT           -- jl
   22         | LU            -- jb
   23         | NE            -- jne
   24         | NEG           -- js
   25         | POS           -- jns
   26         | CARRY         -- jc
   27         | OFLO          -- jo
   28         | PARITY        -- jp
   29         | NOTPARITY     -- jnp
   30         deriving Eq
   31 
   32 condToUnsigned :: Cond -> Cond
   33 condToUnsigned GTT = GU
   34 condToUnsigned LTT = LU
   35 condToUnsigned GE  = GEU
   36 condToUnsigned LE  = LEU
   37 condToUnsigned x   = x
   38 
   39 -- | @maybeFlipCond c@ returns @Just c'@ if it is possible to flip the
   40 -- arguments to the conditional @c@, and the new condition should be @c'@.
   41 maybeFlipCond :: Cond -> Maybe Cond
   42 maybeFlipCond cond  = case cond of
   43         EQQ   -> Just EQQ
   44         NE    -> Just NE
   45         LU    -> Just GU
   46         GU    -> Just LU
   47         LEU   -> Just GEU
   48         GEU   -> Just LEU
   49         LTT   -> Just GTT
   50         GTT   -> Just LTT
   51         LE    -> Just GE
   52         GE    -> Just LE
   53         _other -> Nothing
   54 
   55 -- | If we apply @maybeInvertCond@ to the condition of a jump we turn
   56 -- jumps taken into jumps not taken and vice versa.
   57 --
   58 -- Careful! If the used comparison and the conditional jump
   59 -- don't match the above behaviour will NOT hold.
   60 -- When used for FP comparisons this does not consider unordered
   61 -- numbers.
   62 -- Also inverting twice might return a synonym for the original condition.
   63 maybeInvertCond :: Cond -> Maybe Cond
   64 maybeInvertCond cond  = case cond of
   65         ALWAYS  -> Nothing
   66         EQQ     -> Just NE
   67         NE      -> Just EQQ
   68 
   69         NEG     -> Just POS
   70         POS     -> Just NEG
   71 
   72         GEU     -> Just LU
   73         LU      -> Just GEU
   74 
   75         GE      -> Just LTT
   76         LTT     -> Just GE
   77 
   78         GTT     -> Just LE
   79         LE      -> Just GTT
   80 
   81         GU      -> Just LEU
   82         LEU     -> Just GU
   83 
   84         --GEU "==" NOTCARRY, they are synonyms
   85         --at the assembly level
   86         CARRY   -> Just GEU
   87 
   88         OFLO    -> Nothing
   89 
   90         PARITY  -> Just NOTPARITY
   91         NOTPARITY -> Just PARITY