graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXCompare.java

Print this page
rev 8592 : Graal PTX enhancements


  48             this.x = x;
  49             this.y = y;
  50         }
  51 
  52         @Override
  53         public void emitCode(TargetMethodAssembler tasm, PTXAssembler masm) {
  54             emit(tasm, masm, opcode, condition, x, y);
  55         }
  56 
  57         @Override
  58         protected void verify() {
  59             super.verify();
  60             assert (name().startsWith("I") && x.getKind() == Kind.Int && y.getKind().getStackKind() == Kind.Int) || (name().startsWith("L") && x.getKind() == Kind.Long && y.getKind() == Kind.Long) ||
  61                             (name().startsWith("A") && x.getKind() == Kind.Object && y.getKind() == Kind.Object) ||
  62                             (name().startsWith("F") && x.getKind() == Kind.Float && y.getKind() == Kind.Float) || (name().startsWith("D") && x.getKind() == Kind.Double && y.getKind() == Kind.Double);
  63         }
  64     }
  65 
  66     public static void emit(TargetMethodAssembler tasm, PTXAssembler masm, PTXCompare opcode, Condition condition, Value x, Value y) {
  67         if (isConstant(x)) {
  68             int a = tasm.asIntConst(x);
  69             Register b = asIntReg(y);
  70             switch (opcode) {
  71                 case ICMP:
  72                     emitCompareConstReg(masm, condition, a, b);






  73                     break;
  74                 default:
  75                     throw GraalInternalError.shouldNotReachHere();
  76             }
  77         } else if (isConstant(y)) {
  78             Register a = asIntReg(x);
  79             int b = tasm.asIntConst(y);
  80             switch (opcode) {
  81                 case ICMP:
  82                     emitCompareRegConst(masm, condition, a, b);
  83                     break;
  84                 case ACMP:
  85                     if (((Constant) y).isNull()) {
  86                         switch (condition) {
  87                             case EQ:
  88                                 masm.setp_eq_s32(a, b);
  89                                 break;
  90                             case NE:
  91                                 masm.setp_ne_s32(a, b);
  92                                 break;
  93                             default:
  94                                 throw GraalInternalError.shouldNotReachHere();
  95                         }
  96                     } else {
  97                         throw GraalInternalError.shouldNotReachHere("Only null object constants are allowed in comparisons");
  98                     }
  99                     break;
 100                 default:
 101                     throw GraalInternalError.shouldNotReachHere();
 102             }
 103         } else {
 104             Register a = asIntReg(x);
 105             Register b = asIntReg(y);
 106             switch (opcode) {
 107                 case ICMP:
 108                     emitCompareRegReg(masm, condition, a, b);




































 109                     break;
 110                 default:
 111                     throw GraalInternalError.shouldNotReachHere();
 112             }
 113         }
























 114     }
 115 
 116     private static void emitCompareConstReg(PTXAssembler masm, Condition condition, int a, Register b) {
 117         switch (condition) {
 118             case EQ:
 119                 masm.setp_eq_s32(a, b);
 120                 break;
 121             case NE:
 122                 masm.setp_ne_s32(a, b);
 123                 break;
 124             case LT:
 125                 masm.setp_lt_s32(a, b);
 126                 break;
 127             case LE:
 128                 masm.setp_le_s32(a, b);
 129                 break;
 130             case GT:
 131                 masm.setp_gt_s32(a, b);
 132                 break;
 133             case GE:




  48             this.x = x;
  49             this.y = y;
  50         }
  51 
  52         @Override
  53         public void emitCode(TargetMethodAssembler tasm, PTXAssembler masm) {
  54             emit(tasm, masm, opcode, condition, x, y);
  55         }
  56 
  57         @Override
  58         protected void verify() {
  59             super.verify();
  60             assert (name().startsWith("I") && x.getKind() == Kind.Int && y.getKind().getStackKind() == Kind.Int) || (name().startsWith("L") && x.getKind() == Kind.Long && y.getKind() == Kind.Long) ||
  61                             (name().startsWith("A") && x.getKind() == Kind.Object && y.getKind() == Kind.Object) ||
  62                             (name().startsWith("F") && x.getKind() == Kind.Float && y.getKind() == Kind.Float) || (name().startsWith("D") && x.getKind() == Kind.Double && y.getKind() == Kind.Double);
  63         }
  64     }
  65 
  66     public static void emit(TargetMethodAssembler tasm, PTXAssembler masm, PTXCompare opcode, Condition condition, Value x, Value y) {
  67         if (isConstant(x)) {


  68             switch (opcode) {
  69                 case ICMP:
  70                     emitCompareConstReg(masm, condition, tasm.asIntConst(x), asIntReg(y));
  71                     break;
  72                 case FCMP:
  73                     emitCompareConstReg(masm, condition, tasm.asFloatConst(x), asFloatReg(y));
  74                     break;
  75                 case DCMP:
  76                     emitCompareConstReg(masm, condition, tasm.asDoubleConst(x), asDoubleReg(y));
  77                     break;
  78                 default:
  79                     throw GraalInternalError.shouldNotReachHere();
  80             }
  81         } else if (isConstant(y)) {
  82             Register a = asIntReg(x);
  83             int b = tasm.asIntConst(y);
  84             switch (opcode) {
  85                 case ICMP:
  86                     emitCompareRegConst(masm, condition, a, b);
  87                     break;
  88                 case ACMP:
  89                     if (((Constant) y).isNull()) {
  90                         switch (condition) {
  91                             case EQ:
  92                                 masm.setp_eq_s32(a, b);
  93                                 break;
  94                             case NE:
  95                                 masm.setp_ne_s32(a, b);
  96                                 break;
  97                             default:
  98                                 throw GraalInternalError.shouldNotReachHere();
  99                         }
 100                     } else {
 101                         throw GraalInternalError.shouldNotReachHere("Only null object constants are allowed in comparisons");
 102                     }
 103                     break;
 104                 default:
 105                     throw GraalInternalError.shouldNotReachHere();
 106             }
 107         } else {


 108             switch (opcode) {
 109                 case ICMP:
 110                     emitCompareRegReg(masm, condition, asIntReg(x), asIntReg(y));
 111                     break;
 112                 case LCMP:
 113                     emitCompareRegReg(masm, condition, asLongReg(x), asLongReg(y));
 114                     break;
 115                 case FCMP:
 116                     emitCompareRegReg(masm, condition, asFloatReg(x), asFloatReg(y));
 117                     break;
 118                 case DCMP:
 119                     emitCompareRegReg(masm, condition, asDoubleReg(x), asDoubleReg(y));
 120                     break;
 121                 default:
 122                         System.err.println("missing: "  + opcode);
 123                     throw GraalInternalError.shouldNotReachHere();
 124             }
 125         }
 126     }
 127     
 128     private static void emitCompareConstReg(PTXAssembler masm, Condition condition, float a, Register b) {
 129         switch (condition) {
 130         case EQ:
 131             masm.setp_eq_f32(a, b);
 132             break;
 133         case NE:
 134             masm.setp_ne_f32(a, b);
 135             break;
 136         case LT:
 137             masm.setp_lt_f32(a, b);
 138             break;
 139         case LE:
 140             masm.setp_le_f32(a, b);
 141             break;
 142         case GT:
 143             masm.setp_gt_f32(a, b);
 144             break;
 145         case GE:
 146             masm.setp_ge_f32(a, b);
 147             break;
 148         default:
 149             throw GraalInternalError.shouldNotReachHere();
 150         }
 151     }
 152 
 153     private static void emitCompareConstReg(PTXAssembler masm, Condition condition, double a, Register b) {
 154         switch (condition) {
 155         case EQ:
 156             masm.setp_eq_f64(a, b);
 157             break;
 158         case NE:
 159             masm.setp_ne_f64(a, b);
 160             break;
 161         case LT:
 162             masm.setp_lt_f64(a, b);
 163             break;
 164         case LE:
 165             masm.setp_le_f64(a, b);
 166             break;
 167         case GT:
 168             masm.setp_gt_f64(a, b);
 169             break;
 170         case GE:
 171             masm.setp_ge_f64(a, b);
 172             break;
 173         default:
 174             throw GraalInternalError.shouldNotReachHere();
 175         }
 176     }
 177 
 178     private static void emitCompareConstReg(PTXAssembler masm, Condition condition, int a, Register b) {
 179         switch (condition) {
 180             case EQ:
 181                 masm.setp_eq_s32(a, b);
 182                 break;
 183             case NE:
 184                 masm.setp_ne_s32(a, b);
 185                 break;
 186             case LT:
 187                 masm.setp_lt_s32(a, b);
 188                 break;
 189             case LE:
 190                 masm.setp_le_s32(a, b);
 191                 break;
 192             case GT:
 193                 masm.setp_gt_s32(a, b);
 194                 break;
 195             case GE: