# HG changeset patch # User Morris Meyer # Date 1369664769 14400 # Node ID 04911dff1c664d9c3bb82cb4635dc0ae1943c93e # Parent 5aedcaed6ccf47d23a870ac7aa27b4b4f7148363 SPARC logic and shift operations diff -r 5aedcaed6ccf -r 04911dff1c66 graal/com.oracle.graal.compiler.sparc.test/src/com/oracle/graal/compiler/sparc/test/LogicSPARCTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.sparc.test/src/com/oracle/graal/compiler/sparc/test/LogicSPARCTest.java Mon May 27 10:26:09 2013 -0400 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.sparc.test; + +import java.lang.reflect.Method; + +import org.junit.Test; + +public class LogicSPARCTest extends SPARCTestBase { + + @Test + public void testAnd() { + compile("testAnd2I"); + compile("testAnd2L"); + } + + public static int testAnd2I(int a, int b) { + return a & b; + } + + public static long testAnd2L(long a, long b) { + return a & b; + } + + @Test + public void testOr() { + compile("testOr2I"); + compile("testOr2L"); + } + + public static int testOr2I(int a, int b) { + return a | b; + } + + public static long testOr2L(long a, long b) { + return a | b; + } + + @Test + public void testXor() { + compile("testXor2I"); + compile("testXor2L"); + } + + public static int testXor2I(int a, int b) { + return a ^ b; + } + + public static long testXor2L(long a, long b) { + return a ^ b; + } + + @Test + public void testNot() { + compile("testNot1I"); + compile("testNot1L"); + } + + public static int testNot1I(int a) { + return ~a; + } + + public static long testNot1L(long a) { + return ~a; + } + + @Test + public void testShiftLeft() { + compile("testShiftLeft2I"); + compile("testShiftLeft2L"); + } + + public static int testShiftLeft2I(int a, int b) { + return a << b; + } + + public static long testShiftLeft2L(long a, int b) { + return a << b; + } + + @Test + public void testShiftRight() { + compile("testShiftRight2I"); + compile("testShiftRight2L"); + compile("testUnsignedShiftRight2I"); + compile("testUnsignedShiftRight2L"); + } + + public static int testShiftRight2I(int a, int b) { + return a >> b; + } + + public static long testShiftRight2L(long a, int b) { + return a >> b; + } + + public static int testUnsignedShiftRight2I(int a, int b) { + return a >>> b; + } + + public static long testUnsignedShiftRight2L(long a, long b) { + return a >>> b; + } + + public static void main(String[] args) { + LogicSPARCTest test = new LogicSPARCTest(); + for (Method m : LogicSPARCTest.class.getMethods()) { + String name = m.getName(); + if (m.getAnnotation(Test.class) == null && name.startsWith("test")) { + // CheckStyle: stop system..print check + System.out.println(name + ": \n" + new String(test.compile(name).getTargetCode())); + // CheckStyle: resume system..print check + } + } + } +} diff -r 5aedcaed6ccf -r 04911dff1c66 graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Sun May 26 18:16:28 2013 -0400 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Mon May 27 10:26:09 2013 -0400 @@ -48,6 +48,12 @@ import com.oracle.graal.lir.Variable; import com.oracle.graal.lir.StandardOp.*; import com.oracle.graal.lir.sparc.*; +import com.oracle.graal.lir.sparc.SPARCArithmetic.Op1Stack; +import com.oracle.graal.lir.sparc.SPARCArithmetic.Op2Stack; +import com.oracle.graal.lir.sparc.SPARCArithmetic.Op2Reg; +import com.oracle.graal.lir.sparc.SPARCArithmetic.ShiftOp; +import com.oracle.graal.lir.sparc.SPARCArithmetic.Unary1Op; +import com.oracle.graal.lir.sparc.SPARCArithmetic.Unary2Op; import com.oracle.graal.lir.sparc.SPARCControlFlow.ReturnOp; import com.oracle.graal.lir.sparc.SPARCControlFlow.SequentialSwitchOp; import com.oracle.graal.lir.sparc.SPARCControlFlow.TableSwitchOp; @@ -55,10 +61,6 @@ import com.oracle.graal.lir.sparc.SPARCMove.MoveFromRegOp; import com.oracle.graal.lir.sparc.SPARCMove.MoveToRegOp; import com.oracle.graal.lir.sparc.SPARCMove.StoreOp; -import com.oracle.graal.lir.sparc.SPARCArithmetic.Op1Stack; -import com.oracle.graal.lir.sparc.SPARCArithmetic.Op2Stack; -import com.oracle.graal.lir.sparc.SPARCArithmetic.Unary1Op; -import com.oracle.graal.lir.sparc.SPARCArithmetic.Unary2Op; import com.oracle.graal.nodes.BreakpointNode; import com.oracle.graal.nodes.DeoptimizingNode; import com.oracle.graal.nodes.DirectCallTargetNode; @@ -470,17 +472,51 @@ @Override public Value emitAnd(Value a, Value b) { - throw new InternalError("NYI"); + Variable result = newVariable(a.getKind()); + switch (a.getKind()) { + case Int: + append(new Op2Stack(IAND, result, a, loadNonConst(b))); + break; + case Long: + append(new Op2Stack(LAND, result, a, loadNonConst(b))); + break; + + default: + throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind()); + } + return result; } @Override public Value emitOr(Value a, Value b) { - throw new InternalError("NYI"); + Variable result = newVariable(a.getKind()); + switch (a.getKind()) { + case Int: + append(new Op2Stack(IOR, result, a, loadNonConst(b))); + break; + case Long: + append(new Op2Stack(LOR, result, a, loadNonConst(b))); + break; + default: + throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind()); + } + return result; } @Override public Value emitXor(Value a, Value b) { - throw new InternalError("NYI"); + Variable result = newVariable(a.getKind()); + switch (a.getKind()) { + case Int: + append(new Op2Stack(IXOR, result, a, loadNonConst(b))); + break; + case Long: + append(new Op2Stack(LXOR, result, a, loadNonConst(b))); + break; + default: + throw GraalInternalError.shouldNotReachHere(); + } + return result; } @Override diff -r 5aedcaed6ccf -r 04911dff1c66 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java --- a/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Sun May 26 18:16:28 2013 -0400 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCArithmetic.java Mon May 27 10:26:09 2013 -0400 @@ -41,7 +41,9 @@ import static com.oracle.graal.asm.sparc.SPARCAssembler.Or; import static com.oracle.graal.asm.sparc.SPARCAssembler.Sdivx; import static com.oracle.graal.asm.sparc.SPARCAssembler.Sll; +import static com.oracle.graal.asm.sparc.SPARCAssembler.Sllx; import static com.oracle.graal.asm.sparc.SPARCAssembler.Srl; +import static com.oracle.graal.asm.sparc.SPARCAssembler.Srlx; import static com.oracle.graal.asm.sparc.SPARCAssembler.Sra; import static com.oracle.graal.asm.sparc.SPARCAssembler.Sub; import static com.oracle.graal.asm.sparc.SPARCAssembler.Xor; @@ -56,83 +58,31 @@ import com.oracle.graal.lir.LIRFrameState; import com.oracle.graal.lir.asm.TargetMethodAssembler; +//@formatter:off public enum SPARCArithmetic { - IADD, - ISUB, - IMUL, - IDIV, - IDIVREM, - IREM, - IUDIV, - IUREM, - IAND, - IOR, - IXOR, - ISHL, - ISHR, - IUSHR, - LADD, - LSUB, - LMUL, - LDIV, - LDIVREM, - LREM, - LUDIV, - LUREM, - LAND, - LOR, - LXOR, - LSHL, - LSHR, - LUSHR, - FADD, - FSUB, - FMUL, - FDIV, - FREM, - FAND, - FOR, - FXOR, - DADD, - DSUB, - DMUL, - DDIV, - DREM, - DAND, - DOR, - DXOR, - INEG, - LNEG, - FNEG, - DNEG, - I2L, - L2I, - I2B, - I2C, - I2S, - F2D, - D2F, - I2F, - I2D, - F2I, - D2I, - L2F, - L2D, - F2L, - D2L, - MOV_I2F, - MOV_L2D, - MOV_F2I, - MOV_D2L; + //@formatter:off + IADD, ISUB, IMUL, IDIV, IDIVREM, IREM, IUDIV, IUREM, IAND, IOR, IXOR, ISHL, ISHR, IUSHR, + LADD, LSUB, LMUL, LDIV, LDIVREM, LREM, LUDIV, LUREM, LAND, LOR, LXOR, LSHL, LSHR, LUSHR, + FADD, FSUB, FMUL, FDIV, FREM, FAND, FOR, FXOR, + DADD, DSUB, DMUL, DDIV, DREM, DAND, DOR, DXOR, + INEG, LNEG, FNEG, DNEG, + I2L, L2I, I2B, I2C, I2S, + F2D, D2F, + I2F, I2D, F2I, D2I, + L2F, L2D, F2L, D2L, + MOV_I2F, MOV_L2D, MOV_F2I, MOV_D2L; /** * Unary operation with separate source and destination operand. */ public static class Unary2Op extends SPARCLIRInstruction { - @Opcode private final SPARCArithmetic opcode; - @Def({REG}) protected AllocatableValue result; - @Use({REG, STACK}) protected AllocatableValue x; + @Opcode + private final SPARCArithmetic opcode; + @Def({ REG }) + protected AllocatableValue result; + @Use({ REG, STACK }) + protected AllocatableValue x; public Unary2Op(SPARCArithmetic opcode, AllocatableValue result, AllocatableValue x) { this.opcode = opcode; @@ -152,9 +102,12 @@ */ public static class Unary1Op extends SPARCLIRInstruction { - @Opcode private final SPARCArithmetic opcode; - @Def({REG, HINT}) protected AllocatableValue result; - @Use({REG, STACK}) protected AllocatableValue x; + @Opcode + private final SPARCArithmetic opcode; + @Def({ REG, HINT }) + protected AllocatableValue result; + @Use({ REG, STACK }) + protected AllocatableValue x; public Unary1Op(SPARCArithmetic opcode, AllocatableValue result, AllocatableValue x) { this.opcode = opcode; @@ -170,9 +123,12 @@ public static class Op1Stack extends SPARCLIRInstruction { - @Opcode private final SPARCArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; + @Opcode + private final SPARCArithmetic opcode; + @Def({ REG, HINT }) + protected Value result; + @Use({ REG, STACK, CONST }) + protected Value x; public Op1Stack(SPARCArithmetic opcode, Value result, Value x) { this.opcode = opcode; @@ -188,10 +144,14 @@ public static class Op2Stack extends SPARCLIRInstruction { - @Opcode private final SPARCArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Alive({REG, STACK, CONST}) protected Value y; + @Opcode + private final SPARCArithmetic opcode; + @Def({ REG, HINT }) + protected Value result; + @Use({ REG, STACK, CONST }) + protected Value x; + @Alive({ REG, STACK, CONST }) + protected Value y; public Op2Stack(SPARCArithmetic opcode, Value result, Value x, Value y) { this.opcode = opcode; @@ -214,10 +174,14 @@ public static class Op2Reg extends SPARCLIRInstruction { - @Opcode private final SPARCArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Alive({REG, CONST}) protected Value y; + @Opcode + private final SPARCArithmetic opcode; + @Def({ REG, HINT }) + protected Value result; + @Use({ REG, STACK, CONST }) + protected Value x; + @Alive({ REG, CONST }) + protected Value y; public Op2Reg(SPARCArithmetic opcode, Value result, Value x, Value y) { this.opcode = opcode; @@ -240,10 +204,14 @@ public static class ShiftOp extends SPARCLIRInstruction { - @Opcode private final SPARCArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Alive({REG, CONST}) protected Value y; + @Opcode + private final SPARCArithmetic opcode; + @Def({ REG, HINT }) + protected Value result; + @Use({ REG, STACK, CONST }) + protected Value x; + @Alive({ REG, CONST }) + protected Value y; public ShiftOp(SPARCArithmetic opcode, Value result, Value x, Value y) { this.opcode = opcode; @@ -268,192 +236,217 @@ @SuppressWarnings("unused") protected static void emit(SPARCAssembler masm, SPARCArithmetic opcode, Value result) { switch (opcode) { - case L2I: - new Sra(masm, asLongReg(result), 0, asIntReg(result)); - break; - case I2C: - new Sll(masm, asIntReg(result), 16, asIntReg(result)); - new Srl(masm, asIntReg(result), 16, asIntReg(result)); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); + case L2I: + new And(masm, asIntReg(result), -1, asIntReg(result)); + break; + case I2C: + new Sll(masm, asIntReg(result), 16, asIntReg(result)); + new Srl(masm, asIntReg(result), 16, asIntReg(result)); + break; + default: + throw GraalInternalError.shouldNotReachHere("missing: " + opcode); } } @SuppressWarnings("unused") - public static void emit(TargetMethodAssembler tasm, SPARCAssembler masm, SPARCArithmetic opcode, Value dst, Value src1, Value src2, LIRFrameState info) { + public static void emit(TargetMethodAssembler tasm, SPARCAssembler masm, + SPARCArithmetic opcode, Value dst, Value src1, Value src2, LIRFrameState info) { int exceptionOffset = -1; if (isConstant(src1)) { switch (opcode) { - case ISUB: - assert is_simm13(tasm.asIntConst(src1)); - new Add(masm, asIntReg(src2), -(tasm.asIntConst(src1)), asIntReg(dst)); - break; - case IAND: - throw new InternalError("NYI"); - case IDIV: - assert is_simm13(tasm.asIntConst(src1)); - throw new InternalError("NYI"); - // new Sdivx(masm, asIntReg(src1), asIntReg(src2), - // asIntReg(dst)); - case FSUB: - throw new InternalError("NYI"); - case FDIV: - throw new InternalError("NYI"); - case DSUB: - throw new InternalError("NYI"); - case DDIV: - throw new InternalError("NYI"); - default: - throw GraalInternalError.shouldNotReachHere(); + case ISUB: + assert is_simm13(tasm.asIntConst(src1)); + new Add(masm, asIntReg(src2), -(tasm.asIntConst(src1)), + asIntReg(dst)); + break; + case IAND: + throw new InternalError("NYI"); + case IDIV: + assert is_simm13(tasm.asIntConst(src1)); + throw new InternalError("NYI"); + // new Sdivx(masm, asIntReg(src1), asIntReg(src2), + // asIntReg(dst)); + case FSUB: + throw new InternalError("NYI"); + case FDIV: + throw new InternalError("NYI"); + case DSUB: + throw new InternalError("NYI"); + case DDIV: + throw new InternalError("NYI"); + default: + throw GraalInternalError.shouldNotReachHere(); } } else if (isConstant(src2)) { switch (opcode) { - case IADD: - assert is_simm13(tasm.asIntConst(src2)); - new Add(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case ISUB: - assert is_simm13(tasm.asIntConst(src2)); - new Sub(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case IMUL: - assert is_simm13(tasm.asIntConst(src2)); - new Mulx(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case IAND: - assert is_simm13(tasm.asIntConst(src2)); - new And(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case ISHL: - assert is_simm13(tasm.asIntConst(src2)); - new Sll(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case ISHR: - assert is_simm13(tasm.asIntConst(src2)); - new Srl(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case IUSHR: - assert is_simm13(tasm.asIntConst(src2)); - new Sra(masm, asIntReg(src1), tasm.asIntConst(src2), asIntReg(dst)); - break; - case IXOR: - throw new InternalError("NYI"); - case LXOR: - throw new InternalError("NYI"); - case LUSHR: - throw new InternalError("NYI"); - case FADD: - throw new InternalError("NYI"); - case FMUL: - throw new InternalError("NYI"); - case FDIV: - throw new InternalError("NYI"); - case DADD: - throw new InternalError("NYI"); - case DMUL: - throw new InternalError("NYI"); - case DDIV: - throw new InternalError("NYI"); - default: - throw GraalInternalError.shouldNotReachHere(); + case IADD: + assert is_simm13(tasm.asIntConst(src2)); + new Add(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case ISUB: + assert is_simm13(tasm.asIntConst(src2)); + new Sub(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case IMUL: + assert is_simm13(tasm.asIntConst(src2)); + new Mulx(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case IAND: + assert is_simm13(tasm.asIntConst(src2)); + new And(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case ISHL: + assert is_simm13(tasm.asIntConst(src2)); + new Sll(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case ISHR: + assert is_simm13(tasm.asIntConst(src2)); + new Srl(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case IUSHR: + assert is_simm13(tasm.asIntConst(src2)); + new Sra(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case IXOR: + assert is_simm13(tasm.asIntConst(src2)); + new Xor(masm, asIntReg(src1), tasm.asIntConst(src2), + asIntReg(dst)); + break; + case LXOR: + assert is_simm13(tasm.asIntConst(src2)); + new Add(masm, asLongReg(src1), tasm.asIntConst(src2), + asLongReg(dst)); + break; + case LUSHR: + throw new InternalError("NYI"); + case FADD: + throw new InternalError("NYI"); + case FMUL: + throw new InternalError("NYI"); + case FDIV: + throw new InternalError("NYI"); + case DADD: + throw new InternalError("NYI"); + case DMUL: + throw new InternalError("NYI"); + case DDIV: + throw new InternalError("NYI"); + default: + throw GraalInternalError.shouldNotReachHere(); } } else { switch (opcode) { - case IADD: - new Add(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case ISUB: - new Sub(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IMUL: - new Mulx(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IDIV: - new Sdivx(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IAND: - new And(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IOR: - new Or(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IXOR: - new Xor(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case ISHL: - new Sll(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case ISHR: - new Srl(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IUSHR: - new Sra(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); - break; - case IREM: - throw new InternalError("NYI"); - case LADD: - new Add(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LSUB: - new Sub(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LMUL: - new Mulx(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LDIV: - new Sdivx(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LAND: - new And(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LOR: - new Or(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LXOR: - new Xor(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LSHL: - new Sll(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LSHR: - new Srl(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); - break; - case LUSHR: - new Sra(masm, asLongReg(src1), asLongReg(src2), asIntReg(dst)); - break; - case LREM: - throw new InternalError("NYI"); - case FADD: - new Fadds(masm, asFloatReg(src1), asFloatReg(src2), asFloatReg(dst)); - break; - case FSUB: - new Fsubs(masm, asFloatReg(src1), asFloatReg(src2), asFloatReg(dst)); - break; - case FMUL: - new Fmuls(masm, asFloatReg(src1), asFloatReg(src2), asFloatReg(dst)); - break; - case FDIV: - new Fdivs(masm, asFloatReg(src1), asFloatReg(src2), asFloatReg(dst)); - break; - case FREM: - throw new InternalError("NYI"); - case DADD: - new Faddd(masm, asDoubleReg(src1), asDoubleReg(src2), asDoubleReg(dst)); - break; - case DSUB: - new Fsubd(masm, asDoubleReg(src1), asDoubleReg(src2), asDoubleReg(dst)); - break; - case DMUL: - new Fmuld(masm, asDoubleReg(src1), asDoubleReg(src2), asDoubleReg(dst)); - break; - case DDIV: - new Fdivd(masm, asDoubleReg(src1), asDoubleReg(src2), asDoubleReg(dst)); - break; - case DREM: - throw new InternalError("NYI"); - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); + case IADD: + new Add(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case ISUB: + new Sub(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IMUL: + new Mulx(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IDIV: + new Sdivx(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IAND: + new And(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IOR: + new Or(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IXOR: + new Xor(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case ISHL: + new Sll(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case ISHR: + new Srl(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IUSHR: + new Sra(masm, asIntReg(src1), asIntReg(src2), asIntReg(dst)); + break; + case IREM: + throw new InternalError("NYI"); + case LADD: + new Add(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LSUB: + new Sub(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LMUL: + new Mulx(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LDIV: + new Sdivx(masm, asLongReg(src1), asLongReg(src2), + asLongReg(dst)); + break; + case LAND: + new And(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LOR: + new Or(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LXOR: + new Xor(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LSHL: + new Sll(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LSHR: + new Srl(masm, asLongReg(src1), asLongReg(src2), asLongReg(dst)); + break; + case LUSHR: + new Sra(masm, asLongReg(src1), asIntReg(src2), asLongReg(dst)); + break; + case LREM: + throw new InternalError("NYI"); + case FADD: + new Fadds(masm, asFloatReg(src1), asFloatReg(src2), + asFloatReg(dst)); + break; + case FSUB: + new Fsubs(masm, asFloatReg(src1), asFloatReg(src2), + asFloatReg(dst)); + break; + case FMUL: + new Fmuls(masm, asFloatReg(src1), asFloatReg(src2), + asFloatReg(dst)); + break; + case FDIV: + new Fdivs(masm, asFloatReg(src1), asFloatReg(src2), + asFloatReg(dst)); + break; + case FREM: + throw new InternalError("NYI"); + case DADD: + new Faddd(masm, asDoubleReg(src1), asDoubleReg(src2), + asDoubleReg(dst)); + break; + case DSUB: + new Fsubd(masm, asDoubleReg(src1), asDoubleReg(src2), + asDoubleReg(dst)); + break; + case DMUL: + new Fmuld(masm, asDoubleReg(src1), asDoubleReg(src2), + asDoubleReg(dst)); + break; + case DDIV: + new Fdivd(masm, asDoubleReg(src1), asDoubleReg(src2), + asDoubleReg(dst)); + break; + case DREM: + throw new InternalError("NYI"); + default: + throw GraalInternalError.shouldNotReachHere("missing: " + + opcode); } } @@ -464,41 +457,51 @@ } @SuppressWarnings("unused") - public static void emit(TargetMethodAssembler tasm, SPARCAssembler masm, SPARCArithmetic opcode, Value dst, Value src, LIRFrameState info) { + public static void emit(TargetMethodAssembler tasm, SPARCAssembler masm, + SPARCArithmetic opcode, Value dst, Value src, LIRFrameState info) { int exceptionOffset = -1; if (isRegister(src)) { switch (opcode) { - case I2L: - new Sra(masm, asIntReg(src), 0, asLongReg(dst)); - break; - case I2B: - new Sll(masm, asIntReg(src), 24, asIntReg(src)); - new Srl(masm, asIntReg(dst), 24, asIntReg(src)); - break; - case I2F: - new Fstoi(masm, asIntReg(src), asFloatReg(dst)); - break; - case I2D: - new Fdtoi(masm, asIntReg(src), asDoubleReg(dst)); - break; - case FNEG: - new Fnegs(masm, asFloatReg(src), asFloatReg(dst)); - break; - case DNEG: - new Fnegd(masm, asDoubleReg(src), asDoubleReg(dst)); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); + case I2L: + new Sra(masm, asIntReg(src), 0, asLongReg(dst)); + break; + case I2B: + new Sll(masm, asIntReg(src), 24, asIntReg(src)); + new Srl(masm, asIntReg(dst), 24, asIntReg(src)); + break; + case I2F: + new Fstoi(masm, asIntReg(src), asFloatReg(dst)); + break; + case I2D: + new Fdtoi(masm, asIntReg(src), asDoubleReg(dst)); + break; + case FNEG: + new Fnegs(masm, asFloatReg(src), asFloatReg(dst)); + break; + case DNEG: + new Fnegd(masm, asDoubleReg(src), asDoubleReg(dst)); + break; + case LSHL: + new Sllx(masm, asLongReg(dst), asIntReg(src), asLongReg(dst)); + break; + case LSHR: + new Srlx(masm, asLongReg(dst), asIntReg(src), asLongReg(dst)); + break; + default: + throw GraalInternalError.shouldNotReachHere("missing: " + + opcode); } } else if (isConstant(src)) { switch (opcode) { - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); + default: + throw GraalInternalError.shouldNotReachHere("missing: " + + opcode); } } else { switch (opcode) { - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); + default: + throw GraalInternalError.shouldNotReachHere("missing: " + + opcode); } } @@ -516,11 +519,71 @@ } private static void verifyKind(SPARCArithmetic opcode, Value result, Value x, Value y) { - if (((opcode.name().startsWith("I") && result.getKind() == Kind.Int && x.getKind().getStackKind() == Kind.Int && y.getKind().getStackKind() == Kind.Int) || - (opcode.name().startsWith("L") && result.getKind() == Kind.Long && x.getKind() == Kind.Long && y.getKind() == Kind.Long) || - (opcode.name().startsWith("F") && result.getKind() == Kind.Float && x.getKind() == Kind.Float && y.getKind() == Kind.Float) || (opcode.name().startsWith("D") && - result.getKind() == Kind.Double && x.getKind() == Kind.Double && y.getKind() == Kind.Double)) == false) { - throw GraalInternalError.shouldNotReachHere("opcode: " + opcode.name() + " x: " + x.getKind() + " y: " + y.getKind()); + Kind rk; + Kind xk; + Kind yk; + Kind xsk; + Kind ysk; + + switch (opcode) { + case IADD: + case ISUB: + case IMUL: + case IDIV: + case IREM: + case IAND: + case IOR: + case IXOR: + case ISHL: + case ISHR: + case IUSHR: + rk = result.getKind(); + xsk = x.getKind().getStackKind(); + ysk = y.getKind().getStackKind(); + + assert rk == Kind.Int && xsk == Kind.Int && ysk == Kind.Int; + break; + case LADD: + case LSUB: + case LMUL: + case LDIV: + case LREM: + case LAND: + case LOR: + case LXOR: + case LSHL: + case LSHR: + case LUSHR: + rk = result.getKind(); + xk = x.getKind(); + yk = y.getKind(); + + assert rk == Kind.Long && xk == Kind.Long && yk == Kind.Long; + break; + case FADD: + case FSUB: + case FMUL: + case FDIV: + case FREM: + rk = result.getKind(); + xk = x.getKind(); + yk = y.getKind(); + + assert rk == Kind.Float && xk == Kind.Float && yk == Kind.Float; + break; + case DADD: + case DSUB: + case DMUL: + case DDIV: + case DREM: + rk = result.getKind(); + xk = x.getKind(); + yk = y.getKind(); + + assert rk == Kind.Double && xk == Kind.Double && yk == Kind.Double; + break; + default: + throw new InternalError("NYI: " + opcode); } } }