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