# HG changeset patch # User Doug Simon # Date 1383303982 -3600 # Node ID c73b857b1be94d0c7a00a3b0bafe76a38621d5f9 # Parent 04c74433529a7f5c4caea44d536aeaf3e4dff809 Adds support to the HSAIL backend to generate code for bitwise right shift (>>), bitwise NOT (~), and arithmetic negation Contributed-by: Vasanth Venkatachalam diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAssembler.java --- a/graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAssembler.java Thu Oct 31 18:45:31 2013 +0100 +++ b/graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAssembler.java Fri Nov 01 12:06:22 2013 +0100 @@ -225,7 +225,7 @@ public static final String getArgTypeBitwiseLogical(Value src) { String length = getArgType(src); - String prefix = "b" + (length.endsWith("64") ? "64" : "32"); + String prefix = "_b" + (length.endsWith("64") ? "64" : "32"); return prefix; } @@ -268,10 +268,6 @@ emitString(prefix + getArgType(dest) + "_" + getArgType(src) + " " + HSAIL.mapRegister(dest) + ", " + HSAIL.mapRegister(src) + ";"); } - public void emitArg1(String mnemonic, Value dest, Value src) { - emitString(mnemonic + "_" + getArgType(src) + " " + HSAIL.mapRegister(dest) + ", " + mapRegOrConstToString(src) + ";" + ""); - } - public static String mapAddress(HSAILAddress addr) { return "[$d" + addr.getBase().encoding() + " + " + addr.getDisplacement() + "]"; } @@ -304,40 +300,84 @@ } - public final void emit(String mnemonic, Value dest, Value src0, Value src1) { + /** + * Emits an instruction. + * + * @param mnemonic the instruction mnemonic + * @param dest the destination operand + * @param sources the source operands + */ + public final void emit(String mnemonic, Value dest, Value... sources) { String prefix = getArgType(dest); - emit(mnemonic + "_" + prefix, dest, "", src0, src1); - } - - public final void emitForceUnsigned(String mnemonic, Value dest, Value src0, Value src1) { - String prefix = getArgTypeForceUnsigned(dest); - emit(mnemonic + "_" + prefix, dest, "", src0, src1); + emitTextFormattedInstruction(mnemonic + "_" + prefix, dest, sources); } - private void emit(String instr, Value dest, String controlRegString, Value src0, Value src1) { - assert (!isConstant(dest)); - emitString(String.format("%s %s, %s%s, %s;", instr, HSAIL.mapRegister(dest), controlRegString, mapRegOrConstToString(src0), mapRegOrConstToString(src1))); + /** + * Emits an unsigned instruction. + * + * @param mnemonic the instruction mnemonic + * @param dest the destination argument + * @param sources the source arguments + * + */ + public final void emitForceUnsigned(String mnemonic, Value dest, Value... sources) { + String prefix = getArgTypeForceUnsigned(dest); + emitTextFormattedInstruction(mnemonic + "_" + prefix, dest, sources); } - private void emit(String instr, Value dest, Value src0, Value src1, Value src2) { - assert (!isConstant(dest)); - emitString(String.format("%s %s, %s, %s, %s;", instr, HSAIL.mapRegister(dest), mapRegOrConstToString(src0), mapRegOrConstToString(src1), mapRegOrConstToString(src2))); - } - - public final void cmovCommon(Value dest, Value trueReg, Value falseReg, int width) { - String instr = (width == 32 ? "cmov_b32" : "cmov_b64"); - emit(instr, dest, "$c0, ", trueReg, falseReg); + /** + * Emits an instruction for a bitwise logical operation. + * + * @param mnemonic the instruction mnemonic + * @param dest the destination + * @param sources the source operands + */ + public final void emitForceBitwise(String mnemonic, Value dest, Value... sources) { + String prefix = getArgTypeBitwiseLogical(dest); + emitTextFormattedInstruction(mnemonic + prefix, dest, sources); } /** + * Central helper routine that emits a text formatted HSAIL instruction via call to + * AbstractAssembler.emitString. All the emit routines in the assembler end up calling this one. * - * Emit code to generate a 32-bit or 64-bit bitwise logical operation. Used to generate bitwise - * AND, OR and XOR. + * @param instr the full instruction mnenomics including any prefixes + * @param dest the destination operand + * @param sources the source operand */ - public final void emitBitwiseLogical(String mnemonic, Value dest, Value src0, Value src1) { - // Bitwise ops don't use a control register so the fourth arg is empty. - String prefix = getArgTypeBitwiseLogical(dest); - emit(mnemonic + "_" + prefix, dest, "", src0, src1); + private void emitTextFormattedInstruction(String instr, Value dest, Value... sources) { + /** + * Destination can't be a constant and no instruction has > 3 source operands. + */ + assert (!isConstant(dest) && sources.length <= 3); + switch (sources.length) { + case 3: + // Emit an instruction with three source operands. + emitString(String.format("%s %s, %s, %s, %s;", instr, HSAIL.mapRegister(dest), mapRegOrConstToString(sources[0]), mapRegOrConstToString(sources[1]), mapRegOrConstToString(sources[2]))); + break; + case 2: + // Emit an instruction with two source operands. + emitString(String.format("%s %s, %s, %s;", instr, HSAIL.mapRegister(dest), mapRegOrConstToString(sources[0]), mapRegOrConstToString(sources[1]))); + break; + default: + // Emit an instruction with one source operand. + emitString(String.format("%s %s, %s;", instr, HSAIL.mapRegister(dest), mapRegOrConstToString(sources[0]))); + break; + } + } + + /** + * Emits a conditional move instruction. + * + * @param dest the destination operand storing result of the move + * @param trueReg the register that should be copied to dest if the condition is true + * @param falseReg the register that should be copied to dest if the condition is false + * @param width the width of the instruction (32 or 64 bits) + */ + public final void emitConditionalMove(Value dest, Value trueReg, Value falseReg, int width) { + assert (!isConstant(dest)); + String instr = (width == 32 ? "cmov_b32" : "cmov_b64"); + emitString(String.format("%s %s, %s%s, %s;", instr, HSAIL.mapRegister(dest), "$c0, ", mapRegOrConstToString(trueReg), mapRegOrConstToString(falseReg))); } /** @@ -351,12 +391,12 @@ // only use add if result is not starting as null (unsigned compare) emitCompare(result, Constant.forLong(0), "eq", false, true); emit("add", result, result, Constant.forLong(narrowOopBase)); - cmovCommon(result, Constant.forLong(0), result, 64); + emitConditionalMove(result, Constant.forLong(0), result, 64); } else { // only use mad if result is not starting as null (unsigned compare) emitCompare(result, Constant.forLong(0), "eq", false, true); - emit("mad_u64 ", result, result, Constant.forInt(1 << narrowOopShift), Constant.forLong(narrowOopBase)); - cmovCommon(result, Constant.forLong(0), result, 64); + emitTextFormattedInstruction("mad_u64 ", result, result, Constant.forInt(1 << narrowOopShift), Constant.forLong(narrowOopBase)); + emitConditionalMove(result, Constant.forLong(0), result, 64); } } @@ -369,13 +409,18 @@ // only use sub if result is not starting as null (unsigned compare) emitCompare(result, Constant.forLong(0), "eq", false, true); emit("sub", result, result, Constant.forLong(narrowOopBase)); - cmovCommon(result, Constant.forLong(0), result, 64); + emitConditionalMove(result, Constant.forLong(0), result, 64); } if (narrowOopShift != 0) { emit("shr", result, result, Constant.forInt(narrowOopShift)); } } + /** + * Emits a comment. Useful for debugging purposes. + * + * @param comment + */ public void emitComment(String comment) { emitString(comment); } diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleNegTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleNegTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests negation of double values. Generates a neg_f64 instruction. + */ +public class DoubleNegTest extends GraalKernelTester { + + static final int num = 20; + // Output array storing the results of negation operations. + @Result protected double[] outArray = new double[num]; + + /** + * The static "kernel" method we will be testing. This method performs a negation operation on + * an element of an input array and writes the result to the corresponding index of an output + * array. By convention the gid is the last parameter. + * + * @param out the output array. + * @param ina the input array. + * @param gid the parameter used to index into the input and output arrays. + */ + public static void run(double[] out, double[] ina, int gid) { + out[gid] = -(ina[gid]); + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the input and output arrays passed to the run routine. + * + * @param in the input array. + */ + void setupArrays(double[] in) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + double[] inArray = new double[num]; + setupArrays(inArray); + dispatchMethodKernel(num, outArray, inArray); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatNegTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatNegTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests negation of float values. Generates a neg_f32 instruction. + */ +public class FloatNegTest extends GraalKernelTester { + + static final int num = 20; + // Output array storing the results of negation operations. + @Result protected float[] outArray = new float[num]; + + /** + * The static "kernel" method we will be testing. This method performs a negation operation on + * an element of an input array and writes the result to the corresponding index of an output + * array. By convention the gid is the last parameter. + * + * @param out the output array. + * @param ina the input array. + * @param gid the parameter used to index into the input and output arrays. + */ + public static void run(float[] out, float[] ina, int gid) { + out[gid] = -(ina[gid]); + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the input and output arrays passed to the run routine. + * + * @param in the input array. + */ + void setupArrays(float[] in) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + float[] inArray = new float[num]; + setupArrays(inArray); + dispatchMethodKernel(num, outArray, inArray); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseNotTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseNotTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests bitwise not of an integer. + */ +public class IntBitwiseNotTest extends GraalKernelTester { + + static final int num = 20; + // Output array storing the results of the operations. + @Result protected int[] outArray = new int[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise not operation + * on an element of an input array and writes the result to the corresponding index of an output + * array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(int[] out, int[] ina, int gid) { + out[gid] = ~(ina[gid]); + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the input and output arrays passed to the run routine. + * + * @param in the input array + */ + void setupArrays(int[] in) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + int[] inArray = new int[num]; + setupArrays(inArray); + dispatchMethodKernel(num, outArray, inArray); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftLeftTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftLeftTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; + +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests bitwise shift left of int values. Generates an shl_s32 instruction. + */ +public class IntBitwiseShiftLeftTest extends GraalKernelTester { + + static final int num = 100; + // Output array containing the results of shift operations. + @Result protected int[] outArray = new int[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise shift left + * operation on each element of an input array and writes each result to the corresponding index + * of an output array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param shiftAmount an array of values used for the shift magnitude + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(int[] out, int[] ina, int[] shiftAmount, int gid) { + out[gid] = ina[gid] << shiftAmount[gid]; + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the arrays passed to the run routine. + * + * We do this in such a way that the input arrays contain a mix of negative and positive values. + * As a result, the work items will exercise all the different combinations for the sign of the + * value being shifted and the sign of the shift magnitude. + * + * @param in the input array + */ + void setupArrays(int[] in, int[] shiftAmount) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + shiftAmount[i] = (i & 1) == 0 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + int[] inArray = new int[num]; + int[] shiftAmount = new int[num]; + setupArrays(inArray, shiftAmount); + dispatchMethodKernel(num, outArray, inArray, shiftAmount); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; + +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests bitwise shift right of int values. Generates an shr_s32 instruction. + */ +public class IntBitwiseShiftRightTest extends GraalKernelTester { + + static final int num = 100; + // Output array containing the results of shift operations. + @Result protected int[] outArray = new int[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise shift left + * operation on each element of an input array and writes each result to the corresponding index + * of an output array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param shiftAmount an array of values used for the shift magnitude + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(int[] out, int[] ina, int[] shiftAmount, int gid) { + out[gid] = ina[gid] >> shiftAmount[gid]; + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the arrays passed to the run routine. + * + * We do this in such a way that the input arrays contain a mix of negative and positive values. + * As a result, the work items will exercise all the different combinations for the sign of the + * value being shifted and the sign of the shift magnitude. + * + * @param in the input array + */ + void setupArrays(int[] in, int[] shiftAmount) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + shiftAmount[i] = (i & 1) == 0 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + int[] inArray = new int[num]; + int[] shiftAmount = new int[num]; + setupArrays(inArray, shiftAmount); + dispatchMethodKernel(num, outArray, inArray, shiftAmount); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightUnsignedTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightUnsignedTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests unsigned bitwise shift right of int values. Generates an shr_u32 instruction. + */ +public class IntBitwiseShiftRightUnsignedTest extends GraalKernelTester { + + static final int num = 20; + // Output array containing the results of shift operations. + @Result protected int[] outArray = new int[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise unsigned shift + * right operation on an element of an input array and writes the result to the corresponding + * index of an output array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param shiftAmount array containing values used for the shift magnitude + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(int[] out, int[] ina, int[] shiftAmount, int gid) { + out[gid] = ina[gid] >>> shiftAmount[gid]; + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the arrays passed to the run routine. + * + * We do this in such a way that the input arrays contain a mix of negative and positive values. + * As a result, the work groups will exercise all the different combinations for the sign of the + * value being shifted and the sign of the shift magnitude. + * + * @param in the input array. + */ + void setupArrays(int[] in, int[] shiftAmount) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + shiftAmount[i] = (i & 1) == 0 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + int[] inArray = new int[num]; + int[] shiftAmount = new int[num]; + setupArrays(inArray, shiftAmount); + dispatchMethodKernel(num, outArray, inArray, shiftAmount); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntNegTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntNegTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests integer negation. Generates a neg_s32 instruction. + */ +public class IntNegTest extends GraalKernelTester { + + static final int num = 20; + // Output array storing the results of negation operations. + @Result protected int[] outArray = new int[num]; + + /** + * The static "kernel" method we will be testing. This method performs a negation operation on + * an element of an input array and writes the result to the corresponding index of an output + * array. By convention the gid is the last parameter. + * + * @param out the output array. + * @param ina the input array. + * @param gid the parameter used to index into the input and output arrays. + */ + public static void run(int[] out, int[] ina, int gid) { + out[gid] = -(ina[gid]); + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the input and output arrays passed to the run routine. + * + * @param in the input array. + */ + void setupArrays(int[] in) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + int[] inArray = new int[num]; + setupArrays(inArray); + dispatchMethodKernel(num, outArray, inArray); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseNotTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseNotTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests bitwise not of a long. + */ +public class LongBitwiseNotTest extends GraalKernelTester { + + static final int num = 20; + // Output array storing the results of the operations. + @Result protected long[] outArray = new long[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise not operation + * on an element of an input array and writes the result to the corresponding index of an output + * array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(long[] out, long[] ina, int gid) { + out[gid] = ~(ina[gid]); + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the input and output arrays passed to the run routine. + * + * @param in the input array + */ + void setupArrays(long[] in) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + long[] inArray = new long[num]; + setupArrays(inArray); + dispatchMethodKernel(num, outArray, inArray); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftLeftTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftLeftTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests bitwise left shift of long values. Generates an shl_s64 instruction. + */ +public class LongBitwiseShiftLeftTest extends GraalKernelTester { + + static final int num = 100; + // Output array containing the results of shift operations. + @Result protected long[] outArray = new long[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise shift left + * operation on an element of an input array and writes the result to the corresponding index of + * an output array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param shiftAmount an array of values used for the shift magnitude + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(long[] out, long[] ina, int[] shiftAmount, int gid) { + out[gid] = ina[gid] << shiftAmount[gid]; + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the arrays passed to the run routine. + * + * We do this in such a way that the input arrays contain a mix of negative and positive values. + * As a result, the work items will exercise all the different combinations for the sign of the + * value being shifted and the sign of the shift magnitude. + * + * @param in the input array. + */ + void setupArrays(long[] in, int[] shiftAmount) { + for (int i = 0; i < num; i++) { + /** + * Fill lower half of in[] with positive numbers and upper half with negative numbers. + */ + in[i] = i < num / 2 ? i : -i; + /** + * Fill shiftAmount[] so that even elements are positive and odd elements are negative. + */ + shiftAmount[i] = (i & 1) == 0 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + long[] inArray = new long[num]; + int[] shiftAmount = new int[num]; + setupArrays(inArray, shiftAmount); + dispatchMethodKernel(num, outArray, inArray, shiftAmount); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests bitwise right shift of long values. Generates an shr_s64 instruction. + */ +public class LongBitwiseShiftRightTest extends GraalKernelTester { + + static final int num = 100; + // Output array containing the results of shift operations. + @Result protected long[] outArray = new long[num]; + + /** + * The static "kernel" method we will be testing. This method performs a bitwise shift righj + * operation on an element of an input array and writes the result to the corresponding index of + * an output array. By convention the gid is the last parameter. + * + * @param out the output array + * @param ina the input array + * @param shiftAmount an array of values used for the shift magnitude + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(long[] out, long[] ina, int[] shiftAmount, int gid) { + out[gid] = ina[gid] >> shiftAmount[gid]; + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the arrays passed to the run routine. + * + * We do this in such a way that the input arrays contain a mix of negative and positive values. + * As a result, the work items will exercise all the different combinations for the sign of the + * value being shifted and the sign of the shift magnitude. + * + * @param in the input array + */ + void setupArrays(long[] in, int[] shiftAmount) { + for (int i = 0; i < num; i++) { + /** + * Fill lower half of in[] with positive numbers and upper half with negative numbers. + */ + in[i] = i < num / 2 ? i : -i; + /** + * Fill shiftAmount[] so that even elements are positive and odd elements are negative. + */ + shiftAmount[i] = (i & 1) == 0 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + long[] inArray = new long[num]; + int[] shiftAmount = new int[num]; + setupArrays(inArray, shiftAmount); + dispatchMethodKernel(num, outArray, inArray, shiftAmount); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightUnsignedTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightUnsignedTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009, 2012, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests unsigned bitwise right shift of long values. Generates an shr_u64 instruction. + */ +public class LongBitwiseShiftRightUnsignedTest extends GraalKernelTester { + + static final int num = 20; + // Output array containing the results of shift operations. + @Result protected long[] outArray = new long[num]; + + /** + * The static "kernel" method we will be testing. This method performs an unsigned bitwise shift + * right operation on an element of an input array and writes the result to the corresponding + * index of an output array. By convention the gid is the last parameter. + * + * @param out the output array. + * @param ina the input array. + * @param shiftAmount array containing values used for the shift magnitude + * @param gid the parameter used to index into the input and output arrays + */ + public static void run(long[] out, long[] ina, int[] shiftAmount, int gid) { + out[gid] = ina[gid] >>> shiftAmount[gid]; + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the arrays passed to the run routine. + * + * We do this in such a way that the input arrays contain a mix of negative and positive values. + * As a result, the work groups will exercise all the different combinations for the sign of the + * value being shifted and the sign of the shift magnitude. + * + * @param in the input array. + */ + void setupArrays(long[] in, int[] shiftAmount) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + shiftAmount[i] = (i & 1) == 0 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + long[] inArray = new long[num]; + int[] shiftAmount = new int[num]; + setupArrays(inArray, shiftAmount); + dispatchMethodKernel(num, outArray, inArray, shiftAmount); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongNegTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongNegTest.java Fri Nov 01 12:06:22 2013 +0100 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2009, 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.hsail.test; + +import org.junit.Test; +import com.oracle.graal.compiler.hsail.test.infra.*; + +/** + * Tests negation of long values. Generates a neg_s64 instruction. + */ +public class LongNegTest extends GraalKernelTester { + + static final int num = 20; + // Output array storing the results of negation operations. + @Result protected long[] outArray = new long[num]; + + /** + * The static "kernel" method we will be testing. This method performs a negation operation on + * an element of an input array and writes the result to the corresponding index of an output + * array. By convention the gid is the last parameter. + * + * @param out the output array. + * @param ina the input array. + * @param gid the parameter used to index into the input and output arrays. + */ + public static void run(long[] out, long[] ina, int gid) { + out[gid] = -(ina[gid]); + } + + /** + * Tests the HSAIL code generated for this unit test by comparing the result of executing this + * code with the result of executing a sequential Java version of this unit test. + */ + @Test + public void test() { + super.testGeneratedHsail(); + } + + /** + * Initializes the input and output arrays passed to the run routine. + * + * @param in the input array. + */ + void setupArrays(long[] in) { + for (int i = 0; i < num; i++) { + in[i] = i < num / 2 ? i : -i; + outArray[i] = 0; + } + } + + /** + * Dispatches the HSAIL kernel for this test case. + */ + @Override + public void runTest() { + long[] inArray = new long[num]; + setupArrays(inArray); + dispatchMethodKernel(num, outArray, inArray); + } +} diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java --- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java Thu Oct 31 18:45:31 2013 +0100 +++ b/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java Fri Nov 01 12:06:22 2013 +0100 @@ -246,13 +246,30 @@ throw GraalInternalError.unimplemented(); } + /** + * Generates the LIR instruction for a negation operation. + * + * @param input the value that is being negated + * @return Variable that represents the result of the negation + */ @Override public Variable emitNegate(Value input) { Variable result = newVariable(input.getKind()); switch (input.getKind()) { case Int: + // Note: The Int case also handles the negation of shorts, bytes, and chars because + // Java treats these types as ints at the bytecode level. append(new Op1Stack(INEG, result, input)); break; + case Long: + append(new Op1Stack(LNEG, result, input)); + break; + case Double: + append(new Op1Stack(DNEG, result, input)); + break; + case Float: + append(new Op1Stack(FNEG, result, input)); + break; default: throw GraalInternalError.shouldNotReachHere(); } @@ -260,13 +277,24 @@ } + /** + * Generates the LIR instruction for a bitwise NOT operation. + * + * @param input the source operand + * @return Variable that represents the result of the operation + */ @Override public Variable emitNot(Value input) { Variable result = newVariable(input.getKind()); switch (input.getKind()) { case Int: + // Note: The Int case also covers other primitive integral types smaller than an int + // (char, byte, short) because Java treats these types as ints. append(new Op1Stack(INOT, result, input)); break; + case Long: + append(new Op1Stack(LNOT, result, input)); + break; default: throw GraalInternalError.shouldNotReachHere(); } @@ -491,11 +519,20 @@ return result; } + /** + * Generates the LIR instruction for a shift left operation. + * + * @param a The value that is being shifted + * @param b The shift amount + * @return Variable that represents the result of the operation + */ @Override public Variable emitShl(Value a, Value b) { Variable result = newVariable(a.getKind()); switch (a.getKind()) { case Int: + // Note: The Int case also covers the shifting of bytes, shorts and chars because + // Java treats these types as ints at the bytecode level. append(new ShiftOp(ISHL, result, a, b)); break; case Long: @@ -507,11 +544,38 @@ return result; } + /** + * Generates the LIR instruction for a shift right operation. + * + * @param a The value that is being shifted + * @param b The shift amount + * @return Variable that represents the result of the operation + */ @Override public Variable emitShr(Value a, Value b) { - throw GraalInternalError.unimplemented(); + Variable result = newVariable(a.getKind()); + switch (a.getKind()) { + case Int: + // Note: The Int case also covers the shifting of bytes, shorts and chars because + // Java treats these types as ints at the bytecode level. + append(new ShiftOp(ISHR, result, a, b)); + break; + case Long: + append(new ShiftOp(LSHR, result, a, b)); + break; + default: + GraalInternalError.shouldNotReachHere(); + } + return result; } + /** + * Generates the LIR instruction for an unsigned shift right operation. + * + * @param a The value that is being shifted + * @param b The shift amount + * @return Variable that represents the result of the operation + */ @Override public Variable emitUShr(Value a, Value b) { Variable result = newVariable(a.getKind()); @@ -575,7 +639,6 @@ case F2L: append(new Op1Stack(F2L, result, input)); break; - default: throw GraalInternalError.shouldNotReachHere(); } diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILArithmetic.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILArithmetic.java Thu Oct 31 18:45:31 2013 +0100 +++ b/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILArithmetic.java Fri Nov 01 12:06:22 2013 +0100 @@ -35,85 +35,89 @@ * Defines arithmetic instruction nodes. */ public enum HSAILArithmetic { - IADD, - OADD, - ISUB, - FSUB, - DSUB, - IMUL, - FMUL, - DMUL, - IDIV, + CALL, FDIV, - DDIV, - IUADD, - IUSUB, - IUMUL, - IUDIV, - LADD, + FREM, + D2F, + D2I, + D2L, DADD, - FADD, - LSUB, - LMUL, - LDIV, - LUADD, - LUSUB, - LUMUL, - LUDIV, - IMAX, - LMAX, - IUMAX, - LUMAX, - IMIN, - LMIN, - IUMIN, - LUMIN, - IREM, - LREM, - FREM, + DDIV, + DMUL, + DNEG, DREM, - IUREM, - LUREM, - ICARRY, - LCARRY, - IUCARRY, - LUCARRY, - IAND, - LAND, - INEG, - INOT, - I2B, - I2S, - I2L, - I2C, + DSUB, F2D, F2I, F2L, - D2F, - I2F, + FADD, + FMUL, + FNEG, + FSUB, + I2B, + I2C, I2D, - D2I, + I2F, + I2L, + I2S, + IADD, + IAND, + ICARRY, + IDIV, + IMAX, + IMIN, + IMUL, + INEG, + INOT, + IOR, + IREM, + ISHL, + ISHR, + ISUB, + IUADD, + IUCARRY, + IUDIV, + IUMAX, + IUMIN, + IUMUL, + IUREM, + IUSHR, + IUSUB, + IXOR, + L2D, L2F, - D2L, + L2I, + LADD, + LAND, + LCARRY, + LDIV, + LMAX, + LMIN, + LMUL, + LNEG, + LNOT, + LOR, + LREM, + LSHL, + LSHR, + LSUB, + LUADD, + LUCARRY, + LUDIV, + LUMAX, + LUMIN, + LUMUL, + LUREM, + LUSHR, + LUSUB, + LXOR, MOV_F2I, MOV_D2L, - L2D, MOV_I2F, MOV_L2D, - ISHL, - LSHL, - ISHR, - LSHR, - IUSHR, - LUSHR, + OADD, SQRT, - UNDEF, - CALL, - L2I, - IXOR, - LXOR, - IOR, - LOR; + UNDEF; public static class Op1Stack extends HSAILLIRInstruction { @Opcode private final HSAILArithmetic opcode; @@ -313,7 +317,7 @@ masm.emitConvertIntToByte(dst, src); break; case SQRT: - masm.emitArg1("sqrt", dst, src); + masm.emit("sqrt", dst, src); break; case UNDEF: masm.undefined("undefined node"); @@ -322,7 +326,16 @@ masm.undefined("undefined node CALL"); break; case INOT: - masm.emitArg1("not", dst, src); + case LNOT: + // Emit the HSAIL instruction for a bitwise not. + masm.emitForceBitwise("not", dst, src); + break; + case INEG: + case LNEG: + case FNEG: + case DNEG: + // Emit the HSAIL instruction for a negate operation. + masm.emit("neg", dst, src); break; default: throw GraalInternalError.shouldNotReachHere(); @@ -402,15 +415,15 @@ break; case IAND: case LAND: - masm.emitBitwiseLogical("and", dst, src1, src2); + masm.emitForceBitwise("and", dst, src1, src2); break; case IXOR: case LXOR: - masm.emitBitwiseLogical("xor", dst, src1, src2); + masm.emitForceBitwise("xor", dst, src1, src2); break; case IOR: case LOR: - masm.emitBitwiseLogical("or", dst, src1, src2); + masm.emitForceBitwise("or", dst, src1, src2); break; case IREM: masm.emit("rem", dst, src1, src2); diff -r 04c74433529a -r c73b857b1be9 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILControlFlow.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILControlFlow.java Thu Oct 31 18:45:31 2013 +0100 +++ b/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILControlFlow.java Fri Nov 01 12:06:22 2013 +0100 @@ -265,6 +265,6 @@ default: throw GraalInternalError.shouldNotReachHere(); } - masm.cmovCommon(result, trueValue, falseValue, width); + masm.emitConditionalMove(result, trueValue, falseValue, width); } }