changeset 16518:3eb13b910134

[SPARC] Fixing LongBits tests and some implicit exceptions
author Stefan Anzinger <stefan.anzinger@gmail.com>
date Fri, 11 Jul 2014 18:22:12 -0700
parents cb70055faeeb
children 2b91702c4e69
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/SPARCArithmetic.java graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCByteSwapOp.java graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java
diffstat 6 files changed, 84 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java	Wed Jul 09 09:36:13 2014 -0700
+++ b/graal/com.oracle.graal.asm.sparc/src/com/oracle/graal/asm/sparc/SPARCAssembler.java	Fri Jul 11 18:22:12 2014 -0700
@@ -1082,7 +1082,10 @@
         Staf(0x26, "staf"),
         Stdf(0b100111, "stdf"),
 
-        Fcmp(0b110101, "fcmp");
+        Fcmp(0b110101, "fcmp"),
+
+        Ldxa (0b01_1011, "ldxa"),
+        Lduwa(0b01_0000, "lduwa");
 
         // @formatter:on
 
@@ -3110,6 +3113,20 @@
         }
     }
 
+    public static class Ldxa extends Fmt11 {
+
+        public Ldxa(Register src1, Register src2, Register dst, Asi asi) {
+            super(Op3s.Ldxa, src1, src2, dst, asi);
+        }
+    }
+
+    public static class Lduwa extends Fmt11 {
+
+        public Lduwa(Register src1, Register src2, Register dst, Asi asi) {
+            super(Op3s.Lduwa, src1, src2, dst, asi);
+        }
+    }
+
     public static class Membar extends Fmt10 {
 
         public Membar(int barriers) {
--- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Wed Jul 09 09:36:13 2014 -0700
+++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java	Fri Jul 11 18:22:12 2014 -0700
@@ -42,6 +42,7 @@
 import com.oracle.graal.lir.StandardOp.JumpOp;
 import com.oracle.graal.lir.gen.*;
 import com.oracle.graal.lir.sparc.*;
+import com.oracle.graal.nodes.*;
 import com.oracle.graal.phases.util.*;
 
 /**
@@ -396,7 +397,7 @@
     @Override
     public Value emitMathAbs(Value input) {
         Variable result = newVariable(LIRKind.derive(input));
-        append(new BinaryRegConst(DAND, result, asAllocatable(input), Constant.forDouble(Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL))));
+        append(new BinaryRegConst(DAND, result, asAllocatable(input), Constant.forDouble(Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL)), null));
         return result;
     }
 
@@ -438,7 +439,7 @@
     @Override
     public Value emitByteSwap(Value input) {
         Variable result = newVariable(LIRKind.derive(input));
-        append(new SPARCByteSwapOp(result, input));
+        append(new SPARCByteSwapOp(this, result, input));
         return result;
     }
 
@@ -486,17 +487,17 @@
         return result;
     }
 
-    private Variable emitBinary(SPARCArithmetic op, boolean commutative, Value a, Value b) {
+    private Variable emitBinary(SPARCArithmetic op, boolean commutative, Value a, Value b, LIRFrameState state) {
         if (isConstant(b)) {
-            return emitBinaryConst(op, commutative, asAllocatable(a), asConstant(b));
+            return emitBinaryConst(op, commutative, asAllocatable(a), asConstant(b), state);
         } else if (commutative && isConstant(a)) {
-            return emitBinaryConst(op, commutative, asAllocatable(b), asConstant(a));
+            return emitBinaryConst(op, commutative, asAllocatable(b), asConstant(a), state);
         } else {
-            return emitBinaryVar(op, commutative, asAllocatable(a), asAllocatable(b));
+            return emitBinaryVar(op, commutative, asAllocatable(a), asAllocatable(b), state);
         }
     }
 
-    private Variable emitBinaryConst(SPARCArithmetic op, boolean commutative, AllocatableValue a, Constant b) {
+    private Variable emitBinaryConst(SPARCArithmetic op, boolean commutative, AllocatableValue a, Constant b, LIRFrameState state) {
         switch (op) {
             case IADD:
             case LADD:
@@ -512,16 +513,16 @@
             case LMUL:
                 if (NumUtil.isInt(b.asLong())) {
                     Variable result = newVariable(LIRKind.derive(a, b));
-                    append(new BinaryRegConst(op, result, a, b));
+                    append(new BinaryRegConst(op, result, a, b, state));
                     return result;
                 }
                 break;
         }
 
-        return emitBinaryVar(op, commutative, a, asAllocatable(b));
+        return emitBinaryVar(op, commutative, a, asAllocatable(b), state);
     }
 
-    private Variable emitBinaryVar(SPARCArithmetic op, boolean commutative, AllocatableValue a, AllocatableValue b) {
+    private Variable emitBinaryVar(SPARCArithmetic op, boolean commutative, AllocatableValue a, AllocatableValue b, LIRFrameState state) {
         Variable result = newVariable(LIRKind.derive(a, b));
         if (commutative) {
             append(new BinaryCommutative(op, result, a, b));
@@ -535,13 +536,13 @@
     public Variable emitAdd(Value a, Value b) {
         switch (a.getKind().getStackKind()) {
             case Int:
-                return emitBinary(IADD, true, a, b);
+                return emitBinary(IADD, true, a, b, null);
             case Long:
-                return emitBinary(LADD, true, a, b);
+                return emitBinary(LADD, true, a, b, null);
             case Float:
-                return emitBinary(FADD, true, a, b);
+                return emitBinary(FADD, true, a, b, null);
             case Double:
-                return emitBinary(DADD, true, a, b);
+                return emitBinary(DADD, true, a, b, null);
             default:
                 throw GraalInternalError.shouldNotReachHere();
         }
@@ -603,24 +604,24 @@
 
     @Override
     public Value emitDiv(Value a, Value b, LIRFrameState state) {
-        Variable result = newVariable(LIRKind.derive(a, b));
+        SPARCArithmetic op = null;
         switch (a.getKind().getStackKind()) {
             case Int:
-                append(new BinaryRegReg(IDIV, result, a, loadNonConst(b)));
+                op = IDIV;
                 break;
             case Long:
-                append(new BinaryRegReg(LDIV, result, a, loadNonConst(b), state));
+                op = LDIV;
                 break;
             case Float:
-                append(new Op2Stack(FDIV, result, a, loadNonConst(b)));
+                op = FDIV;
                 break;
             case Double:
-                append(new Op2Stack(DDIV, result, a, loadNonConst(b)));
+                op = DDIV;
                 break;
             default:
                 throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind());
         }
-        return result;
+        return emitBinary(op, false, a, b, state);
     }
 
     @Override
@@ -739,7 +740,7 @@
         Variable result = newVariable(LIRKind.derive(a, b).changeType(a.getPlatformKind()));
         AllocatableValue input = asAllocatable(a);
         if (isConstant(b)) {
-            append(new BinaryRegConst(op, result, input, asConstant(b)));
+            append(new BinaryRegConst(op, result, input, asConstant(b), null));
         } else {
             append(new BinaryRegReg(op, result, input, b));
         }
@@ -902,7 +903,7 @@
             assert inputVal.getKind() == Kind.Long;
             Variable result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Long));
             long mask = IntegerStamp.defaultMask(fromBits);
-            append(new BinaryRegConst(SPARCArithmetic.LAND, result, asAllocatable(inputVal), Constant.forLong(mask)));
+            append(new BinaryRegConst(SPARCArithmetic.LAND, result, asAllocatable(inputVal), Constant.forLong(mask), null));
             return result;
         } else {
             assert inputVal.getKind() == Kind.Int || inputVal.getKind() == Kind.Short || inputVal.getKind() == Kind.Byte : inputVal.getKind();
@@ -910,7 +911,7 @@
             int mask = (int) IntegerStamp.defaultMask(fromBits);
             Constant constant = Constant.forInt(mask);
             if (canInlineConstant(constant)) {
-                append(new BinaryRegConst(SPARCArithmetic.IAND, result, asAllocatable(inputVal), constant));
+                append(new BinaryRegConst(SPARCArithmetic.IAND, result, asAllocatable(inputVal), constant, null));
             } else {
                 Variable maskVar = newVariable(LIRKind.derive(inputVal).changeType(Kind.Int));
                 emitMove(maskVar, constant);
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java	Wed Jul 09 09:36:13 2014 -0700
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java	Fri Jul 11 18:22:12 2014 -0700
@@ -158,13 +158,15 @@
         @Opcode private final SPARCArithmetic opcode;
         @Def({REG}) protected AllocatableValue result;
         @Use({REG}) protected AllocatableValue x;
+        @State protected LIRFrameState state;
         protected Constant y;
 
-        public BinaryRegConst(SPARCArithmetic opcode, AllocatableValue result, AllocatableValue x, Constant y) {
+        public BinaryRegConst(SPARCArithmetic opcode, AllocatableValue result, AllocatableValue x, Constant y, LIRFrameState state) {
             this.opcode = opcode;
             this.result = result;
             this.x = x;
             this.y = y;
+            this.state = state;
         }
 
         @Override
@@ -274,15 +276,16 @@
             switch (opcode) {
                 case ISUB:
                     assert isSimm13(crb.asIntConst(src1));
-                    new Add(asIntReg(src2), -(crb.asIntConst(src1)), asIntReg(dst)).emit(masm);
+                    new Sub(SPARC.g0, asIntReg(src2), asIntReg(src2)).emit(masm);
+                    new Add(asIntReg(src2), crb.asIntConst(src1), asIntReg(dst)).emit(masm);
                     break;
                 case IAND:
                     throw GraalInternalError.unimplemented();
                 case IDIV:
-                    assert isSimm13(crb.asIntConst(src1));
-                    throw GraalInternalError.unimplemented();
-                    // new Sdivx(masm, asIntReg(src1), asIntReg(src2),
-                    // asIntReg(dst));
+                    new Setx(((PrimitiveConstant) src1).asInt(), asIntReg(dst), false).emit(masm);
+                    exceptionOffset = masm.position();
+                    new Sdivx(asIntReg(dst), asIntReg(src2), asIntReg(dst)).emit(masm);
+                    break;
                 case LDIV:
                     int c = crb.asIntConst(src1);
                     assert isSimm13(c);
@@ -297,7 +300,7 @@
                 default:
                     throw GraalInternalError.shouldNotReachHere();
             }
-        } else if (isConstant(src2)) {
+        } else if (!isConstant(src1) && isConstant(src2)) {
             switch (opcode) {
                 case IADD:
                     assert isSimm13(crb.asIntConst(src2));
@@ -313,7 +316,6 @@
                     break;
                 case IDIV:
                     assert isSimm13(crb.asIntConst(src2));
-                    new Signx(asIntReg(src1), asIntReg(src1)).emit(masm);
                     new Sdivx(asIntReg(src1), crb.asIntConst(src2), asIntReg(dst)).emit(masm);
                     break;
                 case IAND:
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java	Wed Jul 09 09:36:13 2014 -0700
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCBitManipulationOp.java	Fri Jul 11 18:22:12 2014 -0700
@@ -54,16 +54,14 @@
 
     @Opcode private final IntrinsicOpcode opcode;
     @Def protected AllocatableValue result;
-    @Use({REG}) protected AllocatableValue input;
-    @Def({REG}) protected Value scratch;
+    @Alive({REG}) protected AllocatableValue input;
+    @Temp({REG}) protected Value scratch;
 
     public SPARCBitManipulationOp(IntrinsicOpcode opcode, AllocatableValue result, AllocatableValue input, LIRGeneratorTool gen) {
         this.opcode = opcode;
         this.result = result;
         this.input = input;
-        if (opcode == IntrinsicOpcode.IBSR || opcode == IntrinsicOpcode.LBSR) {
-            scratch = gen.newVariable(LIRKind.derive(input));
-        }
+        scratch = gen.newVariable(LIRKind.derive(input));
     }
 
     @Override
@@ -117,7 +115,7 @@
                 }
                 case LBSR: {
                     Kind lkind = input.getKind();
-                    assert lkind == Kind.Int;
+                    assert lkind == Kind.Long;
                     Register tmp = asRegister(scratch);
                     new Srlx(src, 1, tmp).emit(masm);
                     new Or(src, tmp, dst).emit(masm);
@@ -132,8 +130,7 @@
                     new Srlx(dst, 32, tmp).emit(masm);
                     new Or(dst, tmp, dst).emit(masm);
                     new Popc(dst, dst).emit(masm);
-                    new Mov(lkind.getBitCount(), tmp).emit(masm);
-                    new Sub(tmp, dst, dst).emit(masm);
+                    new Sub(dst, 1, dst).emit(masm); // This is required to fit the given structure.
                     break;
                 }
                 default:
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCByteSwapOp.java	Wed Jul 09 09:36:13 2014 -0700
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCByteSwapOp.java	Fri Jul 11 18:22:12 2014 -0700
@@ -22,31 +22,49 @@
  */
 package com.oracle.graal.lir.sparc;
 
+import static com.oracle.graal.api.code.ValueUtil.*;
+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.*;
+import com.oracle.graal.asm.sparc.SPARCAssembler.Asi;
 import com.oracle.graal.compiler.common.*;
 import com.oracle.graal.lir.*;
 import com.oracle.graal.lir.asm.*;
+import com.oracle.graal.lir.gen.*;
+import com.sun.javafx.binding.SelectBinding.*;
 
 @Opcode("BSWAP")
 public class SPARCByteSwapOp extends SPARCLIRInstruction {
 
-    @Def({OperandFlag.REG, OperandFlag.HINT}) protected Value result;
-    @Use protected Value input;
+    @Def({REG, HINT}) protected Value result;
+    @Use({REG}) protected Value input;
+    @Temp({REG}) protected Value tempIndex;
+    @Use({STACK}) protected StackSlot tmpSlot;
 
-    public SPARCByteSwapOp(Value result, Value input) {
+    public SPARCByteSwapOp(LIRGeneratorTool tool, Value result, Value input) {
         this.result = result;
         this.input = input;
+        this.tmpSlot = tool.getResult().getFrameMap().allocateSpillSlot(LIRKind.value(Kind.Long));
+        this.tempIndex = tool.newVariable(LIRKind.value(Kind.Long));
     }
 
     @Override
     public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
-        SPARCMove.move(crb, masm, result, input);
+        SPARCMove.move(crb, masm, tmpSlot, input);
         switch (input.getKind()) {
             case Int:
                 // masm.bswapl(ValueUtil.asIntReg(result));
             case Long:
-                // masm.bswapq(ValueUtil.asLongReg(result));
+                SPARCAddress addr = (SPARCAddress) crb.asAddress(tmpSlot);
+                if (addr.getIndex().equals(Register.None)) {
+                    Register tempReg = ValueUtil.asLongReg(tempIndex);
+                    new SPARCMacroAssembler.Setx(addr.getDisplacement(), tempReg, false).emit(masm);
+                    addr = new SPARCAddress(addr.getBase(), tempReg);
+                }
+                new SPARCAssembler.Ldxa(addr.getBase(), addr.getIndex(), asLongReg(result), Asi.ASI_PRIMARY_LITTLE).emit(masm);
+                break;
             default:
                 throw GraalInternalError.shouldNotReachHere();
         }
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java	Wed Jul 09 09:36:13 2014 -0700
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCCompare.java	Fri Jul 11 18:22:12 2014 -0700
@@ -60,10 +60,11 @@
         @Override
         protected void verify() {
             super.verify();
-
             // @formatter:off
-            assert  (name().startsWith("I") && (x.getKind() == Kind.Int || x.getKind()==Kind.Byte) &&
-                            (y.getKind().getStackKind() == Kind.Int || y.getKind().getStackKind() == Kind.Byte)) ||
+            assert  (name().startsWith("I") &&
+                            (!(x.getKind() == Kind.Int) || y.getKind().getStackKind() == Kind.Int) &&
+                            (!(x.getKind() == Kind.Short) || y.getKind().getStackKind() == Kind.Int) &&
+                            (!(x.getKind() == Kind.Byte) || 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) ||