changeset 9843:e05af215586b

SPARC compare
author Morris Meyer <morris.meyer@oracle.com>
date Thu, 30 May 2013 22:56:22 -0400
parents 1cd5e2a6f038
children 2d1687e63484
files graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java
diffstat 3 files changed, 59 insertions(+), 205 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java	Wed May 29 15:33:51 2013 +0200
+++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java	Thu May 30 22:56:22 2013 -0400
@@ -722,6 +722,16 @@
         }
     }
 
+    @SuppressWarnings("unused")
+    public static class Cmp {
+        public Cmp(SPARCAssembler masm, Register a, Register b) {
+            new Subcc(masm, a, b, SPARC.r0);
+        }
+        public Cmp(SPARCAssembler masm, Register a, int simm13) {
+            new Subcc(masm, a, simm13, SPARC.r0);
+        }
+    }
+
     private static int patchUnbound(SPARCAssembler masm, Label label) {
         label.addPatchAt(masm.codeBuffer.position());
         return 0;
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Wed May 29 15:33:51 2013 +0200
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Thu May 30 22:56:22 2013 -0400
@@ -139,23 +139,23 @@
     public void emitCompareBranch(Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef label) {
         switch (left.getKind().getStackKind()) {
             case Int:
-                append(new CompareOp(ICMP, cond, left, right));
+                append(new CompareOp(ICMP, left, right));
                 append(new BranchOp(cond, label));
                 break;
             case Long:
-                append(new CompareOp(LCMP, cond, left, right));
+                append(new CompareOp(LCMP, left, right));
                 append(new BranchOp(cond, label));
                 break;
             case Float:
-                append(new CompareOp(FCMP, cond, left, right));
+                append(new CompareOp(FCMP, left, right));
                 append(new BranchOp(cond, label));
                 break;
             case Double:
-                append(new CompareOp(DCMP, cond, left, right));
+                append(new CompareOp(DCMP, left, right));
                 append(new BranchOp(cond, label));
                 break;
             case Object:
-                append(new CompareOp(ACMP, cond, left, right));
+                append(new CompareOp(ACMP, left, right));
                 append(new BranchOp(cond, label));
                 break;
             default:
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java	Wed May 29 15:33:51 2013 +0200
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java	Thu May 30 22:56:22 2013 -0400
@@ -23,15 +23,16 @@
 package com.oracle.graal.lir.sparc;
 
 import static com.oracle.graal.api.code.ValueUtil.*;
+import static com.oracle.graal.asm.sparc.SPARCAssembler.isSimm13;
 import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
 
-import com.oracle.graal.api.code.*;
 import com.oracle.graal.api.meta.*;
 import com.oracle.graal.asm.sparc.SPARCAssembler;
+import com.oracle.graal.asm.sparc.SPARCAssembler.Cmp;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.lir.asm.*;
-import com.oracle.graal.nodes.calc.*;
 
+//@formatter:off
 public enum SPARCCompare {
     ICMP, LCMP, ACMP, FCMP, DCMP;
 
@@ -40,67 +41,73 @@
         @Opcode private final SPARCCompare opcode;
         @Use({REG, STACK, CONST}) protected Value x;
         @Use({REG, STACK, CONST}) protected Value y;
-        private final Condition condition;
 
-        public CompareOp(SPARCCompare opcode, Condition condition, Value x, Value y) {
+        public CompareOp(SPARCCompare opcode, Value x, Value y) {
             this.opcode = opcode;
-            this.condition = condition;
             this.x = x;
             this.y = y;
         }
 
         @Override
         public void emitCode(TargetMethodAssembler tasm, SPARCAssembler masm) {
-            emit(tasm, masm, opcode, condition, x, y);
+            emit(tasm, masm, opcode, x, y);
         }
 
         @Override
         protected void verify() {
             super.verify();
-            assert (name().startsWith("I") && x.getKind() == Kind.Int && y.getKind().getStackKind() == Kind.Int) || (name().startsWith("L") && x.getKind() == Kind.Long && y.getKind() == Kind.Long) ||
-                            (name().startsWith("A") && x.getKind() == Kind.Object && y.getKind() == Kind.Object) ||
-                            (name().startsWith("F") && x.getKind() == Kind.Float && y.getKind() == Kind.Float) || (name().startsWith("D") && x.getKind() == Kind.Double && y.getKind() == Kind.Double);
+            assert (name().startsWith("I") && x.getKind() == Kind.Int && y.getKind().getStackKind() == Kind.Int)
+                || (name().startsWith("L") && x.getKind() == Kind.Long && y.getKind() == Kind.Long)
+                || (name().startsWith("A") && x.getKind() == Kind.Object && y.getKind() == Kind.Object)
+                || (name().startsWith("F") && x.getKind() == Kind.Float && y.getKind() == Kind.Float)
+                || (name().startsWith("D") && x.getKind() == Kind.Double && y.getKind() == Kind.Double);
         }
     }
 
-    public static void emit(TargetMethodAssembler tasm, SPARCAssembler masm, SPARCCompare opcode, Condition condition, Value x, Value y) {
-        if (isConstant(x)) {
+    @SuppressWarnings("unused")
+    public static void emit(TargetMethodAssembler tasm, SPARCAssembler masm, SPARCCompare opcode, Value x, Value y) {
+        if (isRegister(y)) {
             switch (opcode) {
                 case ICMP:
-                    emitCompareConstReg(masm, condition, tasm.asIntConst(x), asIntReg(y));
+                    new Cmp(masm, asIntReg(x), asIntReg(y));
+                    break;
+                case LCMP:
+                    new Cmp(masm, asLongReg(x), asLongReg(y));
+                    break;
+                case ACMP:
+                    // masm.cmpptr(asObjectReg(x), asObjectReg(y));
                     break;
                 case FCMP:
-                    emitCompareConstReg(masm, condition, tasm.asFloatConst(x), asFloatReg(y));
+                    // masm.ucomiss(asFloatReg(x), asFloatReg(y));
                     break;
                 case DCMP:
-                    emitCompareConstReg(masm, condition, tasm.asDoubleConst(x), asDoubleReg(y));
+                    // masm.ucomisd(asDoubleReg(x), asDoubleReg(y));
                     break;
                 default:
                     throw GraalInternalError.shouldNotReachHere();
             }
         } else if (isConstant(y)) {
-            Register a = asIntReg(x);
-            int b = tasm.asIntConst(y);
             switch (opcode) {
                 case ICMP:
-                    emitCompareRegConst(masm, condition, a, b);
+                    assert isSimm13(tasm.asIntConst(y));
+                    new Cmp(masm, asIntReg(x), tasm.asIntConst(y));
+                    break;
+                case LCMP:
+                    assert isSimm13(tasm.asIntConst(y));
+                    new Cmp(masm, asLongReg(x), tasm.asIntConst(y));
                     break;
                 case ACMP:
                     if (((Constant) y).isNull()) {
-                        switch (condition) {
-                            case EQ:
-                                // masm.setp_eq_s32(a, b);
-                                break;
-                            case NE:
-                                // masm.setp_ne_s32(a, b);
-                                break;
-                            default:
-                                throw GraalInternalError.shouldNotReachHere();
-                        }
+                        // masm.cmpq(asObjectReg(x), 0);
+                        break;
                     } else {
-                        String msg = "Only null object constants allowed";
-                        throw GraalInternalError.shouldNotReachHere(msg);
+                        throw GraalInternalError.shouldNotReachHere("Only null object constants are allowed in comparisons");
                     }
+                case FCMP:
+                    // masm.ucomiss(asFloatReg(x), (AMD64Address) tasm.asFloatConstRef(y));
+                    break;
+                case DCMP:
+                    // masm.ucomisd(asDoubleReg(x), (AMD64Address) tasm.asDoubleConstRef(y));
                     break;
                 default:
                     throw GraalInternalError.shouldNotReachHere();
@@ -108,186 +115,23 @@
         } else {
             switch (opcode) {
                 case ICMP:
-                    emitCompareRegReg(masm, condition, asIntReg(x), asIntReg(y));
+                    // masm.cmpl(asIntReg(x), (AMD64Address) tasm.asIntAddr(y)); 
                     break;
                 case LCMP:
-                    emitCompareRegReg(masm, condition, asLongReg(x), asLongReg(y));
+                    // masm.cmpq(asLongReg(x), (AMD64Address) tasm.asLongAddr(y));
+                    break;
+                case ACMP:
+                    // masm.cmpptr(asObjectReg(x), (AMD64Address) tasm.asObjectAddr(y));
                     break;
                 case FCMP:
-                    emitCompareRegReg(masm, condition, asFloatReg(x), asFloatReg(y));
+                    // masm.ucomiss(asFloatReg(x), (AMD64Address) tasm.asFloatAddr(y));
                     break;
                 case DCMP:
-                    emitCompareRegReg(masm, condition, asDoubleReg(x), asDoubleReg(y));
+                    // masm.ucomisd(asDoubleReg(x), (AMD64Address) tasm.asDoubleAddr(y)); 
                     break;
                 default:
-                    throw GraalInternalError.shouldNotReachHere("missing: " + opcode);
+                    throw GraalInternalError.shouldNotReachHere();
             }
         }
     }
-
-    @SuppressWarnings("unused")
-    private static void emitCompareConstReg(SPARCAssembler masm, Condition condition, float a, Register b) {
-        switch (condition) {
-            case EQ:
-                // masm.setp_eq_f32(a, b);
-                break;
-            case NE:
-                // masm.setp_ne_f32(a, b);
-                break;
-            case LT:
-                // masm.setp_lt_f32(a, b);
-                break;
-            case LE:
-                // masm.setp_le_f32(a, b);
-                break;
-            case GT:
-                // masm.setp_gt_f32(a, b);
-                break;
-            case GE:
-                // masm.setp_ge_f32(a, b);
-                break;
-            default:
-                throw GraalInternalError.shouldNotReachHere();
-        }
-    }
-
-    @SuppressWarnings("unused")
-    private static void emitCompareConstReg(SPARCAssembler masm, Condition condition, double a, Register b) {
-        switch (condition) {
-            case EQ:
-                // masm.setp_eq_f64(a, b);
-                break;
-            case NE:
-                // masm.setp_ne_f64(a, b);
-                break;
-            case LT:
-                // masm.setp_lt_f64(a, b);
-                break;
-            case LE:
-                // masm.setp_le_f64(a, b);
-                break;
-            case GT:
-                // masm.setp_gt_f64(a, b);
-                break;
-            case GE:
-                // masm.setp_ge_f64(a, b);
-                break;
-            default:
-                throw GraalInternalError.shouldNotReachHere();
-        }
-    }
-
-    @SuppressWarnings("unused")
-    private static void emitCompareConstReg(SPARCAssembler masm, Condition condition, int a, Register b) {
-        switch (condition) {
-            case EQ:
-                // masm.setp_eq_s32(a, b);
-                break;
-            case NE:
-                // masm.setp_ne_s32(a, b);
-                break;
-            case LT:
-                // masm.setp_lt_s32(a, b);
-                break;
-            case LE:
-                // masm.setp_le_s32(a, b);
-                break;
-            case GT:
-                // masm.setp_gt_s32(a, b);
-                break;
-            case GE:
-                // masm.setp_ge_s32(a, b);
-                break;
-            case AT:
-                // masm.setp_gt_u32(a, b);
-                break;
-            case AE:
-                // masm.setp_ge_u32(a, b);
-                break;
-            case BT:
-                // masm.setp_lt_u32(a, b);
-                break;
-            case BE:
-                // masm.setp_le_u32(a, b);
-                break;
-            default:
-                throw GraalInternalError.shouldNotReachHere();
-        }
-    }
-
-    @SuppressWarnings("unused")
-    private static void emitCompareRegConst(SPARCAssembler masm, Condition condition, Register a, int b) {
-        switch (condition) {
-            case EQ:
-                // masm.setp_eq_s32(a, b);
-                break;
-            case NE:
-                // masm.setp_ne_s32(a, b);
-                break;
-            case LT:
-                // masm.setp_lt_s32(a, b);
-                break;
-            case LE:
-                // masm.setp_le_s32(a, b);
-                break;
-            case GT:
-                // masm.setp_gt_s32(a, b);
-                break;
-            case GE:
-                // masm.setp_ge_s32(a, b);
-                break;
-            case AT:
-                // masm.setp_gt_u32(a, b);
-                break;
-            case AE:
-                // masm.setp_ge_u32(a, b);
-                break;
-            case BT:
-                // masm.setp_lt_u32(a, b);
-                break;
-            case BE:
-                // masm.setp_le_u32(a, b);
-                break;
-            default:
-                throw GraalInternalError.shouldNotReachHere();
-        }
-    }
-
-    @SuppressWarnings("unused")
-    private static void emitCompareRegReg(SPARCAssembler masm, Condition condition, Register a, Register b) {
-        switch (condition) {
-            case EQ:
-                // masm.setp_eq_s32(a, b);
-                break;
-            case NE:
-                // masm.setp_ne_s32(a, b);
-                break;
-            case LT:
-                // masm.setp_lt_s32(a, b);
-                break;
-            case LE:
-                // masm.setp_le_s32(a, b);
-                break;
-            case GT:
-                // masm.setp_gt_s32(a, b);
-                break;
-            case GE:
-                // masm.setp_ge_s32(a, b);
-                break;
-            case AT:
-                // masm.setp_gt_u32(a, b);
-                break;
-            case AE:
-                // masm.setp_ge_u32(a, b);
-                break;
-            case BT:
-                // masm.setp_lt_u32(a, b);
-                break;
-            case BE:
-                // masm.setp_le_u32(a, b);
-                break;
-            default:
-                throw GraalInternalError.shouldNotReachHere();
-        }
-    }
 }