changeset 16644:fa14ceabaf15

[SPARC] Implement irem
author Stefan Anzinger <stefan.anzinger@gmail.com>
date Fri, 25 Jul 2014 20:48:28 -0700
parents b1af1727a783
children 8c70d65ec04a
files graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_irem.java graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java
diffstat 2 files changed, 56 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_irem.java	Thu Jul 24 16:03:29 2014 -0700
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/bytecode/BC_irem.java	Fri Jul 25 20:48:28 2014 -0700
@@ -34,6 +34,16 @@
         return a % b;
     }
 
+    // Left as constant
+    public static int test2(int b) {
+        return 13 % b;
+    }
+
+    // Right as constant
+    public static int test3(int a) {
+        return a % 13;
+    }
+
     @Test
     public void run0() throws Throwable {
         runTest("test", 1, 2);
@@ -54,4 +64,33 @@
         runTest("test", 135, 7);
     }
 
+    @Test
+    public void run20() throws Throwable {
+        runTest("test2", 2);
+    }
+
+    @Test
+    public void run21() throws Throwable {
+        runTest("test2", 20000000);
+    }
+
+    @Test
+    public void run22() throws Throwable {
+        runTest("test2", -20000000);
+    }
+
+    @Test
+    public void run30() throws Throwable {
+        runTest("test3", 2);
+    }
+
+    @Test
+    public void run31() throws Throwable {
+        runTest("test3", 200000000);
+    }
+
+    @Test
+    public void run32() throws Throwable {
+        runTest("test3", -200000000);
+    }
 }
--- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java	Thu Jul 24 16:03:29 2014 -0700
+++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java	Fri Jul 25 20:48:28 2014 -0700
@@ -250,8 +250,8 @@
         @Def({REG}) protected Value result;
         @Use({REG, CONST}) protected Value x;
         @Alive({REG, CONST}) protected Value y;
-        @Def({REG}) protected Value scratch1;
-        @Def({REG}) protected Value scratch2;
+        @Temp({REG}) protected Value scratch1;
+        @Temp({REG}) protected Value scratch2;
         @State protected LIRFrameState state;
 
         public RemOp(SPARCArithmetic opcode, Value result, Value x, Value y, LIRFrameState state, LIRGeneratorTool gen) {
@@ -549,11 +549,6 @@
                 default:
                     throw GraalInternalError.shouldNotReachHere("not implemented");
             }
-        } else if (isConstant(src1)) {
-            switch (opcode) {
-                default:
-                    throw GraalInternalError.shouldNotReachHere();
-            }
         } else if (isConstant(src2)) {
             switch (opcode) {
                 case IREM:
@@ -577,18 +572,27 @@
                     throw GraalInternalError.shouldNotReachHere();
             }
         } else {
+            Value srcLeft = src1;
             switch (opcode) {
                 case LREM:
+                    if (isConstant(src1)) {
+                        new Setx(crb.asLongConst(src1), asLongReg(scratch2), false).emit(masm);
+                        srcLeft = scratch2;
+                    }
                     exceptionOffset = masm.position();
-                    new Sdivx(asLongReg(src1), asLongReg(src2), asLongReg(scratch1)).emit(masm);
-                    new Mulx(asLongReg(scratch1), asLongReg(src2), asLongReg(scratch2)).emit(masm);
-                    new Sub(asLongReg(src1), asLongReg(scratch2), asLongReg(dst)).emit(masm);
+                    new Sdivx(asLongReg(srcLeft), asLongReg(src2), asLongReg(scratch1)).emit(masm);
+                    new Mulx(asLongReg(scratch1), asLongReg(src2), asLongReg(scratch1)).emit(masm);
+                    new Sub(asLongReg(srcLeft), asLongReg(scratch1), asLongReg(dst)).emit(masm);
                     break;
                 case IREM:
+                    if (isConstant(src1)) {
+                        new Setx(crb.asIntConst(src1), asIntReg(scratch2), false).emit(masm);
+                        srcLeft = scratch2;
+                    }
                     exceptionOffset = masm.position();
-                    new Sdivx(asIntReg(src1), asIntReg(src2), asIntReg(scratch1)).emit(masm);
-                    new Mulx(asIntReg(scratch1), asIntReg(src2), asIntReg(scratch2)).emit(masm);
-                    new Sub(asIntReg(src1), asIntReg(scratch2), asIntReg(dst)).emit(masm);
+                    new Sdivx(asIntReg(srcLeft), asIntReg(src2), asIntReg(scratch1)).emit(masm);
+                    new Mulx(asIntReg(scratch1), asIntReg(src2), asIntReg(scratch1)).emit(masm);
+                    new Sub(asIntReg(srcLeft), asIntReg(scratch1), asIntReg(dst)).emit(masm);
                     break;
                 case LUREM:
                     throw GraalInternalError.unimplemented();