changeset 16664:62f295bdea36

[SPARC] Fixing compare of short/char with constants, using half of single float registers as of now, otherwise it would overlap with double registers
author Stefan Anzinger <stefan.anzinger@gmail.com>
date Thu, 31 Jul 2014 07:07:38 -0700
parents 4ccd6b6b6780
children 2f4487a0b588
files graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java
diffstat 2 files changed, 19 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Wed Jul 30 14:49:41 2014 -0700
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Thu Jul 31 07:07:38 2014 -0700
@@ -221,7 +221,7 @@
     @Override
     public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination,
                     double trueDestinationProbability) {
-        boolean mirrored = emitCompare(left, right);
+        boolean mirrored = emitCompare(cmpKind, left, right);
         Condition finalCondition = mirrored ? cond.mirror() : cond;
         Kind kind = left.getKind().getStackKind();
         switch (kind) {
@@ -262,7 +262,7 @@
 
     @Override
     public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
-        boolean mirrored = emitCompare(left, right);
+        boolean mirrored = emitCompare(cmpKind, left, right);
         Condition finalCondition = mirrored ? cond.mirror() : cond;
 
         Variable result = newVariable(trueValue.getLIRKind());
@@ -287,11 +287,12 @@
      * This method emits the compare instruction, and may reorder the operands. It returns true if
      * it did so.
      *
+     * @param cmpKind Kind how a and b have to be compared
      * @param a the left operand of the comparison
      * @param b the right operand of the comparison
      * @return true if the left and right operands were switched, false otherwise
      */
-    protected boolean emitCompare(Value a, Value b) {
+    protected boolean emitCompare(PlatformKind cmpKind, Value a, Value b) {
         Variable left;
         Value right;
         boolean mirrored;
@@ -304,7 +305,14 @@
             right = loadNonConst(b);
             mirrored = false;
         }
-        switch (left.getKind().getStackKind()) {
+        switch ((Kind) cmpKind) {
+            case Short:
+            case Char:
+                append(new CompareOp(ICMP, emitZeroExtend(left, 16, 32), emitZeroExtend(right, 16, 32)));
+                break;
+            case Byte:
+                append(new CompareOp(ICMP, emitZeroExtend(left, 8, 32), emitZeroExtend(right, 8, 32)));
+                break;
             case Int:
                 append(new CompareOp(ICMP, left, right));
                 break;
@@ -906,14 +914,16 @@
         } else {
             assert inputVal.getKind() == Kind.Int || inputVal.getKind() == Kind.Short || inputVal.getKind() == Kind.Byte : inputVal.getKind();
             Variable result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Int));
-            int mask = (int) IntegerStamp.defaultMask(fromBits);
-            Constant constant = Constant.forInt(mask);
+            long mask = IntegerStamp.defaultMask(fromBits);
+            Constant constant = Constant.forLong(mask);
             if (canInlineConstant(constant)) {
                 append(new BinaryRegConst(SPARCArithmetic.IAND, result, asAllocatable(inputVal), constant, null));
+            } else if (fromBits == 32) {
+                append(new ShiftOp(IUSHR, result, inputVal, Constant.forInt(0)));
             } else {
                 Variable maskVar = newVariable(LIRKind.derive(inputVal).changeType(Kind.Int));
                 emitMove(maskVar, constant);
-                append(new BinaryRegReg(IAND, result, maskVar, (inputVal)));
+                append(new BinaryRegReg(IAND, result, maskVar, asAllocatable(inputVal)));
             }
             if (toBits > 32) {
                 Variable longResult = newVariable(LIRKind.derive(inputVal).changeType(Kind.Long));
--- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java	Wed Jul 30 14:49:41 2014 -0700
+++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotRegisterConfig.java	Thu Jul 31 07:07:38 2014 -0700
@@ -59,7 +59,8 @@
         for (Register reg : getAllocatableRegisters()) {
             if (architecture.canStoreValue(reg.getRegisterCategory(), kind)) {
                 // Special treatment for double precision
-                if (kind == Kind.Double) {
+                // TODO: This is wasteful it uses only half of the registers as float.
+                if (kind == Kind.Double || kind == Kind.Float) {
                     // Only even register numbers are valid double precision regs
                     if (reg.number % 2 == 0) {
                         list.add(reg);