# HG changeset patch # User Doug Simon # Date 1422006861 -3600 # Node ID 8f2fb6bec986c7989d8fb5c3539806c6a32606fa # Parent c8fc6e2d128b0a6913e1b19e1c8b07098dbc987e removed GPU code diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/AbstractHSAILAssembler.java --- a/graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/AbstractHSAILAssembler.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * 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.asm.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.asm.*; - -/** - * The platform-dependent base class for the HSAIL assembler. - */ -public abstract class AbstractHSAILAssembler extends Assembler { - - public AbstractHSAILAssembler(TargetDescription target) { - super(target); - } - - @Override - public final void bind(Label l) { - super.bind(l); - emitString0(nameOf(l) + ":\n"); - } - - @Override - public void align(int modulus) { - // Nothing to do - } - - @Override - public void jmp(Label l) { - emitJumpToLabelName(nameOf(l)); - } - - public void emitJumpToLabelName(String labelName) { - emitString("brn " + labelName + ";"); - } - - @Override - protected void patchJumpTarget(int branch, int jumpTarget) { - // Nothing to do - } - - @Override - protected String createLabelName(Label l, int id) { - int blockId = l.getBlockId(); - return "@L" + (blockId == -1 ? id : blockId); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAddress.java --- a/graal/com.oracle.graal.asm.hsail/src/com/oracle/graal/asm/hsail/HSAILAddress.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * 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.asm.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; - -/** - * Represents an address in target machine memory, specified via some combination of a base register - * and a displacement. - */ -public final class HSAILAddress extends AbstractAddress { - - private final Register base; - private final long displacement; - - /** - * Creates an {@link HSAILAddress} with given base register and no displacement. - * - * - * @param base the base register - */ - public HSAILAddress(Register base) { - this(base, 0); - } - - /** - * Creates an {@link HSAILAddress} with given base register and a displacement. This is the most - * general constructor. - * - * @param base the base register - * @param displacement the displacement - */ - public HSAILAddress(Register base, long displacement) { - this.base = base; - this.displacement = displacement; - } - - /** - * @return Base register that defines the start of the address computation. If not present, is - * denoted by {@link Value#ILLEGAL}. - */ - public Register getBase() { - return base; - } - - /** - * @return Optional additive displacement. - */ - public long getDisplacement() { - return displacement; - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 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 Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,661 +0,0 @@ -/* - * Copyright (c) 2009, 2014, 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.asm.hsail; - -import static com.oracle.graal.api.code.MemoryBarriers.*; -import static com.oracle.graal.api.code.ValueUtil.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.hsail.*; - -/** - * This class contains routines to emit HSAIL assembly code. - */ -public abstract class HSAILAssembler extends AbstractHSAILAssembler { - - /** - * Stack size in bytes (used to keep track of spilling). - */ - private int maxDataTypeSize; - - /** - * Maximum stack offset used by a store operation. - */ - private long maxStackOffset = 0; - - public long upperBoundStackSize() { - return maxStackOffset + maxDataTypeSize; - } - - public HSAILAssembler(TargetDescription target) { - super(target); - } - - @Override - public HSAILAddress makeAddress(Register base, int displacement) { - return new HSAILAddress(base, displacement); - } - - @Override - public HSAILAddress getPlaceholder() { - return null; - } - - @Override - public final void ensureUniquePC() { - throw GraalInternalError.unimplemented(); - } - - public final void undefined(String str) { - emitString("undefined operation " + str); - } - - public final void exit() { - emitString("ret;" + ""); - } - - /** - * Moves an Object into a register. - * - * Because Object references become stale after Garbage collection (GC) the technique used here - * is to load a JNI global reference to that Object into the register. These JNI global - * references get updated by the GC whenever the GC moves an Object. - * - * @param a the destination register - * @param src the Object Constant being moved - */ - public abstract void mov(Register a, JavaConstant src); - - private static String getBitTypeFromKind(Kind kind) { - switch (kind) { - case Boolean: - case Byte: - case Short: - case Char: - case Int: - case Float: - return "b32"; - case Long: - case Double: - case Object: - return "b64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public final void emitMov(Kind kind, Value dst, Value src) { - if (isRegister(dst) && isConstant(src) && kind.getStackKind() == Kind.Object) { - mov(asRegister(dst), asConstant(src)); - } else { - String argtype = getBitTypeFromKind(kind); - emitString("mov_" + argtype + " " + mapRegOrConstToString(dst) + ", " + mapRegOrConstToString(src) + ";"); - } - } - - private void emitAddrOp(String instr, Value reg, HSAILAddress addr) { - String storeValue = mapRegOrConstToString(reg); - emitString(instr + " " + storeValue + ", " + mapAddress(addr) + ";"); - } - - /** - * Emits a memory barrier instruction. - * - * @param barriers the kind of barrier to emit - */ - public final void emitMembar(int barriers) { - if (barriers == 0) { - emitString("// no barrier before volatile read"); - } else if (barriers == JMM_POST_VOLATILE_READ) { - emitString("sync; // barriers=" + MemoryBarriers.barriersString(barriers)); - } else if (barriers == JMM_PRE_VOLATILE_WRITE) { - emitString("sync; // barriers=" + MemoryBarriers.barriersString(barriers)); - } else if (barriers == JMM_POST_VOLATILE_WRITE) { - emitString("sync; // barriers=" + MemoryBarriers.barriersString(barriers)); - } - } - - public final void emitLoad(Kind kind, Value dest, HSAILAddress addr) { - emitLoad(dest, addr, getArgTypeFromKind(kind)); - } - - public final void emitLoad(Value dest, HSAILAddress addr, String argTypeStr) { - emitAddrOp("ld_global_" + argTypeStr, dest, addr); - } - - public final void emitLda(Value dest, HSAILAddress addr) { - emitAddrOp("lda_global_u64", dest, addr); - } - - public final void emitLea(Value dest, HSAILAddress addr) { - String prefix = getArgType(dest); - emitString(String.format("add_%s %s, $%s, 0x%s;", prefix, HSAIL.mapRegister(dest), addr.getBase().name, Long.toHexString(addr.getDisplacement()))); - } - - public final void emitLoadKernelArg(Value dest, String kernArgName, String argTypeStr) { - emitString("ld_kernarg_" + argTypeStr + " " + HSAIL.mapRegister(dest) + ", [" + kernArgName + "];"); - } - - public final void emitStore(Kind kind, Value src, HSAILAddress addr) { - emitStore(src, addr, getArgTypeFromKind(kind)); - } - - public final void emitStore(Value dest, HSAILAddress addr, String argTypeStr) { - emitAddrOp("st_global_" + argTypeStr, dest, addr); - } - - private void storeImmediateImpl(String storeType, String value, HSAILAddress addr) { - emitString("st_global_" + storeType + " " + value + ", " + mapAddress(addr) + ";"); - } - - public final void emitStoreImmediate(Kind kind, long src, HSAILAddress addr) { - assert (kind != Kind.Float && kind != Kind.Double); - storeImmediateImpl(getArgTypeFromKind(kind), Long.toString(src), addr); - } - - public final void emitStoreImmediate(float src, HSAILAddress addr) { - storeImmediateImpl("f32", floatToString(src), addr); - } - - public final void emitStoreImmediate(double src, HSAILAddress addr) { - storeImmediateImpl("f64", doubleToString(src), addr); - } - - public final void emitSpillLoad(Kind kind, Value dest, Value src) { - emitString("ld_spill_" + getArgTypeFromKind(kind) + " " + HSAIL.mapRegister(dest) + ", " + mapStackSlot(src, getArgSizeFromKind(kind)) + ";"); - } - - public final void emitStore(Value src, HSAILAddress addr) { - emitString("st_global_" + getArgType(src) + " " + HSAIL.mapRegister(src) + ", " + mapAddress(addr) + ";"); - } - - public final void emitSpillStore(Kind kind, Value src, Value dest) { - int sizestored = getArgSizeFromKind(kind); - if (maxDataTypeSize < sizestored) { - maxDataTypeSize = sizestored; - } - int stackoffset = HSAIL.getStackOffset(dest); - if (maxStackOffset < stackoffset) { - maxStackOffset = stackoffset; - } - emitString("st_spill_" + getArgTypeFromKind(kind) + " " + HSAIL.mapRegister(src) + ", " + mapStackSlot(dest, getArgSizeFromKind(kind)) + ";"); - } - - public static String mapStackSlot(Value reg, int argSize) { - long startOffset = HSAIL.getStackOffsetStart(reg, argSize); - return "[%spillseg]" + "[" + startOffset + "]"; - } - - public void cbr(String target1) { - emitString("cbr " + "$c0" + ", " + target1 + ";"); - } - - public int getArgSize(Value src) { - return getArgSizeFromKind(src.getKind()); - } - - private static int getArgSizeFromKind(Kind kind) { - switch (kind) { - case Int: - case Float: - return 32; - case Double: - case Long: - case Object: - return 64; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - private static String getArgType(Value src) { - return getArgTypeFromKind(src.getKind()); - } - - private static String getArgTypeFromKind(Kind kind) { - String prefix = ""; - switch (kind) { - case Float: - prefix = "f32"; - break; - case Double: - prefix = "f64"; - break; - case Int: - prefix = "s32"; - break; - case Long: - prefix = "s64"; - break; - case Object: - prefix = "u64"; - break; - case Char: - prefix = "u16"; - break; - case Short: - prefix = "s16"; - break; - case Byte: - prefix = "s8"; - break; - case Boolean: - prefix = "u8"; - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return prefix; - } - - public static final String getArgTypeForceUnsigned(Value src) { - return getArgTypeForceUnsignedKind(src.getKind()); - } - - public static final String getArgTypeForceUnsignedKind(Kind kind) { - switch (kind) { - case Int: - return "u32"; - case Long: - case Object: - return "u64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public static final String getArgTypeBitwiseLogical(Value src) { - String length = getArgType(src); - String prefix = "_b" + (length.endsWith("64") ? "64" : "32"); - return prefix; - } - - /** - * Emits a compare instruction. - * - * @param src0 - the first source register - * @param src1 - the second source register - * @param condition - the compare condition i.e., eq, ne, lt, gt - * @param unordered - flag specifying if this is an unordered compare. This only applies to - * float compares. - * @param isUnsignedCompare - flag specifying if this is a compare of unsigned values. - */ - public void emitCompare(Kind compareKind, Value src0, Value src1, String condition, boolean unordered, boolean isUnsignedCompare) { - // Formulate the prefix of the instruction. - // if unordered is true, it should be ignored unless the src type is f32 or f64 - String argType = getArgTypeFromKind(compareKind); - String unorderedPrefix = (argType.startsWith("f") && unordered ? "u" : ""); - String prefix = "cmp_" + condition + unorderedPrefix + "_b1_" + (isUnsignedCompare ? getArgTypeForceUnsigned(src1) : argType); - // Generate a comment for debugging purposes - String comment = (isConstant(src1) && (src1.getKind() == Kind.Object) && (asConstant(src1).isNull()) ? " // null test " : ""); - // Emit the instruction. - emitString(prefix + " $c0, " + mapRegOrConstToString(src0) + ", " + mapRegOrConstToString(src1) + ";" + comment); - } - - public void emitConvert(Value dest, Value src, String destType, String srcType) { - String prefix = "cvt_"; - if (destType.equals("f32") && srcType.equals("f64")) { - prefix = "cvt_near_"; - } else if (srcType.startsWith("f") && (destType.startsWith("s") || destType.startsWith("u"))) { - prefix = "cvt_zeroi_sat_"; - } - emitString(prefix + destType + "_" + srcType + " " + HSAIL.mapRegister(dest) + ", " + HSAIL.mapRegister(src) + ";"); - } - - public void emitConvert(Value dest, Value src, Kind destKind, Kind srcKind) { - String destType = getArgTypeFromKind(destKind); - String srcType = getArgTypeFromKind(srcKind); - emitConvert(dest, src, destType, srcType); - } - - /** - * Emits a convert instruction that uses unsigned prefix, regardless of the type of dest and - * src. - * - * @param dest the destination operand - * @param src the source operand - */ - public void emitConvertForceUnsigned(Value dest, Value src) { - emitString("cvt_" + getArgTypeForceUnsigned(dest) + "_" + getArgTypeForceUnsigned(src) + " " + HSAIL.mapRegister(dest) + ", " + HSAIL.mapRegister(src) + ";"); - } - - public static String mapAddress(HSAILAddress addr) { - if (addr.getBase().encoding() < 0) { - return "[0x" + Long.toHexString(addr.getDisplacement()) + "]"; - } else { - return "[$d" + addr.getBase().encoding() + " + " + addr.getDisplacement() + "]"; - } - } - - private static String doubleToString(double dval) { - long lval = Double.doubleToRawLongBits(dval); - long lvalIgnoreSign = lval & 0x7fffffffffffffffL; - if (lvalIgnoreSign >= 0x7ff0000000000000L) { - return "0D" + String.format("%16x", lval); - } else { - return Double.toString(dval); - } - } - - private static String floatToString(float fval) { - int ival = Float.floatToRawIntBits(fval); - int ivalIgnoreSign = ival & 0x7fffffff; - if (ivalIgnoreSign >= 0x7f800000) { - return "0F" + String.format("%8x", ival); - } else { - return Float.toString(fval) + "f"; - } - } - - private static String mapRegOrConstToString(Value src) { - if (!isConstant(src)) { - return HSAIL.mapRegister(src); - } else { - JavaConstant consrc = asConstant(src); - switch (src.getKind()) { - case Boolean: - case Int: - return Integer.toString(consrc.asInt()); - case Float: - return floatToString(consrc.asFloat()); - case Double: - return doubleToString(consrc.asDouble()); - case Long: - return "0x" + Long.toHexString(consrc.asLong()); - case Object: - if (consrc.isNull()) { - return "0"; - } else { - throw GraalInternalError.shouldNotReachHere("unknown type: " + src); - } - default: - throw GraalInternalError.shouldNotReachHere("unknown type: " + src); - } - } - - } - - /** - * 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); - emitTextFormattedInstruction(mnemonic + "_" + prefix, dest, sources); - } - - /** - * 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); - } - - public final void emitForceUnsignedKind(String mnemonic, Kind kind, Value dest, Value... sources) { - String prefix = getArgTypeForceUnsignedKind(kind); - emitTextFormattedInstruction(mnemonic + "_" + prefix, dest, sources); - } - - /** - * 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. - * - * @param instr the full instruction mnenomics including any prefixes - * @param dest the destination operand - * @param sources the source operand - */ - 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; - case 1: - // Emit an instruction with one source operand. - emitString(String.format("%s %s, %s;", instr, HSAIL.mapRegister(dest), mapRegOrConstToString(sources[0]))); - break; - default: - // Emit an instruction with one source operand. - emitString(String.format("%s %s;", instr, HSAIL.mapRegister(dest))); - 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))); - } - - /** - * Emits code to build a 64-bit pointer from a compressed value and the associated base and - * shift. The compressed value could represent either a normal oop or a klass ptr. If the - * compressed value is 0, the uncompressed must also be 0. We only emit this if base and shift - * are not both zero. - * - * @param result the register containing the compressed value on input and the uncompressed ptr - * on output - * @param base the amount to be added to the compressed value - * @param shift the number of bits to shift left the compressed value - * @param testForNull true if the compressed value might be null - */ - public void emitCompressedOopDecode(Value result, long base, int shift, boolean testForNull) { - assert (base != 0 || shift != 0); - assert (!isConstant(result)); - if (base == 0) { - // we don't have to test for null if shl is the only operation - emitForceUnsignedKind("shl", Kind.Long, result, result, JavaConstant.forInt(shift)); - } else if (shift == 0) { - // only use add if result is not starting as null (test only if testForNull is true) - emitWithOptionalTestForNull(testForNull, "add", result, result, JavaConstant.forLong(base)); - } else { - // only use mad if result is not starting as null (test only if testForNull is true) - emitWithOptionalTestForNull(testForNull, "mad", result, result, JavaConstant.forInt(1 << shift), JavaConstant.forLong(base)); - } - } - - /** - * Emits code to build a compressed value from a full 64-bit pointer using the associated base - * and shift. The compressed value could represent either a normal oop or a klass ptr. If the - * ptr is 0, the compressed value must also be 0. We only emit this if base and shift are not - * both zero. - * - * @param result the register containing the 64-bit pointer on input and the compressed value on - * output - * @param base the amount to be subtracted from the 64-bit pointer - * @param shift the number of bits to shift right the 64-bit pointer - * @param testForNull true if the 64-bit pointer might be null - */ - public void emitCompressedOopEncode(Value result, long base, int shift, boolean testForNull) { - assert (base != 0 || shift != 0); - assert (!isConstant(result)); - if (base != 0) { - // only use sub if result is not starting as null (test only if testForNull is true) - emitWithOptionalTestForNull(testForNull, "sub", result, result, JavaConstant.forLong(base)); - } - if (shift != 0) { - // note that the shr can still be done even if the result is null - emitForceUnsignedKind("shr", Kind.Long, result, result, JavaConstant.forInt(shift)); - } - } - - /** - * Emits code for the requested mnemonic on the result and sources. In addition, if testForNull - * is true, surrounds the instruction with code that will guarantee that if the result starts as - * 0, it will remain 0. - * - * @param testForNull true if we want to add the code to check for and preserve null - * @param mnemonic the instruction to be applied (without size prefix) - * @param result the register which is both an input and the final output - * @param sources the sources for the mnemonic instruction - */ - private void emitWithOptionalTestForNull(boolean testForNull, String mnemonic, Value result, Value... sources) { - if (testForNull) { - emitCompare(Kind.Long, result, JavaConstant.forLong(0), "eq", false, true); - } - emitForceUnsigned(mnemonic, result, sources); - if (testForNull) { - emitConditionalMove(result, JavaConstant.forLong(0), result, 64); - } - } - - /** - * Emits an atomic_cas_global instruction. - * - * @param result result operand that gets the original contents of the memory location - * @param address the memory location - * @param cmpValue the value that will be compared against the memory location - * @param newValue the new value that will be written to the memory location if the cmpValue - * comparison matches - */ - public void emitAtomicCas(Kind accessKind, AllocatableValue result, HSAILAddress address, Value cmpValue, Value newValue) { - emitString(String.format("atomic_cas_global_b%d %s, %s, %s, %s;", getArgSizeFromKind(accessKind), HSAIL.mapRegister(result), mapAddress(address), mapRegOrConstToString(cmpValue), - mapRegOrConstToString(newValue))); - } - - /** - * Emits an atomic_add_global instruction. - * - * @param result result operand that gets the original contents of the memory location - * @param address the memory location - * @param delta the amount to add - */ - public void emitAtomicAdd(AllocatableValue result, HSAILAddress address, Value delta) { - // ensure result and delta agree (this should probably be at some higher level) - Value mydelta = delta; - if (!isConstant(delta) && (getArgSize(result) != getArgSize(delta))) { - emitConvert(result, delta, result.getKind(), delta.getKind()); - mydelta = result; - } - String prefix = getArgTypeForceUnsigned(result); - emitString(String.format("atomic_add_global_%s %s, %s, %s;", prefix, HSAIL.mapRegister(result), mapAddress(address), mapRegOrConstToString(mydelta))); - } - - /** - * Emits an atomic_exch_global instruction. - * - * @param result result operand that gets the original contents of the memory location - * @param address the memory location - * @param newValue the new value to write to the memory location - */ - public void emitAtomicExch(Kind accessKind, AllocatableValue result, HSAILAddress address, Value newValue) { - emitString(String.format("atomic_exch_global_b%d %s, %s, %s;", getArgSizeFromKind(accessKind), HSAIL.mapRegister(result), mapAddress(address), mapRegOrConstToString(newValue))); - } - - /** - * Emits a comment. Useful for debugging purposes. - * - * @param comment - */ - public void emitComment(String comment) { - emitString(comment); - } - - public String getDeoptInfoName() { - return "%_deoptInfo"; - } - - public String getDeoptLabelName() { - return "@L_Deopt"; - } - - public void emitWorkItemAbsId(Value dest) { - emitString(String.format("workitemabsid_u32 %s, 0;", HSAIL.mapRegister(dest))); - } - - public void emitCuId(Value dest) { - emitString(String.format("cuid_u32 %s;", HSAIL.mapRegister(dest))); - } - - public void emitLaneId(Value dest) { - emitString(String.format("laneid_u32 %s;", HSAIL.mapRegister(dest))); - } - - public void emitWaveId(Value dest) { - emitString(String.format("waveid_u32 %s;", HSAIL.mapRegister(dest))); - } - - public void emitMaxWaveId(Value dest) { - // emitString(String.format("maxwaveid_u32 %s;", HSAIL.mapRegister(dest))); - int hardCodedMaxWaveId = 36; - emitComment("// Hard-coded maxwaveid=" + hardCodedMaxWaveId + " until it works"); - emitMov(Kind.Int, dest, JavaConstant.forInt(hardCodedMaxWaveId)); - } - - public void emitMultiplyByWavesize(Value dest) { - String regName = HSAIL.mapRegister(dest); - emitString(String.format("mul_u%d %s, %s, WAVESIZE;", getArgSize(dest), regName, regName)); - } - - public void emitGetWavesize(Value dest) { - String regName = HSAIL.mapRegister(dest); - emitString(String.format("mov_b%d %s, WAVESIZE;", getArgSize(dest), regName)); - } - - public void emitLoadAcquire(Value dest, HSAILAddress address) { - emitString(String.format("ld_global_acq_u%d %s, %s;", getArgSize(dest), HSAIL.mapRegister(dest), mapAddress(address))); - } - - public void emitStoreRelease(Value src, HSAILAddress address) { - emitString(String.format("st_global_rel_u%d %s, %s;", getArgSize(src), HSAIL.mapRegister(src), mapAddress(address))); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/AbstractPTXAssembler.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/AbstractPTXAssembler.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * 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.asm.ptx; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.asm.*; - -/** - * The platform-dependent base class for the PTX assembler. - */ -public abstract class AbstractPTXAssembler extends Assembler { - - public AbstractPTXAssembler(TargetDescription target) { - super(target); - } - - @Override - public final void bind(Label l) { - super.bind(l); - emitString0(nameOf(l) + ":\n"); - } - - @Override - public void align(int modulus) { - // Nothing to do - } - - @Override - public void jmp(Label l) { - // Nothing to do - } - - @Override - protected void patchJumpTarget(int branch, int jumpTarget) { - // Nothing to do. All branches already point to the right label. - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAddress.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAddress.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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.asm.ptx; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.lir.*; - -/** - * Represents an address in target machine memory, specified via some combination of a base register - * and a displacement. - */ -public final class PTXAddress extends AbstractAddress { - - private final Variable base; - private final long displacement; - - /** - * Creates an {@link PTXAddress} with given base register and no displacement. - * - * @param base the base register - */ - public PTXAddress(Variable base) { - this(base, 0); - } - - /** - * Creates an {@link PTXAddress} with given base register and a displacement. This is the most - * general constructor. - * - * @param base the base register - * @param displacement the displacement - */ - public PTXAddress(Variable base, long displacement) { - this.base = base; - this.displacement = displacement; - } - - /** - * @return Base register that defines the start of the address computation. If not present, is - * denoted by {@link Value#ILLEGAL}. - */ - public Variable getBase() { - return base; - } - - /** - * @return Optional additive displacement. - */ - public long getDisplacement() { - return displacement; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAsmOptions.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAsmOptions.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * 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.asm.ptx; - -public class PTXAsmOptions { - // Nothing for now -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXAssembler.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,712 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.asm.ptx; - -import static com.oracle.graal.api.code.ValueUtil.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.lir.*; - -public class PTXAssembler extends AbstractPTXAssembler { - - public PTXAssembler(TargetDescription target, @SuppressWarnings("unused") RegisterConfig registerConfig) { - super(target); - } - - public enum ConditionOperator { - // @formatter:off - - // Signed integer operators - S_EQ("eq"), - S_NE("ne"), - S_LT("lt"), - S_LE("le"), - S_GT("gt"), - S_GE("ge"), - - // Unsigned integer operators - U_EQ("eq"), - U_NE("ne"), - U_LO("lo"), - U_LS("ls"), - U_HI("hi"), - U_HS("hs"), - - // Bit-size integer operators - B_EQ("eq"), - B_NE("ne"), - - // Floating-point operators - F_EQ("eq"), - F_NE("ne"), - F_LT("lt"), - F_LE("le"), - F_GT("gt"), - F_GE("ge"), - - // Floating-point operators accepting NaN - F_EQU("equ"), - F_NEU("neu"), - F_LTU("ltu"), - F_LEU("leu"), - F_GTU("gtu"), - F_GEU("geu"), - - // Floating-point operators testing for NaN - F_NUM("num"), - F_NAN("nan"); - - // @formatter:on - - private final String operator; - - private ConditionOperator(String op) { - this.operator = op; - } - - public String getOperator() { - return operator; - } - } - - public static class StandardFormat { - - // Type of destination value - protected Kind valueKind; - protected Variable dest; - protected Value source1; - protected Value source2; - - public StandardFormat(Variable dst, Value src1, Value src2) { - setDestination(dst); - setSource1(src1); - setSource2(src2); - setKind(dst.getKind()); - } - - public void setKind(Kind k) { - valueKind = k; - } - - public void setDestination(Variable var) { - assert var != null; - dest = var; - setKind(var.getKind()); - } - - public void setSource1(Value val) { - assert val != null; - source1 = val; - } - - public void setSource2(Value val) { - assert val != null; - source2 = val; - } - - public String typeForKind(Kind k) { - switch (k.getTypeChar()) { - // Boolean - case 'z': - return "u8"; - // Byte - case 'b': - return "b8"; - // Short - case 's': - return "s16"; - case 'c': - return "u16"; - case 'i': - return "s32"; - case 'f': - return "f32"; - case 'j': - return "s64"; - case 'd': - return "f64"; - case 'a': - return "u64"; - case '-': - return "u32"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public String emit() { - return (typeForKind(valueKind) + emitRegister(dest, true) + emitValue(source1, true) + emitValue(source2, false) + ";"); - } - - public String emitValue(Value v, boolean comma) { - assert v != null; - - if (isConstant(v)) { - return (emitConstant(v, comma)); - } else { - return (emitRegister((Variable) v, comma)); - } - } - - public String emitRegister(Variable v, boolean comma) { - return (" %r" + v.index + (comma ? "," : "")); - } - - public String emitConstant(Value v, boolean comma) { - JavaConstant constant = (JavaConstant) v; - String str = null; - - switch (v.getKind().getTypeChar()) { - case 'i': - str = String.valueOf((int) constant.asLong()); - break; - case 'f': - str = String.valueOf(constant.asFloat()); - break; - case 'j': - str = String.valueOf(constant.asLong()); - break; - case 'd': - str = String.valueOf(constant.asDouble()); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - if (comma) { - return (str + ","); - } else { - return str; - } - } - } - - public static class LogicInstructionFormat extends StandardFormat { - public LogicInstructionFormat(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - @Override - public String emit() { - String kindStr; - switch (valueKind.getTypeChar()) { - case 's': - kindStr = "b16"; - break; - case 'i': - kindStr = "b32"; - break; - case 'j': - kindStr = "b64"; - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - - return (kindStr + emitRegister(dest, true) + emitValue(source1, true) + emitValue(source2, false) + ";"); - } - } - - public static class SingleOperandFormat { - - protected Variable dest; - protected Value source; - - public SingleOperandFormat(Variable dst, Value src) { - setDestination(dst); - setSource(src); - } - - public void setDestination(Variable var) { - dest = var; - } - - public void setSource(Value var) { - source = var; - } - - public String typeForKind(Kind k) { - switch (k.getTypeChar()) { - case 'z': - return "u8"; - case 'b': - return "s8"; - case 's': - return "s16"; - case 'c': - return "u16"; - case 'i': - return "s32"; - case 'f': - return "f32"; - case 'j': - return "s64"; - case 'd': - return "f64"; - case 'a': - return "u64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public String emit() { - return (typeForKind(dest.getKind()) + " " + emitVariable(dest) + ", " + emitValue(source) + ";"); - } - - public String emitValue(Value v) { - assert v != null; - - if (isConstant(v)) { - return (emitConstant(v)); - } else { - return (emitVariable((Variable) v)); - } - } - - public String emitConstant(Value v) { - JavaConstant constant = (JavaConstant) v; - - switch (v.getKind().getTypeChar()) { - case 'i': - return (String.valueOf((int) constant.asLong())); - case 'f': - return (String.valueOf(constant.asFloat())); - case 'j': - return (String.valueOf(constant.asLong())); - case 'd': - return (String.valueOf(constant.asDouble())); - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public String emitVariable(Variable v) { - String name = v.getName(); - - if (name == null) { - return (" %r" + v.index); - } else { - return name; - } - } - } - - public static class BinarySingleOperandFormat extends SingleOperandFormat { - - public BinarySingleOperandFormat(Variable dst, Value src) { - super(dst, src); - } - - @Override - public String typeForKind(Kind k) { - switch (k.getTypeChar()) { - case 's': - return "b16"; - case 'i': - return "b32"; - case 'j': - return "b64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - public static class ConversionFormat extends SingleOperandFormat { - - private final Kind dstKind; - private final Kind srcKind; - - public ConversionFormat(Variable dst, Value src, Kind dstKind, Kind srcKind) { - super(dst, src); - this.dstKind = dstKind; - this.srcKind = srcKind; - } - - @Override - public String emit() { - return (typeForKind(dstKind) + "." + typeForKind(srcKind) + " " + emitVariable(dest) + ", " + emitValue(source) + ";"); - } - } - - public static class LoadStoreFormat extends StandardFormat { - - protected PTXStateSpace space; - - public LoadStoreFormat(PTXStateSpace space, Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - setStateSpace(space); - } - - public void setStateSpace(PTXStateSpace ss) { - space = ss; - } - - public String emitAddress(Value var, Value val) { - assert var instanceof Variable; - assert val instanceof JavaConstant; - JavaConstant constant = (JavaConstant) val; - return ("[" + ((space == PTXStateSpace.Parameter) ? emitParameter((Variable) var) : emitRegister((Variable) var, false)) + " + " + constant.toValueString() + "]"); - } - - @Override - public String emitRegister(Variable var, boolean comma) { - return ("%r" + var.index); - } - - public String emitParameter(Variable v) { - return ("param" + v.index); - } - - public String emit(boolean isLoad) { - if (isLoad) { - return (space.getStateName() + "." + typeForKind(valueKind) + " " + emitRegister(dest, false) + ", " + emitAddress(source1, source2) + ";"); - } else { - return (space.getStateName() + "." + typeForKind(valueKind) + " " + emitAddress(source1, source2) + ", " + emitRegister(dest, false) + ";"); - } - } - } - - // Checkstyle: stop method name check - /* - * Emit conditional branch to target 'tgt' guarded by predicate register 'pred' whose state is - * tested to be 'predCheck'. - */ - public final void bra(String tgt, int pred, boolean predCheck) { - assert pred >= 0; - - if (tgt.equals("?")) { - Thread.dumpStack(); - } - emitString("@" + (predCheck ? "%p" : "!%p") + pred + " " + "bra" + " " + tgt + ";"); - } - - public final void bra(String src) { - emitString("bra " + src + ";"); - } - - public final void bra_uni(String tgt) { - emitString("bra.uni" + " " + tgt + ";" + ""); - } - - public final void exit() { - emitString("exit;" + " " + ""); - } - - public static class Global { - - private Kind kind; - private String name; - private LabelRef[] targets; - - public Global(Value val, String name, LabelRef[] targets) { - this.kind = val.getKind(); - this.name = name; - this.targets = targets; - } - - private static String valueForKind(Kind k) { - switch (k.getTypeChar()) { - case 'i': - return "s32"; - case 'j': - return "s64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - private static String emitTargets(PTXAssembler asm, LabelRef[] refs) { - StringBuffer sb = new StringBuffer(); - - for (int i = 0; i < refs.length; i++) { - sb.append(asm.nameOf(refs[i].label())); - if (i < (refs.length - 1)) { - sb.append(", "); - } - } - - return sb.toString(); - } - - public void emit(PTXAssembler asm) { - asm.emitString(".global ." + valueForKind(kind) + " " + name + "[" + targets.length + "] = " + "{ " + emitTargets(asm, targets) + " };"); - } - } - - public final void popc_b32(Register d, Register a) { - emitString("popc.b32" + " " + "%r" + d.encoding() + ", %r" + a.encoding() + ";" + ""); - } - - public final void popc_b64(Register d, Register a) { - emitString("popc.b64" + " " + "%r" + d.encoding() + ", %r" + a.encoding() + ";" + ""); - } - - public final void ret() { - emitString("ret;" + " " + ""); - } - - public final void ret_uni() { - emitString("ret.uni;" + " " + ""); - } - - public enum BooleanOperator { - AND("and"), - OR("or"), - XOR("xor"); - - private final String output; - - private BooleanOperator(String out) { - this.output = out; - } - - public String getOperator() { - return output + "."; - } - } - - public static class Setp { - - private BooleanOperator booleanOperator; - private ConditionOperator operator; - private Value first, second; - private Kind kind; - private int predicate; - - public Setp(Condition condition, Value first, Value second, int predicateRegisterNumber) { - setFirst(first); - setSecond(second); - setPredicate(predicateRegisterNumber); - setKind(); - setConditionOperator(operatorForConditon(condition)); - } - - public Setp(Condition condition, BooleanOperator operator, Value first, Value second, int predicateRegisterNumber) { - setFirst(first); - setSecond(second); - setPredicate(predicateRegisterNumber); - setKind(); - setConditionOperator(operatorForConditon(condition)); - setBooleanOperator(operator); - } - - public void setFirst(Value v) { - first = v; - } - - public void setSecond(Value v) { - second = v; - } - - public void setPredicate(int p) { - predicate = p; - } - - public void setConditionOperator(ConditionOperator co) { - operator = co; - } - - public void setBooleanOperator(BooleanOperator bo) { - booleanOperator = bo; - } - - private ConditionOperator operatorForConditon(Condition condition) { - char typeChar = kind.getTypeChar(); - - switch (typeChar) { - case 'z': - case 'c': - case 'a': - // unsigned - switch (condition) { - case EQ: - return ConditionOperator.U_EQ; - case NE: - return ConditionOperator.U_NE; - case LT: - return ConditionOperator.U_LO; - case LE: - return ConditionOperator.U_LS; - case GT: - return ConditionOperator.U_HI; - case GE: - return ConditionOperator.U_HS; - default: - throw GraalInternalError.shouldNotReachHere(); - } - case 'b': - case 's': - case 'i': - case 'j': - // signed - switch (condition) { - case EQ: - return ConditionOperator.S_EQ; - case NE: - return ConditionOperator.S_NE; - case LT: - return ConditionOperator.S_LT; - case LE: - return ConditionOperator.S_LE; - case GT: - return ConditionOperator.S_GT; - case GE: - case AE: - return ConditionOperator.S_GE; - default: - throw GraalInternalError.shouldNotReachHere(); - } - case 'f': - case 'd': - // floating point - do these need to accept NaN?? - switch (condition) { - case EQ: - return ConditionOperator.F_EQ; - case NE: - return ConditionOperator.F_NE; - case LT: - return ConditionOperator.F_LT; - case LE: - return ConditionOperator.F_LE; - case GT: - return ConditionOperator.F_GT; - case GE: - return ConditionOperator.F_GE; - default: - throw GraalInternalError.shouldNotReachHere(); - } - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public void setKind() { - // assert isConstant(first) && isConstant(second) == false; - - if (isConstant(first)) { - kind = second.getKind(); - } else { - kind = first.getKind(); - } - } - - public String emitValue(Value v) { - assert v != null; - - if (isConstant(v)) { - return (", " + emitConstant(v)); - } else { - return (", " + emitVariable((Variable) v)); - } - } - - public String typeForKind(Kind k) { - switch (k.getTypeChar()) { - case 'z': - return "u8"; - case 'b': - return "s8"; - case 's': - return "s16"; - case 'c': - return "u16"; - case 'i': - return "s32"; - case 'f': - return "f32"; - case 'j': - return "s64"; - case 'd': - return "f64"; - case 'a': - return "u64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public String emitConstant(Value v) { - JavaConstant constant = (JavaConstant) v; - - switch (v.getKind().getTypeChar()) { - case 'i': - return (String.valueOf((int) constant.asLong())); - case 'f': - return (String.valueOf(constant.asFloat())); - case 'j': - return (String.valueOf(constant.asLong())); - case 'd': - return (String.valueOf(constant.asDouble())); - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - public String emitVariable(Variable v) { - return ("%r" + v.index); - } - - public void emit(PTXAssembler asm) { - - if (booleanOperator != null) { - // Predicates need to be objects - asm.emitString("setp." + operator.getOperator() + "." + booleanOperator.getOperator() + typeForKind(kind) + " %p" + predicate + emitValue(first) + emitValue(second) + ", %r;"); - } else { - asm.emitString("setp." + operator.getOperator() + "." + typeForKind(kind) + " %p" + predicate + emitValue(first) + emitValue(second) + ";"); - } - } - } - - @Override - public PTXAddress makeAddress(Register base, int displacement) { - throw GraalInternalError.shouldNotReachHere(); - } - - @Override - public PTXAddress getPlaceholder() { - return null; - } - - @Override - public final void ensureUniquePC() { - throw GraalInternalError.unimplemented(); - } - - @Override - public void jmp(Label l) { - String str = nameOf(l); - bra(str); - } - - /** - * @param r - */ - public void nullCheck(Register r) { - // setp(....); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXMacroAssembler.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXMacroAssembler.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,322 +0,0 @@ -/* - * 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.asm.ptx; - -import sun.misc.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; - -public class PTXMacroAssembler extends PTXAssembler { - - public PTXMacroAssembler(TargetDescription target, RegisterConfig registerConfig) { - super(target, registerConfig); - } - - public static class LoadAddr extends LoadStoreFormat { - - public LoadAddr(PTXStateSpace space, Variable dst, Variable src1, Value src2) { - super(space, dst, src1, src2); - } - - public void emit(PTXMacroAssembler masm) { - String ldAddrStr = "ld." + space.getStateName(); - if (Unsafe.ADDRESS_SIZE == 8) { - ldAddrStr = ldAddrStr + ".u64"; - } else { - ldAddrStr = ldAddrStr + ".u32"; - } - masm.emitString(ldAddrStr + " " + emitRegister(dest, false) + ", " + emitAddress(source1, source2) + ";"); - } - } - - public static class Ld extends LoadStoreFormat { - - public Ld(PTXStateSpace space, Variable dst, Variable src1, Value src2) { - super(space, dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("ld." + super.emit(true)); - } - } - - public static class St extends LoadStoreFormat { - - public St(PTXStateSpace space, Variable dst, Variable src1, Value src2) { - super(space, dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("st." + super.emit(false)); - } - } - - public static class LoadParam extends Ld { - // Type of the operation is dependent on src1's type. - public LoadParam(PTXStateSpace space, Variable dst, Variable src1, Value src2) { - super(space, dst, src1, src2); - setKind(src1.getKind()); - } - } - - public static class Add extends StandardFormat { - - public Add(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("add." + super.emit()); - } - } - - public static class And extends LogicInstructionFormat { - - public And(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("and." + super.emit()); - } - } - - public static class Div extends StandardFormat { - - public Div(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("div." + super.emit()); - } - } - - public static class Mul extends StandardFormat { - - public Mul(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("mul.lo." + super.emit()); - } - } - - public static class Or extends LogicInstructionFormat { - - public Or(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("or." + super.emit()); - } - } - - public static class Rem extends StandardFormat { - - public Rem(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("rem." + super.emit()); - } - } - - public static class Shl extends LogicInstructionFormat { - - public Shl(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("shl." + super.emit()); - } - } - - public static class Shr extends StandardFormat { - - public Shr(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("shr." + super.emit()); - } - } - - public static class Sub extends StandardFormat { - - public Sub(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("sub." + super.emit()); - } - } - - public static class Ushr extends StandardFormat { - - public Ushr(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - setKind(Kind.Illegal); // get around not having an Unsigned Kind - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("shr." + super.emit()); - } - } - - public static class Xor extends LogicInstructionFormat { - - public Xor(Variable dst, Value src1, Value src2) { - super(dst, src1, src2); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("xor." + super.emit()); - } - } - - public static class Cvt extends ConversionFormat { - - public Cvt(Variable dst, Variable src, Kind dstKind, Kind srcKind) { - super(dst, src, dstKind, srcKind); - } - - public void emit(PTXMacroAssembler asm) { - if (dest.getKind() == Kind.Float || dest.getKind() == Kind.Double) { - // round-to-zero - might not be right - asm.emitString("cvt.rz." + super.emit()); - } else { - asm.emitString("cvt." + super.emit()); - } - } - } - - public static class Mov extends SingleOperandFormat { - - private int predicateRegisterNumber = -1; - - public Mov(Variable dst, Value src) { - super(dst, src); - } - - public Mov(Variable dst, Value src, int predicate) { - super(dst, src); - this.predicateRegisterNumber = predicate; - } - - /* - * public Mov(Variable dst, AbstractAddress src) { throw - * GraalInternalError.unimplemented("AbstractAddress Mov"); } - */ - - public void emit(PTXMacroAssembler asm) { - if (predicateRegisterNumber >= 0) { - asm.emitString("@%p" + String.valueOf(predicateRegisterNumber) + " mov." + super.emit()); - } else { - asm.emitString("mov." + super.emit()); - } - } - } - - public static class Neg extends SingleOperandFormat { - - public Neg(Variable dst, Variable src) { - super(dst, src); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("neg." + super.emit()); - } - } - - public static class Not extends BinarySingleOperandFormat { - - public Not(Variable dst, Variable src) { - super(dst, src); - } - - public void emit(PTXMacroAssembler asm) { - asm.emitString("not." + super.emit()); - } - } - - public static class Param extends SingleOperandFormat { - boolean isReturnParameter; - - public Param(Variable d, boolean isRet) { - super(d, null); - isReturnParameter = isRet; - } - - public String emitParameter(Variable v) { - return (" param" + v.index); - } - - public void emit(PTXMacroAssembler asm, boolean isLastParam) { - asm.emitString(".param ." + paramForKind(dest.getKind()) + emitParameter(dest) + (isLastParam ? "" : ",")); - } - - public String paramForKind(Kind k) { - if (isReturnParameter) { - if (Unsafe.ADDRESS_SIZE == 8) { - return "u64"; - } else { - return "u32"; - } - } else { - switch (k.getTypeChar()) { - case 'z': - case 'f': - return "s32"; - case 'b': - return "b8"; - case 's': - return "s16"; - case 'c': - return "u16"; - case 'i': - return "s32"; - case 'j': - return "s64"; - case 'd': - return "f64"; - case 'a': - return "u64"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXStateSpace.java --- a/graal/com.oracle.graal.asm.ptx/src/com/oracle/graal/asm/ptx/PTXStateSpace.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.asm.ptx; - -/** - * Represents the various PTX state spaces. - */ -public enum PTXStateSpace { - - Parameter("param"), - - Shared("shared"), - - Local("local"), - - Global("global"), - - Const("const"); - - private final String stateName; - - private PTXStateSpace(String name) { - this.stateName = name; - } - - public String getStateName() { - return stateName; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/ForceDeoptSubstitutions.java --- a/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/ForceDeoptSubstitutions.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014, 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.infra; - -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.api.meta.*; - -@ClassSubstitution(GraalKernelTester.class) -class ForceDeoptSubstitutions { - - /** - * Allows us to force a non-exception throwing deopt from java code. - */ - @MethodSubstitution - public static int forceDeopt(int x) { - DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); - // will never get here but keep the compiler happy - return x * x; - } - - @MethodSubstitution - public static double forceDeopt(double x) { - DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); - // will never get here but keep the compiler happy - return x * x; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/GraalKernelTester.java --- a/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/GraalKernelTester.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,226 +0,0 @@ -/* - * 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.infra; - -/** - * This class extends KernelTester and provides a base class - * for which the HSAIL code comes from the Graal compiler. - */ -import static com.oracle.graal.compiler.common.GraalOptions.*; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static org.junit.Assume.*; - -import java.io.*; -import java.lang.reflect.*; - -import org.junit.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.target.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.gpu.*; -import com.oracle.graal.hotspot.hsail.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hsail.*; -import com.oracle.graal.options.*; -import com.oracle.graal.options.OptionValue.OverrideScope; - -public abstract class GraalKernelTester extends KernelTester { - - private static boolean substitutionsInstalled; - - private static synchronized void installSubstitutions() { - if (!substitutionsInstalled) { - getHSAILBackend().getProviders().getReplacements().registerSubstitutions(GraalKernelTester.class, ForceDeoptSubstitutions.class); - substitutionsInstalled = true; - } - } - - public GraalKernelTester() { - super(getHSAILBackend().isDeviceInitialized()); - installSubstitutions(); - } - - protected static HSAILHotSpotBackend getHSAILBackend() { - Backend backend = runtime().getBackend(HSAIL.class); - Assume.assumeTrue("No HSAIL backend, skipping test!", backend instanceof HSAILHotSpotBackend); - return (HSAILHotSpotBackend) backend; - } - - ExternalCompilationResult hsailCode; - private boolean showHsailSource = false; - private boolean saveInFile = false; - - @Override - public String getCompiledHSAILSource(Method method) { - if (hsailCode == null) { - HSAILHotSpotBackend backend = getHSAILBackend(); - ResolvedJavaMethod javaMethod = backend.getProviders().getMetaAccess().lookupJavaMethod(method); - hsailCode = backend.compileKernel(javaMethod, false); - } - String hsailSource = hsailCode.getCodeString(); - if (showHsailSource) { - logger.severe(hsailSource); - } - if (saveInFile) { - try { - File fout = File.createTempFile("tmp", ".hsail"); - logger.fine("creating " + fout.getCanonicalPath()); - FileWriter fw = new FileWriter(fout); - BufferedWriter bw = new BufferedWriter(fw); - bw.write(hsailSource); - bw.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - return hsailSource; - } - - public boolean aggressiveInliningEnabled() { - return (InlineEverything.getValue()); - } - - public boolean canHandleHSAILMethodCalls() { - // needs 2 things, backend needs to be able to generate such calls, and target needs to be - // able to run them - boolean canGenerateCalls = false; // not implemented yet - boolean canExecuteCalls = runningOnSimulator(); - return (canGenerateCalls && canExecuteCalls); - } - - private static boolean supportsObjectAllocation() { - return true; - } - - /** - * Determines if the runtime supports object allocation in HSAIL code. - */ - public boolean canHandleObjectAllocation() { - return supportsObjectAllocation() && canDeoptimize(); - } - - /** - * Determines if the runtime supports deoptimization in HSAIL code. - */ - public boolean canDeoptimize() { - return getHSAILBackend().getRuntime().getConfig().useHSAILDeoptimization; - } - - /** - * Determines if we are running CQE tests (via a -D flag). - */ - public boolean runningCQETests() { - return Boolean.getBoolean("com.amd.CQE"); - } - - /** - * Determines if the JVM supports the required typeProfileWidth. - */ - public boolean typeProfileWidthAtLeast(int val) { - return (getHSAILBackend().getRuntime().getConfig().typeProfileWidth >= val); - } - - /** - * Determines if the runtime supports {@link VirtualObject}s in {@link DebugInfo} associated - * with HSAIL code. - */ - public boolean canHandleDeoptVirtualObjects() { - return true; - } - - /** - * Determines if the runtime has the capabilities required by this test. - */ - protected boolean supportsRequiredCapabilities() { - return true; - } - - HotSpotNmethod installedCode; - - @Override - protected void dispatchKernelOkra(int range, Object... args) { - HSAILHotSpotBackend backend = getHSAILBackend(); - if (backend.isDeviceInitialized()) { - try { - if (installedCode == null) { - installedCode = backend.compileAndInstallKernel(testMethod); - } - backend.executeKernel(installedCode, range, args); - } catch (InvalidInstalledCodeException e) { - Debug.log("WARNING:Invalid installed code: " + e); - e.printStackTrace(); - } - } else { - super.dispatchKernelOkra(range, args); - } - } - - public static OptionValue getOptionFromField(Class declaringClass, String fieldName) { - try { - Field f = declaringClass.getDeclaredField(fieldName); - f.setAccessible(true); - return (OptionValue) f.get(null); - } catch (Exception e) { - throw new GraalInternalError(e); - } - } - - private OptionValue accessibleRemoveNeverExecutedCode = getOptionFromField(GraalOptions.class, "RemoveNeverExecutedCode"); - - // Special overrides for the testGeneratedxxx routines which set - // required graal options that we need to run any junit test - - private OverrideScope getOverrideScope() { - return OptionValue.override(GraalOptions.InlineEverything, true, accessibleRemoveNeverExecutedCode, false); - } - - @Override - public void testGeneratedHsail() { - try (OverrideScope s = getOverrideScope()) { - assumeTrue("Orka environment not initialized or unsupported!", supportsRequiredCapabilities() && okraEnvIsInitialized()); - super.testGeneratedHsail(); - } - } - - @Override - public void testGeneratedHsailUsingLambdaMethod() { - try (OverrideScope s = getOverrideScope()) { - assumeTrue("Orka environment not initialized or unsupported!", supportsRequiredCapabilities() && okraEnvIsInitialized()); - super.testGeneratedHsailUsingLambdaMethod(); - } - } - - // used for forcing a deoptimization - public static int forceDeopt(int x) { - return x * x; - } - - public static double forceDeopt(double x) { - return x * x; - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/KernelTester.java --- a/graal/com.oracle.graal.compiler.hsail.test.infra/src/com/oracle/graal/compiler/hsail/test/infra/KernelTester.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,795 +0,0 @@ -/* - * 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.infra; - -import static org.junit.Assert.*; -import static org.junit.Assume.*; - -import java.io.*; -import java.lang.annotation.*; -import java.lang.reflect.*; -import java.nio.file.*; -import java.util.*; -import java.util.concurrent.atomic.*; -import java.util.logging.*; - -import com.amd.okra.*; -import com.oracle.graal.test.*; - -/** - * Abstract class on which the HSAIL unit tests are built. Executes a method or lambda on both the - * Java side and the Okra side and compares the results for fields that are annotated with - * {@link Result}. - */ -public abstract class KernelTester extends GraalTest { - - /** - * Denotes a field whose value is to be - * {@linkplain KernelTester#assertResultFieldsEqual(KernelTester) compared} as part of computing - * the result of a test. - */ - @Retention(RetentionPolicy.RUNTIME) - @Target(ElementType.FIELD) - public @interface Result { - } - - // Using these in case we want to compile with Java 7. - public interface MyIntConsumer { - - void accept(int value); - } - - public interface MyObjConsumer { - - void accept(Object obj); - } - - public enum DispatchMode { - SEQ, - JTP, - OKRA - } - - public enum HsailMode { - COMPILED, - INJECT_HSAIL, - INJECT_OCL - } - - public DispatchMode dispatchMode; - // Where the hsail comes from. - private HsailMode hsailMode; - protected Method testMethod; - // What type of okra dispatch to use when client calls. - private boolean useLambdaMethod; - private Class[] testMethodParams = null; - private int id = nextId.incrementAndGet(); - static AtomicInteger nextId = new AtomicInteger(0); - public static Logger logger; - private OkraContext okraContext; - private OkraKernel okraKernel; - private static final String propPkgName = KernelTester.class.getPackage().getName(); - private static Level logLevel; - private static ConsoleHandler consoleHandler; - private boolean runOkraFirst = Boolean.getBoolean("kerneltester.runOkraFirst"); - - static { - logger = Logger.getLogger(propPkgName); - logLevel = Level.parse(System.getProperty("kerneltester.logLevel", "OFF")); - - // This block configure the logger with handler and formatter. - consoleHandler = new ConsoleHandler(); - logger.addHandler(consoleHandler); - logger.setUseParentHandlers(false); - SimpleFormatter formatter = new SimpleFormatter() { - - @SuppressWarnings("sync-override") - @Override - public String format(LogRecord record) { - return (record.getMessage() + "\n"); - } - }; - consoleHandler.setFormatter(formatter); - setLogLevel(logLevel); - } - - private static boolean gaveNoOkraWarning = false; - private boolean onSimulator; - private final boolean okraLibExists; - - public boolean runningOnSimulator() { - return onSimulator; - } - - public boolean okraEnvIsInitialized() { - return this.okraLibExists; - } - - public KernelTester(boolean okraLibExists) { - dispatchMode = DispatchMode.SEQ; - hsailMode = HsailMode.COMPILED; - useLambdaMethod = false; - - this.okraLibExists = okraLibExists || OkraUtil.okraLibExists(); - if (!this.okraLibExists) { - logger.info("Okra native library cannot be found or loaded while running" + this.getClass().getSimpleName()); - return; - } - - // Control which okra instances can run the tests (isSimulator is static). - onSimulator = OkraContext.isSimulator(); - } - - public abstract void runTest(); - - /** - * Asserts that the value of all {@link Result} annotated fields in this object and - * {@code other} are {@linkplain #assertDeepEquals(Object, Object) equal}. - * - * @throws AssertionError if the value of a result field in this and {@code other} are not equal - */ - public void assertResultFieldsEqual(KernelTester other) { - Class clazz = this.getClass(); - while (clazz != null && clazz != KernelTester.class) { - for (Field f : clazz.getDeclaredFields()) { - if (!Modifier.isStatic(f.getModifiers())) { - Result annos = f.getAnnotation(Result.class); - if (annos != null) { - Object actualResult = getFieldFromObject(f, this); - Object expectedResult = getFieldFromObject(f, other); - assertDeepEquals(f.toString(), expectedResult, actualResult); - } - } - } - clazz = clazz.getSuperclass(); - } - } - - public void setDispatchMode(DispatchMode dispatchMode) { - this.dispatchMode = dispatchMode; - } - - public void setHsailMode(HsailMode hsailMode) { - this.hsailMode = hsailMode; - } - - /** - * Return a clone of this instance unless overridden, we just call the null constructor. - */ - public KernelTester newInstance() { - try { - return this.getClass().getConstructor((Class[]) null).newInstance(); - } catch (Throwable t) { - fail("Unexpected exception " + t); - return null; - } - } - - public Method getMethodFromMethodName(String methName, Class clazz) { - Class clazz2 = clazz; - while (clazz2 != null) { - for (Method m : clazz2.getDeclaredMethods()) { - logger.fine(" in " + clazz2 + ", trying to match " + m); - if (m.getName().equals(methName)) { - testMethodParams = m.getParameterTypes(); - if (logLevel.intValue() <= Level.FINE.intValue()) { - logger.fine(" in " + clazz2 + ", matched " + m); - logger.fine("parameter types are..."); - int paramNum = 0; - for (Class pclazz : testMethodParams) { - logger.fine(paramNum++ + ") " + pclazz.toString()); - } - } - return m; - } - } - // Didn't find it in current clazz, try superclass. - clazz2 = clazz2.getSuperclass(); - } - // If we got this far, no match. - return null; - } - - private void setTestMethod(String methName, Class inClazz) { - testMethod = getMethodFromMethodName(methName, inClazz); - if (testMethod == null) { - fail("cannot find method " + methName + " in class " + inClazz); - } else { - // Print info but only for first such class. - if (id == 1) { - logger.fine("testMethod to be compiled is \n " + testMethod); - } - } - } - - // Default is method name "run", but could be overridden. - private final String defaultMethodName = "run"; - - public String getTestMethodName() { - return defaultMethodName; - } - - /** - * The dispatchMethodKernel dispatches a non-lambda method. All the parameters of the compiled - * method are supplied as parameters to this call. - */ - public void dispatchMethodKernel(int range, Object... args) { - if (testMethod == null) { - setTestMethod(getTestMethodName(), this.getClass()); - } - if (dispatchMode == DispatchMode.SEQ) { - dispatchMethodKernelSeq(range, args); - } else if (dispatchMode == DispatchMode.OKRA) { - dispatchMethodKernelOkra(range, args); - } - } - - /** - * The "array stream" version of {@link #dispatchMethodKernel(int, Object...)}. - */ - public void dispatchMethodKernel(Object[] ary, Object... args) { - if (testMethod == null) { - setTestMethod(getTestMethodName(), this.getClass()); - } - if (dispatchMode == DispatchMode.SEQ) { - dispatchMethodKernelSeq(ary, args); - } else if (dispatchMode == DispatchMode.OKRA) { - dispatchMethodKernelOkra(ary, args); - } - } - - /** - * This dispatchLambdaMethodKernel dispatches the lambda version of a kernel where the "kernel" - * is for the lambda method itself (like lambda$0). - */ - public void dispatchLambdaMethodKernel(int range, MyIntConsumer consumer) { - if (testMethod == null) { - setTestMethod(findLambdaMethodName(), this.getClass()); - } - if (dispatchMode == DispatchMode.SEQ) { - dispatchLambdaKernelSeq(range, consumer); - } else if (dispatchMode == DispatchMode.OKRA) { - dispatchLambdaMethodKernelOkra(range, consumer); - } - } - - public void dispatchLambdaMethodKernel(Object[] ary, MyObjConsumer consumer) { - if (testMethod == null) { - setTestMethod(findLambdaMethodName(), this.getClass()); - } - if (dispatchMode == DispatchMode.SEQ) { - dispatchLambdaKernelSeq(ary, consumer); - } else if (dispatchMode == DispatchMode.OKRA) { - dispatchLambdaMethodKernelOkra(ary, consumer); - } - } - - /** - * Dispatches the lambda version of a kernel where the "kernel" is for the xxx$$Lambda.accept - * method in the wrapper for the lambda. Note that the useLambdaMethod boolean provides a way of - * actually invoking dispatchLambdaMethodKernel from this API. - */ - public void dispatchLambdaKernel(int range, MyIntConsumer consumer) { - if (useLambdaMethod) { - dispatchLambdaMethodKernel(range, consumer); - return; - } - if (testMethod == null) { - setTestMethod("accept", consumer.getClass()); - } - if (dispatchMode == DispatchMode.SEQ) { - dispatchLambdaKernelSeq(range, consumer); - } else if (dispatchMode == DispatchMode.OKRA) { - dispatchLambdaKernelOkra(range, consumer); - } - } - - public void dispatchLambdaKernel(Object[] ary, MyObjConsumer consumer) { - if (useLambdaMethod) { - dispatchLambdaMethodKernel(ary, consumer); - return; - } - if (testMethod == null) { - setTestMethod("accept", consumer.getClass()); - } - if (dispatchMode == DispatchMode.SEQ) { - dispatchLambdaKernelSeq(ary, consumer); - } else if (dispatchMode == DispatchMode.OKRA) { - dispatchLambdaKernelOkra(ary, consumer); - } - } - - private ArrayList getLambdaMethodNames() { - Class clazz = this.getClass(); - ArrayList lambdaNames = new ArrayList<>(); - while (clazz != null && (lambdaNames.size() == 0)) { - for (Method m : clazz.getDeclaredMethods()) { - logger.fine(" in " + clazz + ", trying to match " + m); - if (m.getName().startsWith("lambda$")) { - lambdaNames.add(m.getName()); - } - } - // Didn't find it in current clazz, try superclass. - clazz = clazz.getSuperclass(); - } - return lambdaNames; - } - - /** - * findLambdaMethodName finds a name in the class starting with lambda$. If we find more than - * one, throw an error, and tell user to override explicitly - */ - private String findLambdaMethodName() { - // If user overrode getTestMethodName, use that name. - if (!getTestMethodName().equals(defaultMethodName)) { - return getTestMethodName(); - } else { - ArrayList lambdaNames = getLambdaMethodNames(); - switch (lambdaNames.size()) { - case 1: - return lambdaNames.get(0); - case 0: - fail("No lambda method found in " + this.getClass()); - return null; - default: - // More than one lambda. - String msg = "Multiple lambda methods found in " + this.getClass() + "\nYou should override getTestMethodName with one of the following\n"; - for (String name : lambdaNames) { - msg = msg + name + "\n"; - } - fail(msg); - return null; - } - } - } - - /** - * The getCompiledHSAILSource returns the string of HSAIL code for the compiled method. By - * default, throws an error. In graal for instance, this would be overridden in - * GraalKernelTester. - */ - public String getCompiledHSAILSource(Method testMethod1) { - fail("no compiler connected so unable to compile " + testMethod1 + "\nYou could try injecting HSAIL or OpenCL"); - return null; - } - - public String getHSAILSource(Method testMethod1) { - switch (hsailMode) { - case COMPILED: - return getCompiledHSAILSource(testMethod1); - case INJECT_HSAIL: - return getHsailFromClassnameHsailFile(); - case INJECT_OCL: - return getHsailFromClassnameOclFile(); - default: - fail("unknown hsailMode = " + hsailMode); - return null; - } - } - - /** - * The getHSAILKernelName returns the name of the hsail kernel. By default we use 'run'. unless - * coming from opencl injection. Could be overridden by the junit test. - */ - public String getHSAILKernelName() { - return (hsailMode != HsailMode.INJECT_OCL ? "&run" : "&__OpenCL_run_kernel"); - } - - private void createOkraKernel() { - // Call routines in the derived class to get the hsail code and kernel name. - String hsailSource = getHSAILSource(testMethod); - if (!okraLibExists) { - if (!gaveNoOkraWarning) { - logger.severe("No Okra library detected, skipping all KernelTester tests in " + this.getClass().getPackage().getName()); - gaveNoOkraWarning = true; - } - } - // Ignore any kerneltester test if okra does not exist. - assumeTrue("No Okra library detected, skipping test!", okraLibExists); - // Control which okra instances can run the tests. - onSimulator = OkraContext.isSimulator(); - okraContext = new OkraContext(); - if (!okraContext.isValid()) { - fail("...unable to create context"); - } - // Control verbosity in okra from our logLevel. - if (logLevel.intValue() <= Level.INFO.intValue()) { - okraContext.setVerbose(true); - } - okraKernel = new OkraKernel(okraContext, hsailSource, getHSAILKernelName()); - if (!okraKernel.isValid()) { - fail("...unable to create kernel"); - } - } - - /** - * Dispatches an okra kernel over a given range using JNI. Protected so that it can be - * overridden in {@link GraalKernelTester} which will dispatch without JNI. - */ - protected void dispatchKernelOkra(int range, Object... args) { - if (okraKernel == null) { - createOkraKernel(); - } - if (logLevel.intValue() <= Level.FINE.intValue()) { - logger.fine("Arguments passed to okra..."); - for (Object arg : args) { - logger.fine(" " + arg); - } - } - okraKernel.setLaunchAttributes(range); - okraKernel.dispatchWithArgs(args); - } - - // int stream version - private void dispatchMethodKernelSeq(int range, Object... args) { - Object[] invokeArgs = new Object[args.length + 1]; - // Need space on the end for the gid parameter. - System.arraycopy(args, 0, invokeArgs, 0, args.length); - int gidArgIndex = invokeArgs.length - 1; - if (logLevel.intValue() <= Level.FINE.intValue()) { - for (Object arg : args) { - logger.fine(arg.toString()); - } - } - for (int rangeIndex = 0; rangeIndex < range; rangeIndex++) { - invokeArgs[gidArgIndex] = rangeIndex; - invokeMethodKernelSeq(invokeArgs, rangeIndex); - } - } - - // array stream version - private void dispatchMethodKernelSeq(Object[] ary, Object... args) { - Object[] invokeArgs = new Object[args.length + 1]; - // Need space on the end for the final obj parameter. - System.arraycopy(args, 0, invokeArgs, 0, args.length); - int objArgIndex = invokeArgs.length - 1; - if (logLevel.intValue() <= Level.FINE.intValue()) { - for (Object arg : args) { - logger.fine(arg.toString()); - } - } - int range = ary.length; - for (int rangeIndex = 0; rangeIndex < range; rangeIndex++) { - invokeArgs[objArgIndex] = ary[rangeIndex]; - invokeMethodKernelSeq(invokeArgs, rangeIndex); - } - } - - private void invokeMethodKernelSeq(Object[] invokeArgs, int rangeIndex) { - try { - testMethod.invoke(this, invokeArgs); - } catch (IllegalAccessException e) { - fail("could not invoke " + testMethod + ", make sure it is public"); - } catch (IllegalArgumentException e) { - fail("wrong arguments invoking " + testMethod + ", check number and type of args passed to dispatchMethodKernel"); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - if (cause instanceof RuntimeException) { - throw ((RuntimeException) cause); - } else { - String errstr = testMethod + " threw a checked exception on gid=" + rangeIndex + ", exception was " + cause; - fail(errstr); - } - } catch (Exception e) { - fail("Unknown exception " + e + " invoking " + testMethod); - } - } - - // int stream version - private void dispatchMethodKernelOkra(int range, Object... args) { - Object[] fixedArgs = fixArgTypes(args); - if (Modifier.isStatic(testMethod.getModifiers())) { - dispatchKernelOkra(range, fixedArgs); - } else { - // If it is a non-static method we have to push "this" as the first argument. - Object[] newFixedArgs = new Object[fixedArgs.length + 1]; - System.arraycopy(fixedArgs, 0, newFixedArgs, 1, fixedArgs.length); - newFixedArgs[0] = this; - dispatchKernelOkra(range, newFixedArgs); - } - } - - // array stream version - private void dispatchMethodKernelOkra(Object[] ary, Object... args) { - // add the ary itself as the last arg in the passed parameter list - Object[] argsWithAry = new Object[args.length + 1]; - System.arraycopy(args, 0, argsWithAry, 0, args.length); - argsWithAry[argsWithAry.length - 1] = ary; - - Object[] fixedArgs = fixArgTypes(argsWithAry); - int range = ary.length; - if (Modifier.isStatic(testMethod.getModifiers())) { - dispatchKernelOkra(range, fixedArgs); - } else { - // If it is a non-static method we have to push "this" as the first argument. - Object[] newFixedArgs = new Object[fixedArgs.length + 1]; - System.arraycopy(fixedArgs, 0, newFixedArgs, 1, fixedArgs.length); - newFixedArgs[0] = this; - dispatchKernelOkra(range, newFixedArgs); - } - } - - /** - * For primitive arg parameters, make sure arg types are cast to whatever the testMethod - * signature says they should be. - */ - protected Object[] fixArgTypes(Object[] args) { - Object[] fixedArgs = new Object[args.length]; - for (int i = 0; i < args.length; i++) { - Class paramClass = testMethodParams[i]; - if (paramClass.equals(Float.class) || paramClass.equals(float.class)) { - fixedArgs[i] = ((Number) args[i]).floatValue(); - } else if (paramClass.equals(Integer.class) || paramClass.equals(int.class)) { - fixedArgs[i] = ((Number) args[i]).intValue(); - } else if (paramClass.equals(Long.class) || paramClass.equals(long.class)) { - fixedArgs[i] = ((Number) args[i]).longValue(); - } else if (paramClass.equals(Double.class) || paramClass.equals(double.class)) { - fixedArgs[i] = ((Number) args[i]).doubleValue(); - } else if (paramClass.equals(Byte.class) || paramClass.equals(byte.class)) { - fixedArgs[i] = ((Number) args[i]).byteValue(); - } else if (paramClass.equals(Boolean.class) || paramClass.equals(boolean.class)) { - fixedArgs[i] = (boolean) args[i]; - } else { - // All others just move unchanged. - fixedArgs[i] = args[i]; - } - } - return fixedArgs; - } - - /** - * Dispatching a lambda on the java side is simple. - */ - @SuppressWarnings("static-method") - private void dispatchLambdaKernelSeq(int range, MyIntConsumer consumer) { - for (int i = 0; i < range; i++) { - consumer.accept(i); - } - } - - @SuppressWarnings("static-method") - private void dispatchLambdaKernelSeq(Object[] ary, MyObjConsumer consumer) { - for (Object obj : ary) { - consumer.accept(obj); - } - } - - /** - * The dispatchLambdaMethodKernelOkra dispatches in the case where the hsail kernel implements - * the lambda method itself as opposed to the wrapper that calls the lambda method. From the - * consumer object, we need to find the fields and pass them to the kernel. - */ - protected void dispatchLambdaMethodKernelOkra(int range, MyIntConsumer consumer) { - logger.info("To determine parameters to pass to hsail kernel, we will examine " + consumer.getClass()); - Field[] fields = consumer.getClass().getDeclaredFields(); - Object[] args = new Object[fields.length]; - int argIndex = 0; - for (Field f : fields) { - logger.info("... " + f); - args[argIndex++] = getFieldFromObject(f, consumer); - } - dispatchKernelOkra(range, args); - } - - private void dispatchLambdaMethodKernelOkra(Object[] ary, MyObjConsumer consumer) { - logger.info("To determine parameters to pass to hsail kernel, we will examine " + consumer.getClass()); - Field[] fields = consumer.getClass().getDeclaredFields(); - Object[] args = new Object[fields.length + 1]; // + 1 because we also pass the array - int argIndex = 0; - for (Field f : fields) { - logger.info("... " + f); - args[argIndex++] = getFieldFromObject(f, consumer); - } - args[argIndex] = ary; - dispatchKernelOkra(ary.length, args); - } - - /** - * The dispatchLambdaKernelOkra dispatches in the case where the hsail kernel where the hsail - * kernel implements the accept method of the wrapper that calls the lambda method as opposed to - * the actual lambda method itself. - */ - private void dispatchLambdaKernelOkra(int range, MyIntConsumer consumer) { - // The "wrapper" method always has only one arg consisting of the consumer. - Object[] args = new Object[1]; - args[0] = consumer; - dispatchKernelOkra(range, args); - } - - private void dispatchLambdaKernelOkra(Object[] ary, MyObjConsumer consumer) { - // The "wrapper" method always has only one arg consisting of the consumer. - Object[] args = new Object[2]; - args[0] = consumer; - args[1] = ary; - dispatchKernelOkra(ary.length, args); - } - - private void disposeKernelOkra() { - if (okraContext != null) { - okraContext.dispose(); - } - } - - private void assertOkraEqualsSeq(HsailMode hsailModeToUse) { - assertOkraEqualsSeq(hsailModeToUse, false); - } - - /** - * Runs this instance on OKRA, and as SEQ and compares the output of the two executions. the - * runOkraFirst flag controls which order they are done in. Note the compiler must use eager - * resolving if Okra is done first. - */ - private void assertOkraEqualsSeq(HsailMode hsailModeToUse, boolean useLambda) { - KernelTester testerSeq; - if (runOkraFirst) { - runOkraInstance(hsailModeToUse, useLambda); - testerSeq = runSeqInstance(); - } else { - testerSeq = runSeqInstance(); - runOkraInstance(hsailModeToUse, useLambda); - } - assertResultFieldsEqual(testerSeq); - } - - private void runOkraInstance(HsailMode hsailModeToUse, boolean useLambda) { - // run Okra instance in exiting KernelTester object - this.setHsailMode(hsailModeToUse); - this.setDispatchMode(DispatchMode.OKRA); - this.useLambdaMethod = useLambda; - this.runTest(); - this.disposeKernelOkra(); - } - - private KernelTester runSeqInstance() { - // Create and run sequential instance. - KernelTester testerSeq = newInstance(); - testerSeq.setDispatchMode(DispatchMode.SEQ); - testerSeq.runTest(); - return testerSeq; - } - - public void testGeneratedHsail() { - assertOkraEqualsSeq(HsailMode.COMPILED); - } - - public void testGeneratedHsailUsingLambdaMethod() { - assertOkraEqualsSeq(HsailMode.COMPILED, true); - } - - public void testInjectedHsail() { - newInstance().assertOkraEqualsSeq(HsailMode.INJECT_HSAIL); - } - - public void testInjectedOpencl() { - newInstance().assertOkraEqualsSeq(HsailMode.INJECT_OCL); - } - - protected static Object getFieldFromObject(Field f, Object fromObj) { - try { - f.setAccessible(true); - Type type = f.getType(); - logger.info("type = " + type); - if (type == double.class) { - return f.getDouble(fromObj); - } else if (type == float.class) { - return f.getFloat(fromObj); - } else if (type == long.class) { - return f.getLong(fromObj); - } else if (type == int.class) { - return f.getInt(fromObj); - } else if (type == byte.class) { - return f.getByte(fromObj); - } else if (type == boolean.class) { - return f.getBoolean(fromObj); - } else { - return f.get(fromObj); - } - } catch (Exception e) { - fail("unable to get field " + f + " from " + fromObj); - return null; - } - } - - public static void checkFileExists(String fileName) { - assertTrue(fileName + " does not exist", fileExists(fileName)); - } - - public static boolean fileExists(String fileName) { - return new File(fileName).exists(); - } - - public static String getFileAsString(String sourceFileName) { - String source = null; - try { - checkFileExists(sourceFileName); - source = new String(Files.readAllBytes(FileSystems.getDefault().getPath(sourceFileName))); - } catch (IOException e) { - fail("could not open file " + sourceFileName); - return null; - } - return source; - } - - public static String getHsailFromFile(String sourceFileName) { - logger.severe("... getting hsail from file " + sourceFileName); - return getFileAsString(sourceFileName); - } - - private static void executeCmd(String... cmd) { - logger.info("spawning" + Arrays.toString(cmd)); - try { - ProcessBuilder pb = new ProcessBuilder(cmd); - Process p = pb.start(); - if (logLevel.intValue() <= Level.INFO.intValue()) { - InputStream in = p.getInputStream(); - BufferedInputStream buf = new BufferedInputStream(in); - InputStreamReader inread = new InputStreamReader(buf); - BufferedReader bufferedreader = new BufferedReader(inread); - String line; - while ((line = bufferedreader.readLine()) != null) { - logger.info(line); - } - } - p.waitFor(); - } catch (Exception e) { - fail("could not execute <" + Arrays.toString(cmd) + ">"); - } - } - - public static String getHsailFromOpenCLFile(String openclFileName) { - String openclHsailFile = "opencl_out.hsail"; - String tmpTahitiFile = "_temp_0_Tahiti.txt"; - checkFileExists(openclFileName); - logger.severe("...converting " + openclFileName + " to HSAIL..."); - executeCmd("aoc2", "-m64", "-I./", "-march=hsail", openclFileName); - if (fileExists(tmpTahitiFile)) { - return getFileAsString(tmpTahitiFile); - } else { - executeCmd("HSAILasm", "-disassemble", "-o", openclHsailFile, openclFileName.replace(".cl", ".bin")); - checkFileExists(openclHsailFile); - return getFileAsString(openclHsailFile); - } - } - - public String getHsailFromClassnameHsailFile() { - return (getHsailFromFile(this.getClass().getSimpleName() + ".hsail")); - } - - public String getHsailFromClassnameOclFile() { - return (getHsailFromOpenCLFile(this.getClass().getSimpleName() + ".cl")); - } - - public static void logInfo(String msg) { - logger.info(msg); - } - - public static void logSevere(String msg) { - logger.severe(msg); - } - - public static void setLogLevel(Level level) { - logLevel = level; - logger.setLevel(level); - consoleHandler.setLevel(level); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for an IJ signature {@code IntStream} instance function. - */ -public abstract class ArgsIntBase extends GraalKernelTester { - - static final int NUM = 20; - - @Result public double[] outArray = new double[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntInstIITest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntInstIITest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an II signature {@code IntStream} instance function. - */ -public class ArgsIntInstIITest extends ArgsIntBase { - - public void run(int arg1, int arg2, int gid) { - outArray[gid] = gid + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(NUM, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntInstIJTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntInstIJTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an IJ signature {@code IntStream} instance function. - */ -public class ArgsIntInstIJTest extends ArgsIntBase { - - public void run(int arg1, long arg2, int gid) { - outArray[gid] = gid + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(NUM, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntStatAIITest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntStatAIITest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an AII signature {@code IntStream} static function. - */ -public class ArgsIntStatAIITest extends ArgsIntBase { - - public static void run(double[] out, int arg1, int arg2, int gid) { - out[gid] = gid + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(NUM, outArray, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntStatAIJTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsIntStatAIJTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an AIJ signature {@code IntStream} static function. - */ -public class ArgsIntStatAIJTest extends ArgsIntBase { - - public static void run(double[] out, int arg1, long arg2, int gid) { - out[gid] = gid + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(NUM, outArray, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for an IJ signature Object stream instance function. - */ -public abstract class ArgsObjBase extends GraalKernelTester { - - static class MyObj { - public int id; - public double d; - - public MyObj(int id) { - this.id = id; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof MyObj)) { - return false; - } - MyObj oth = (MyObj) other; - return (oth.id == id && oth.d == d); - } - - @Override - public String toString() { - return ("MyObj[" + id + ", " + d + "]"); - } - - @Override - public int hashCode() { - return id; - } - - } - - static final int NUM = 20; - - @Result public MyObj[] outArray = new MyObj[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = new MyObj(i + 1); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjInstIITest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjInstIITest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an II signature Object stream instance function. - */ -public class ArgsObjInstIITest extends ArgsObjBase { - - public void run(int arg1, int arg2, MyObj myobj) { - myobj.d = myobj.id + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(outArray, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjInstIJTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjInstIJTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an IJ signature Object stream instance function. - */ -public class ArgsObjInstIJTest extends ArgsObjBase { - - public void run(int arg1, long arg2, MyObj myobj) { - myobj.d = myobj.id + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(outArray, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjStatIITest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjStatIITest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an II signature Object stream static function. - */ -public class ArgsObjStatIITest extends ArgsObjBase { - - public static void run(int arg1, int arg2, MyObj myobj) { - myobj.d = myobj.id + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(outArray, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjStatIJTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ArgsObjStatIJTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for an IJ signature Object stream static function. - */ -public class ArgsObjStatIJTest extends ArgsObjBase { - - public static void run(int arg1, long arg2, MyObj myobj) { - myobj.d = myobj.id + arg1 + arg2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(outArray, 7, 6); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicIntGetAndAddTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicIntGetAndAddTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.hsail.test; - -import java.util.*; -import java.util.concurrent.atomic.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests {@link AtomicInteger#getAndAdd(int)} which tests HSAIL atomic_add codegen. - */ -public class AtomicIntGetAndAddTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - public void run(int gid) { - outArray[gid] = atomicInt.getAndAdd(0x7); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicIntGetAndSetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicIntGetAndSetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * 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.hsail.test; - -import java.util.*; -import java.util.concurrent.atomic.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests {@link AtomicInteger#getAndSet(int)} which tests HSAIL atomic_exch codegen. - */ -public class AtomicIntGetAndSetTest extends GraalKernelTester { - - static final int NUM = 1000; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(Integer.MAX_VALUE); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - // to complete the circle, replace the initial get value with that of the last executor - for (int i = 0; i < NUM; i++) { - if (outArray[i] == Integer.MAX_VALUE) { - outArray[i] = atomicInt.get(); - } - } - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - public void run(int gid) { - outArray[gid] = atomicInt.getAndSet(gid); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicLongGetAndAddTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicLongGetAndAddTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.hsail.test; - -import java.util.*; -import java.util.concurrent.atomic.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests {@link AtomicLong#getAndAdd(long)} which tests HSAIL atomic_add codegen. - */ -public class AtomicLongGetAndAddTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - AtomicLong atomicLong = new AtomicLong(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - public void run(int gid) { - outArray[gid] = atomicLong.getAndAdd(0x7); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicLongGetAndSetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicLongGetAndSetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * 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.hsail.test; - -import java.util.*; -import java.util.concurrent.atomic.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests {@link AtomicLong#getAndSet(long)} which tests HSAIL atomic_exch codegen. - */ -public class AtomicLongGetAndSetTest extends GraalKernelTester { - - static final int NUM = 1000; - @Result public long[] outArray = new long[NUM]; - AtomicLong atomicLong = new AtomicLong(Long.MAX_VALUE); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - // to complete the circle, replace the initial get value with that of the last executor - for (int i = 0; i < NUM; i++) { - if (outArray[i] == Long.MAX_VALUE) { - outArray[i] = atomicLong.get(); - } - } - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - public void run(int gid) { - outArray[gid] = atomicLong.getAndSet(gid); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicReferenceGetAndSetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/AtomicReferenceGetAndSetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * 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.hsail.test; - -import java.util.concurrent.atomic.*; - -import org.junit.*; - -import sun.misc.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; -import com.oracle.graal.debug.*; - -/** - * Tests {@link AtomicReference#getAndSet(Object)} which indirectly tests - * {@link Unsafe#compareAndSwapObject(Object, long, Object, Object)}. The latter requires special - * handling if compressed oops are enabled. - */ -public class AtomicReferenceGetAndSetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] followedCount = new int[NUM]; - public MyObj[] inArray = new MyObj[NUM]; - AtomicReference atomicRef = new AtomicReference<>(); - - public static class MyObj { - public int val; - public boolean[] followedBy = new boolean[NUM + 1]; - - MyObj(int n) { - val = n; - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new MyObj(i + 1); - } - atomicRef.set(new MyObj(0)); // initial value - } - - private static final boolean DEBUG = false; - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - - // make a fake followedBy for the final object - MyObj finalObj = atomicRef.get(); - finalObj.followedBy[0] = true; - - // When the kernel is done, compute the number of true bits in each followedBy array; - for (int i = 0; i < NUM; i++) { - MyObj obj = inArray[i]; - int count = 0; - for (int j = 0; j < NUM + 1; j++) { - boolean b = obj.followedBy[j]; - if (b) { - count++; - if (DEBUG) { - TTY.println("obj " + obj.val + " was followed by " + j); - } - } - - } - followedCount[i] = count; - } - } - - public void run(int gid) { - MyObj newObj = inArray[gid]; - MyObj oldObj = atomicRef.getAndSet(newObj); - oldObj.followedBy[newObj.val] = true; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BasicHSAILTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BasicHSAILTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,387 +0,0 @@ -/* - * Copyright (c) 2011, 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 static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; - -import org.junit.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.target.*; -import com.oracle.graal.compiler.test.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.gpu.*; -import com.oracle.graal.hotspot.hsail.*; -import com.oracle.graal.hsail.*; - -/** - * Test class for small Java methods compiled to HSAIL kernels. - */ -public class BasicHSAILTest extends GraalCompilerTest { - - public BasicHSAILTest() { - super(HSAIL.class); - } - - public void testAdd() { - test("testAddSnippet"); - } - - public static int testAddSnippet(int a) { - return a * a; - } - - public void testArrayConstantIndex() { - test("testArrayReturnFirstElement"); - } - - public void testArrayVariableIndex() { - test("testArrayReturnIthElement"); - } - - public void testArrayMultiplyConstant() { - test("testArrayMultiplyZero"); - } - - public void testArrayMultiplyVar() { - test("testArrayMultiplyGid"); - } - - public void testArrayMisc() { - test("testArrayLocalVariable"); - } - - public void testArrayLoopVar() { - test("testArrayMultiplyGidLoop"); - } - - void setupPalette(int[] in) { - for (int i = 0; i < in.length; i++) { - in[i] = i; - } - } - - public void testNBody() { - test("nBodySpill"); - } - - public void testArrayMandel() { - final int width = 768; - final int height = width; - int loopiterations = 1; - int counter = 0; - final int range = width * height; - int[] rgb = new int[range]; - int[] palette = new int[range]; - setupPalette(palette); - while (counter < loopiterations) { - for (int gid = 0; gid < range; gid++) { - testMandelSimple(rgb, palette, -1.0f, 0.0f, 3f, gid); - } - counter++; - } - test("testMandelSimple"); - } - - public void testDanglingElse() { - test("danglingElse"); - } - - public void testIntSquaresTernary() { - test("intSquaresTernary"); - } - - public void testDanglingElse2() { - test("danglingElse2"); - } - - public void testDanglingElse3() { - test("danglingElse3"); - } - - public void testSimpleIf() { - test("simpleIf"); - } - - public void testParams11() { - test("testParams1"); - } - - public void testParams21() { - test("testParams2"); - } - - public void testParams31() { - test("testParams3"); - } - - public void testAssignment1() { - test("testAssignment"); - } - - public void testArithmetic1() { - test("testArithmetic"); - } - - public void testSimpleWhile1() { - test("testSimpleWhile"); - } - - public void testComplexWhile1() { - test("testComplexWhile"); - } - - public void testSquaresThree() { - test("testMulThreeArrays"); - } - - @Test - public void testCondMoves() { - test("testMinI"); - test("testMinF"); - } - - public int testMinI(int a, int b) { - return (a < b ? 1 : 2); - } - - public float testMinF(int a, int b) { - return (a < b ? 1.0f : 2.0f); - } - - public static void testMulThreeArrays(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = ina[gid] * inb[gid]; - } - - public static int testArrayMultiplyZero(int[] array1, int[] array2) { - return array1[0] = array2[0] * array2[0]; - } - - public static int testArrayMultiplyGid(int[] array1, int[] array2, int gid) { - return array1[gid] = array2[gid] * array2[gid]; - } - - public static float testParams3(float c, float d, float e) { - return c + d + e; - } - - public static int testAssignment() { - final int width = 768; - final int height = 768; - final int maxIterations = 64; - return width * height * maxIterations; - } - - public static int testSimpleWhile(int i) { - int count = 0; - int j = 0; - final int maxIterations = 64; - while (count < maxIterations) { - j += count * i; - count++; - } - return j; - } - - public static void testComplexWhile() { - float lx = 1; - float ly = 2; - float zx = lx; - float zy = ly; - float newzx = 0f; - final int maxIterations = 64; - int count = 0; - while (count < maxIterations && zx * zx + zy * zy < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - } - - public static void testMandel(int[] rgb, int[] pallette, float xoffset, float yoffset, float scale, int gid) { - final int width = 768; - final int height = 768; - final int maxIterations = 64; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; - int count = 0; - float zx = lx; - float zy = ly; - float newzx = 0f; - /** - * Iterate until the algorithm converges or until maxIterations are reached. - */ - while (count < maxIterations && zx * zx + zy * zy < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - rgb[gid] = pallette[count]; - } - - public static void testMandelSimple(int[] rgb, int[] pallette, float xoffset, float yoffset, float scale, int gid) { - final int width = 768; - final int height = width; - final int maxIterations = 64; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; - int count = 0; - float zx = lx; - float zy = ly; - float newzx = 0f; - /** - * Iterate until the algorithm converges or until maxIterations are reached. - */ - while (count < maxIterations && zx * zx + zy * zy < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - rgb[gid] = pallette[count]; - } - - public static void testMandel2(int[] rgb, int[] pallette, int xoffseti, int yoffseti, int scalei, int gid) { - final int width = 768; - final int height = 768; - final int maxIterations = 64; - float xoffset = xoffseti; - float yoffset = yoffseti; - float scale = scalei; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; - int count = 0; - float zx = lx; - float zy = ly; - float newzx = 0f; - /** - * Iterate until the algorithm converges or until maxIterations are reached. - */ - while (count < maxIterations && zx * zx + zy * zy < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - rgb[gid] = pallette[count]; - } - - public static int testArrayLocalVariable(int gid, int[] array) { - int foo = 198; - return array[gid + foo]; - } - - public static int testArrayReturnFirstElement(int[] array) { - return array[0]; - } - - public static int testArrayReturnIthElement(int i, int[] array) { - return array[i]; - } - - public static void simpleIf(int[] out, int[] in, int gid) { - if (gid > 9) { - out[gid] = in[gid] * in[gid]; - } - } - - public static int danglingElse(int a) { - return (a > 5) ? (a + 7) : (a - 3); - } - - public static int danglingElse2(int a, int b) { - if (a > 5) { - return (a + 7 * (b - 4 + a)); - } else { - return (a - 3 + b * 3 * a + 5); - } - } - - public static int danglingElse3(int a, int b) { - int val; - if (a > 5) { - val = (a + 7 * (b - 4 + a)); - } else { - val = (a - 3 + b * 3 * a + 5); - } - return val + a; - } - - public static void intSquaresTernary(int[] out, int[] in, int gid) { - int val = in[gid] * in[gid]; - val = (val % 2 == 1 ? val + 1 : val); - out[gid] = val; - } - - @Override - protected HSAILHotSpotBackend getBackend() { - Backend backend = super.getBackend(); - Assume.assumeTrue("No HSAIL backend, skipping test!", backend instanceof HSAILHotSpotBackend); - return (HSAILHotSpotBackend) backend; - } - - private void test(final String snippet) { - try (DebugConfigScope dcs = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { - try (Scope s = Debug.scope("HSAILCodeGen")) { - ResolvedJavaMethod method = getResolvedJavaMethod(snippet); - ExternalCompilationResult hsailCode = getBackend().compileKernel(method, false); - Debug.log("HSAIL code generated for %s:%n%s", snippet, hsailCode.getCodeString()); - } catch (Throwable e) { - throw Debug.handle(e); - } - } - } - - public static void nBodySpill(float[] inxyz, float[] outxyz, float[] invxyz, float[] outvxyz, int gid) { - final int bodies = 8; - final float delT = .005f; - final float espSqr = 1.0f; - final float mass = 5f; - final int count = bodies * 3; - final int globalId = gid * 3; - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - for (int i = 0; i < count; i += 3) { - final float dx = inxyz[i + 0] - inxyz[globalId + 0]; - final float dy = inxyz[i + 1] - inxyz[globalId + 1]; - final float dz = inxyz[i + 2] - inxyz[globalId + 2]; - final float invDist = (float) (1.0 / (Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr))); - accx += mass * invDist * invDist * invDist * dx; - accy += mass * invDist * invDist * invDist * dy; - accz += mass * invDist * invDist * invDist * dz; - } - accx *= delT; - accy *= delT; - accz *= delT; - outxyz[globalId + 0] = inxyz[globalId + 0] + (invxyz[globalId + 0] * delT) + (accx * .5f * delT); - outxyz[globalId + 1] = inxyz[globalId + 1] + (invxyz[globalId + 1] * delT) + (accy * .5f * delT); - outxyz[globalId + 2] = inxyz[globalId + 2] + (invxyz[globalId + 2] * delT) + (accz * .5f * delT); - outvxyz[globalId + 0] = invxyz[globalId + 0] + accx; - outvxyz[globalId + 1] = invxyz[globalId + 1] + accy; - outvxyz[globalId + 2] = invxyz[globalId + 2] + accz; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestFF.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestFF.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two boolean values which are both false. - */ -public class BooleanBitwiseAndTestFF extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = false; - in2[i] = false; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestFT.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestFT.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two booleans. First input is false and second input is true. - */ -public class BooleanBitwiseAndTestFT extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = false; - in2[i] = true; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestTF.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestTF.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two booleans. First input is true and second is false. - */ -public class BooleanBitwiseAndTestTF extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = true; - in2[i] = false; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestTT.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseAndTestTT.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two booleans. Both inputs are true. - */ -public class BooleanBitwiseAndTestTT extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = true; - in2[i] = true; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestFF.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestFF.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two booleans. Both inputs are false. - */ -public class BooleanBitwiseOrTestFF extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = false; - in2[i] = false; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestFT.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestFT.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two booleans. First input is false. Second input is true. - */ -public class BooleanBitwiseOrTestFT extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = false; - in2[i] = true; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestTF.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestTF.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two booleans. First input is true. Second input is false. - */ -public class BooleanBitwiseOrTestTF extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = true; - in2[i] = false; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestTT.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseOrTestTT.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two booleans. Both inputs are true. - */ -public class BooleanBitwiseOrTestTT extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = true; - in2[i] = true; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestFF.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestFF.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two booleans. Both inputs are false. - */ -public class BooleanBitwiseXorTestFF extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = false; - in2[i] = false; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestFT.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestFT.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two booleans. First input is false. Second input is true. - */ -public class BooleanBitwiseXorTestFT extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = false; - in2[i] = true; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestTF.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestTF.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two booelans. First input is true. Second input is false. - */ -public class BooleanBitwiseXorTestTF extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = true; - in2[i] = false; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestTT.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BooleanBitwiseXorTestTT.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two booleans. Both inputs are true. - */ -public class BooleanBitwiseXorTestTT extends GraalKernelTester { - - static final int num = 20; - @Result protected boolean[] outArray = new boolean[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(boolean[] out, boolean[] ina, boolean[] inb, int gid) { - out[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(boolean[] in, boolean[] in2) { - for (int i = 0; i < num; i++) { - in[i] = true; - in2[i] = true; - outArray[i] = false; - } - } - - @Override - public void runTest() { - boolean[] inArray = new boolean[num]; - boolean[] inArray2 = new boolean[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Base Class for tests that deopt but then catch the exception in the run routine itself. - */ -public abstract class BoundsCatchBase extends GraalKernelTester { - - abstract int getGlobalSize(); - - final int num = getGlobalSize(); - @Result int[] outArray = new int[num]; - - void setupArrays() { - for (int i = 0; i < num; i++) { - outArray[i] = -i; - } - } - - // Note: could not push the whole run routine here because - // problems with indirect call to getDeoptGid - int getOutval(int gid) { - int adjustment = 0; - int tmp = gid + 10; - while (tmp > gid) { - adjustment += tmp; - tmp--; - } - int outval = (outArray[gid] * -1) + adjustment; - return outval; - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canDeoptimize(); - } - - @Override - public void runTest() { - setupArrays(); - - // we should not get an exception escaping from the kernel - dispatchMethodKernel(num); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany16384Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany16384Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 16384, deopt on many gids but then catch the exception in the run routine itself. - */ -public class BoundsCatchMany16384Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 16384; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany20000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany20000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 20000, deopt on many gids but then catch the exception in the run routine itself. - */ -public class BoundsCatchMany20000Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 20000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany5000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany5000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 5000, deopt on many gids but then catch the exception in the run routine itself. - */ -public class BoundsCatchMany5000Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 5000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany8192Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany8192Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 8192, deopt on many gids but then catch the exception in the run routine itself. - */ -public class BoundsCatchMany8192Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 8192; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany987654HighTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany987654HighTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 987654, deopt on many gids but then catch the exception in the run routine itself - * deopt ids are at the high end. - */ -public class BoundsCatchMany987654HighTest extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 987654; - } - - boolean isMyDeoptGid(int gid) { - return (gid > getGlobalSize() - 4096 && gid % 512 == 1); - } - - // copied run routine here because otherwise polymorphic calls to isDeoptGid - @Override - public void run(int gid) { - int outval = getOutval(gid); - try { - int index = (isMyDeoptGid(gid) ? num + 1 : gid); - outArray[index] = outval; - } catch (ArrayIndexOutOfBoundsException e) { - // set up so we can detect if we go thru here twice - outArray[gid] += outval; - // note: cannot record the exceptiongid here for many deopts in parallel - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany987654Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany987654Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 987654, deopt on many gids but then catch the exception in the run routine itself. - */ -public class BoundsCatchMany987654Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 987654; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany99999Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMany99999Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 99999, deopt on many gids but then catch the exception in the run routine itself. - */ -public class BoundsCatchMany99999Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 99999; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchManyBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchManyBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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; - -/** - * Base Class for tests that deopt on multiple gids gid but then catches the exception in the run - * routine itself. - */ -public abstract class BoundsCatchManyBase extends BoundsCatchBase { - - boolean isDeoptGid(int gid) { - return (gid < 4096 && gid % 512 == 1); - } - - public void run(int gid) { - int outval = getOutval(gid); - try { - int index = (isDeoptGid(gid) ? num + 1 : gid); - outArray[index] = outval; - } catch (ArrayIndexOutOfBoundsException e) { - // set up so we can detect if we go thru here twice - outArray[gid] += outval; - // note: cannot record the exceptiongid here for many deopts in parallel - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMost1000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMost1000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 1000, deopt on almost all gids but then catch the exception in the run routine - * itself. - */ -public class BoundsCatchMost1000Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 1000; - } - - boolean isMyDeoptGid(int gid) { - return (gid % 100 != 1); - } - - // copied run routine here because otherwise polymorphic calls to isDeoptGid - @Override - public void run(int gid) { - int outval = getOutval(gid); - try { - int index = (isMyDeoptGid(gid) ? num + 1 : gid); - outArray[index] = outval; - } catch (ArrayIndexOutOfBoundsException e) { - // set up so we can detect if we go thru here twice - outArray[gid] += outval; - // note: cannot record the exceptiongid here for many deopts in parallel - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMost20000StressGCTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMost20000StressGCTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * 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.*; - -/** - * A version which is likely to get a GC while running the never_rans, and so is good for oops_do - * testing. - */ -public class BoundsCatchMost20000StressGCTest extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 20000; - } - - boolean isMyDeoptGid(int gid) { - return (gid > 100 && gid % 100 != 1); - } - - int[] dummyArray; - - // copied run routine here because otherwise polymorphic calls to isDeoptGid - @Override - public void run(int gid) { - int outval = getOutval(gid); - try { - int index = (isMyDeoptGid(gid) ? num + 1 : gid); - outArray[index] = outval; - } catch (ArrayIndexOutOfBoundsException e) { - // set up so we can detect if we go thru here twice - outArray[gid] += outval; - // note: cannot record the exceptiongid here for many deopts in parallel - - // allocate something so GCs happen more often - dummyArray = new int[1000]; - } - } - - @Override - public void runTest() { - setupArrays(); - - for (int i = 0; i < 10; i++) { - // we should not get an exception escaping from the kernel - dispatchMethodKernel(num); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMost20000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchMost20000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 20000, deopt on almost all gids but then catch the exception in the run routine - * itself. - */ -public class BoundsCatchMost20000Test extends BoundsCatchManyBase { - - @Override - int getGlobalSize() { - return 20000; - } - - boolean isMyDeoptGid(int gid) { - return (gid % 100 != 1); - } - - // copied run routine here because otherwise polymorphic calls to isDeoptGid - @Override - public void run(int gid) { - int outval = getOutval(gid); - try { - int index = (isMyDeoptGid(gid) ? num + 1 : gid); - outArray[index] = outval; - } catch (ArrayIndexOutOfBoundsException e) { - // set up so we can detect if we go thru here twice - outArray[gid] += outval; - // note: cannot record the exceptiongid here for many deopts in parallel - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle16384Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle16384Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 16384, deopt on a single gid but then catch the exception in the run routine - * itself. - */ -public class BoundsCatchSingle16384Test extends BoundsCatchSingleBase { - - @Override - int getGlobalSize() { - return 16384; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle20000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle20000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 20000, deopt on a single gid but then catch the exception in the run routine - * itself. - */ -public class BoundsCatchSingle20000Test extends BoundsCatchSingleBase { - - @Override - int getGlobalSize() { - return 20000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle5000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle5000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 5000, deopt on a single gid but then catch the exception in the run routine - * itself. - */ -public class BoundsCatchSingle5000Test extends BoundsCatchSingleBase { - - @Override - int getGlobalSize() { - return 5000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle8192Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingle8192Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * 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.*; - -/** - * For globalsize 8192, deopt on a single gid but then catch the exception in the run routine - * itself. - */ -public class BoundsCatchSingle8192Test extends BoundsCatchSingleBase { - - @Override - int getGlobalSize() { - return 8192; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingleBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCatchSingleBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * 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; - -/** - * Base Class for tests that deopt on a single gid but then catch the exception in the run routine - * itself. - */ -public abstract class BoundsCatchSingleBase extends BoundsCatchBase { - - int getDeoptGid() { - return 512; - } - - boolean isDeoptGid(int gid) { - return (gid == getDeoptGid()); - } - - @Result public int exceptionGid; - - public void run(int gid) { - int outval = getOutval(gid); - try { - int index = (isDeoptGid(gid) ? num + 1 : gid); - outArray[index] = outval; - } catch (ArrayIndexOutOfBoundsException e) { - // set up so we can detect if we go thru here twice - outArray[gid] -= outval; - exceptionGid = gid; - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckDoubleNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckDoubleNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code. - */ -public class BoundsCheckDoubleNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - double[] outArray = new double[num]; - - void setupArrays(double[] in1, double[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - static double dummyDouble = 10; - - public static void run(double[] out, double[] ina, double[] inb, int gid) { - // This will fail when gid+1==num - double adjustment = 0; - double tmp = dummyDouble; - while (tmp-- >= 0) { - adjustment += tmp; - } - out[gid + 1] = ina[gid] + inb[gid] + adjustment; - } - - @Override - public void runTest() { - double[] inArray1 = new double[num]; - double[] inArray2 = new double[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckFailsInMiddleTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckFailsInMiddleTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code, in the middle of the array. - */ -public class BoundsCheckFailsInMiddleTest extends SingleExceptionTestBase { - static final int num = 128; // * 256; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - int[] outArray = new int[num]; - static final int abortingGid = (new java.util.Random()).nextInt(num / 4); - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -99; - } - } - - public static void run(int[] out, int[] ina, int[] inb, int gid) { - // Throw in the middle of doing the work - out[gid == abortingGid ? (gid + num) : gid] = ina[gid] + inb[gid]; - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckFloatNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckFloatNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code. - */ -public class BoundsCheckFloatNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - float[] outArray = new float[num]; - - void setupArrays(float[] in1, float[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - static float dummyFloat = 10; - - public static void run(float[] out, float[] ina, float[] inb, int gid) { - // This will fail when gid+1==num - float adjustment = 0; - float tmp = dummyFloat; - while (tmp-- >= 0) { - adjustment += tmp; - } - out[gid + 1] = ina[gid] + inb[gid] + adjustment; - } - - @Override - public void runTest() { - float[] inArray1 = new float[num]; - float[] inArray2 = new float[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckInlineTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckInlineTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * 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.*; - -/** - * - * @author ecaspole - */ -public class BoundsCheckInlineTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - int[] outArray = new int[num]; - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - static volatile int dummy; - - static void writesum(int[] out, int gid, int val) { - out[gid + 1] = val; - } - - public static void run(int[] out, int[] ina, int[] inb, int gid) { - // This will fail when gid+1==num - writesum(out, gid, ina[gid] + inb[gid]); - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckLongNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckLongNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code. - */ -public class BoundsCheckLongNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - long[] outArray = new long[num]; - - void setupArrays(long[] in1, long[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - static long dummyLong = 10; - - public static void run(long[] out, long[] ina, long[] inb, int gid) { - // This will fail when gid+1==num - long adjustment = 0x1234567890abcdefL; - long tmp = dummyLong; - while (tmp-- >= 0) { - adjustment += tmp; - } - out[gid + 1] = ina[gid] + inb[gid] + adjustment; - } - - @Override - public void runTest() { - long[] inArray1 = new long[num]; - long[] inArray2 = new long[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckNonZeroBciInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckNonZeroBciInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code. - */ -public class BoundsCheckNonZeroBciInstanceTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - int[] outArray = new int[num]; - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - int dummyInt = 10; - - public void run(int gid) { - // This will fail when gid+1==num - int adjustment = 0; - int tmp = dummyInt; - while (tmp-- >= 0) { - adjustment += tmp; - } - outArray[gid + 1] = inArray1[gid] + inArray2[gid] + adjustment; - } - - @Override - public void runTest() { - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code. - */ -public class BoundsCheckNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - int[] outArray = new int[num]; - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - static int dummyInt = 10; - - public static void run(int[] out, int[] ina, int[] inb, int gid) { - // This will fail when gid+1==num - int adjustment = 0; - int tmp = dummyInt; - while (tmp-- >= 0) { - adjustment += tmp; - } - out[gid + 1] = ina[gid] + inb[gid] + adjustment; - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/BoundsCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.*; - -/** - * This test deliberately causes an ArrayIndexOutOfBoundsException to test throwing the exception - * back to the java code. - */ -public class BoundsCheckTest extends SingleExceptionTestBase { - - static final int num = 20; - // note: outArray not marked as @Result because we can't predict - // which workitems will get done in parallel execution - int[] outArray = new int[num]; - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - in1[i] = i; - in2[i] = i + 1; - outArray[i] = -i; - } - } - - public static void run(int[] out, int[] ina, int[] inb, int gid) { - // This will fail when gid+1==num - out[gid + 1] = ina[gid] + inb[gid]; - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseAndCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseAndCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two bytes and casts the result to a byte. - */ -public class ByteBitwiseAndCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected byte[] outArray1 = new byte[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(byte[] out1, byte[] ina, byte[] inb, int gid) { - out1[gid] = (byte) (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(byte[] in, byte[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (byte) (i + i); - in2[i] = (byte) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - byte[] inArray = new byte[num]; - byte[] inArray2 = new byte[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseAndTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseAndTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two bytes. - */ -public class ByteBitwiseAndTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, byte[] ina, byte[] inb, int gid) { - out1[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(byte[] in, byte[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (byte) (i + i); - in2[i] = (byte) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - byte[] inArray = new byte[num]; - byte[] inArray2 = new byte[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseOrCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseOrCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two bytes and casts the result to a byte. - */ -public class ByteBitwiseOrCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected byte[] outArray1 = new byte[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(byte[] out1, byte[] ina, byte[] inb, int gid) { - out1[gid] = (byte) (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(byte[] in, byte[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (byte) (i * 2); - in2[i] = (byte) (i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - byte[] inArray = new byte[num]; - byte[] inArray2 = new byte[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseOrTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseOrTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two bytes. - */ -public class ByteBitwiseOrTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, byte[] ina, byte[] inb, int gid) { - out1[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(byte[] in, byte[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (byte) (i * 2); - in2[i] = (byte) (i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - byte[] inArray = new byte[num]; - byte[] inArray2 = new byte[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseXorCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseXorCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two bytes and casts the result to a byte. - */ -public class ByteBitwiseXorCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected byte[] outArray1 = new byte[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(byte[] out1, byte[] ina, byte[] inb, int gid) { - out1[gid] = (byte) (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(byte[] in, byte[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (byte) (i); - in2[i] = (byte) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - byte[] inArray = new byte[num]; - byte[] inArray2 = new byte[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseXorTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ByteBitwiseXorTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two bytes. - */ -public class ByteBitwiseXorTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, byte[] ina, byte[] inb, int gid) { - out1[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(byte[] in, byte[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (byte) (i); - in2[i] = (byte) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - byte[] inArray = new byte[num]; - byte[] inArray2 = new byte[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CallTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CallTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests direct method calls. - */ -public class CallTest extends GraalKernelTester { - - static final int width = 768; - static final int height = width; - private int iterations = 100; - static final int range = width * height; - @Result public float[] inArray = new float[range]; - - public static int foo(int gid, int i) { - if (gid < 25) { - return gid * i; - } else { - return gid - i; - } - } - - public void run(float[] inArray1, int gid) { - for (int i = 0; i < iterations; i++) { - inArray1[gid] = foo(gid, i); - } - } - - @Override - public void runTest() { - dispatchMethodKernel(range, inArray); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseAndCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseAndCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two chars and casts result to a char. - */ -public class CharBitwiseAndCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected char[] outArray1 = new char[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(char[] out1, char[] ina, char[] inb, int gid) { - out1[gid] = (char) (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(char[] in, char[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (char) (i + 65); - in2[i] = (char) (i + 97); - outArray1[i] = (char) 0; - } - } - - @Override - public void runTest() { - char[] inArray = new char[num]; - char[] inArray2 = new char[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseAndTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseAndTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two chars. - */ -public class CharBitwiseAndTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, char[] ina, char[] inb, int gid) { - out1[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(char[] in, char[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (char) (i + 65); - in2[i] = (char) (i + 97); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - char[] inArray = new char[num]; - char[] inArray2 = new char[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseOrCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseOrCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two chars and casts the result to a char. - */ -public class CharBitwiseOrCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected char[] outArray1 = new char[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(char[] out1, char[] ina, char[] inb, int gid) { - out1[gid] = (char) (ina[gid] | inb[gid]); - - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(char[] in, char[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (char) (i + 65); - in2[i] = (char) (i + 97); - outArray1[i] = (char) 0; - } - } - - @Override - public void runTest() { - char[] inArray = new char[num]; - char[] inArray2 = new char[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseOrTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseOrTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two chars. - */ -public class CharBitwiseOrTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, char[] ina, char[] inb, int gid) { - out1[gid] = (ina[gid] | inb[gid]); - - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(char[] in, char[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (char) (i + 65); - in2[i] = (char) (i + 97); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - char[] inArray = new char[num]; - char[] inArray2 = new char[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseXorCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseXorCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two chars and casts the result to a char. - */ -public class CharBitwiseXorCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected char[] outArray1 = new char[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(char[] out1, char[] ina, char[] inb, int gid) { - out1[gid] = (char) (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(char[] in, char[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (char) (i + 65); - in2[i] = (char) (i + 97); - outArray1[i] = (char) 0; - } - } - - @Override - public void runTest() { - char[] inArray = new char[num]; - char[] inArray2 = new char[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseXorTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/CharBitwiseXorTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two chars. - */ -public class CharBitwiseXorTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, char[] ina, char[] inb, int gid) { - out1[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(char[] in, char[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (char) (i + 65); - in2[i] = (char) (i + 97); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - char[] inArray = new char[num]; - char[] inArray2 = new char[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ClassCastNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ClassCastNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * 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.hsail.test; - -import org.junit.*; - -/** - * This test deliberately causes a ClassCastException to test throwing the exception back to the - * java code. - */ -public class ClassCastNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - - static class BasePoint { - int x; - int y; - - public BasePoint(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - } - - static class MyPoint extends BasePoint { - public MyPoint(int x, int y) { - super(x, y); - } - } - - BasePoint[] inputs = new BasePoint[num]; - MyPoint[] outputs = new MyPoint[num]; - - void setupArrays() { - for (int i = 0; i < num; i++) { - inputs[i] = new MyPoint(i, i + 1); - } - inputs[2] = new BasePoint(1, 1); - } - - public void run(int gid) { - // gid 2 should always throw ClassCastException - int adjustment = 0; - int tmp = gid; - while (tmp-- >= 0) { - adjustment += tmp; - } - MyPoint mp = (MyPoint) inputs[gid]; - mp.x = mp.y + adjustment; - outputs[gid] = mp; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(num); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ClassCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ClassCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * 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.hsail.test; - -import org.junit.*; - -/** - * This test deliberately causes a ClassCastException to test throwing the exception back to the - * java code. - */ -public class ClassCastTest extends SingleExceptionTestBase { - - static final int num = 20; - - static class BasePoint { - int x; - int y; - - public BasePoint(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - } - - static class MyPoint extends BasePoint { - public MyPoint(int x, int y) { - super(x, y); - } - } - - BasePoint[] inputs = new BasePoint[num]; - MyPoint[] outputs = new MyPoint[num]; - - void setupArrays() { - for (int i = 0; i < num; i++) { - inputs[i] = new MyPoint(i, i + 1); - } - inputs[2] = new BasePoint(1, 1); - } - - public void run(int gid) { - // gid 2 should always throw ClassCastException - MyPoint mp = (MyPoint) inputs[gid]; - mp.x = mp.y + 2; - outputs[gid] = mp; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(num); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DVec3.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DVec3.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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; - -/** - * A simple 3 element Vector object used in some junit tests. - */ -public class DVec3 { - - public DVec3(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - public double x; - public double y; - public double z; - - public static DVec3 add(DVec3 a, DVec3 b) { - return new DVec3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof DVec3)) { - return false; - } - DVec3 oth = (DVec3) other; - return (oth.x == x && oth.y == y && oth.z == z); - } - - @Override - public String toString() { - return ("DVec3[" + x + ", " + y + ", " + z + "]"); - } - - @Override - public int hashCode() { - return (int) (x + y + z); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleAbsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleAbsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for calls to Math.abs(double). Generates a abs_f64 instruction. - */ -public class DoubleAbsTest extends GraalKernelTester { - - static final int num = 40; - // Output array storing the results of calling Math.abs(). - @Result protected double[] outArray = new double[num]; - - /** - * The static "kernel" method we will be testing. This method calls Math.abs() 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] = Math.abs(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++) { - // Include positive and negative values as well as corner cases. - if (i == 1) { - in[i] = Double.NaN; - } else if (i == 2) { - in[i] = Double.NEGATIVE_INFINITY; - } else if (i == 3) { - in[i] = Double.POSITIVE_INFINITY; - } else if (i == 4) { - in[i] = -0.0; - } else { - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleCeilTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleCeilTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for calls to Math.ceil(). Generates a ceil_f64 instruction. - */ -public class DoubleCeilTest extends GraalKernelTester { - - static final int num = 40; - // Output array storing the results. - @Result protected double[] outArray = new double[num]; - - /** - * The static "kernel" method we will be testing. This method calls Math.ceil() 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] = Math.ceil(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) { - // Initialize arrays with a mix of positive and negativ values and any corner cases. - for (int i = 0; i < num; i++) { - if (i == 0) { - in[i] = 0.0; - } else if (i == 1) { - in[i] = -0.0; - } else if (i == 2) { - in[i] = Double.NaN; - } else if (i == 3) { - in[i] = Double.NEGATIVE_INFINITY; - } else if (i == 4) { - in[i] = Double.POSITIVE_INFINITY; - } else { - in[i] = i < num / 2 ? i + 0.5 : -i - 0.5; - } - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleFloorTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleFloorTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for calls to Math.floor(). Generates a floor_f64 instruction. - */ -public class DoubleFloorTest extends GraalKernelTester { - - static final int num = 40; - // Output array storing the results. - @Result protected double[] outArray = new double[num]; - - /** - * The static "kernel" method we will be testing. This method calls Math.floor() 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] = Math.floor(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) { - // Initialize input array with a mix of positive and negative values and any corner cases. - for (int i = 0; i < num; i++) { - if (i == 0) { - in[i] = 0.0; - } else if (i == 1) { - in[i] = -0.0; - } else if (i == 2) { - in[i] = Double.NaN; - } else if (i == 3) { - in[i] = Double.NEGATIVE_INFINITY; - } else if (i == 4) { - in[i] = Double.POSITIVE_INFINITY; - } else { - in[i] = i < num / 2 ? i + 0.5 : -i - 0.5; - } - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleLongConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleLongConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests double to long conversion. - */ -public class DoubleLongConvertTest extends GraalKernelTester { - - static final int size = 128; - static final double[] inputDouble = new double[size]; - static final long[] inputLong = new long[size]; - @Result static final double[] outputDouble = new double[size]; - @Result static final long[] outputLong = new long[size]; - static double[] seedDouble = new double[size]; - { - for (int i = 0; i < seedDouble.length; i++) { - seedDouble[i] = (int) Math.random(); - } - } - static long[] seedLong = new long[size]; - { - for (int i = 0; i < seedLong.length; i++) { - seedLong[i] = (long) Math.random(); - } - } - - public static void run(double[] inDouble, long[] inLong, double[] outDouble, long[] outLong, int gid) { - outDouble[gid] = inLong[gid]; - outLong[gid] = (long) inDouble[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedLong, 0, inputLong, 0, seedLong.length); - Arrays.fill(outputLong, 0); - System.arraycopy(seedDouble, 0, inputDouble, 0, seedDouble.length); - Arrays.fill(outputDouble, 0); - dispatchMethodKernel(64, inputDouble, inputLong, outputDouble, outputLong); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleNegTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleNegTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleRintTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleRintTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for Math.rint(). Generates an rint_f64 instruction. - */ -public class DoubleRintTest extends GraalKernelTester { - - static final int size = 64; - @Result double[] out = new double[size]; - - /** - * The static "kernel" method we will be testing. This method calls Math.rint() 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 in the input array. - * @param gid the parameter used to index into the input and output arrays. - */ - public static void run(double[] out, double[] in, int gid) { - out[gid] = Math.rint(in[gid]); - } - - /** - * Initialize input arrays. - * - * @param in the input array - */ - void setupArrays(double[] in) { - // Initialize input array with a mix of positive and negative values and corner cases. - for (int i = 0; i < size; i++) { - if (i == 1) { - in[i] = Double.NaN; - } else if (i == 2) { - in[i] = Double.NEGATIVE_INFINITY; - } else if (i == 3) { - in[i] = Double.POSITIVE_INFINITY; - - } else if (i == 4) { - in[i] = 0.0; - } else if (i == 5) { - in[i] = -0.0; - } else { - in[i] = i < size / 2 ? i + 0.5 : -i - 0.6; - } - out[i] = 0; - } - } - - /** - * Dispatches the HSAIL kernel for this test case. - */ - @Override - public void runTest() { - double[] inArray = new double[size]; - setupArrays(inArray); - dispatchMethodKernel(size, out, inArray); - } - - /** - * 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() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleSqrtTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/DoubleSqrtTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for call to Math.sqrt(double). Generates a sqrt_f64 instruction. - */ -public class DoubleSqrtTest extends GraalKernelTester { - - static final int size = 64; - @Result double[] out = new double[size]; - - /** - * The static "kernel" method we will be testing. This method calls Math.sqrt() 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 in the input array. - * @param gid the parameter used to index into the input and output arrays. - */ - public static void run(double[] in, double[] out, int gid) { - out[gid] = Math.sqrt(in[gid]); - } - - /** - * 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 < size; i++) { - // Include positive and negative values as well as corner cases. - if (i == 1) { - in[i] = Double.NaN; - } else if (i == 2) { - in[i] = Double.NEGATIVE_INFINITY; - } else if (i == 3) { - in[i] = Double.POSITIVE_INFINITY; - } else if (i == 4) { - in[i] = -0.0; - } else if (i > 5 && i < 10) { - in[i] = i + 0.5; - } else { - in[i] = i < size / 2 ? i : -i; - } - out[i] = 0; - } - } - - /** - * Dispatches the HSAIL kernel for this test case. - */ - @Override - public void runTest() { - double[] inArray = new double[size]; - setupArrays(inArray); - dispatchMethodKernel(size, inArray, out); - } - - /** - * 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() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2014, 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 com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import java.util.Arrays; - -/** - * Base Class for tests that allocate escaping objects. - */ - -public class EscapingNewBase extends GraalKernelTester { - - final int num = getRange(); - - int getRange() { - return 24; - } - - @Result public Object[] outArray = new Object[num]; - public Object[] savedOutArray; - @Result public boolean savedOutArrayMatch1; - @Result public boolean savedOutArrayMatch2; - @Result public boolean savedOutArrayMatch3; - - void setupArrays() { - for (int i = 0; i < num; i++) { - outArray[i] = null; - } - } - - int getDispatches() { - return 1; - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canHandleObjectAllocation(); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(num); - // use System.gc() to ensure new objects are in form that gc likes - System.gc(); - savedOutArray = Arrays.copyOf(outArray, num); - savedOutArrayMatch1 = Arrays.equals(outArray, savedOutArray); - if (getDispatches() > 1) { - // redispatch kernel without gc - dispatchMethodKernel(num); - savedOutArrayMatch2 = Arrays.equals(outArray, savedOutArray); - // and one more time with gc - dispatchMethodKernel(num); - savedOutArrayMatch3 = Arrays.equals(outArray, savedOutArray); - System.gc(); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewFloatStringTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewFloatStringTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014, 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.*; - -/** - * Tests creating a new String from a float. - */ - -public class EscapingNewFloatStringTest extends EscapingNewBase { - - @Result public String[] myOutArray = new String[num]; - - public void run(int gid) { - outArray[gid] = Float.toString(gid * 1.11f); - myOutArray[gid] = Float.toString(gid * 2.22f); - } - - @Ignore("problems runs out of memory space while inlining") - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewFloatTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewFloatTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -public class EscapingNewFloatTest extends EscapingNewBase { - @Result Float[] myOutArray = new Float[num]; - - public void run(int gid) { - outArray[gid] = (gid + 1) * 1.11f; - myOutArray[gid] = (gid + 1) * 2.22f; - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewIntArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewIntArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of an integer array per workitem. - */ - -public class EscapingNewIntArrayTest extends EscapingNewBase { - - public void run(int gid) { - int size = gid + 1; - int[] ary = new int[size]; - for (int i = 0; i < ary.length; i++) { - ary[i] = i * 3; - } - outArray[gid] = ary; - } - - private static final boolean DEBUG = Boolean.getBoolean("hsail.debug"); - - @Override - public void runTest() { - super.runTest(); - if (DEBUG) { - for (int i = 0; i < num; i++) { - int[] ary = (int[]) outArray[i]; - System.out.print("ary len " + ary.length + ": "); - for (int val : ary) { - System.out.print(val + ","); - } - System.out.println(); - } - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewIntegerTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewIntegerTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a java.lang.Integer per workitem. - */ - -public class EscapingNewIntegerTest extends EscapingNewBase { - @Result Integer[] myOutArray = new Integer[num]; - - public void run(int gid) { - outArray[gid] = (gid + 1) * 111; - myOutArray[gid] = (gid + 1) * 222; - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStoreFieldTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStoreFieldTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2014, 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 com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests allocation of a Vec3 object stored in a field by workitem #1. - */ - -public class EscapingNewStoreFieldTest extends GraalKernelTester { - - static final int NUM = 20; - public float[] inArray = new float[NUM]; - @Result public Vec3 outField; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - } - } - - public void run(int gid) { - if (gid == 1) { - float inval = inArray[gid]; - outField = new Vec3(inval + 1, inval + 2, inval + 3); - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - - // see what happens if we do it again - dispatchMethodKernel(NUM); - System.gc(); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canHandleObjectAllocation(); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringConcatTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringConcatTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2014, 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 static com.oracle.graal.debug.Debug.*; - -import org.junit.*; - -import com.oracle.graal.debug.*; - -/** - * Tests allocation of a new String based on string concatenation. - */ - -public class EscapingNewStringConcatTest extends EscapingNewBase { - - @Result public String[] myOutArray = new String[num]; - public String[] inArray = new String[num]; - - @Override - void setupArrays() { - super.setupArrays(); - for (int i = 0; i < num; i++) { - inArray[i] = Integer.toString(i + 100); - } - } - - public void run(int gid) { - outArray[gid] = inArray[gid] + inArray[(gid + num / 2) % num]; - myOutArray[gid] = inArray[(gid + num / 2) % num] + inArray[gid]; - } - - @Ignore("emitDirectCall unimplemented") - @Test - public void test() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsail(); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringInternTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringInternTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014, 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 static com.oracle.graal.debug.Debug.*; - -import org.junit.Test; - -import com.oracle.graal.debug.*; - -/** - * Tests allocation of a new String based on string interning. - */ - -public class EscapingNewStringInternTest extends EscapingNewBase { - - public void run(int gid) { - outArray[gid] = Integer.toString(gid * 111).intern(); - } - - // at node: 12|Invoke#Direct#intern - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void test() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsail(); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringLargeRangeTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringLargeRangeTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new String from integer with a large range of workitems. - */ - -public class EscapingNewStringLargeRangeTest extends EscapingNewStringTest { - - @Override - int getRange() { - return 125000; - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewStringTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new String from an integer per workitem. - */ - -public class EscapingNewStringTest extends EscapingNewBase { - - @Result public String[] myOutArray = new String[num]; - - public void run(int gid) { - outArray[gid] = Integer.toString(gid * 111); - myOutArray[gid] = Integer.toString(gid * 222); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3ArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3ArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of an array of Vec3 objects per workitem. - */ - -public class EscapingNewVec3ArrayTest extends EscapingNewBase { - - public void run(int gid) { - int size = gid + 1; - Vec3[] vec3ary = new Vec3[size]; - for (int i = 0; i < vec3ary.length; i++) { - vec3ary[i] = new Vec3(size + i + 1.1f, size + i + 2.2f, size + i + 3.3f); - } - outArray[gid] = vec3ary; - } - - private static final boolean DEBUG = Boolean.getBoolean("hsail.debug"); - - @Override - public void runTest() { - super.runTest(); - if (DEBUG) { - System.out.println("dumping results"); - for (int i = 0; i < num; i++) { - Vec3[] ary = (Vec3[]) outArray[i]; - System.out.print("ary len " + ary.length + ": "); - for (Vec3 val : ary) { - System.out.print(val + ", "); - } - System.out.println(); - } - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3Base.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3Base.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Base class for Vec3 object allocation tests. - */ - -public class EscapingNewVec3Base extends EscapingNewBase { - - float[] inArray = new float[num]; - @Result Vec3[] myOutArray = new Vec3[num]; - - @Override - void setupArrays() { - super.setupArrays(); - for (int i = 0; i < num; i++) { - inArray[i] = i; - myOutArray[i] = null; - } - } - - public void run(int gid) { - float inval = inArray[gid]; - // allocate and store in Object array - outArray[gid] = new Vec3(inval + 1.1f, inval + 2.1f, inval + 3.1f); - // allocate and store in Vec3 array - myOutArray[gid] = new Vec3(inval + 4.1f, inval + 5.1f, inval + 6.1f); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3LargeRangeDisp3Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3LargeRangeDisp3Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new Vec3 object with a large range of workitems with 3 dispatches. - */ - -public class EscapingNewVec3LargeRangeDisp3Test extends EscapingNewVec3Test { - - @Override - int getRange() { - return 250000; - } - - @Override - int getDispatches() { - return 3; - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3LargeRangeTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3LargeRangeTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new Vec3 object with a large range of workitems. - */ - -public class EscapingNewVec3LargeRangeTest extends EscapingNewVec3Test { - - @Override - int getRange() { - return 250000; - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3MediumRangeTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3MediumRangeTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new Vec3 object with a medium range of workitems. - */ - -public class EscapingNewVec3MediumRangeTest extends EscapingNewVec3Test { - - @Override - int getRange() { - return 100000; - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3Partial2Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3Partial2Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new Vec3 object but skipping one workitem. - */ - -public class EscapingNewVec3Partial2Test extends EscapingNewVec3Base { - - int testGid = num / 2; - - @Override - public void run(int gid) { - float inval = inArray[gid]; - if (gid != testGid) { - outArray[gid] = new Vec3(inval + 1.1f, inval + 2.1f, inval + 3.1f); - myOutArray[gid] = new Vec3(inval + 4.1f, inval + 5.1f, inval + 6.1f); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3PartialTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3PartialTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new Vec3 object but only for half of the workitems. - */ - -public class EscapingNewVec3PartialTest extends EscapingNewVec3Base { - - @Override - public void run(int gid) { - float inval = inArray[gid]; - outArray[gid] = (gid % 2 == 0 ? new Vec3(inval + 1.1f, inval + 2.1f, inval + 3.1f) : null); - myOutArray[gid] = (gid % 2 != 0 ? new Vec3(inval + 4.1f, inval + 5.1f, inval + 6.1f) : null); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/EscapingNewVec3Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2014, 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; - -/** - * Tests allocation of a new Vec3 object per workitem. - */ - -public class EscapingNewVec3Test extends EscapingNewVec3Base { - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FcompUnorderedTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FcompUnorderedTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * This was a version of Mandel Test that happened to generate a Nan and so was useful for testing - * ordered and unordered comparison. However, we should probably replace this with a test (or set of - * tests) that is more focussed on Nan and comparisons. - */ -public class FcompUnorderedTest extends GraalKernelTester { - - static final int initialWidth = 5; - static final int initialHeight = initialWidth; - static final int range = 25; - @Result private int[] rgb = new int[range]; - private float[] lxresult = new float[range]; - - public static void run(int[] rgb, float xoffset, float yoffset, float scale, int gid) { - final int width = initialWidth; - final int height = initialHeight; - final int maxIterations = 64; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; - int count = 0; - float zx = lx; - float zy = ly; - float newzx = 0f; - /** - * Iterate until the algorithm converges or until maxIterations are reached. - */ - while (count < maxIterations && zx < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - rgb[gid] = count; - } - - void setupPalette(int[] in) { - for (int i = 0; i < in.length; i++) { - in[i] = i; - } - } - - @Override - public void runTest() { - int[] palette = new int[256]; - setupPalette(palette); - for (int i = 0; i < range; i++) { - lxresult[i] = -1; - } - /* - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - */ - dispatchMethodKernel(range, rgb, 1.0f, 1.0f, 1.0f); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Float2DMatrixBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Float2DMatrixBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Base class used by other Float2DMatrix tests. - */ -public abstract class Float2DMatrixBase extends GraalKernelTester { - - float[][] matrixA; - float[][] matrixB; - @Result float[][] outMatrix; - - public void setupArrays(int range) { - matrixA = new float[range][]; - matrixB = new float[range][]; - outMatrix = new float[range][]; - for (int j = 0; j < range; j++) { - matrixA[j] = new float[range]; - matrixB[j] = new float[range]; - outMatrix[j] = new float[range]; - for (int k = 0; k < range; k++) { - matrixA[j][k] = (j + k) % 7; - matrixB[j][k] = (j + k + 1) % 8; - } - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Float2DMatrixMultiplyRangeFinalTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Float2DMatrixMultiplyRangeFinalTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * 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.*; - -/** - * Tests the mixing of 32-bit and 64-bit spills caused by loop unrolling. - */ -public class Float2DMatrixMultiplyRangeFinalTest extends Float2DMatrixBase { - - static final int range = 6; - - public void run(int gid) { - for (int j = 0; j < range; j++) { - float sum = 0; - for (int k = 0; k < range; k++) { - sum += (matrixA[gid][k] * matrixB[k][j]); - } - outMatrix[gid][j] = sum; - } - } - - @Override - public void runTest() { - setupArrays(range); - dispatchMethodKernel(range); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Float2DMatrixMultiplyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Float2DMatrixMultiplyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * 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.*; - -/** - * Tests 2D array access for Matrix Multiplication. - */ -public class Float2DMatrixMultiplyTest extends Float2DMatrixBase { - - int range = 20; - - public void run(int gid) { - for (int j = 0; j < range; j++) { - float sum = 0; - for (int k = 0; k < range; k++) { - sum += (matrixA[gid][k] * matrixB[k][j]); - } - outMatrix[gid][j] = sum; - } - } - - @Override - public void runTest() { - setupArrays(range); - dispatchMethodKernel(range); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatAbsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatAbsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for calls to Math.abs(float). Generates an abs_f32 instruction. - */ -public class FloatAbsTest extends GraalKernelTester { - - static final int num = 40; - // Output array storing the results of calling Math.abs(). - @Result protected float[] outArray = new float[num]; - - /** - * The static "kernel" method we will be testing. This method calls Math.abs() 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] = Math.abs(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++) { - // Initialize array with positive and negative values as well as corner cases. - if (i == 1) { - in[i] = Float.NaN; - } else if (i == 2) { - in[i] = Float.NEGATIVE_INFINITY; - } else if (i == 3) { - in[i] = Float.POSITIVE_INFINITY; - } else if (i == 4) { - in[i] = -0; - } else { - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests floating point comparison. - */ -public class FloatConvertTest extends GraalKernelTester { - - static final int size = 128; - static final float[] inputFloat = new float[size]; - static final double[] inputDouble = new double[size]; - @Result static final float[] outputFloat = new float[size]; - @Result static final double[] outputDouble = new double[size]; - static float[] seedFloat = new float[size]; - { - for (int i = 0; i < seedFloat.length; i++) { - seedFloat[i] = (float) Math.random(); - } - } - static double[] seedDouble = new double[size]; - { - for (int i = 0; i < seedDouble.length; i++) { - seedDouble[i] = Math.random(); - } - } - - public static void run(float[] inFloat, double[] inDouble, float[] outFloat, double[] outDouble, int gid) { - outFloat[gid] = (float) inDouble[gid]; - outDouble[gid] = inFloat[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedDouble, 0, inputDouble, 0, seedDouble.length); - Arrays.fill(outputDouble, 0f); - System.arraycopy(seedFloat, 0, inputFloat, 0, seedFloat.length); - Arrays.fill(outputFloat, 0f); - dispatchMethodKernel(64, inputFloat, inputDouble, outputFloat, outputDouble); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDivPrecisionTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDivPrecisionTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * This test (originally derived from a discrepancy seen in Mandel) showed a difference in the - * division answers when run on Bonaire hardware (compared to Java). - */ -public class FloatDivPrecisionTest extends GraalKernelTester { - - static final int width = 768; - static final int height = width; - static final int range = width * height; - @Result private float[] floatResult = new float[range]; - - public static void run(float[] floatOut, int gid) { - floatOut[gid] = gid / (float) width; - } - - @Override - public void runTest() { - dispatchMethodKernel(range, floatResult); - - } - - @Override - protected double equalFloatsOrDoublesDelta() { - return 0.0D; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDoubleConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatDoubleConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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 java.util.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests float to double conversion. - */ -public class FloatDoubleConvertTest extends GraalKernelTester { - - static final int size = 128; - static final float[] inputFloat = new float[size]; - static final double[] inputDouble = new double[size]; - @Result static final float[] outputFloat = new float[size]; - @Result static final double[] outputDouble = new double[size]; - static float[] seedFloat = new float[size]; - { - for (int i = 0; i < seedFloat.length; i++) { - seedFloat[i] = (float) Math.random(); - } - } - static double[] seedDouble = new double[size]; - { - for (int i = 0; i < seedDouble.length; i++) { - seedDouble[i] = Math.random(); - } - } - - public static void run(float[] inFloat, double[] inDouble, float[] outFloat, double[] outDouble, int gid) { - outFloat[gid] = (float) inDouble[gid]; - outDouble[gid] = inFloat[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedDouble, 0, inputDouble, 0, seedDouble.length); - Arrays.fill(outputDouble, 0); - System.arraycopy(seedFloat, 0, inputFloat, 0, seedFloat.length); - Arrays.fill(outputFloat, 0); - dispatchMethodKernel(64, inputFloat, inputDouble, outputFloat, outputDouble); - } - - public void test() { - super.testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatLongConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatLongConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests float to long conversion. - */ -public class FloatLongConvertTest extends GraalKernelTester { - - static final int size = 128; - static final float[] inputFloat = new float[size]; - static final long[] inputLong = new long[size]; - @Result static final float[] outputFloat = new float[size]; - @Result static final long[] outputLong = new long[size]; - static float[] seedFloat = new float[size]; - { - for (int i = 0; i < seedFloat.length; i++) { - seedFloat[i] = (float) Math.random(); - } - } - static long[] seedLong = new long[size]; - { - for (int i = 0; i < seedLong.length; i++) { - seedLong[i] = (long) Math.random(); - } - } - - public static void run(float[] inFloat, long[] inLong, float[] outFloat, long[] outLong, int gid) { - outFloat[gid] = inLong[gid]; - outLong[gid] = (long) inFloat[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedLong, 0, inputLong, 0, seedLong.length); - Arrays.fill(outputLong, 0); - System.arraycopy(seedFloat, 0, inputFloat, 0, seedFloat.length); - Arrays.fill(outputFloat, 0); - dispatchMethodKernel(64, inputFloat, inputLong, outputFloat, outputLong); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatNegTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatNegTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/FloatSqrtTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests floating point square root. - */ -public class FloatSqrtTest extends GraalKernelTester { - - static final int size = 64; - float[] input = new float[size]; - @Result float[] output = new float[size]; - { - for (int i = 0; i < size; i++) { - input[i] = i; - output[i] = -1.0f; - } - - } - - public static void run(float[] input1, float[] output1, int gid) { - output1[gid] = (float) Math.sqrt(input1[gid]); - } - - @Override - public void runTest() { - dispatchMethodKernel(size, input, output); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/InstanceOfTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/InstanceOfTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * 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.hsail.test; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests instanceof operator. Requires correct support for decompression of klass ptrs. - */ -public class InstanceOfTest extends GraalKernelTester { - - static final int NUM = 20; - - abstract static class Shape { - - public abstract float getArea(); - } - - static class Circle extends Shape { - - private float radius; - - Circle(float r) { - radius = r; - } - - @Override - public float getArea() { - return (float) (Math.PI * radius * radius); - } - } - - static class Square extends Shape { - - private float len; - - Square(float len) { - this.len = len; - } - - @Override - public float getArea() { - return len * len; - } - } - - @Result public float[] outArray = new float[NUM]; - public Shape[] inShapeArray = new Shape[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - if (i % 2 == 0) { - inShapeArray[i] = new Circle(i + 1); - } else { - inShapeArray[i] = new Square(i + 1); - } - outArray[i] = -i; - } - } - - public void run(int gid) { - outArray[gid] = (inShapeArray[gid] instanceof Circle ? 1.0f : 2.0f); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/InstanceOfTwoLevelTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/InstanceOfTwoLevelTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -public class InstanceOfTwoLevelTest extends GraalKernelTester { - - static final int NUM = 20; - - abstract static class Shape { - public abstract float getArea(); - } - - static class Ellipse extends Shape { - private float major; - private float minor; - - Ellipse(float major, float minor) { - this.major = major; - this.minor = minor; - } - - public float getEccentricity() { - float a = major / 2; - float b = minor / 2; - return (float) Math.sqrt(1 - (b / a) * (b / a)); - } - - @Override - public float getArea() { - float a = major / 2; - float b = minor / 2; - return (float) (Math.PI * a * b); - } - } - - static class Circle extends Ellipse { - Circle(float r) { - super(2 * r, 2 * r); - } - } - - static class Square extends Shape { - private float len; - - Square(float len) { - this.len = len; - } - - @Override - public float getArea() { - return len * len; - } - } - - @Result public float[] outArray = new float[NUM]; - public Object[] inShapeArray = new Object[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - switch (i % 4) { - case 0: - inShapeArray[i] = new Circle(i + 1); - break; - case 1: - inShapeArray[i] = new Square(i + 1); - break; - case 2: - inShapeArray[i] = new Ellipse(i + 1, i + 2); - break; - case 3: - inShapeArray[i] = new Object(); - break; - } - outArray[i] = -i; - } - } - - public void run(int gid) { - outArray[gid] = (inShapeArray[gid] instanceof Shape ? 1.0f : 2.0f); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAbsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAbsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for call to Math.abs(int). Generates an abs_s32 instruction. - */ -public class IntAbsTest 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 calls Math.abs( ) 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] = Math.abs(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) { - // initialize input array with a mix of positive and negative values and any corner cases. - for (int i = 0; i < num; i++) { - if (i == 1) { - in[i] = Integer.MIN_VALUE; - } else { - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAddIndexTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAddIndexTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.*; - -/** - * Tests array element addition. - */ -public class IntAddIndexTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - int outIdx = gid + ina[0] - 1; - out[outIdx] = ina[gid] + inb[gid]; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAddTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntAddTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.*; - -/** - * Tests integer addition. - */ -public class IntAddTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = ina[gid] + inb[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseAndTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseAndTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two ints. - */ -public class IntBitwiseAndTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(int[] in, int[] in2) { - for (int i = 0; i < num; i++) { - in[i] = i + i; - in2[i] = i * i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - int[] inArray = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseNotTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseNotTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseOrTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseOrTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two ints. - */ -public class IntBitwiseOrTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(int[] in, int[] in2) { - for (int i = 0; i < num; i++) { - in[i] = i + 1; - in2[i] = i * i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - int[] inArray = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftLeftTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftLeftTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightUnsignedTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseShiftRightUnsignedTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseXorTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntBitwiseXorTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two ints. - */ -public class IntBitwiseXorTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(int[] in, int[] in2) { - for (int i = 0; i < num; i++) { - in[i] = i; - in2[i] = i * i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - int[] inArray = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntByteConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntByteConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests integer to byte conversion. - */ -public class IntByteConvertTest extends GraalKernelTester { - - static final int size = 128; - static final int[] inputInt = new int[size]; - static final byte[] inputByte = new byte[size]; - @Result static final int[] outputInt = new int[size]; - @Result static final byte[] outputByte = new byte[size]; - static int[] seedInt = new int[size]; - { - for (int i = 0; i < seedInt.length; i++) { - seedInt[i] = (int) Math.random(); - } - } - static byte[] seedByte = new byte[size]; - { - for (int i = 0; i < seedByte.length; i++) { - seedByte[i] = (byte) Math.random(); - } - } - - public static void run(int[] inInt, byte[] inByte, int[] outInt, byte[] outByte, int gid) { - outInt[gid] = inByte[gid]; - outByte[gid] = (byte) inInt[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedByte, 0, inputByte, 0, seedByte.length); - Arrays.fill(outputByte, (byte) 0); - System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length); - Arrays.fill(outputInt, 0); - dispatchMethodKernel(64, inputInt, inputByte, outputInt, outputByte); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntCharConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntCharConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests integer to char conversion. - */ -public class IntCharConvertTest extends GraalKernelTester { - - static final int size = 128; - static final int[] inputInt = new int[size]; - static final char[] inputChar = new char[size]; - @Result static final int[] outputInt = new int[size]; - @Result static final char[] outputChar = new char[size]; - static int[] seedInt = new int[size]; - { - for (int i = 0; i < seedInt.length; i++) { - seedInt[i] = (int) Math.random(); - } - } - static char[] seedChar = new char[size]; - { - for (int i = 0; i < seedChar.length; i++) { - seedChar[i] = (char) Math.random(); - } - } - - public static void run(int[] inInt, char[] inChar, int[] outInt, char[] outChar, int gid) { - outInt[gid] = inChar[gid]; - outChar[gid] = (char) inInt[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedChar, 0, inputChar, 0, seedChar.length); - Arrays.fill(outputChar, (char) 0); - System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length); - Arrays.fill(outputInt, 0); - dispatchMethodKernel(64, inputInt, inputChar, outputInt, outputChar); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntDivTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntDivTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.*; - -/** - * Tests integer division. - */ -public class IntDivTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param ina - * @param inb - * @param gid - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = inb[gid] / ina[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntDoubleConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntDoubleConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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 java.util.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests integer to double conversion. - */ -public class IntDoubleConvertTest extends GraalKernelTester { - - static final int size = 128; - static final int[] inputInt = new int[size]; - static final double[] inputDouble = new double[size]; - @Result static final int[] outputInt = new int[size]; - @Result static final double[] outputDouble = new double[size]; - static int[] seedInt = new int[size]; - { - for (int i = 0; i < seedInt.length; i++) { - seedInt[i] = (int) Math.random(); - } - } - static double[] seedDouble = new double[size]; - { - for (int i = 0; i < seedDouble.length; i++) { - seedDouble[i] = Math.random(); - } - } - - public static void run(int[] inInt, double[] inDouble, int[] outInt, double[] outDouble, int gid) { - outInt[gid] = (int) inDouble[gid]; - outDouble[gid] = inInt[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedDouble, 0, inputDouble, 0, seedDouble.length); - Arrays.fill(outputDouble, 0); - System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length); - Arrays.fill(outputInt, 0); - dispatchMethodKernel(64, inputInt, inputDouble, outputInt, outputDouble); - } - - public void test() { - super.testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntDoubledTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntDoubledTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests doubling an integer value. - */ -public class IntDoubledTest extends StaticMethodTwoIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param in - * @param gid - */ - public static void run(int[] out, int[] in, int gid) { - out[gid] = in[gid] + in[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntFloatConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntFloatConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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 java.util.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests integer to float conversion. - */ -public class IntFloatConvertTest extends GraalKernelTester { - - static final int size = 128; - static final int[] inputInt = new int[size]; - static final float[] inputFloat = new float[size]; - @Result static final int[] outputInt = new int[size]; - @Result static final float[] outputFloat = new float[size]; - static int[] seedInt = new int[size]; - { - for (int i = 0; i < seedInt.length; i++) { - seedInt[i] = (int) Math.random(); - } - } - static float[] seedFloat = new float[size]; - { - for (int i = 0; i < seedFloat.length; i++) { - seedFloat[i] = (float) Math.random(); - } - } - - public static void run(int[] inInt, float[] inFloat, int[] outInt, float[] outFloat, int gid) { - outInt[gid] = (int) inFloat[gid]; - outFloat[gid] = inInt[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedFloat, 0, inputFloat, 0, seedFloat.length); - Arrays.fill(outputFloat, 0); - System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length); - Arrays.fill(outputInt, 0); - dispatchMethodKernel(64, inputInt, inputFloat, outputInt, outputFloat); - } - - public void test() { - super.testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntLongConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntLongConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests integer to long conversion. - */ -public class IntLongConvertTest extends GraalKernelTester { - - static final int size = 128; - static final int[] inputInt = new int[size]; - static final long[] inputLong = new long[size]; - @Result static final int[] outputInt = new int[size]; - @Result static final long[] outputLong = new long[size]; - static int[] seedInt = new int[size]; - { - for (int i = 0; i < seedInt.length; i++) { - seedInt[i] = (int) Math.random(); - } - } - static long[] seedLong = new long[size]; - { - for (int i = 0; i < seedLong.length; i++) { - seedLong[i] = (long) Math.random(); - } - } - - public static void run(int[] inInt, long[] inLong, int[] outInt, long[] outLong, int gid) { - outInt[gid] = (int) inLong[gid]; - outLong[gid] = inInt[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedLong, 0, inputLong, 0, seedLong.length); - Arrays.fill(outputLong, 0); - System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length); - Arrays.fill(outputInt, 0); - dispatchMethodKernel(64, inputInt, inputLong, outputInt, outputLong); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntLookupSwitchTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntLookupSwitchTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests a switch statement with integer keys. This test exercises the LOOKUPSWITCH Java bytecode - * instruction. - * - * The HSAIL code generated for this example is a series of cascading compare and branch - * instructions for each case of the switch. - * - * These HSAIL instructions have the following form: - * - * - * //Check whether the key matches the key constant of the case. Store the result of the compare (0 - * or 1) in the control register c0. - * - * cmp_eq $c0 <source register>, <key constant for case statement> - * - * //Branch to the corresponding label of that case if there's a match. - * - * cbr $c0 <branch target for that case> - */ -public class IntLookupSwitchTest 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 writes to an output array based on - * switching on an element of an input array. By convention the gid is the last parameter. - * - * Note: Because the key constants used in the cases of the switch are sparsely distributed, the - * Java source compiler compiles this example into the LOOKUPSWITCH bytecode instruction. So - * this is really a test to see whether the HSAIL backend is appropriately handling the - * LOOKUPSWITCH bytecode. - * - * @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) { - switch (ina[gid]) { - case 0: - out[gid] = ina[gid]; - break; - case 1: - case 2: - break; - case 5: - out[gid] = ina[gid] * ina[gid]; - break; - case 10: - out[gid] = -ina[gid]; - break; - case 15: - out[gid] = ina[gid] - ina[gid]; - break; - case 19: - out[gid] = ina[gid] + ina[gid]; - break; - default: - out[gid] = 9; - break; - } - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntModTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntModTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.*; - -/** - * Tests modulo operation. - */ -public class IntModTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param ina - * @param inb - * @param gid - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = inb[gid] % ina[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntMulTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntMulTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.*; - -/** - * Tests array multiplication. - */ -public class IntMulTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param ina - * @param inb - * @param gid - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = ina[gid] * inb[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntNegTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntNegTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntShortConvertTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntShortConvertTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests integer to short conversion. - */ -public class IntShortConvertTest extends GraalKernelTester { - - static final int size = 128; - static final int[] inputInt = new int[size]; - static final short[] inputShort = new short[size]; - @Result static final int[] outputInt = new int[size]; - @Result static final short[] outputShort = new short[size]; - static int[] seedInt = new int[size]; - { - for (int i = 0; i < seedInt.length; i++) { - seedInt[i] = (int) Math.random(); - } - } - static short[] seedShort = new short[size]; - { - for (int i = 0; i < seedShort.length; i++) { - seedShort[i] = (short) Math.random(); - } - } - - public static void run(int[] inInt, short[] inShort, int[] outInt, short[] outShort, int gid) { - outInt[gid] = inShort[gid]; - outShort[gid] = (short) inInt[gid]; - } - - @Override - public void runTest() { - System.arraycopy(seedShort, 0, inputShort, 0, seedShort.length); - Arrays.fill(outputShort, (short) 0); - System.arraycopy(seedInt, 0, inputInt, 0, seedInt.length); - Arrays.fill(outputInt, 0); - dispatchMethodKernel(64, inputInt, inputShort, outputInt, outputShort); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSqrAddTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSqrAddTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.*; - -/** - * Tests array addition and multiplication. - */ -public class IntSqrAddTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param ina - * @param inb - * @param gid - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = (ina[gid] * ina[gid]) + inb[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSquaredGidCmpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSquaredGidCmpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * 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.*; - -/** - * Tests comparison operation and array multiplication. - */ -public class IntSquaredGidCmpTest extends StaticMethodTwoIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter - * - * @param out - * @param in - * @param gid - */ - public static void run(int[] out, int[] in, int gid) { - if (gid > 9) { - out[gid] = in[gid] * in[gid]; - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSquaredTernaryTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSquaredTernaryTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * 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.*; - -/** - * Tests conditionals, modulo arithmetic, and addition and multiplications. - */ -public class IntSquaredTernaryTest extends StaticMethodTwoIntArrays { - - /** - * The static "kernel" method we will be testing By convention the gid is the last parameter. - * - * @param out - * @param in - * @param gid - */ - public static void run(int[] out, int[] in, int gid) { - int val = in[gid] * in[gid]; - val = (val % 2 == 1 ? val + 1 : val); - out[gid] = val; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSquaredTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSquaredTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests squaring an array element. - */ -public class IntSquaredTest extends StaticMethodTwoIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param in - * @param gid - */ - public static void run(int[] out, int[] in, int gid) { - out[gid] = in[gid] * in[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullCatchNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullCatchNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -/* - * 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.hsail.test; - -import org.junit.*; - -/** - * This test tests an int stream where we deliberately cause a NPE to test throwing the exception - * back to the java code. In addition, it is set up so the bci of the exception point is not zero. - */ -public class IntStreamNullCatchNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - - static class BasePoint { - int x; - int y; - - public BasePoint(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - } - - static class MyPoint extends BasePoint { - public MyPoint(int x, int y) { - super(x, y); - } - } - - BasePoint[] inputs = new BasePoint[num]; - MyPoint[] outputs = new MyPoint[num]; - - void setupArrays() { - for (int i = 0; i < num; i++) { - inputs[i] = new MyPoint(i, i + 1); - } - inputs[10] = null; - } - - @Result public int nullSeenGid; - @Result public int nullSeenAdjustment; - - public void run(int gid) { - // gid 10 should always throw NPE - MyPoint mp = (MyPoint) inputs[gid]; - int adjustment = 0; - int tmp = gid; - while (tmp-- >= 0) { - adjustment += tmp; - } - try { - mp.x = mp.y + adjustment; - } catch (NullPointerException e) { - nullSeenGid = gid; - nullSeenAdjustment = adjustment; - } - outputs[gid] = mp; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(num); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullCheckNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullCheckNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * 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.hsail.test; - -import org.junit.*; - -/** - * This test tests an int stream where we deliberately cause a NPE to test throwing the exception - * back to the java code. In addition, it is set up so the bci of the exception point is not zero. - */ -public class IntStreamNullCheckNonZeroBciTest extends SingleExceptionTestBase { - - static final int num = 20; - - static class BasePoint { - int x; - int y; - - public BasePoint(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - } - - static class MyPoint extends BasePoint { - public MyPoint(int x, int y) { - super(x, y); - } - } - - BasePoint[] inputs = new BasePoint[num]; - MyPoint[] outputs = new MyPoint[num]; - - void setupArrays() { - for (int i = 0; i < num; i++) { - inputs[i] = new MyPoint(i, i + 1); - } - inputs[10] = null; - } - - public void run(int gid) { - // gid 10 should always throw NPE - MyPoint mp = (MyPoint) inputs[gid]; - int adjustment = 0; - int tmp = gid; - while (tmp-- >= 0) { - adjustment += tmp; - } - mp.x = mp.y + adjustment; - outputs[gid] = mp; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(num); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * 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.hsail.test; - -import org.junit.*; - -/** - * This test tests an int stream where we deliberately cause a NPE to test throwing the exception - * back to the java code. - */ -public class IntStreamNullCheckTest extends SingleExceptionTestBase { - - static final int num = 20; - - static class BasePoint { - int x; - int y; - - public BasePoint(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - } - - static class MyPoint extends BasePoint { - public MyPoint(int x, int y) { - super(x, y); - } - } - - BasePoint[] inputs = new BasePoint[num]; - MyPoint[] outputs = new MyPoint[num]; - - void setupArrays() { - for (int i = 0; i < num; i++) { - inputs[i] = new MyPoint(i, i + 1); - } - inputs[10] = null; - } - - public void run(int gid) { - // gid 10 should always throw NPE - MyPoint mp = (MyPoint) inputs[gid]; - mp.x = mp.y + 2; - outputs[gid] = mp; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(num); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullNonArrayParamCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullNonArrayParamCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * 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.*; - -/** - * Tests one of the kernel parameters being null. - */ -public class IntStreamNullNonArrayParamCheckTest extends SingleExceptionTestBase { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - static class MyObj { - public int val; - } - - public static void run(int[] out, int[] ina, MyObj adjustment, int gid) { - out[gid] = ina[gid] + adjustment.val; - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, inArray1, null); - } catch (Exception e) { - recordException(e); - } - } - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - // Fill input arrays with a mix of positive and negative values. - in1[i] = i < num / 2 ? i + 1 : -(i + 1); - in2[i] = (i & 1) == 0 ? in1[i] + 10 : -(in1[i] + 10); - outArray[i] = -i; - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullParamCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntStreamNullParamCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.*; - -/** - * Tests one of the kernel parameters being null. - */ -public class IntStreamNullParamCheckTest extends SingleExceptionTestBase { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = ina[gid] + inb[gid]; - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - try { - dispatchMethodKernel(num, outArray, null, inArray2); - } catch (Exception e) { - recordException(e); - } - } - - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - // Fill input arrays with a mix of positive and negative values. - in1[i] = i < num / 2 ? i + 1 : -(i + 1); - in2[i] = (i & 1) == 0 ? in1[i] + 10 : -(in1[i] + 10); - outArray[i] = -i; - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSubTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSubTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.*; - -/** - * Tests subtracting one array element from another. - */ -public class IntSubTest extends StaticMethodThreeIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param ina - * @param inb - * @param gid - */ - public static void run(int[] out, int[] ina, int[] inb, int gid) { - out[gid] = ina[gid] - inb[gid]; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSumArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntSumArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * 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.*; - -/** - * Tests iteratively summing the elements of an array. - */ -public class IntSumArrayTest extends StaticMethodTwoIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param in - * @param gid - */ - public static void run(int[] out, int[] in, int gid) { - int sum = 0; - for (int n : in) { - sum += n; - } - out[gid] = sum; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntTableSwitchTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntTableSwitchTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests a switch statement with integer keys. This test exercises the TABLESWITCH Java bytecode - * instruction. - * - * The HSAIL code generated for this example is a series of cascading compare and branch - * instructions for each case of the switch. - * - * These instruction have the following form: - * - * - * //Check whether the key matches the key constant of the case. Store the result of the compare (0 - * or 1) in the control register c0. - * - * cmp_eq $c0 <source register>, <key constant for case statement> - * - * //Branch to the corresponding label of that case if there's a match. - * - * cbr $c0 <branch target for that case> - */ -public class IntTableSwitchTest 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 writes to an output array based on - * switching on an element of an input array. - * - * Note: Because the key constants used in the cases of the switch are in consecutive order, the - * Java source compiler compiles this example into the TABLESWITCH bytecode instruction. So this - * is really a test to see whether the HSAIL backend is appropriately handling the TABLESWITCH - * bytecode. - * - * @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) { - switch (ina[gid]) { - case 0: - out[gid] = ina[gid]; - break; - case 1: - out[gid] = ina[gid] * ina[gid]; - break; - case 2: - out[gid] = -ina[gid]; - break; - case 3: - out[gid] = ina[gid] - ina[gid]; - break; - case 4: - out[gid] = ina[gid] + ina[gid]; - break; - case 5: - case 6: - out[gid] = ina[gid] * ina[gid]; - break; - case 7: - out[gid] = -ina[gid] * 7; - break; - case 8: - break; - case 9: - int i = ina[gid] * 5; - out[gid] = ina[gid] - ina[gid] + i; - break; - case 10: - out[gid] = ina[gid] + ina[gid]; - break; - default: - out[gid] = 9; - break; - } - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntTestBranchTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/IntTestBranchTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * 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; - -/** - * Tests code generation for IntegerTestNode for HSAIL backend. - */ -public class IntTestBranchTest extends StaticMethodTwoIntArrays { - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - * @param out - * @param in - * @param gid - */ - public static void run(int[] out, int[] in, int gid) { - if ((in[gid] & 3) != 0) { - out[gid] = in[gid] * 2; - } else { - out[gid] = in[gid] * 3; - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongAbsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongAbsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests intrinsic for call to Math.abs(long). Generates an abs_s64 instruction. - */ -public class LongAbsTest 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 calls Math.abs( ) 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] = Math.abs(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) { - // Initialize input array with a mix of positive and negative values and any corner cases. - for (int i = 0; i < num; i++) { - if (i == 1) { - in[i] = Long.MIN_VALUE; - } else { - 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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseAndTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseAndTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two longs. - */ -public class LongBitwiseAndTest extends GraalKernelTester { - - static final int num = 20; - @Result protected long[] outArray = new long[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(long[] out, long[] ina, long[] inb, int gid) { - out[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(long[] in, long[] in2) { - for (int i = 0; i < num; i++) { - in[i] = i + i; - in2[i] = i * i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - long[] inArray = new long[num]; - long[] inArray2 = new long[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseNotTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseNotTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseOrTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseOrTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two longs. - */ -public class LongBitwiseOrTest extends GraalKernelTester { - - static final int num = 20; - @Result protected long[] outArray = new long[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(long[] out, long[] ina, long[] inb, int gid) { - out[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(long[] in, long[] in2) { - for (int i = 0; i < num; i++) { - in[i] = i + 1; - in2[i] = i * i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - long[] inArray = new long[num]; - long[] inArray2 = new long[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftLeftTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftLeftTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightUnsignedTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseShiftRightUnsignedTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseXorTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongBitwiseXorTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two longs. - */ -public class LongBitwiseXorTest extends GraalKernelTester { - - static final int num = 20; - @Result protected long[] outArray = new long[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(long[] out, long[] ina, long[] inb, int gid) { - out[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(long[] in, long[] in2) { - for (int i = 0; i < num; i++) { - in[i] = i; - in2[i] = i * i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - long[] inArray = new long[num]; - long[] inArray2 = new long[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongModTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongModTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests the remainder operation (%) on two longs. Generates a rem_s64 instruction. - */ -public class LongModTest extends GraalKernelTester { - - static final int num = 20; - @Result protected long[] outArray = new long[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * This routine performs the remainder operation (%) on elements from two input arrays and - * writes the result to the corresponding index of an output array. - * - * @param out the output array - * @param ina the first input array - * @param inb the second input array - * @param gid the parameter used to index into the input and output arrays - */ - public static void run(long[] out, long[] ina, long[] inb, int gid) { - out[gid] = (ina[gid] % inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - /** - * Initialize input and output arrays. - * - * @param in first input array - * @param in2 second input array - */ - void setupArrays(long[] in, long[] in2) { - for (int i = 0; i < num; i++) { - // Fill input arrays with a mix of positive and negative values. - in[i] = i < num / 2 ? i + 1 : -(i + 1); - in2[i] = (i & 1) == 0 ? i + 10 : -(i + 10); - outArray[i] = 0; - } - } - - /** - * Dispatches the HSAIL kernel for this test case. - */ - @Override - public void runTest() { - long[] inArray = new long[num]; - long[] inArray2 = new long[num]; - setupArrays(inArray, inArray2); - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongNegTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/LongNegTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -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 c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/NestedStaticCallTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/NestedStaticCallTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests direct method calls. - */ -public class NestedStaticCallTest extends GraalKernelTester { - - static final int width = 768; - static final int height = width; - private int iterations = 100; - static final int range = width * height; - @Result public float[] outArray = new float[range]; - - public static int a(int i) { - if (i < 2) { - return b(i); - } else { - return i; - } - } - - public static int b(int i) { - if (i < 90) { - return c(i) + i; - } else { - return d(i) - i; - } - } - - public static int c(int i) { - - return d(i) + 5; - } - - public static int d(int i) { - - return e(i) + 10; - } - - public static int e(int i) { - return 52 + i; - } - - public void run(int gid) { - for (int i = 0; i < iterations; i++) { - outArray[gid] = a(gid) + i; - } - } - - @Override - public void runTest() { - dispatchMethodKernel(range); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/NestedVirtualCallTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/NestedVirtualCallTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests direct method calls. - */ -public class NestedVirtualCallTest extends GraalKernelTester { - - static final int width = 768; - static final int height = width; - private int iterations = 100; - static final int range = width * height; - @Result public float[] outArray = new float[range]; - - public int a(int i) { - if (i < 2) { - return b(i); - } else { - return i; - } - } - - public int b(int i) { - if (i < 90) { - return c(i) + i; - } else { - return d(i) - i; - } - } - - public int c(int i) { - - return d(i) + 5; - } - - public int d(int i) { - - return e(i) + 10; - } - - public int e(int i) { - return 52 + i; - } - - public void run(int gid) { - for (int i = 0; i < iterations; i++) { - outArray[gid] = a(gid) + i; - } - } - - @Override - public void runTest() { - dispatchMethodKernel(range); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * 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 java.util.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Base class for testing deopt when objects are in stack slots. - */ -public abstract class ObjSpillDeoptBase extends GraalKernelTester { - - abstract int getSize(); - - int loopcount = 5; - int objcount = 20; - @Result double[] out = new double[getSize()]; - @Result double[] aux = new double[getSize()]; - DVec3[] in = new DVec3[objcount]; - - public void doCompute(int gid, boolean causeDeopt) { - int idx = gid * 2 + 7; - DVec3 v0 = in[(idx++) % objcount]; - DVec3 v1 = in[(idx++) % objcount]; - DVec3 v2 = in[(idx++) % objcount]; - DVec3 v3 = in[(idx++) % objcount]; - DVec3 v4 = in[(idx++) % objcount]; - DVec3 v5 = in[(idx++) % objcount]; - DVec3 v6 = in[(idx++) % objcount]; - DVec3 v7 = in[(idx++) % objcount]; - DVec3 v8 = in[(idx++) % objcount]; - DVec3 v9 = in[(idx++) % objcount]; - idx += gid; - DVec3 v10 = in[(idx++) % objcount]; - DVec3 v11 = in[(idx++) % objcount]; - DVec3 v12 = in[(idx++) % objcount]; - DVec3 v13 = in[(idx++) % objcount]; - DVec3 v14 = in[(idx++) % objcount]; - DVec3 v15 = in[(idx++) % objcount]; - DVec3 v16 = in[(idx++) % objcount]; - DVec3 v17 = in[(idx++) % objcount]; - DVec3 v18 = in[(idx++) % objcount]; - DVec3 v19 = in[(idx++) % objcount]; - double sum = 0.0; - double sum1 = 0.0; - double sum2 = 0.0; - for (int i = 0; i < loopcount; i++) { - sum1 += v0.x + v1.y + v2.z + v3.x + v4.y + v5.z + v6.x + v7.y + v8.z + v9.x + i; - sum2 += v10.y + v11.z + v12.x + v13.y + v14.z + v15.x + v16.y + v17.z + v18.x + v19.y - i; - sum += sum1 - sum2 + i; - aux[gid] += sum1 + 1.2345; - } - if (causeDeopt) { - aux[gid] += forceDeopt(sum1); - } - out[gid] += sum; - } - - @Override - public void runTest() { - Arrays.fill(out, -1.0); - for (int i = 0; i < objcount; i++) { - in[i] = new DVec3(i / 10f, (i + 1) / 10f, (i + 2) / 10f); - } - dispatchMethodKernel(getSize()); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canDeoptimize(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMany20000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMany20000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, with many items deopting. - */ -public class ObjSpillDeoptMany20000Test extends ObjSpillDeoptManyBase { - - @Override - int getSize() { - return 20000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMany5000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMany5000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, with many items deopting. - */ -public class ObjSpillDeoptMany5000Test extends ObjSpillDeoptManyBase { - - @Override - int getSize() { - return 5000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMany99999Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMany99999Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, with many items deopting. - */ -public class ObjSpillDeoptMany99999Test extends ObjSpillDeoptManyBase { - - @Override - int getSize() { - return 99999; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptManyBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptManyBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/* - * 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; - -/** - * Base class for testing deopt with objects in stack slots, with many items deopting. - */ -public abstract class ObjSpillDeoptManyBase extends ObjSpillDeoptBase { - - public void run(int gid) { - boolean causeDeopt = (gid < 4096 && gid % 512 == 1); - doCompute(gid, causeDeopt); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMost20000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMost20000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, with most items deopting. - */ -public class ObjSpillDeoptMost20000Test extends ObjSpillDeoptMostBase { - - @Override - int getSize() { - return 20000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMost5000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMost5000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, with most items deopting. - */ -public class ObjSpillDeoptMost5000Test extends ObjSpillDeoptMostBase { - - @Override - int getSize() { - return 5000; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMost99999Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMost99999Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, with most items deopting. - */ -public class ObjSpillDeoptMost99999Test extends ObjSpillDeoptMostBase { - - @Override - int getSize() { - return 99999; - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMostBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptMostBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -/* - * 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; - -/** - * Base class for testing deopt with objects in stack slots. - */ -public abstract class ObjSpillDeoptMostBase extends ObjSpillDeoptBase { - - public void run(int gid) { - boolean causeDeopt = (gid % 500 != 1); - doCompute(gid, causeDeopt); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptSingle100Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptSingle100Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, one item deopting. - */ -public class ObjSpillDeoptSingle100Test extends ObjSpillDeoptBase { - - final int size = 100; - - @Override - int getSize() { - return size; - } - - public void run(int gid) { - boolean causeDeopt = (gid == size / 2); - doCompute(gid, causeDeopt); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptSingle20000Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjSpillDeoptSingle20000Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Tests deopt with objects in stack slots, one item deopting. - */ -public class ObjSpillDeoptSingle20000Test extends ObjSpillDeoptBase { - - final int size = 20000; - - @Override - int getSize() { - return size; - } - - public void run(int gid) { - boolean causeDeopt = (gid == size / 2); - doCompute(gid, causeDeopt); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjectStoreNullTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjectStoreNullTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -/* - * 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.*; - -/** - * Tests the storing of null in an Object array. - */ -public class ObjectStoreNullTest extends ObjectStoreTest { - - @Override - public void run(int gid) { - outIntegerArray[gid] = (gid % 3 == 1 ? null : inIntegerArray[gid]); - } - - @Test - @Override - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjectStoreTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ObjectStoreTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests the storing of objects into an array. - */ -public class ObjectStoreTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Integer[] outIntegerArray = new Integer[NUM]; - public Integer[] inIntegerArray = new Integer[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inIntegerArray[i] = new Integer(i); - outIntegerArray[i] = null; - } - } - - public void run(int gid) { - outIntegerArray[gid] = inIntegerArray[gid]; - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseAndCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseAndCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two shorts and casts the result to a short. - */ -public class ShortBitwiseAndCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected short[] outArray1 = new short[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(short[] out1, short[] ina, short[] inb, int gid) { - out1[gid] = (short) (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(short[] in, short[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (short) (i + i); - in2[i] = (short) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - short[] inArray = new short[num]; - short[] inArray2 = new short[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseAndTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseAndTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise AND of two shorts. - */ -public class ShortBitwiseAndTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, short[] ina, short[] inb, int gid) { - out1[gid] = (ina[gid] & inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(short[] in, short[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (short) (i + i); - in2[i] = (short) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - short[] inArray = new short[num]; - short[] inArray2 = new short[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseOrCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseOrCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two shorts and casts the result to a short. - */ -public class ShortBitwiseOrCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected short[] outArray1 = new short[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(short[] out1, short[] ina, short[] inb, int gid) { - out1[gid] = (short) (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(short[] in, short[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (short) (i + 1); - in2[i] = (short) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - short[] inArray = new short[num]; - short[] inArray2 = new short[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseOrTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseOrTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise OR of two shorts. - */ -public class ShortBitwiseOrTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, short[] ina, short[] inb, int gid) { - out1[gid] = (ina[gid] | inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(short[] in, short[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (short) (i + 1); - in2[i] = (short) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - short[] inArray = new short[num]; - short[] inArray2 = new short[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseXorCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseXorCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two shorts and casts the result to a short. - */ -public class ShortBitwiseXorCastTest extends GraalKernelTester { - - static final int num = 20; - @Result protected short[] outArray1 = new short[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(short[] out1, short[] ina, short[] inb, int gid) { - out1[gid] = (short) (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(short[] in, short[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (short) (i); - in2[i] = (short) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - short[] inArray = new short[num]; - short[] inArray2 = new short[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseXorTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/ShortBitwiseXorTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * Tests bitwise XOR of two shorts. - */ -public class ShortBitwiseXorTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray1 = new int[num]; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public static void run(int[] out1, short[] ina, short[] inb, int gid) { - out1[gid] = (ina[gid] ^ inb[gid]); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(short[] in, short[] in2) { - for (int i = 0; i < num; i++) { - in[i] = (short) (i); - in2[i] = (short) (i * i); - outArray1[i] = 0; - } - } - - @Override - public void runTest() { - short[] inArray = new short[num]; - short[] inArray2 = new short[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray1, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/SingleExceptionTestBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/SingleExceptionTestBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * - * @author ecaspole - */ -public abstract class SingleExceptionTestBase extends GraalKernelTester { - - @Result Class exceptionClass; - @Result String exceptionString; - @Result StackTraceElement firstStackTraceElement; - - @Override - protected boolean supportsRequiredCapabilities() { - return canDeoptimize(); - } - - void recordException(Exception e) { - // for now we just test that the class the of the exception - // matches for the java and gpu side - exceptionClass = e.getClass(); - // exception = e; - StackTraceElement[] elems = e.getStackTrace(); - firstStackTraceElement = elems[0]; - // for tests where the exception was in the method parameters - // ignore the firstStackTraceElement matching - if (firstStackTraceElement.getClassName().contains("KernelTester")) { - firstStackTraceElement = null; - } - for (StackTraceElement elem : elems) { - if (elem.toString().contains("KernelTester")) { - break; - } - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticCallTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticCallTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests direct method calls. - */ -public class StaticCallTest extends GraalKernelTester { - - static final int width = 768; - static final int height = width; - private int iterations = 100; - static final int range = width * height; - @Result public float[] outArray = new float[range]; - - public static int foo(int gid, int i) { - if (gid < 2) { - return bar(gid, i); - } else { - return gid + i; - } - } - - public static int bar(int gid, int i) { - if (gid < 90) { - return gid + i; - } else { - return gid - i; - } - } - - public void run(int gid) { - for (int i = 0; i < iterations; i++) { - outArray[gid] = bar(gid, i); - } - } - - @Override - public void runTest() { - dispatchMethodKernel(range); - } - - @Test - public void test() { - super.testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticDoubleSpillBoundsCatchOneTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticDoubleSpillBoundsCatchOneTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests the spilling of double variables into memory with deopt. - */ -public class StaticDoubleSpillBoundsCatchOneTest extends GraalKernelTester { - - static final int size = 100; - private double[] in = new double[size * 400]; - @Result public double[] out = new double[size * 400]; - @Result public double[] aux = new double[2]; - - public static void run(double[] out, double[] in, double[] aux, int gid) { - int id = gid; - int step = 20; - double sum0; - double sum1; - double sum2; - double sum3; - double sum4; - double sum5; - double sum6; - double sum7; - double sum8; - double sum9; - double sum10; - double sum11; - double sum12; - double sum13; - double sum14; - double sum15; - double sum16; - double sum17; - double sum18; - double sum19; - sum0 = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = sum7 = sum8 = sum9 = 0; - sum10 = sum11 = sum12 = sum13 = sum14 = sum15 = sum16 = sum17 = sum18 = sum19 = 0; - try { - for (int i = 0; i < size; i += step) { - sum0 += in[i + 0]; - sum1 += in[i + 1]; - sum2 += in[i + 2]; - sum3 += in[i + 3]; - sum4 += in[i + 4]; - sum5 += in[i + 5]; - sum6 += in[i + 6]; - sum7 += in[i + 7]; - sum8 += in[i + 8]; - sum9 += in[i + 9]; - sum10 += in[i + 0]; - sum11 += in[i + 1]; - sum12 += in[i + 2]; - sum13 += in[i + 3]; - sum14 += in[i + 4]; - sum15 += in[i + 5]; - sum16 += in[i + 6]; - sum17 += in[i + 7]; - sum18 += in[i + 8]; - sum19 += in[i + 9]; - - if (id == size / 2) { - aux[id] = sum1 + sum2 + sum3 + sum4 + sum5 + sum6 + sum7 + sum8 + sum9 + sum10 + sum11 + sum12 + sum13 + sum14 + sum15 + sum16; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - aux[0] += sum1 + sum2; - } - - out[id * step + 0] = sum0; - out[id * step + 1] = sum1; - out[id * step + 2] = sum2; - out[id * step + 3] = sum3; - out[id * step + 4] = sum4; - out[id * step + 5] = sum5; - out[id * step + 6] = sum6; - out[id * step + 7] = sum7; - out[id * step + 8] = sum8; - out[id * step + 9] = sum9; - out[id * step + 10] = sum10; - out[id * step + 11] = sum11; - out[id * step + 12] = sum12; - out[id * step + 13] = sum13; - out[id * step + 14] = sum14; - out[id * step + 15] = sum15; - out[id * step + 16] = sum16; - out[id * step + 17] = sum17; - out[id * step + 18] = sum18; - out[id * step + 19] = sum19; - } - - @Override - public void runTest() { - /** - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - * - */ - Arrays.fill(out, -1f); - for (int i = 0; i < size; i++) { - in[i] = i + 1; - } - dispatchMethodKernel(size, out, in, aux); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canDeoptimize(); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticDoubleSpillBoundsCatchTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticDoubleSpillBoundsCatchTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests the spilling of double variables into memory with deopt. - */ -public class StaticDoubleSpillBoundsCatchTest extends GraalKernelTester { - - static final int size = 100; - private double[] in = new double[size * 400]; - @Result public double[] out = new double[size * 400]; - @Result public double[] aux = new double[size]; - - public static void run(double[] out, double[] in, double[] aux, int gid) { - int id = gid; - int step = 20; - double sum0; - double sum1; - double sum2; - double sum3; - double sum4; - double sum5; - double sum6; - double sum7; - double sum8; - double sum9; - double sum10; - double sum11; - double sum12; - double sum13; - double sum14; - double sum15; - double sum16; - double sum17; - double sum18; - double sum19; - sum0 = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = sum7 = sum8 = sum9 = 0; - sum10 = sum11 = sum12 = sum13 = sum14 = sum15 = sum16 = sum17 = sum18 = sum19 = 0; - try { - for (int i = 0; i < size; i += step) { - sum0 += in[i + 0]; - sum1 += in[i + 1]; - sum2 += in[i + 2]; - sum3 += in[i + 3]; - sum4 += in[i + 4]; - sum5 += in[i + 5]; - sum6 += in[i + 6]; - sum7 += in[i + 7]; - sum8 += in[i + 8]; - sum9 += in[i + 9]; - sum10 += in[i + 0]; - sum11 += in[i + 1]; - sum12 += in[i + 2]; - sum13 += in[i + 3]; - sum14 += in[i + 4]; - sum15 += in[i + 5]; - sum16 += in[i + 6]; - sum17 += in[i + 7]; - sum18 += in[i + 8]; - sum19 += in[i + 9]; - - if (id > size / 2) { - aux[id + 10] += sum1 + sum2; - // + sum3 + sum4 + sum5 + sum6 + sum7 + sum8 + sum9 + sum10 + sum11 + sum12 + - // sum13 + sum14 + sum15 + sum16; - } - } - } catch (ArrayIndexOutOfBoundsException e) { - aux[id] += sum1 + sum2; - } - - out[id * step + 0] = sum0; - out[id * step + 1] = sum1; - out[id * step + 2] = sum2; - out[id * step + 3] = sum3; - out[id * step + 4] = sum4; - out[id * step + 5] = sum5; - out[id * step + 6] = sum6; - out[id * step + 7] = sum7; - out[id * step + 8] = sum8; - out[id * step + 9] = sum9; - out[id * step + 10] = sum10; - out[id * step + 11] = sum11; - out[id * step + 12] = sum12; - out[id * step + 13] = sum13; - out[id * step + 14] = sum14; - out[id * step + 15] = sum15; - out[id * step + 16] = sum16; - out[id * step + 17] = sum17; - out[id * step + 18] = sum18; - out[id * step + 19] = sum19; - } - - @Override - public void runTest() { - /** - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - * - */ - Arrays.fill(out, -1f); - Arrays.fill(aux, 0f); - for (int i = 0; i < size; i++) { - in[i] = i + 1; - } - dispatchMethodKernel(size, out, in, aux); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canDeoptimize(); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticDoubleSpillTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticDoubleSpillTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests the spilling of double variables into memory. - */ -public class StaticDoubleSpillTest extends GraalKernelTester { - - static final int size = 100; - private double[] in = new double[size * 400]; - @Result private double[] out = new double[size * 400]; - - public static void run(double[] out, double[] in, int gid) { - int id = gid; - int step = 20; - double sum0; - double sum1; - double sum2; - double sum3; - double sum4; - double sum5; - double sum6; - double sum7; - double sum8; - double sum9; - double sum10; - double sum11; - double sum12; - double sum13; - double sum14; - double sum15; - double sum16; - double sum17; - double sum18; - double sum19; - sum0 = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = sum7 = sum8 = sum9 = 0; - sum10 = sum11 = sum12 = sum13 = sum14 = sum15 = sum16 = sum17 = sum18 = sum19 = 0; - for (int i = 0; i < size; i += step) { - sum0 += in[i + 0]; - sum1 += in[i + 1]; - sum2 += in[i + 2]; - sum3 += in[i + 3]; - sum4 += in[i + 4]; - sum5 += in[i + 5]; - sum6 += in[i + 6]; - sum7 += in[i + 7]; - sum8 += in[i + 8]; - sum9 += in[i + 9]; - sum10 += in[i + 0]; - sum11 += in[i + 1]; - sum12 += in[i + 2]; - sum13 += in[i + 3]; - sum14 += in[i + 4]; - sum15 += in[i + 5]; - sum16 += in[i + 6]; - sum17 += in[i + 7]; - sum18 += in[i + 8]; - sum19 += in[i + 9]; - } - out[id * step + 0] = sum0; - out[id * step + 1] = sum1; - out[id * step + 2] = sum2; - out[id * step + 3] = sum3; - out[id * step + 4] = sum4; - out[id * step + 5] = sum5; - out[id * step + 6] = sum6; - out[id * step + 7] = sum7; - out[id * step + 8] = sum8; - out[id * step + 9] = sum9; - out[id * step + 10] = sum10; - out[id * step + 11] = sum11; - out[id * step + 12] = sum12; - out[id * step + 13] = sum13; - out[id * step + 14] = sum14; - out[id * step + 15] = sum15; - out[id * step + 16] = sum16; - out[id * step + 17] = sum17; - out[id * step + 18] = sum18; - out[id * step + 19] = sum19; - } - - @Override - public void runTest() { - /** - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - * - */ - Arrays.fill(out, -1f); - for (int i = 0; i < size; i++) { - in[i] = i + 1; - } - dispatchMethodKernel(size, out, in); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticIntSpillTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticIntSpillTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests the spilling of integers into memory. - */ -public class StaticIntSpillTest extends GraalKernelTester { - - static final int size = 100; - private int[] in = new int[size * 400]; - @Result private int[] out = new int[size * 400]; - - public static void run(int[] out, int[] in, int gid) { - int id = gid; - int step = 20; - int sum0; - int sum1; - int sum2; - int sum3; - int sum4; - int sum5; - int sum6; - int sum7; - int sum8; - int sum9; - sum0 = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = sum7 = sum8 = sum9 = 0; - for (int i = 0; i < size; i += step) { - sum0 += in[i + 0]; - sum1 += in[i + 1]; - sum2 += in[i + 2]; - sum3 += in[i + 3]; - sum4 += in[i + 4]; - sum5 += in[i + 5]; - sum6 += in[i + 6]; - sum7 += in[i + 7]; - sum8 += in[i + 8]; - sum9 += in[i + 9]; - } - out[id * step + 0] = sum0; - out[id * step + 1] = sum1; - out[id * step + 2] = sum2; - out[id * step + 3] = sum3; - out[id * step + 4] = sum4; - out[id * step + 5] = sum5; - out[id * step + 6] = sum6; - out[id * step + 7] = sum7; - out[id * step + 8] = sum8; - out[id * step + 9] = sum9; - } - - @Override - public void runTest() { - /** - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - * - */ - Arrays.fill(out, 0); - Arrays.fill(in, 0); - dispatchMethodKernel(size, out, in); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMandelBoundsCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMandelBoundsCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * 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.*; - -/** - * Unit test that simulates the Mandelbrot application. The run method here is a static method - * version of the original mandel kernel and the invoke parameters are for the starting point of the - * mandel demo. Note: this will likely not pass the junit test on real hardware, but should pass on - * the simulator. - */ -public class StaticMandelBoundsCheckTest extends SingleExceptionTestBase { - - static final int initWidth = 768; - static final int initHeight = initWidth; - static final int maxIterations = 64; - static final int range = initWidth * initHeight; - private int[] rgb = new int[range]; - - public static void run(int[] rgb, int[] pallette, float xoffset, float yoffset, float scale, int gid) { - final int width = initWidth; - final int height = initHeight; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; - int count = 0; - float zx = lx; - float zy = ly; - float newzx = 0f; - - // Iterate until the algorithm converges or until maxIterations are reached. - while (count < maxIterations && zx * zx + zy * zy < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - rgb[gid + 1] = pallette[count]; // will cause exception on last of range - } - - void setupPalette(int[] in) { - for (int i = 0; i < in.length; i++) { - in[i] = i; - } - } - - @Override - public void runTest() { - int[] palette = new int[256]; - setupPalette(palette); - /** - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - */ - try { - dispatchMethodKernel(range, rgb, palette, -1f, 0f, 3f); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMandelTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMandelTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * 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.*; -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Unit test that simulates the Mandelbrot application. The run method here is a static method - * version of the original mandel kernel and the invoke parameters are for the starting point of the - * mandel demo. Note: this will likely not pass the junit test on real hardware, but should pass on - * the simulator. - */ -public class StaticMandelTest extends GraalKernelTester { - - static final int initWidth = 768; - static final int initHeight = initWidth; - static final int maxIterations = 64; - static final int range = initWidth * initHeight; - @Result private int[] rgb = new int[range]; - - public static void run(int[] rgb, int[] pallette, float xoffset, float yoffset, float scale, int gid) { - final int width = initWidth; - final int height = initHeight; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xoffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yoffset; - int count = 0; - float zx = lx; - float zy = ly; - float newzx = 0f; - - // Iterate until the algorithm converges or until maxIterations are reached. - while (count < maxIterations && zx * zx + zy * zy < 8) { - newzx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newzx; - count++; - } - rgb[gid] = pallette[count]; - } - - void setupPalette(int[] in) { - for (int i = 0; i < in.length; i++) { - in[i] = i; - } - } - - @Override - public void runTest() { - int[] palette = new int[256]; - setupPalette(palette); - /** - * Call it for a range, specifying testmethod args (but not the fields it uses or the gid - * argument). - */ - dispatchMethodKernel(range, rgb, palette, -1f, 0f, 3f); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethod16InArraysTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethod16InArraysTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -/* - * 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 static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; - -import org.junit.*; - -import com.oracle.graal.debug.*; - -/** - * Tests the addition of elements from sixteen input arrays. - */ -public class StaticMethod16InArraysTest extends StaticMethodTwoIntArrays { - - @Override - void setupArrays(int[] in) { - for (int i = 0; i < num; i++) { - in[i] = i; - outArray[i] = -i; - } - } - - public static void run(int[] out, int[] ina, int[] inb, int[] inc, int[] ind, int[] ine, int[] inf, int[] ing, int[] inh, int[] ini, int[] inj, int[] ink, int[] inl, int[] inm, int[] inn, - int[] ino, int[] inp, int gid) { - out[gid] = ina[gid] + inb[gid] + inc[gid] + ind[gid] + ine[gid] + inf[gid] + ing[gid] + inh[gid] + ini[gid] + inj[gid] + ink[gid] + inl[gid] + inm[gid] + inn[gid] + ino[gid] + inp[gid]; - } - - @Override - public void runTest() { - int[] inArray = new int[num]; - setupArrays(inArray); - /** - * DumpArrayParameters(inArray); Call it for a range, specifying testmethod args (but not - * the fields it uses or the gid argument). Will put output in outArray. - */ - dispatchMethodKernel(num, outArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray, inArray); - } - - /** - * This test fails because we don't have correct logic to handle more input parameters than - * there are registers. - */ - @Test(expected = java.lang.ClassCastException.class) - @Ignore("until GPU backends can co-exist") - public void test() { - try (DebugConfigScope s = Debug.setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { - testGeneratedHsail(); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethodThreeIntArrays.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethodThreeIntArrays.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * 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; - -/** - * Superclass that initializes two input arrays containing ints and one output array. Derived by - * some of the other test cases that take two arrays of ints as input parameters. - */ -public abstract class StaticMethodThreeIntArrays extends StaticMethodTwoIntArrays { - - /** - * Initialize the input and output arrays. - * - * @param in1 the first input array - * @param in2 the second input array - */ - void setupArrays(int[] in1, int[] in2) { - for (int i = 0; i < num; i++) { - // Fill input arrays with a mix of positive and negative values. - in1[i] = i < num / 2 ? i + 1 : -(i + 1); - in2[i] = (i & 1) == 0 ? in1[i] + 10 : -(in1[i] + 10); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - int[] inArray1 = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray1, inArray2); - - /** - * DumpArrayParameters(inArray); Call it for a range, specifying testmethod args (but not - * the fields it uses or the gid argument). Will put output in outArray. - */ - dispatchMethodKernel(num, outArray, inArray1, inArray2); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethodTwoIntArrays.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticMethodTwoIntArrays.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Superclass that initializes one input array and one output array. Derived by some of the other - * test cases that take one array as input and write to an output array. - */ -public abstract class StaticMethodTwoIntArrays extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - void setupArrays(int[] in) { - for (int i = 0; i < num; i++) { - in[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - int[] inArray = new int[num]; - setupArrays(inArray); - /** - * DumpArrayParameters(inArray); Call it for a range, specifying testmethod args (but not - * the fields it uses or the gid argument). Will put output in outArray. - */ - dispatchMethodKernel(num, outArray, inArray); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyCallTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyCallTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * 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.*; - -/** - * Unit test of NBody demo app. This version uses a call to the main routine which would normally be - * too large to inline. - */ -public class StaticNBodyCallTest extends StaticNBodyTest { - - public static void run(float[] inxyz, float[] outxyz, float[] invxyz, float[] outvxyz, int gid) { - StaticNBodyTest.run(inxyz, outxyz, invxyz, outvxyz, gid); - } - - @Override - public void runTest() { - super.runTest(); - } - - @Test - @Override - public void test() throws Exception { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodySpillTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodySpillTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * This version of NBody causes Graal to generate register spilling code. - */ -public class StaticNBodySpillTest extends GraalKernelTester { - - static final int bodies = 5; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - // Positions xy and z of bodies. - @Result private float[] inxyz = new float[bodies * 3]; - // Positions xy and z of bodies. - @Result private float[] outxyz = new float[bodies * 3]; // positions xy and z of bodies - // Velocity component of x,y and z of bodies. - @Result private float[] invxyz = new float[bodies * 3]; - @Result private float[] outvxyz = new float[bodies * 3]; - static float[] seedxyz = new float[bodies * 3]; - static { - final float maxDist = width / 4; - for (int body = 0; body < (bodies * 3); body += 3) { - final float theta = (float) (Math.random() * Math.PI * 2); - final float phi = (float) (Math.random() * Math.PI * 2); - final float radius = (float) (Math.random() * maxDist); - seedxyz[body + 0] = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - seedxyz[body + 1] = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - seedxyz[body + 2] = (float) (radius * Math.cos(phi)); - } - } - - public static void run(float[] inxyz, float[] outxyz, float[] invxyz, float[] outvxyz, int gid) { - final int count = bodies * 3; - final int globalId = gid * 3; - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - for (int i = 0; i < count; i += 3) { - final float dx = inxyz[i + 0] - inxyz[globalId + 0]; - final float dy = inxyz[i + 1] - inxyz[globalId + 1]; - final float dz = inxyz[i + 2] - inxyz[globalId + 2]; - final float invDist = (float) (1.0 / (Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr))); - accx += mass * invDist * invDist * invDist * dx; - accy += mass * invDist * invDist * invDist * dy; - accz += mass * invDist * invDist * invDist * dz; - } - accx *= delT; - accy *= delT; - accz *= delT; - outxyz[globalId + 0] = inxyz[globalId + 0] + (invxyz[globalId + 0] * delT) + (accx * .5f * delT); - outxyz[globalId + 1] = inxyz[globalId + 1] + (invxyz[globalId + 1] * delT) + (accy * .5f * delT); - outxyz[globalId + 2] = inxyz[globalId + 2] + (invxyz[globalId + 2] * delT) + (accz * .5f * delT); - outvxyz[globalId + 0] = invxyz[globalId + 0] + accx; - outvxyz[globalId + 1] = invxyz[globalId + 1] + accy; - outvxyz[globalId + 2] = invxyz[globalId + 2] + accz; - } - - @Override - public void runTest() { - System.arraycopy(seedxyz, 0, inxyz, 0, seedxyz.length); - Arrays.fill(outxyz, 0f); - Arrays.fill(outvxyz, 0f); - Arrays.fill(invxyz, 0f); - dispatchMethodKernel(bodies, inxyz, outxyz, invxyz, outvxyz); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StaticNBodyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * 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 java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Unit test of NBody demo app. - */ -public class StaticNBodyTest extends GraalKernelTester { - - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - // Positions xy and z of bodies. - @Result private float[] inxyz = new float[bodies * 3]; - // Positions xy and z of bodies. - @Result private float[] outxyz = new float[bodies * 3]; - // Velocity component of x,y and z of bodies. - @Result private float[] invxyz = new float[bodies * 3]; - @Result private float[] outvxyz = new float[bodies * 3]; - static float[] seedxyz = new float[bodies * 3]; - static { - final float maxDist = width / 4; - for (int body = 0; body < (bodies * 3); body += 3) { - final float theta = (float) (Math.random() * Math.PI * 2); - final float phi = (float) (Math.random() * Math.PI * 2); - final float radius = (float) (Math.random() * maxDist); - seedxyz[body + 0] = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - seedxyz[body + 1] = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - seedxyz[body + 2] = (float) (radius * Math.cos(phi)); - } - } - - public static void run(float[] inxyz, float[] outxyz, float[] invxyz, float[] outvxyz, int gid) { - final int count = bodies * 3; - final int globalId = gid * 3; - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - for (int i = 0; i < count; i += 3) { - final float dx = inxyz[i + 0] - inxyz[globalId + 0]; - final float dy = inxyz[i + 1] - inxyz[globalId + 1]; - final float dz = inxyz[i + 2] - inxyz[globalId + 2]; - final float invDist = (float) (1.0 / (Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr))); - accx += mass * invDist * invDist * invDist * dx; - accy += mass * invDist * invDist * invDist * dy; - accz += mass * invDist * invDist * invDist * dz; - } - accx *= delT; - accy *= delT; - accz *= delT; - outxyz[globalId + 0] = inxyz[globalId + 0] + (invxyz[globalId + 0] * delT) + (accx * .5f * delT); - outxyz[globalId + 1] = inxyz[globalId + 1] + (invxyz[globalId + 1] * delT) + (accy * .5f * delT); - outxyz[globalId + 2] = inxyz[globalId + 2] + (invxyz[globalId + 2] * delT) + (accz * .5f * delT); - outvxyz[globalId + 0] = invxyz[globalId + 0] + accx; - outvxyz[globalId + 1] = invxyz[globalId + 1] + accy; - outvxyz[globalId + 2] = invxyz[globalId + 2] + accz; - } - - @Override - public void runTest() { - System.arraycopy(seedxyz, 0, inxyz, 0, seedxyz.length); - Arrays.fill(outxyz, 0f); - Arrays.fill(outvxyz, 0f); - Arrays.fill(invxyz, 0f); - dispatchMethodKernel(bodies, inxyz, outxyz, invxyz, outvxyz); - } - - @Test - public void test() throws Exception { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringContainsAcceptTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringContainsAcceptTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * 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.*; - -/** - * Tests codegen for String.contains() but with a wrapper method such as one would get in the - * IntConsumer.accept calls. - */ -public class StringContainsAcceptTest extends StringContainsTest { - - String base = "CDE"; - - // the accept method which "captured" the base - public void run(int gid) { - super.run(base, gid); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM); - } - - @Test - @Override - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringContainsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringContainsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for String.contains(). - */ -public class StringContainsTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public boolean[] outArray = new boolean[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, i, 10); - } - } - - public void run(String base, int gid) { - outArray[gid] = inArray[gid].contains(base); - } - - @Override - public void runTest() { - setupArrays(); - String base = "CDE"; - dispatchMethodKernel(NUM, base); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringEqualsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringEqualsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -public class StringEqualsTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public boolean[] outArray = new boolean[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, 0, 10 + (i % 3)); - } - } - - public void run(String base, int gid) { - outArray[gid] = inArray[gid].equals(base); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchMethodKernel(NUM, "ABCDEFGHIJ"); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringIndexOfTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringIndexOfTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for String.indexOf(). - */ -public class StringIndexOfTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, i, 10); - } - } - - public void run(String base, int gid) { - outArray[gid] = inArray[gid].indexOf(base); - } - - @Override - public void runTest() { - setupArrays(); - String base = "CDE"; - dispatchMethodKernel(NUM, base); - } - - @Test - public void test() { - testGeneratedHsail(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringSwitchTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/StringSwitchTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests switch statement with String literal keys. - * - * Note: In Java bytecode, this example reduces to a LOOKUPSWITCH over int keys because the Java - * source compiler generates a call to String.hashcode( ) to convert to int values. - * - * The HSAIL code generated for this example is a series of cascading compare and branch - * instructions for each case of the switch. - * - * These instruction have the following form: - * - * - * //Check whether the key matches the key constant of the case. Store the result of the compare (0 - * or 1) in the control register c0. - * - * cmp_eq $c0 <source register>, <key constant for case statement> - * - * //Branch to the corresponding label of that case if there's a match. - * - * cbr $c0 <branch target for that case> - */ -public class StringSwitchTest extends GraalKernelTester { - - static final int num = 40; - // Output array storing the results of the operations. - @Result protected int[] outArray = new int[num]; - - // Array of Strings - String[] names = {"0-42L", "0-43-", "Mazda", "Nissan", "Chevrolet", "Porsche", "Ford Focus", "Volvo", "Cadillac", "BMW", "Indy Car", "Police Car", "Lexus", "Datsun", "Saab", "Volkswagen", - "Honda Civic", "Jeeo Wrangler", "Toyota", "Mustang", "Chrysler", "Subaru"}; - - /** - * The static "kernel" method we will be testing. This method performs a switch statement over a - * String literal key. - * - * @param out the output array - * @param ina the input array of String literal keys - * @param gid the parameter used to index into the input and output arrays - */ - public static void run(int[] out, String[] ina, int gid) { - switch (ina[gid]) { - case "Mazda": - out[gid] = 1; - break; - case "Nissan": - out[gid] = 2; - break; - case "Chevrolet": - out[gid] = 3; - break; - case "Porsche": - out[gid] = 4; - break; - case "Jeep Wrangler": - out[gid] = 5; - break; - case "Toyota": - out[gid] = 6; - break; - case "0-42L": - out[gid] = 890; - break; - case "0-43-": - out[gid] = 995; - break; - case "Chrysler": - out[gid] = 7; - break; - case "Mitsubishi": - out[gid] = 8; - break; - case "Ford Focus": - out[gid] = 9; - break; - case "Volvo": - out[gid] = 10; - break; - case "Subaru": - out[gid] = 11; - break; - case "BMW": - out[gid] = 12; - break; - case "Indy Car": - out[gid] = 13; - break; - case "Police Car": - out[gid] = 14; - break; - } - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - /** - * Initializes the input and output arrays passed to the run routine. - * - * @param in the input array - */ - void setupArrays(String[] in) { - for (int i = 0; i < num; i++) { - // fill the input array with Strings. - in[i] = names[i % names.length]; - outArray[i] = 0; - } - } - - /** - * Dispatches the HSAIL kernel for this test case. - */ - @Override - public void runTest() { - String[] inArray = new String[num]; - setupArrays(inArray); - dispatchMethodKernel(num, outArray, inArray); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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; - -/** - * A simple 3 element Vector object used in some junit tests. - */ -public class Vec3 { - - public Vec3(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } - - public float x; - public float y; - public float z; - - public static Vec3 add(Vec3 a, Vec3 b) { - return new Vec3(a.x + b.x, a.y + b.y, a.z + b.z); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Vec3)) { - return false; - } - Vec3 oth = (Vec3) other; - return (oth.x == x && oth.y == y && oth.z == z); - } - - @Override - public String toString() { - return ("Vec3[" + x + ", " + y + ", " + z + "]"); - } - - @Override - public int hashCode() { - return (int) (x + y + z); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamClassCastNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamClassCastNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * 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.*; - -/** - * Tests an object array stream with one element being of the wrong class. - */ -public class Vec3ObjStreamClassCastNonZeroBciTest extends SingleExceptionTestBase { - - static final int NUM = 20; - - public Vec3[] inArray = new Vec3[NUM]; - - static class MyVec3 extends Vec3 { - public MyVec3(float x, float y, float z) { - super(x, y, z); - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new MyVec3(i, i + 1, -1); - } - // insert one wrong type - inArray[10] = new Vec3(10, 11, -1); - } - - int dummyInt = 10; - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - int adjustment = 0; - int tmp = dummyInt; - while (tmp-- >= 0) { - adjustment += tmp; - } - MyVec3 myvec3 = (MyVec3) vec3; - myvec3.z = myvec3.x + myvec3.y + adjustment; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(inArray); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamClassCastTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamClassCastTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * 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.*; - -/** - * Tests an object array stream with one element being of the wrong class. - */ -public class Vec3ObjStreamClassCastTest extends SingleExceptionTestBase { - - static final int NUM = 20; - - public Vec3[] inArray = new Vec3[NUM]; - - static class MyVec3 extends Vec3 { - public MyVec3(float x, float y, float z) { - super(x, y, z); - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new MyVec3(i, i + 1, -1); - } - // insert one wrong type - inArray[10] = new Vec3(10, 11, -1); - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - MyVec3 myvec3 = (MyVec3) vec3; - myvec3.z = myvec3.x + myvec3.y; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(inArray); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamFloatCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamFloatCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for a java 7 style object array stream kernel, one float capture. - */ -public class Vec3ObjStreamFloatCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(float adjustment, Vec3 vec3) { - vec3.z = vec3.x + vec3.y - adjustment; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(inArray, 0.5f); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamIntCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamIntCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for a java 7 style object array stream kernel, one int capture. - */ -public class Vec3ObjStreamIntCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(int adjustment, Vec3 vec3) { - vec3.z = vec3.x + vec3.y - adjustment; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(inArray, 7); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamIntFloatCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamIntFloatCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for a java 7 style object array stream kernel, with one int and one float capture. - */ -public class Vec3ObjStreamIntFloatCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(int adjustment, float multiplier, Vec3 vec3) { - vec3.z = (vec3.x + vec3.y - adjustment) * multiplier; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(inArray, 7, 0.5f); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamNullCheckNonZeroBciTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamNullCheckNonZeroBciTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * 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.*; - -/** - * Tests an object array stream with one element being null. - */ -public class Vec3ObjStreamNullCheckNonZeroBciTest extends SingleExceptionTestBase { - - static final int NUM = 20; - - public Vec3[] inArray = new Vec3[NUM]; - - static class MyVec3 extends Vec3 { - public MyVec3(float x, float y, float z) { - super(x, y, z); - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new MyVec3(i, i + 1, -1); - } - // insert one null - inArray[10] = null; - } - - int dummyInt = 10; - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - int adjustment = 0; - int tmp = dummyInt; - while (tmp-- >= 0) { - adjustment += tmp; - } - vec3.z = vec3.x + vec3.y + adjustment; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(inArray); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamNullCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamNullCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * 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.*; - -/** - * Tests an object array stream with one element being null. - */ -public class Vec3ObjStreamNullCheckTest extends SingleExceptionTestBase { - - static final int NUM = 20; - - public Vec3[] inArray = new Vec3[NUM]; - - static class MyVec3 extends Vec3 { - public MyVec3(float x, float y, float z) { - super(x, y, z); - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new MyVec3(i, i + 1, -1); - } - // insert one null - inArray[10] = null; - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - vec3.z = vec3.x + vec3.y; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(inArray); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamNullParamCheckTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamNullParamCheckTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * 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.*; - -/** - * Tests an object array stream with the object stream itself being null. - */ -public class Vec3ObjStreamNullParamCheckTest extends SingleExceptionTestBase { - - static final int NUM = 20; - - public Vec3[] inArray = new Vec3[NUM]; - - static class MyVec3 extends Vec3 { - public MyVec3(float x, float y, float z) { - super(x, y, z); - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new MyVec3(i, i + 1, -1); - } - // insert one null - inArray[10] = null; - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - MyVec3 myvec3 = (MyVec3) vec3; - myvec3.z = myvec3.x + myvec3.y; - } - - @Override - public void runTest() { - setupArrays(); - try { - dispatchMethodKernel(null); - } catch (Exception e) { - recordException(e); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamObjCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamObjCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for a java 7 style object array stream kernel, one object capture. - */ -public class Vec3ObjStreamObjCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 basevec, Vec3 vec3) { - vec3.z = vec3.x + vec3.y - basevec.z; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(inArray, new Vec3(1, 2, 3)); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamObjFieldTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamObjFieldTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for a java 7 style object array stream kernel, no captures. Instance method which - * accesses an object field - */ -public class Vec3ObjStreamObjFieldTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - Vec3 basevec = new Vec3(1, 2, 3); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - vec3.z = vec3.x + vec3.y - basevec.z; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(inArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/Vec3ObjStreamTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests codegen for a java 7 style object array stream kernel, no captures. - */ -public class Vec3ObjStreamTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - /** - * The "kernel" method we will be testing. For Array Stream, an object from the array will be - * the last parameter - */ - public void run(Vec3 vec3) { - vec3.z = vec3.x + vec3.y; - } - - @Override - public void runTest() { - setupArrays(); - dispatchMethodKernel(inArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/VolatileIntTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/VolatileIntTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -/* - * 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 com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * - * @author ecaspole - */ -public class VolatileIntTest extends GraalKernelTester { - - static final int num = 20; - @Result protected int[] outArray = new int[num]; - - volatile int theVolatileInt = 42; - - /** - * The static "kernel" method we will be testing. By convention the gid is the last parameter. - * - */ - public void run(int[] out, int[] ina, int[] inb, int gid) { - - // Note these array ops are not really part of the test results - int x = theVolatileInt; - - out[gid] = ina[gid] + inb[gid]; - - theVolatileInt = x; - } - - @Test - public void test() { - super.testGeneratedHsail(); - } - - void setupArrays(int[] in, int[] in2) { - for (int i = 0; i < num; i++) { - in[i] = 1; - in2[i] = 2; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - int[] inArray = new int[num]; - int[] inArray2 = new int[num]; - setupArrays(inArray, inArray2); - - dispatchMethodKernel(num, outArray, inArray, inArray2); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayFieldAccessTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayFieldAccessTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests accessing a field which is an array. - */ -public class ArrayFieldAccessTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * 3; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayListGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayListGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests calling ArrayList.get(). - */ -public class ArrayListGetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public ArrayList inList = new ArrayList<>(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inList.add(i); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - int val = inList.get(gid); - outArray[gid] = val * val + 1; - }); - } - - @Ignore("emitDirectCall unimplemented") - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayListSetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayListSetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; -import java.util.*; - -/** - * Tests calling ArrayList.set(). - */ -public class ArrayListSetTest extends GraalKernelTester { - - static final int NUM = 50; - ArrayList aryList = new ArrayList<>(); - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - aryList.add(-1); - } - dispatchLambdaKernel(NUM, (gid) -> { - aryList.set(gid, gid); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - @Ignore - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayListStreamTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ArrayListStreamTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/* - * 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.lambda; - -import java.util.ArrayList; -import java.util.stream.Stream; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -/** - * Tests using ArrayLists as streams. - */ -public class ArrayListStreamTest { - - // Static and instance fields to test codegen for - // each type of variable - static int staticSize = 16; - final int size = staticSize; - - static int staticFactor = 3; - final int factor = staticFactor; - - class MyPoint { - - int x; - int y; - - public MyPoint(int x, int y) { - this.x = x; - this.y = y; - } - } - - public ArrayList buildMyPointInputArray() { - ArrayList inputs = new ArrayList<>(size); - - for (int i = 0; i < size; i++) { - inputs.add(new MyPoint(i, i + 1)); - } - return inputs; - } - - public int[] buildIntInputArray() { - int[] inputs = new int[size]; - - for (int i = 0; i < size; i++) { - inputs[i] = i * 4; - } - return inputs; - } - - @Test - public void testForEachObjectStreamNoCaptures() { - ArrayList inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - // Swap the values - int tmp = p.x; - p.x = p.y + factor; - p.y = tmp; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.x == (p.y + 1 + factor)); - } - } - - @Test - public void testForEachObjectStreamNoCapturesUseStatic() { - ArrayList inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - // Swap the values - int tmp = p.x; - p.x = p.y + staticFactor; - p.y = tmp; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.x == (p.y + 1 + staticFactor)); - } - } - - @Test - public void testForEachObjectStreamOneCapture() { - int[] data = buildIntInputArray(); - ArrayList inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x]; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x]); - } - - } - - @Test - public void testForEachObjectStreamOneCaptureUseStatic() { - int[] data = buildIntInputArray(); - ArrayList inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x] + staticFactor; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == (data[p.x] + +staticFactor)); - } - - } - - @Test - public void testForEachObjectStreamTwoCaptures() { - int[] data = buildIntInputArray(); - int[] data2 = buildIntInputArray(); - ArrayList inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x] + data2[p.x]; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x] + data2[p.x]); - } - - } - - @Test - public void testForEachObjectStreamTwoCapturesUseStatic() { - int[] data = buildIntInputArray(); - int[] data2 = buildIntInputArray(); - ArrayList inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x] + data2[p.x] + staticFactor; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x] + data2[p.x] + staticFactor); - } - - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntAddAndGetGidTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntAddAndGetGidTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#addAndGet(int)} with a variable delta. - */ -public class AtomicIntAddAndGetGidTest extends GraalKernelTester { - - static final int NUM = 20; - public int[] outArray = new int[NUM]; - @Result public int[] gaps = new int[NUM]; - AtomicInteger atomicInt; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - atomicInt = new AtomicInteger(0); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.addAndGet(gid); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - // System.out.print("outArray: "); - // for (int val : outArray) { - // System.out.print(val + ", "); - // } - // System.out.println(); - // create array of gaps - gaps[0] = outArray[0] - 0; - for (int i = 1; i < NUM; i++) { - gaps[i] = outArray[i] - outArray[i - 1]; - } - Arrays.sort(gaps); - - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntAddAndGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntAddAndGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#addAndGet(int)} with the delta being a constant. - */ -public class AtomicIntAddAndGetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.addAndGet(0x7); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntDecAndGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntDecAndGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#decrementAndGet()}. - */ -public class AtomicIntDecAndGetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.decrementAndGet(); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntGetAndAddTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntGetAndAddTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#getAndAdd(int)} with the delta being a constant. - */ -public class AtomicIntGetAndAddTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.getAndAdd(0x7); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntGetAndDecTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntGetAndDecTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#getAndDecrement()}. - */ -public class AtomicIntGetAndDecTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.getAndDecrement(); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntGetAndIncTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntGetAndIncTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#getAndIncrement()}. - */ -public class AtomicIntGetAndIncTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.getAndIncrement(); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntIncAndGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicIntIncAndGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.Arrays; - -/** - * Tests {@link AtomicInteger#incrementAndGet()}. - */ -public class AtomicIntIncAndGetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - AtomicInteger atomicInt = new AtomicInteger(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicInt.incrementAndGet(); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongAddAndGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongAddAndGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -import org.junit.Test; - -import java.util.concurrent.atomic.*; -import java.util.Arrays; - -/** - * Tests {@link AtomicLong#addAndGet(long)} with the delta being a constant. - */ -public class AtomicLongAddAndGetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - AtomicLong atomicLong = new AtomicLong(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicLong.addAndGet(0x7); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongGetAndAddTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongGetAndAddTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicLong; -import java.util.Arrays; - -/** - * Tests {@link AtomicLong#getAndAdd(long)} with the delta being a constant. - */ -public class AtomicLongGetAndAddTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - AtomicLong atomicLong = new AtomicLong(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicLong.getAndAdd(0x7); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongGetAndIncTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongGetAndIncTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicLong; -import java.util.Arrays; - -/** - * Tests {@link AtomicLong#getAndIncrement()}. - */ -public class AtomicLongGetAndIncTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - AtomicLong atomicLong = new AtomicLong(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicLong.getAndIncrement(); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongIncAndGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/AtomicLongIncAndGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.util.concurrent.atomic.AtomicLong; -import java.util.Arrays; - -/** - * Tests {@link AtomicLong#incrementAndGet()}. - */ -public class AtomicLongIncAndGetTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - AtomicLong atomicLong = new AtomicLong(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = atomicLong.incrementAndGet(); - }); - - // note: the actual order of entries in outArray is not predictable - // thus we sort before we compare results - Arrays.sort(outArray); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/BigIntegerSquaredTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/BigIntegerSquaredTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import java.math.BigInteger; - -/** - * Tests squaring a BigInteger. - */ -public class BigIntegerSquaredTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public BigInteger[] inArray = new BigInteger[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new BigInteger(Integer.toString(i)); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid].multiply(inArray[gid]).intValue(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - // recursive calls - return (canHandleHSAILMethodCalls()); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Body.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Body.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * A Body object derived from Vec3 used in NBody tests. - */ -public class Body extends Vec3 { - - public Body(float x, float y, float z, float m) { - super(x, y, z); - this.m = m; - v = new Vec3(0, 0, 0); - } - - float m; - Vec3 v; - - public float getX() { - return x; - } - - public float getY() { - return y; - } - - public float getZ() { - return z; - } - - public float getVx() { - return v.x; - } - - public float getVy() { - return v.y; - } - - public float getVz() { - return v.z; - } - - public float getM() { - return m; - } - - public void setM(float value) { - m = value; - } - - public void setX(float value) { - x = value; - } - - public void setY(float value) { - y = value; - } - - public void setZ(float value) { - z = value; - } - - public void setVx(float value) { - v.x = value; - } - - public void setVy(float value) { - v.y = value; - } - - public void setVz(float value) { - v.z = value; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Body)) { - return false; - } - Body oth = (Body) other; - return (oth.x == x && oth.y == y && oth.z == z && oth.m == m && v.equals(oth.v)); - } - - @Override - public int hashCode() { - // TODO Auto-generated method stub - return super.hashCode(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ByteArrayCopyConjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ByteArrayCopyConjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a byte array where src and dest overlap. - */ -public class ByteArrayCopyConjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result byte[][] outArray = new byte[NUM][MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - for (int j = 0; j < outArray[i].length; j++) { - outArray[i][j] = (byte) (i + j); - } - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(outArray[gid], 0, outArray[gid], gid % NUM, NUM); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ByteArrayCopyDisjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ByteArrayCopyDisjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a byte array where src and dest do not overlap. - */ -public class ByteArrayCopyDisjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result byte[][] outArray = new byte[NUM][MAXOUTSIZ]; - byte[] inArray = new byte[NUM + MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < inArray.length; i++) { - inArray[i] = (byte) i; - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(inArray, gid, outArray[gid], 0, MAXOUTSIZ); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ByteArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ByteArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests reading from a byte array. - */ -public class ByteArrayTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public byte[] inArray = new byte[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = (byte) ((i + 1) * (i % 3 == 0 ? 1 : -1)); - outArray[i] = 99; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/CharArrayCopyConjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/CharArrayCopyConjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a char array where src and dest overlap. - */ -public class CharArrayCopyConjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result char[][] outArray = new char[NUM][MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - for (int j = 0; j < outArray[i].length; j++) { - outArray[i][j] = (char) (i + j); - } - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(outArray[gid], 0, outArray[gid], gid % NUM, NUM); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/CharArrayCopyDisjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/CharArrayCopyDisjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a char array where src and dest do not overlap. - */ -public class CharArrayCopyDisjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result char[][] outArray = new char[NUM][MAXOUTSIZ]; - char[] inArray = new char[NUM + MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < inArray.length; i++) { - inArray[i] = (char) i; - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(inArray, gid, outArray[gid], 0, MAXOUTSIZ); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/CountMatchesBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/CountMatchesBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Base class for tests that use Apache StringUtils.countMatches(). - */ -public abstract class CountMatchesBase extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + (i % 10)); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, i, 40); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAcosTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAcosTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#acos(double)}. - */ -public class DoubleAcosTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.acos(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAsinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAsinTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#asin(double)}. - */ -public class DoubleAsinTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.asin(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAtan2Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAtan2Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#atan2(double, double)}. - */ -public class DoubleAtan2Test extends DoubleTwoInputMathBase { - - // for atan2 ULPs can be off by 2 ulps. - @Override - protected int ulpsDelta() { - return 2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = Math.atan2(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAtanTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleAtanTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#atan(double)}. - */ -public class DoubleAtanTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.atan(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCbrtTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCbrtTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#cbrt(double)}. - */ -public class DoubleCbrtTest extends DoubleMathBase { - - /** - * Dispatches the HSAIL kernel for this test case. - */ - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.cbrt(inArray[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 testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCosTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCosTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#cos(double)}. - */ -public class DoubleCosTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.cos(inArray[gid]); - }); - } - - // internally allocates a Rempiostruct, escape analysis not catching it - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCoshTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleCoshTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#cosh(double)}. - */ -public class DoubleCoshTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.cosh(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleExpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleExpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#exp(double)}. - */ -public class DoubleExpTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.exp(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleExpm1Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleExpm1Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#expm1(double)}. - */ -public class DoubleExpm1Test extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.expm1(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleFieldAccessTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleFieldAccessTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests accessing a double field. - */ -public class DoubleFieldAccessTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public double[] outArray = new double[NUM]; - public double[] inArray = new double[NUM]; - - double doubleField = 7.0; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - double[] out = outArray; - double[] in = inArray; - dispatchLambdaKernel(NUM, (gid) -> { - out[gid] = in[gid] + doubleField; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleGetExponentTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleGetExponentTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#getExponent(double)}. - */ -public class DoubleGetExponentTest extends DoubleMathLargeBase { - - @Result int[] outIntArray = new int[size]; - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outIntArray[gid] = Math.getExponent(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleHypotTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleHypotTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#hypot(double, double)}. - */ -public class DoubleHypotTest extends DoubleTwoInputMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = Math.hypot(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleIeeeRemainderTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleIeeeRemainderTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#IEEEremainder(double, double)}. - */ -public class DoubleIeeeRemainderTest extends DoubleTwoInputMathBase { - - @Override - public void runTest() { - setupArrays(); - // for debugging - inArray1[0] = inArray1[258]; - inArray2[0] = inArray2[258]; - - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = Math.IEEEremainder(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleLog10Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleLog10Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#log10(double)}. - */ -public class DoubleLog10Test extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.log10(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleLogTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleLogTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#log(double)}. - */ -public class DoubleLogTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.log(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleMathBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleMathBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * 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.lambda; - -public abstract class DoubleMathBase extends MathTestBase { - - static final int size = 256; - @Result double[] outArray = new double[size]; - double[] inArray = new double[size]; - - @Override - String getInputString(int idx) { - return Double.toString(inArray[idx]); - } - - double largestValue() { - return Math.PI; - } - - /** - * Initializes the input and output arrays. - */ - void setupArrays() { - for (int i = 0; i < size / 2; i++) { - // Include positive and negative values as well as corner cases. - double val = (largestValue() / (size / 2)) * i; - inArray[i] = val; - inArray[i + size / 2] = -val; - } - // special values filled at end - inArray[size - 1] = Double.NaN; - inArray[size - 2] = Double.NEGATIVE_INFINITY; - inArray[size - 3] = Double.POSITIVE_INFINITY; - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleMathLargeBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleMathLargeBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.lambda; - -public abstract class DoubleMathLargeBase extends DoubleMathBase { - - @Override - void setupArrays() { - for (int i = 0; i < size / 2; i++) { - // Include positive and negative values as well as corner cases. - double val = (i == 0 ? 0 : Math.pow(1.99, i)); - inArray[i] = val; - inArray[i + size / 2] = -val; - } - // special values filled at end - inArray[size - 1] = Double.NaN; - inArray[size - 2] = Double.NEGATIVE_INFINITY; - inArray[size - 3] = Double.POSITIVE_INFINITY; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextAfterTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextAfterTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#nextAfter(double, double)}. - */ -public class DoubleNextAfterTest extends DoubleMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - double direction = (gid & 1) == 0 ? Double.POSITIVE_INFINITY : Double.NEGATIVE_INFINITY; - outArray[gid] = Math.nextAfter(inArray[gid], direction); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (runningOnSimulator() || runningCQETests()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextUpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleNextUpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#nextUp(double)}. - */ -public class DoubleNextUpTest extends DoubleMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.nextUp(inArray[gid]); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (runningOnSimulator() || runningCQETests()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoublePowTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoublePowTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#pow(double, double)}. - */ -public class DoublePowTest extends DoubleTwoInputMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = Math.pow(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleRoundTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleRoundTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#round(double)}. - */ -public class DoubleRoundTest extends DoubleMathLargeBase { - - @Result long[] outLongArray = new long[size]; - - @Override - public void runTest() { - setupArrays(); - // for testing - inArray[0] = inArray[66]; - dispatchLambdaKernel(size, (gid) -> { - outLongArray[gid] = Math.round(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleScalbTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleScalbTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#scalb(double, int)}. - */ -public class DoubleScalbTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.scalb(inArray[gid], 64 - (gid % 128)); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSignumTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSignumTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#signum(double)}. - */ -public class DoubleSignumTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.signum(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#sin(double)}. - */ -public class DoubleSinTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.sin(inArray[gid]); - }); - } - - // internally allocates a Rempiostruct, escape analysis not catching it - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinhTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleSinhTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#sinh(double)}. - */ -public class DoubleSinhTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.sinh(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#tan(double)}. - */ -public class DoubleTanTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.tan(inArray[gid]); - }); - } - - // internally allocates a Rempiostruct, escape analysis not catching it - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanhTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTanhTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#tanh(double)}. - */ -public class DoubleTanhTest extends DoubleMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.tanh(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleToLongTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleToLongTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#round(double)}. - */ -public class DoubleToLongTest extends DoubleMathLargeBase { - - @Result long[] outLongArray = new long[size]; - - @Override - public void runTest() { - setupArrays(); - // for testing - // inArray[0] = inArray[66]; - dispatchLambdaKernel(size, (gid) -> { - outLongArray[gid] = (long) inArray[gid]; - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTwoInputMathBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleTwoInputMathBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * 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.lambda; - -public abstract class DoubleTwoInputMathBase extends DoubleMathBase { - - double[] inArray1 = new double[size * size]; - double[] inArray2 = new double[size * size]; - @Result double[] bigOutArray = new double[size * size]; - - @Override - String getInputString(int idx) { - return "(" + inArray1[idx] + ", " + inArray2[idx] + ")"; - } - - /** - * Initializes the input and output arrays. - */ - @Override - void setupArrays() { - super.setupArrays(); - // make combinations of the input array - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - int idx = i * size + j; - inArray1[idx] = inArray[i]; - inArray2[idx] = inArray[j]; - bigOutArray[idx] = 0; - } - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleUlpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DoubleUlpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#ulp(double)}. - */ -public class DoubleUlpTest extends DoubleMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.ulp(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DremTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/DremTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests the DREM bytecode instruction. - */ -public class DremTest extends DoubleTwoInputMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - double f1 = inArray1[gid]; - double f2 = inArray2[gid]; - bigOutArray[gid] = f1 % f2; - }); - } - - // ignoring until we implement support for DREM bytecode - @Ignore - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FibRecursionTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FibRecursionTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests a recursive method invocation. - */ -public class FibRecursionTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - int fib(int n) { - return (n <= 2 ? 1 : fib(n - 2) + fib(n - 1)); - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = fib(inArray[gid]); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - // recursive calls - return (canHandleHSAILMethodCalls()); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Base class for 2D float matrix tests. - */ -public abstract class Float2DMatrixBase extends GraalKernelTester { - - float[][] matrixA; - float[][] matrixB; - @Result float[][] outMatrix; - - public void setupArrays(int range) { - matrixA = new float[range][]; - matrixB = new float[range][]; - outMatrix = new float[range][]; - for (int j = 0; j < range; j++) { - matrixA[j] = new float[range]; - matrixB[j] = new float[range]; - outMatrix[j] = new float[range]; - for (int k = 0; k < range; k++) { - matrixA[j][k] = (j + k) % 7; - matrixB[j][k] = (j + k + 1) % 8; - } - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixMultiplyRangeFinalTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixMultiplyRangeFinalTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests 2D float matrix multiply with range being final. - */ -public class Float2DMatrixMultiplyRangeFinalTest extends Float2DMatrixBase { - - static final int range = 6; - - @Override - public void runTest() { - setupArrays(range); - - dispatchLambdaKernel(range, (gid) -> { - for (int j = 0; j < range; j++) { - float sum = 0; - for (int k = 0; k < range; k++) { - sum += (matrixA[gid][k] * matrixB[k][j]); - } - outMatrix[gid][j] = sum; - } - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixMultiplySingleOutTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixMultiplySingleOutTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests 2D float matrix multiply with each workitem outputting one entry of the result matrix. - */ -public class Float2DMatrixMultiplySingleOutTest extends Float2DMatrixBase { - - @Override - public void runTest() { - int range = 20; - setupArrays(range); - - dispatchLambdaKernel(range * range, (gid) -> { - int i = gid % range; - int j = gid / range; - float sum = 0; - for (int k = 0; k < range; k++) { - sum += (matrixA[i][k] * matrixB[k][j]); - } - outMatrix[i][j] = sum; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixMultiplyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Float2DMatrixMultiplyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests 2D float matrix multiply with each workitem outputting one row of the result matrix. - */ -public class Float2DMatrixMultiplyTest extends Float2DMatrixBase { - - @Override - public void runTest() { - int range = 20; - setupArrays(range); - - dispatchLambdaKernel(range, (gid) -> { - for (int j = 0; j < range; j++) { - float sum = 0; - for (int k = 0; k < range; k++) { - sum += (matrixA[gid][k] * matrixB[k][j]); - } - outMatrix[gid][j] = sum; - } - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAcosTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAcosTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#acos(double)} with float arg. - */ -public class FloatAcosTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.acos(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAsinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAsinTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#asin(double)} with float arg. - */ -public class FloatAsinTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.asin(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAtan2Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAtan2Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#atan2(double, double)}. - */ -public class FloatAtan2Test extends FloatTwoInputMathBase { - - // for atan2 ULPs can be off by 2 ulps. - @Override - protected int ulpsDelta() { - return 2; - } - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = (float) Math.atan2(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAtanTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatAtanTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#atan(double)} with float arg. - */ -public class FloatAtanTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.atan(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCbrtTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCbrtTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#cbrt(double)} with float arg. - */ -public class FloatCbrtTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.cbrt(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCondMoveTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCondMoveTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests conditional move of a float value. - */ -public class FloatCondMoveTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - public float[] inArray = new float[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = (gid > 9 ? 2.0f : 3.0f); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCosTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCosTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#cos(double)} with float arg. - */ -public class FloatCosTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.cos(inArray[gid]); - }); - } - - // internally allocates a Rempiostruct, escape analysis not catching it - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCoshTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatCoshTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#cosh(double)} with float arg. - */ -public class FloatCoshTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.cosh(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatExpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatExpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#exp(double)} with float arg. - */ -public class FloatExpTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.exp(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatExpm1Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatExpm1Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#expm1(double)} with float arg. - */ -public class FloatExpm1Test extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.expm1(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatFieldAccessTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatFieldAccessTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests accessing a float field. - */ -public class FloatFieldAccessTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - public int[] inArray = new int[NUM]; - - float floatField = 7f; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - float[] out = outArray; - int[] in = inArray; - dispatchLambdaKernel(NUM, (gid) -> { - out[gid] = in[gid] + floatField; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatFieldWriteTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatFieldWriteTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests writing a float field. - */ -public class FloatFieldWriteTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Body[] bodyArray = new Body[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - Body b = new Body(i, i + 1, -i, 0); - bodyArray[i] = b; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Body b = bodyArray[gid]; - b.z = b.x * b.y; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatGetExponentTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatGetExponentTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#getExponent(double)} with float arg. - */ -public class FloatGetExponentTest extends FloatMathLargeBase { - - @Result int[] outIntArray = new int[size]; - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outIntArray[gid] = Math.getExponent(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatIeeeRemainderTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatIeeeRemainderTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#IEEEremainder(double, double)}. - */ -public class FloatIeeeRemainderTest extends FloatTwoInputMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = (float) Math.IEEEremainder(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatLog10Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatLog10Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#log10(double)} with float arg. - */ -public class FloatLog10Test extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.log10(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatLogTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatLogTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#log(double)} with float arg. - */ -public class FloatLogTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.log(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatMathBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatMathBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * 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.lambda; - -public abstract class FloatMathBase extends MathTestBase { - - static final int size = 256; - @Result float[] outArray = new float[size]; - float[] inArray = new float[size]; - - @Override - String getInputString(int idx) { - return Float.toString(inArray[idx]); - } - - /** - * Initializes the input and output arrays. - */ - void setupArrays() { - for (int i = 0; i < size / 2; i++) { - // Include positive and negative values as well as corner cases. - float val = (float) (i * Math.PI / (size / 2)); - inArray[i] = val; - inArray[i + size / 2] = -val; - outArray[i] = 999.0f; - outArray[i + size / 2] = 999.0f; - } - // special values filled at end - inArray[size - 1] = Float.NaN; - inArray[size - 2] = Float.NEGATIVE_INFINITY; - inArray[size - 3] = Float.POSITIVE_INFINITY; - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatMathLargeBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatMathLargeBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * 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.lambda; - -public abstract class FloatMathLargeBase extends FloatMathBase { - - @Override - void setupArrays() { - for (int i = 0; i < size / 2; i++) { - // Include positive and negative values as well as corner cases. - float val = (float) (i == 0 ? 0 : Math.pow(1.99, (i % 100))); - inArray[i] = val; - inArray[i + size / 2] = -val; - } - // special values filled at end - inArray[size - 1] = Float.NaN; - inArray[size - 2] = Float.NEGATIVE_INFINITY; - inArray[size - 3] = Float.POSITIVE_INFINITY; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextAfterTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextAfterTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#nextAfter(float, double)}. - */ -public class FloatNextAfterTest extends FloatMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - float direction = (gid & 1) == 0 ? Float.POSITIVE_INFINITY : Float.NEGATIVE_INFINITY; - outArray[gid] = Math.nextAfter(inArray[gid], direction); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (runningOnSimulator() || runningCQETests()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextUpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatNextUpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#nextUp(float)} with float arg. - */ -public class FloatNextUpTest extends FloatMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.nextUp(inArray[gid]); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (runningOnSimulator() || runningCQETests()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatPowTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatPowTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#pow(double, double)}. - */ -public class FloatPowTest extends FloatTwoInputMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size * size, (gid) -> { - bigOutArray[gid] = (float) Math.pow(inArray1[gid], inArray2[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatRoundTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatRoundTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#round(float)}. - */ -public class FloatRoundTest extends FloatMathLargeBase { - - @Result int[] outIntArray = new int[size]; - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outIntArray[gid] = Math.round(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatScalbTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatScalbTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#scalb(float, int)}. - */ -public class FloatScalbTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.scalb(inArray[gid], 64 - (gid % 128)); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSignumTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSignumTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#signum(float)}. - */ -public class FloatSignumTest extends FloatMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.signum(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#sin(double)} with float arg. - */ -public class FloatSinTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.sin(inArray[gid]); - }); - } - - // internally allocates a Rempiostruct, escape analysis not catching it - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinhTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatSinhTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#sinh(double)} with float arg. - */ -public class FloatSinhTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.sinh(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#tan(double)} with float arg. - */ -public class FloatTanTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.tan(inArray[gid]); - }); - } - - // internally allocates a Rempiostruct, escape analysis not catching it - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation()); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanhTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTanhTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#tanh(double)} with float arg. - */ -public class FloatTanhTest extends FloatMathBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = (float) Math.tanh(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTwoInputMathBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatTwoInputMathBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * 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.lambda; - -public abstract class FloatTwoInputMathBase extends FloatMathBase { - - float[] inArray1 = new float[size * size]; - float[] inArray2 = new float[size * size]; - @Result float[] bigOutArray = new float[size * size]; - - @Override - String getInputString(int idx) { - return "(" + inArray1[idx] + ", " + inArray2[idx] + ")"; - } - - /** - * Initializes the input and output arrays. - */ - @Override - void setupArrays() { - super.setupArrays(); - // make combinations of the input array - for (int i = 0; i < size; i++) { - for (int j = 0; j < size; j++) { - int idx = i * size + j; - inArray1[idx] = inArray[i]; - inArray2[idx] = inArray[j]; - bigOutArray[idx] = 0; - } - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatUlpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/FloatUlpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests call to {@link Math#ulp(float)}. - */ -public class FloatUlpTest extends FloatMathLargeBase { - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(size, (gid) -> { - outArray[gid] = Math.ulp(inArray[gid]); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ForEachToGraalTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ForEachToGraalTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,316 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static org.junit.Assert.*; - -import java.util.*; -import java.util.stream.*; - -import org.junit.*; - -/** - * Several tests for the Sumatra APIs. - */ -public class ForEachToGraalTest { - - // Static and instance fields to test codegen for - // each type of variable - static int staticSize = 16; - final int size = staticSize; - - static int printSize = 4; - - static int staticFactor = 3; - final int factor = staticFactor; - - class MyPoint { - - int x; - int y; - - public MyPoint(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public int getY() { - return y; - } - } - - public MyPoint[] buildMyPointInputArray() { - MyPoint[] inputs = new MyPoint[size]; - - for (int i = 0; i < size; i++) { - inputs[i] = new MyPoint(i, i + 1); - } - return inputs; - } - - public int[] buildIntInputArray() { - int[] inputs = new int[size]; - - for (int i = 0; i < size; i++) { - inputs[i] = i * 4; - } - return inputs; - } - - @Test - public void testForEachIntRangeNoCaptures() { - int[] dest = new int[size]; - IntStream range = IntStream.range(0, dest.length).parallel(); - - // System.out.println("testForEachIntRangeNoCaptures"); - - range.forEach(p -> { - dest[p] = p * factor; - }); - - for (int k = 0; k < dest.length; k++) { - if (k < printSize) { - // System.out.println(k + " ... " + dest[k]); - } - assertTrue(dest[k] == k * factor); - } - } - - @Test - public void testForEachIntRangeNoCapturesUseStatic() { - int[] dest = new int[size]; - IntStream range = IntStream.range(0, dest.length).parallel(); - - // System.out.println("testForEachIntRangeNoCapturesUseStatic"); - - range.forEach(p -> { - dest[p] = p * staticFactor; - }); - - for (int k = 0; k < dest.length; k++) { - if (k < printSize) { - // System.out.println(k + " ... " + dest[k]); - } - assertTrue(dest[k] == k * staticFactor); - } - } - - @Test - public void testForEachIntRangeOneCapture() { - int[] dest = new int[size]; - IntStream range = IntStream.range(0, dest.length).parallel(); - int[] data = buildIntInputArray(); - - range.forEach(p -> { - dest[p] = p * factor + data[p]; - }); - - for (int k = 0; k < dest.length; k++) { - if (k < printSize) { - // System.out.println(k + " ... " + dest[k]); - } - assertTrue(dest[k] == k * 3 + data[k]); - } - - } - - @Test - public void testForEachIntRangeOneCaptureUseStatic() { - int[] dest = new int[size]; - IntStream range = IntStream.range(0, dest.length).parallel(); - int[] data = buildIntInputArray(); - - range.forEach(p -> { - dest[p] = p * staticFactor + data[p]; - }); - - for (int k = 0; k < dest.length; k++) { - // System.out.println( k + " ... " + dest[k] ); - assertTrue(dest[k] == k * staticFactor + data[k]); - } - - } - - @Test - public void testForEachObjectStreamNoCaptures() { - MyPoint[] inputs = buildMyPointInputArray(); - - Arrays.stream(inputs).parallel().forEach(p -> { - // Swap the values - int tmp = p.x; - p.x = p.y + factor; - p.y = tmp; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs[k]; - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.x == (p.y + 1 + factor)); - } - } - - @Test - public void testForEachObjectStreamNoCapturesUseStatic() { - MyPoint[] inputs = buildMyPointInputArray(); - - Arrays.stream(inputs).parallel().forEach(p -> { - // Swap the values - int tmp = p.x; - p.x = p.y + staticFactor; - p.y = tmp; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs[k]; - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.x == (p.y + 1 + staticFactor)); - } - } - - @Test - public void testForEachObjectStreamOneCapture() { - MyPoint[] inputs = buildMyPointInputArray(); - int[] data = buildIntInputArray(); - - Arrays.stream(inputs).parallel().forEach(p -> { - p.y = data[p.x]; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs[k]; - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x]); - } - - } - - @Test - public void testForEachObjectStreamOneCaptureUseStatic() { - MyPoint[] inputs = buildMyPointInputArray(); - int[] data = buildIntInputArray(); - - Arrays.stream(inputs).parallel().forEach(p -> { - p.y = data[p.x] + staticFactor; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs[k]; - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == (data[p.x] + +staticFactor)); - } - - } - - @Test - public void testForEachObjectStreamTwoCaptures() { - MyPoint[] inputs = buildMyPointInputArray(); - int[] data = buildIntInputArray(); - int[] data2 = buildIntInputArray(); - - Arrays.stream(inputs).parallel().forEach(p -> { - p.y = data[p.x] + data2[p.x]; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs[k]; - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x] + data2[p.x]); - } - - } - - @Test - public void testForEachObjectStreamTwoCapturesUseStatic() { - MyPoint[] inputs = buildMyPointInputArray(); - int[] data = buildIntInputArray(); - int[] data2 = buildIntInputArray(); - - Arrays.stream(inputs).parallel().forEach(p -> { - p.y = data[p.x] + data2[p.x] + staticFactor; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs[k]; - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x] + data2[p.x] + staticFactor); - } - - } - - // This test should fall back to the regular Java path if - // Graal throws NYI - @Test - public void testForEachIntRangeNoCapturesUseEscapingNew() { - if (runtime().getConfig().useHSAILDeoptimization == false) { - return; - } - - MyPoint[] dest = new MyPoint[size]; - IntStream range = IntStream.range(0, dest.length).parallel(); - - range.forEach(p -> { - dest[p] = new MyPoint(p + p, p); - }); - - for (int k = 0; k < dest.length; k++) { - if (k < printSize) { - // System.out.println(k + " ... " + dest[k]); - } - assertTrue(dest[k].getX() == (k + k)); - } - } - - // This test should fall back to the regular Java path if - // Graal throws NYI - @Test - public void testForEachIntRangeNoCapturesUseCall() { - MyPoint[] dest = new MyPoint[size]; - ArrayList list = new ArrayList<>(size); - IntStream range = IntStream.range(0, dest.length).parallel(); - - for (int i = 0; i < dest.length; i++) { - list.add(new MyPoint(i + i, i)); - } - - range.forEach(p -> { - dest[p] = list.get(p); - }); - - for (int k = 0; k < dest.length; k++) { - if (k < printSize) { - // System.out.println(k + " ... " + dest[k]); - } - assertTrue(dest[k].getX() == (k + k)); - } - } - // public static void main(String args[]) { - // (new ForEachToGraalTest()).testForEachIntRange(); - // } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/HashMapGetTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/HashMapGetTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.debug.Debug.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import com.oracle.graal.debug.*; - -import java.util.HashMap; - -import org.junit.Test; - -/** - * Tests calling HashMap.get(). - */ -public class HashMapGetTest extends GraalKernelTester { - - static final int NUM = 20; - - static class MyObj { - public MyObj(int id) { - this.id = id; - } - - int id; - - public int getId() { - return id; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof MyObj)) { - return false; - } - MyObj othobj = (MyObj) other; - return (othobj.id == this.id); - } - - @Override - public int hashCode() { - return 43 * (id % 7); - } - - } - - @Result public MyObj[] outArray = new MyObj[NUM]; - MyObj[] inArray = new MyObj[NUM]; - public HashMap inMap = new HashMap<>(); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - MyObj myobj = new MyObj(i); - inMap.put(myobj, new MyObj(i * 3)); - inArray[NUM - 1 - i] = myobj; - outArray[i] = null; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inMap.get(inArray[gid]); - }); - } - - // ForeignCall to Invoke#Direct#get - // not inlining HashMapGetTest.lambda$38@15: java.util.HashMap.get(Object):Object (20 bytes): no - // type profile exists - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void test() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsail(); - } - } - - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void testUsingLambdaMethod() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsailUsingLambdaMethod(); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceNBodyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceNBodyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +0,0 @@ -/* - * 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.lambda; - -import java.util.*; -import org.junit.*; -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Test intstream lambda version of nbody. - */ -public class InstanceNBodyTest extends GraalKernelTester { - - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - - @Result float[] inXyz = new float[bodies * 3]; // positions xy and z of bodies - - @Result float[] outXyz = new float[bodies * 3]; // positions xy and z of bodies - - @Result float[] inVxyz = new float[bodies * 3]; // velocity component of x,y and z of - // bodies - - @Result float[] outVxyz = new float[bodies * 3]; - - static float[] seedXyz = new float[bodies * 3]; - static { - final float maxDist = width / 4; - for (int body = 0; body < (bodies * 3); body += 3) { - final float theta = (float) (Math.random() * Math.PI * 2); - final float phi = (float) (Math.random() * Math.PI * 2); - final float radius = (float) (Math.random() * maxDist); - seedXyz[body + 0] = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - seedXyz[body + 1] = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - seedXyz[body + 2] = (float) (radius * Math.cos(phi)); - } - } - - @Override - public void runTest() { - System.arraycopy(seedXyz, 0, inXyz, 0, seedXyz.length); - Arrays.fill(outXyz, 0f); - Arrays.fill(outVxyz, 0f); - Arrays.fill(inVxyz, 0f); - - // no local copies to make it an instance lambda - - dispatchLambdaKernel(bodies, (gid) -> { - final int count = bodies * 3; - final int globalId = gid * 3; - - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - for (int i = 0; i < count; i += 3) { - final float dx = inXyz[i + 0] - inXyz[globalId + 0]; - final float dy = inXyz[i + 1] - inXyz[globalId + 1]; - final float dz = inXyz[i + 2] - inXyz[globalId + 2]; - final float invDist = (float) (1.0 / (Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr))); - accx += mass * invDist * invDist * invDist * dx; - accy += mass * invDist * invDist * invDist * dy; - accz += mass * invDist * invDist * invDist * dz; - } - accx *= delT; - accy *= delT; - accz *= delT; - outXyz[globalId + 0] = inXyz[globalId + 0] + (inVxyz[globalId + 0] * delT) + (accx * .5f * delT); - outXyz[globalId + 1] = inXyz[globalId + 1] + (inVxyz[globalId + 1] * delT) + (accy * .5f * delT); - outXyz[globalId + 2] = inXyz[globalId + 2] + (inVxyz[globalId + 2] * delT) + (accz * .5f * delT); - - outVxyz[globalId + 0] = inVxyz[globalId + 0] + accx; - outVxyz[globalId + 1] = inVxyz[globalId + 1] + accy; - outVxyz[globalId + 2] = inVxyz[globalId + 2] + accz; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOfNullTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOfNullTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests instanceof operator on a null object. - */ -public class InstanceOfNullTest extends VirtualCallTest { - - @Override - public void runTest() { - setupArrays(); - // change some of the inShapes to null - for (int i = 0; i < NUM; i++) { - if (i % 3 == 0) { - inShapeArray[i] = null; - } - } - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = (inShapeArray[gid] instanceof Circle ? 1.0f : 2.0f); - }); - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - - @Override - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOfTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOfTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests instanceof operator. - */ -public class InstanceOfTest extends VirtualCallTest { - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = (inShapeArray[gid] instanceof Circle ? 1.0f : 2.0f); - }); - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - - @Override - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOopNBodyAccTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOopNBodyAccTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,125 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests Oop NBody calling a method that returns acceleration. - */ -public class InstanceOopNBodyAccTest extends GraalKernelTester { - - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - - static class Body extends com.oracle.graal.compiler.hsail.test.lambda.Body { - - public Body(float x, float y, float z, float m) { - super(x, y, z, m); - } - - public Vec3 computeAcc(Body[] inBodies, float espSqr1, float delT1) { - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - float myPosx = x; - float myPosy = y; - float myPosz = z; - - for (int b = 0; b < inBodies.length; b++) { - float dx = inBodies[b].getX() - myPosx; - float dy = inBodies[b].getY() - myPosy; - float dz = inBodies[b].getZ() - myPosz; - float invDist = 1.0f / (float) Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr1); - float s = inBodies[b].getM() * invDist * invDist * invDist; - accx = accx + (s * dx); - accy = accy + (s * dy); - accz = accz + (s * dz); - } - - // now return acc as a Vec3 - return new Vec3(accx * delT1, accy * delT1, accz * delT1); - } - } - - @Result Body[] inBodies = new Body[bodies]; - @Result Body[] outBodies = new Body[bodies]; - - static Body[] seedBodies = new Body[bodies]; - static { - final float maxDist = width / 4; - for (int body = 0; body < bodies; body++) { - final float theta = (float) (Math.random() * Math.PI * 2); - final float phi = (float) (Math.random() * Math.PI * 2); - final float radius = (float) (Math.random() * maxDist); - float x = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - float y = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - float z = (float) (radius * Math.cos(phi)); - seedBodies[body] = new Body(x, y, z, mass); - } - } - - @Override - public void runTest() { - System.arraycopy(seedBodies, 0, inBodies, 0, seedBodies.length); - for (int b = 0; b < bodies; b++) { - outBodies[b] = new Body(0, 0, 0, mass); - } - // no local copies of arrays so we make it an instance lambda - - dispatchLambdaKernel(bodies, (gid) -> { - Body bin = inBodies[gid]; - Body bout = outBodies[gid]; - Vec3 acc = bin.computeAcc(inBodies, espSqr, delT); - - float myPosx = bin.getX(); - float myPosy = bin.getY(); - float myPosz = bin.getZ(); - bout.setX(myPosx + (bin.getVx() * delT) + (acc.x * .5f * delT)); - bout.setY(myPosy + (bin.getVy() * delT) + (acc.y * .5f * delT)); - bout.setZ(myPosz + (bin.getVz() * delT) + (acc.z * .5f * delT)); - - bout.setVx(bin.getVx() + acc.x); - bout.setVy(bin.getVy() + acc.y); - bout.setVz(bin.getVz() + acc.z); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOopNBodyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/InstanceOopNBodyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests OopStream NBody as an instance lambda. - */ -public class InstanceOopNBodyTest extends GraalKernelTester { - - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - - @Result Body[] inBodies = new Body[bodies]; - - @Result Body[] outBodies = new Body[bodies]; - - static Body[] seedBodies = new Body[bodies]; - static { - final float maxDist = width / 4; - for (int body = 0; body < bodies; body++) { - final float theta = (float) (Math.random() * Math.PI * 2); - final float phi = (float) (Math.random() * Math.PI * 2); - final float radius = (float) (Math.random() * maxDist); - float x = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - float y = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - float z = (float) (radius * Math.cos(phi)); - seedBodies[body] = new Body(x, y, z, mass); - } - } - - @Override - public void runTest() { - System.arraycopy(seedBodies, 0, inBodies, 0, seedBodies.length); - for (int b = 0; b < bodies; b++) { - outBodies[b] = new Body(0, 0, 0, mass); - } - // no local copies of arrays so we make it an instance lambda - - dispatchLambdaKernel(bodies, (gid) -> { - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - Body inb = inBodies[gid]; - Body outb = outBodies[gid]; - float myPosx = inb.getX(); - float myPosy = inb.getY(); - float myPosz = inb.getZ(); - - for (Body b : inBodies) { - final float dx = b.getX() - myPosx; - final float dy = b.getY() - myPosy; - final float dz = b.getZ() - myPosz; - final float invDist = 1.0f / (float) Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr); - final float s = b.getM() * invDist * invDist * invDist; - accx = accx + (s * dx); - accy = accy + (s * dy); - accz = accz + (s * dz); - } - - accx = accx * delT; - accy = accy * delT; - accz = accz * delT; - outb.setX(myPosx + (inb.getVx() * delT) + (accx * .5f * delT)); - outb.setY(myPosy + (inb.getVy() * delT) + (accy * .5f * delT)); - outb.setZ(myPosz + (inb.getVz() * delT) + (accz * .5f * delT)); - - outb.setVx(inb.getVx() + accx); - outb.setVy(inb.getVy() + accy); - outb.setVz(inb.getVz() + accz); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntArrayCopyConjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntArrayCopyConjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a int array where src and dest overlap. - */ -public class IntArrayCopyConjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result int[][] outArray = new int[NUM][MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - for (int j = 0; j < outArray[i].length; j++) { - outArray[i][j] = i + j; - } - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(outArray[gid], 0, outArray[gid], gid % NUM, NUM); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntArrayCopyDisjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntArrayCopyDisjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a int array where src and dest do not overlap. - */ -public class IntArrayCopyDisjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result int[][] outArray = new int[NUM][MAXOUTSIZ]; - int[] inArray = new int[NUM + MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < inArray.length; i++) { - inArray[i] = i; - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(inArray, gid, outArray[gid], 0, MAXOUTSIZ); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntCondMoveTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntCondMoveTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests conditional move of an int value. - */ -public class IntCondMoveTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * (gid > 9 ? 2 : 3); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntFieldAccessTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntFieldAccessTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests accessing an integer field. - */ -public class IntFieldAccessTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - int intField = 7; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - int[] out = outArray; - int[] in = inArray; - dispatchLambdaKernel(NUM, (gid) -> { - out[gid] = in[gid] + intField; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntNegateInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntNegateInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests integer negation. - */ -public class IntNegateInstanceTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = -inArray[gid]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntSquaredInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntSquaredInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests squaring an integer as an instance lambda. - */ -public class IntSquaredInstanceTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * inArray[gid] + 1; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntSquaredStaticTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntSquaredStaticTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests squaring an integer as a static lambda. - */ -public class IntSquaredStaticTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - int[] out = outArray; - int[] in = inArray; - dispatchLambdaKernel(NUM, (gid) -> { - out[gid] = in[gid] * in[gid] + 1; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntToLongTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntToLongTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests conversion an int to a long. - */ -public class IntToLongTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = ((i + 1) * (i % 3 == 0 ? 1 : -1)); - outArray[i] = 99; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntegerObjectCreateTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntegerObjectCreateTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests allocation of an Integer object. - */ -public class IntegerObjectCreateTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public Integer[] outArray = new Integer[NUM]; - public Integer[] inArray = new Integer[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - int val = inArray[gid]; - outArray[gid] = val * val + 1; - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return canHandleObjectAllocation(); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntegerObjectReadTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/IntegerObjectReadTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests reading and unboxing of an Integer object. - */ -public class IntegerObjectReadTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public Integer[] inArray = new Integer[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - int val = inArray[gid]; - outArray[gid] = val * val + 1; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongAdderTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongAdderTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.debug.Debug.*; -import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import com.oracle.graal.debug.*; -import java.util.concurrent.atomic.LongAdder; - -import org.junit.Test; - -/** - * Tests calling LongAdder.add(). - */ -public class LongAdderTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long finalSum; - LongAdder adder = new LongAdder(); - - void setupArrays() { - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - adder.add(gid); - }); - - finalSum = adder.sum(); - } - - // cannot handle node: CurrentJavaThread - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void test() { - try (DebugConfigScope dcs = setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { - testGeneratedHsail(); - } - } - - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void testUsingLambdaMethod() { - try (DebugConfigScope dcs = setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { - testGeneratedHsailUsingLambdaMethod(); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongArrayCopyConjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongArrayCopyConjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a long array where src and dest overlap. - */ -public class LongArrayCopyConjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result long[][] outArray = new long[NUM][MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - for (int j = 0; j < outArray[i].length; j++) { - outArray[i][j] = i + j; - } - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(outArray[gid], 0, outArray[gid], gid % NUM, NUM); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongArrayCopyDisjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongArrayCopyDisjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests copying a long array where src and dest do not overlap. - */ -public class LongArrayCopyDisjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result long[][] outArray = new long[NUM][MAXOUTSIZ]; - long[] inArray = new long[NUM + MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < inArray.length; i++) { - inArray[i] = i; - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(inArray, gid, outArray[gid], 0, MAXOUTSIZ); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongCmpTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongCmpTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests comparing a long to a constant. - */ -public class LongCmpTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - public long[] inArray = new long[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - long val = inArray[gid]; - long result = val * val; - if (val > 9) { - result++; - } - outArray[gid] = result; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongCondMoveTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongCondMoveTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests conditional move of a long value. - */ -public class LongCondMoveTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - public long[] inArray = new long[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * (gid > 9 ? 0x123456789L : 0x123456780L); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongNegateInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongNegateInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests negation of a long. - */ -public class LongNegateInstanceTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - public long[] inArray = new long[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = 0; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = -inArray[gid]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongSquaredInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/LongSquaredInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests squaring of a long as an instance lambda. - */ -public class LongSquaredInstanceTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public long[] outArray = new long[NUM]; - public long[] inArray = new long[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * inArray[gid] + 1; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Main.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Main.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +0,0 @@ -/* - * 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.lambda; - -/** - * a place to put a direct call to a test if you don't want to go thru junit. - */ - -public class Main { - - public static void main(String[] args) { - // new StaticIntFieldAccessTest().test(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MandelInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MandelInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests mandel as an instance lambda. - */ - -public class MandelInstanceTest extends GraalKernelTester { - - static final int WIDTH = 768; - static final int HEIGHT = WIDTH; - static final int maxIterations = 64; - - static final int RANGE = WIDTH * HEIGHT; - @Result public int[] rgb = new int[RANGE]; - int[] palette = new int[256]; - - void setupPalette(int[] in) { - for (int i = 0; i < in.length; i++) { - in[i] = i; - } - } - - @Override - public void runTest() { - setupPalette(palette); - - float xOffset = -1f; - float yOffset = 0f; - float scale = 3f; - - // call it for a range, specifying the lambda - dispatchLambdaKernel(RANGE, (gid) -> { - final int width = WIDTH; - final int height = HEIGHT; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xOffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yOffset; - - int count = 0; - float zx = lx; - float zy = ly; - float newZx = 0f; - - // Iterate until the algorithm converges or until maxIterations are reached. - while (count < maxIterations && zx * zx + zy * zy < 8) { - newZx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newZx; - count++; - } - - rgb[gid] = palette[count]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MandelStaticTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MandelStaticTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests static lambda version of Mandel. - */ -public class MandelStaticTest extends GraalKernelTester { - - static final int WIDTH = 768; - static final int HEIGHT = WIDTH; - static final int maxIterations = 64; - - static final int RANGE = WIDTH * HEIGHT; - @Result public int[] rgb = new int[RANGE]; - - void setupPalette(int[] in) { - for (int i = 0; i < in.length; i++) { - in[i] = i; - } - } - - @Override - public void runTest() { - int[] palette = new int[256]; - setupPalette(palette); - - // since we want this to be a fully static lambda, make local copies - // of the arrays and values that will get captured by the lambda - int[] rgb1 = this.rgb; - float xOffset = -1f; - float yOffset = 0f; - float scale = 3f; - - // call it for a range, specifying lambda - dispatchLambdaKernel(RANGE, (gid) -> { - final int width = WIDTH; - final int height = HEIGHT; - float lx = (((gid % width * scale) - ((scale / 2) * width)) / width) + xOffset; - float ly = (((gid / width * scale) - ((scale / 2) * height)) / height) + yOffset; - - int count = 0; - float zx = lx; - float zy = ly; - float newZx = 0f; - - // Iterate until the algorithm converges or until maxIterations are reached. - while (count < maxIterations && zx * zx + zy * zy < 8) { - newZx = zx * zx - zy * zy + lx; - zy = 2 * zx * zy + ly; - zx = newZx; - count++; - } - - rgb1[gid] = palette[count]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MathTestBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MathTestBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.Scope; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -/** - * Tests call to Math.tan(double). - */ -public abstract class MathTestBase extends GraalKernelTester { - - abstract String getInputString(int idx); - - // standard ulps requirement for these tests is one ULP - @Override - protected int ulpsDelta() { - return 1; - } - - // if logging of DeepEquals is set, override assertDeepEquals to just log all input and output - // with ulps errors if any - @Override - protected void assertDeepEquals(String message, Object expected, Object actual, int ulpsDelta) { - try (Scope s = Debug.scope("DeepEquals")) { - if (Debug.isLogEnabled()) { - if (expected != null && actual != null) { - Class expectedClass = expected.getClass(); - Class actualClass = actual.getClass(); - Assert.assertEquals(message, expectedClass, actualClass); - if (expectedClass.isArray()) { - if (expected instanceof double[]) { - double[] ae = (double[]) expected; - double[] aa = (double[]) actual; - for (int i = 0; i < ae.length; i++) { - double de = ae[i]; - double da = aa[i]; - String ulpsStr = ""; - if (!Double.isNaN(de) && Double.isFinite(de)) { - double absdiff = Math.abs(de - da); - double absdiffUlps = absdiff / Math.ulp(de); - ulpsStr = ", absDiffUlps=" + absdiffUlps; - } - Debug.log(i + "| input=" + getInputString(i) + ", expected=" + de + ", actual=" + da + ulpsStr); - } - return; - } else if (expected instanceof float[]) { - float[] ae = (float[]) expected; - float[] aa = (float[]) actual; - for (int i = 0; i < ae.length; i++) { - float fe = ae[i]; - float fa = aa[i]; - String ulpsStr = ""; - if (!Float.isNaN(fe) && Float.isFinite(fe)) { - float absdiff = Math.abs(fe - fa); - float absdiffUlps = absdiff / Math.ulp(fe); - ulpsStr = ", absDiffUlps=" + absdiffUlps; - } - Debug.log(i + "| input=" + getInputString(i) + ", expected=" + fe + ", actual=" + fa + ulpsStr); - } - return; - } - } - } - } - } - super.assertDeepEquals(message, expected, actual, ulpsDelta); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MoreThanEightArgsOOBTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MoreThanEightArgsOOBTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -import org.junit.*; - -public class MoreThanEightArgsOOBTest extends GraalKernelTester { - - int[] makeIntArray(int size) { - int[] out = new int[size]; - - for (int i = 0; i < size; i++) { - out[i] = 1; - } - return out; - } - - final int rows = 4096; - final int cols = 4096; - final int loops = 1; - - @Result int[] result; - - void innerTest(int[] res, int[] a, int[] b, int[] c, int[] d, int base, int stride) { - final int resCols = a.length; - final int resRows = res.length; - final int limit = resCols - stride; - - dispatchLambdaKernel(resRows, (row) -> { - res[row] = 0; - if (a != null) { - for (int col = base; col < limit; col += 4) { - int p0 = 0; - int p1 = 0; - int p2 = 0; - int p3 = 0; - p0 = a[col] + b[col] + c[col] + d[col] + stride; - p1 = a[col + 1] + b[col + 1] + c[col + 1] + d[col + 1]; - p2 = a[col + 2] + b[col + 2] + c[col + 2] + d[col + 2]; - p3 = a[col + 3] + b[col + 3] + c[col + 3] + d[col + 5000]; - res[row] += p0 + p1 + p2 + p3; - } - } - }); - } - - @Override - public void runTest() { - int[] a; - int[] b; - int[] c; - int[] d; - - result = makeIntArray(rows); - a = makeIntArray(cols); - b = makeIntArray(cols); - c = makeIntArray(cols); - d = makeIntArray(cols); - for (int i = 0; i < loops; i++) { - innerTest(result, a, b, c, d, 0, 4); - } - } - - @Test(expected = ArrayIndexOutOfBoundsException.class) - public void test() { - testGeneratedHsail(); - } - - @Test(expected = ArrayIndexOutOfBoundsException.class) - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MoreThanEightArgsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/MoreThanEightArgsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -import org.junit.*; - -public class MoreThanEightArgsTest extends GraalKernelTester { - - int[] makeIntArray(int size) { - int[] out = new int[size]; - - for (int i = 0; i < size; i++) { - out[i] = 1; - } - return out; - } - - final int rows = 4096; - final int cols = 4096; - final int loops = 2; - - @Result int[] result; - - void innerTest(int[] res, int[] a, int[] b, int[] c, int[] d, int base, int stride) { - final int resCols = a.length; - final int resRows = res.length; - final int limit = resCols - stride; - - dispatchLambdaKernel(resRows, (row) -> { - res[row] = 0; - if (a != null) { - for (int col = base; col < limit; col += 4) { - int p0 = 0; - int p1 = 0; - int p2 = 0; - int p3 = 0; - p0 = a[col] + b[col] + c[col] + d[col] + stride; - p1 = a[col + 1] + b[col + 1] + c[col + 1] + d[col + 1]; - p2 = a[col + 2] + b[col + 2] + c[col + 2] + d[col + 2]; - p3 = a[col + 3] + b[col + 3] + c[col + 3] + d[col + 3]; - res[row] += p0 + p1 + p2 + p3; - } - } - }); - } - - @Override - public void runTest() { - int[] a; - int[] b; - int[] c; - int[] d; - - result = makeIntArray(rows); - a = makeIntArray(cols); - b = makeIntArray(cols); - c = makeIntArray(cols); - d = makeIntArray(cols); - for (int i = 0; i < loops; i++) { - innerTest(result, a, b, c, d, 0, 4); - } - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NewStringEqualsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NewStringEqualsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.debug.Debug.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; -import com.oracle.graal.debug.*; - -/** - * Tests creating a String and calling .equals() on it. - */ -public class NewStringEqualsTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public boolean[] outArray = new boolean[NUM]; - char[] chars = new char[100]; - - void setupArrays() { - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - } - } - - @Override - public void runTest() { - setupArrays(); - String base = "ABCDEFGHIJ"; - - // Resolving StringIndexOutOfBoundsException causes compilation of the - // lambda to fail as. Combined with use of InlineEverything and RemoveNeverExecutedCode - // the inlining budget is blown before String.equals can be inlined leaving - // a DirectCallTargetNode in the graph which cannot be lowered by HSAIL. - new StringIndexOutOfBoundsException().fillInStackTrace(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = new String(chars, 0, 10 + (gid % 3)).equals(base); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - // although not escaping, seems to require object allocation support - return (canHandleObjectAllocation()); - } - - @Ignore("see comment in runTest") - @Test - public void test() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsail(); - } - } - - @Ignore("see comment in runTest") - @Test - public void testUsingLambdaMethod() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsailUsingLambdaMethod(); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NewStringLenTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NewStringLenTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests creating a String and calling .length() on it. - */ -public class NewStringLenTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - char[] chars = new char[100]; - - void setupArrays() { - for (int i = 0; i < chars.length; i++) { - chars[i] = 'A'; - } - for (int i = 0; i < NUM; i++) { - inArray[i] = i + 10; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = Integer.toString(gid).length(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - // although not escaping, seems to require object allocation support - return (canHandleObjectAllocation()); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NonEscapingNewArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NonEscapingNewArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests creating a non-escaping array and using it. - */ -public class NonEscapingNewArrayTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - float[] ary = {gid, gid + 1, gid + 2}; - outArray[gid] = ary[0] * ary[1] * ary[2]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NonEscapingNewObjWithArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NonEscapingNewObjWithArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.debug.Debug.*; -import static com.oracle.graal.debug.DelegatingDebugConfig.Feature.*; - -import java.util.*; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.*; -import com.oracle.graal.debug.*; - -/** - * Tests non-escaping object creation and calling a method on it. - */ -public class NonEscapingNewObjWithArrayTest extends GraalKernelTester { - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - - static class MyObj { - float[] a; - - public MyObj(float[] src, int ofst) { - a = Arrays.copyOfRange(src, ofst, ofst + 3); - } - - public float productOf() { - return a[0] * a[1] * a[2]; - } - } - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - float[] fsrc = new float[2 * NUM]; - for (int i = 0; i < 2 * NUM; i++) { - fsrc[i] = i; - } - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = new MyObj(fsrc, gid).productOf(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - // although not escaping, seems to require object allocation support - return (canHandleObjectAllocation()); - } - - // NYI emitForeignCall floatArraycopy - @Ignore - @Test - public void test() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsail(); - } - } - - @Ignore - @Test - public void testUsingLambdaMethod() { - try (DebugConfigScope dcs = setConfig(new DelegatingDebugConfig().disable(INTERCEPT))) { - testGeneratedHsailUsingLambdaMethod(); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NonEscapingNewTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/NonEscapingNewTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests creation of three non-escaping objects. - */ -public class NonEscapingNewTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, i + 2); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Vec3 veca = inArray[gid]; - Vec3 vecb = inArray[(gid + 1) % NUM]; - Vec3 vecresult = Vec3.add(veca, vecb); - outArray[gid] = vecresult.z; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjArrayCopyConjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjArrayCopyConjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests {@link System#arraycopy} for object arrays where dest and src type are same, and overlap. - */ -public class ObjArrayCopyConjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result String[][] outArray = new String[NUM][MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - for (int j = 0; j < outArray[i].length; j++) { - outArray[i][j] = Integer.toString(i * 100 + j); - } - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(outArray[gid], 0, outArray[gid], gid % NUM, NUM); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjArrayCopyDisjointNonExactTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjArrayCopyDisjointNonExactTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests {@link System#arraycopy} for object arrays where dest is a superclass of src. - */ -public class ObjArrayCopyDisjointNonExactTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result Object[][] outArray = new Object[NUM][MAXOUTSIZ]; - String[] inArray = new String[NUM + MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < inArray.length; i++) { - inArray[i] = Integer.toString(i * 1111); - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(inArray, gid, outArray[gid], 0, MAXOUTSIZ); - }); - } - - // this fails because we do not have a pure java snippet for this case - // see ArrayCopySnippets.arrayCopy(Object, int, Object, int, int) - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjArrayCopyDisjointTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjArrayCopyDisjointTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests {@link System#arraycopy} for object arrays where dest and src type are same, no overlap. - */ -public class ObjArrayCopyDisjointTest extends GraalKernelTester { - - static final int MAXOUTSIZ = 100; - static final int NUM = 20; - - @Result String[][] outArray = new String[NUM][MAXOUTSIZ]; - String[] inArray = new String[NUM + MAXOUTSIZ]; - - @Override - public void runTest() { - for (int i = 0; i < inArray.length; i++) { - inArray[i] = Integer.toString(i * 1111); - } - dispatchLambdaKernel(NUM, (gid) -> { - System.arraycopy(inArray, gid, outArray[gid], 0, MAXOUTSIZ); - }); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectArrayInstanceDerivedTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectArrayInstanceDerivedTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests calling a method on an object when there are derived types of that object. Note: if you - * enable these tests, not only will these tests fail but other tests like ObjectArrayInstanceTest - * will also fail because they depend on there being no derived classes from Body. - */ -public class ObjectArrayInstanceDerivedTest extends GraalKernelTester { - - static final int NUM = 20; - - class DerivedBody extends Body { - - DerivedBody(float x, float y, float z, float m) { - super(x, y, z, m); - } - - @Override - public float getX() { - return 42.0f; - } - } - - @Result public float[] outArray = new float[NUM]; - public Body[] inBodyArray = new Body[NUM]; - public Body[] unusedBodyArray = new Body[NUM]; - public DerivedBody[] unusedDerivedBodyArray = new DerivedBody[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inBodyArray[i] = new Body(i, i + 1, i + 2, i + 3); - // unusedBodyArray[i] = new DerivedBody(i, i+1, i+2, i+3); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Body b = inBodyArray[gid]; - outArray[gid] = b.getX() * b.getY(); - }); - } - - @Ignore - @Test - public void test() { - testGeneratedHsail(); - } - - @Ignore - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectArrayInstanceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectArrayInstanceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -import org.junit.*; - -/** - * Tests calling a method on an object when there are no derived types of that object. - */ -public class ObjectArrayInstanceTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public float[] outArray = new float[NUM]; - public Body[] inBodyArray = new Body[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inBodyArray[i] = new Body(i, i + 1, i + 2, i + 3); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Body b = inBodyArray[gid]; - outArray[gid] = b.getX() * b.getY(); - }); - } - - @Ignore - @Test - public void test() { - testGeneratedHsail(); - } - - @Ignore - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectStoreNullTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectStoreNullTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests the storing of null in an Object array. - */ -public class ObjectStoreNullTest extends ObjectStoreTest { - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outBodyArray[gid] = (gid % 3 == 1 ? null : inBodyArray[gid]); - }); - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - - @Override - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectStoreTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ObjectStoreTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests copying an object from one array to another. - */ -public class ObjectStoreTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Body[] outBodyArray = new Body[NUM]; - public Body[] inBodyArray = new Body[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inBodyArray[i] = new Body(i, i + 1, i + 2, i + 3); - outBodyArray[i] = null; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outBodyArray[gid] = inBodyArray[gid]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/OverloadMethodTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/OverloadMethodTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests calling methods with the same name but different signatures. - */ -public class OverloadMethodTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - int addArgs(int a, int b) { - return a + b; - } - - int addArgs(int a, int b, int c) { - return a + b + c; - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = (gid > 9 ? addArgs(inArray[gid], gid + 1) : addArgs(inArray[gid], gid - 1, gid - 2)); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ReduceMaxTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ReduceMaxTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static org.junit.Assert.*; -import static org.junit.Assume.*; - -import java.util.*; -import java.util.stream.*; - -import org.junit.*; - -import com.amd.okra.*; -import com.oracle.graal.hotspot.*; - -public class ReduceMaxTest { - // The length of the input array - static int jobSize = 1027 * 1023 * 13; - static int loops = 1; - - // The source array - int[] bigArray = null; - - // result for baseline single threaded stream - int resultStream = 0; - // result for parallel CPU and offloaded streams - int resultOffload = 0; - - int evaluate(boolean doParallelStream) { - int result = 0; - for (int i = 0; i < loops; i++) { - IntStream s = Arrays.stream(bigArray); - if (doParallelStream == true) { - OptionalInt resultParallel = s.parallel().reduce(Integer::max); - result = resultParallel.getAsInt(); - } else { - result = s.reduce(Integer::max).getAsInt(); - } - } - return result; - } - - int evaluateWithIdentity(boolean doParallelStream) { - int result = 0; - for (int i = 0; i < loops; i++) { - IntStream s = Arrays.stream(bigArray); - if (doParallelStream == true) { - result = s.parallel().reduce(0, Integer::max); - } else { - result = s.reduce(0, Integer::max); - } - } - return result; - } - - @Test - public void testReduce() { - - // The simulator does not support HSA local memory as of June 2014 - assumeTrue("The simulator does not support HSA local memory, skipping!", OkraUtil.okraLibExists() && OkraContext.isSimulator() == false); - - // Handmade reduce does not support +UseCompressedOops - HotSpotVMConfig config = runtime().getConfig(); - if (config.useCompressedOops == true || config.useHSAILDeoptimization == true) { - return; - } - - bigArray = new int[jobSize]; - for (int i = 0; i < jobSize; i++) { - // bigArray[i] = i + 1; - bigArray[i] = -1024 + i + 1; - } - - // Get non parallel baseline - resultStream = evaluate(false); - - // Get OptionalInt version kernel - resultOffload = evaluate(true); - assertTrue(resultStream == resultOffload); - - // Do identity version kernel - // Get non parallel baseline - resultStream = evaluateWithIdentity(false); - - resultOffload = evaluateWithIdentity(true); - assertTrue(resultStream == resultOffload); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ReduceMinTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ReduceMinTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static org.junit.Assert.*; -import static org.junit.Assume.*; - -import java.util.*; -import java.util.stream.*; - -import org.junit.*; - -import com.amd.okra.*; -import com.oracle.graal.hotspot.*; - -public class ReduceMinTest { - // The length of the input array - static int jobSize = 1027 * 1023 * 13; - static int loops = 1; - - // The input array to the kernel - int[] bigArray = null; - - // result for baseline single threaded stream - int resultStream = 0; - // result for parallel CPU and offloaded streams - int resultOffload = 0; - - int evaluate(boolean doParallelStream) { - int result = 0; - for (int i = 0; i < loops; i++) { - IntStream s = Arrays.stream(bigArray); - if (doParallelStream == true) { - OptionalInt resultParallel = s.parallel().reduce(Integer::min); - result = resultParallel.getAsInt(); - } else { - result = s.reduce(Integer::min).getAsInt(); - } - } - return result; - } - - int evaluateWithIdentity(boolean doParallelStream) { - int result = 0; - for (int i = 0; i < loops; i++) { - IntStream s = Arrays.stream(bigArray); - if (doParallelStream == true) { - result = s.parallel().reduce(0, Integer::min); - } else { - result = s.reduce(0, Integer::min); - } - } - return result; - } - - @Test - public void testReduce() { - - // The simulator does not support HSA local memory as of June 2014 - assumeTrue("The simulator does not support HSA local memory, skipping!", OkraUtil.okraLibExists() && OkraContext.isSimulator() == false); - - // Handmade reduce does not support +UseCompressedOops - HotSpotVMConfig config = runtime().getConfig(); - if (config.useCompressedOops == true || config.useHSAILDeoptimization == true) { - return; - } - - bigArray = new int[jobSize]; - for (int i = 0; i < jobSize; i++) { - bigArray[i] = -1024 + i + 1; - } - - // Get non parallel baseline - resultStream = evaluate(false); - - // Get OptionalInt version kernel - resultOffload = evaluate(true); - assertTrue(resultStream == resultOffload); - - // Do identity version kernel - // Get non parallel baseline - resultStream = evaluateWithIdentity(false); - - resultOffload = evaluateWithIdentity(true); - assertTrue(resultStream == resultOffload); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ReduceSumTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ReduceSumTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static org.junit.Assert.*; -import static org.junit.Assume.*; - -import java.util.*; -import java.util.stream.*; - -import org.junit.*; - -import com.amd.okra.*; -import com.oracle.graal.hotspot.*; - -public class ReduceSumTest { - // The length of the input array - static int jobSize = 1027 * 1023 * 13; - static int loops = 1; - - // The array to be summed - int[] bigArray = null; - - // sum for baseline single threaded stream - int sumStream = 0; - // sum for parallel CPU and offloaded streams - int sumOffload = 0; - - int evaluate(boolean doParallelStream) { - int sum = 0; - for (int i = 0; i < loops; i++) { - IntStream s = Arrays.stream(bigArray); - if (doParallelStream == true) { - OptionalInt resultParallel = s.parallel().reduce(Integer::sum); - sum = resultParallel.getAsInt(); - } else { - OptionalInt resultStream = s.reduce(Integer::sum); - sum = resultStream.getAsInt(); - } - } - return sum; - } - - int evaluateWithIdentity(boolean doParallelStream) { - int sum = 0; - for (int i = 0; i < loops; i++) { - IntStream s = Arrays.stream(bigArray); - if (doParallelStream == true) { - sum = s.parallel().reduce(0, Integer::sum); - } else { - sum = s.reduce(0, Integer::sum); - } - } - return sum; - } - - @Test - public void testReduce() { - - // The simulator does not support HSA local memory as of June 2014 - assumeTrue("The simulator does not support HSA local memory, skipping!", OkraUtil.okraLibExists() && OkraContext.isSimulator() == false); - - // Handmade reduce does not support +UseCompressedOops - HotSpotVMConfig config = runtime().getConfig(); - if (config.useCompressedOops == true || config.useHSAILDeoptimization == true) { - return; - } - - bigArray = new int[jobSize]; - for (int i = 0; i < jobSize; i++) { - bigArray[i] = -1024 + i + 1; - } - - // Get non parallel baseline - sumStream = evaluate(false); - - // Get OptionalInt version kernel - sumOffload = evaluate(true); - assertTrue(sumStream == sumOffload); - - // Get identity version kernel - sumOffload = evaluateWithIdentity(true); - assertTrue(sumStream == sumOffload); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ShortArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/ShortArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests accessing an array of shorts. - */ -public class ShortArrayTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public short[] inArray = new short[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = (short) ((i + 1) * (i % 3 == 0 ? 1 : -1)); - outArray[i] = 99; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid]; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticFloatFieldReadTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticFloatFieldReadTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests reading from a static float field. - */ -public class StaticFloatFieldReadTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - public float[] inArray = new float[NUM]; - - static float floatField = 7.123f; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - float[] out = outArray; - float[] in = inArray; - dispatchLambdaKernel(NUM, (gid) -> { - out[gid] = in[gid] + floatField; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntField2ReadTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntField2ReadTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests reading from a two static int fields in different classes. - */ -public class StaticIntField2ReadTest extends StaticIntFieldReadTest { - - static int intField2 = 8; - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * intField1 + intField2; - }); - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - - @Override - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntFieldReadTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntFieldReadTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests reading from a static int field. - */ -public class StaticIntFieldReadTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - static int intField1 = 7; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] + intField1; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntFieldSameClassTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntFieldSameClassTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests reading from a two static int fields in the same class. - */ -public class StaticIntFieldSameClassTest extends StaticIntFieldReadTest { - - static int myField1 = 5; - static int myField2 = -99; - @Result int fieldResult; - - @Override - public void runTest() { - setupArrays(); - myField2 = -99; - dispatchLambdaKernel(NUM, (gid) -> { - int val = inArray[gid] * myField1; - outArray[gid] = val; - if (gid == 3) { - myField2 = val + gid; - } - }); - fieldResult = myField2; - } - - @Override - @Test - public void test() { - testGeneratedHsail(); - } - - @Override - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntFieldWriteTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticIntFieldWriteTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests writing a static int field. - */ -public class StaticIntFieldWriteTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - @Result int fieldResult; - - static int intStaticField = -99; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - intStaticField = -99; - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid] * 2; - if (gid == 3) { - intStaticField = outArray[gid]; - } - }); - fieldResult = intStaticField; // save for kerneltester comparison - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticNBodyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StaticNBodyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +0,0 @@ -/* - * 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.lambda; - -import java.util.*; -import org.junit.*; -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Tests a static lambda version of nbody. - */ -public class StaticNBodyTest extends GraalKernelTester { - - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - - @Result float[] inXyz = new float[bodies * 3]; // positions xy and z of bodies - - @Result float[] outXyz = new float[bodies * 3]; // positions xy and z of bodies - - @Result float[] inVxyz = new float[bodies * 3]; // velocity component of x,y and z of - // bodies - - @Result float[] outVxyz = new float[bodies * 3]; - - static float[] seedXyz = new float[bodies * 3]; - static { - final float maxDist = width / 4; - for (int body = 0; body < (bodies * 3); body += 3) { - final float theta = (float) (Math.random() * Math.PI * 2); - final float phi = (float) (Math.random() * Math.PI * 2); - final float radius = (float) (Math.random() * maxDist); - seedXyz[body + 0] = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - seedXyz[body + 1] = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - seedXyz[body + 2] = (float) (radius * Math.cos(phi)); - } - } - - @Override - public void runTest() { - System.arraycopy(seedXyz, 0, inXyz, 0, seedXyz.length); - Arrays.fill(outXyz, 0f); - Arrays.fill(outVxyz, 0f); - Arrays.fill(inVxyz, 0f); - - // local copies for a static lambda - float[] inXyz1 = this.inXyz; - float[] outXyz1 = this.outXyz; - float[] inVxyz1 = this.inVxyz; - float[] outVxyz1 = this.outVxyz; - - dispatchLambdaKernel(bodies, (gid) -> { - final int count = bodies * 3; - final int globalId = gid * 3; - - float accx = 0.f; - float accy = 0.f; - float accz = 0.f; - for (int i = 0; i < count; i += 3) { - final float dx = inXyz1[i + 0] - inXyz1[globalId + 0]; - final float dy = inXyz1[i + 1] - inXyz1[globalId + 1]; - final float dz = inXyz1[i + 2] - inXyz1[globalId + 2]; - final float invDist = (float) (1.0 / (Math.sqrt((dx * dx) + (dy * dy) + (dz * dz) + espSqr))); - accx += mass * invDist * invDist * invDist * dx; - accy += mass * invDist * invDist * invDist * dy; - accz += mass * invDist * invDist * invDist * dz; - } - accx *= delT; - accy *= delT; - accz *= delT; - outXyz1[globalId + 0] = inXyz1[globalId + 0] + (inVxyz1[globalId + 0] * delT) + (accx * .5f * delT); - outXyz1[globalId + 1] = inXyz1[globalId + 1] + (inVxyz1[globalId + 1] * delT) + (accy * .5f * delT); - outXyz1[globalId + 2] = inXyz1[globalId + 2] + (inVxyz1[globalId + 2] * delT) + (accz * .5f * delT); - - outVxyz1[globalId + 0] = inVxyz1[globalId + 0] + accx; - outVxyz1[globalId + 1] = inVxyz1[globalId + 1] + accy; - outVxyz1[globalId + 2] = inVxyz1[globalId + 2] + accz; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringBuilderTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringBuilderTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests creating a new String using StringBuilder (relies on {@link System#arraycopy}). - */ -public class StringBuilderTest extends GraalKernelTester { - - static final int NUM = 20; - StringBuilder[] builders = new StringBuilder[NUM]; - @Result String[] resultString = new String[NUM]; - - @Override - public void runTest() { - for (int i = 0; i < NUM; i++) { - builders[i] = new StringBuilder().append(i).append("abc"); - } - dispatchLambdaKernel(NUM, (gid) -> { - resultString[gid] = builders[gid].append(gid * 1234).toString(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleObjectAllocation() && (runningOnSimulator() || runningCQETests())); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringContainsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringContainsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests calling String.contains(). - */ -public class StringContainsTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public boolean[] outArray = new boolean[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, i, 10); - } - } - - @Override - public void runTest() { - setupArrays(); - String base = "CDE"; - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid].contains(base); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringEqualsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringEqualsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests calling String.equals(). - */ -public class StringEqualsTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public boolean[] outArray = new boolean[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, 0, 10 + (i % 3)); - } - } - - @Override - public void runTest() { - setupArrays(); - String base = "ABCDEFGHIJ"; - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid].equals(base); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringHashTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringHashTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests calling String.hashCode(). - */ -public class StringHashTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + i); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, 0, i + 1); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid].hashCode(); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringLenTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringLenTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests calling String.length(). - */ -public class StringLenTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public String[] inArray = new String[NUM]; - - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = 'A'; - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, 0, i + 10); - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid].length(); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringSubsequenceTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringSubsequenceTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests creating a new {@link CharSequence} using {@link String#subSequence(int, int)}. - */ -public class StringSubsequenceTest extends GraalKernelTester { - - static final int NUM = 50; - String inputString; - @Result CharSequence[] resultSequence = new String[NUM]; - - @Override - public void runTest() { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < NUM + 10; i++) { - builder.append(i); - } - inputString = builder.toString(); - dispatchLambdaKernel(NUM, (gid) -> { - resultSequence[gid] = inputString.subSequence(gid, gid + 10); - }); - - // for (int i = 0; i < NUM; i++) { - // System.out.println(resultSequence[i]); - // } - } - - @Ignore("emitDirectCall unimplemented") - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringSubstringTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringSubstringTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2014, 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.*; - -import org.junit.*; - -/** - * Tests creating a new String using {@link String#substring(int, int)}. - */ -public class StringSubstringTest extends GraalKernelTester { - - static final int NUM = 50; - String inputString; - @Result String[] resultString = new String[NUM]; - - @Override - public void runTest() { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < NUM + 10; i++) { - builder.append(i); - } - inputString = builder.toString(); - dispatchLambdaKernel(NUM, (gid) -> { - resultString[gid] = inputString.substring(gid, gid + 10); - }); - } - - @Ignore("emitDirectCall unimplemented") - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringUtilsCountMatches2Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringUtilsCountMatches2Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.compiler.hsail.test.lambda.StringUtilsCountMatchesTest.*; - -import org.junit.*; - -/** - * Tests calling a method similar to {@code StringUtils.countMatches()} from the Apache commons-lang - * library. The second argument varies per workitem. - */ -public class StringUtilsCountMatches2Test extends CountMatchesBase { - @Override - void setupArrays() { - char[] chars = new char[100]; - for (int i = 0; i < chars.length; i++) { - chars[i] = (char) ('A' + (i % 10)); - } - for (int i = 0; i < NUM; i++) { - inArray[i] = new String(chars, i, (i % 5 + 1)); - } - } - - @Override - public void runTest() { - setupArrays(); - String base = "ABCDE BCDEF CDEFG DEFGH EFGHI FGHIJ ABCDE BCDEF CDEFG DEFGH EFGHI FGHIJ "; - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = countMatches(base, inArray[gid]); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringUtilsCountMatchesTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/StringUtilsCountMatchesTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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.lambda; - -import org.junit.*; - -/** - * Tests calling a method similar to {@code StringUtils.countMatches()} from the Apache commons-lang - * library. The first argument varies per workitem. - */ -public class StringUtilsCountMatchesTest extends CountMatchesBase { - - public static int countMatches(String str, String sub) { - if (isEmpty(str) || isEmpty(sub)) { - return 0; - } - int count = 0; - int idx = 0; - while ((idx = str.indexOf(sub, idx)) != -1) { - count++; - idx += sub.length(); - } - return count; - } - - private static boolean isEmpty(String str) { - return str == null || str.length() == 0; - } - - @Override - public void runTest() { - setupArrays(); - String base = "CDE"; - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = countMatches(inArray[gid], base); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/SynchronizedMethodTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/SynchronizedMethodTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * 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.lambda; - -import static com.oracle.graal.debug.Debug.*; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import com.oracle.graal.debug.*; - -import org.junit.Test; - -/** - * Tests calling a synchronized method. - */ -public class SynchronizedMethodTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - synchronized int syncSquare(int n) { - return n * n; - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = syncSquare(inArray[gid]); - }); - } - - // cannot handle the BeginLockScope node - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void test() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsail(); - } - } - - // cannot handle the BeginLockScope node - @Test(expected = com.oracle.graal.compiler.common.GraalInternalError.class) - public void testUsingLambdaMethod() { - try (DebugConfigScope s = disableIntercept()) { - testGeneratedHsailUsingLambdaMethod(); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/TooSimpleNewTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/TooSimpleNewTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests a very simple non-escaping object allocation. - */ -public class TooSimpleNewTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public float[] outArray = new float[NUM]; - public float[] inArray = new float[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - float inval = inArray[gid]; - Vec3 vec3 = new Vec3(inval + 1, inval + 2, inval + 3); - outArray[gid] = vec3.x; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/TwoDIntArrayTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/TwoDIntArrayTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests reading from a 2-D int array. - */ -public class TwoDIntArrayTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[][] inArray = new int[NUM][NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - for (int j = 0; j < NUM; j++) { - inArray[i][j] = i * j; - } - outArray[i] = -i; - } - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = inArray[gid][gid] + 100; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VarArgsTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VarArgsTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; - -/** - * Tests calling a varargs method. - */ -public class VarArgsTest extends GraalKernelTester { - - static final int NUM = 20; - @Result public int[] outArray = new int[NUM]; - public int[] inArray = new int[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = i; - outArray[i] = -i; - } - } - - int addArgs(Object... args) { - int sum = 0; - for (Object n : args) { - sum += (Integer) n; - } - return sum; - } - - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - outArray[gid] = (gid > 9 ? addArgs(gid, gid + 1, gid + 2) : addArgs(inArray[gid], gid - 1, gid - 2, gid - 3)); - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamFloatCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamFloatCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests codegen for a java 8 lambda style object array stream kernel, one float capture. - */ -public class Vec3ObjStreamFloatCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - float baseAdjustment = 0.5f; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - @Override - public void runTest() { - setupArrays(); - float adjustment = baseAdjustment; - dispatchLambdaKernel(inArray, obj -> { - Vec3 vec3 = (Vec3) obj; - vec3.z = vec3.x + vec3.y - adjustment; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamIntCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamIntCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests codegen for a java 8 style object array stream kernel, one int capture. - */ -public class Vec3ObjStreamIntCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - int baseAdjustment = 7; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - @Override - public void runTest() { - setupArrays(); - int adjustment = baseAdjustment; - dispatchLambdaKernel(inArray, obj -> { - Vec3 vec3 = (Vec3) obj; - vec3.z = vec3.x + vec3.y - adjustment; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamIntFloatCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamIntFloatCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests codegen for a java 8 style object array stream kernel, one int and one float capture. - */ -public class Vec3ObjStreamIntFloatCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - int baseAdjustment = 7; - float baseMultiplier = 0.5f; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - @Override - public void runTest() { - setupArrays(); - int adjustment = baseAdjustment; - float multiplier = baseMultiplier; - - dispatchLambdaKernel(inArray, obj -> { - Vec3 vec3 = (Vec3) obj; - vec3.z = (vec3.x + vec3.y - adjustment) * multiplier; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamObjCaptureTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamObjCaptureTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests codegen for a java 8 lambda style object array stream kernel, one object capture. - */ -public class Vec3ObjStreamObjCaptureTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - float baseAdjustment = 0.5f; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - @Override - public void runTest() { - setupArrays(); - Vec3 basevec = new Vec3(1, 2, 3); - dispatchLambdaKernel(inArray, obj -> { - Vec3 vec3 = (Vec3) obj; - vec3.z = vec3.x + vec3.y - basevec.z; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamObjFieldTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamObjFieldTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests codegen for a java 8 style object array stream kernel. Instance method which accesses an - * object field. - */ -public class Vec3ObjStreamObjFieldTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - Vec3 basevec = new Vec3(1, 2, 3); - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(inArray, obj -> { - Vec3 vec3 = (Vec3) obj; - vec3.z = vec3.x + vec3.y - basevec.z; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/Vec3ObjStreamTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import org.junit.Test; -import com.oracle.graal.compiler.hsail.test.Vec3; - -/** - * Tests codegen for a java 8 style object array stream kernel, no captures. - */ -public class Vec3ObjStreamTest extends GraalKernelTester { - - static final int NUM = 20; - - @Result public Vec3[] inArray = new Vec3[NUM]; - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - inArray[i] = new Vec3(i, i + 1, -1); - } - } - - @Override - public void runTest() { - setupArrays(); - dispatchLambdaKernel(inArray, obj -> { - Vec3 vec3 = (Vec3) obj; - vec3.z = vec3.x + vec3.y; - }); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VecmathNBodyDeoptTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VecmathNBodyDeoptTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,138 +0,0 @@ -/* - * 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.lambda; - -import java.util.*; -import org.junit.*; -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import javax.vecmath.*; - -/** - * Tests NBody algorithm using the javax.vecmath package (all objects non-escaping). - */ -public class VecmathNBodyDeoptTest extends GraalKernelTester { - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - - static class Body extends Vector3f { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public Body(float x, float y, float z, float m) { - super(x, y, z); - this.m = m; - this.v = new Vector3f(0, 0, 0); - } - - float m; - Vector3f v; - - public float getM() { - return m; - } - - public Vector3f computeAcc(Body[] inBodies, float espSqr1, float delT1) { - Vector3f acc = new Vector3f(); - - for (Body b : inBodies) { - Vector3f d = new Vector3f(); - d.sub(b, this); - float invDist = 1.0f / (float) Math.sqrt(d.lengthSquared() + espSqr1); - float s = b.getM() * invDist * invDist * invDist; - acc.scaleAdd(s, d, acc); - } - - // now return acc scaled by delT - acc.scale(delT1); - return acc; - } - } - - @Result Body[] inBodies = new Body[bodies]; - @Result Body[] outBodies = new Body[bodies]; - - static Body[] seedBodies = new Body[bodies]; - - static { - java.util.Random randgen = new Random(0); - final float maxDist = width / 4; - for (int body = 0; body < bodies; body++) { - final float theta = (float) (randgen.nextFloat() * Math.PI * 2); - final float phi = (float) (randgen.nextFloat() * Math.PI * 2); - final float radius = randgen.nextFloat() * maxDist; - float x = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - float y = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - float z = (float) (radius * Math.cos(phi)); - seedBodies[body] = new Body(x, y, z, mass); - } - } - - @Override - public void runTest() { - System.arraycopy(seedBodies, 0, inBodies, 0, seedBodies.length); - for (int b = 0; b < bodies; b++) { - outBodies[b] = new Body(0, 0, 0, mass); - } - // no local copies of arrays so we make it an instance lambda - - dispatchLambdaKernel(bodies, (gid) -> { - Body inb = inBodies[gid]; - Body outb = outBodies[gid]; - Vector3f acc = inb.computeAcc(inBodies, espSqr, delT); - - Vector3f tmpPos = new Vector3f(); - tmpPos.scaleAdd(delT, inb.v, inb); - if (gid == bodies / 2) { - tmpPos.x += forceDeopt(gid); - } - tmpPos.scaleAdd(0.5f * delT, acc, tmpPos); - outb.set(tmpPos); - - outb.v.add(inb.v, acc); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleDeoptVirtualObjects() && canDeoptimize()); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VecmathNBodyTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VecmathNBodyTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -/* - * 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.lambda; - -import java.util.*; -import org.junit.*; -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; -import javax.vecmath.*; - -/** - * Tests NBody algorithm using the javax.vecmath package (all objects non-escaping). - */ -public class VecmathNBodyTest extends GraalKernelTester { - static final int bodies = 1024; - static final float delT = .005f; - static final float espSqr = 1.0f; - static final float mass = 5f; - static final int width = 768; - static final int height = 768; - - static class Body extends Vector3f { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public Body(float x, float y, float z, float m) { - super(x, y, z); - this.m = m; - this.v = new Vector3f(0, 0, 0); - } - - float m; - Vector3f v; - - public float getM() { - return m; - } - - public Vector3f computeAcc(Body[] inBodies, float espSqr1, float delT1) { - Vector3f acc = new Vector3f(); - - for (Body b : inBodies) { - Vector3f d = new Vector3f(); - d.sub(b, this); - float invDist = 1.0f / (float) Math.sqrt(d.lengthSquared() + espSqr1); - float s = b.getM() * invDist * invDist * invDist; - acc.scaleAdd(s, d, acc); - } - - // now return acc scaled by delT - acc.scale(delT1); - return acc; - } - } - - @Result Body[] inBodies = new Body[bodies]; - @Result Body[] outBodies = new Body[bodies]; - - static Body[] seedBodies = new Body[bodies]; - - static { - java.util.Random randgen = new Random(0); - final float maxDist = width / 4; - for (int body = 0; body < bodies; body++) { - final float theta = (float) (randgen.nextFloat() * Math.PI * 2); - final float phi = (float) (randgen.nextFloat() * Math.PI * 2); - final float radius = randgen.nextFloat() * maxDist; - float x = (float) (radius * Math.cos(theta) * Math.sin(phi)) + width / 2; - float y = (float) (radius * Math.sin(theta) * Math.sin(phi)) + height / 2; - float z = (float) (radius * Math.cos(phi)); - seedBodies[body] = new Body(x, y, z, mass); - } - } - - @Override - public void runTest() { - System.arraycopy(seedBodies, 0, inBodies, 0, seedBodies.length); - for (int b = 0; b < bodies; b++) { - outBodies[b] = new Body(0, 0, 0, mass); - } - // no local copies of arrays so we make it an instance lambda - - dispatchLambdaKernel(bodies, (gid) -> { - Body inb = inBodies[gid]; - Body outb = outBodies[gid]; - Vector3f acc = inb.computeAcc(inBodies, espSqr, delT); - - Vector3f tmpPos = new Vector3f(); - tmpPos.scaleAdd(delT, inb.v, inb); - tmpPos.scaleAdd(0.5f * delT, acc, tmpPos); - outb.set(tmpPos); - - outb.v.add(inb.v, acc); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return (canHandleDeoptVirtualObjects()); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VectorStreamTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VectorStreamTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/* - * 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.lambda; - -import java.util.Vector; -import java.util.stream.Stream; -import static org.junit.Assert.assertTrue; -import org.junit.Test; - -/** - * Sumatra API tests which use a Stream derived from a Vector. - */ -public class VectorStreamTest { - - // Static and instance fields to test codegen for - // each type of variable - static int staticSize = 16; - final int size = staticSize; - - static int staticFactor = 3; - final int factor = staticFactor; - - class MyPoint { - - int x; - int y; - - public MyPoint(int x, int y) { - this.x = x; - this.y = y; - } - } - - public Vector buildMyPointInputArray() { - Vector inputs = new Vector<>(size); - - for (int i = 0; i < size; i++) { - inputs.add(new MyPoint(i, i + 1)); - } - return inputs; - } - - public int[] buildIntInputArray() { - int[] inputs = new int[size]; - - for (int i = 0; i < size; i++) { - inputs[i] = i * 4; - } - return inputs; - } - - @Test - public void testForEachObjectStreamNoCaptures() { - Vector inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - // Swap the values - int tmp = p.x; - p.x = p.y + factor; - p.y = tmp; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.x == (p.y + 1 + factor)); - } - } - - @Test - public void testForEachObjectStreamNoCapturesUseStatic() { - Vector inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - // Swap the values - int tmp = p.x; - p.x = p.y + staticFactor; - p.y = tmp; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.x == (p.y + 1 + staticFactor)); - } - } - - @Test - public void testForEachObjectStreamOneCapture() { - int[] data = buildIntInputArray(); - Vector inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x]; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x]); - } - - } - - @Test - public void testForEachObjectStreamOneCaptureUseStatic() { - int[] data = buildIntInputArray(); - Vector inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x] + staticFactor; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == (data[p.x] + +staticFactor)); - } - - } - - @Test - public void testForEachObjectStreamTwoCaptures() { - int[] data = buildIntInputArray(); - int[] data2 = buildIntInputArray(); - Vector inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x] + data2[p.x]; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x] + data2[p.x]); - } - - } - - @Test - public void testForEachObjectStreamTwoCapturesUseStatic() { - int[] data = buildIntInputArray(); - int[] data2 = buildIntInputArray(); - Vector inputs = buildMyPointInputArray(); - - Stream s = inputs.stream(); - s = s.parallel(); - s.forEach(p -> { - p.y = data[p.x] + data2[p.x] + staticFactor; - }); - - for (int k = 0; k < size; k++) { - MyPoint p = inputs.get(k); - // System.out.println( k + " ... p.x=" + p.x ); - assertTrue(p.y == data[p.x] + data2[p.x] + staticFactor); - } - - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCall3Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCall3Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests a true virtual method call with 3 targets. - */ -public class VirtualCall3Test extends VirtualCallBase { - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - inShapeArray[i] = createShape(i % 3, i + 1); - } - } - - // although runTest is the same in each class derived from VirtualCallBase - // we duplicate the logic in each derived test so as to have different lambda call sites - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Shape shape = inShapeArray[gid]; - outArray[gid] = shape.getArea(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return typeProfileWidthAtLeast(3); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCall4Test.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCall4Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests a true virtual method call with 4 targets. - */ -public class VirtualCall4Test extends VirtualCallBase { - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - inShapeArray[i] = createShape(i % 4, i + 1); - } - } - - // although runTest is the same in each class derived from VirtualCallBase - // we duplicate the logic in each derived test so as to have different lambda call sites - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Shape shape = inShapeArray[gid]; - outArray[gid] = shape.getArea(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return typeProfileWidthAtLeast(4); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCallBase.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCallBase.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -/* - * 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.lambda; - -import com.oracle.graal.compiler.hsail.test.infra.GraalKernelTester; - -/** - * Base class for testing virtual method calls. - */ -public abstract class VirtualCallBase extends GraalKernelTester { - - static final int NUM = 20000; - - @Result public float[] outArray = new float[NUM]; - public Shape[] inShapeArray = new Shape[NUM]; - - abstract static class Shape { - - public abstract float getArea(); - } - - static class Circle extends Shape { - - private float radius; - - Circle(float r) { - radius = r; - } - - @Override - public float getArea() { - return (float) (Math.PI * radius * radius); - } - } - - static class Square extends Shape { - - private float len; - - Square(float len) { - this.len = len; - } - - @Override - public float getArea() { - return len * len; - } - } - - static class Triangle extends Shape { - - private float base; - private float height; - - Triangle(float base, float height) { - this.base = base; - this.height = height; - } - - @Override - public float getArea() { - return (base * height / 2.0f); - } - } - - static class Rectangle extends Shape { - - private float base; - private float height; - - Rectangle(float base, float height) { - this.base = base; - this.height = height; - } - - @Override - public float getArea() { - return (base * height); - } - } - - Shape createShape(int kind, int size) { - switch (kind) { - case 0: - return new Circle(size); - case 1: - return new Square(size); - case 2: - return new Triangle(size, size + 1); - case 3: - return new Rectangle(size, size + 1); - default: - return null; - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCallTest.java --- a/graal/com.oracle.graal.compiler.hsail.test/src/com/oracle/graal/compiler/hsail/test/lambda/VirtualCallTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -/* - * 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.lambda; - -import org.junit.Test; - -/** - * Tests a true virtual method call with 2 targets. - */ -public class VirtualCallTest extends VirtualCallBase { - - void setupArrays() { - for (int i = 0; i < NUM; i++) { - outArray[i] = -i; - int kind = i % 3 == 0 ? 0 : 1; - inShapeArray[i] = createShape(kind, i + 1); - } - } - - // although runTest is the same in each class derived from VirtualCallBase - // we duplicate the logic in each derived test so as to have different lambda call sites - @Override - public void runTest() { - setupArrays(); - - dispatchLambdaKernel(NUM, (gid) -> { - Shape shape = inShapeArray[gid]; - outArray[gid] = shape.getArea(); - }); - } - - @Override - protected boolean supportsRequiredCapabilities() { - return typeProfileWidthAtLeast(2); - } - - @Test - public void test() { - testGeneratedHsail(); - } - - @Test - public void testUsingLambdaMethod() { - testGeneratedHsailUsingLambdaMethod(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/CompileAndDispatch.java --- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/CompileAndDispatch.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2009, 2011, 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; - -/** - * Interface for compiling a Java program to HSAIL and dispatching execution to the GPU or an HSAIL - * simulator. - */ -public interface CompileAndDispatch { - - Object createKernel(Class consumerClass); - - boolean dispatchKernel(Object kernel, int jobSize, Object[] args); - - Object createKernelFromHsailString(String code, String methodName); - - String getIntegerReduceIntrinsic(String reducerName); - - Integer offloadIntReduceImpl(Object kernel, int identity, int[] streamSource); - - String getIntReduceTargetName(Class opClass); -} diff -r c8fc6e2d128b -r 8f2fb6bec986 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 Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,874 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.hsail.HSAILArithmetic.*; -import static com.oracle.graal.lir.hsail.HSAILBitManipulationOp.IntrinsicOpcode.*; -import static com.oracle.graal.lir.hsail.HSAILCompare.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.compiler.common.spi.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.JumpOp; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.hsail.*; -import com.oracle.graal.lir.hsail.HSAILArithmetic.ConvertOp; -import com.oracle.graal.lir.hsail.HSAILArithmetic.Op1Reg; -import com.oracle.graal.lir.hsail.HSAILArithmetic.Op2Reg; -import com.oracle.graal.lir.hsail.HSAILArithmetic.ShiftOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.CompareBranchOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.CondMoveOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.FloatCondMoveOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.ReturnOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.StrategySwitchOp; -import com.oracle.graal.lir.hsail.HSAILMove.LeaOp; -import com.oracle.graal.lir.hsail.HSAILMove.MembarOp; -import com.oracle.graal.lir.hsail.HSAILMove.MoveFromRegOp; -import com.oracle.graal.lir.hsail.HSAILMove.MoveToRegOp; -import com.oracle.graal.phases.util.*; - -/** - * This class implements the HSAIL specific portion of the LIR generator. - */ -public abstract class HSAILLIRGenerator extends LIRGenerator { - - public class HSAILSpillMoveFactory implements LIR.SpillMoveFactory { - - @Override - public LIRInstruction createMove(AllocatableValue dst, Value src) { - return HSAILLIRGenerator.this.createMove(dst, src); - } - } - - public HSAILLIRGenerator(LIRKindTool lirKindTool, Providers providers, CallingConvention cc, LIRGenerationResult lirGenRes) { - super(lirKindTool, providers, cc, lirGenRes); - lirGenRes.getLIR().setSpillMoveFactory(new HSAILSpillMoveFactory()); - } - - @Override - public boolean canInlineConstant(JavaConstant c) { - switch (c.getKind()) { - case Long: - return NumUtil.isInt(c.asLong()) && !getCodeCache().needsDataPatch(c); - case Object: - return c.isNull(); - default: - return true; - } - } - - protected HSAILLIRInstruction createMove(AllocatableValue dst, Value src) { - if (src instanceof HSAILAddressValue) { - return new LeaOp(dst, (HSAILAddressValue) src); - } else if (isRegister(src) || isStackSlotValue(dst)) { - return new MoveFromRegOp(dst.getKind(), dst, src); - } else { - return new MoveToRegOp(dst.getKind(), dst, src); - } - } - - @Override - public void emitMove(AllocatableValue dst, Value src) { - append(createMove(dst, src)); - } - - public void emitData(AllocatableValue dst, byte[] data) { - throw GraalInternalError.unimplemented(); - } - - public HSAILAddressValue asAddressValue(Value address) { - if (address instanceof HSAILAddressValue) { - return (HSAILAddressValue) address; - } else { - return emitAddress(address, 0, Value.ILLEGAL, 0); - } - } - - public HSAILAddressValue emitAddress(Value base, long displacement, Value index, int scale) { - AllocatableValue baseRegister; - long finalDisp = displacement; - - if (isConstant(base)) { - if (asConstant(base).isNull()) { - baseRegister = Value.ILLEGAL; - } else if (asConstant(base).getKind() != Kind.Object) { - finalDisp += asConstant(base).asLong(); - baseRegister = Value.ILLEGAL; - } else { - baseRegister = load(base); - } - } else if (base.equals(Value.ILLEGAL)) { - baseRegister = Value.ILLEGAL; - } else { - baseRegister = asAllocatable(base); - } - if (!index.equals(Value.ILLEGAL)) { - if (isConstant(index)) { - finalDisp += asConstant(index).asLong() * scale; - } else { - Value indexRegister; - Value convertedIndex = index.getKind() == Kind.Long ? index : this.emitSignExtend(index, 32, 64); - if (scale != 1) { - indexRegister = emitUMul(convertedIndex, JavaConstant.forInt(scale)); - } else { - indexRegister = convertedIndex; - } - if (baseRegister.equals(Value.ILLEGAL)) { - baseRegister = asAllocatable(indexRegister); - } else { - baseRegister = emitAdd(baseRegister, indexRegister, false); - } - } - } - - LIRKind resultKind = getAddressKind(base, displacement, index); - return new HSAILAddressValue(resultKind, baseRegister, finalDisp); - } - - @Override - public Variable emitAddress(StackSlotValue address) { - throw GraalInternalError.unimplemented(); - } - - @Override - public void emitJump(LabelRef label) { - append(new JumpOp(label)); - } - - public static HSAILCompare mapKindToCompareOp(Kind kind) { - switch (kind) { - case Int: - return ICMP; - case Long: - return LCMP; - case Float: - return FCMP; - case Double: - return DCMP; - case Object: - return ACMP; - default: - throw GraalInternalError.shouldNotReachHere("" + kind); - } - } - - @Override - public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, - double trueDestinationProbability) { - // We don't have to worry about mirroring the condition on HSAIL. - Condition finalCondition = cond; - Variable result = newVariable(left.getLIRKind()); - Kind kind = left.getKind().getStackKind(); - switch (kind) { - case Int: - case Long: - case Object: - append(new CompareBranchOp(mapKindToCompareOp(kind), finalCondition, left, right, result, result, trueDestination, falseDestination, false)); - break; - case Float: - case Double: - append(new CompareBranchOp(mapKindToCompareOp(kind), finalCondition, left, right, result, result, trueDestination, falseDestination, unorderedIsTrue)); - break; - default: - throw GraalInternalError.shouldNotReachHere("" + left.getKind()); - } - } - - @Override - public void emitOverflowCheckBranch(LabelRef overflow, LabelRef noOverflow, LIRKind cmpLIRKind, double overflowProbability) { - throw GraalInternalError.unimplemented(); - } - - @Override - public void emitIntegerTestBranch(Value left, Value right, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) { - Variable result = emitAnd(left, right); - Variable dummyResult = newVariable(left.getLIRKind()); - append(new CompareBranchOp(mapKindToCompareOp(result.getKind()), Condition.EQ, result, JavaConstant.forInt(0), dummyResult, dummyResult, trueDestination, falseDestination, false)); - } - - @Override - public Variable emitIntegerTestMove(Value left, Value right, Value trueValue, Value falseValue) { - Variable result = emitAnd(left, right); - append(new CondMoveOp(mapKindToCompareOp(result.getKind()), result, JavaConstant.forInt(0), result, Condition.EQ, load(trueValue), load(falseValue))); - return result; - } - - @Override - public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) { - Condition finalCondition = cond; - Variable result = newVariable(trueValue.getLIRKind()); - Kind kind = left.getKind().getStackKind(); - switch (kind) { - case Int: - case Long: - case Object: - append(new CondMoveOp(mapKindToCompareOp(kind), load(left), load(right), result, finalCondition, load(trueValue), load(falseValue))); - break; - case Float: - case Double: - append(new FloatCondMoveOp(mapKindToCompareOp(kind), load(left), load(right), result, finalCondition, unorderedIsTrue, load(trueValue), load(falseValue))); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + left.getKind()); - } - return result; - } - - /** - * 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(LIRKind.derive(input)); - 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 Op1Reg(INEG, result, input)); - break; - case Long: - append(new Op1Reg(LNEG, result, input)); - break; - case Double: - append(new Op1Reg(DNEG, result, input)); - break; - case Float: - append(new Op1Reg(FNEG, result, input)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - - } - - /** - * 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(LIRKind.derive(input)); - 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 Op1Reg(INOT, result, input)); - break; - case Long: - append(new Op1Reg(LNOT, result, input)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - - } - - public Variable emitTestAddressAdd(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IADD, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LADD, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Reg(FADD, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Reg(DADD, result, a, loadNonConst(b))); - break; - case Object: - throw GraalInternalError.shouldNotReachHere(); - default: - throw GraalInternalError.shouldNotReachHere(); - } - - return result; - } - - @Override - public Variable emitAdd(Value a, Value b, boolean setFlags) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IADD, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LADD, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Reg(FADD, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Reg(DADD, result, a, loadNonConst(b))); - break; - case Object: - append(new Op2Reg(OADD, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitSub(Value a, Value b, boolean setFlags) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(ISUB, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Reg(FSUB, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LSUB, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Reg(DSUB, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitMul(Value a, Value b, boolean setFlags) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IMUL, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LMUL, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Reg(FMUL, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Reg(DMUL, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - public Variable emitUMul(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(LUMUL, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LUMUL, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Value emitMulHigh(Value a, Value b) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitUMulHigh(Value a, Value b) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitDiv(Value a, Value b, LIRFrameState state) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IDIV, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LDIV, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Reg(FDIV, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Reg(DDIV, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - - } - - @Override - public Value emitRem(Value a, Value b, LIRFrameState state) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IREM, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LREM, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Reg(FREM, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Reg(DREM, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitUDiv(Value a, Value b, LIRFrameState state) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Variable emitURem(Value a, Value b, LIRFrameState state) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Variable emitAnd(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IAND, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LAND, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitOr(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IOR, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LOR, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitXor(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IXOR, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LXOR, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - 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(LIRKind.derive(a, b).changeType(a.getPlatformKind())); - 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: - append(new ShiftOp(LSHL, result, a, b)); - break; - default: - GraalInternalError.shouldNotReachHere(); - } - 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) { - Variable result = newVariable(LIRKind.derive(a, b).changeType(a.getPlatformKind())); - 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(LIRKind.derive(a, b).changeType(a.getPlatformKind())); - switch (a.getKind()) { - case Int: - append(new ShiftOp(IUSHR, result, a, b)); - break; - case Long: - append(new ShiftOp(LUSHR, result, a, b)); - break; - default: - GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Value emitFloatConvert(FloatConvert op, Value inputVal) { - Variable input = load(inputVal); - - String from; - switch (op) { - case D2F: - case D2I: - case D2L: - from = "f64"; - break; - case F2D: - case F2I: - case F2L: - from = "f32"; - break; - case I2D: - case I2F: - from = "s32"; - break; - case L2D: - case L2F: - from = "s64"; - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - - Variable result; - String to; - switch (op) { - case D2I: - case F2I: - to = "s32"; - result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Int)); - break; - case D2L: - case F2L: - to = "s64"; - result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Long)); - break; - case F2D: - case I2D: - case L2D: - to = "f64"; - result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Double)); - break; - case D2F: - case I2F: - case L2F: - to = "f32"; - result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Float)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - - append(new ConvertOp(result, input, to, from)); - return result; - } - - @Override - public Value emitNarrow(Value inputVal, int bits) { - Variable input = load(inputVal); - Variable result = newVariable(LIRKind.derive(inputVal).changeType(bits > 32 ? Kind.Long : Kind.Int)); - append(new ConvertOp(result, input, "s" + bits, input.getKind() == Kind.Long ? "s64" : "s32")); - return result; - } - - @Override - public Value emitSignExtend(Value inputVal, int fromBits, int toBits) { - Variable input = load(inputVal); - Variable result = newVariable(LIRKind.derive(inputVal).changeType(toBits > 32 ? Kind.Long : Kind.Int)); - append(new ConvertOp(result, input, "s" + toBits, "s" + fromBits)); - return result; - } - - @Override - public Value emitZeroExtend(Value inputVal, int fromBits, int toBits) { - Variable input = load(inputVal); - Variable result = newVariable(LIRKind.derive(inputVal).changeType(toBits > 32 ? Kind.Long : Kind.Int)); - append(new ConvertOp(result, input, "u" + toBits, "u" + fromBits)); - return result; - } - - @Override - public Value emitReinterpret(LIRKind to, Value inputVal) { - Variable result = newVariable(to); - emitMove(result, inputVal); - return result; - } - - @Override - public void emitDeoptimize(Value actionAndReason, Value speculation, LIRFrameState state) { - append(new ReturnOp(Value.ILLEGAL)); - } - - @Override - public void emitMembar(int barriers) { - int necessaryBarriers = target().arch.requiredBarriers(barriers); - append(new MembarOp(necessaryBarriers)); - } - - @Override - public Value emitBitCount(Value value) { - Variable result = newVariable(LIRKind.derive(value).changeType(Kind.Int)); - if (value.getKind().getStackKind() == Kind.Int) { - append(new HSAILBitManipulationOp(IPOPCNT, result, value)); - } else { - append(new HSAILBitManipulationOp(LPOPCNT, result, value)); - } - return result; - } - - @Override - public Value emitBitScanForward(Value value) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitBitScanReverse(Value value) { - throw GraalInternalError.unimplemented(); - } - - /** - * Emits the LIR code for the {@link HSAILArithmetic#ABS} operation. - * - * @param input the source operand - * @return Value representing the result of the operation - */ - @Override - public Value emitMathAbs(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - append(new Op1Reg(ABS, result, input)); - return result; - } - - /** - * Emits the LIR code for the {@link HSAILArithmetic#CEIL} operation. - * - * @param input the source operand - * @return Value representing the result of the operation - */ - public Value emitMathCeil(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - append(new Op1Reg(CEIL, result, input)); - return result; - } - - /** - * Emits the LIR code for the {@link HSAILArithmetic#FLOOR} operation. - * - * @param input the source operand - * @return Value representing the result of the operation - */ - public Value emitMathFloor(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - append(new Op1Reg(FLOOR, result, input)); - return result; - } - - /** - * Emits the LIR code for the {@link HSAILArithmetic#RINT} operation. - * - * @param input the source operand - * @return Value representing the result of the operation - */ - public Value emitMathRint(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - append(new Op1Reg(RINT, result, input)); - return result; - } - - /** - * Emits the LIR code for the {@link HSAILArithmetic#SQRT} operation. - * - * @param input the source operand - * @return value representing the result of the operation - */ - @Override - public Value emitMathSqrt(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - append(new Op1Reg(SQRT, result, input)); - return result; - } - - @Override - public Value emitMathLog(Value input, boolean base10) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitMathCos(Value input) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitMathSin(Value input) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitMathTan(Value input) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitByteSwap(Value input) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitArrayEquals(Kind kind, Value array1, Value array2, Value length) { - // TODO Auto-generated method stub - throw GraalInternalError.unimplemented(); - } - - @Override - public void emitReturn(Value input) { - AllocatableValue operand = Value.ILLEGAL; - if (input != null) { - operand = resultOperandFor(input.getLIRKind()); - emitMove(operand, input); - } - append(new ReturnOp(operand)); - } - - /** - * This routine handles the LIR code generation for switch nodes by calling - * emitSequentialSwitch. - * - * This routine overrides LIRGenerator.emitSwitch( ) which calls emitSequentialSwitch or - * emitTableSwitch based on a heuristic. - * - * The recommended approach in HSAIL for generating performant code for switch statements is to - * emit a series of cascading compare and branches. Thus this routines always calls - * emitSequentialSwitch, which implements this approach. - * - * Note: Only IntegerSwitchNodes are currently supported. The IntegerSwitchNode is the node that - * Graal generates for any switch construct appearing in Java bytecode. - */ - @Override - public void emitStrategySwitch(JavaConstant[] keyConstants, double[] keyProbabilities, LabelRef[] keyTargets, LabelRef defaultTarget, Variable value) { - emitStrategySwitch(new SwitchStrategy.SequentialStrategy(keyProbabilities, keyConstants), value, keyTargets, defaultTarget); - } - - /** - * Generates the LIR instruction for a switch construct that is meant to be assembled into a - * series of cascading compare and branch instructions. This is currently the recommended way of - * generating performant HSAIL code for switch constructs. - * - * @param strategy the strategy used for this switch. - * @param keyTargets array of branch targets for each of the cases. - * @param defaultTarget the branch target for the default case. - * @param key the key that is compared against the key constants in the case statements. - */ - @Override - public void emitStrategySwitch(SwitchStrategy strategy, Variable key, LabelRef[] keyTargets, LabelRef defaultTarget) { - switch (key.getKind()) { - case Int: - case Long: - case Object: - // Append the LIR instruction for generating compare and branch instructions. - append(new StrategySwitchOp(strategy, keyTargets, defaultTarget, key)); - break; - default: - // Throw an exception if the key kind is anything else. - throw GraalInternalError.unimplemented("Switch statements not supported for keys of type " + key.getKind()); - } - } - - @Override - protected void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key) { - throw GraalInternalError.unimplemented(); - } - - @Override - public void emitUnwind(Value operand) { - throw GraalInternalError.unimplemented(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILNodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILNodeLIRBuilder.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.gen.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.nodes.*; - -/** - * This class implements the HSAIL specific portion of the LIR generator. - */ -public abstract class HSAILNodeLIRBuilder extends NodeLIRBuilder { - - public HSAILNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) { - super(graph, lirGen); - } - - @Override - protected boolean peephole(ValueNode valueNode) { - // No peephole optimizations for now. - return false; - } - - @Override - protected void emitDirectCall(DirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { - throw GraalInternalError.unimplemented(callTarget.targetMethod().format("direct call to %H.%n(%p)")); - } - - @Override - protected void emitIndirectCall(IndirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { - throw GraalInternalError.unimplemented(callTarget.targetMethod().format("direct call to %H.%n(%p)")); - } - - @Override - public void visitBreakpointNode(BreakpointNode node) { - throw GraalInternalError.unimplemented(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ArrayPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.ptx.test; - -import static com.oracle.graal.lir.ptx.ThreadDimension.*; - -import org.junit.*; - -import com.oracle.graal.lir.ptx.*; - -public class ArrayPTXTest extends PTXTest { - - @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented") - @Test - public void test1() { - test("testStoreArray1I", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2); - } - - @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented") - @Test - public void test2() { - test("testStoreArrayWarp0", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2); - } - - @Ignore("PTXHotSpotForeignCallsProvider.lookupForeignCall() is unimplemented") - @Test - public void test3() { - test("testStoreArrayWarp1I", new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9}, 2); - } - - public static void testStoreArray1I(int[] array, int i) { - array[i] = 42; - } - - public static void testStoreArrayWarp0(int[] array, @Warp(dimension = X) int i) { - array[i] = 42; - } - - public static void testStoreArrayWarp1I(@ParallelOver(dimension = X) int[] array, @Warp(dimension = X) int i) { - array[i] = 42; - } - - public static void main(String[] args) { - compileAndPrintCode(new ArrayPTXTest()); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/BasicPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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.ptx.test; - -import static org.junit.Assert.*; - -import org.junit.*; - -/** - * Test class for small Java methods compiled to PTX kernels. - */ -public class BasicPTXTest extends PTXTest { - - @Test - public void test() { - test("testConstI"); - } - - public static int testConstI() { - return 42; - } - - @Test - public void testStaticIntKernel() { - test("staticIntKernel", 'a', 42); - } - - public static int staticIntKernel(char p0, int p1) { - return p1 + p0; - } - - @Test - public void testVirtualIntKernel() { - test("virtualIntKernel", 'a', 42); - } - - public int virtualIntKernel(char p0, int p1) { - return p1 + p0; - } - - @Test - public void testGetAvailableProcessors() { - assertTrue(getPTXBackend().getAvailableProcessors() >= 0); - } - - public static void main(String[] args) { - compileAndPrintCode(new BasicPTXTest()); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ControlPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,151 +0,0 @@ -/* - * 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.ptx.test; - -import org.junit.*; - -public class ControlPTXTest extends PTXTest { - - @Test - public void testControl1() { - test("testLoop", 42); - test("testSwitchDefault1I", 3); - test("testSwitch1I", 2); - test("testIfElse1I", 222); - test("testIfElse2I", 19, 64); - } - - @Ignore("PTXHotSpotLIRGenerator.emitCompress is unimplemented") - @Test - public void testControl2() { - compileKernel("testStatic"); - compileKernel("testCall"); - } - - @Ignore("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options") - @Test - public void testControl3() { - // test("testIntegerTestBranch2I", 0xff00, 0x00ff); - compileKernel("testIntegerTestBranch2I"); - compileKernel("testLookupSwitch1I"); - } - - public static boolean testIntegerTestBranch2I(int x, int y) { - return (x & y) == 0; - } - - public static int testLoop(int n) { - int sum = 0; - - for (int i = 0; i < n; i++) { - sum++; - } - return sum; - } - - public static int testIfElse1I(int n) { - if (n > 22) { - return 42; - } else { - return -42; - } - } - - public static int testIfElse2I(int c, int y) { - if (c > 19) { - return 'M'; // millenial - } else if (y > 84) { - return 'Y'; // young - } else { - return 'O'; // old - } - } - - public static int testSwitchDefault1I(int a) { - switch (a) { - default: - return 4; - } - } - - public static int testSwitch1I(int a) { - switch (a) { - case 1: - return 2; - case 2: - return 3; - default: - return 4; - } - } - - public static int testLookupSwitch1I(int a) { - switch (a) { - case 0: - return 10; - case 1: - return 11; - case 2: - return 12; - case 3: - return 13; - case 4: - return 14; - case 5: - return 15; - case 6: - return 16; - case 7: - return 17; - case 8: - return 18; - case 9: - return 19; - case 10: - return 20; - case 11: - return 21; - default: - return 42; - } - } - - @SuppressWarnings("unused") private static Object foo = null; - - public static boolean testStatic(Object o) { - foo = o; - return true; - } - - private static int method(int a, int b) { - return a + b; - } - - public static int testCall(int a, int b) { - return method(a, b); - } - - public static void main(String[] args) { - compileAndPrintCode(new ControlPTXTest()); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/FloatPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,237 +0,0 @@ -/* - * 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.ptx.test; - -import org.junit.*; - -/* PTX ISA 3.1 - 8.7.3 Floating-Point Instructions */ -public class FloatPTXTest extends PTXTest { - - @Test - public void testAdd() { - test("testAdd2I", 42, 43); - test("testAdd2F", 42.1F, 43.5F); - test("testAddFConst", 42.1F); - test("testAdd2D", 42.1, 43.5); - } - - public static float testAdd2I(int a, int b) { - return a + b; - } - - public static float testAdd2F(float a, float b) { - return (a + b); - } - - public static double testAdd2D(double a, double b) { - return a + b; - } - - public static float testAddFConst(float a) { - return a + 32.0F; - } - - public static float testAddConstF(float a) { - return 32.0F + a; - } - - public static double testAddDConst(double a) { - return a + 32.0; - } - - public static double testAddConstD(double a) { - return 32.0 + a; - } - - @Test - public void testSub() { - compileKernel("testSub2F"); - compileKernel("testSub2D"); - compileKernel("testSubFConst"); - compileKernel("testSubConstF"); - compileKernel("testSubDConst"); - compileKernel("testSubConstD"); - } - - public static float testSub2F(float a, float b) { - return a - b; - } - - public static double testSub2D(double a, double b) { - return a - b; - } - - public static float testSubFConst(float a) { - return a - 32.0F; - } - - public static float testSubConstF(float a) { - return 32.0F - a; - } - - public static double testSubDConst(double a) { - return a - 32.0; - } - - public static double testSubConstD(double a) { - return 32.0 - a; - } - - @Ignore("[CUDA] *** Error (209) Failed to load module data with online compiler options for method testMul2F") - @Test - public void testMul() { - compileKernel("testMul2F"); - compileKernel("testMul2D"); - compileKernel("testMulFConst"); - compileKernel("testMulConstF"); - compileKernel("testMulDConst"); - compileKernel("testMulConstD"); - } - - public static float testMul2F(float a, float b) { - return a * b; - } - - public static double testMul2D(double a, double b) { - return a * b; - } - - public static float testMulFConst(float a) { - return a * 32.0F; - } - - public static float testMulConstF(float a) { - return 32.0F * a; - } - - public static double testMulDConst(double a) { - return a * 32.0; - } - - public static double testMulConstD(double a) { - return 32.0 * a; - } - - @Ignore("[CUDA] *** Error (209) Failed to load module data with online compiler options for method testDiv2F") - @Test - public void testDiv() { - compileKernel("testDiv2F"); - compileKernel("testDiv2D"); - compileKernel("testDivFConst"); - compileKernel("testDivConstF"); - compileKernel("testDivDConst"); - compileKernel("testDivConstD"); - } - - public static float testDiv2F(float a, float b) { - return a / b; - } - - public static double testDiv2D(double a, double b) { - return a / b; - } - - public static float testDivFConst(float a) { - return a / 32.0F; - } - - public static float testDivConstF(float a) { - return 32.0F / a; - } - - public static double testDivDConst(double a) { - return a / 32.0; - } - - public static double testDivConstD(double a) { - return 32.0 / a; - } - - @Test - public void testNeg() { - compileKernel("testNeg2F"); - compileKernel("testNeg2D"); - } - - public static float testNeg2F(float a) { - return -a; - } - - public static double testNeg2D(double a) { - return -a; - } - - @Ignore("need linkage to PTX remainder") - @Test - public void testRem() { - compileKernel("testRem2F"); - compileKernel("testRem2D"); - } - - public static float testRem2F(float a, float b) { - return a % b; - } - - public static double testRem2D(double a, double b) { - return a % b; - } - - @Ignore("[CUDA] *** Error (209) Failed to load module data with online compiler options for method testF2I") - @Test - public void testFloatConversion() { - compileKernel("testF2I"); - compileKernel("testF2L"); - compileKernel("testF2D"); - compileKernel("testD2I"); - compileKernel("testD2L"); - compileKernel("testD2F"); - } - - public static int testF2I(float a) { - return (int) a; - } - - public static long testF2L(float a) { - return (long) a; - } - - public static double testF2D(float a) { - return a; - } - - public static int testD2I(double a) { - return (int) a; - } - - public static long testD2L(double a) { - return (long) a; - } - - public static float testD2F(double a) { - return (float) a; - } - - public static void main(String[] args) { - compileAndPrintCode(new FloatPTXTest()); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/IntegerPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -/* - * 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.ptx.test; - -import java.io.*; -import java.lang.reflect.*; - -import org.junit.*; - -public class IntegerPTXTest extends PTXTest { - - @Test - public void testAdd() { - test("testAdd2B", (byte) 6, (byte) 4); - test("testAdd2I", 18, 24); - test("testAdd2L", (long) 12, (long) 6); - test("testAddIConst", 5); - test("testAddConstI", 7); - } - - public static int testAdd2I(int a, int b) { - return a + b; - } - - public static long testAdd2L(long a, long b) { - return a + b; - } - - public static int testAdd2B(byte a, byte b) { - return a + b; - } - - public static int testAddIConst(int a) { - return a + 32; - } - - public static int testAddConstI(int a) { - return 32 + a; - } - - @Test - public void testSub() { - test("testSub2I", 18, 4); - test("testSub2L", (long) 12, (long) 6); - test("testSubIConst", 35); - test("testSubConstI", 12); - } - - public static int testSub2I(int a, int b) { - return a - b; - } - - public static long testSub2L(long a, long b) { - return a - b; - } - - public static int testSubIConst(int a) { - return a - 32; - } - - public static int testSubConstI(int a) { - return 32 - a; - } - - @Test - public void testMul() { - test("testMul2I", 8, 4); - test("testMul2L", (long) 12, (long) 6); - test("testMulIConst", 4); - test("testMulConstI", 5); - } - - public static int testMul2I(int a, int b) { - return a * b; - } - - public static long testMul2L(long a, long b) { - return a * b; - } - - public static int testMulIConst(int a) { - return a * 32; - } - - public static int testMulConstI(int a) { - return 32 * a; - } - - @Test - public void testDiv() { - test("testDiv2I", 8, 4); - test("testDiv2L", (long) 12, (long) 6); - test("testDivIConst", 64); - test("testDivConstI", 8); - } - - public static int testDiv2I(int a, int b) { - return a / b; - } - - public static long testDiv2L(long a, long b) { - return a / b; - } - - public static int testDivIConst(int a) { - return a / 32; - } - - public static int testDivConstI(int a) { - return 32 / a; - } - - @Test - public void testRem() { - test("testRem2I", 8, 4); - test("testRem2L", (long) 12, (long) 6); - } - - public static int testRem2I(int a, int b) { - return a % b; - } - - public static long testRem2L(long a, long b) { - return a % b; - } - - @Ignore - @Test - public void testIntConversion() { - test("testI2L", 8); - test("testL2I", (long) 12); - // test("testI2C", 65); - // test("testI2B", 9); - // test("testI2F", 17); - // test("testI2D", 22); - } - - public static long testI2L(int a) { - return a; - } - - public static char testI2C(int a) { - return (char) a; - } - - public static byte testI2B(int a) { - return (byte) a; - } - - public static float testI2F(int a) { - return a; - } - - public static double testI2D(int a) { - return a; - } - - public static int testL2I(long a) { - return (int) a; - } - - public static void main(String[] args) { - IntegerPTXTest test = new IntegerPTXTest(); - for (Method m : IntegerPTXTest.class.getMethods()) { - String name = m.getName(); - if (m.getAnnotation(Test.class) == null && name.startsWith("test")) { - PrintStream out = System.out; - out.println(name + ": \n" + new String(test.compileKernel(name).getTargetCode())); - } - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/LogicPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,127 +0,0 @@ -/* - * 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.ptx.test; - -import org.junit.*; - -/* PTX ISA 3.1 - 8.7.5 Logic and Shift Instructions */ -public class LogicPTXTest extends PTXTest { - - @Test - public void testAnd() { - compileKernel("testAnd2I"); - compileKernel("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() { - compileKernel("testOr2I"); - compileKernel("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() { - compileKernel("testXor2I"); - compileKernel("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() { - compileKernel("testNot1I"); - compileKernel("testNot1L"); - } - - public static int testNot1I(int a) { - return ~a; - } - - public static long testNot1L(long a) { - return ~a; - } - - @Test - public void testShiftLeft() { - compileKernel("testShiftLeft2I"); - compileKernel("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() { - compileKernel("testShiftRight2I"); - compileKernel("testShiftRight2L"); - compileKernel("testUnsignedShiftRight2I"); - // compileKernel("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) { - compileAndPrintCode(new LogicPTXTest()); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ObjectPTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/ObjectPTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,164 +0,0 @@ -/* - * 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.ptx.test; - -import java.util.*; - -import org.junit.*; - -public class ObjectPTXTest extends PTXTest { - - static class A { - boolean z = true; - byte b = 17; - char c = 'D'; - short s = 12345; - int i = 0x1234565; - long l; - Object o; - float f; - double d; - } - - @Test - public void test0() { - for (long l : new long[]{Long.MIN_VALUE, -10, 0, 1, 2, 10, Long.MAX_VALUE}) { - A a = new A(); - a.l = l; - test("testLong", l * 2, a); - } - } - - public static long testLong(long l, A a) { - return a.l + l; - } - - @Test - public void test1() { - for (int i : new int[]{Integer.MIN_VALUE, -10, 0, 1, 2, 10, Integer.MAX_VALUE}) { - A a = new A(); - a.i = i; - test("testInt", i * 2, a); - } - } - - public static int testInt(int i, A a) { - return a.i + i; - } - - @Ignore("com.oracle.graal.graph.GraalInternalError: should not reach here: unhandled register type v3|z") - @Test - public void test2() { - A a = new A(); - a.z = true; - test("testBoolean", a); - a.z = false; - test("testBoolean", a); - } - - public static boolean testBoolean(A a) { - return a.z; - } - - @Ignore("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options") - @Test - public void test3() { - for (byte b : new byte[]{Byte.MIN_VALUE, -10, 0, 1, 2, 10, Byte.MAX_VALUE}) { - A a = new A(); - a.b = b; - test("testByte", b, a); - } - } - - public static int testByte(byte b, A a) { - return a.b + b; - } - - @Ignore("com.oracle.graal.graph.GraalInternalError: should not reach here: unhandled register type v5|s") - @Test - public void test4() { - for (short s : new short[]{Short.MIN_VALUE, -10, 0, 1, 2, 10, Short.MAX_VALUE}) { - A a = new A(); - a.s = s; - test("testShort", s, a); - } - } - - public static int testShort(short s, A a) { - return a.s + s; - } - - @Ignore("java.lang.AssertionError: expected:<65531> but was:<809107451>") - @Test - public void test5() { - for (char c : new char[]{Character.MIN_VALUE, 1, 2, 10, Character.MAX_VALUE}) { - A a = new A(); - a.c = c; - test("testChar", (char) (c - 5), a); - } - } - - public static int testChar(char c, A a) { - return a.c + c; - } - - @Test - public void test6() { - for (float f : new float[]{Float.MIN_VALUE, Float.MIN_NORMAL, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NaN, -11.45F, -0.0F, 0.0F, 2, 10, Float.MAX_VALUE}) { - A a = new A(); - a.f = f; - test("testFloat", f * 2, a); - } - } - - public static float testFloat(float f, A a) { - return a.f + f; - } - - @Test - public void test7() { - for (double d : new double[]{Double.MIN_VALUE, Double.MIN_NORMAL, Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, -11.45D, -0.0D, 0.0D, 2, 10, Double.MAX_VALUE}) { - A a = new A(); - a.d = d; - test("testDouble", d * 2, a); - } - } - - public static double testDouble(double d, A a) { - return a.d + d; - } - - @Ignore("Object return values not yet supported") - @Test - public void test9() { - for (Object o : new Object[]{null, "object", new Object(), new HashMap<>()}) { - A a = new A(); - a.o = o; - test("testObject", a); - } - } - - public static Object testObject(A a) { - return a.o; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXMethodInvalidation1Test.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXMethodInvalidation1Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * 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.ptx.test; - -import org.junit.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.gpu.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.ptx.*; - -/** - * Tests that a {@linkplain PTXWrapperBuilder PTX kernel wrapper} deoptimizes if the kernel is - * invalid. - */ -public class PTXMethodInvalidation1Test extends PTXTest { - - @Test - public void test() { - test("testSnippet", 100); - } - - @Override - protected HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) { - HotSpotNmethod ptxKernel = super.installKernel(method, ptxCode); - ptxKernel.invalidate(); - return ptxKernel; - } - - int f = 42; - - public int testSnippet(int delta) { - return f + delta; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXMethodInvalidation2Test.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXMethodInvalidation2Test.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * 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.ptx.test; - -import java.lang.ref.*; - -import org.junit.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.ptx.*; -import com.oracle.graal.nodes.*; - -/** - * A full GC on HotSpot will unload an nmethod that contains an embedded oop which is the only - * reference to its referent. The nmethod created for a {@linkplain PTXWrapperBuilder PTX kernel - * wrapper} has an embedded oop referring to a {@link HotSpotNmethod} object associated with the - * nmethod for the installed PTX kernel. This embedded oop is a weak reference as described above so - * there must be another strong reference from the wrapper to the {@link HotSpotNmethod} object. - */ -public class PTXMethodInvalidation2Test extends PTXTest { - - @Test - public void test() { - test("testSnippet", 100); - } - - @Override - protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph graph) { - InstalledCode code = super.getCode(method, graph); - - // Try hard to force a full GC - int attempts = 0; - WeakReference ref = new WeakReference<>(new Object()); - while (ref.get() != null) { - System.gc(); - // Give up after 1000 attempts - Assume.assumeTrue("Giving up after too many attempts!", ++attempts < 1000); - } - - Assert.assertFalse(code.getStart() == 0L); - return code; - } - - int f = 42; - - public int testSnippet(int delta) { - return f + delta; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java --- a/graal/com.oracle.graal.compiler.ptx.test/src/com/oracle/graal/compiler/ptx/test/PTXTest.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2011, 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.ptx.test; - -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; - -import java.io.*; -import java.lang.reflect.*; - -import org.junit.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.target.*; -import com.oracle.graal.compiler.test.*; -import com.oracle.graal.gpu.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.ptx.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.ptx.*; - -/** - * Base class for PTX tests. - */ -public abstract class PTXTest extends GraalCompilerTest { - - public static PTXHotSpotBackend getPTXBackend() { - Backend backend = runtime().getBackend(PTX.class); - Assume.assumeTrue("No PTX backend, skipping test!", backend instanceof PTXHotSpotBackend); - return (PTXHotSpotBackend) backend; - } - - protected ExternalCompilationResult compileKernel(ResolvedJavaMethod method) { - return getPTXBackend().compileKernel(method, getPTXBackend().isDeviceInitialized()); - } - - protected ExternalCompilationResult compileKernel(String test) { - return compileKernel(getResolvedJavaMethod(test)); - } - - protected HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) { - PTXHotSpotBackend ptxBackend = getPTXBackend(); - return ptxBackend.installKernel(method, ptxCode); - } - - @Override - protected InstalledCode getCode(ResolvedJavaMethod installedCodeOwner, StructuredGraph graph) { - PTXHotSpotBackend ptxBackend = getPTXBackend(); - ExternalCompilationResult ptxCode = compileKernel(installedCodeOwner); - Assume.assumeTrue("Skipping PTX test: device not initialized!", ptxBackend.isDeviceInitialized()); - HotSpotNmethod installedPTXCode = installKernel(installedCodeOwner, ptxCode); - StructuredGraph wrapper = new PTXWrapperBuilder(installedCodeOwner, installedPTXCode, (HotSpotProviders) getProviders()).getGraph(); - - // The PTX C++ layer expects a 1:1 relationship between kernel compilation - // and kernel execution as it creates a cuContext in the former and - // destroys it in the latter. So, each kernel installed requires a unique - // wrapper. - // TODO: do cuContext management properly - boolean forceCompile = true; - - return getCode(installedCodeOwner, wrapper, forceCompile); - } - - protected static void compileAndPrintCode(PTXTest test) { - for (Method m : test.getClass().getMethods()) { - String name = m.getName(); - if (m.getAnnotation(Test.class) == null && name.startsWith("test")) { - PrintStream out = System.out; - out.println(name + ": \n" + new String(test.compileKernel(name).getTargetCode())); - } - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java --- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,883 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.ptx; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.ptx.PTXArithmetic.*; -import static com.oracle.graal.lir.ptx.PTXBitManipulationOp.IntrinsicOpcode.*; -import static com.oracle.graal.lir.ptx.PTXCompare.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.compiler.common.spi.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.JumpOp; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.ptx.*; -import com.oracle.graal.lir.ptx.PTXArithmetic.ConvertOp; -import com.oracle.graal.lir.ptx.PTXArithmetic.Op1Stack; -import com.oracle.graal.lir.ptx.PTXArithmetic.Op2Reg; -import com.oracle.graal.lir.ptx.PTXArithmetic.Op2Stack; -import com.oracle.graal.lir.ptx.PTXArithmetic.ShiftOp; -import com.oracle.graal.lir.ptx.PTXCompare.CompareOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.BranchOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.CondMoveOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.FloatCondMoveOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.ReturnNoValOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.ReturnOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.StrategySwitchOp; -import com.oracle.graal.lir.ptx.PTXControlFlow.TableSwitchOp; -import com.oracle.graal.lir.ptx.PTXMemOp.LoadOp; -import com.oracle.graal.lir.ptx.PTXMemOp.LoadParamOp; -import com.oracle.graal.lir.ptx.PTXMemOp.LoadReturnAddrOp; -import com.oracle.graal.lir.ptx.PTXMemOp.StoreOp; -import com.oracle.graal.lir.ptx.PTXMemOp.StoreReturnValOp; -import com.oracle.graal.lir.ptx.PTXMove.MoveFromRegOp; -import com.oracle.graal.lir.ptx.PTXMove.MoveToRegOp; -import com.oracle.graal.phases.util.*; - -/** - * This class implements the PTX specific portion of the LIR generator. - */ -public class PTXLIRGenerator extends LIRGenerator { - - // Number of the predicate register that can be used when needed. - // This value will be recorded and incremented in the LIR instruction - // that sets a predicate register. (e.g., CompareOp) - private int nextPredRegNum; - - public static final ForeignCallDescriptor ARITHMETIC_FREM = new ForeignCallDescriptor("arithmeticFrem", float.class, float.class, float.class); - public static final ForeignCallDescriptor ARITHMETIC_DREM = new ForeignCallDescriptor("arithmeticDrem", double.class, double.class, double.class); - - public static class PTXSpillMoveFactory implements LIR.SpillMoveFactory { - - @Override - public LIRInstruction createMove(AllocatableValue result, Value input) { - throw GraalInternalError.unimplemented("PTXSpillMoveFactory.createMove()"); - } - } - - public PTXLIRGenerator(LIRKindTool lirKindTool, Providers providers, CallingConvention cc, LIRGenerationResult lirGenRes) { - super(lirKindTool, providers, cc, lirGenRes); - lirGenRes.getLIR().setSpillMoveFactory(new PTXSpillMoveFactory()); - int callVariables = cc.getArgumentCount() + (cc.getReturn().equals(Value.ILLEGAL) ? 0 : 1); - lirGenRes.getLIR().setFirstVariableNumber(callVariables); - nextPredRegNum = 0; - } - - public int getNextPredRegNumber() { - return nextPredRegNum; - } - - @Override - public boolean canInlineConstant(JavaConstant c) { - switch (c.getKind()) { - case Long: - return NumUtil.isInt(c.asLong()) && !getCodeCache().needsDataPatch(c); - case Object: - return c.isNull(); - default: - return true; - } - } - - public Variable emitWarpParam(Kind kind, Warp annotation) { - Variable result = newVariable(target().getLIRKind(kind)); - Variable tid = newVariable(LIRKind.value(Kind.Char)); - - switch (annotation.dimension()) { - case X: - tid.setName("%tid.x"); - break; - case Y: - tid.setName("%tid.y"); - break; - case Z: - tid.setName("%tid.y"); - break; - } - emitMove(result, tid); - - return result; - } - - @Override - public void emitMove(AllocatableValue dst, Value src) { - if (isRegister(src) || isStackSlotValue(dst)) { - append(new MoveFromRegOp(dst, src)); - } else { - append(new MoveToRegOp(dst, src)); - } - } - - @Override - public void emitData(AllocatableValue dst, byte[] data) { - throw GraalInternalError.unimplemented(); - } - - @Override - public PTXAddressValue emitAddress(Value base, long displacement, Value index, int scale) { - AllocatableValue baseRegister; - long finalDisp = displacement; - - if (isConstant(base)) { - if (asConstant(base).isNull()) { - baseRegister = Value.ILLEGAL; - } else if (asConstant(base).getKind() != Kind.Object && !getCodeCache().needsDataPatch(asConstant(base))) { - finalDisp += asConstant(base).asLong(); - baseRegister = Value.ILLEGAL; - } else { - baseRegister = load(base); - } - } else if (base.equals(Value.ILLEGAL)) { - baseRegister = Value.ILLEGAL; - } else { - baseRegister = asAllocatable(base); - } - - if (!index.equals(Value.ILLEGAL)) { - if (isConstant(index)) { - finalDisp += asConstant(index).asLong() * scale; - } else { - Value convertedIndex; - Value indexRegister; - - convertedIndex = emitSignExtend(index, 32, 64); - if (scale != 1) { - if (CodeUtil.isPowerOf2(scale)) { - indexRegister = emitShl(convertedIndex, JavaConstant.forInt(CodeUtil.log2(scale))); - } else { - indexRegister = emitMul(convertedIndex, JavaConstant.forInt(scale), false); - } - } else { - indexRegister = convertedIndex; - } - if (baseRegister.equals(Value.ILLEGAL)) { - baseRegister = asAllocatable(indexRegister); - } else { - Variable longBaseRegister = newVariable(LIRKind.derivedReference(Kind.Long)); - emitMove(longBaseRegister, baseRegister); - baseRegister = emitAdd(longBaseRegister, indexRegister, false); - } - } - } - - LIRKind resultKind = getAddressKind(base, displacement, index); - return new PTXAddressValue(resultKind, baseRegister, finalDisp); - } - - private PTXAddressValue asAddress(Value address) { - assert address != null; - - if (address instanceof PTXAddressValue) { - return (PTXAddressValue) address; - } else { - return emitAddress(address, 0, Value.ILLEGAL, 0); - } - } - - @Override - public Variable emitLoad(LIRKind kind, Value address, LIRFrameState state) { - PTXAddressValue loadAddress = asAddress(address); - Variable result = newVariable(kind); - append(new LoadOp((Kind) kind.getPlatformKind(), result, loadAddress, state)); - return result; - } - - @Override - public void emitStore(LIRKind kind, Value address, Value inputVal, LIRFrameState state) { - PTXAddressValue storeAddress = asAddress(address); - Variable input = load(inputVal); - append(new StoreOp((Kind) kind.getPlatformKind(), storeAddress, input, state)); - } - - @Override - public Variable emitAddress(StackSlotValue address) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitAddress()"); - } - - @Override - public void emitJump(LabelRef label) { - append(new JumpOp(label)); - } - - @Override - public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, - double trueDestinationProbability) { - switch (left.getKind().getStackKind()) { - case Int: - append(new CompareOp(ICMP, cond, left, right, nextPredRegNum)); - append(new BranchOp(cond, trueDestination, falseDestination, nextPredRegNum++)); - break; - case Long: - append(new CompareOp(LCMP, cond, left, right, nextPredRegNum)); - append(new BranchOp(cond, trueDestination, falseDestination, nextPredRegNum++)); - break; - case Float: - append(new CompareOp(FCMP, cond, left, right, nextPredRegNum)); - append(new BranchOp(cond, trueDestination, falseDestination, nextPredRegNum++)); - break; - case Double: - append(new CompareOp(DCMP, cond, left, right, nextPredRegNum)); - append(new BranchOp(cond, trueDestination, falseDestination, nextPredRegNum++)); - break; - case Object: - append(new CompareOp(ACMP, cond, left, right, nextPredRegNum)); - append(new BranchOp(cond, trueDestination, falseDestination, nextPredRegNum++)); - break; - default: - throw GraalInternalError.shouldNotReachHere("" + left.getKind()); - } - } - - @Override - public void emitOverflowCheckBranch(LabelRef overflow, LabelRef noOverflow, LIRKind cmpLIRKind, double overflowProbability) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitOverflowCheckBranch()"); - } - - @Override - public void emitIntegerTestBranch(Value left, Value right, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) { - // / emitIntegerTest(left, right); - // append(new BranchOp(negated ? Condition.NE : Condition.EQ, label)); - throw GraalInternalError.unimplemented("emitIntegerTestBranch()"); - } - - @Override - public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) { - - Condition finalCondition = LIRValueUtil.isVariable(right) ? cond.mirror() : cond; - - emitCompare(finalCondition, left, right); - - Variable result = newVariable(trueValue.getLIRKind()); - switch (left.getKind().getStackKind()) { - case Int: - case Long: - case Object: - append(new CondMoveOp(result, finalCondition, load(trueValue), loadNonConst(falseValue), nextPredRegNum)); - nextPredRegNum++; - break; - case Float: - case Double: - append(new FloatCondMoveOp(result, finalCondition, unorderedIsTrue, load(trueValue), load(falseValue), nextPredRegNum)); - nextPredRegNum++; - break; - default: - throw GraalInternalError.shouldNotReachHere("" + left.getKind()); - } - return result; - } - - /** - * This method emits the compare instruction, and may reorder the operands. It returns true if - * it did so. - * - * @param a the left operand of the comparison - * @param b the right operand of the comparison - * @return true if the left and right operands were switched, false otherwise - */ - private boolean emitCompare(Condition cond, Value a, Value b) { - Variable left; - Value right; - boolean mirrored; - if (LIRValueUtil.isVariable(b)) { - left = load(b); - right = loadNonConst(a); - mirrored = true; - } else { - left = load(a); - right = loadNonConst(b); - mirrored = false; - } - switch (left.getKind().getStackKind()) { - case Int: - append(new CompareOp(ICMP, cond, left, right, nextPredRegNum)); - break; - case Long: - append(new CompareOp(LCMP, cond, left, right, nextPredRegNum)); - break; - case Object: - append(new CompareOp(ACMP, cond, left, right, nextPredRegNum)); - break; - case Float: - append(new CompareOp(FCMP, cond, left, right, nextPredRegNum)); - break; - case Double: - append(new CompareOp(DCMP, cond, left, right, nextPredRegNum)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return mirrored; - } - - @Override - public Variable emitIntegerTestMove(Value left, Value right, Value trueValue, Value falseValue) { - emitIntegerTest(left, right); - Variable result = newVariable(trueValue.getLIRKind()); - append(new CondMoveOp(result, Condition.EQ, load(trueValue), loadNonConst(falseValue), nextPredRegNum)); - nextPredRegNum++; - - return result; - } - - private void emitIntegerTest(Value a, Value b) { - assert a.getKind().isNumericInteger(); - - if (LIRValueUtil.isVariable(b)) { - append(new PTXTestOp(load(b), loadNonConst(a), nextPredRegNum)); - } else { - append(new PTXTestOp(load(a), loadNonConst(b), nextPredRegNum)); - } - } - - @Override - public Variable emitNegate(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - switch (input.getKind()) { - case Int: - append(new Op1Stack(INEG, result, input)); - break; - case Float: - append(new Op1Stack(FNEG, result, input)); - break; - case Double: - append(new Op1Stack(DNEG, result, input)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitNot(Value input) { - Variable result = newVariable(LIRKind.derive(input)); - switch (input.getKind()) { - case Int: - append(new Op1Stack(INOT, result, input)); - break; - case Long: - append(new Op1Stack(LNOT, result, input)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitAdd(Value a, Value b, boolean setFlags) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Stack(IADD, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Stack(LADD, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Stack(FADD, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Stack(DADD, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind() + " prim: " + a.getKind().isPrimitive()); - } - return result; - } - - @Override - public Variable emitSub(Value a, Value b, boolean setFlags) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Stack(ISUB, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Stack(LSUB, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Stack(FSUB, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Stack(DSUB, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind()); - } - return result; - } - - @Override - public Variable emitMul(Value a, Value b, boolean setFlags) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IMUL, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LMUL, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Stack(FMUL, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Stack(DMUL, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind()); - } - return result; - } - - @Override - public Value emitMulHigh(Value a, Value b) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitUMulHigh(Value a, Value b) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitDiv(Value a, Value b, LIRFrameState state) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IDIV, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LDIV, result, a, loadNonConst(b))); - break; - case Float: - append(new Op2Stack(FDIV, result, a, loadNonConst(b))); - break; - case Double: - append(new Op2Stack(DDIV, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind()); - } - return result; - } - - @Override - public Value emitRem(Value a, Value b, LIRFrameState state) { - Variable result = newVariable(LIRKind.derive(a, b)); - switch (a.getKind()) { - case Int: - append(new Op2Reg(IREM, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Reg(LREM, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + a.getKind()); - } - return result; - } - - @Override - public Variable emitUDiv(Value a, Value b, LIRFrameState state) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitUDiv()"); - } - - @Override - public Variable emitURem(Value a, Value b, LIRFrameState state) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitURem()"); - } - - @Override - public Variable emitAnd(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - 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 Variable emitOr(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - 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 Variable emitXor(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b)); - 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 - public Variable emitShl(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b).changeType(a.getPlatformKind())); - switch (a.getKind()) { - case Int: - append(new Op2Stack(ISHL, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Stack(LSHL, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitShr(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b).changeType(a.getPlatformKind())); - switch (a.getKind()) { - case Int: - append(new Op2Stack(ISHR, result, a, loadNonConst(b))); - break; - case Long: - append(new Op2Stack(LSHR, result, a, loadNonConst(b))); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - @Override - public Variable emitUShr(Value a, Value b) { - Variable result = newVariable(LIRKind.derive(a, b).changeType(a.getPlatformKind())); - switch (a.getKind()) { - case Int: - append(new ShiftOp(IUSHR, result, a, b)); - break; - case Long: - append(new ShiftOp(LUSHR, result, a, b)); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - return result; - } - - public Variable emitConvertOp(Kind from, Kind to, Value inputVal) { - Variable input = load(inputVal); - Variable result = newVariable(LIRKind.derive(inputVal).changeType(to)); - append(new ConvertOp(result, input, to, from)); - return result; - } - - @Override - public Value emitFloatConvert(FloatConvert op, Value inputVal) { - switch (op) { - case D2F: - return emitConvertOp(Kind.Double, Kind.Float, inputVal); - case D2I: - return emitConvertOp(Kind.Double, Kind.Int, inputVal); - case D2L: - return emitConvertOp(Kind.Double, Kind.Long, inputVal); - case F2D: - return emitConvertOp(Kind.Float, Kind.Double, inputVal); - case F2I: - return emitConvertOp(Kind.Float, Kind.Int, inputVal); - case F2L: - return emitConvertOp(Kind.Float, Kind.Long, inputVal); - case I2D: - return emitConvertOp(Kind.Int, Kind.Double, inputVal); - case I2F: - return emitConvertOp(Kind.Int, Kind.Float, inputVal); - case L2D: - return emitConvertOp(Kind.Long, Kind.Double, inputVal); - case L2F: - return emitConvertOp(Kind.Long, Kind.Float, inputVal); - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - @Override - public Value emitNarrow(Value inputVal, int bits) { - if (inputVal.getKind() == Kind.Long && bits <= 32) { - return emitConvertOp(Kind.Long, Kind.Int, inputVal); - } else { - return inputVal; - } - } - - @Override - public Value emitSignExtend(Value inputVal, int fromBits, int toBits) { - assert fromBits <= toBits && toBits <= 64; - if (fromBits == toBits) { - return inputVal; - } else if (toBits > 32) { - // sign extend to 64 bits - switch (fromBits) { - case 8: - return emitConvertOp(Kind.Byte, Kind.Long, inputVal); - case 16: - return emitConvertOp(Kind.Short, Kind.Long, inputVal); - case 32: - return emitConvertOp(Kind.Int, Kind.Long, inputVal); - case 64: - return inputVal; - default: - throw GraalInternalError.unimplemented("unsupported sign extension (" + fromBits + " bit -> " + toBits + " bit)"); - } - } else { - // sign extend to 32 bits (smaller values are internally represented as 32 bit values) - switch (fromBits) { - case 8: - return emitConvertOp(Kind.Byte, Kind.Int, inputVal); - case 16: - return emitConvertOp(Kind.Short, Kind.Int, inputVal); - case 32: - return inputVal; - default: - throw GraalInternalError.unimplemented("unsupported sign extension (" + fromBits + " bit -> " + toBits + " bit)"); - } - } - } - - @Override - public Value emitZeroExtend(Value inputVal, int fromBits, int toBits) { - assert fromBits <= toBits && toBits <= 64; - if (fromBits == toBits) { - return inputVal; - } else if (fromBits > 32) { - assert inputVal.getKind() == Kind.Long; - Variable result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Long)); - long mask = CodeUtil.mask(fromBits); - append(new Op2Stack(LAND, result, inputVal, JavaConstant.forLong(mask))); - return result; - } else { - assert inputVal.getKind() == Kind.Int; - Variable result = newVariable(LIRKind.derive(inputVal).changeType(Kind.Int)); - int mask = (int) CodeUtil.mask(fromBits); - append(new Op2Stack(IAND, result, inputVal, JavaConstant.forInt(mask))); - if (toBits > 32) { - Variable longResult = newVariable(LIRKind.derive(inputVal).changeType(Kind.Long)); - emitMove(longResult, result); - return longResult; - } else { - return result; - } - } - } - - @Override - public Value emitReinterpret(LIRKind to, Value inputVal) { - Variable result = newVariable(to); - emitMove(result, inputVal); - return result; - } - - @Override - public void emitDeoptimize(Value actionAndReason, Value speculation, LIRFrameState state) { - append(new ReturnOp(Value.ILLEGAL)); - } - - @Override - public void emitMembar(int barriers) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMembar()"); - } - - @Override - protected void emitForeignCall(ForeignCallLinkage callTarget, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitForeignCall()"); - } - - @Override - public Value emitBitCount(Value value) { - Variable result = newVariable(LIRKind.derive(value).changeType(Kind.Int)); - if (value.getKind().getStackKind() == Kind.Int) { - append(new PTXBitManipulationOp(IPOPCNT, result, value)); - } else { - append(new PTXBitManipulationOp(LPOPCNT, result, value)); - } - return result; - } - - @Override - public Value emitBitScanForward(Value value) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitBitScanForward()"); - } - - @Override - public Value emitBitScanReverse(Value value) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitBitScanReverse()"); - } - - @Override - public Value emitMathAbs(Value input) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMathAbs()"); - } - - @Override - public Value emitMathSqrt(Value input) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMathSqrt()"); - } - - @Override - public Value emitMathLog(Value input, boolean base10) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMathLog()"); - } - - @Override - public Value emitMathCos(Value input) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMathCos()"); - } - - @Override - public Value emitMathSin(Value input) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMathSin()"); - } - - @Override - public Value emitMathTan(Value input) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitMathTan()"); - } - - @Override - public Value emitByteSwap(Value input) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitByteSwap()"); - } - - @Override - public Value emitArrayEquals(Kind kind, Value array1, Value array2, Value length) { - // TODO Auto-generated method stub - throw GraalInternalError.unimplemented(); - } - - @Override - public void emitReturn(Value input) { - if (input != null) { - AllocatableValue operand = resultOperandFor(input.getLIRKind()); - // Load the global memory address from return parameter - Variable loadVar = emitLoadReturnAddress(operand.getKind(), operand, null); - // Store input in global memory whose location is loadVar - emitStoreReturnValue(operand.getKind(), loadVar, input, null); - } - emitReturnNoVal(); - } - - void emitReturnNoVal() { - append(new ReturnNoValOp()); - } - - @Override - public void emitStrategySwitch(SwitchStrategy strategy, Variable key, LabelRef[] keyTargets, LabelRef defaultTarget) { - boolean needsTemp = key.getKind() == Kind.Object; - append(new StrategySwitchOp(strategy, keyTargets, defaultTarget, key, needsTemp ? newVariable(key.getLIRKind()) : Value.ILLEGAL, nextPredRegNum++)); - } - - @Override - protected void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key) { - // Making a copy of the switch value is necessary because jump table destroys the input - // value - Variable tmp = emitMove(key); - append(new TableSwitchOp(lowKey, defaultTarget, targets, tmp, newVariable(LIRKind.value(target().wordKind)), nextPredRegNum++)); - } - - @Override - public void emitUnwind(Value operand) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitUnwind()"); - } - - public Variable emitLoadParam(Kind kind, Value address, LIRFrameState state) { - - PTXAddressValue loadAddress = asAddress(address); - Variable result = newVariable(target().getLIRKind(kind)); - append(new LoadParamOp(kind, result, loadAddress, state)); - - return result; - } - - public Variable emitLoadReturnAddress(Kind kind, Value address, LIRFrameState state) { - PTXAddressValue loadAddress = asAddress(address); - Variable result; - switch (kind) { - case Float: - result = newVariable(LIRKind.value(Kind.Int)); - break; - case Double: - result = newVariable(LIRKind.value(Kind.Long)); - break; - default: - result = newVariable(target().getLIRKind(kind)); - } - append(new LoadReturnAddrOp(kind, result, loadAddress, state)); - - return result; - } - - public void emitStoreReturnValue(Kind kind, Value address, Value inputVal, LIRFrameState state) { - PTXAddressValue storeAddress = asAddress(address); - Variable input = load(inputVal); - append(new StoreReturnValOp(kind, storeAddress, input, state)); - } - - @Override - public AllocatableValue resultOperandFor(LIRKind kind) { - return (new Variable(kind, 0)); - } - - public Value emitCompareAndSwap(Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue) { - throw GraalInternalError.unimplemented(); - } - - public void emitNullCheck(Value address, LIRFrameState state) { - assert address.getKind() == Kind.Object : address + " - " + address.getKind() + " not an object!"; - append(new PTXMove.NullCheckOp(load(address), state)); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXNodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXNodeLIRBuilder.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.ptx; - -import java.lang.reflect.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.gen.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.ptx.*; -import com.oracle.graal.nodes.*; - -/** - * This class implements the PTX specific portion of the LIR generator. - */ -public class PTXNodeLIRBuilder extends NodeLIRBuilder { - - public static final ForeignCallDescriptor ARITHMETIC_FREM = new ForeignCallDescriptor("arithmeticFrem", float.class, float.class, float.class); - public static final ForeignCallDescriptor ARITHMETIC_DREM = new ForeignCallDescriptor("arithmeticDrem", double.class, double.class, double.class); - - public static class PTXSpillMoveFactory implements LIR.SpillMoveFactory { - - @Override - public LIRInstruction createMove(AllocatableValue result, Value input) { - throw GraalInternalError.unimplemented("PTXSpillMoveFactory.createMove()"); - } - } - - public PTXNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) { - super(graph, lirGen); - } - - @Override - public void emitPrologue(StructuredGraph graph) { - // Need to emit .param directives based on incoming arguments and return value - CallingConvention incomingArguments = gen.getCallingConvention(); - Object returnObject = incomingArguments.getReturn(); - AllocatableValue[] params = incomingArguments.getArguments(); - int argCount = incomingArguments.getArgumentCount(); - - if (returnObject.equals(Value.ILLEGAL)) { - params = incomingArguments.getArguments(); - append(new PTXParameterOp(params, false)); - } else { - argCount = incomingArguments.getArgumentCount(); - params = new Variable[argCount + 1]; - for (int i = 0; i < argCount; i++) { - params[i] = incomingArguments.getArgument(i); - } - params[argCount] = (Variable) returnObject; - append(new PTXParameterOp(params, true)); - } - - for (ParameterNode param : graph.getNodes(ParameterNode.class)) { - int localIndex = param.index(); - Value paramValue = params[param.index()]; - int parameterIndex = localIndex; - if (!Modifier.isStatic(graph.method().getModifiers())) { - parameterIndex--; - } - Warp warpAnnotation = parameterIndex >= 0 ? graph.method().getParameterAnnotation(Warp.class, parameterIndex) : null; - if (warpAnnotation != null) { - setResult(param, getGen().emitWarpParam(paramValue.getKind().getStackKind(), warpAnnotation)); - } else { - setResult(param, getGen().emitLoadParam(paramValue.getKind().getStackKind(), paramValue, null)); - } - } - } - - private PTXLIRGenerator getGen() { - return (PTXLIRGenerator) gen; - } - - @Override - protected boolean peephole(ValueNode valueNode) { - // No peephole optimizations for now - return false; - } - - @Override - protected void emitDirectCall(DirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitDirectCall()"); - } - - @Override - protected void emitIndirectCall(IndirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.emitIndirectCall()"); - } - - @Override - public void visitBreakpointNode(BreakpointNode node) { - throw GraalInternalError.unimplemented("PTXLIRGenerator.visitBreakpointNode()"); - } - - @Override - public void visitSafepointNode(SafepointNode i) { - // LIRFrameState info = state(i); - // append(new PTXSafepointOp(info, runtime().config, this)); - Debug.log("visitSafePointNode unimplemented"); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.gpu/src/com/oracle/graal/gpu/ExternalCompilationResult.java --- a/graal/com.oracle.graal.gpu/src/com/oracle/graal/gpu/ExternalCompilationResult.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* - * 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.gpu; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.nodes.*; - -/** - * Represents the output from compiling a method generated by Graal, but executing in a memory and - * computational subsystem outside the Graal host system. - * - * Output may include the compiled machine code, associated data and references, relocation - * information, deoptimization information, as this result is generated from a structure graph on - * the Graal host system. - */ -public class ExternalCompilationResult extends CompilationResult { - - private static final long serialVersionUID = 1L; - - /** - * Address of the point of entry to the external compilation result. - */ - private long entryPoint; - private StructuredGraph hostGraph; - - private int[] oopMapArray; - private boolean usesAllocation; - - /** - * Set the address for the point of entry to the external compilation result. - * - * @param addr the address of the entry point - */ - public void setEntryPoint(long addr) { - entryPoint = addr; - } - - /** - * Return the address for the point of entry to the external compilation result. - * - * @return address value - */ - public long getEntryPoint() { - return entryPoint; - } - - /** - * Gets the {@linkplain #getTargetCode() code} in this compilation result as a string. - */ - public String getCodeString() { - return new String(getTargetCode(), 0, getTargetCodeSize()); - } - - public void setHostGraph(StructuredGraph hostGraph) { - this.hostGraph = hostGraph; - } - - public StructuredGraph getHostGraph() { - return hostGraph; - } - - public void setOopMapArray(int[] arr) { - oopMapArray = arr; - } - - public int[] getOopMapArray() { - return oopMapArray; - } - - public void setUsesAllocationFlag(boolean val) { - usesAllocation = val; - } - - public boolean getUsesAllocationFlag() { - return usesAllocation; - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/ForEachToGraal.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/ForEachToGraal.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,462 +0,0 @@ -/* - * Copyright (c) 2009, 2011, 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.hotspot.hsail; - -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; - -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.function.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.hsail.*; -import com.oracle.graal.compiler.target.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.internal.*; -import com.oracle.graal.gpu.*; -import com.oracle.graal.graph.iterators.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hsail.*; -import com.oracle.graal.java.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.phases.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.printer.*; - -/** - * Implements compile and dispatch of Java code containing lambda constructs. Currently only used by - * JDK interception code that offloads to the GPU. - */ -public class ForEachToGraal implements CompileAndDispatch { - - private static HSAILHotSpotBackend getHSAILBackend() { - Backend backend = runtime().getBackend(HSAIL.class); - return (HSAILHotSpotBackend) backend; - } - - ConcurrentHashMap, String> resolvedConsumerTargetMethods = new ConcurrentHashMap<>(); - - /** - * Returns the name of the reduction method given a class implementing {@link IntConsumer}. - * - * @param opClass a class implementing {@link IntConsumer}. - * @return the name of the reduction method - */ - public String getIntReduceTargetName(Class opClass) { - String cachedMethodName = resolvedConsumerTargetMethods.get(Objects.requireNonNull(opClass)); - if (cachedMethodName != null) { - return cachedMethodName; - } else { - Method acceptMethod = null; - for (Method m : opClass.getMethods()) { - if (m.getName().equals("applyAsInt")) { - assert acceptMethod == null : "found more than one implementation of applyAsInt in " + opClass; - acceptMethod = m; - } - } - // Ensure a debug configuration for this thread is initialized - if (DebugScope.getConfig() == null) { - DebugEnvironment.initialize(System.out); - } - - HSAILHotSpotBackend backend = getHSAILBackend(); - Providers providers = backend.getProviders(); - StructuredGraph graph = new StructuredGraph(((HotSpotMetaAccessProvider) providers.getMetaAccess()).lookupJavaMethod(acceptMethod)); - new GraphBuilderPhase.Instance(providers.getMetaAccess(), GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL).apply(graph); - NodeIterable calls = graph.getNodes(MethodCallTargetNode.class); - assert calls.count() == 1; - ResolvedJavaMethod lambdaMethod = calls.first().targetMethod(); - Debug.log("target ... %s", lambdaMethod); - - String className = lambdaMethod.getDeclaringClass().getName(); - if (!className.equals("Ljava/lang/Integer;")) { - return null; - } - resolvedConsumerTargetMethods.put(opClass, lambdaMethod.getName()); - return lambdaMethod.getName().intern(); - } - } - - /** - * Gets a compiled and installed kernel for the lambda called by the - * {@link IntConsumer#accept(int)} method in a class implementing {@link IntConsumer}. - * - * @param intConsumerClass a class implementing {@link IntConsumer} - * @return a {@link HotSpotNmethod} handle to the compiled and installed kernel - */ - private static HotSpotNmethod getCompiledLambda(Class intConsumerClass) { - Method acceptMethod = null; - for (Method m : intConsumerClass.getMethods()) { - if (m.getName().equals("accept")) { - assert acceptMethod == null : "found more than one implementation of accept(int) in " + intConsumerClass; - acceptMethod = m; - } - } - - // Ensure a debug configuration for this thread is initialized - if (DebugScope.getConfig() == null) { - DebugEnvironment.initialize(System.out); - } - - HSAILHotSpotBackend backend = getHSAILBackend(); - Providers providers = backend.getProviders(); - StructuredGraph graph = new StructuredGraph(((HotSpotMetaAccessProvider) providers.getMetaAccess()).lookupJavaMethod(acceptMethod)); - new GraphBuilderPhase.Instance(providers.getMetaAccess(), GraphBuilderConfiguration.getDefault(), OptimisticOptimizations.ALL).apply(graph); - NodeIterable calls = graph.getNodes(MethodCallTargetNode.class); - assert calls.count() == 1; - ResolvedJavaMethod lambdaMethod = calls.first().targetMethod(); - Debug.log("target ... %s", lambdaMethod); - - if (lambdaMethod == null) { - Debug.log("Did not find call in accept()"); - return null; - } - assert lambdaMethod.getName().startsWith("lambda$"); - - ExternalCompilationResult hsailCode = backend.compileKernel(lambdaMethod, true); - return backend.installKernel(lambdaMethod, hsailCode); - } - - @Override - public Object createKernel(Class consumerClass) { - try { - return getCompiledLambda(consumerClass); - } catch (Throwable e) { - // If Graal compilation throws an exception, we want to revert to regular Java - Debug.log("WARNING: Graal compilation failed"); - e.printStackTrace(); - return null; - } - } - - @Override - public Object createKernelFromHsailString(String code, String methodName) { - ExternalCompilationResult hsailCode = new ExternalCompilationResult(); - try (Debug.Scope ds = Debug.scope("GeneratingKernelBinary")) { - - HSAILHotSpotBackend backend = getHSAILBackend(); - Providers providers = backend.getProviders(); - Method integerOffloadMethod = null; - - for (Method m : Integer.class.getMethods()) { - if (m.getName().equals(methodName)) { - integerOffloadMethod = m; - break; - } - } - if (integerOffloadMethod != null) { - ResolvedJavaMethod rm = ((HotSpotMetaAccessProvider) providers.getMetaAccess()).lookupJavaMethod(integerOffloadMethod); - - long kernel = HSAILHotSpotBackend.generateKernel(code.getBytes(), "Integer::" + methodName); - if (kernel == 0) { - throw new GraalInternalError("Failed to compile HSAIL kernel from String"); - } - hsailCode.setEntryPoint(kernel); - return backend.installKernel(rm, hsailCode); // is a HotSpotNmethod - } else { - return null; - } - } catch (Throwable e) { - throw Debug.handle(e); - } - } - - @Override - public boolean dispatchKernel(Object kernel, int jobSize, Object[] args) { - HotSpotNmethod code = (HotSpotNmethod) kernel; - if (code != null) { - try { - // No return value from HSAIL kernels - getHSAILBackend().executeKernel(code, jobSize, args); - return true; - } catch (InvalidInstalledCodeException iice) { - Debug.log("WARNING: Invalid installed code at exec time: %s", iice); - iice.printStackTrace(); - return false; - } - } else { - // Should throw something sensible here - return false; - } - } - - /** - * Running with a larger global size seems to increase the performance for sum, but it might be - * different for other reductions so it is a knob. - */ - private static final int GlobalSize = 1024 * Integer.getInteger("com.amd.sumatra.reduce.globalsize.multiple", 1); - - @Override - public Integer offloadIntReduceImpl(Object okraKernel, int identity, int[] streamSource) { - // NOTE - this reduce requires local size of 64 which is the SumatraUtils default - - // Handmade reduce does not support +UseCompressedOops - HotSpotVMConfig config = runtime().getConfig(); - if (config.useCompressedOops == true || config.useHSAILDeoptimization == true) { - throw new GraalInternalError("Reduce offload not compatible with +UseCompressedOops or +UseHSAILDeoptimization"); - } - - try { - assert streamSource.length >= GlobalSize : "Input array length=" + streamSource.length + " smaller than requested global_size=" + GlobalSize; - - int[] result = {identity}; - Object[] args = {streamSource, result, streamSource.length}; - args[0] = streamSource; - - dispatchKernel(okraKernel, GlobalSize, args); - - // kernel result is result[0]. - return result[0]; - } catch (Exception e) { - System.err.println(e); - e.printStackTrace(); - } - return null; - } - - @Override - public String getIntegerReduceIntrinsic(String reducerName) { - - // Note all of these depend on group size of 256 - - String reduceOp = "/* Invalid */ "; - String atomicResultProduction = "/* Invalid */ "; - if (reducerName.equals("sum")) { - reduceOp = "add_u32 "; - atomicResultProduction = "atomicnoret_add_global_u32 "; - } else if (reducerName.equals("max")) { - reduceOp = "max_s32 "; - atomicResultProduction = "atomicnoret_max_global_s32 "; - } else if (reducerName.equals("min")) { - reduceOp = "min_s32 "; - atomicResultProduction = "atomicnoret_min_global_s32 "; - } else { - return "/* Invalid */ "; - } - - // @formatter:off - return new String( - "version 0:95:$full:$large; // BRIG Object Format Version 0:4" + "\n" - + "" + "\n" - + "kernel &run(" + "\n" - + " align 8 kernarg_u64 %arg_p3," + "\n" - + " align 8 kernarg_u64 %arg_p4," + "\n" - + " align 4 kernarg_u32 %arg_p5)" + "\n" - + "{" + "\n" - + "" + "\n" - + " align 4 group_u32 %reduce_cllocal_scratch[256];" + "\n" - + "" + "\n" - + " workitemabsid_u32 $s2, 0;" + "\n" - + "" + "\n" - + " ld_kernarg_u32 $s1, [%arg_p5];" + "\n" - + " ld_kernarg_u64 $d0, [%arg_p4];" + "\n" - + " ld_kernarg_u64 $d1, [%arg_p3];" + "\n" - + "" + "\n" - + " add_u64 $d0, $d0, 24; // adjust over obj array headers" + "\n" - + " add_u64 $d1, $d1, 24;" + "\n" - + " cmp_ge_b1_s32 $c0, $s2, $s1; // if(gloId < length){" + "\n" - + " cbr $c0, @BB0_1;" + "\n" - + " gridsize_u32 $s0, 0; // s0 is globalsize" + "\n" - + " add_u32 $s0, $s0, $s2; // gx += globalsize" + "\n" - + " cvt_s64_s32 $d2, $s2; // s2 is global id" + "\n" - + " shl_u64 $d2, $d2, 2;" + "\n" - + " add_u64 $d2, $d1, $d2;" + "\n" - + " ld_global_u32 $s3, [$d2]; // load this element from input" + "\n" - + " brn @BB0_3;" + "\n" - + "" + "\n" - + "@BB0_1:" + "\n" - + " mov_b32 $s0, $s2;" + "\n" + "" + "\n" - + "@BB0_3:" + "\n" - + " cmp_ge_b1_s32 $c1, $s0, $s1; // while (gx < length)" + "\n" - + " cbr $c1, @BB0_6;" + "\n" - + " gridsize_u32 $s2, 0;" + "\n" - + "" + "\n" - + "@BB0_5:" + "\n" - + " cvt_s64_s32 $d2, $s0;" + "\n" - + " shl_u64 $d2, $d2, 2;" + "\n" - + " add_u64 $d2, $d1, $d2;" + "\n" - + " ld_global_u32 $s4, [$d2];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " add_u32 $s0, $s0, $s2;" + "\n" - + " cmp_lt_b1_s32 $c1, $s0, $s1;" + "\n" - + " cbr $c1, @BB0_5;" + "\n" - + "" + "\n" - + "@BB0_6:" + "\n" - + " workgroupid_u32 $s0, 0;" + "\n" - + " workgroupsize_u32 $s2, 0;" + "\n" - + " mul_u32 $s2, $s2, $s0;" + "\n" - + " sub_u32 $s2, $s1, $s2;" + "\n" - + " workitemid_u32 $s1, 0;" + "\n" - + " add_u32 $s4, $s1, 128;" - + "\n" - + " cmp_lt_b1_u32 $c1, $s4, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 128;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " cvt_s64_s32 $d1, $s1;" + "\n" - + " shl_u64 $d1, $d1, 2;" + "\n" - + " lda_group_u64 $d2, [%reduce_cllocal_scratch];" + "\n" - + " add_u64 $d1, $d2, $d1;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_8;" + "\n" - + " ld_group_u32 $s3, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s4;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s4, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_8:" + "\n" - + " add_u32 $s3, $s1, 64;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 64;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_10;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" - + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_10:" + "\n" - + " add_u32 $s3, $s1, 32;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 32;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_12;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_12:" + "\n" - + " add_u32 $s3, $s1, 16;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 16;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_14;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_14:" + "\n" - + " add_u32 $s3, $s1, 8;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 8;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_16;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_16:" + "\n" - + " add_u32 $s3, $s1, 4;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 4;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_18;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_18:" + "\n" - + " add_u32 $s3, $s1, 2;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 2;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_20;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d3, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d3];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_20:" + "\n" - + " add_u32 $s3, $s1, 1;" + "\n" - + " cmp_lt_b1_u32 $c1, $s3, $s2;" + "\n" - + " cmp_lt_b1_s32 $c2, $s1, 1;" + "\n" - + " and_b1 $c1, $c2, $c1;" + "\n" - + " barrier_fgroup;" + "\n" - + " not_b1 $c1, $c1;" + "\n" - + " cbr $c1, @BB0_22;" + "\n" - + " ld_group_u32 $s4, [$d1];" + "\n" - + " cvt_s64_s32 $d3, $s3;" + "\n" - + " shl_u64 $d3, $d3, 2;" + "\n" - + " add_u64 $d2, $d2, $d3;" + "\n" - + " ld_group_u32 $s3, [$d2];" + "\n" - + reduceOp + " $s3, $s3, $s4;" + "\n" - + " st_group_u32 $s3, [$d1];" + "\n" - + "" + "\n" - + "@BB0_22:" + "\n" - + " cmp_gt_b1_u32 $c0, $s1, 0; // s1 is local id, done if > 0" + "\n" - + " cbr $c0, @BB0_24;" + "\n" - + "" + "\n" - + " ld_group_u32 $s2, [%reduce_cllocal_scratch]; // s2 is result[get_group_id(0)];" + "\n" - + atomicResultProduction + " [$d0], $s2; // build global result from local results" + "\n" - + "" + "\n" - + "@BB0_24:" + "\n" - + " ret;" + "\n" - + "};" + "\n"); - //@formatter:on - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotAssembler.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotAssembler.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2009, 2014, 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.hotspot.hsail; - -import java.lang.reflect.*; - -import com.amd.okra.*; -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.hotspot.meta.*; - -/** - * This class contains routines to emit HSAIL assembly code. - */ -public class HSAILHotSpotAssembler extends HSAILAssembler { - - public HSAILHotSpotAssembler(TargetDescription target) { - super(target); - } - - // This means the HSAIL backend cannot (currently) be executed - // in remote/replay compilation mode. - private static Field objectField; - - private static Object getObject(JavaConstant src) { - try { - if (objectField == null) { - objectField = HotSpotObjectConstantImpl.class.getDeclaredField("object"); - objectField.setAccessible(true); - } - return objectField.get(src); - } catch (Exception e) { - throw new GraalInternalError(e); - } - - } - - @Override - public final void mov(Register a, JavaConstant src) { - String regName = "$d" + a.encoding(); - // For a null object simply move 0x0 into the destination register. - if (src.isNull()) { - emitString("mov_b64 " + regName + ", 0x0; // null object"); - } else { - assert src instanceof HotSpotObjectConstantImpl; - Object obj = getObject(src); - // Get a JNI reference handle to the object. - long refHandle = OkraUtil.getRefHandle(obj); - // Get the clasname of the object for emitting a comment. - Class clazz = obj.getClass(); - String className = clazz.getName(); - String comment = "// handle for object of type " + className; - // If the object is an array note the array length in the comment. - if (className.startsWith("[")) { - comment += ", length " + Array.getLength(obj); - } - // First move the reference handle into a register. - emitString("mov_b64 " + regName + ", 0x" + Long.toHexString(refHandle) + "; " + comment); - // Next load the Object addressed by this reference handle into the destination reg. - emitString("ld_global_u64 " + regName + ", [" + regName + "];"); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1257 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.hotspot.hsail; - -import static com.oracle.graal.api.code.CallingConvention.Type.*; -import static com.oracle.graal.api.code.CodeUtil.*; -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.api.meta.LocationIdentity.*; -import static com.oracle.graal.compiler.GraalCompiler.*; -import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static com.oracle.graal.hotspot.hsail.HSAILHotSpotBackend.Options.*; -import static com.oracle.graal.hotspot.hsail.replacements.HSAILNewObjectSnippets.Options.*; - -import java.lang.reflect.*; -import java.util.*; -import java.util.Map.Entry; -import java.util.function.*; -import java.util.stream.*; - -import com.amd.okra.*; -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.Assumptions.Assumption; -import com.oracle.graal.api.code.CallingConvention.Type; -import com.oracle.graal.api.code.CompilationResult.Call; -import com.oracle.graal.api.code.CompilationResult.CodeAnnotation; -import com.oracle.graal.api.code.CompilationResult.DataPatch; -import com.oracle.graal.api.code.CompilationResult.DataSectionReference; -import com.oracle.graal.api.code.CompilationResult.ExceptionHandler; -import com.oracle.graal.api.code.CompilationResult.Infopoint; -import com.oracle.graal.api.code.CompilationResult.Mark; -import com.oracle.graal.api.code.DataSection.Data; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.cfg.*; -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.gpu.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.bridge.CompilerToVM.CodeInstallResult; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.hsail.*; -import com.oracle.graal.java.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.hsail.*; -import com.oracle.graal.lir.hsail.HSAILControlFlow.DeoptimizingOp; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.StructuredGraph.GuardsStage; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.virtual.*; -import com.oracle.graal.options.*; -import com.oracle.graal.phases.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.virtual.nodes.*; - -/** - * HSAIL specific backend. - */ -public class HSAILHotSpotBackend extends HotSpotBackend { - - public static class Options { - - // @formatter:off - @Option(help = "Number of TLABs used for HSAIL kernels which allocate", type = OptionType.Debug) - public static final OptionValue HsailKernelTlabs = new OptionValue<>(4); - // @formatter:on - } - - private Map paramTypeMap = new HashMap<>(); - private final boolean deviceInitialized; - // TODO: get maximum Concurrency from okra - private int maxDeoptIndex = 8 * 40 * 64; // see gpu_hsail.hpp - - public HSAILHotSpotBackend(HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) { - super(runtime, providers); - paramTypeMap.put("HotSpotResolvedPrimitiveType", "s32"); - paramTypeMap.put("HotSpotResolvedPrimitiveType", "f32"); - paramTypeMap.put("HotSpotResolvedPrimitiveType", "f64"); - paramTypeMap.put("HotSpotResolvedPrimitiveType", "s64"); - - /* - * The order of the conjunction below is important: the OkraUtil call may provision the - * native library required by the initialize() call - */ - deviceInitialized = OkraUtil.okraLibExists() && initialize(); - } - - @Override - public boolean shouldAllocateRegisters() { - return true; - } - - /** - * Initializes the GPU device. - * - * @return whether or not initialization was successful - */ - private static native boolean initialize(); - - /** - * Determines if the GPU device (or simulator) is available and initialized. - */ - public boolean isDeviceInitialized() { - return deviceInitialized; - } - - /** - * Completes the initialization of the HSAIL backend. This includes initializing the providers - * and registering any method substitutions specified by the HSAIL backend. - */ - @Override - public void completeInitialization() { - final HotSpotProviders providers = getProviders(); - HotSpotVMConfig config = getRuntime().getConfig(); - // Initialize the lowering provider. - final HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer(); - lowerer.initialize(providers, config); - - // Register the replacements used by the HSAIL backend. - HSAILHotSpotReplacementsImpl replacements = (HSAILHotSpotReplacementsImpl) providers.getReplacements(); - replacements.completeInitialization(); - } - - /** - * Compiles and installs a given method to a GPU binary. - */ - public HotSpotNmethod compileAndInstallKernel(Method method) { - ResolvedJavaMethod javaMethod = getProviders().getMetaAccess().lookupJavaMethod(method); - HotSpotNmethod nm = installKernel(javaMethod, compileKernel(javaMethod, true)); - try (Scope s = Debug.scope("HostCodeGen")) { - if (Debug.isLogEnabled()) { - DisassemblerProvider dis = getRuntime().getHostBackend().getDisassembler(); - if (dis != null) { - String disasm = dis.disassemble(nm); - Debug.log("host code generated for %s%n%s", javaMethod, disasm); - } else { - Debug.log("host code disassembler is null"); - } - } - } catch (Throwable e) { - throw Debug.handle(e); - } - return nm; - } - - /** - * Compiles a given method to HSAIL code. - * - * @param makeBinary specifies whether a GPU binary should also be generated for the HSAIL code. - * If true, the returned value is guaranteed to have a non-zero - * {@linkplain ExternalCompilationResult#getEntryPoint() entry point}. - * @return the HSAIL code compiled from {@code method}'s bytecode - */ - public ExternalCompilationResult compileKernel(ResolvedJavaMethod method, boolean makeBinary) { - StructuredGraph graph = new StructuredGraph(method); - HotSpotProviders providers = getProviders(); - MetaAccessProvider metaAccess = getProviders().getMetaAccess(); - - // changed this from default to help us generate deopts when needed - OptimisticOptimizations optimisticOpts = OptimisticOptimizations.ALL; - optimisticOpts.remove(OptimisticOptimizations.Optimization.UseExceptionProbabilityForOperations); - new GraphBuilderPhase.Instance(metaAccess, GraphBuilderConfiguration.getSnippetDefault(), optimisticOpts).apply(graph); - PhaseSuite graphBuilderSuite = providers.getSuites().getDefaultGraphBuilderSuite(); - CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, graph.method(), false); - - // append special HSAILNonNullParametersPhase - int numArgs = cc.getArguments().length; - graphBuilderSuite.appendPhase(new HSAILNonNullParametersPhase(numArgs)); - - Suites suites = providers.getSuites().getDefaultSuites(); - ExternalCompilationResult hsailCode = compileGraph(graph, null, cc, method, providers, this, this.getTarget(), null, graphBuilderSuite, optimisticOpts, getProfilingInfo(graph), null, suites, - new ExternalCompilationResult(), CompilationResultBuilderFactory.Default); - - // this code added to dump infopoints - try (Scope s = Debug.scope("CodeGen")) { - if (Debug.isLogEnabled()) { - // show infopoints - List infoList = hsailCode.getInfopoints(); - Debug.log("%d HSAIL infopoints", infoList.size()); - for (Infopoint info : infoList) { - Debug.log(info.toString()); - Debug.log(info.debugInfo.frame().toString()); - } - } - } catch (Throwable e) { - throw Debug.handle(e); - } - - if (makeBinary) { - if (!deviceInitialized) { - throw new GraalInternalError("Cannot generate GPU kernel if device is not initialized"); - } - try (Scope ds = Debug.scope("GeneratingKernelBinary")) { - long kernel = generateKernel(hsailCode.getTargetCode(), method.getName()); - if (kernel == 0) { - throw new GraalInternalError("Failed to compile HSAIL kernel"); - } - hsailCode.setEntryPoint(kernel); - } catch (Throwable e) { - throw Debug.handle(e); - } - } - return hsailCode; - } - - private static class HSAILNonNullParametersPhase extends Phase { - // we use this to limit the stamping to exclude the final argument in an obj stream method - private int numArgs; - - public HSAILNonNullParametersPhase(int numArgs) { - this.numArgs = numArgs; - } - - @Override - protected void run(StructuredGraph graph) { - int argCount = 0; - Stamp nonNull = StampFactory.objectNonNull(); - for (ParameterNode param : graph.getNodes(ParameterNode.class)) { - argCount++; - if (argCount < numArgs && param.stamp() instanceof ObjectStamp) { - ObjectStamp paramStamp = (ObjectStamp) param.stamp(); - param.setStamp(paramStamp.join(nonNull)); - } - } - } - } - - /** - * Generates a GPU binary from HSAIL code. - */ - static native long generateKernel(byte[] hsailCode, String name); - - /** - * Installs the {@linkplain ExternalCompilationResult#getEntryPoint() GPU binary} associated - * with some given HSAIL code in the code cache and returns a {@link HotSpotNmethod} handle to - * the installed code. - * - * @param hsailCode HSAIL compilation result for which a GPU binary has been generated - * @return a handle to the binary as installed in the HotSpot code cache - */ - public final HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult hsailCode) { - assert hsailCode.getEntryPoint() != 0L; - // Code here based on HotSpotCodeCacheProvider.addExternalMethod(). - HotSpotResolvedJavaMethod javaMethod = (HotSpotResolvedJavaMethod) method; - if (hsailCode.getId() == -1) { - hsailCode.setId(javaMethod.allocateCompileId(hsailCode.getEntryBCI())); - } - CompilationResult compilationResult = hsailCode; - StructuredGraph hostGraph = hsailCode.getHostGraph(); - if (hostGraph != null) { - // TODO get rid of the unverified entry point in the host code - try (Scope ds = Debug.scope("GeneratingHostGraph", new DebugDumpScope("HostGraph"))) { - HotSpotBackend hostBackend = getRuntime().getHostBackend(); - JavaType[] parameterTypes = new JavaType[hostGraph.getNodes(ParameterNode.class).count()]; - Debug.log("Param count: %d", parameterTypes.length); - for (int i = 0; i < parameterTypes.length; i++) { - ParameterNode parameter = hostGraph.getParameter(i); - Debug.log("Param [%d]=%s", i, parameter); - parameterTypes[i] = parameter.stamp().javaType(hostBackend.getProviders().getMetaAccess()); - Debug.log(" %s", parameterTypes[i]); - } - CallingConvention cc = hostBackend.getProviders().getCodeCache().getRegisterConfig().getCallingConvention(Type.JavaCallee, method.getSignature().getReturnType(null), parameterTypes, - hostBackend.getTarget(), false); - CompilationResult hostCode = compileGraph(hostGraph, null, cc, method, hostBackend.getProviders(), hostBackend, this.getTarget(), null, - hostBackend.getProviders().getSuites().getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE, null, null, - hostBackend.getProviders().getSuites().getDefaultSuites(), new CompilationResult(), CompilationResultBuilderFactory.Default); - compilationResult = merge(hostCode, hsailCode); - } catch (Throwable e) { - throw Debug.handle(e); - } - } - - HSAILHotSpotNmethod code = new HSAILHotSpotNmethod(javaMethod, hsailCode.getName(), false, true); - code.setOopMapArray(hsailCode.getOopMapArray()); - code.setUsesAllocationFlag(hsailCode.getUsesAllocationFlag()); - HotSpotCompiledNmethod compiled = new HotSpotCompiledNmethod(javaMethod, compilationResult); - CodeInstallResult result = getRuntime().getCompilerToVM().installCode(compiled, code, null); - if (result != CodeInstallResult.OK) { - return null; - } - return code; - } - - private static ExternalCompilationResult merge(CompilationResult hostCode, ExternalCompilationResult hsailCode) { - ExternalCompilationResult result = new ExternalCompilationResult(); - - // from hsail code - result.setEntryPoint(hsailCode.getEntryPoint()); - result.setId(hsailCode.getId()); - result.setEntryBCI(hsailCode.getEntryBCI()); - assert hsailCode.getMarks().isEmpty(); - assert hsailCode.getExceptionHandlers().isEmpty(); - assert hsailCode.getDataPatches().isEmpty(); - - // from host code - result.setTotalFrameSize(hostCode.getTotalFrameSize()); - result.setCustomStackAreaOffset(hostCode.getCustomStackAreaOffset()); - result.setTargetCode(hostCode.getTargetCode(), hostCode.getTargetCodeSize()); - for (CodeAnnotation annotation : hostCode.getAnnotations()) { - result.addAnnotation(annotation); - } - for (Mark mark : hostCode.getMarks()) { - result.recordMark(mark.pcOffset, mark.id); - } - for (ExceptionHandler handler : hostCode.getExceptionHandlers()) { - result.recordExceptionHandler(handler.pcOffset, handler.handlerPos); - } - for (DataPatch patch : hostCode.getDataPatches()) { - if (patch.reference instanceof DataSectionReference) { - Data hostData = hostCode.getDataSection().findData((DataSectionReference) patch.reference); - Data resultData = new Data(hostData.getAlignment(), hostData.getSize(), hostData.getBuilder()); - patch.reference = result.getDataSection().insertData(resultData); - } - result.recordDataPatch(patch.pcOffset, patch.reference); - } - for (Infopoint infopoint : hostCode.getInfopoints()) { - if (infopoint instanceof Call) { - Call call = (Call) infopoint; - result.recordCall(call.pcOffset, call.size, call.target, call.debugInfo, call.direct); - } else { - result.recordInfopoint(infopoint.pcOffset, infopoint.debugInfo, infopoint.reason); - } - } - - // merged - Assumptions mergedAssumptions = new Assumptions(true); - if (hostCode.getAssumptions() != null) { - for (Assumption assumption : hostCode.getAssumptions().getAssumptions()) { - if (assumption != null) { - mergedAssumptions.record(assumption); - } - } - } - if (hsailCode.getAssumptions() != null) { - for (Assumption assumption : hsailCode.getAssumptions().getAssumptions()) { - if (assumption != null) { - mergedAssumptions.record(assumption); - } - } - } - if (!mergedAssumptions.isEmpty()) { - result.setAssumptions(mergedAssumptions); - } - return result; - } - - public boolean executeKernel(HotSpotInstalledCode kernel, int jobSize, Object[] args) throws InvalidInstalledCodeException { - if (!deviceInitialized) { - throw new GraalInternalError("Cannot execute GPU kernel if device is not initialized"); - } - int[] oopMapArray = ((HSAILHotSpotNmethod) kernel).getOopMapArray(); - - // Pass HsailKernelTlabs number if this kernel uses allocation, otherwise 0 - int numTlabs = ((HSAILHotSpotNmethod) kernel).getUsesAllocationFlag() ? HsailKernelTlabs.getValue() : 0; - return executeKernel0(kernel, jobSize, args, numTlabs, HsailAllocBytesPerWorkitem.getValue(), oopMapArray); - } - - private static native boolean executeKernel0(HotSpotInstalledCode kernel, int jobSize, Object[] args, int numTlabs, int allocBytesPerWorkitem, int[] oopMapArray) - throws InvalidInstalledCodeException; - - @Override - public FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig) { - RegisterConfig registerConfigNonNull = registerConfig == null ? getCodeCache().getRegisterConfig() : registerConfig; - return new FrameMapBuilderImpl(newFrameMap(registerConfigNonNull), getCodeCache(), registerConfigNonNull); - } - - /** - * Use the HSAIL register set when the compilation target is HSAIL. - */ - @Override - public FrameMap newFrameMap(RegisterConfig registerConfig) { - return new HSAILFrameMap(getCodeCache(), registerConfig); - } - - @Override - public LIRGeneratorTool newLIRGenerator(CallingConvention cc, LIRGenerationResult lirGenRes) { - return new HSAILHotSpotLIRGenerator(getProviders(), getRuntime().getConfig(), cc, lirGenRes); - } - - @Override - public LIRGenerationResult newLIRGenerationResult(LIR lir, FrameMapBuilder frameMapBuilder, ResolvedJavaMethod method, Object stub) { - return new HSAILHotSpotLIRGenerationResult(lir, frameMapBuilder); - } - - @Override - public NodeLIRBuilderTool newNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) { - return new HSAILHotSpotNodeLIRBuilder(graph, lirGen); - } - - class HotSpotFrameContext implements FrameContext { - - public boolean hasFrame() { - return true; - } - - @Override - public void enter(CompilationResultBuilder crb) { - Debug.log("Nothing to do here"); - } - - @Override - public void leave(CompilationResultBuilder crb) { - Debug.log("Nothing to do here"); - } - } - - /** - * a class to allow us to save lirGen. - */ - static class HSAILCompilationResultBuilder extends CompilationResultBuilder { - public HSAILHotSpotLIRGenerationResult lirGenRes; - - public HSAILCompilationResultBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, FrameContext frameContext, - CompilationResult compilationResult, HSAILHotSpotLIRGenerationResult lirGenRes) { - super(codeCache, foreignCalls, frameMap, asm, frameContext, compilationResult); - this.lirGenRes = lirGenRes; - } - } - - static class HSAILHotSpotNmethod extends HotSpotNmethod { - private int[] oopMapArray; - private boolean usesAllocation; - - HSAILHotSpotNmethod(HotSpotResolvedJavaMethod method, String name, boolean isDefault, boolean isExternal) { - super(method, name, isDefault, isExternal); - } - - void setOopMapArray(int[] array) { - oopMapArray = array; - } - - int[] getOopMapArray() { - return oopMapArray; - } - - public void setUsesAllocationFlag(boolean val) { - usesAllocation = val; - } - - public boolean getUsesAllocationFlag() { - return usesAllocation; - } - } - - @Override - protected Assembler createAssembler(FrameMap frameMap) { - return new HSAILHotSpotAssembler(getTarget()); - } - - @Override - public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenRes, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) { - Assembler masm = createAssembler(frameMap); - HotSpotFrameContext frameContext = new HotSpotFrameContext(); - // save lirGen for later use by setHostGraph - CompilationResultBuilder crb = new HSAILCompilationResultBuilder(getCodeCache(), getForeignCalls(), frameMap, masm, frameContext, compilationResult, - (HSAILHotSpotLIRGenerationResult) lirGenRes); - crb.setTotalFrameSize(frameMap.totalFrameSize()); - return crb; - } - - @Override - public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod method) { - assert method != null : lir + " is not associated with a method"; - Kind wordKind = getProviders().getCodeCache().getTarget().wordKind; - LIRKind wordLIRKind = LIRKind.value(wordKind); - - HotSpotVMConfig config = getRuntime().getConfig(); - boolean useHSAILDeoptimization = config.useHSAILDeoptimization; - boolean useHSAILSafepoints = config.useHSAILSafepoints; - - if ((useHSAILSafepoints == true) && (useHSAILDeoptimization == false)) { - Debug.log("+UseHSAILSafepoints requires +UseHSAILDeoptimization"); - } - - /* - * See what graph nodes we have to see if we are using the thread register. If not, we don't - * have to emit the code that sets it up. Maybe there is a better way to do this? - */ - boolean usesAllocation = false; - search: for (AbstractBlock b : lir.linearScanOrder()) { - for (LIRInstruction op : lir.getLIRforBlock(b)) { - if ((op instanceof HSAILMove.LoadOp) && ((HSAILMove.LoadOp) op).usesThreadRegister()) { - usesAllocation = true; - assert useHSAILDeoptimization : "cannot use thread register if HSAIL deopt support is disabled"; - break search; - } - } - } - // save usesAllocation flag in ExternalCompilationResult - ((ExternalCompilationResult) crb.compilationResult).setUsesAllocationFlag(usesAllocation); - - // Emit the prologue. - HSAILAssembler asm = (HSAILAssembler) crb.asm; - asm.emitString0("version 0:95: $full : $large;\n"); - - Signature signature = method.getSignature(); - int sigParamCount = signature.getParameterCount(false); - // We're subtracting 1 because we're not making the final gid as a parameter. - - int nonConstantParamCount = sigParamCount - 1; - boolean isStatic = (method.isStatic()); - // Determine if this is an object lambda. - boolean isObjectLambda = true; - - if (signature.getParameterType(nonConstantParamCount, null).getKind() == Kind.Int) { - isObjectLambda = false; - } else { - // Add space for gid int reg. - nonConstantParamCount++; - } - - // If this is an instance method, include the "this" parameter - if (!isStatic) { - nonConstantParamCount++; - } - // Add in any "constant" parameters (currently none). - int totalParamCount = nonConstantParamCount; - JavaType[] paramtypes = new JavaType[totalParamCount]; - String[] paramNames = new String[totalParamCount]; - int pidx = 0; - MetaAccessProvider metaAccess = getProviders().getMetaAccess(); - for (int i = 0; i < totalParamCount; i++) { - if (i == 0 && !isStatic) { - paramtypes[i] = metaAccess.lookupJavaType(Object.class); - paramNames[i] = "%_this"; - } else if (i < nonConstantParamCount) { - if (isObjectLambda && (i == (nonConstantParamCount))) { - // Set up the gid register mapping. - paramtypes[i] = metaAccess.lookupJavaType(int.class); - paramNames[i] = "%_gid"; - } else { - paramtypes[i] = signature.getParameterType(pidx++, null); - paramNames[i] = "%_arg" + i; - } - } - } - - asm.emitString0("// " + (isStatic ? "static" : "instance") + " method " + method + "\n"); - asm.emitString0("kernel &run ( \n"); - - FrameMap frameMap = crb.frameMap; - RegisterConfig regConfig = frameMap.getRegisterConfig(); - // Build list of param types which does include the gid (for cc register mapping query). - JavaType[] ccParamTypes = new JavaType[nonConstantParamCount + 1]; - // Include the gid. - System.arraycopy(paramtypes, 0, ccParamTypes, 0, nonConstantParamCount); - - /* - * Last entry is always int (its register gets used in the workitemabsid instruction). This - * is true even for object stream lambdas. - */ - if (sigParamCount > 0) { - ccParamTypes[ccParamTypes.length - 1] = metaAccess.lookupJavaType(int.class); - } - CallingConvention cc = regConfig.getCallingConvention(JavaCallee, null, ccParamTypes, getTarget(), false); - - /** - * Compute the hsail size mappings up to but not including the last non-constant parameter - * (which is the gid). - * - */ - String[] paramHsailSizes = new String[totalParamCount]; - for (int i = 0; i < totalParamCount; i++) { - String paramtypeStr = paramtypes[i].toString(); - String sizeStr = paramTypeMap.get(paramtypeStr); - // Catch all for any unmapped paramtype that is u64 (address of an object). - paramHsailSizes[i] = (sizeStr != null ? sizeStr : "u64"); - } - // Emit the kernel function parameters. - for (int i = 0; i < totalParamCount; i++) { - String str = "align 8 kernarg_" + paramHsailSizes[i] + " " + paramNames[i]; - - if (useHSAILDeoptimization || (i != totalParamCount - 1)) { - str += ","; - } - asm.emitString(str); - } - - if (useHSAILDeoptimization) { - // add in the deoptInfo parameter - asm.emitString("kernarg_u64 " + asm.getDeoptInfoName()); - } - - asm.emitString(") {"); - - /* - * End of parameters start of prolog code. Emit the load instructions for loading of the - * kernel non-constant parameters into registers. The constant class parameters will not be - * loaded up front but will be loaded as needed. - */ - for (int i = 0; i < nonConstantParamCount; i++) { - asm.emitString("ld_kernarg_" + paramHsailSizes[i] + " " + HSAIL.mapRegister(cc.getArgument(i)) + ", [" + paramNames[i] + "];"); - } - - /* - * Emit the workitemaid instruction for loading the hidden gid parameter. This is assigned - * the register as if it were the last of the nonConstant parameters. - */ - String workItemReg = "$s" + Integer.toString(asRegister(cc.getArgument(nonConstantParamCount)).encoding()); - asm.emitString("workitemabsid_u32 " + workItemReg + ", 0;"); - - final String deoptInProgressLabel = "@LHandleDeoptInProgress"; - - if (useHSAILDeoptimization) { - // Aliases for d16 - RegisterValue d16DeoptInfo = HSAIL.d16.asValue(wordLIRKind); - - // Aliases for d17 - RegisterValue d17TlabIndex = HSAIL.d17.asValue(wordLIRKind); - RegisterValue d17SafepointFlagAddrIndex = d17TlabIndex; - - // Aliases for s34 - RegisterValue s34DeoptOccurred = HSAIL.s34.asValue(LIRKind.value(Kind.Int)); - RegisterValue s34TlabIndex = s34DeoptOccurred; - - asm.emitLoadKernelArg(d16DeoptInfo, asm.getDeoptInfoName(), "u64"); - asm.emitComment("// Check if a deopt or safepoint has occurred and abort if true before doing any work"); - - if (useHSAILSafepoints) { - // Load address of _notice_safepoints field - asm.emitLoad(wordKind, d17SafepointFlagAddrIndex, new HSAILAddressValue(wordLIRKind, d16DeoptInfo, config.hsailNoticeSafepointsOffset).toAddress()); - // Load int value from that field - asm.emitLoadAcquire(s34DeoptOccurred, new HSAILAddressValue(wordLIRKind, d17SafepointFlagAddrIndex, 0).toAddress()); - asm.emitCompare(Kind.Int, s34DeoptOccurred, JavaConstant.forInt(0), "ne", false, false); - asm.cbr(deoptInProgressLabel); - } - asm.emitLoadAcquire(s34DeoptOccurred, new HSAILAddressValue(wordLIRKind, d16DeoptInfo, config.hsailDeoptOccurredOffset).toAddress()); - asm.emitCompare(Kind.Int, s34DeoptOccurred, JavaConstant.forInt(0), "ne", false, false); - asm.cbr(deoptInProgressLabel); - // load thread register if this kernel performs allocation - if (usesAllocation) { - RegisterValue threadReg = getProviders().getRegisters().getThreadRegister().asValue(wordLIRKind); - assert HsailKernelTlabs.getValue() > 0; - asm.emitLoad(wordKind, threadReg, new HSAILAddressValue(wordLIRKind, d16DeoptInfo, config.hsailCurTlabInfoOffset).toAddress()); - if (HsailKernelTlabs.getValue() != 1) { - asm.emitComment("// map workitem to a tlab"); - asm.emitString(String.format("rem_u32 $%s, %s, %d;", s34TlabIndex.getRegister(), workItemReg, HsailKernelTlabs.getValue())); - asm.emitConvert(d17TlabIndex, s34TlabIndex, wordKind, Kind.Int); - asm.emit("mad", threadReg, d17TlabIndex, JavaConstant.forInt(8), threadReg); - } else { - // workitem is already mapped to solitary tlab - } - asm.emitComment("// $" + getProviders().getRegisters().getThreadRegister() + " will point to holder of tlab thread info for this workitem"); - } - } - - /* - * Note the logic used for this spillseg size is to leave space and then go back and patch - * in the correct size once we have generated all the instructions. This should probably be - * done in a more robust way by implementing something like asm.insertString. - */ - int spillsegDeclarationPosition = asm.position() + 1; - String spillsegTemplate = "align 4 spill_u8 %spillseg[123456];"; - asm.emitString(spillsegTemplate); - // Emit object array load prologue here. - if (isObjectLambda) { - boolean useCompressedOops = config.useCompressedOops; - final int arrayElementsOffset = runtime().getArrayBaseOffset(wordKind); - String iterationObjArgReg = HSAIL.mapRegister(cc.getArgument(nonConstantParamCount - 1)); - /* - * iterationObjArgReg will be the highest $d register in use (it is the last parameter) - * so tempReg can be the next higher $d register. As of 1.0 spec, we cannot use - * ld_global_u32 $dxx, [addr]; so we need a temporary $s register. We can use - * workItemReg+1; - */ - String tmpReg = "$d" + (asRegister(cc.getArgument(nonConstantParamCount - 1)).encoding() + 1); - // Convert gid to long. - asm.emitString("cvt_u64_s32 " + tmpReg + ", " + workItemReg + "; // Convert gid to long"); - // Adjust index for sizeof ref. Where to pull this size from? - asm.emitString("mul_u64 " + tmpReg + ", " + tmpReg + ", " + (useCompressedOops ? 4 : 8) + "; // Adjust index for sizeof ref"); - // Adjust for actual data start. - asm.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + arrayElementsOffset + "; // Adjust for actual elements data start"); - // Add to array ref ptr. - asm.emitString("add_u64 " + tmpReg + ", " + tmpReg + ", " + iterationObjArgReg + "; // Add to array ref ptr"); - // Load the object into the parameter reg. - if (useCompressedOops) { - int workItemRegEncoding = asRegister(cc.getArgument(nonConstantParamCount)).encoding(); - String tmpReg32 = "$s" + Integer.toString(workItemRegEncoding + 1); - - // Load u32 into the temporary $s reg since it will become an object address - - asm.emitString("ld_global_u32 " + tmpReg32 + ", " + "[" + tmpReg + "]" + "; // Load compressed ptr from array"); - asm.emitString("cvt_u64_u32 " + tmpReg + ", " + tmpReg32 + "; // cvt to 64 bits"); - - long narrowOopBase = config.narrowOopBase; - long narrowOopShift = config.narrowOopShift; - - if (narrowOopBase == 0 && narrowOopShift == 0) { - // No more calculation to do, mov to target register - asm.emitString("mov_b64 " + iterationObjArgReg + ", " + tmpReg + "; // no shift or base addition"); - } else { - if (narrowOopBase == 0) { - asm.emitString("shl_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + narrowOopShift + "; // do narrowOopShift"); - } else if (narrowOopShift == 0) { - // not sure if we ever get add with 0 shift but just in case - asm.emitString("cmp_eq_b1_u64 $c0, " + tmpReg + ", 0x0; // avoid add if compressed is null"); - asm.emitString("add_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + narrowOopBase + "; // add narrowOopBase"); - asm.emitString("cmov_b64 " + iterationObjArgReg + ", $c0, 0x0, " + iterationObjArgReg + "; // avoid add if compressed is null"); - } else { - asm.emitString("cmp_eq_b1_u64 $c0, " + tmpReg + ", 0x0; // avoid shift-add if compressed is null"); - asm.emitString("mad_u64 " + iterationObjArgReg + ", " + tmpReg + ", " + (1 << narrowOopShift) + ", " + narrowOopBase + "; // shift and add narrowOopBase"); - asm.emitString("cmov_b64 " + iterationObjArgReg + ", $c0, 0x0, " + iterationObjArgReg + "; // avoid shift-add if compressed is null"); - } - } - - } else { - asm.emitString("ld_global_u64 " + iterationObjArgReg + ", " + "[" + tmpReg + "]" + "; // Load from array element into parameter reg"); - } - } - // Prologue done, Emit code for the LIR. - crb.emit(lir); - // Now that code is emitted go back and figure out what the upper Bound stack size was. - long maxStackSize = ((HSAILAssembler) crb.asm).upperBoundStackSize(); - String spillsegStringFinal; - if (maxStackSize == 0) { - // If no spilling, get rid of spillseg declaration. - char[] array = new char[spillsegTemplate.length()]; - Arrays.fill(array, ' '); - spillsegStringFinal = new String(array); - } else { - spillsegStringFinal = spillsegTemplate.replace("123456", String.format("%6d", maxStackSize)); - } - asm.emitString(spillsegStringFinal, spillsegDeclarationPosition); - // Emit the epilogue. - - HSAILHotSpotLIRGenerationResult lirGenRes = ((HSAILCompilationResultBuilder) crb).lirGenRes; - - int numSRegs = 0; - int numDRegs = 0; - int numStackSlotBytes = 0; - if (useHSAILDeoptimization) { - /* - * Get the union of registers and stack slots needed to be saved at the infopoints. - * While doing this compute the highest register in each category. - */ - HSAILHotSpotRegisterConfig hsailRegConfig = (HSAILHotSpotRegisterConfig) regConfig; - Set infoUsedRegs = new TreeSet<>(); - Set infoUsedStackSlots = new HashSet<>(); - List infoList = crb.compilationResult.getInfopoints(); - Queue workList = new LinkedList<>(); - for (Infopoint info : infoList) { - BytecodeFrame frame = info.debugInfo.frame(); - while (frame != null) { - workList.add(frame.values); - frame = frame.caller(); - } - } - while (!workList.isEmpty()) { - JavaValue[] values = workList.poll(); - for (JavaValue val : values) { - if (!Value.ILLEGAL.equals(val)) { - if (val instanceof RegisterValue) { - Register reg = ((RegisterValue) val).getRegister(); - infoUsedRegs.add(reg); - if (hsailRegConfig.isAllocatableSReg(reg)) { - numSRegs = Math.max(numSRegs, reg.encoding + 1); - } else if (hsailRegConfig.isAllocatableDReg(reg)) { - numDRegs = Math.max(numDRegs, reg.encoding + 1); - } - } else if (val instanceof StackSlot) { - StackSlot slot = (StackSlot) val; - Kind slotKind = slot.getKind(); - int slotSizeBytes = (slotKind.isObject() ? 8 : slotKind.getByteCount()); - int slotOffsetMax = HSAIL.getStackOffsetStart(slot, slotSizeBytes * 8) + slotSizeBytes; - numStackSlotBytes = Math.max(numStackSlotBytes, slotOffsetMax); - infoUsedStackSlots.add(slot); - } else if (val instanceof VirtualObject) { - workList.add(((VirtualObject) val).getValues()); - } else { - assert val instanceof JavaConstant : "Unsupported value: " + val; - } - } - } - } - - // round up numSRegs to even number so dregs start on aligned boundary - numSRegs += (numSRegs & 1); - - // numStackSlots is the number of 8-byte locations used for stack variables - int numStackSlots = (numStackSlotBytes + 7) / 8; - - final int offsetToDeoptSaveStates = config.hsailDeoptimizationInfoHeaderSize; - final int bytesPerSaveArea = 4 * numSRegs + 8 * numDRegs + 8 * numStackSlots; - final int sizeofKernelDeopt = config.hsailKernelDeoptimizationHeaderSize + config.hsailFrameHeaderSize + bytesPerSaveArea; - final int offsetToNeverRanArray = config.hsailNeverRanArrayOffset; - final int offsetToDeoptNextIndex = config.hsailDeoptNextIndexOffset; - final int offsetToDeoptimizationWorkItem = config.hsailDeoptimizationWorkItem; - final int offsetToDeoptimizationReason = config.hsailDeoptimizationReason; - final int offsetToDeoptimizationFrame = config.hsailKernelDeoptimizationHeaderSize; - final int offsetToFramePc = config.hsailFramePcOffset; - final int offsetToNumSaves = config.hsailFrameNumSRegOffset; - final int offsetToSaveArea = config.hsailFrameHeaderSize; - - AllocatableValue scratch64 = HSAIL.d16.asValue(wordLIRKind); - AllocatableValue cuSaveAreaPtr = HSAIL.d17.asValue(wordLIRKind); - AllocatableValue waveMathScratch1 = HSAIL.d18.asValue(wordLIRKind); - AllocatableValue waveMathScratch2 = HSAIL.d19.asValue(wordLIRKind); - - AllocatableValue actionAndReasonReg = HSAIL.actionAndReasonReg.asValue(LIRKind.value(Kind.Int)); - AllocatableValue codeBufferOffsetReg = HSAIL.codeBufferOffsetReg.asValue(LIRKind.value(Kind.Int)); - AllocatableValue scratch32 = HSAIL.s34.asValue(LIRKind.value(Kind.Int)); - AllocatableValue workidreg = HSAIL.s35.asValue(LIRKind.value(Kind.Int)); - - HSAILAddress deoptNextIndexAddr = new HSAILAddressValue(wordLIRKind, scratch64, offsetToDeoptNextIndex).toAddress(); - HSAILAddress neverRanArrayAddr = new HSAILAddressValue(wordLIRKind, scratch64, offsetToNeverRanArray).toAddress(); - - // The just-started lanes that see the deopt flag will jump here - asm.emitString0(deoptInProgressLabel + ":\n"); - asm.emitLoad(wordKind, waveMathScratch1, neverRanArrayAddr); - asm.emitWorkItemAbsId(workidreg); - asm.emitConvert(waveMathScratch2, workidreg, wordKind, Kind.Int); - asm.emit("add", waveMathScratch1, waveMathScratch1, waveMathScratch2); - HSAILAddress neverRanStoreAddr = new HSAILAddressValue(wordLIRKind, waveMathScratch1, 0).toAddress(); - asm.emitStore(Kind.Byte, JavaConstant.forInt(1), neverRanStoreAddr); - asm.emitString("ret;"); - - // The deoptimizing lanes will jump here - asm.emitString0(asm.getDeoptLabelName() + ":\n"); - String labelExit = asm.getDeoptLabelName() + "_Exit"; - - HSAILAddress deoptInfoAddr = new HSAILAddressValue(wordLIRKind, scratch64, config.hsailDeoptOccurredOffset).toAddress(); - asm.emitLoadKernelArg(scratch64, asm.getDeoptInfoName(), "u64"); - - // Set deopt occurred flag - asm.emitMov(Kind.Int, scratch32, JavaConstant.forInt(1)); - asm.emitStoreRelease(scratch32, deoptInfoAddr); - - asm.emitComment("// Determine next deopt save slot"); - asm.emitAtomicAdd(scratch32, deoptNextIndexAddr, JavaConstant.forInt(1)); - /* - * scratch32 now holds next index to use set error condition if no room in save area - */ - asm.emitComment("// assert room to save deopt"); - asm.emitCompare(Kind.Int, scratch32, JavaConstant.forInt(maxDeoptIndex), "lt", false, false); - asm.cbr("@L_StoreDeopt"); - /* - * if assert fails, store a guaranteed negative workitemid in top level deopt occurred - * flag - */ - asm.emitWorkItemAbsId(scratch32); - asm.emit("mad", scratch32, scratch32, JavaConstant.forInt(-1), JavaConstant.forInt(-1)); - asm.emitStore(scratch32, deoptInfoAddr); - asm.emitString("ret;"); - - asm.emitString0("@L_StoreDeopt" + ":\n"); - - // Store deopt for this workitem into its slot in the HSAILComputeUnitSaveStates array - - asm.emitComment("// Convert id's for ptr math"); - asm.emitConvert(cuSaveAreaPtr, scratch32, wordKind, Kind.Int); - asm.emitComment("// multiply by sizeof KernelDeoptArea"); - asm.emit("mul", cuSaveAreaPtr, cuSaveAreaPtr, JavaConstant.forInt(sizeofKernelDeopt)); - asm.emitComment("// Add computed offset to deoptInfoPtr base"); - asm.emit("add", cuSaveAreaPtr, cuSaveAreaPtr, scratch64); - // Add offset to _deopt_save_states[0] - asm.emit("add", scratch64, cuSaveAreaPtr, JavaConstant.forInt(offsetToDeoptSaveStates)); - - HSAILAddress workItemAddr = new HSAILAddressValue(wordLIRKind, scratch64, offsetToDeoptimizationWorkItem).toAddress(); - HSAILAddress actionReasonStoreAddr = new HSAILAddressValue(wordLIRKind, scratch64, offsetToDeoptimizationReason).toAddress(); - - asm.emitComment("// Get _deopt_info._first_frame"); - asm.emit("add", waveMathScratch1, scratch64, JavaConstant.forInt(offsetToDeoptimizationFrame)); - // Now scratch64 is the _deopt_info._first_frame - HSAILAddress pcStoreAddr = new HSAILAddressValue(wordLIRKind, waveMathScratch1, offsetToFramePc).toAddress(); - HSAILAddress regCountsAddr = new HSAILAddressValue(wordLIRKind, waveMathScratch1, offsetToNumSaves).toAddress(); - asm.emitComment("// store deopting workitem"); - asm.emitWorkItemAbsId(scratch32); - asm.emitStore(Kind.Int, scratch32, workItemAddr); - asm.emitComment("// store actionAndReason"); - asm.emitStore(Kind.Int, actionAndReasonReg, actionReasonStoreAddr); - asm.emitComment("// store PC"); - asm.emitStore(Kind.Int, codeBufferOffsetReg, pcStoreAddr); - - asm.emitComment("// store regCounts (" + numSRegs + " $s registers, " + numDRegs + " $d registers, " + numStackSlots + " stack slots)"); - asm.emitStore(Kind.Int, JavaConstant.forInt(numSRegs + (numDRegs << 8) + (numStackSlots << 16)), regCountsAddr); - - /* - * Loop thru the usedValues storing each of the registers that are used. We always store - * in a fixed location, even if some registers are skipped. - */ - asm.emitComment("// store used regs"); - for (Register reg : infoUsedRegs) { - if (hsailRegConfig.isAllocatableSReg(reg)) { - // 32 bit registers - Kind kind = Kind.Int; - int ofst = offsetToSaveArea + reg.encoding * 4; - HSAILAddress addr = new HSAILAddressValue(wordLIRKind, waveMathScratch1, ofst).toAddress(); - AllocatableValue regValue = reg.asValue(LIRKind.value(kind)); - asm.emitStore(kind, regValue, addr); - } else if (hsailRegConfig.isAllocatableDReg(reg)) { - // 64 bit registers - Kind kind = Kind.Long; - // d reg ofst starts past the 32 sregs - int ofst = offsetToSaveArea + (numSRegs * 4) + reg.encoding * 8; - HSAILAddress addr = new HSAILAddressValue(wordLIRKind, waveMathScratch1, ofst).toAddress(); - AllocatableValue regValue = reg.asValue(LIRKind.value(kind)); - asm.emitStore(kind, regValue, addr); - } else { - throw GraalInternalError.unimplemented(); - } - } - - // loop thru the usedStackSlots creating instructions to save in the save area - if (numStackSlotBytes > 0) { - asm.emitComment("// store stack slots (uses " + numStackSlotBytes + " bytes)"); - for (StackSlot slot : infoUsedStackSlots) { - asm.emitComment("// store " + slot); - Kind kind = slot.getKind(); - int sizeInBits = (kind.isObject() || kind.getByteCount() == 8 ? 64 : 32); - int ofst = offsetToSaveArea + (numSRegs * 4) + (numDRegs * 8) + HSAIL.getStackOffsetStart(slot, sizeInBits); - HSAILAddress addr = new HSAILAddressValue(wordLIRKind, waveMathScratch1, ofst).toAddress(); - if (sizeInBits == 64) { - asm.emitSpillLoad(kind, scratch64, slot); - asm.emitStore(kind, scratch64, addr); - } else { - asm.emitSpillLoad(kind, scratch32, slot); - asm.emitStore(kind, scratch32, addr); - } - } - } - - asm.emitString0(labelExit + ":\n"); - - // and emit the return - crb.frameContext.leave(crb); - asm.exit(); - // build the oopMap Array - int[] oopMapArray = new OopMapArrayBuilder().build(infoList, numSRegs, numDRegs, numStackSlots, hsailRegConfig); - ((ExternalCompilationResult) crb.compilationResult).setOopMapArray(oopMapArray); - } else { - // Deoptimization is explicitly off, so emit simple return - asm.emitString0(asm.getDeoptLabelName() + ":\n"); - asm.emitComment("// No deoptimization"); - asm.emitString("ret;"); - } - - asm.emitString0("}; \n"); - - ExternalCompilationResult compilationResult = (ExternalCompilationResult) crb.compilationResult; - if (useHSAILDeoptimization) { - compilationResult.setHostGraph(prepareHostGraph(method, lirGenRes.getDeopts(), getProviders(), config, numSRegs, numDRegs)); - } - } - - private static class OopMapArrayBuilder { - // oopMapArray struct - // int bytesPerSaveArea; (not strictly part of oopsmap but convenient to put here) - // int intsPerInfopoint; - static final int SAVEAREACOUNTS_OFST = 0; - static final int INTSPERINFOPOINT_OFST = 1; - static final int HEADERSIZE = 2; - // for each infopoint: - // int deoptId - // one or more ints of bits for the oopmap - - private int[] array; - private int intsPerInfopoint; - - int[] build(List infoList, int numSRegs, int numDRegs, int numStackSlots, HSAILHotSpotRegisterConfig hsailRegConfig) { - /* - * We are told that infoList is always sorted. Each infoPoint can have a different - * oopMap. Since numStackSlots is the number of 8-byte stack slots used, it is an upper - * limit on the number of oop stack slots - */ - int bitsPerInfopoint = numDRegs + numStackSlots; - int intsForBits = (bitsPerInfopoint + 31) / 32; - int numInfopoints = infoList.size(); - intsPerInfopoint = intsForBits + 1; // +1 for the pcoffset - int arraySize = HEADERSIZE + (numInfopoints * intsPerInfopoint); - array = new int[arraySize]; - array[INTSPERINFOPOINT_OFST] = intsPerInfopoint; - // compute saveAreaCounts - int saveAreaCounts = (numSRegs & 0xff) + (numDRegs << 8) + (numStackSlots << 16); - array[SAVEAREACOUNTS_OFST] = saveAreaCounts; - - // loop thru the infoList - int infoIndex = 0; - for (Infopoint info : infoList) { - setOopMapPcOffset(infoIndex, info.pcOffset); - BytecodeFrame frame = info.debugInfo.frame(); - while (frame != null) { - for (int i = 0; i < frame.numLocals + frame.numStack; i++) { - JavaValue val = frame.values[i]; - if (val instanceof RegisterValue) { - Register reg = ((RegisterValue) val).getRegister(); - if (val.getKind().isObject()) { - assert (hsailRegConfig.isAllocatableDReg(reg)); - int bitIndex = reg.encoding(); - setOopMapBit(infoIndex, bitIndex); - } - } else if (val instanceof StackSlot) { - StackSlot slot = (StackSlot) val; - if (val.getKind().isObject()) { - assert (HSAIL.getStackOffsetStart(slot, 64) % 8 == 0); - int bitIndex = numDRegs + HSAIL.getStackOffsetStart(slot, 64) / 8; - setOopMapBit(infoIndex, bitIndex); - } - } - } - frame = frame.caller(); - } - infoIndex++; - } - try (Scope s = Debug.scope("CodeGen")) { - if (Debug.isLogEnabled()) { - Debug.log("numSRegs=%d, numDRegs=%d, numStackSlots=%d", numSRegs, numDRegs, numStackSlots); - // show infopoint oopmap details - for (infoIndex = 0; infoIndex < infoList.size(); infoIndex++) { - String infoString = "Infopoint " + infoIndex + ", pcOffset=" + getOopMapPcOffset(infoIndex) + ", oopmap="; - for (int i = 0; i < intsForBits; i++) { - infoString += (i != 0 ? ", " : "") + Integer.toHexString(getOopMapBitsAsInt(infoIndex, i)); - } - Debug.log(infoString); - } - } - } catch (Throwable e) { - throw Debug.handle(e); - } - - return array; - } - - private void setOopMapPcOffset(int infoIndex, int pcOffset) { - int arrIndex = HEADERSIZE + infoIndex * intsPerInfopoint; - array[arrIndex] = pcOffset; - } - - private int getOopMapPcOffset(int infoIndex) { - int arrIndex = HEADERSIZE + infoIndex * intsPerInfopoint; - return array[arrIndex]; - } - - private void setOopMapBit(int infoIndex, int bitIndex) { - int arrIndex = HEADERSIZE + infoIndex * intsPerInfopoint + 1 + bitIndex / 32; - array[arrIndex] |= (1 << (bitIndex % 32)); - } - - private int getOopMapBitsAsInt(int infoIndex, int intIndex) { - int arrIndex = HEADERSIZE + infoIndex * intsPerInfopoint + 1 + intIndex; - return array[arrIndex]; - } - } - - private static StructuredGraph prepareHostGraph(ResolvedJavaMethod method, List deopts, HotSpotProviders providers, HotSpotVMConfig config, int numSRegs, int numDRegs) { - if (deopts.isEmpty()) { - return null; - } - StructuredGraph hostGraph = new StructuredGraph(method, -2); - ParameterNode deoptId = hostGraph.unique(new ParameterNode(0, StampFactory.intValue())); - ParameterNode hsailFrame = hostGraph.unique(new ParameterNode(1, StampFactory.forKind(providers.getCodeCache().getTarget().wordKind))); - ParameterNode reasonAndAction = hostGraph.unique(new ParameterNode(2, StampFactory.intValue())); - ParameterNode speculation = hostGraph.unique(new ParameterNode(3, StampFactory.object())); - BeginNode[] branches = new BeginNode[deopts.size() + 1]; - int[] keys = new int[deopts.size()]; - int[] keySuccessors = new int[deopts.size() + 1]; - double[] keyProbabilities = new double[deopts.size() + 1]; - int i = 0; - Collections.sort(deopts, new Comparator() { - public int compare(DeoptimizingOp o1, DeoptimizingOp o2) { - return o1.getCodeBufferPos() - o2.getCodeBufferPos(); - } - }); - for (DeoptimizingOp deopt : deopts) { - keySuccessors[i] = i; - keyProbabilities[i] = 1.0 / deopts.size(); - keys[i] = deopt.getCodeBufferPos(); - assert keys[i] >= 0; - branches[i] = createHostDeoptBranch(deopt, hsailFrame, reasonAndAction, speculation, providers, config, numSRegs, numDRegs); - - i++; - } - keyProbabilities[deopts.size()] = 0; // default - keySuccessors[deopts.size()] = deopts.size(); - branches[deopts.size()] = createHostCrashBranch(hostGraph, deoptId); - IntegerSwitchNode switchNode = hostGraph.add(new IntegerSwitchNode(deoptId, branches, keys, keyProbabilities, keySuccessors)); - StartNode start = hostGraph.start(); - start.setNext(switchNode); - /* - * printf.setNext(printf2); printf2.setNext(switchNode); - */ - hostGraph.setGuardsStage(GuardsStage.AFTER_FSA); - return hostGraph; - } - - private static BeginNode createHostCrashBranch(StructuredGraph hostGraph, ValueNode deoptId) { - VMErrorNode vmError = hostGraph.add(new VMErrorNode("Error in HSAIL deopt. DeoptId=%d", deoptId)); - // ConvertNode.convert(hostGraph, Kind.Long, deoptId))); - vmError.setNext(hostGraph.add(new ReturnNode(ConstantNode.defaultForKind(hostGraph.method().getSignature().getReturnKind(), hostGraph)))); - return BeginNode.begin(vmError); - } - - private static BeginNode createHostDeoptBranch(DeoptimizingOp deopt, ParameterNode hsailFrame, ValueNode reasonAndAction, ValueNode speculation, HotSpotProviders providers, - HotSpotVMConfig config, int numSRegs, int numDRegs) { - BeginNode branch = hsailFrame.graph().add(new BeginNode()); - DynamicDeoptimizeNode deoptimization = hsailFrame.graph().add(new DynamicDeoptimizeNode(reasonAndAction, speculation)); - deoptimization.setStateBefore(createFrameState(deopt.getFrameState().topFrame, hsailFrame, providers, config, numSRegs, numDRegs)); - branch.setNext(deoptimization); - return branch; - } - - private static FrameState createFrameState(BytecodeFrame lowLevelFrame, ParameterNode hsailFrame, HotSpotProviders providers, HotSpotVMConfig config, int numSRegs, int numDRegs) { - return createFrameState(lowLevelFrame, hsailFrame, providers, config, numSRegs, numDRegs, new HashMap()); - } - - private static FrameState createFrameState(BytecodeFrame lowLevelFrame, ParameterNode hsailFrame, HotSpotProviders providers, HotSpotVMConfig config, int numSRegs, int numDRegs, - Map virtualObjects) { - FrameState outterFrameState = null; - if (lowLevelFrame.caller() != null) { - outterFrameState = createFrameState(lowLevelFrame.caller(), hsailFrame, providers, config, numSRegs, numDRegs, virtualObjects); - } - StructuredGraph hostGraph = hsailFrame.graph(); - Function lirValueToHirNode = v -> getNodeForValueFromFrame(v, hsailFrame, hostGraph, providers, config, numSRegs, numDRegs, virtualObjects); - ValueNode[] locals = new ValueNode[lowLevelFrame.numLocals]; - for (int i = 0; i < lowLevelFrame.numLocals; i++) { - locals[i] = lirValueToHirNode.apply(lowLevelFrame.getLocalValue(i)); - } - List stack = new ArrayList<>(lowLevelFrame.numStack); - for (int i = 0; i < lowLevelFrame.numStack; i++) { - stack.add(lirValueToHirNode.apply(lowLevelFrame.getStackValue(i))); - } - ValueNode[] locks = new ValueNode[lowLevelFrame.numLocks]; - MonitorIdNode[] monitorIds = new MonitorIdNode[lowLevelFrame.numLocks]; - for (int i = 0; i < lowLevelFrame.numLocks; i++) { - HotSpotMonitorValue lockValue = (HotSpotMonitorValue) lowLevelFrame.getLockValue(i); - locks[i] = lirValueToHirNode.apply(lockValue); - monitorIds[i] = getMonitorIdForHotSpotMonitorValueFromFrame(lockValue, hsailFrame, hostGraph); - } - FrameState frameState = hostGraph.add(new FrameState(null, lowLevelFrame.getMethod(), lowLevelFrame.getBCI(), locals, stack.toArray(new ValueNode[0]), stack.size(), locks, monitorIds, - lowLevelFrame.rethrowException, false)); - if (outterFrameState != null) { - frameState.setOuterFrameState(outterFrameState); - } - Map virtualObjectsCopy; - // TODO this could be implemented more efficiently with a mark into the map - // unfortunately LinkedHashMap doesn't seem to provide that. - List virtualStates = new ArrayList<>(virtualObjects.size()); - do { - virtualObjectsCopy = new HashMap<>(virtualObjects); - virtualStates.clear(); - for (Entry entry : virtualObjectsCopy.entrySet()) { - VirtualObject virtualObject = entry.getKey(); - VirtualObjectNode virtualObjectNode = entry.getValue(); - List fieldValues = Arrays.stream(virtualObject.getValues()).map(lirValueToHirNode).collect(Collectors.toList()); - virtualStates.add(new VirtualObjectState(virtualObjectNode, fieldValues)); - } - // New virtual objects may have been discovered while processing the previous set. - // Wait until a fixed point is reached - } while (virtualObjectsCopy.size() < virtualObjects.size()); - virtualStates.forEach(vos -> frameState.addVirtualObjectMapping(hostGraph.unique(vos))); - return frameState; - } - - @SuppressWarnings("unused") - private static MonitorIdNode getMonitorIdForHotSpotMonitorValueFromFrame(HotSpotMonitorValue lockValue, ParameterNode hsailFrame, StructuredGraph hsailGraph) { - if (lockValue.isEliminated()) { - return null; - } - throw GraalInternalError.unimplemented(); - } - - private static ValueNode getNodeForValueFromFrame(JavaValue localValue, ParameterNode hsailFrame, StructuredGraph hostGraph, HotSpotProviders providers, HotSpotVMConfig config, int numSRegs, - int numDRegs, Map virtualObjects) { - ValueNode valueNode; - if (localValue instanceof JavaConstant) { - valueNode = ConstantNode.forConstant((JavaConstant) localValue, providers.getMetaAccess(), hostGraph); - } else if (localValue instanceof VirtualObject) { - valueNode = getNodeForVirtualObjectFromFrame((VirtualObject) localValue, virtualObjects, hostGraph); - } else if (localValue instanceof StackSlot) { - StackSlot slot = (StackSlot) localValue; - valueNode = getNodeForStackSlotFromFrame(slot, localValue.getKind(), hsailFrame, hostGraph, providers, config, numSRegs, numDRegs); - } else if (localValue instanceof HotSpotMonitorValue) { - HotSpotMonitorValue hotSpotMonitorValue = (HotSpotMonitorValue) localValue; - return getNodeForValueFromFrame(hotSpotMonitorValue.getOwner(), hsailFrame, hostGraph, providers, config, numSRegs, numDRegs, virtualObjects); - } else if (localValue instanceof RegisterValue) { - RegisterValue registerValue = (RegisterValue) localValue; - int regNumber = registerValue.getRegister().number; - valueNode = getNodeForRegisterFromFrame(regNumber, localValue.getKind(), hsailFrame, hostGraph, providers, config, numSRegs); - } else if (Value.ILLEGAL.equals(localValue)) { - valueNode = null; - } else { - throw GraalInternalError.shouldNotReachHere(); - } - return valueNode; - } - - private static ValueNode getNodeForVirtualObjectFromFrame(VirtualObject virtualObject, Map virtualObjects, StructuredGraph hostGraph) { - return virtualObjects.computeIfAbsent(virtualObject, vo -> { - if (vo.getType().isArray()) { - return hostGraph.add(new VirtualArrayNode(vo.getType().getComponentType(), vo.getValues().length)); - } else { - return hostGraph.add(new VirtualInstanceNode(vo.getType(), true)); - } - }); - } - - private static ValueNode getNodeForRegisterFromFrame(int regNumber, Kind valueKind, ParameterNode hsailFrame, StructuredGraph hostGraph, HotSpotProviders providers, HotSpotVMConfig config, - int numSRegs) { - ValueNode valueNode; - LocationNode location; - int longSize = providers.getCodeCache().getTarget().arch.getSizeInBytes(Kind.Long); - int intSize = providers.getCodeCache().getTarget().arch.getSizeInBytes(Kind.Int); - if (regNumber >= HSAIL.s0.number && regNumber <= HSAIL.s31.number) { - long offset = config.hsailFrameHeaderSize + intSize * (regNumber - HSAIL.s0.number); - location = hostGraph.unique(new ConstantLocationNode(FINAL_LOCATION, offset)); - } else if (regNumber >= HSAIL.d0.number && regNumber <= HSAIL.d15.number) { - long offset = config.hsailFrameHeaderSize + intSize * numSRegs + longSize * (regNumber - HSAIL.d0.number); - location = hostGraph.unique(new ConstantLocationNode(FINAL_LOCATION, offset)); - } else { - throw GraalInternalError.shouldNotReachHere("unknown hsail register: " + regNumber); - } - valueNode = hostGraph.unique(new FloatingReadNode(hsailFrame, location, null, StampFactory.forKind(valueKind))); - return valueNode; - } - - private static ValueNode getNodeForStackSlotFromFrame(StackSlot slot, Kind valueKind, ParameterNode hsailFrame, StructuredGraph hostGraph, HotSpotProviders providers, HotSpotVMConfig config, - int numSRegs, int numDRegs) { - int slotSizeInBits = (valueKind == Kind.Object ? 64 : valueKind.getByteCount() * 8); - if ((slotSizeInBits == 32) || (slotSizeInBits == 64)) { - int longSize = providers.getCodeCache().getTarget().arch.getSizeInBytes(Kind.Long); - int intSize = providers.getCodeCache().getTarget().arch.getSizeInBytes(Kind.Int); - long offset = config.hsailFrameHeaderSize + (intSize * numSRegs) + (longSize * numDRegs) + HSAIL.getStackOffsetStart(slot, slotSizeInBits); - LocationNode location = hostGraph.unique(new ConstantLocationNode(FINAL_LOCATION, offset)); - ValueNode valueNode = hostGraph.unique(new FloatingReadNode(hsailFrame, location, null, StampFactory.forKind(valueKind))); - return valueNode; - } else { - throw GraalInternalError.shouldNotReachHere("unsupported stack slot kind: " + valueKind); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotBackendFactory.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2012, 2014, 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.hotspot.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.hsail.replacements.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hsail.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.phases.util.*; - -@ServiceProvider(HotSpotBackendFactory.class) -public class HSAILHotSpotBackendFactory implements HotSpotBackendFactory { - - protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, HotSpotForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, - TargetDescription target) { - return new HSAILHotSpotLoweringProvider(runtime, metaAccess, foreignCalls, registers, target); - } - - @Override - public HSAILHotSpotBackend createBackend(HotSpotGraalRuntimeProvider runtime, HotSpotBackend hostBackend) { - HotSpotProviders host = hostBackend.getProviders(); - - HotSpotRegisters registers = new HotSpotRegisters(HSAIL.threadRegister, Register.None, Register.None); - MetaAccessProvider metaAccess = host.getMetaAccess(); - TargetDescription target = createTarget(); - HSAILHotSpotCodeCacheProvider codeCache = new HSAILHotSpotCodeCacheProvider(runtime, target); - ConstantReflectionProvider constantReflection = host.getConstantReflection(); - HotSpotForeignCallsProvider foreignCalls = new HSAILHotSpotForeignCallsProvider(runtime, metaAccess, codeCache); - HotSpotLoweringProvider lowerer = createLowerer(runtime, metaAccess, foreignCalls, registers, target); - // Replacements cannot have speculative optimizations since they have - // to be valid for the entire run of the VM. - Assumptions assumptions = new Assumptions(false); - Providers p = new Providers(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, null, new HotSpotStampProvider()); - Replacements replacements = new HSAILHotSpotReplacementsImpl(p, host.getSnippetReflection(), assumptions, codeCache.getTarget(), host.getReplacements()); - HotSpotDisassemblerProvider disassembler = host.getDisassembler(); - SuitesProvider suites = new HotSpotSuitesProvider(runtime); - HotSpotProviders providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, disassembler, suites, registers, host.getSnippetReflection()); - - // pass registers info down to ReplacementsUtil (maybe a better way to do this?) - HSAILHotSpotReplacementsUtil.initialize(providers.getRegisters()); - - return new HSAILHotSpotBackend(runtime, providers); - } - - protected TargetDescription createTarget() { - final int stackFrameAlignment = 8; - final int implicitNullCheckLimit = 0; - final boolean inlineObjects = true; - return new HotSpotTargetDescription(new HSAIL(), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects); - } - - public String getArchitecture() { - return "HSAIL"; - } - - public String getGraalRuntimeName() { - return "basic"; - } - - @Override - public String toString() { - return getGraalRuntimeName() + ":" + getArchitecture(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotCodeCacheProvider.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -/* - * 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.hotspot.hsail; - -import java.util.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; - -public class HSAILHotSpotCodeCacheProvider extends HotSpotCodeCacheProvider { - - public HSAILHotSpotCodeCacheProvider(HotSpotGraalRuntimeProvider runtime, TargetDescription target) { - super(runtime, target, new HSAILHotSpotRegisterConfig()); - - } - - @Override - public String disassemble(CompilationResult compResult, InstalledCode installedCode) { - byte[] code = installedCode == null ? Arrays.copyOf(compResult.getTargetCode(), compResult.getTargetCodeSize()) : installedCode.getCode(); - return new String(code); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotForeignCallsProvider.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,66 +0,0 @@ -/* - * 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.hotspot.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; - -public class HSAILHotSpotForeignCallsProvider extends HotSpotForeignCallsProviderImpl { - - public HSAILHotSpotForeignCallsProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache) { - super(runtime, metaAccess, codeCache); - } - - @Override - public HotSpotForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor) { - // we don't really support foreign calls yet, but we do want to generate dummy code for them - // so we lazily create dummy linkages here. - if (foreignCalls.get(descriptor) == null) { - return register(new HotSpotForeignCallLinkageImpl(descriptor, 0x12345678, null, null, null, null, false, new LocationIdentity[0])); - } else { - return super.lookupForeignCall(descriptor); - } - } - - @Override - public boolean isReexecutable(ForeignCallDescriptor descriptor) { - return lookupForeignCall(descriptor).isReexecutable(); - } - - @Override - public LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor) { - return lookupForeignCall(descriptor).getKilledLocations(); - } - - @Override - public boolean canDeoptimize(ForeignCallDescriptor descriptor) { - return lookupForeignCall(descriptor).canDeoptimize(); - } - - public Value[] getNativeABICallerSaveRegisters() { - // TODO is this correct? - return new Value[0]; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerationResult.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerationResult.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2014, 2014, 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.hotspot.hsail; - -import java.util.*; - -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.hsail.HSAILControlFlow.DeoptimizingOp; - -public class HSAILHotSpotLIRGenerationResult extends LIRGenerationResultBase { - - private List deopts = new ArrayList<>(); - - public HSAILHotSpotLIRGenerationResult(LIR lir, FrameMapBuilder frameMapBuilder) { - super(lir, frameMapBuilder); - } - - public List getDeopts() { - return deopts; - } - - public void addDeopt(DeoptimizingOp deopt) { - deopts.add(deopt); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,300 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.hotspot.hsail; - -import static com.oracle.graal.api.code.ValueUtil.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.compiler.hsail.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.HotSpotVMConfig.CompressEncoding; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.SaveRegistersOp; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.hsail.*; -import com.oracle.graal.lir.hsail.HSAILControlFlow.CondMoveOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.DeoptimizeOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.ForeignCall1ArgOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.ForeignCall2ArgOp; -import com.oracle.graal.lir.hsail.HSAILControlFlow.ForeignCallNoArgOp; -import com.oracle.graal.lir.hsail.HSAILMove.CompareAndSwapOp; -import com.oracle.graal.lir.hsail.HSAILMove.LoadAcquireOp; -import com.oracle.graal.lir.hsail.HSAILMove.LoadOp; -import com.oracle.graal.lir.hsail.HSAILMove.MoveToRegOp; -import com.oracle.graal.lir.hsail.HSAILMove.StoreConstantOp; -import com.oracle.graal.lir.hsail.HSAILMove.StoreOp; -import com.oracle.graal.lir.hsail.HSAILMove.StoreReleaseOp; -import com.oracle.graal.lir.hsail.HSAILMove.WorkItemAbsIdOp; -import com.oracle.graal.phases.util.*; - -/** - * The HotSpot specific portion of the HSAIL LIR generator. - */ -public class HSAILHotSpotLIRGenerator extends HSAILLIRGenerator implements HotSpotLIRGenerator { - - final HotSpotVMConfig config; - - public HSAILHotSpotLIRGenerator(Providers providers, HotSpotVMConfig config, CallingConvention cc, LIRGenerationResult lirGenRes) { - super(new DefaultLIRKindTool(providers.getCodeCache().getTarget().wordKind), providers, cc, lirGenRes); - this.config = config; - } - - @Override - public HotSpotProviders getProviders() { - return (HotSpotProviders) super.getProviders(); - } - - int getLogMinObjectAlignment() { - return config.logMinObjAlignment(); - } - - int getNarrowOopShift() { - return config.narrowOopShift; - } - - long getNarrowOopBase() { - return config.narrowOopBase; - } - - int getLogKlassAlignment() { - return config.logKlassAlignment; - } - - int getNarrowKlassShift() { - return config.narrowKlassShift; - } - - long getNarrowKlassBase() { - return config.narrowKlassBase; - } - - private static boolean canStoreConstant(JavaConstant c) { - return !(c instanceof HotSpotObjectConstant); - } - - @Override - public boolean canInlineConstant(JavaConstant c) { - if (c instanceof HotSpotObjectConstant) { - return c.isNull(); - } else { - return super.canInlineConstant(c); - } - } - - @Override - public Variable emitLoad(LIRKind kind, Value address, LIRFrameState state) { - HSAILAddressValue loadAddress = asAddressValue(address); - Variable result = newVariable(kind); - append(new LoadOp((Kind) kind.getPlatformKind(), result, loadAddress, state)); - return result; - } - - public Variable emitLoadAcquire(LIRKind kind, Value address, LIRFrameState state) { - HSAILAddressValue loadAddress = asAddressValue(address); - Variable result = newVariable(kind); - append(new LoadAcquireOp((Kind) kind.getPlatformKind(), result, loadAddress, state)); - return result; - } - - @Override - public void emitStore(LIRKind kind, Value address, Value inputVal, LIRFrameState state) { - HSAILAddressValue storeAddress = asAddressValue(address); - if (isConstant(inputVal)) { - JavaConstant c = asConstant(inputVal); - if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(c)) { - c = JavaConstant.INT_0; - } - if (canStoreConstant(c)) { - append(new StoreConstantOp((Kind) kind.getPlatformKind(), storeAddress, c, state)); - return; - } - } - Variable input = load(inputVal); - append(new StoreOp((Kind) kind.getPlatformKind(), storeAddress, input, state)); - } - - public void emitStoreRelease(LIRKind kind, Value address, Value inputVal, LIRFrameState state) { - HSAILAddressValue storeAddress = asAddressValue(address); - // TODO: handle Constants here - Variable input = load(inputVal); - append(new StoreReleaseOp((Kind) kind.getPlatformKind(), storeAddress, input, state)); - } - - public Value emitCompareAndSwap(Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue) { - LIRKind kind = newValue.getLIRKind(); - assert kind.equals(expectedValue.getLIRKind()); - Kind memKind = (Kind) kind.getPlatformKind(); - - HSAILAddressValue addressValue = asAddressValue(address); - Variable expected = emitMove(expectedValue); - Variable casResult = newVariable(kind); - append(new CompareAndSwapOp(memKind, casResult, addressValue, expected, asAllocatable(newValue))); - - assert trueValue.getLIRKind().equals(falseValue.getLIRKind()); - Variable nodeResult = newVariable(trueValue.getLIRKind()); - append(new CondMoveOp(HSAILLIRGenerator.mapKindToCompareOp(memKind), casResult, expected, nodeResult, Condition.EQ, trueValue, falseValue)); - return nodeResult; - } - - @Override - public Value emitAtomicReadAndAdd(Value address, Value delta) { - LIRKind kind = delta.getLIRKind(); - Kind memKind = (Kind) kind.getPlatformKind(); - Variable result = newVariable(kind); - HSAILAddressValue addressValue = asAddressValue(address); - append(new HSAILMove.AtomicReadAndAddOp(memKind, result, addressValue, asAllocatable(delta))); - return result; - } - - @Override - public Value emitAtomicReadAndWrite(Value address, Value newValue) { - LIRKind kind = newValue.getLIRKind(); - Kind memKind = (Kind) kind.getPlatformKind(); - Variable result = newVariable(kind); - HSAILAddressValue addressValue = asAddressValue(address); - append(new HSAILMove.AtomicReadAndWriteOp(memKind, result, addressValue, asAllocatable(newValue))); - return result; - } - - @Override - public void emitDeoptimize(Value actionAndReason, Value failedSpeculation, LIRFrameState state) { - emitDeoptimizeInner(actionAndReason, state, "emitDeoptimize"); - } - - /*** - * We need 64-bit and 32-bit scratch registers for the codegen $s0 can be live at this block. - */ - private void emitDeoptimizeInner(Value actionAndReason, LIRFrameState lirFrameState, String emitName) { - DeoptimizeOp deopt = new DeoptimizeOp(actionAndReason, lirFrameState, emitName, config.useHSAILDeoptimization, getMetaAccess()); - ((HSAILHotSpotLIRGenerationResult) getResult()).addDeopt(deopt); - append(deopt); - } - - /*** - * This is a very temporary solution to emitForeignCall. We don't really support foreign calls - * yet, but we do want to generate dummy code for them. The ForeignCallXXXOps just end up - * emitting a comment as to what Foreign call they would have made. - */ - @Override - public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args) { - Variable result = newVariable(LIRKind.reference(Kind.Object)); // linkage.getDescriptor().getResultType()); - - // to make the LIRVerifier happy, we move any constants into registers - Value[] argLocations = new Value[args.length]; - for (int i = 0; i < args.length; i++) { - Value arg = args[i]; - AllocatableValue loc = newVariable(arg.getLIRKind()); - emitMove(loc, arg); - argLocations[i] = loc; - } - - // here we could check the callName if we wanted to only handle certain callnames - String callName = linkage.getDescriptor().getName(); - switch (argLocations.length) { - case 0: - append(new ForeignCallNoArgOp(callName, result)); - break; - case 1: - append(new ForeignCall1ArgOp(callName, result, argLocations[0])); - break; - case 2: - append(new ForeignCall2ArgOp(callName, result, argLocations[0], argLocations[1])); - break; - default: - throw new InternalError("NYI emitForeignCall " + callName + ", " + argLocations.length + ", " + linkage); - } - return result; - } - - @Override - protected HSAILLIRInstruction createMove(AllocatableValue dst, Value src) { - if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(src)) { - return new MoveToRegOp(Kind.Int, dst, JavaConstant.INT_0); - } else if (src instanceof HotSpotObjectConstant && ((HotSpotObjectConstant) src).isCompressed()) { - Variable uncompressed = newVariable(LIRKind.reference(Kind.Object)); - append(new MoveToRegOp(Kind.Object, uncompressed, src)); - CompressEncoding oopEncoding = config.getOopEncoding(); - return new HSAILMove.CompressPointer(dst, newVariable(LIRKind.reference(Kind.Object)), uncompressed, oopEncoding.base, oopEncoding.shift, oopEncoding.alignment, true); - } else { - return super.createMove(dst, src); - } - } - - @Override - protected void emitForeignCall(ForeignCallLinkage linkage, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { - // this version of emitForeignCall not used for now - } - - public void emitTailcall(Value[] args, Value address) { - throw GraalInternalError.unimplemented(); - } - - public void emitDeoptimizeCaller(DeoptimizationAction action, DeoptimizationReason reason) { - throw GraalInternalError.unimplemented(); - } - - public StackSlot getLockSlot(int lockDepth) { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitCompress(Value pointer, CompressEncoding encoding, boolean nonNull) { - Variable result = newVariable(pointer.getLIRKind().changeType(Kind.Int)); - append(new HSAILMove.CompressPointer(result, newVariable(pointer.getLIRKind()), asAllocatable(pointer), encoding.base, encoding.shift, encoding.alignment, nonNull)); - return result; - } - - @Override - public Value emitUncompress(Value pointer, CompressEncoding encoding, boolean nonNull) { - Variable result; - if (pointer.getLIRKind().isReference(0)) { - result = newVariable(LIRKind.reference(Kind.Object)); - } else { - result = newVariable(LIRKind.value(Kind.Long)); - } - append(new HSAILMove.UncompressPointer(result, asAllocatable(pointer), encoding.base, encoding.shift, encoding.alignment, nonNull)); - return result; - } - - public SaveRegistersOp emitSaveAllRegisters() { - throw GraalInternalError.unimplemented(); - } - - public void emitNullCheck(Value address, LIRFrameState state) { - assert address.getKind() == Kind.Object : address + " - " + address.getKind() + " not an object!"; - Variable obj = newVariable(LIRKind.reference(Kind.Object)); - emitMove(obj, address); - append(new HSAILMove.NullCheckOp(obj, state)); - } - - public Variable emitWorkItemAbsId() { - Variable result = newVariable(LIRKind.value(Kind.Int)); - append(new WorkItemAbsIdOp(result)); - return result; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLoweringProvider.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -/* - * 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.hotspot.hsail; - -import java.util.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.hsail.replacements.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.spi.*; - -public class HSAILHotSpotLoweringProvider extends DefaultHotSpotLoweringProvider { - - private HSAILNewObjectSnippets.Templates hsailNewObjectSnippets; - - abstract class LoweringStrategy { - abstract void lower(Node n, LoweringTool tool); - } - - final LoweringStrategy passThruStrategy = new LoweringStrategy() { - @Override - void lower(Node n, LoweringTool tool) { - return; - } - }; - - final LoweringStrategy rejectStrategy = new LoweringStrategy() { - @Override - void lower(Node n, LoweringTool tool) { - throw new GraalInternalError("Node implementing Lowerable not handled in HSAIL Backend: " + n); - } - }; - - final LoweringStrategy newObjectStrategy = new LoweringStrategy() { - @Override - void lower(Node n, LoweringTool tool) { - StructuredGraph graph = (StructuredGraph) n.graph(); - if (graph.getGuardsStage() == StructuredGraph.GuardsStage.AFTER_FSA) { - if (n instanceof NewInstanceNode) { - hsailNewObjectSnippets.lower((NewInstanceNode) n, tool); - } else if (n instanceof NewArrayNode) { - hsailNewObjectSnippets.lower((NewArrayNode) n, runtime, tool); - } - } - } - }; - - // strategy to replace an UnwindNode with a DeoptNode - final LoweringStrategy unwindNodeStrategy = new LoweringStrategy() { - @Override - void lower(Node n, LoweringTool tool) { - StructuredGraph graph = (StructuredGraph) n.graph(); - UnwindNode unwind = (UnwindNode) n; - ValueNode exception = unwind.exception(); - if (exception instanceof ForeignCallNode) { - // build up action and reason - String callName = ((ForeignCallNode) exception).getDescriptor().getName(); - DeoptimizationReason reason; - switch (callName) { - case "createOutOfBoundsException": - reason = DeoptimizationReason.BoundsCheckException; - break; - case "createNullPointerException": - reason = DeoptimizationReason.NullCheckException; - break; - default: - reason = DeoptimizationReason.None; - } - unwind.replaceAtPredecessor(graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, reason))); - unwind.safeDelete(); - } else { - // unwind whose exception is not an instance of ForeignCallNode - throw new GraalInternalError("UnwindNode seen without ForeignCallNode: " + exception); - } - } - }; - - private HashMap strategyMap = new HashMap<>(); - - void initStrategyMap() { - strategyMap.put(NodeClass.get(IntegerConvertNode.class), passThruStrategy); - strategyMap.put(NodeClass.get(FloatConvertNode.class), passThruStrategy); - strategyMap.put(NodeClass.get(NewInstanceNode.class), newObjectStrategy); - strategyMap.put(NodeClass.get(NewArrayNode.class), newObjectStrategy); - strategyMap.put(NodeClass.get(NewMultiArrayNode.class), rejectStrategy); - strategyMap.put(NodeClass.get(DynamicNewArrayNode.class), rejectStrategy); - strategyMap.put(NodeClass.get(MonitorEnterNode.class), rejectStrategy); - strategyMap.put(NodeClass.get(MonitorExitNode.class), rejectStrategy); - strategyMap.put(NodeClass.get(UnwindNode.class), unwindNodeStrategy); - } - - private LoweringStrategy getStrategy(Node n) { - return strategyMap.get(n.getNodeClass()); - } - - public HSAILHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers, - TargetDescription target) { - super(runtime, metaAccess, foreignCalls, registers, target); - initStrategyMap(); - } - - @Override - public void initialize(HotSpotProviders providers, HotSpotVMConfig config) { - super.initialize(providers, config); - hsailNewObjectSnippets = new HSAILNewObjectSnippets.Templates(providers, target); - } - - @Override - public void lower(Node n, LoweringTool tool) { - LoweringStrategy strategy = getStrategy(n); - // if not in map, let superclass handle it - if (strategy == null) { - super.lower(n, tool); - } else { - strategy.lower(n, tool); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotNodeLIRBuilder.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotNodeLIRBuilder.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.hotspot.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.hsail.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.hsail.*; -import com.oracle.graal.lir.hsail.HSAILMove.CompareAndSwapOp; -import com.oracle.graal.nodes.*; - -/** - * The HotSpot specific portion of the HSAIL LIR generator. - */ -public class HSAILHotSpotNodeLIRBuilder extends HSAILNodeLIRBuilder implements HotSpotNodeLIRBuilder { - - public HSAILHotSpotNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) { - super(graph, lirGen); - } - - @Override - protected void emitNode(ValueNode node) { - if (node instanceof CurrentJavaThreadNode) { - throw new GraalInternalError("HSAILHotSpotLIRGenerator cannot handle node: " + node); - } else { - super.emitNode(node); - } - } - - private HSAILHotSpotLIRGenerator getGen() { - return (HSAILHotSpotLIRGenerator) gen; - } - - public void visitDirectCompareAndSwap(DirectCompareAndSwapNode x) { - Variable expected = getGen().load(operand(x.expectedValue())); - Variable newVal = getGen().load(operand(x.newValue())); - - LIRKind kind = newVal.getLIRKind(); - assert kind.equals(expected.getLIRKind()); - - int disp = 0; - HSAILAddressValue address; - Value index = operand(x.offset()); - if (ValueUtil.isConstant(index) && NumUtil.isInt(ValueUtil.asConstant(index).asLong() + disp)) { - assert !getGen().getCodeCache().needsDataPatch(ValueUtil.asConstant(index)); - disp += (int) ValueUtil.asConstant(index).asLong(); - address = new HSAILAddressValue(kind, getGen().load(operand(x.object())), disp); - } else { - throw GraalInternalError.shouldNotReachHere("NYI"); - } - - Variable casResult = gen.newVariable(kind); - append(new CompareAndSwapOp((Kind) kind.getPlatformKind(), casResult, address, expected, newVal)); - - setResult(x, casResult); - } - - @Override - public void visitSafepointNode(SafepointNode i) { - HotSpotVMConfig config = getGen().config; - if ((config.useHSAILSafepoints == true) && (config.useHSAILDeoptimization == true)) { - LIRFrameState info = state(i); - HSAILHotSpotSafepointOp safepoint = new HSAILHotSpotSafepointOp(info, config, this); - ((HSAILHotSpotLIRGenerationResult) getGen().getResult()).addDeopt(safepoint); - append(safepoint); - } else { - Debug.log("HSAIL safepoints turned off"); - } - } - - @Override - public void emitPrefetchAllocate(ValueNode address, ValueNode distance) { - // nop - } - - @Override - public void emitPatchReturnAddress(ValueNode address) { - throw GraalInternalError.unimplemented(); - } - - @Override - public void emitJumpToExceptionHandlerInCaller(ValueNode handlerInCallerPc, ValueNode exception, ValueNode exceptionPc) { - throw GraalInternalError.unimplemented(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotRegisterConfig.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotRegisterConfig.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,200 +0,0 @@ -/* - * Copyright (c) 2009, 2014, 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.hotspot.hsail; - -import static com.oracle.graal.hsail.HSAIL.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.CallingConvention.Type; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.hsail.*; - -/** - * This class defines a higher level interface for the register allocator to be able to access info - * about the {@link HSAIL} register set. - * - * Note: In HSAIL, the number of registers of each type is actually a variable number that must - * satisfy the equation: Total num of registers = No. of S registers + 2 * (No. of D registers) + 4 - * * (No. of Q registers) = 128 In other words we can have up to 128S or 64 D or 32Q or a blend. - * - * For now we haven't implemented support for a variable sized register file. Instead we've fixed - * the number of registers of each type so that they satisfy the above equation. See {@link HSAIL} - * for more details. - */ -public class HSAILHotSpotRegisterConfig implements RegisterConfig { - - private final Register[] allocatable = {s0, s1, s2, s3, s4, s5, s6, /* s7, */s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31, - d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15}; - - private final Register[] regBitness32 = {s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31}; - private final Register[] regBitness64 = {d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15}; - private final RegisterAttributes[] attributesMap = RegisterAttributes.createMap(this, HSAIL.allRegisters); - - @Override - public Register getReturnRegister(Kind kind) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - return s0; - case Float: - case Double: - return d0; - case Void: - case Illegal: - return null; - default: - throw new UnsupportedOperationException("no return register for type " + kind); - } - } - - @Override - public Register getFrameRegister() { - // TODO Auto-generated method stub - return null; - } - - @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { - return callingConvention(regBitness32, regBitness64, returnType, parameterTypes, type, target, stackOnly); - } - - private CallingConvention callingConvention(Register[] generalParameterRegisters, Register[] longParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, - TargetDescription target, boolean stackOnly) { - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; - - int currentRegs32 = 0; - int currentRegs64 = 0; - int currentStackOffset = 0; - - for (int i = 0; i < parameterTypes.length; i++) { - final Kind kind = parameterTypes[i].getKind(); - - switch (kind) { - case Byte: - case Boolean: - case Short: - case Char: - case Int: - case Float: - - if (!stackOnly && currentRegs32 < generalParameterRegisters.length) { - Register register = generalParameterRegisters[currentRegs32++]; - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - case Long: - case Object: - case Double: - if (!stackOnly && currentRegs64 < longParameterRegisters.length) { - Register register = longParameterRegisters[currentRegs64++]; - locations[i] = register.asValue(target.getLIRKind(kind)); - } - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - - if (locations[i] == null) { - locations[i] = StackSlot.get(target.getLIRKind(kind.getStackKind()), currentStackOffset, !type.out); - currentStackOffset += Math.max(target.getSizeInBytes(kind), target.wordSize); - } - } - - Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); - AllocatableValue returnLocation = returnKind == Kind.Void ? Value.ILLEGAL : getReturnRegister(returnKind).asValue(target.getLIRKind(returnKind)); - return new CallingConvention(currentStackOffset, returnLocation, locations); - } - - @Override - public Register[] getCallingConventionRegisters(Type type, Kind kind) { - throw new GraalInternalError("getCallingConventinoRegisters unimplemented"); - } - - @Override - public Register[] getAllocatableRegisters() { - return allocatable.clone(); - } - - @Override - public Register[] getAllocatableRegisters(PlatformKind kind) { - switch ((Kind) kind) { - case Int: - case Short: - case Byte: - case Float: - return regBitness32.clone(); - case Long: - case Double: - case Object: - return regBitness64.clone(); - - default: - throw new GraalInternalError("unknown register allocation"); - } - } - - @Override - public Register[] getCallerSaveRegisters() { - // TODO Auto-generated method stub - return new Register[0]; - } - - @Override - public boolean areAllAllocatableRegistersCallerSaved() { - return false; - } - - @Override - public CalleeSaveLayout getCalleeSaveLayout() { - return null; - } - - @Override - public RegisterAttributes[] getAttributesMap() { - return attributesMap.clone(); - } - - @Override - public Register getRegisterForRole(int id) { - throw new UnsupportedOperationException(); - } - - public boolean isAllocatableSReg(Register reg) { - return (reg.number >= HSAIL.s0.number && reg.number <= HSAIL.s31.number); - } - - public boolean isAllocatableDReg(Register reg) { - return (reg.number >= HSAIL.d0.number && reg.number <= HSAIL.d15.number); - } - - public HSAILHotSpotRegisterConfig() { - - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotReplacementsImpl.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * 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.hotspot.hsail; - -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.hotspot.replacements.arraycopy.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.phases.util.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.hsail.*; - -/** - * The substitutions and snippets supported by HSAIL. - */ -public class HSAILHotSpotReplacementsImpl extends ReplacementsImpl { - - private final Replacements host; - private HashSet ignoredResolvedMethods = new HashSet<>(); - private HashMap arrayCopyRedirectMethods = new HashMap<>(); - - public HSAILHotSpotReplacementsImpl(Providers providers, SnippetReflectionProvider snippetReflection, Assumptions assumptions, TargetDescription target, Replacements host) { - super(providers, snippetReflection, assumptions, target); - this.host = host; - } - - public void addIgnoredResolvedMethod(Class cls, String methName, Class... params) { - try { - Method m = cls.getMethod(methName, params); - ResolvedJavaMethod rjm = providers.getMetaAccess().lookupJavaMethod(m); - ignoredResolvedMethods.add(rjm); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void completeInitialization() { - // Register the substitutions for java.lang.Math routines. - registerSubstitutions(Math.class, HSAILMathSubstitutions.class); - - // Register the ignored substitutions - addIgnoredResolvedMethod(String.class, "equals", Object.class); - - /* - * Register the special arraycopy snippet handling This basically ignores the sense of the - * CallArrayCopy flag and always directs to the snippets from UnsafeArrayCopyNode - */ - redirectArraycopySnippetMethod(Kind.Byte); - redirectArraycopySnippetMethod(Kind.Boolean); - redirectArraycopySnippetMethod(Kind.Char); - redirectArraycopySnippetMethod(Kind.Short); - redirectArraycopySnippetMethod(Kind.Int); - redirectArraycopySnippetMethod(Kind.Long); - redirectArraycopySnippetMethod(Kind.Float); - redirectArraycopySnippetMethod(Kind.Double); - redirectArraycopySnippetMethod(Kind.Object); - } - - private void redirectArraycopySnippetMethod(Kind kind) { - ResolvedJavaMethod foreignCallMethod = providers.getMetaAccess().lookupJavaMethod(ArrayCopySnippets.getSnippetForKind(kind, false, true)); - ResolvedJavaMethod nonForeignCallMethod = providers.getMetaAccess().lookupJavaMethod(ArrayCopySnippets.getSnippetForKind(kind, false, false)); - if (!foreignCallMethod.equals(nonForeignCallMethod)) { - arrayCopyRedirectMethods.put(foreignCallMethod, nonForeignCallMethod); - } - } - - @Override - protected ResolvedJavaMethod registerMethodSubstitution(ClassReplacements cr, Executable originalMethod, Method substituteMethod) { - // TODO: decide if we want to override this in any way - return super.registerMethodSubstitution(cr, originalMethod, substituteMethod); - } - - @Override - public Class getMacroSubstitution(ResolvedJavaMethod method) { - Class klass = super.getMacroSubstitution(method); - if (klass == null) { - /* - * Eventually we want to only defer certain macro substitutions to the host, but for now - * we will do everything. - */ - return host.getMacroSubstitution(method); - } - return klass; - } - - @Override - public StructuredGraph getSnippet(ResolvedJavaMethod method, ResolvedJavaMethod recursiveEntry) { - /* - * Must work in cooperation with HSAILHotSpotLoweringProvider. Before asking for the host - * snippet, see if it is one of the arraycopy methods which we want to redirect to the - * non-foreign-call version, regardless of the sense of CallArrayCopy option - */ - ResolvedJavaMethod snippetMethod = method; - ResolvedJavaMethod snippetRecursiveEntry = recursiveEntry; - ResolvedJavaMethod redirect = arrayCopyRedirectMethods.get(method); - if (redirect != null) { - snippetMethod = redirect; - if (recursiveEntry != null && recursiveEntry.equals(method)) { - snippetRecursiveEntry = redirect; - } - } - return host.getSnippet(snippetMethod, snippetRecursiveEntry); - } - - @Override - public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) { - StructuredGraph m = super.getMethodSubstitution(original); - if (m == null) { - /* - * We check for a few special cases we do NOT want to defer here but basically we defer - * everything else to the host. - */ - if (ignoredResolvedMethods.contains(original)) { - return null; - } else { - return host.getMethodSubstitution(original); - } - } - return m; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotSafepointOp.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotSafepointOp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.hotspot.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hsail.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.hsail.*; -import com.oracle.graal.nodes.spi.*; - -/** - * Emits a safepoint deoptimization from HSA back to CPU. - */ -@Opcode("SAFEPOINT") -public class HSAILHotSpotSafepointOp extends HSAILLIRInstruction implements HSAILControlFlow.DeoptimizingOp { - private JavaConstant actionAndReason; - @State protected LIRFrameState frameState; - protected int codeBufferPos = -1; - final int offsetToNoticeSafepoints; - final HotSpotVMConfig config; - - public HSAILHotSpotSafepointOp(LIRFrameState state, HotSpotVMConfig config, NodeLIRBuilderTool tool) { - actionAndReason = tool.getLIRGeneratorTool().getMetaAccess().encodeDeoptActionAndReason(DeoptimizationAction.None, DeoptimizationReason.None, 0); - frameState = state; - offsetToNoticeSafepoints = config.hsailNoticeSafepointsOffset; - this.config = config; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - if (config.useHSAILDeoptimization) { - // get a unique codeBuffer position - // when we save our state, we will save this as well (it can be used as a key to get the - // debugInfo) - codeBufferPos = masm.position(); - - masm.emitComment(" /* HSAIL safepoint bci=" + frameState.debugInfo().getBytecodePosition().getBCI() + ", frameState=" + frameState + " */"); - String afterSafepointLabel = "@LAfterSafepoint_at_pos_" + codeBufferPos; - - AllocatableValue scratch64 = HSAIL.d16.asValue(LIRKind.reference(Kind.Object)); - AllocatableValue spAddrReg = HSAIL.d17.asValue(LIRKind.reference(Kind.Object)); - AllocatableValue scratch32 = HSAIL.s34.asValue(LIRKind.value(Kind.Int)); - masm.emitLoadKernelArg(scratch64, masm.getDeoptInfoName(), "u64"); - - // Build address of noticeSafepoints field - HSAILAddress noticeSafepointsAddr = new HSAILAddressValue(LIRKind.value(Kind.Long), scratch64, offsetToNoticeSafepoints).toAddress(); - masm.emitLoad(Kind.Object, spAddrReg, noticeSafepointsAddr); - - // Load int value from that field - HSAILAddress noticeSafepointsIntAddr = new HSAILAddressValue(LIRKind.value(Kind.Long), spAddrReg, 0).toAddress(); - masm.emitLoadAcquire(scratch32, noticeSafepointsIntAddr); - masm.emitCompare(Kind.Int, scratch32, JavaConstant.forInt(0), "eq", false, false); - masm.cbr(afterSafepointLabel); - - AllocatableValue actionAndReasonReg = HSAIL.actionAndReasonReg.asValue(LIRKind.value(Kind.Int)); - AllocatableValue codeBufferOffsetReg = HSAIL.codeBufferOffsetReg.asValue(LIRKind.value(Kind.Int)); - masm.emitMov(Kind.Int, actionAndReasonReg, actionAndReason); - masm.emitMov(Kind.Int, codeBufferOffsetReg, JavaConstant.forInt(codeBufferPos)); - masm.emitJumpToLabelName(masm.getDeoptLabelName()); - - masm.emitString0(afterSafepointLabel + ":\n"); - - // now record the debuginfo - crb.recordInfopoint(codeBufferPos, frameState, InfopointReason.SAFEPOINT); - } else { - masm.emitComment("/* HSAIL safepoint would have been here. */"); - } - } - - public LIRFrameState getFrameState() { - return frameState; - } - - public int getCodeBufferPos() { - return codeBufferPos; - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILDirectLoadAcquireNode.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILDirectLoadAcquireNode.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.hotspot.hsail.replacements; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.hsail.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.nodes.*; -import com.oracle.graal.word.*; - -// JaCoCo Exclude -@NodeInfo -public class HSAILDirectLoadAcquireNode extends DirectReadNode { - - public HSAILDirectLoadAcquireNode(ValueNode address, Kind readKind) { - super(address, readKind); - } - - @Override - public void generate(NodeLIRBuilderTool gen) { - HSAILHotSpotLIRGenerator hsailgen = (HSAILHotSpotLIRGenerator) (gen.getLIRGeneratorTool()); - LIRKind kind = hsailgen.getLIRKind(stamp()); - Value result = hsailgen.emitLoadAcquire(kind, gen.operand(getAddress()), null); - gen.setResult(this, result); - } - - @NodeIntrinsic - public static native long loadAcquire(long address, @ConstantNodeParameter Kind kind); - - public static long loadAcquireLong(Word address) { - return loadAcquire(address.rawValue(), Kind.Long); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILDirectStoreReleaseNode.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILDirectStoreReleaseNode.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.hotspot.hsail.replacements; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.hsail.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.replacements.nodes.*; -import com.oracle.graal.word.*; - -// JaCoCo Exclude -@NodeInfo -public class HSAILDirectStoreReleaseNode extends DirectStoreNode { - - public HSAILDirectStoreReleaseNode(ValueNode address, ValueNode value, Kind kind) { - super(address, value, kind); - } - - @Override - public void generate(NodeLIRBuilderTool gen) { - HSAILHotSpotLIRGenerator hsailgen = (HSAILHotSpotLIRGenerator) (gen.getLIRGeneratorTool()); - Value v = gen.operand(getValue()); - LIRKind lirKind = hsailgen.getLIRKind(getValue().stamp()); - hsailgen.emitStoreRelease(lirKind, gen.operand(getAddress()), v, null); - } - - @NodeIntrinsic - public static native void storeRelease(long address, long value, @ConstantNodeParameter Kind kind); - - public static void storeReleaseLong(Word address, long value) { - storeRelease(address.rawValue(), value, Kind.Long); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILHotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILHotSpotReplacementsUtil.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2012, 2014, 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.hotspot.hsail.replacements; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.replacements.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.word.*; - -//JaCoCo Exclude - -/** - * A collection of methods used in HSAIL-specific snippets and substitutions. - */ -public class HSAILHotSpotReplacementsUtil extends HotSpotReplacementsUtil { - - private static HotSpotRegistersProvider hsailRegisters; - - public static void initialize(HotSpotRegistersProvider registers) { - hsailRegisters = registers; - } - - public static final LocationIdentity TLAB_INFO_LOCATION = NamedLocationIdentity.mutable("TlabInfo"); - public static final LocationIdentity TLABINFO_LASTGOODTOP_LOCATION = NamedLocationIdentity.mutable("TlabInfoLastGoodTop"); - public static final LocationIdentity TLABINFO_END_LOCATION = NamedLocationIdentity.mutable("TlabInfoEnd"); - public static final LocationIdentity TLABINFO_TOP_LOCATION = NamedLocationIdentity.mutable("TlabInfoTop"); - public static final LocationIdentity TLABINFO_START_LOCATION = NamedLocationIdentity.mutable("TlabInfoStart"); - public static final LocationIdentity TLABINFO_ALLOCINFO_LOCATION = NamedLocationIdentity.mutable("TlabInfoAllocInfo"); - public static final LocationIdentity TLABINFO_ORIGINALTOP_LOCATION = NamedLocationIdentity.mutable("TlabInfoOriginalTop"); - public static final LocationIdentity TLABINFO_TLAB_LOCATION = NamedLocationIdentity.mutable("TlabInfoTlab"); - - public static final LocationIdentity ALLOCINFO_TLABINFOSPOOLNEXT_LOCATION = NamedLocationIdentity.mutable("AllocInfoTlabInfosPoolNext"); - public static final LocationIdentity ALLOCINFO_TLABINFOSPOOLEND_LOCATION = NamedLocationIdentity.mutable("AllocInfoTlabInfosPoolEnd"); - public static final LocationIdentity ALLOCINFO_TLABALIGNRESERVEBYTES_LOCATION = NamedLocationIdentity.mutable("AllocInfoTlabAlignreservebytes"); - - /** - * Gets the value of the thread register as a Word. There is a level of indirection here. Thread - * register actually points to a holder for tlab info. - */ - public static Word getTlabInfoPtr() { - Word threadRegAsWord = registerAsWord(threadRegister(), true, false); - return threadRegAsWord.readWord(0, TLAB_INFO_LOCATION); - } - - public static Word getTlabInfoPtrLoadAcquire() { - Word threadRegAsWord = registerAsWord(threadRegister(), true, false); - return Word.unsigned(HSAILDirectLoadAcquireNode.loadAcquireLong(threadRegAsWord)); - } - - public static void writeTlabInfoPtrStoreRelease(Word val) { - // this only gets done in the waiting loop so we will always use Store Release - Word threadRegAsWord = registerAsWord(threadRegister(), true, false); - HSAILDirectStoreReleaseNode.storeReleaseLong(threadRegAsWord, val.rawValue()); - } - - @Fold - public static Register threadRegister() { - return hsailRegisters.getThreadRegister(); - } - - public static Word atomicGetAndAddTlabInfoTop(Word tlabInfo, int delta) { - return Word.unsigned(AtomicReadAndAddNode.getAndAddLong(null, tlabInfo.rawValue() + config().hsailTlabInfoTopOffset, delta, TLABINFO_TOP_LOCATION)); - } - - public static Word readTlabInfoEnd(Word tlabInfo) { - return tlabInfo.readWord(config().hsailTlabInfoEndOffset, TLABINFO_END_LOCATION); - } - - public static Word readTlabInfoStart(Word tlabInfo) { - return tlabInfo.readWord(config().hsailTlabInfoStartOffset, TLABINFO_START_LOCATION); - } - - public static void writeTlabInfoLastGoodTop(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoLastGoodTopOffset, val, TLABINFO_LASTGOODTOP_LOCATION); - } - - public static void writeTlabInfoStart(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoStartOffset, val, TLABINFO_START_LOCATION); - } - - public static void writeTlabInfoTop(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoTopOffset, val, TLABINFO_TOP_LOCATION); - } - - public static void writeTlabInfoEnd(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoEndOffset, val, TLABINFO_END_LOCATION); - } - - public static Word readTlabInfoAllocInfo(Word tlabInfo) { - return tlabInfo.readWord(config().hsailTlabInfoAllocInfoOffset, TLABINFO_ALLOCINFO_LOCATION); - } - - public static void writeTlabInfoAllocInfo(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoAllocInfoOffset, val, TLABINFO_ALLOCINFO_LOCATION); - } - - public static void writeTlabInfoOriginalTop(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoOriginalTopOffset, val, TLABINFO_ORIGINALTOP_LOCATION); - } - - public static void writeTlabInfoTlab(Word tlabInfo, Word val) { - tlabInfo.writeWord(config().hsailTlabInfoTlabOffset, val, TLABINFO_TLAB_LOCATION); - } - - public static Word readTlabInfoTlab(Word tlabInfo) { - return tlabInfo.readWord(config().hsailTlabInfoTlabOffset, TLABINFO_TLAB_LOCATION); - } - - public static Word readAllocInfoTlabInfosPoolEnd(Word allocInfo) { - return allocInfo.readWord(config().hsailAllocInfoTlabInfosPoolEndOffset, ALLOCINFO_TLABINFOSPOOLEND_LOCATION); - } - - public static Word readAllocInfoTlabAlignReserveBytes(Word allocInfo) { - return allocInfo.readWord(config().hsailAllocInfoTlabAlignReserveBytesOffset, ALLOCINFO_TLABALIGNRESERVEBYTES_LOCATION); - } - - public static Word atomicGetAndAddAllocInfoTlabInfosPoolNext(Word allocInfo, int delta) { - return Word.unsigned(AtomicReadAndAddNode.getAndAddLong(null, allocInfo.rawValue() + config().hsailAllocInfoTlabInfosPoolNextOffset, delta, ALLOCINFO_TLABINFOSPOOLNEXT_LOCATION)); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILNewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILNewObjectSnippets.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,348 +0,0 @@ -/* - * Copyright (c) 2012, 2014, 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.hotspot.hsail.replacements; - -import static com.oracle.graal.api.code.UnsignedMath.*; -import static com.oracle.graal.compiler.common.GraalOptions.*; -import static com.oracle.graal.hotspot.hsail.replacements.HSAILHotSpotReplacementsUtil.*; -import static com.oracle.graal.hotspot.hsail.replacements.HSAILNewObjectSnippets.Options.*; -import static com.oracle.graal.nodes.PiArrayNode.*; -import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; -import static com.oracle.graal.replacements.SnippetTemplate.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.type.*; -import com.oracle.graal.hotspot.replacements.*; -import com.oracle.graal.hotspot.stubs.*; -import com.oracle.graal.hotspot.word.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.options.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.Snippet.ConstantParameter; -import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates; -import com.oracle.graal.replacements.SnippetTemplate.Arguments; -import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo; -import com.oracle.graal.word.*; - -/** - * HSAIL-specific Snippets used for implementing NEW and NEWARRAY. - */ -public class HSAILNewObjectSnippets extends NewObjectSnippets { - - public static class Options { - - // @formatter:off - @Option(help = "In HSAIL allocation, allow allocation from eden as fallback if TLAB is full", type = OptionType.Debug) - static final OptionValue HsailUseEdenAllocate = new OptionValue<>(false); - - @Option(help = "In HSAIL allocation, allow GPU to allocate a new tlab if TLAB is full", type = OptionType.Debug) - static final OptionValue HsailNewTlabAllocate = new OptionValue<>(true); - - @Option(help = "Estimate of number of bytes allocated by each HSAIL workitem, used to size TLABs", type = OptionType.Debug) - public static final OptionValue HsailAllocBytesPerWorkitem = new OptionValue<>(64); - - // @formatter:on - } - - private static final boolean hsailUseEdenAllocate = HsailUseEdenAllocate.getValue(); - private static final boolean hsailNewTlabAllocate = HsailNewTlabAllocate.getValue(); - - protected static Word fillNewTlabInfoWithTlab(Word oldTlabInfo) { - Word allocInfo = readTlabInfoAllocInfo(oldTlabInfo); - Word newTlabInfo = atomicGetAndAddAllocInfoTlabInfosPoolNext(allocInfo, config().hsailTlabInfoSize); - Word tlabInfosPoolEnd = readAllocInfoTlabInfosPoolEnd(allocInfo); - if (newTlabInfo.aboveOrEqual(tlabInfosPoolEnd)) { - // could not get a new tlab info, mark zero and we will later deoptimize - return (Word.zero()); - } - - // make new size depend on old tlab size - Word newTlabSize = readTlabInfoEnd(oldTlabInfo).subtract(readTlabInfoStart(oldTlabInfo)); - // try to allocate a new tlab - Word tlabStart = NewInstanceStub.edenAllocate(newTlabSize, false); - writeTlabInfoStart(newTlabInfo, tlabStart); // write this field even if zero - if (tlabStart.equal(0)) { - // could not get a new tlab, mark zero and we will later deoptimize - return (Word.zero()); - } - // here we have a new tlab and a tlabInfo, we can fill it in - writeTlabInfoTop(newTlabInfo, tlabStart); - writeTlabInfoOriginalTop(newTlabInfo, tlabStart); - // set end so that we leave space for the tlab "alignment reserve" - Word alignReserveBytes = readAllocInfoTlabAlignReserveBytes(allocInfo); - writeTlabInfoEnd(newTlabInfo, tlabStart.add(newTlabSize.subtract(alignReserveBytes))); - writeTlabInfoAllocInfo(newTlabInfo, allocInfo); - writeTlabInfoTlab(newTlabInfo, readTlabInfoTlab(oldTlabInfo)); - return (newTlabInfo); - } - - protected static Word allocateFromTlabSlowPath(Word fastPathTlabInfo, int size, Word fastPathTop, Word fastPathEnd) { - // eventually this will be a separate call, not inlined - - // we come here from the fastpath allocation - // here we know that the tlab has overflowed (top + size > end) - // find out if we are the first overflower - Word tlabInfo = fastPathTlabInfo; - Word top = fastPathTop; - Word end = fastPathEnd; - - // start a loop where we try to get a new tlab and then try to allocate from it - // keep doing this until we run out of tlabs or tlabInfo structures - // initialize result with error return value - Word result = Word.zero(); - while (result.equal(Word.zero()) && tlabInfo.notEqual(Word.zero())) { - boolean firstOverflower = top.belowOrEqual(end); - if (firstOverflower) { - // store the last good top before overflow into last_good_top field - // we will move it back into top later when back in the VM - writeTlabInfoLastGoodTop(tlabInfo, top); - } - - // if all this allocate tlab from gpu logic is disabled, - // just immediately set tlabInfo to 0 here - if (!hsailNewTlabAllocate) { - tlabInfo = Word.zero(); - } else { - // loop here waiting for the first overflower to get a new tlab - // note that on an hsa device we must be careful how we loop in order to ensure - // "forward progress". For example we must not break out of the loop. - Word oldTlabInfo = tlabInfo; - do { - if (firstOverflower) { - // allocate new tlabInfo and new tlab to fill it, returning 0 if any - // problems - // this will get all spinners out of this loop. - tlabInfo = fillNewTlabInfoWithTlab(oldTlabInfo); - writeTlabInfoPtrStoreRelease(tlabInfo); - } else { - tlabInfo = getTlabInfoPtrLoadAcquire(); - } - } while (tlabInfo.equal(oldTlabInfo)); - // when we get out of the loop if tlabInfoPtr contains 0, it means we - // can't get any more tlabs and will have to deoptimize - // otherwise, we have a valid new tlabInfo/tlab and can try to allocate again. - if (tlabInfo.notEqual(0)) { - top = atomicGetAndAddTlabInfoTop(tlabInfo, size); - end = readTlabInfoEnd(tlabInfo); - Word newTop = top.add(size); - if (probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) { - result = top; - } - } - } - } // while (result == 0) && (tlabInfo != 0)) - return result; - } - - protected static Object addressToFormattedObject(Word addr, @ConstantParameter int size, KlassPointer hub, Word prototypeMarkWord, @ConstantParameter boolean fillContents, - @ConstantParameter String typeContext) { - Object result = formatObject(hub, size, addr, prototypeMarkWord, fillContents, true, true); - profileAllocation("instance", size, typeContext); - return piCast(verifyOop(result), StampFactory.forNodeIntrinsic()); - } - - @Snippet - public static Object allocateInstanceAtomic(@ConstantParameter int size, KlassPointer hub, Word prototypeMarkWord, @ConstantParameter boolean fillContents, @ConstantParameter String typeContext) { - boolean haveResult = false; - if (useTLAB()) { - // inlining this manually here because it resulted in better fastpath codegen - Word tlabInfo = getTlabInfoPtr(); - if (probability(FAST_PATH_PROBABILITY, tlabInfo.notEqual(0))) { - Word top = atomicGetAndAddTlabInfoTop(tlabInfo, size); - Word end = readTlabInfoEnd(tlabInfo); - Word newTop = top.add(size); - if (probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) { - return addressToFormattedObject(top, size, hub, prototypeMarkWord, fillContents, typeContext); - } else { - Word addr = allocateFromTlabSlowPath(tlabInfo, size, top, end); - if (addr.notEqual(0)) { - return addressToFormattedObject(addr, size, hub, prototypeMarkWord, fillContents, typeContext); - } - } - } - } - - // we could not allocate from tlab, try allocating directly from eden - if (hsailUseEdenAllocate) { - // false for no logging - Word addr = NewInstanceStub.edenAllocate(Word.unsigned(size), false); - if (addr.notEqual(0)) { - new_eden.inc(); - return addressToFormattedObject(addr, size, hub, prototypeMarkWord, fillContents, typeContext); - } - } - // haveResult test here helps avoid dropping earlier stores were seen to be dropped without - // this. - if (!haveResult) { - DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); - } - // will never get here but this keeps the compiler happy - return Word.zero().toObject(); - } - - @Snippet - public static Object allocateArrayAtomic(KlassPointer hub, int length, Word prototypeMarkWord, @ConstantParameter int headerSize, @ConstantParameter int log2ElementSize, - @ConstantParameter boolean fillContents, @ConstantParameter boolean maybeUnroll, @ConstantParameter String typeContext) { - if (!belowThan(length, MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH)) { - // This handles both negative array sizes and very large array sizes - DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); - } - return allocateArrayAtomicImpl(hub, length, prototypeMarkWord, headerSize, log2ElementSize, fillContents, maybeUnroll, typeContext); - } - - protected static Object addressToFormattedArray(Word addr, int allocationSize, int length, int headerSize, KlassPointer hub, Word prototypeMarkWord, boolean fillContents, boolean maybeUnroll, - @ConstantParameter String typeContext) { - // we are not in a stub so we can set useSnippetCounters to true - Object result = formatArray(hub, allocationSize, length, headerSize, addr, prototypeMarkWord, fillContents, maybeUnroll, true); - profileAllocation("array", allocationSize, typeContext); - return piArrayCast(verifyOop(result), length, StampFactory.forNodeIntrinsic()); - } - - private static Object allocateArrayAtomicImpl(KlassPointer hub, int length, Word prototypeMarkWord, int headerSize, int log2ElementSize, boolean fillContents, boolean maybeUnroll, - String typeContext) { - int alignment = wordSize(); - int allocationSize = computeArrayAllocationSize(length, alignment, headerSize, log2ElementSize); - boolean haveResult = false; - if (useTLAB()) { - // inlining this manually here because it resulted in better fastpath codegen - Word tlabInfo = getTlabInfoPtr(); - if (probability(FAST_PATH_PROBABILITY, tlabInfo.notEqual(0))) { - Word top = atomicGetAndAddTlabInfoTop(tlabInfo, allocationSize); - Word end = readTlabInfoEnd(tlabInfo); - Word newTop = top.add(allocationSize); - if (probability(FAST_PATH_PROBABILITY, newTop.belowOrEqual(end))) { - return addressToFormattedArray(top, allocationSize, length, headerSize, hub, prototypeMarkWord, fillContents, maybeUnroll, typeContext); - } else { - Word addr = allocateFromTlabSlowPath(tlabInfo, allocationSize, top, end); - if (addr.notEqual(0)) { - return addressToFormattedArray(addr, allocationSize, length, headerSize, hub, prototypeMarkWord, fillContents, maybeUnroll, typeContext); - } - } - } - } - - // we could not allocate from tlab, try allocating directly from eden - if (hsailUseEdenAllocate) { - // false for no logging - Word addr = NewInstanceStub.edenAllocate(Word.unsigned(allocationSize), false); - if (addr.notEqual(0)) { - newarray_eden.inc(); - return addressToFormattedArray(addr, allocationSize, length, headerSize, hub, prototypeMarkWord, fillContents, maybeUnroll, typeContext); - } - } - if (!haveResult) { - DeoptimizeNode.deopt(DeoptimizationAction.None, DeoptimizationReason.RuntimeConstraint); - } - // will never get here but this keeps the compiler happy - return Word.zero().toObject(); - } - - public static class Templates extends AbstractTemplates { - - private final SnippetInfo allocateInstance = snippet(HSAILNewObjectSnippets.class, "allocateInstanceAtomic"); - private final SnippetInfo allocateArray = snippet(HSAILNewObjectSnippets.class, "allocateArrayAtomic"); - - // private final SnippetInfo allocateArrayDynamic = snippet(NewObjectSnippets.class, - // "allocateArrayDynamic"); - // private final SnippetInfo newmultiarray = snippet(NewObjectSnippets.class, - // "newmultiarray"); - - public Templates(HotSpotProviders providers, TargetDescription target) { - super(providers, providers.getSnippetReflection(), target); - } - - /** - * Lowers a {@link NewInstanceNode}. - */ - public void lower(NewInstanceNode newInstanceNode, LoweringTool tool) { - StructuredGraph graph = newInstanceNode.graph(); - HotSpotResolvedObjectType type = (HotSpotResolvedObjectType) newInstanceNode.instanceClass(); - assert !type.isArray(); - ConstantNode hub = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), type.klass(), providers.getMetaAccess(), graph); - int size = instanceSize(type); - - Arguments args = new Arguments(allocateInstance, graph.getGuardsStage(), tool.getLoweringStage()); - args.addConst("size", size); - args.add("hub", hub); - args.add("prototypeMarkWord", type.prototypeMarkWord()); - args.addConst("fillContents", newInstanceNode.fillContents()); - args.addConst("typeContext", type.toJavaName(false)); - - SnippetTemplate template = template(args); - Debug.log("Lowering allocateInstance in %s: node=%s, template=%s, arguments=%s", graph, newInstanceNode, template, args); - template.instantiate(providers.getMetaAccess(), newInstanceNode, DEFAULT_REPLACER, args); - } - - /** - * Lowers a {@link NewArrayNode}. - */ - public void lower(NewArrayNode newArrayNode, HotSpotGraalRuntimeProvider runtime, LoweringTool tool) { - StructuredGraph graph = newArrayNode.graph(); - ResolvedJavaType elementType = newArrayNode.elementType(); - HotSpotResolvedObjectType arrayType = (HotSpotResolvedObjectType) elementType.getArrayClass(); - Kind elementKind = elementType.getKind(); - ConstantNode hub = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), arrayType.klass(), providers.getMetaAccess(), graph); - final int headerSize = runtime.getArrayBaseOffset(elementKind); - // lowerer extends HotSpotLoweringProvider so we can just use that - HotSpotLoweringProvider lowerer = (HotSpotLoweringProvider) providers.getLowerer(); - int log2ElementSize = CodeUtil.log2(lowerer.arrayScalingFactor(elementKind)); - - Arguments args = new Arguments(allocateArray, graph.getGuardsStage(), tool.getLoweringStage()); - args.add("hub", hub); - ValueNode length = newArrayNode.length(); - args.add("length", length.isAlive() ? length : graph.addOrUniqueWithInputs(length)); - args.add("prototypeMarkWord", arrayType.prototypeMarkWord()); - args.addConst("headerSize", headerSize); - args.addConst("log2ElementSize", log2ElementSize); - args.addConst("fillContents", newArrayNode.fillContents()); - args.addConst("maybeUnroll", length.isConstant()); - args.addConst("typeContext", arrayType.toJavaName(false)); - - SnippetTemplate template = template(args); - Debug.log("Lowering allocateArray in %s: node=%s, template=%s, arguments=%s", graph, newArrayNode, template, args); - template.instantiate(providers.getMetaAccess(), newArrayNode, DEFAULT_REPLACER, args); - } - - private static int instanceSize(HotSpotResolvedObjectType type) { - int size = type.instanceSize(); - assert (size % wordSize()) == 0; - assert size >= 0; - return size; - } - } - - private static final SnippetCounter.Group countersNew = SnippetCounters.getValue() ? new SnippetCounter.Group("NewInstance") : null; - private static final SnippetCounter new_eden = new SnippetCounter(countersNew, "eden", "used edenAllocate"); - - private static final SnippetCounter.Group countersNewArray = SnippetCounters.getValue() ? new SnippetCounter.Group("NewArray") : null; - // private static final SnippetCounter newarray_loopInit = new SnippetCounter(countersNewArray, - // "tlabLoopInit", "TLAB alloc with zeroing in a loop"); - private static final SnippetCounter newarray_eden = new SnippetCounter(countersNewArray, "eden", "used edenAllocate"); -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILWorkItemAbsIdNode.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/replacements/HSAILWorkItemAbsIdNode.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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.hotspot.hsail.replacements; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.hotspot.hsail.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; - -@NodeInfo -public class HSAILWorkItemAbsIdNode extends FixedWithNextNode implements LIRLowerable { - - public HSAILWorkItemAbsIdNode() { - super(StampFactory.forKind(Kind.Int)); - } - - @Override - public void generate(NodeLIRBuilderTool gen) { - HSAILHotSpotLIRGenerator hsailgen = (HSAILHotSpotLIRGenerator) (gen.getLIRGeneratorTool()); - Value result = hsailgen.emitWorkItemAbsId(); - gen.setResult(this, result); - } - - @NodeIntrinsic - public static native int getWorkItemAbsId(); - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackend.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,495 +0,0 @@ -/* - * Copyright (c) 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.hotspot.ptx; - -import static com.oracle.graal.api.code.CodeUtil.*; -import static com.oracle.graal.api.meta.LocationIdentity.*; -import static com.oracle.graal.compiler.GraalCompiler.*; -import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*; -import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.*; -import static com.oracle.graal.lir.LIRValueUtil.*; - -import java.util.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.CallingConvention.Type; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.cfg.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.debug.Debug.Scope; -import com.oracle.graal.gpu.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.LIRInstruction.OperandFlag; -import com.oracle.graal.lir.LIRInstruction.OperandMode; -import com.oracle.graal.lir.StandardOp.LabelOp; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.lir.framemap.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.ptx.PTXControlFlow.PTXPredicatedLIRInstruction; -import com.oracle.graal.lir.ptx.*; -import com.oracle.graal.lir.ptx.PTXMemOp.LoadReturnAddrOp; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.phases.*; -import com.oracle.graal.phases.common.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.word.*; - -/** - * HotSpot PTX specific backend. - */ -public class PTXHotSpotBackend extends HotSpotBackend { - - private final boolean deviceInitialized; - - /** - * Descriptor for the PTX runtime method for calling a kernel. The C++ signature is: - * - *
-     *     jlong (JavaThread* thread,
-     *            jlong kernel,
-     *            jint dimX,
-     *            jint dimY,
-     *            jint dimZ,
-     *            jlong parametersAndReturnValueBuffer,
-     *            jint parametersAndReturnValueBufferSize,
-     *            jint objectParametersCount,
-     *            jlong objectParametersOffsets,
-     *            jlong pinnedObjects,
-     *            jint encodedReturnTypeSize)
-     * 
- */ - // @formatter:off - public static final ForeignCallDescriptor CALL_KERNEL = new ForeignCallDescriptor("execute_kernel_from_vm", long.class, - Word.class, // thread - long.class, // kernel - int.class, // dimX - int.class, // dimY - int.class, // dimZ - long.class, // parametersAndReturnValueBuffer - int.class, // parametersAndReturnValueBufferSize - int.class, // objectParameterCount - long.class, // objectParameterOffsets - long.class, // pinnedObjects - int.class); // encodedReturnTypeSize - - // @formatter:on - - public PTXHotSpotBackend(HotSpotGraalRuntimeProvider runtime, HotSpotProviders providers) { - super(runtime, providers); - if (OmitDeviceInit) { - deviceInitialized = true; - } else { - boolean init = false; - try { - init = initialize(); - } catch (UnsatisfiedLinkError e) { - } - deviceInitialized = init; - } - } - - /** - * Initializes the GPU device. - * - * @return whether or not initialization was successful - */ - private static native boolean initialize(); - - @Override - public boolean shouldAllocateRegisters() { - return false; - } - - /** - * Used to omit {@linkplain #initialize() device initialization}. - */ - private static final boolean OmitDeviceInit = Boolean.getBoolean("graal.ptx.omitDeviceInit"); - - @Override - public void completeInitialization() { - HotSpotProviders hostProviders = getRuntime().getHostProviders(); - HotSpotHostForeignCallsProvider hostForeignCalls = (HotSpotHostForeignCallsProvider) hostProviders.getForeignCalls(); - if (deviceInitialized) { - long launchKernel = getLaunchKernelAddress(); - hostForeignCalls.linkForeignCall(hostProviders, CALL_KERNEL, launchKernel, false, NOT_LEAF, NOT_REEXECUTABLE, ANY_LOCATION); - } - /* Add a shutdown hook to destroy CUDA context(s) */ - Runtime.getRuntime().addShutdownHook(new Thread("PTXShutdown") { - @Override - public void run() { - destroyContext(); - } - }); - super.completeInitialization(); - } - - private static native void destroyContext(); - - /** - * Gets the address of {@code Ptx::execute_kernel_from_vm()}. - */ - private static native long getLaunchKernelAddress(); - - @Override - public FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig) { - RegisterConfig registerConfigNonNull = registerConfig == null ? getCodeCache().getRegisterConfig() : registerConfig; - return new FrameMapBuilderImpl(newFrameMap(registerConfigNonNull), getCodeCache(), registerConfigNonNull); - } - - @Override - public FrameMap newFrameMap(RegisterConfig registerConfig) { - return new PTXFrameMap(getCodeCache(), registerConfig); - } - - /** - * Determines if the GPU device (or simulator) is available and initialized. - */ - public boolean isDeviceInitialized() { - return deviceInitialized; - } - - /** - * Compiles a given method to PTX code. - * - * @param makeBinary specifies whether a GPU binary should also be generated for the PTX code. - * If true, the returned value is guaranteed to have a non-zero - * {@linkplain ExternalCompilationResult#getEntryPoint() entry point}. - * @return the PTX code compiled from {@code method}'s bytecode - */ - public ExternalCompilationResult compileKernel(ResolvedJavaMethod method, boolean makeBinary) { - StructuredGraph graph = new StructuredGraph(method); - HotSpotProviders providers = getProviders(); - CallingConvention cc = getCallingConvention(providers.getCodeCache(), Type.JavaCallee, method, false); - PhaseSuite graphBuilderSuite = providers.getSuites().getDefaultGraphBuilderSuite(); - graphBuilderSuite.appendPhase(new NonNullParametersPhase()); - Suites suites = providers.getSuites().getDefaultSuites(); - ExternalCompilationResult ptxCode = compileGraph(graph, null, cc, method, providers, this, this.getTarget(), null, graphBuilderSuite, OptimisticOptimizations.NONE, getProfilingInfo(graph), - null, suites, new ExternalCompilationResult(), CompilationResultBuilderFactory.Default); - if (makeBinary) { - try (Scope ds = Debug.scope("GeneratingKernelBinary")) { - assert ptxCode.getTargetCode() != null; - long kernel = generateKernel(ptxCode.getTargetCode(), method.getName()); - ptxCode.setEntryPoint(kernel); - } catch (Throwable e) { - throw Debug.handle(e); - } - } - return ptxCode; - } - - /** - * Generates a GPU binary from PTX code. - */ - private static native long generateKernel(byte[] targetCode, String name); - - /** - * A list of the {@linkplain #installKernel(ResolvedJavaMethod, ExternalCompilationResult) - * installed} kernels. This is required so that there is a strong reference to each installed - * kernel as long as it is {@linkplain HotSpotNmethod#isValid() valid}. The list is pruned of - * invalid kernels every time a new kernel is installed. - */ - private List installedKernels = new LinkedList<>(); - - public final HotSpotNmethod installKernel(ResolvedJavaMethod method, ExternalCompilationResult ptxCode) { - assert OmitDeviceInit || ptxCode.getEntryPoint() != 0L; - HotSpotNmethod kernel = getProviders().getCodeCache().addExternalMethod(method, ptxCode); - synchronized (installedKernels) { - for (Iterator i = installedKernels.iterator(); i.hasNext();) { - HotSpotNmethod entry = i.next(); - if (!entry.isValid()) { - i.remove(); - } - } - installedKernels.add(kernel); - } - return kernel; - } - - static final class RegisterAnalysis implements ValueConsumer { - private final SortedSet signed32 = new TreeSet<>(); - private final SortedSet signed64 = new TreeSet<>(); - - // unsigned8 is only for ld, st and cbt - private final SortedSet unsigned8 = new TreeSet<>(); - private final SortedSet unsigned64 = new TreeSet<>(); - - // private final SortedSet float16 = new TreeSet<>(); - private final SortedSet float32 = new TreeSet<>(); - private final SortedSet float64 = new TreeSet<>(); - - LIRInstruction op; - - void emitDeclarations(Assembler asm) { - for (Integer i : unsigned8) { - asm.emitString(".reg .u8 %r" + i.intValue() + ";"); - } - for (Integer i : signed32) { - asm.emitString(".reg .s32 %r" + i.intValue() + ";"); - } - for (Integer i : signed64) { - asm.emitString(".reg .s64 %r" + i.intValue() + ";"); - } - for (Integer i : unsigned64) { - asm.emitString(".reg .u64 %r" + i.intValue() + ";"); - } - for (Integer i : float32) { - asm.emitString(".reg .f32 %r" + i.intValue() + ";"); - } - for (Integer i : float64) { - asm.emitString(".reg .f64 %r" + i.intValue() + ";"); - } - } - - @Override - public void visitValue(Value value, OperandMode mode, EnumSet flags) { - if (isVariable(value)) { - Variable regVal = (Variable) value; - Kind regKind = regVal.getKind(); - if ((op instanceof LoadReturnAddrOp) && (mode == OperandMode.DEF)) { - unsigned64.add(regVal.index); - } else { - switch (regKind) { - case Int: - // If the register was used as a wider signed type - // do not add it here - if (!signed64.contains(regVal.index)) { - signed32.add(regVal.index); - } - break; - case Long: - // If the register was used as a narrower signed type - // remove it from there and add it to wider type. - if (signed32.contains(regVal.index)) { - signed32.remove(regVal.index); - } - signed64.add(regVal.index); - break; - case Float: - // If the register was used as a wider signed type - // do not add it here - if (!float64.contains(regVal.index)) { - float32.add(regVal.index); - } - break; - case Double: - // If the register was used as a narrower signed type - // remove it from there and add it to wider type. - if (float32.contains(regVal.index)) { - float32.remove(regVal.index); - } - float64.add(regVal.index); - break; - case Object: - unsigned64.add(regVal.index); - break; - case Byte: - unsigned8.add(regVal.index); - break; - default: - throw GraalInternalError.shouldNotReachHere("unhandled register type " + value.toString()); - } - } - } - } - } - - class PTXFrameContext implements FrameContext { - - @Override - public void enter(CompilationResultBuilder crb) { - // codeBuffer.emitString(".address_size 32"); // PTX ISA version 2.3 - } - - @Override - public void leave(CompilationResultBuilder crb) { - } - - public boolean hasFrame() { - return true; - } - } - - @Override - public CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenRes, FrameMap frameMap, CompilationResult compilationResult, CompilationResultBuilderFactory factory) { - // Omit the frame of the method: - // - has no spill slots or other slots allocated during register allocation - // - has no callee-saved registers - // - has no incoming arguments passed on the stack - // - has no instructions with debug info - Assembler masm = createAssembler(frameMap); - PTXFrameContext frameContext = new PTXFrameContext(); - CompilationResultBuilder crb = factory.createBuilder(getCodeCache(), getForeignCalls(), frameMap, masm, frameContext, compilationResult); - crb.setTotalFrameSize(0); - return crb; - } - - @Override - public LIRGenerationResult newLIRGenerationResult(LIR lir, FrameMapBuilder frameMapBuilder, ResolvedJavaMethod method, Object stub) { - return new LIRGenerationResultBase(lir, frameMapBuilder); - } - - @Override - protected Assembler createAssembler(FrameMap frameMap) { - return new PTXMacroAssembler(getTarget(), frameMap.getRegisterConfig()); - } - - @Override - public LIRGeneratorTool newLIRGenerator(CallingConvention cc, LIRGenerationResult lirGenRes) { - return new PTXHotSpotLIRGenerator(getProviders(), getRuntime().getConfig(), cc, lirGenRes); - } - - @Override - public NodeLIRBuilderTool newNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) { - return new PTXHotSpotNodeLIRBuilder(graph, lirGen); - } - - private static void emitKernelEntry(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod codeCacheOwner) { - // Emit PTX kernel entry text based on PTXParameterOp - // instructions in the start block. Remove the instructions - // once kernel entry text and directives are emitted to - // facilitate seemless PTX code generation subsequently. - assert codeCacheOwner != null : lir + " is not associated with a method"; - final String name = codeCacheOwner.getName(); - Assembler asm = crb.asm; - - // Emit initial boiler-plate directives. - asm.emitString(".version 3.0"); - asm.emitString(".target sm_30"); - asm.emitString0(".entry " + name + " ("); - asm.emitString(""); - - // Get the start block - AbstractBlock startBlock = lir.getControlFlowGraph().getStartBlock(); - // Keep a list of ParameterOp instructions to delete from the - // list of instructions in the block. - ArrayList deleteOps = new ArrayList<>(); - - // Emit .param arguments to kernel entry based on ParameterOp - // instruction. - for (LIRInstruction op : lir.getLIRforBlock(startBlock)) { - if (op instanceof PTXParameterOp) { - op.emitCode(crb); - deleteOps.add(op); - } - } - - // Delete ParameterOp instructions. - for (LIRInstruction op : deleteOps) { - lir.getLIRforBlock(startBlock).remove(op); - } - - // Start emiting body of the PTX kernel. - asm.emitString0(") {"); - asm.emitString(""); - } - - // Emit .reg space declarations - private static void emitRegisterDecl(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod codeCacheOwner) { - - assert codeCacheOwner != null : lir + " is not associated with a method"; - - RegisterAnalysis registerAnalysis = new RegisterAnalysis(); - // Assume no predicate registers are used - int maxPredRegNum = -1; - - for (AbstractBlock b : lir.codeEmittingOrder()) { - for (LIRInstruction op : lir.getLIRforBlock(b)) { - if (op instanceof LabelOp) { - // Don't consider this as a definition - } else { - if (op instanceof PTXPredicatedLIRInstruction) { - // Update maximum predicate register number if op uses a larger number - int opPredRegNum = ((PTXPredicatedLIRInstruction) op).getPredRegNum(); - maxPredRegNum = (opPredRegNum > maxPredRegNum) ? opPredRegNum : maxPredRegNum; - } - // Record registers used in the kernel - registerAnalysis.op = op; - op.visitEachTemp(registerAnalysis); - op.visitEachOutput(registerAnalysis); - } - } - } - - // Emit register declarations - Assembler asm = crb.asm; - registerAnalysis.emitDeclarations(asm); - - // emit predicate register declaration - if (maxPredRegNum > -1) { - asm.emitString(".reg .pred %p<" + ++maxPredRegNum + ">;"); - } - } - - @Override - public void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod codeCacheOwner) { - assert codeCacheOwner != null : lir + " is not associated with a method"; - Assembler asm = crb.asm; - - // Emit the prologue - emitKernelEntry(crb, lir, codeCacheOwner); - - // Emit register declarations - try { - emitRegisterDecl(crb, lir, codeCacheOwner); - } catch (GraalInternalError e) { - e.printStackTrace(); - // TODO : Better error handling needs to be done once - // all types of parameters are handled. - asm.close(false); - return; - } - // Emit code for the LIR - try { - crb.emit(lir); - } catch (GraalInternalError e) { - e.printStackTrace(); - // TODO : Better error handling needs to be done once - // all types of parameters are handled. - asm.close(false); - return; - } - - // Emit the epilogue - asm.emitString0("}"); - asm.emitString(""); - } - - /** - * Gets the total number of available CUDA cores. - */ - public int getAvailableProcessors() { - if (!deviceInitialized) { - return 0; - } - return getAvailableProcessors0(); - } - - private static native int getAvailableProcessors0(); - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackendFactory.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotBackendFactory.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2012, 2014, 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.hotspot.ptx; - -import static com.oracle.graal.hotspot.InitTimer.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.java.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.phases.tiers.*; -import com.oracle.graal.ptx.*; - -@ServiceProvider(HotSpotBackendFactory.class) -public class PTXHotSpotBackendFactory implements HotSpotBackendFactory { - - public HotSpotBackend createBackend(HotSpotGraalRuntimeProvider runtime, HotSpotBackend hostBackend) { - HotSpotProviders host = hostBackend.getProviders(); - MetaAccessProvider metaAccess; - PTXHotSpotCodeCacheProvider codeCache; - ConstantReflectionProvider constantReflection; - HotSpotForeignCallsProvider foreignCalls; - LoweringProvider lowerer; - Replacements replacements; - HotSpotDisassemblerProvider disassembler; - SuitesProvider suites; - HotSpotRegistersProvider registers; - HotSpotProviders providers; - try (InitTimer t = timer("create providers")) { - try (InitTimer rt = timer("create MetaAccess provider")) { - metaAccess = host.getMetaAccess(); - } - try (InitTimer rt = timer("create CodeCache provider")) { - codeCache = new PTXHotSpotCodeCacheProvider(runtime, createTarget()); - } - try (InitTimer rt = timer("create ConstantReflection provider")) { - constantReflection = host.getConstantReflection(); - } - try (InitTimer rt = timer("create ForeignCalls provider")) { - foreignCalls = new PTXHotSpotForeignCallsProvider(); - } - try (InitTimer rt = timer("create Lowerer provider")) { - lowerer = new PTXHotSpotLoweringProvider(host.getLowerer()); - } - try (InitTimer rt = timer("create Replacements provider")) { - replacements = host.getReplacements(); - } - try (InitTimer rt = timer("create Disassembler provider")) { - disassembler = host.getDisassembler(); - } - try (InitTimer rt = timer("create Suites provider")) { - suites = new DefaultSuitesProvider(); - } - try (InitTimer rt = timer("create HotSpotRegisters provider")) { - registers = new HotSpotRegisters(PTX.tid, Register.None, Register.None); - } - providers = new HotSpotProviders(metaAccess, codeCache, constantReflection, foreignCalls, lowerer, replacements, disassembler, suites, registers, host.getSnippetReflection()); - } - try (InitTimer rt = timer("instantiate backend")) { - return new PTXHotSpotBackend(runtime, providers); - } - } - - protected Architecture createArchitecture() { - return new PTX(); - } - - protected TargetDescription createTarget() { - final int stackFrameAlignment = 1; - final int implicitNullCheckLimit = 0; - final boolean inlineObjects = true; - return new HotSpotTargetDescription(createArchitecture(), true, stackFrameAlignment, implicitNullCheckLimit, inlineObjects); - } - - public String getArchitecture() { - return "PTX"; - } - - public String getGraalRuntimeName() { - return "basic"; - } - - @Override - public String toString() { - return getGraalRuntimeName() + ":" + getArchitecture(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotCodeCacheProvider.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotCodeCacheProvider.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * 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.hotspot.ptx; - -import java.util.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.meta.*; - -public class PTXHotSpotCodeCacheProvider extends HotSpotCodeCacheProvider { - - public PTXHotSpotCodeCacheProvider(HotSpotGraalRuntimeProvider runtime, TargetDescription target) { - super(runtime, target, new PTXHotSpotRegisterConfig()); - } - - @Override - public String disassemble(CompilationResult compResult, InstalledCode installedCode) { - byte[] code = installedCode == null ? Arrays.copyOf(compResult.getTargetCode(), compResult.getTargetCodeSize()) : installedCode.getCode(); - return new String(code); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotForeignCallsProvider.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotForeignCallsProvider.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * 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.hotspot.ptx; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.hotspot.meta.*; - -public class PTXHotSpotForeignCallsProvider implements HotSpotForeignCallsProvider { - - public boolean isReexecutable(ForeignCallDescriptor descriptor) { - throw GraalInternalError.unimplemented(); - } - - @Override - public LocationIdentity[] getKilledLocations(ForeignCallDescriptor descriptor) { - throw GraalInternalError.unimplemented(); - } - - @Override - public boolean canDeoptimize(ForeignCallDescriptor descriptor) { - throw GraalInternalError.unimplemented(); - } - - public ForeignCallLinkage lookupForeignCall(ForeignCallDescriptor descriptor) { - throw GraalInternalError.unimplemented(); - } - - public Value[] getNativeABICallerSaveRegisters() { - throw GraalInternalError.unimplemented(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLIRGenerator.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright (c) 2014, 2014, 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.hotspot.ptx; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.ptx.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.HotSpotVMConfig.CompressEncoding; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.lir.StandardOp.SaveRegistersOp; -import com.oracle.graal.lir.gen.*; - -/** - * LIR generator specialized for PTX HotSpot. - */ -public class PTXHotSpotLIRGenerator extends PTXLIRGenerator implements HotSpotLIRGenerator { - - protected PTXHotSpotLIRGenerator(HotSpotProviders providers, HotSpotVMConfig config, CallingConvention cc, LIRGenerationResult lirGenRes) { - super(new DefaultLIRKindTool(providers.getCodeCache().getTarget().wordKind), providers, cc, lirGenRes); - assert config.basicLockSize == 8; - } - - public void emitTailcall(Value[] args, Value address) { - throw GraalInternalError.unimplemented(); - } - - public void emitDeoptimizeCaller(DeoptimizationAction action, DeoptimizationReason reason) { - throw GraalInternalError.unimplemented(); - } - - public StackSlot getLockSlot(int lockDepth) { - throw GraalInternalError.unimplemented(); - } - - @Override - public HotSpotProviders getProviders() { - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitCompress(Value pointer, CompressEncoding encoding, boolean nonNull) { - // TODO - throw GraalInternalError.unimplemented(); - } - - @Override - public Value emitUncompress(Value pointer, CompressEncoding encoding, boolean nonNull) { - // TODO - throw GraalInternalError.unimplemented(); - } - - public SaveRegistersOp emitSaveAllRegisters() { - throw GraalInternalError.unimplemented(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLoweringProvider.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotLoweringProvider.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * 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.hotspot.ptx; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; - -public class PTXHotSpotLoweringProvider implements LoweringProvider { - - private final LoweringProvider host; - - public PTXHotSpotLoweringProvider(LoweringProvider host) { - this.host = host; - } - - @Override - public void lower(Node n, LoweringTool tool) { - if (n instanceof ConvertNode) { - // PTX has a cvt instruction that "takes a variety of - // operand types and sizes, as its job is to convert from - // nearly any data type to any other data type (and - // size)." [Section 6.2 of PTX ISA manual] - // So, there is no need to lower the operation. - return; - } else { - host.lower(n, tool); - } - } - - public ValueNode reconstructArrayIndex(Kind elementKind, LocationNode location) { - throw GraalInternalError.unimplemented(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotNodeLIRBuilder.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotNodeLIRBuilder.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2014, 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.hotspot.ptx; - -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.ptx.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.nodes.*; - -/** - * LIR generator specialized for PTX HotSpot. - */ -public class PTXHotSpotNodeLIRBuilder extends PTXNodeLIRBuilder implements HotSpotNodeLIRBuilder { - - protected PTXHotSpotNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen) { - super(graph, lirGen); - } - - public void emitPrefetchAllocate(ValueNode address, ValueNode distance) { - // nop - } - - public void emitPatchReturnAddress(ValueNode address) { - throw GraalInternalError.unimplemented(); - } - - public void emitJumpToExceptionHandlerInCaller(ValueNode handlerInCallerPc, ValueNode exception, ValueNode exceptionPc) { - throw GraalInternalError.unimplemented(); - } - - public void visitDirectCompareAndSwap(DirectCompareAndSwapNode x) { - throw GraalInternalError.unimplemented(); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotRegisterConfig.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXHotSpotRegisterConfig.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2011, 2014, 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.hotspot.ptx; - -import static com.oracle.graal.ptx.PTX.*; - -import java.util.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.CallingConvention.Type; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; - -public class PTXHotSpotRegisterConfig implements RegisterConfig { - - private final Register[] allocatable; - - @Override - public Register[] getAllocatableRegisters() { - return allocatable.clone(); - } - - @Override - public Register[] getAllocatableRegisters(PlatformKind kind) { - throw GraalInternalError.unimplemented("PTXHotSpotRegisterConfig.getAllocatableRegisters()"); - } - - @Override - public RegisterAttributes[] getAttributesMap() { - throw GraalInternalError.unimplemented("PTXHotSpotRegisterConfig.getAttributesMap()"); - } - - private final Register[] javaGeneralParameterRegisters; - private final Register[] nativeGeneralParameterRegisters; - - private static Register[] initAllocatable() { - Register[] registers = new Register[]{r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15}; - - return registers; - } - - public PTXHotSpotRegisterConfig() { - javaGeneralParameterRegisters = paramRegisters; - nativeGeneralParameterRegisters = gprRegisters; - - allocatable = initAllocatable(); - } - - @Override - public Register[] getCallerSaveRegisters() { - // No caller save registers; return empty array - return new Register[]{}; - } - - @Override - public boolean areAllAllocatableRegistersCallerSaved() { - throw GraalInternalError.unimplemented(); - } - - @Override - public Register getRegisterForRole(int index) { - throw GraalInternalError.unimplemented("PTXHotSpotRegisterConfig.getRegisterForRole()"); - } - - @Override - public CallingConvention getCallingConvention(Type type, JavaType returnType, JavaType[] parameterTypes, TargetDescription target, boolean stackOnly) { - if (type == Type.NativeCall) { - return callingConvention(nativeGeneralParameterRegisters, returnType, parameterTypes, type, target, stackOnly); - } - return callingConvention(javaGeneralParameterRegisters, returnType, parameterTypes, type, target, stackOnly); - } - - @Override - public Register[] getCallingConventionRegisters(Type type, Kind kind) { - throw GraalInternalError.unimplemented("PTXHotSpotRegisterConfig.getRegisterForRole()"); - } - - private static CallingConvention callingConvention(@SuppressWarnings("unused") Register[] generalParameterRegisters, JavaType returnType, JavaType[] parameterTypes, Type type, - TargetDescription target, boolean stackOnly) { - - assert stackOnly == false; - - int currentGeneral = 0; - int currentStackOffset = 0; - - Kind returnKind = returnType == null ? Kind.Void : returnType.getKind(); - - AllocatableValue returnLocation; - if (returnKind == Kind.Void) { - returnLocation = Value.ILLEGAL; - } else { - returnLocation = new Variable(target.getLIRKind(returnKind), currentGeneral++); - } - - AllocatableValue[] locations = new AllocatableValue[parameterTypes.length]; - - for (int i = 0; i < parameterTypes.length; i++) { - final Kind kind = parameterTypes[i].getKind(); - - switch (kind) { - case Byte: - case Boolean: - case Short: - case Char: - case Int: - case Long: - case Float: - case Double: - case Object: - if (!stackOnly) { - locations[i] = new Variable(target.getLIRKind(kind), currentGeneral++); - } - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - - if (locations[i] == null) { - locations[i] = StackSlot.get(target.getLIRKind(kind.getStackKind()), currentStackOffset, !type.out); - currentStackOffset += Math.max(target.getSizeInBytes(kind), target.wordSize); - } - } - - return new CallingConvention(currentStackOffset, returnLocation, locations); - } - - @Override - public Register getReturnRegister(Kind kind) { - throw GraalInternalError.unimplemented("PTXHotSpotRegisterConfig.getRegisterForRole()"); - } - - @Override - public Register getFrameRegister() { - // No frame register - return null; - } - - public CalleeSaveLayout getCalleeSaveLayout() { - return null; - } - - @Override - public String toString() { - return String.format("Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n"); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java --- a/graal/com.oracle.graal.hotspot.ptx/src/com/oracle/graal/hotspot/ptx/PTXWrapperBuilder.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,361 +0,0 @@ -/* - * Copyright (c) 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.hotspot.ptx; - -import static com.oracle.graal.api.meta.DeoptimizationAction.*; -import static com.oracle.graal.api.meta.DeoptimizationReason.*; -import static com.oracle.graal.api.meta.LocationIdentity.*; -import static com.oracle.graal.asm.NumUtil.*; -import static com.oracle.graal.hotspot.ptx.PTXHotSpotBackend.*; -import static com.oracle.graal.hotspot.ptx.PTXWrapperBuilder.LaunchArg.*; -import static com.oracle.graal.hotspot.replacements.HotSpotReplacementsUtil.*; -import static com.oracle.graal.nodes.ConstantNode.*; - -import java.util.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.hotspot.meta.*; -import com.oracle.graal.hotspot.nodes.*; -import com.oracle.graal.java.*; -import com.oracle.graal.lir.ptx.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.HeapAccess.BarrierType; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.nodes.*; -import com.oracle.graal.word.*; - -/** - * Utility for building a graph that "wraps" a compiled PTX kernel. Such a wrapper handles the - * transition from the host CPU to the GPU and back. The wrapper allocate 3 on-stack buffers: - *
    - *
  • PARAMS: a buffer for the kernel parameters and one word for the on-device address of the - * return value (if any).
  • - *
  • PINNED: a buffer into which the address of pinned objects is saved.
  • - *
  • OBJECT_OFFSETS: the offsets of the object values in PARAMS.
  • - *
- * - * - * The PARAMS buffer is the {@code CU_LAUNCH_PARAM_BUFFER_POINTER} buffer passed in the - * {@code extra} argument to the {@code cuLaunchKernel} function. This buffer contains the - * parameters to the call. The buffer is word aligned and each parameter is aligned in the buffer - * according to its data size. The wrapper copies the incoming arguments into the buffer as is. The - * native {@link PTXHotSpotBackend#CALL_KERNEL callKernel} function will pin the memory for each - * object parameter (using {@code cuMemHostRegister}) and then replace the object pointer in PARAMS - * with an on-device pointer to the object's memory (see {@code cuMemHostGetDevicePointer}). The - * function saves pinned object pointer into PINNED so that it can unpinned once the kernel returns. - * The object pointers in PARAMS are specified by OBJECT_OFFSETS. - *

- * As a concrete example, for a kernel whose Java method signature is: - * - *

- *     static int kernel(int p1, short p2, Object p3, long p4)
- * 
- * - * the graph created is shown below as psuedo-code: - * - *
- *     int kernel_wrapper(int p1, short p2, oop p3, long p4) {
- *         address kernelAddr = kernel.start;
- *         if (kernelAddr == 0) {
- *             deopt(InvalidateRecompile, RuntimeConstraint);
- *         }
- *         byte PARAMS[32];
- *         word PINNED[1]; // note: no refmap
- *         int OBJECT_OFFSETS[1] = {8};
- *         ((int*) PARAMS)[0] = p1;
- *         ((short*) PARAMS)[2] = p2;
- *         ((word*) PARAMS)[1] = p3;
- *         ((long*) PARAMS)[2] = p4;
- *         int result = CALL_KERNEL(THREAD_REGISTER, KERNEL_ENTRY_POINT, 1, 1, 1, PARAMS, 32, 1, OBJECT_OFFSETS, PINNED, 4);
- *         if (clearPendingException(thread)) {
- *             deopt(None, RuntimeConstraint);
- *         }
- *         return result;
- *     }
- * 
- *

- * The generated graph includes a reference to the {@link HotSpotNmethod} for the kernel. There must - * be another reference to the same {@link HotSpotNmethod} object to ensure that the nmethod is not - * unloaded by the next full GC. Currently, these extra "keep-alive" references are maintained by - * {@link PTXHotSpotBackend}. - *

- * The PTX runtime code called by the wrapper blocks GC while the kernel is executing (cf - * GetPrimitiveArrayCritical/ReleasePrimitiveArrayCritical JNI functions). This ensures objects can - * be safely passed to kernels but should be replaced with a lighter weight mechanism at some point. - */ -public class PTXWrapperBuilder extends GraphKit { - - /** - * The incoming Java arguments to the method. - */ - ParameterNode[] javaParameters; - - /** - * The size of the buffer holding the kernel parameters and the extra word for storing the - * pointer to device memory for the return value. - * - * @see LaunchArg#ParametersAndReturnValueBufferSize - */ - int bufSize; - - /** - * Offset of each Java argument in the kernel parameters buffer. - */ - int[] javaParameterOffsetsInKernelParametersBuffer; - - /** - * Constants denoting the arguments to {@link PTXHotSpotBackend#CALL_KERNEL}. - */ - // @formatter:off - enum LaunchArg { - Thread, - Kernel, - DimX, - DimY, - DimZ, - ParametersAndReturnValueBuffer, - ParametersAndReturnValueBufferSize, - ObjectParametersCount, - ObjectParametersOffsets, - PinnedObjects, - EncodedReturnTypeSize - } - // @formatter:on - - /** - * Creates the graph implementing the CPU to GPU transition. - * - * @param method a method that has been compiled to GPU binary code - * @param kernel the installed GPU binary for {@code method} - * @see PTXWrapperBuilder - */ - public PTXWrapperBuilder(ResolvedJavaMethod method, HotSpotNmethod kernel, HotSpotProviders providers) { - super(new StructuredGraph(method), providers); - int wordSize = providers.getCodeCache().getTarget().wordSize; - int intSize = Integer.SIZE / Byte.SIZE; - Kind wordKind = providers.getCodeCache().getTarget().wordKind; - Signature sig = method.getSignature(); - boolean isStatic = method.isStatic(); - int sigCount = sig.getParameterCount(false); - javaParameters = new ParameterNode[(!isStatic ? 1 : 0) + sigCount]; - javaParameterOffsetsInKernelParametersBuffer = new int[javaParameters.length]; - int javaParametersIndex = 0; - Kind returnKind = sig.getReturnKind(); - - List objectSlots = new ArrayList<>(javaParameters.length); - if (!isStatic) { - allocateParameter(Kind.Object, javaParametersIndex++, objectSlots, wordSize); - } - for (int sigIndex = 0; sigIndex < sigCount; sigIndex++) { - Kind kind = sig.getParameterKind(sigIndex); - allocateParameter(kind, javaParametersIndex++, objectSlots, wordSize); - } - bufSize = roundUp(bufSize, wordSize); - - // Add slot for the device memory pointer. The kernel writes a - // pointer in this slot that points to the return value. - int encodedReturnTypeSize = 0; - if (returnKind != Kind.Void) { - bufSize += wordSize; - if (returnKind == Kind.Object) { - encodedReturnTypeSize = -wordSize; - } else { - encodedReturnTypeSize = returnKind.getBitCount() / Byte.SIZE; - } - } - - InvokeNode kernelStart = createInvoke(getClass(), "getKernelStart", ConstantNode.forConstant(kernel.asConstant(), providers.getMetaAccess(), getGraph())); - - AllocaNode buf = append(new AllocaNode(bufSize / wordSize, wordKind, new BitSet())); - ValueNode objectParametersOffsets; - ValueNode pinnedObjects; - ConstantNode nullWord = ConstantNode.forIntegerKind(wordKind, 0L, getGraph()); - if (objectSlots.isEmpty()) { - objectParametersOffsets = ConstantNode.forLong(0, getGraph()); - pinnedObjects = ConstantNode.forLong(0, getGraph()); - } else { - int intsPerWord = wordSize / intSize; - int slots = roundUp(objectSlots.size(), intsPerWord); - objectParametersOffsets = append(new AllocaNode(slots, wordKind, new BitSet())); - // No refmap for pinned objects list since kernel execution is (currently) GC unsafe - pinnedObjects = append(new AllocaNode(objectSlots.size(), wordKind, new BitSet())); - - // Initialize the object parameter offsets array - int index = 0; - for (int slot : objectSlots) { - int offset = slot * wordSize; - LocationNode location = getGraph().unique(new ConstantLocationNode(FINAL_LOCATION, index * intSize)); - append(new WriteNode(objectParametersOffsets, ConstantNode.forInt(offset, getGraph()), location, BarrierType.NONE, false)); - index++; - } - } - - Map args = new EnumMap<>(LaunchArg.class); - args.put(Thread, append(new ReadRegisterNode(providers.getRegisters().getThreadRegister(), true, false))); - args.put(Kernel, kernelStart); - args.put(DimX, forInt(1, getGraph())); - args.put(DimY, forInt(1, getGraph())); - args.put(DimZ, forInt(1, getGraph())); - args.put(ParametersAndReturnValueBuffer, buf); - args.put(ParametersAndReturnValueBufferSize, forInt(bufSize, getGraph())); - args.put(ObjectParametersCount, forInt(objectSlots.size(), getGraph())); - args.put(ObjectParametersOffsets, objectParametersOffsets); - args.put(PinnedObjects, pinnedObjects); - args.put(EncodedReturnTypeSize, forInt(encodedReturnTypeSize, getGraph())); - - int sigIndex = isStatic ? 0 : -1; - for (javaParametersIndex = 0; javaParametersIndex < javaParameters.length; javaParametersIndex++) { - ParameterNode javaParameter = javaParameters[javaParametersIndex]; - int javaParameterOffset = javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex]; - LocationNode location = getGraph().unique(new ConstantLocationNode(FINAL_LOCATION, javaParameterOffset)); - append(new WriteNode(buf, javaParameter, location, BarrierType.NONE, false)); - updateDimArg(method, sig, sigIndex++, args, javaParameter); - } - if (returnKind != Kind.Void) { - LocationNode location = getGraph().unique(new ConstantLocationNode(FINAL_LOCATION, bufSize - wordSize)); - append(new WriteNode(buf, nullWord, location, BarrierType.NONE, false)); - } - - HIRFrameStateBuilder fsb = new HIRFrameStateBuilder(method, getGraph(), null); - fsb.initializeForMethodStart(true); - FrameState fs = fsb.create(0); - getGraph().start().setStateAfter(fs); - - ValueNode[] launchArgsArray = args.values().toArray(new ValueNode[args.size()]); - ForeignCallNode result = append(new ForeignCallNode(providers.getForeignCalls(), CALL_KERNEL, launchArgsArray)); - result.setStateAfter(fs); - - InvokeNode getObjectResult = null; - ValueNode returnValue; - switch (returnKind) { - case Void: - returnValue = null; - break; - case Boolean: - case Byte: - case Short: - case Char: - case Int: - returnValue = unique(new NarrowNode(result, 32)); - break; - case Long: - returnValue = result; - break; - case Float: { - ValueNode asInt = unique(new NarrowNode(result, 32)); - returnValue = ReinterpretNode.reinterpret(Kind.Float, asInt); - break; - } - case Double: - returnValue = ReinterpretNode.reinterpret(Kind.Double, result); - break; - case Object: - getObjectResult = createInvoke(getClass(), "getObjectResult", args.get(Thread)); - returnValue = append(getObjectResult); - break; - default: - throw new GraalInternalError("%s return kind not supported", returnKind); - } - - append(new ReturnNode(returnValue)); - - if (Debug.isDumpEnabled()) { - Debug.dump(getGraph(), "Initial kernel launch graph"); - } - - rewriteWordTypes(providers.getSnippetReflection()); - inlineInvokes(providers.getSnippetReflection()); - - if (Debug.isDumpEnabled()) { - Debug.dump(getGraph(), "Kernel launch graph before compilation"); - } - } - - /** - * Computes offset and size of space in PARAMS for a Java parameter. - * - * @param kind the kind of the parameter - * @param javaParametersIndex the index of the Java parameter - */ - private void allocateParameter(Kind kind, int javaParametersIndex, List objectSlots, int wordSize) { - int kindByteSize = kind == Kind.Object ? wordSize : kind.getBitCount() / Byte.SIZE; - bufSize = roundUp(bufSize, kindByteSize); - javaParameterOffsetsInKernelParametersBuffer[javaParametersIndex] = bufSize; - Stamp stamp; - if (kind == Kind.Object) { - stamp = StampFactory.object(); - int slot = bufSize / wordSize; - objectSlots.add(slot); - } else { - stamp = StampFactory.forKind(kind); - } - javaParameters[javaParametersIndex] = unique(new ParameterNode(javaParametersIndex, stamp)); - bufSize += kindByteSize; - } - - /** - * Updates the {@code dimX}, {@code dimY} or {@code dimZ} argument passed to the kernel if - * {@code javaParameter} is annotated with {@link ParallelOver}. - */ - private void updateDimArg(ResolvedJavaMethod method, Signature sig, int sigIndex, Map launchArgs, ParameterNode javaParameter) { - if (sigIndex >= 0) { - ParallelOver parallelOver = method.getParameterAnnotation(ParallelOver.class, sigIndex); - if (parallelOver != null && sig.getParameterType(sigIndex, method.getDeclaringClass()).equals(providers.getMetaAccess().lookupJavaType(int[].class))) { - ArrayLengthNode dimension = append(new ArrayLengthNode(javaParameter)); - LaunchArg argKey = LaunchArg.valueOf(LaunchArg.class, "Dim" + parallelOver.dimension()); - ValueNode existing = launchArgs.put(argKey, dimension); - if (existing != null && existing instanceof ArrayLengthNode) { - throw new GraalInternalError("@" + ParallelOver.class.getSimpleName() + " with dimension=" + parallelOver.dimension() + " applied to multiple parameters"); - } - } - } - } - - /** - * Snippet invoked to get the {@linkplain HotSpotNmethod#getStart() entry point} of the kernel, - * deoptimizing if the kernel is invalid. - */ - @Snippet - private static long getKernelStart(HotSpotNmethod ptxKernel) { - long start = ptxKernel.getStart(); - if (start == 0L) { - DeoptimizeNode.deopt(InvalidateRecompile, RuntimeConstraint); - } - return start; - } - - /** - * Snippet invoked upon return from the kernel to retrieve an object return value from the - * thread local used for communicating object return values from VM calls. - */ - @Snippet - private static Object getObjectResult(Word thread) { - return getAndClearObjectResult(thread); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Jan 22 23:16:17 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Fri Jan 23 10:54:21 2015 +0100 @@ -747,7 +747,6 @@ @HotSpotVMFlag(name = "PrintInlining") @Stable public boolean printInlining; @HotSpotVMFlag(name = "GraalUseFastLocking") @Stable public boolean useFastLocking; @HotSpotVMFlag(name = "ForceUnreachable") @Stable public boolean forceUnreachable; - @HotSpotVMFlag(name = "GPUOffload") @Stable public boolean gpuOffload; @HotSpotVMFlag(name = "UseTLAB") @Stable public boolean useTLAB; @HotSpotVMFlag(name = "UseBiasedLocking") @Stable public boolean useBiasedLocking; @@ -1056,44 +1055,6 @@ @HotSpotVMField(name = "ThreadShadow::_pending_failed_speculation", type = "oop", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingFailedSpeculationOffset; @HotSpotVMField(name = "ThreadShadow::_pending_transfer_to_interpreter", type = "bool", get = HotSpotVMField.Type.OFFSET) @Stable public int pendingTransferToInterpreterOffset; - @HotSpotVMFlag(name = "UseHSAILDeoptimization") @Stable public boolean useHSAILDeoptimization; - @HotSpotVMFlag(name = "UseHSAILSafepoints") @Stable public boolean useHSAILSafepoints; - - /** - * Offsets of Hsail deoptimization fields (defined in gpu_hsail.hpp). Used to propagate - * exceptions from Hsail back to C++ runtime. - */ - @HotSpotVMField(name = "Hsail::HSAILDeoptimizationInfo::_notice_safepoints", type = "jint*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailNoticeSafepointsOffset; - @HotSpotVMField(name = "Hsail::HSAILDeoptimizationInfo::_deopt_occurred", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailDeoptOccurredOffset; - @HotSpotVMField(name = "Hsail::HSAILDeoptimizationInfo::_never_ran_array", type = "jboolean*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailNeverRanArrayOffset; - @HotSpotVMField(name = "Hsail::HSAILDeoptimizationInfo::_deopt_next_index", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailDeoptNextIndexOffset; - @HotSpotVMField(name = "Hsail::HSAILDeoptimizationInfo::_alloc_info", type = "HSAILAllocationInfo*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailAllocInfoOffset; - @HotSpotVMField(name = "Hsail::HSAILDeoptimizationInfo::_cur_tlab_info", type = "HSAILTlabInfo**", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailCurTlabInfoOffset; - - @HotSpotVMField(name = "Hsail::HSAILKernelDeoptimization::_workitemid", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailDeoptimizationWorkItem; - @HotSpotVMField(name = "Hsail::HSAILKernelDeoptimization::_actionAndReason", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailDeoptimizationReason; - - @HotSpotVMField(name = "HSAILFrame::_pc_offset", type = "jint", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailFramePcOffset; - @HotSpotVMField(name = "HSAILFrame::_num_s_regs", type = "jbyte", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailFrameNumSRegOffset; - @HotSpotVMField(name = "HSAILFrame::_num_d_regs", type = "jbyte", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailFrameNumDRegOffset; - @HotSpotVMType(name = "HSAILFrame", get = HotSpotVMType.Type.SIZE) @Stable public int hsailFrameHeaderSize; - @HotSpotVMType(name = "Hsail::HSAILKernelDeoptimization", get = HotSpotVMType.Type.SIZE) @Stable public int hsailKernelDeoptimizationHeaderSize; - @HotSpotVMType(name = "Hsail::HSAILDeoptimizationInfo", get = HotSpotVMType.Type.SIZE) @Stable public int hsailDeoptimizationInfoHeaderSize; - - @HotSpotVMField(name = "HSAILAllocationInfo::_tlab_infos_pool_start", type = "HSAILTlabInfo*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailAllocInfoTlabInfosPoolStartOffset; - @HotSpotVMField(name = "HSAILAllocationInfo::_tlab_infos_pool_next", type = "HSAILTlabInfo*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailAllocInfoTlabInfosPoolNextOffset; - @HotSpotVMField(name = "HSAILAllocationInfo::_tlab_infos_pool_end", type = "HSAILTlabInfo*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailAllocInfoTlabInfosPoolEndOffset; - @HotSpotVMField(name = "HSAILAllocationInfo::_tlab_align_reserve_bytes", type = "size_t", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailAllocInfoTlabAlignReserveBytesOffset; - - @HotSpotVMField(name = "HSAILTlabInfo::_start", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoStartOffset; - @HotSpotVMField(name = "HSAILTlabInfo::_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoTopOffset; - @HotSpotVMField(name = "HSAILTlabInfo::_end", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoEndOffset; - @HotSpotVMField(name = "HSAILTlabInfo::_last_good_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoLastGoodTopOffset; - @HotSpotVMField(name = "HSAILTlabInfo::_original_top", type = "HeapWord*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoOriginalTopOffset; - @HotSpotVMField(name = "HSAILTlabInfo::_alloc_info", type = "HSAILAllocationInfo*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoAllocInfoOffset; - @HotSpotVMField(name = "HSAILTlabInfo::_tlab", type = "ThreadLocalAllocBuffer*", get = HotSpotVMField.Type.OFFSET) @Stable public int hsailTlabInfoTlabOffset; - @HotSpotVMType(name = "HSAILTlabInfo", get = HotSpotVMType.Type.SIZE) @Stable public int hsailTlabInfoSize; - /** * Mark word right shift to get identity hash code. */ diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Jan 22 23:16:17 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Fri Jan 23 10:54:21 2015 +0100 @@ -181,7 +181,9 @@ public native int allocateCompileId(long metaspaceMethod, int entryBCI); - public native String getGPUs(); + public String getGPUs() { + return ""; + } public native boolean canInlineMethod(long metaspaceMethod); diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.hsail/src/com/oracle/graal/hsail/HSAIL.java --- a/graal/com.oracle.graal.hsail/src/com/oracle/graal/hsail/HSAIL.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,261 +0,0 @@ -/* - * Copyright (c) 2009, 2014, 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.hsail; - -import static com.oracle.graal.api.code.ValueUtil.*; - -import java.nio.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.Register.RegisterCategory; -import com.oracle.graal.api.meta.*; - -/** - * Represents the HSAIL architecture. - */ -public class HSAIL extends Architecture { - - private static final int CPU_CONTROL_OFFSET = 0; - private static final int CPU_CONTROL_SHIFT = 0; - private static final int CPU_CONTROL_NUM = 8; - - private static final int CPU32_OFFSET = CPU_CONTROL_NUM << CPU_CONTROL_SHIFT; - private static final int CPU32_SHIFT = 0; - private static final int CPU32_NUM = 40; - - private static final int CPU64_OFFSET = CPU32_OFFSET + CPU32_NUM << CPU32_SHIFT; - private static final int CPU64_SHIFT = 0; - private static final int CPU64_NUM = 21; - - private static final int CPU128_OFFSET = CPU64_OFFSET + CPU64_NUM << CPU64_SHIFT; - private static final int CPU128_SHIFT = 1; - private static final int CPU128_NUM = 16; - - public static final RegisterCategory CPU_CONTROL = new RegisterCategory("CPU_CONTROL", CPU_CONTROL_OFFSET, CPU_CONTROL_SHIFT); - public static final RegisterCategory CPU32 = new RegisterCategory("CPU32", CPU32_OFFSET, CPU32_SHIFT); - public static final RegisterCategory CPU64 = new RegisterCategory("CPU64", CPU64_OFFSET, CPU64_SHIFT); - public static final RegisterCategory CPU128 = new RegisterCategory("CPU128", CPU128_OFFSET, CPU128_SHIFT); - - // Control registers. - public static final Register c0 = new Register(0, 0, "c0", CPU_CONTROL); - public static final Register c1 = new Register(1, 1, "c1", CPU_CONTROL); - public static final Register c2 = new Register(2, 2, "c2", CPU_CONTROL); - public static final Register c3 = new Register(3, 3, "c3", CPU_CONTROL); - public static final Register c4 = new Register(4, 4, "c4", CPU_CONTROL); - public static final Register c5 = new Register(5, 5, "c5", CPU_CONTROL); - public static final Register c6 = new Register(6, 6, "c6", CPU_CONTROL); - public static final Register c7 = new Register(7, 7, "c7", CPU_CONTROL); - - // 32 bit registers. - public static final Register s0 = new Register(8, 0, "s0", CPU32); - public static final Register s1 = new Register(9, 1, "s1", CPU32); - public static final Register s2 = new Register(10, 2, "s2", CPU32); - public static final Register s3 = new Register(11, 3, "s3", CPU32); - public static final Register s4 = new Register(12, 4, "s4", CPU32); - public static final Register s5 = new Register(13, 5, "s5", CPU32); - public static final Register s6 = new Register(14, 6, "s6", CPU32); - public static final Register s7 = new Register(15, 7, "s7", CPU32); - public static final Register s8 = new Register(16, 8, "s8", CPU32); - public static final Register s9 = new Register(17, 9, "s9", CPU32); - public static final Register s10 = new Register(18, 10, "s10", CPU32); - public static final Register s11 = new Register(19, 11, "s11", CPU32); - public static final Register s12 = new Register(20, 12, "s12", CPU32); - public static final Register s13 = new Register(21, 13, "s13", CPU32); - public static final Register s14 = new Register(22, 14, "s14", CPU32); - public static final Register s15 = new Register(23, 15, "s15", CPU32); - public static final Register s16 = new Register(24, 16, "s16", CPU32); - public static final Register s17 = new Register(25, 17, "s17", CPU32); - public static final Register s18 = new Register(26, 18, "s18", CPU32); - public static final Register s19 = new Register(27, 19, "s19", CPU32); - public static final Register s20 = new Register(28, 20, "s20", CPU32); - public static final Register s21 = new Register(29, 21, "s21", CPU32); - public static final Register s22 = new Register(30, 22, "s22", CPU32); - public static final Register s23 = new Register(31, 23, "s23", CPU32); - public static final Register s24 = new Register(32, 24, "s24", CPU32); - public static final Register s25 = new Register(33, 25, "s25", CPU32); - public static final Register s26 = new Register(34, 26, "s26", CPU32); - public static final Register s27 = new Register(35, 27, "s27", CPU32); - public static final Register s28 = new Register(36, 28, "s28", CPU32); - public static final Register s29 = new Register(37, 29, "s29", CPU32); - public static final Register s30 = new Register(38, 30, "s30", CPU32); - public static final Register s31 = new Register(39, 31, "s31", CPU32); - - // 64 bit registers. - public static final Register d0 = new Register(40, 0, "d0", CPU64); - public static final Register d1 = new Register(41, 1, "d1", CPU64); - public static final Register d2 = new Register(42, 2, "d2", CPU64); - public static final Register d3 = new Register(43, 3, "d3", CPU64); - public static final Register d4 = new Register(44, 4, "d4", CPU64); - public static final Register d5 = new Register(45, 5, "d5", CPU64); - public static final Register d6 = new Register(46, 6, "d6", CPU64); - public static final Register d7 = new Register(47, 7, "d7", CPU64); - public static final Register d8 = new Register(48, 8, "d8", CPU64); - public static final Register d9 = new Register(49, 9, "d9", CPU64); - public static final Register d10 = new Register(50, 10, "d10", CPU64); - public static final Register d11 = new Register(51, 11, "d11", CPU64); - public static final Register d12 = new Register(52, 12, "d12", CPU64); - public static final Register d13 = new Register(53, 13, "d13", CPU64); - public static final Register d14 = new Register(54, 14, "d14", CPU64); - public static final Register d15 = new Register(55, 15, "d15", CPU64); - - // 128 bit registers. - public static final Register q0 = new Register(56, 0, "q0", CPU128); - public static final Register q1 = new Register(57, 1, "q1", CPU128); - public static final Register q2 = new Register(58, 2, "q2", CPU128); - public static final Register q3 = new Register(59, 3, "q3", CPU128); - public static final Register q4 = new Register(60, 4, "q4", CPU128); - public static final Register q5 = new Register(61, 5, "q5", CPU128); - public static final Register q6 = new Register(62, 6, "q6", CPU128); - public static final Register q7 = new Register(63, 7, "q7", CPU128); - public static final Register q8 = new Register(64, 8, "q8", CPU128); - public static final Register q9 = new Register(65, 9, "q9", CPU128); - public static final Register q10 = new Register(66, 10, "q10", CPU128); - public static final Register q11 = new Register(67, 11, "q11", CPU128); - public static final Register q12 = new Register(68, 12, "q12", CPU128); - public static final Register q13 = new Register(69, 13, "q13", CPU128); - public static final Register q14 = new Register(70, 14, "q14", CPU128); - public static final Register q15 = new Register(71, 15, "q15", CPU128); - - // non-allocatable registers used for deopt - public static final Register s32 = new Register(72, 32, "s32", CPU32); - public static final Register s33 = new Register(73, 33, "s33", CPU32); - public static final Register s34 = new Register(74, 34, "s34", CPU32); - public static final Register s35 = new Register(75, 35, "s35", CPU32); - public static final Register s36 = new Register(76, 36, "s36", CPU32); - public static final Register s37 = new Register(77, 37, "s37", CPU32); - public static final Register s38 = new Register(78, 38, "s38", CPU32); - public static final Register s39 = new Register(79, 39, "s39", CPU32); - public static final Register d16 = new Register(80, 16, "d16", CPU64); - public static final Register d17 = new Register(81, 17, "d17", CPU64); - public static final Register d18 = new Register(82, 18, "d18", CPU64); - public static final Register d19 = new Register(83, 19, "d19", CPU64); - public static final Register d20 = new Register(84, 20, "d20", CPU64); - - public static final Register threadRegister = d20; - public static final Register actionAndReasonReg = s32; - public static final Register codeBufferOffsetReg = s33; - - // @formatter:off - public static final Register[] cRegisters = { - c0, c1, c2, c3, c4, c5, c6, c7 - }; - - public static final Register[] sRegisters = { - s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, - s11, s12, s13, s14, s15, s16, s17, s18, s19, - s20, s21, s22, s23, s24, s25, s26, s27, s28, - s29, s30, s31 - }; - - public static final Register[] dRegisters = { - d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, threadRegister - }; - - public static final Register[] qRegisters = { - q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, q12, q13, q14, q15 - }; - - public static final Register[] allRegisters = { - c0, c1, c2, c3, c4, c5, c6, c7, s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, - s16, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31, - d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, - d14, d15, q0, q1, q2, q3, q4, q5, q6, q7, q8, q9, q10, q11, - q12, q13, q14, q15, - s32, s33, s34, s35, s36, s37, s38, s39, - d16, d17, d18, d19, threadRegister - }; - - // @formatter:on - - public HSAIL() { - super("HSAIL", 8, ByteOrder.LITTLE_ENDIAN, false, allRegisters, 0, 1, CPU128_OFFSET + CPU128_NUM << CPU128_SHIFT, 8); - } - - public static int getStackOffset(Value reg) { - return -(((StackSlot) reg).getRawOffset()); - } - - /** - * The mapping to stack slots is always relative to the beginning of the spillseg. - * {@link #getStackOffset(Value)} returns the positive version of the originally negative - * offset. Then we back up from that by {@code argSize} in bytes. This ensures that slots of - * different size do not overlap, even though we have converted from negative to positive - * offsets. - */ - public static int getStackOffsetStart(Value reg, int argSize) { - int argSizeInBytes = argSize / 8; - return getStackOffset(reg) - argSizeInBytes; - } - - public static String mapRegister(Value arg) { - return "$" + asRegister(arg).name; - } - - @Override - public boolean canStoreValue(RegisterCategory category, PlatformKind platformKind) { - if (!(platformKind instanceof Kind)) { - return false; - } - Kind kind = (Kind) platformKind; - if (category.equals(CPU32)) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Float: - return true; - case Long: - case Double: - case Object: - return false; - } - } else if (category.equals(CPU64) || category.equals(CPU128)) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Float: - case Long: - case Double: - case Object: - return true; - } - } - return false; - } - - @Override - public PlatformKind getLargestStorableKind(RegisterCategory category) { - if (category.equals(CPU32)) { - return Kind.Int; - } else if (category.equals(CPU64) || category.equals(CPU128)) { - return Kind.Long; - } else { - return Kind.Illegal; - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILAddressValue.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILAddressValue.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2009, 2014, 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.lir.hsail; - -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.hsail.*; -import com.oracle.graal.lir.*; - -/** - * Represents an address value used in HSAIL code. - */ -public final class HSAILAddressValue extends CompositeValue { - - private static final long serialVersionUID = 1802222435353022623L; - @Component({REG, LIRInstruction.OperandFlag.ILLEGAL}) private AllocatableValue base; - private final long displacement; - - /** - * Creates an {@link HSAILAddressValue} with given base register and no displacement. - * - * @param kind the kind of the value being addressed - * @param base the base register - */ - public HSAILAddressValue(LIRKind kind, AllocatableValue base) { - this(kind, base, 0); - } - - /** - * Creates an {@link HSAILAddressValue} with given base register and a displacement. This is the - * most general constructor. - * - * @param kind the kind of the value being addressed - * @param base the base register - * @param displacement the displacement - */ - public HSAILAddressValue(LIRKind kind, AllocatableValue base, long displacement) { - super(kind); - this.base = base; - this.displacement = displacement; - assert !isStackSlotValue(base); - } - - public HSAILAddress toAddress() { - Register baseReg = base.equals(Value.ILLEGAL) ? Register.None : asRegister(base); - return new HSAILAddress(baseReg, displacement); - } - - @Override - public String toString() { - StringBuilder s = new StringBuilder(); - s.append(getKind().getJavaName()).append("["); - String sep = ""; - if (isLegal(base)) { - s.append(base); - sep = " + "; - } - if (displacement < 0) { - s.append(" - ").append(-displacement); - } else if (displacement > 0) { - s.append(sep).append(displacement); - } - s.append("]"); - return s.toString(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof HSAILAddressValue) { - HSAILAddressValue addr = (HSAILAddressValue) obj; - return getLIRKind().equals(addr.getLIRKind()) && displacement == addr.displacement && base.equals(addr.base); - } - return false; - } - - @Override - public int hashCode() { - return base.hashCode() ^ ((int) displacement << 4) ^ (getKind().ordinal() << 12); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 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 Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,384 +0,0 @@ -/* - * 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.lir.hsail; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -/** - * Defines arithmetic instruction nodes. - */ -public enum HSAILArithmetic { - ABS, - CALL, - CEIL, - FDIV, - FLOOR, - FREM, - DADD, - DDIV, - DMUL, - DNEG, - DREM, - DSUB, - FADD, - FMUL, - FNEG, - FSUB, - IADD, - IAND, - ICARRY, - IDIV, - IMAX, - IMIN, - IMUL, - INEG, - INOT, - IOR, - IREM, - ISHL, - ISHR, - ISUB, - IUADD, - IUCARRY, - IUDIV, - IUMAX, - IUMIN, - IUMUL, - IUREM, - IUSHR, - IUSUB, - IXOR, - LADD, - LAND, - LCARRY, - LDIV, - LMAX, - LMIN, - LMUL, - LNEG, - LNOT, - LOR, - LREM, - LSHL, - LSHR, - LSUB, - LUADD, - LUCARRY, - LUDIV, - LUMAX, - LUMIN, - LUMUL, - LUREM, - LUSHR, - LUSUB, - LXOR, - OADD, - RINT, - SQRT, - UNDEF; - - public static class ConvertOp extends HSAILLIRInstruction { - private final String from; - private final String to; - @Def({REG}) protected AllocatableValue result; - @Use({REG}) protected AllocatableValue x; - - public ConvertOp(AllocatableValue result, AllocatableValue x, String to, String from) { - this.from = from; - this.to = to; - this.result = result; - this.x = x; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitConvert(result, x, to, from); - } - } - - public static class Op1Reg extends HSAILLIRInstruction { - @Opcode private final HSAILArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, CONST}) protected Value x; - - public Op1Reg(HSAILArithmetic opcode, Value result, Value x) { - this.opcode = opcode; - this.result = result; - this.x = x; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - emit(crb, masm, opcode, result, x, null); - } - } - - public static class Op2Reg extends HSAILLIRInstruction { - @Opcode private final HSAILArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, CONST}) protected Value x; - @Alive({REG, CONST}) protected Value y; - - public Op2Reg(HSAILArithmetic opcode, Value result, Value x, Value y) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - emit(crb, masm, opcode, result, x, y, null); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, y); - } - } - - public static class ShiftOp extends HSAILLIRInstruction { - @Opcode private final HSAILArithmetic opcode; - @Def({REG}) protected Value result; - @Use({REG, CONST}) protected Value x; - @Alive({REG, CONST}) protected Value y; - - public ShiftOp(HSAILArithmetic opcode, Value result, Value x, Value y) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - emit(crb, masm, opcode, result, x, y, null); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, x); - assert y.getKind().getStackKind() == Kind.Int; - } - } - - public static class DivOp extends HSAILLIRInstruction { - @Opcode private final HSAILArithmetic opcode; - @Def protected Value result; - @Use protected Value x; - @Alive protected Value y; - @State protected LIRFrameState state; - - public DivOp(HSAILArithmetic opcode, Value result, Value x, Value y, LIRFrameState state) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - emit(crb, masm, opcode, result, y, state); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, y); - } - } - - @SuppressWarnings("unused") - protected static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value result) { - switch (opcode) { - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - /** - * Emits the HSAIL code for an arithmetic operation taking one input parameter. - * - * @param crb the CompilationResultBuilder - * @param masm the HSAIL assembler - * @param opcode the opcode of the arithmetic operation - * @param dst the destination - * @param src the source parameter - * @param info structure that stores the LIRFrameState. Used for exception handling. - */ - - public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src, LIRFrameState info) { - int exceptionOffset = -1; - if (isRegister(src)) { - switch (opcode) { - case ABS: - masm.emit("abs", dst, src); - break; - case CEIL: - masm.emit("ceil", dst, src); - break; - case FLOOR: - masm.emit("floor", dst, src); - break; - case RINT: - masm.emit("rint", dst, src); - break; - case SQRT: - masm.emit("sqrt", dst, src); - break; - case UNDEF: - masm.undefined("undefined node"); - break; - case CALL: - masm.undefined("undefined node CALL"); - break; - case INOT: - case LNOT: - masm.emitForceBitwise("not", dst, src); - break; - case INEG: - case LNEG: - case FNEG: - case DNEG: - masm.emit("neg", dst, src); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } else { - throw GraalInternalError.shouldNotReachHere(); - } - if (info != null) { - assert exceptionOffset != -1; - crb.recordImplicitException(exceptionOffset, info); - } - } - - public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILArithmetic opcode, Value dst, Value src1, Value src2, LIRFrameState info) { - /** - * First check if one of src1 or src2 is an AddressValue. If it is, convert the address to a - * register using an lda instruction. We can just reuse the eventual dst register for this. - */ - if (src1 instanceof HSAILAddressValue) { - assert (!(src2 instanceof HSAILAddressValue)); - masm.emitLda(dst, ((HSAILAddressValue) src1).toAddress()); - emit(crb, masm, opcode, dst, dst, src2, info); - return; - } else if (src2 instanceof HSAILAddressValue) { - assert (!(src1 instanceof HSAILAddressValue)); - masm.emitLda(dst, ((HSAILAddressValue) src2).toAddress()); - emit(crb, masm, opcode, dst, src1, dst, info); - return; - } - int exceptionOffset = -1; - switch (opcode) { - case IADD: - case LADD: - case DADD: - case FADD: - case OADD: - masm.emit("add", dst, src1, src2); - break; - case ISUB: - case LSUB: - case DSUB: - case FSUB: - masm.emit("sub", dst, src1, src2); - break; - case IMUL: - case LMUL: - case FMUL: - case DMUL: - case LUMUL: - masm.emit("mul", dst, src1, src2); - break; - case IDIV: - case LDIV: - case FDIV: - case DDIV: - masm.emit("div", dst, src1, src2); - break; - case IMAX: - case LMAX: - masm.emit("max", dst, src1, src2); - break; - case IMIN: - case LMIN: - masm.emit("min", dst, src1, src2); - break; - case ISHL: - case LSHL: - masm.emit("shl", dst, src1, src2); - break; - case ISHR: - case LSHR: - masm.emit("shr", dst, src1, src2); - break; - case IUSHR: - case LUSHR: - masm.emitForceUnsigned("shr", dst, src1, src2); - break; - case IAND: - case LAND: - masm.emitForceBitwise("and", dst, src1, src2); - break; - case IXOR: - case LXOR: - masm.emitForceBitwise("xor", dst, src1, src2); - break; - case IOR: - case LOR: - masm.emitForceBitwise("or", dst, src1, src2); - break; - case IREM: - case LREM: - masm.emit("rem", dst, src1, src2); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - if (info != null) { - assert exceptionOffset != -1; - crb.recordImplicitException(exceptionOffset, info); - } - } - - private static void verifyKind(HSAILArithmetic opcode, Value result, Value x, Value y) { - assert (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("LU") && result.getKind() == Kind.Long && x.getKind() == Kind.Long && y.getKind() == Kind.Int) || - (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) || - (opcode.name().startsWith("O") && result.getKind() == Kind.Object && x.getKind() == Kind.Object && (y.getKind() == Kind.Int || y.getKind() == Kind.Long)); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILBitManipulationOp.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILBitManipulationOp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.lir.hsail; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -/** - * Defines bit manipulation operations. - */ -public class HSAILBitManipulationOp extends HSAILLIRInstruction { - - public enum IntrinsicOpcode { - IPOPCNT, - LPOPCNT, - IBSR, - LBSR, - BSF; - } - - @Opcode private final IntrinsicOpcode opcode; - @Def protected Value result; - @Use({OperandFlag.REG}) protected Value input; - - public HSAILBitManipulationOp(IntrinsicOpcode opcode, Value result, Value input) { - this.opcode = opcode; - this.result = result; - this.input = input; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - switch (opcode) { - case IPOPCNT: - throw GraalInternalError.shouldNotReachHere(); - case LPOPCNT: - throw GraalInternalError.shouldNotReachHere(); - default: - throw GraalInternalError.shouldNotReachHere(); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILCompare.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILCompare.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2011, 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.lir.hsail; - -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -/** - * Implementation of compare operations. - */ -public enum HSAILCompare { - ICMP(Kind.Int), - LCMP(Kind.Long), - ACMP(Kind.Object), - FCMP(Kind.Float), - DCMP(Kind.Double); - - public final Kind kind; - - private HSAILCompare(Kind kind) { - this.kind = kind; - } - - public static class CompareOp extends HSAILLIRInstruction { - - @Opcode private final HSAILCompare opcode; - @Use({REG, CONST}) protected Value x; - @Use({REG, CONST}) protected Value y; - @Def({REG}) protected Value z; - private final Condition condition; - public boolean unordered = false; - - public CompareOp(HSAILCompare opcode, Condition condition, Value x, Value y, Value z) { - this.opcode = opcode; - this.condition = condition; - this.x = x; - this.y = y; - this.z = z; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - emit(crb, masm, opcode, condition, x, y, z, unordered); - } - - @Override - public void verify() { - super.verify(); - assert (x.getKind() == y.getKind() && ((name().startsWith("I") && x.getKind() == Kind.Int) || (name().startsWith("L") && x.getKind() == Kind.Long) || - (name().startsWith("A") && x.getKind() == Kind.Object) || (name().startsWith("F") && x.getKind() == Kind.Float) || (name().startsWith("D") && x.getKind() == Kind.Double))); - } - } - - @SuppressWarnings("unused") - public static void emit(CompilationResultBuilder crb, HSAILAssembler masm, HSAILCompare opcode, Condition condition, Value x, Value y, Value z, boolean unorderedIsTrue) { - masm.emitCompare(opcode.kind, x, y, conditionToString(condition), unorderedIsTrue, isUnsignedCompare(condition)); - } - - public static String conditionToString(Condition condition) { - switch (condition) { - case EQ: - return "eq"; - case NE: - return "ne"; - case LT: - case BT: - return "lt"; - case LE: - case BE: - return "le"; - case GT: - case AT: - return "gt"; - case GE: - case AE: - return "ge"; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - private static boolean isUnsignedCompare(Condition condition) { - switch (condition) { - case BT: - case BE: - case AT: - case AE: - return true; - default: - return false; - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 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 Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,359 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.hsail; - -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.*; -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.hsail.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.BlockEndOp; -import com.oracle.graal.lir.SwitchStrategy.BaseSwitchClosure; -import com.oracle.graal.lir.asm.*; - -/** - * Implementation of control flow instructions. - */ -public class HSAILControlFlow { - - /** - * This class represents the LIR instruction that the HSAIL backend generates for a switch - * construct in Java. - * - * The HSAIL backend compiles switch statements into a series of cascading compare and branch - * instructions because this is the currently the recommended way to generate optimally - * performing HSAIL code. Thus the execution path for both the TABLESWITCH and LOOKUPSWITCH - * bytecodes go through this op. - */ - public static class StrategySwitchOp extends HSAILLIRInstruction implements BlockEndOp { - /** - * The array of key constants used for the cases of this switch statement. - */ - @Use({CONST}) protected JavaConstant[] keyConstants; - /** - * The branch target labels that correspond to each case. - */ - private final LabelRef[] keyTargets; - private LabelRef defaultTarget; - /** - * The key of the switch. This will be compared with each of the keyConstants. - */ - @Alive({REG}) protected Value key; - - private final SwitchStrategy strategy; - - /** - * Constructor. Called from the HSAILLIRGenerator.emitStrategySwitch routine. - */ - public StrategySwitchOp(SwitchStrategy strategy, LabelRef[] keyTargets, LabelRef defaultTarget, Value key) { - this.strategy = strategy; - this.keyConstants = strategy.keyConstants; - this.keyTargets = keyTargets; - this.defaultTarget = defaultTarget; - this.key = key; - assert keyConstants.length == keyTargets.length; - assert keyConstants.length == strategy.keyProbabilities.length; - } - - /** - * Generates the code for this switch op. - * - * @param crb the CompilationResultBuilder - * @param masm the HSAIL assembler - */ - @Override - public void emitCode(CompilationResultBuilder crb, final HSAILAssembler masm) { - BaseSwitchClosure closure = new BaseSwitchClosure(crb, masm, keyTargets, defaultTarget) { - @Override - protected void conditionalJump(int index, Condition condition, Label target) { - switch (key.getKind()) { - case Int: - case Long: - case Object: - // Generate cascading compare and branches for each case. - masm.emitCompare(key.getKind(), key, keyConstants[index], HSAILCompare.conditionToString(condition), false, false); - masm.cbr(masm.nameOf(target)); - break; - default: - throw new GraalInternalError("switch not supported for kind " + key.getKind()); - } - } - }; - strategy.run(closure); - } - } - - public static class ReturnOp extends HSAILLIRInstruction implements BlockEndOp { - - @Use({REG, ILLEGAL}) protected Value x; - - public ReturnOp(Value x) { - this.x = x; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - crb.frameContext.leave(crb); - masm.exit(); - } - } - - public interface DeoptimizingOp { - LIRFrameState getFrameState(); - - int getCodeBufferPos(); - } - - /*** - * The ALIVE annotation is so we can get a scratch32 register that does not clobber - * actionAndReason. - */ - public static class DeoptimizeOp extends ReturnOp implements DeoptimizingOp { - - @Alive({REG, CONST}) protected Value actionAndReason; - @State protected LIRFrameState frameState; - protected MetaAccessProvider metaAccessProvider; - protected String emitName; - protected int codeBufferPos = -1; - private final boolean emitInfopoint; - - public DeoptimizeOp(Value actionAndReason, LIRFrameState frameState, String emitName, boolean emitInfopoint, MetaAccessProvider metaAccessProvider) { - super(Value.ILLEGAL); // return with no ret value - this.actionAndReason = actionAndReason; - this.frameState = frameState; - this.emitName = emitName; - this.metaAccessProvider = metaAccessProvider; - this.emitInfopoint = emitInfopoint; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - String reasonString; - if (isConstant(actionAndReason)) { - DeoptimizationReason reason = metaAccessProvider.decodeDeoptReason((JavaConstant) actionAndReason); - reasonString = reason.toString(); - } else { - reasonString = "Variable Reason"; - } - - masm.emitComment("// " + emitName + ", Deoptimization for " + reasonString); - - if (frameState == null) { - masm.emitComment("// frameState == null"); - // and emit the return - super.emitCode(crb, masm); - return; - } - // get a unique codeBuffer position - // when we save our state, we will save this as well (it can be used as a key to get the - // debugInfo) - codeBufferPos = masm.position(); - - masm.emitComment("/* HSAIL Deoptimization pos=" + codeBufferPos + ", bci=" + frameState.debugInfo().getBytecodePosition().getBCI() + ", frameState=" + frameState + " */"); - - AllocatableValue actionAndReasonReg = HSAIL.actionAndReasonReg.asValue(LIRKind.value(Kind.Int)); - AllocatableValue codeBufferOffsetReg = HSAIL.codeBufferOffsetReg.asValue(LIRKind.value(Kind.Int)); - masm.emitMov(Kind.Int, actionAndReasonReg, actionAndReason); - masm.emitMov(Kind.Int, codeBufferOffsetReg, JavaConstant.forInt(codeBufferPos)); - masm.emitJumpToLabelName(masm.getDeoptLabelName()); - - // Now record the debuginfo. If HSAIL deoptimization is off, - // no debuginfo is emitted and the kernel will return without - // a deoptimization. - if (emitInfopoint) { - crb.recordInfopoint(codeBufferPos, frameState, InfopointReason.IMPLICIT_EXCEPTION); - } - } - - public LIRFrameState getFrameState() { - return frameState; - } - - public int getCodeBufferPos() { - return codeBufferPos; - } - } - - public static class UnwindOp extends ReturnOp { - - protected String commentMessage; - - public UnwindOp(String commentMessage) { - super(Value.ILLEGAL); // return with no ret value - this.commentMessage = commentMessage; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitComment("// " + commentMessage); - super.emitCode(crb, masm); - } - } - - public static class ForeignCallNoArgOp extends HSAILLIRInstruction { - - @Def({REG}) protected Value out; - String callName; - - public ForeignCallNoArgOp(String callName, Value out) { - this.out = out; - this.callName = callName; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitComment("//ForeignCall to " + callName + " would have gone here"); - } - } - - public static class ForeignCall1ArgOp extends ForeignCallNoArgOp { - - @Use({REG, ILLEGAL}) protected Value arg1; - - public ForeignCall1ArgOp(String callName, Value out, Value arg1) { - super(callName, out); - this.arg1 = arg1; - } - } - - public static class ForeignCall2ArgOp extends ForeignCall1ArgOp { - - @Use({REG, ILLEGAL}) protected Value arg2; - - public ForeignCall2ArgOp(String callName, Value out, Value arg1, Value arg2) { - super(callName, out, arg1); - this.arg2 = arg2; - } - } - - public static class CompareBranchOp extends HSAILLIRInstruction implements StandardOp.BranchOp { - - @Opcode protected final HSAILCompare opcode; - @Use({REG, CONST}) protected Value x; - @Use({REG, CONST}) protected Value y; - @Def({REG}) protected Value z; - protected final Condition condition; - protected final LabelRef trueDestination; - protected final LabelRef falseDestination; - @Def({REG}) protected Value result; - protected final boolean unordered; - - public CompareBranchOp(HSAILCompare opcode, Condition condition, Value x, Value y, Value z, Value result, LabelRef trueDestination, LabelRef falseDestination, boolean unordered) { - this.condition = condition; - this.opcode = opcode; - this.x = x; - this.y = y; - this.z = z; - this.result = result; - this.trueDestination = trueDestination; - this.falseDestination = falseDestination; - this.unordered = unordered; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - if (crb.isSuccessorEdge(trueDestination)) { - HSAILCompare.emit(crb, masm, opcode, condition.negate(), x, y, z, !unordered); - masm.cbr(masm.nameOf(falseDestination.label())); - } else { - HSAILCompare.emit(crb, masm, opcode, condition, x, y, z, unordered); - masm.cbr(masm.nameOf(trueDestination.label())); - if (!crb.isSuccessorEdge(falseDestination)) { - masm.jmp(falseDestination.label()); - } - } - } - } - - public static class CondMoveOp extends HSAILLIRInstruction { - - @Opcode protected final HSAILCompare opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, CONST}) protected Value trueValue; - @Use({REG, CONST}) protected Value falseValue; - @Use({REG, CONST}) protected Value left; - @Use({REG, CONST}) protected Value right; - protected final Condition condition; - - public CondMoveOp(HSAILCompare opcode, Variable left, Value right, Variable result, Condition condition, Value trueValue, Value falseValue) { - this.opcode = opcode; - this.result = result; - this.left = left; - this.right = right; - this.condition = condition; - this.trueValue = trueValue; - this.falseValue = falseValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - HSAILCompare.emit(crb, masm, opcode, condition, left, right, right, false); - cmove(masm, result, trueValue, falseValue); - } - } - - public static class FloatCondMoveOp extends CondMoveOp { - - private final boolean unorderedIsTrue; - - public FloatCondMoveOp(HSAILCompare opcode, Variable left, Variable right, Variable result, Condition condition, boolean unorderedIsTrue, Variable trueValue, Value falseValue) { - super(opcode, left, right, result, condition, trueValue, falseValue); - this.unorderedIsTrue = unorderedIsTrue; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - HSAILCompare.emit(crb, masm, opcode, condition, left, right, right, unorderedIsTrue); - cmove(masm, result, trueValue, falseValue); - } - } - - private static void cmove(HSAILAssembler masm, Value result, Value trueValue, Value falseValue) { - // Check that we don't overwrite an input operand before it is used. - assert (result.getKind() == trueValue.getKind() && result.getKind() == falseValue.getKind()); - int width; - switch (result.getKind()) { - /** - * We don't need to pass the cond to the assembler. We will always use $c0 as the control - * register. - */ - case Float: - case Int: - width = 32; - break; - case Double: - case Long: - width = 64; - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - masm.emitConditionalMove(result, trueValue, falseValue, width); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILFrameMap.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILFrameMap.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.hsail; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.lir.framemap.*; - -/** - * HSAIL specific frame map. - * - * This is the format of a HSAIL stack frame: - * - *

- * TODO stack frame layout
- * 
- */ -public final class HSAILFrameMap extends FrameMap { - - public HSAILFrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig) { - super(codeCache, registerConfig); - } - - @Override - public int totalFrameSize() { - // FIXME return some sane values - return frameSize(); - } - - @Override - public int currentFrameSize() { - // FIXME return some sane values - return alignFrameSize(outgoingSize + spillSize); - } - - @Override - protected int alignFrameSize(int size) { - // FIXME return some sane values - int x = size + (getTarget().stackAlignment - 1); - return (x / getTarget().stackAlignment) * getTarget().stackAlignment; - } - - @Override - public int offsetToCalleeSaveArea() { - return frameSize() - calleeSaveAreaSize(); - } - - @Override - protected StackSlot allocateNewSpillSlot(LIRKind kind, int additionalOffset) { - return StackSlot.get(kind, -spillSize + additionalOffset, true); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILLIRInstruction.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILLIRInstruction.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * 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.lir.hsail; - -import com.oracle.graal.asm.hsail.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -/** - * Convenience class to provide HSAILAssembler for the {@link #emitCode} method. - */ -public abstract class HSAILLIRInstruction extends LIRInstructionBase { - - @Override - public final void emitCode(CompilationResultBuilder crb) { - emitCode(crb, (HSAILAssembler) crb.asm); - } - - public abstract void emitCode(CompilationResultBuilder crb, HSAILAssembler masm); -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILMove.java --- a/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILMove.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,518 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.hsail; - -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.hsail.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.debug.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.MoveOp; -import com.oracle.graal.lir.asm.*; -import com.oracle.graal.hsail.*; - -/** - * Implementation of move instructions. - */ -public class HSAILMove { - - // Stack size in bytes (used to keep track of spilling). - static int maxDatatypeSize; - // Maximum stack offset used by a store operation. - static long maxStackOffset = 0; - - public static long upperBoundStackSize() { - return maxStackOffset + maxDatatypeSize; - } - - private abstract static class AbstractMoveOp extends HSAILLIRInstruction implements MoveOp { - - private Kind moveKind; - - public AbstractMoveOp(Kind moveKind) { - this.moveKind = moveKind; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - move(moveKind, crb, masm, getResult(), getInput()); - } - } - - @Opcode("MOVE") - public static class MoveToRegOp extends AbstractMoveOp { - - @Def({REG, HINT}) protected AllocatableValue result; - @Use({REG, STACK, CONST}) protected Value input; - - public MoveToRegOp(Kind moveKind, AllocatableValue result, Value input) { - super(moveKind); - this.result = result; - this.input = input; - checkForNullObjectInput(); - } - - private void checkForNullObjectInput() { - if (result.getKind() == Kind.Object && isConstant(input) && input.getKind() == Kind.Long && ((JavaConstant) input).asLong() == 0) { - input = JavaConstant.NULL_POINTER; - } - } - - @Override - public Value getInput() { - return input; - } - - @Override - public AllocatableValue getResult() { - return result; - } - } - - @Opcode("MOVE") - public static class MoveFromRegOp extends AbstractMoveOp { - - @Def({REG, STACK}) protected AllocatableValue result; - @Use({REG, CONST, HINT}) protected Value input; - - public MoveFromRegOp(Kind moveKind, AllocatableValue result, Value input) { - super(moveKind); - this.result = result; - this.input = input; - } - - @Override - public Value getInput() { - return input; - } - - @Override - public AllocatableValue getResult() { - return result; - } - } - - public abstract static class MemOp extends HSAILLIRInstruction { - - protected final Kind kind; - @Use({COMPOSITE}) protected HSAILAddressValue address; - @State protected LIRFrameState state; - - public MemOp(Kind kind, HSAILAddressValue address, LIRFrameState state) { - this.kind = kind; - this.address = address; - this.state = state; - } - - protected abstract void emitMemAccess(HSAILAssembler masm); - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - if (state != null) { - // crb.recordImplicitException(masm.position(), state); - throw new InternalError("NYI"); - } - emitMemAccess(masm); - } - } - - public static class MembarOp extends HSAILLIRInstruction { - - private final int barriers; - - public MembarOp(final int barriers) { - this.barriers = barriers; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitMembar(barriers); - } - } - - public static class LoadOp extends MemOp { - - @Def({REG}) protected AllocatableValue result; - - public LoadOp(Kind kind, AllocatableValue result, HSAILAddressValue address, LIRFrameState state) { - super(kind, address, state); - this.result = result; - } - - @Override - public void emitMemAccess(HSAILAssembler masm) { - HSAILAddress addr = address.toAddress(); - masm.emitLoad(kind, result, addr); - } - - public boolean usesThreadRegister() { - return (address.toAddress().getBase().equals(HSAIL.threadRegister)); - } - } - - /** - * A LoadOp that uses the HSAIL ld_acq instruction. - */ - public static class LoadAcquireOp extends LoadOp { - public LoadAcquireOp(Kind kind, AllocatableValue result, HSAILAddressValue address, LIRFrameState state) { - super(kind, result, address, state); - } - - @Override - public void emitMemAccess(HSAILAssembler masm) { - HSAILAddress addr = address.toAddress(); - masm.emitLoadAcquire(result, addr); - } - } - - public static class StoreOp extends MemOp { - - @Use({REG}) protected AllocatableValue input; - - public StoreOp(Kind kind, HSAILAddressValue address, AllocatableValue input, LIRFrameState state) { - super(kind, address, state); - this.input = input; - } - - @Override - public void emitMemAccess(HSAILAssembler masm) { - assert isRegister(input); - HSAILAddress addr = address.toAddress(); - masm.emitStore(kind, input, addr); - } - } - - /** - * A StoreOp that uses the HSAIL st_rel instruction. - */ - public static class StoreReleaseOp extends StoreOp { - public StoreReleaseOp(Kind kind, HSAILAddressValue address, AllocatableValue input, LIRFrameState state) { - super(kind, address, input, state); - } - - @Override - public void emitMemAccess(HSAILAssembler masm) { - assert isRegister(input); - HSAILAddress addr = address.toAddress(); - masm.emitStoreRelease(input, addr); - } - } - - public static class StoreConstantOp extends MemOp { - - protected final JavaConstant input; - - public StoreConstantOp(Kind kind, HSAILAddressValue address, JavaConstant input, LIRFrameState state) { - super(kind, address, state); - this.input = input; - } - - @Override - public void emitMemAccess(HSAILAssembler masm) { - switch (kind) { - case Boolean: - case Byte: - masm.emitStoreImmediate(kind, input.asLong() & 0xFF, address.toAddress()); - break; - case Char: - case Short: - masm.emitStoreImmediate(kind, input.asLong() & 0xFFFF, address.toAddress()); - break; - case Int: - case Long: - masm.emitStoreImmediate(kind, input.asLong(), address.toAddress()); - break; - case Float: - masm.emitStoreImmediate(input.asFloat(), address.toAddress()); - break; - case Double: - masm.emitStoreImmediate(input.asDouble(), address.toAddress()); - break; - case Object: - if (input.isNull()) { - masm.emitStoreImmediate(kind, 0L, address.toAddress()); - } else { - throw GraalInternalError.shouldNotReachHere("Cannot store 64-bit constants to object ref"); - } - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - public static class CompressPointer extends HSAILLIRInstruction { - - private final long base; - private final int shift; - private final int alignment; - private final boolean nonNull; - - @Def({REG}) protected AllocatableValue result; - @Temp({REG, HINT}) protected AllocatableValue scratch; - @Use({REG}) protected AllocatableValue input; - - public CompressPointer(AllocatableValue result, AllocatableValue scratch, AllocatableValue input, long base, int shift, int alignment, boolean nonNull) { - this.result = result; - this.scratch = scratch; - this.input = input; - this.base = base; - this.shift = shift; - this.alignment = alignment; - this.nonNull = nonNull; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitMov(Kind.Long, scratch, input); - boolean testForNull = !nonNull; - encodePointer(masm, scratch, base, shift, alignment, testForNull); - masm.emitConvert(result, scratch, "u32", "u64"); - } - } - - public static class UncompressPointer extends HSAILLIRInstruction { - - private final long base; - private final int shift; - private final int alignment; - private final boolean nonNull; - - @Def({REG, HINT}) protected AllocatableValue result; - @Use({REG}) protected AllocatableValue input; - - public UncompressPointer(AllocatableValue result, AllocatableValue input, long base, int shift, int alignment, boolean nonNull) { - this.result = result; - this.input = input; - this.base = base; - this.shift = shift; - this.alignment = alignment; - this.nonNull = nonNull; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitConvert(result, input, "u64", "u32"); - boolean testForNull = !nonNull; - decodePointer(masm, result, base, shift, alignment, testForNull); - } - } - - private static void encodePointer(HSAILAssembler masm, Value scratch, long base, int shift, int alignment, boolean testForNull) { - if (base == 0 && shift == 0) { - return; - } - if (shift != 0) { - assert alignment == shift : "Encode algorithm is wrong"; - } - masm.emitCompressedOopEncode(scratch, base, shift, testForNull); - } - - private static void decodePointer(HSAILAssembler masm, Value result, long base, int shift, int alignment, boolean testForNull) { - if (base == 0 && shift == 0) { - return; - } - if (shift != 0) { - assert alignment == shift : "Decode algorithm is wrong"; - } - masm.emitCompressedOopDecode(result, base, shift, testForNull); - } - - public static class LeaOp extends HSAILLIRInstruction { - - @Def({REG}) protected AllocatableValue result; - @Use({COMPOSITE, UNINITIALIZED}) protected HSAILAddressValue address; - - public LeaOp(AllocatableValue result, HSAILAddressValue address) { - this.result = result; - this.address = address; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - HSAILAddress addr = address.toAddress(); - masm.emitLea(result, addr); - } - } - - public static class StackLeaOp extends HSAILLIRInstruction { - - @Def({REG}) protected AllocatableValue result; - @Use({STACK, UNINITIALIZED}) protected StackSlot slot; - - public StackLeaOp(AllocatableValue result, StackSlot slot) { - this.result = result; - this.slot = slot; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - throw new InternalError("NYI"); - } - } - - @Opcode("CAS") - public static class CompareAndSwapOp extends HSAILLIRInstruction { - - private final Kind accessKind; - - @Def protected AllocatableValue result; - @Use({COMPOSITE}) protected HSAILAddressValue address; - @Use protected AllocatableValue cmpValue; - @Use protected AllocatableValue newValue; - - public CompareAndSwapOp(Kind accessKind, AllocatableValue result, HSAILAddressValue address, AllocatableValue cmpValue, AllocatableValue newValue) { - this.accessKind = accessKind; - this.result = result; - this.address = address; - this.cmpValue = cmpValue; - this.newValue = newValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitAtomicCas(accessKind, result, address.toAddress(), cmpValue, newValue); - } - } - - @Opcode("ATOMIC_READ_AND_ADD") - public static class AtomicReadAndAddOp extends HSAILLIRInstruction { - - private final Kind accessKind; - - @Def protected AllocatableValue result; - @Use({COMPOSITE}) protected HSAILAddressValue address; - @Use({REG, CONST}) protected Value delta; - - public AtomicReadAndAddOp(Kind accessKind, AllocatableValue result, HSAILAddressValue address, Value delta) { - this.accessKind = accessKind; - this.result = result; - this.address = address; - this.delta = delta; - } - - public HSAILAddressValue getAddress() { - return address; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - switch (accessKind) { - case Int: - case Long: - masm.emitAtomicAdd(result, address.toAddress(), delta); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - @Opcode("ATOMIC_READ_AND_WRITE") - public static class AtomicReadAndWriteOp extends HSAILLIRInstruction { - - private final Kind accessKind; - - @Def protected AllocatableValue result; - @Use({COMPOSITE}) protected HSAILAddressValue address; - @Use({REG, CONST}) protected Value newValue; - - public AtomicReadAndWriteOp(Kind accessKind, AllocatableValue result, HSAILAddressValue address, Value newValue) { - this.accessKind = accessKind; - this.result = result; - this.address = address; - this.newValue = newValue; - } - - public HSAILAddressValue getAddress() { - return address; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitAtomicExch(accessKind, result, address.toAddress(), newValue); - } - } - - public static class NullCheckOp extends HSAILLIRInstruction { - - @Use protected Value input; - @State protected LIRFrameState state; - - public NullCheckOp(Variable input, LIRFrameState state) { - this.input = input; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - Debug.log("NullCheckOp unimplemented"); - } - } - - @SuppressWarnings("unused") - public static void move(Kind kind, CompilationResultBuilder crb, HSAILAssembler masm, Value result, Value input) { - if (isRegister(input)) { - if (isRegister(result)) { - masm.emitMov(kind, result, input); - } else if (isStackSlot(result)) { - masm.emitSpillStore(kind, input, result); - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } else if (isStackSlot(input)) { - if (isRegister(result)) { - masm.emitSpillLoad(kind, result, input); - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } else if (isConstant(input)) { - if (isRegister(result)) { - masm.emitMov(kind, result, input); - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } - - public static class WorkItemAbsIdOp extends HSAILLIRInstruction { - - @Def({REG}) protected AllocatableValue result; - - public WorkItemAbsIdOp(AllocatableValue result) { - this.result = result; - } - - @Override - public void emitCode(CompilationResultBuilder crb, HSAILAssembler masm) { - masm.emitWorkItemAbsId(result); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXAddressValue.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXAddressValue.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.ptx; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.LIRInstruction.OperandFlag; - -/** - * Represents an address in target machine memory, specified via some combination of a base register - * and a displacement. - */ -public final class PTXAddressValue extends CompositeValue { - - private static final long serialVersionUID = 1802222435353022623L; - - @Component({REG, OperandFlag.ILLEGAL}) private AllocatableValue base; - private final long displacement; - - /** - * Creates an {@link PTXAddressValue} with given base register and no displacement. - * - * @param kind the kind of the value being addressed - * @param base the base register - */ - public PTXAddressValue(LIRKind kind, AllocatableValue base) { - this(kind, base, 0); - } - - /** - * Creates an {@link PTXAddressValue} with given base register and a displacement. This is the - * most general constructor. - * - * @param kind the kind of the value being addressed - * @param base the base register - * @param displacement the displacement - */ - public PTXAddressValue(LIRKind kind, AllocatableValue base, long displacement) { - super(kind); - this.base = base; - this.displacement = displacement; - - assert !isStackSlotValue(base); - } - - public PTXAddress toAddress() { - // Register baseReg = base.equals( == Value.ILLEGAL) ? Register.None : asRegister(base); - return new PTXAddress((Variable) base, displacement); - } - - @Override - public String toString() { - StringBuilder s = new StringBuilder(); - s.append(getKind().getJavaName()).append("["); - String sep = ""; - if (isLegal(base)) { - s.append(base); - sep = " + "; - } - if (displacement < 0) { - s.append(" - ").append(-displacement); - } else if (displacement > 0) { - s.append(sep).append(displacement); - } - s.append("]"); - return s.toString(); - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof PTXAddressValue) { - PTXAddressValue addr = (PTXAddressValue) obj; - return getLIRKind().equals(addr.getLIRKind()) && displacement == addr.displacement && base.equals(addr.base); - } - return false; - } - - @Override - public int hashCode() { - return base.hashCode() ^ ((int) displacement << 4) ^ getLIRKind().hashCode(); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXArithmetic.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXArithmetic.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,427 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.ptx; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.lir.LIRValueUtil.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Add; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.And; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Cvt; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Div; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Mul; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Neg; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Not; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Or; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Rem; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Shl; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Shr; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Sub; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Ushr; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Xor; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -// @formatter:off -public enum PTXArithmetic { - 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, INOT, LNOT; - - - public static class ConvertOp extends PTXLIRInstruction { - private final Kind from; - private final Kind to; - @Def({REG}) protected AllocatableValue result; - @Use({REG, STACK}) protected AllocatableValue x; - - public ConvertOp(AllocatableValue result, AllocatableValue x, Kind to, Kind from) { - this.from = from; - this.to = to; - this.result = result; - this.x = x; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - Variable dst = (Variable) result; - Variable src = (Variable) x; - if (from == Kind.Long && to == Kind.Int) { - new And(dst, src, JavaConstant.forLong(0xFFFFFFFF)).emit(masm); - } else if ((from == Kind.Int || from == Kind.Long) && to == Kind.Short) { - new And(dst, src, JavaConstant.forInt((short) 0xFFFF)).emit(masm); - } else { - new Cvt((Variable) result, (Variable) x, to, from).emit(masm); - } - } - } - - public static class Op1Stack extends PTXLIRInstruction { - @Opcode private final PTXArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - - public Op1Stack(PTXArithmetic opcode, Value result, Value x) { - this.opcode = opcode; - this.result = result; - this.x = x; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(crb, masm, opcode, result, x, null); - } - } - - public static class Op2Stack extends PTXLIRInstruction { - @Opcode private final PTXArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Alive({REG, STACK, CONST}) protected Value y; - - public Op2Stack(PTXArithmetic opcode, Value result, Value x, Value y) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(crb, masm, opcode, result, x, y, null); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, y); - } - } - - public static class Op2Reg extends PTXLIRInstruction { - @Opcode private final PTXArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Alive({REG, CONST}) protected Value y; - - public Op2Reg(PTXArithmetic opcode, Value result, Value x, Value y) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(crb, masm, opcode, result, x, y, null); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, y); - } - } - - public static class Op2RegCommutative extends PTXLIRInstruction { - @Opcode private final PTXArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Use({REG, CONST}) protected Value y; - - public Op2RegCommutative(PTXArithmetic opcode, Value result, Value x, Value y) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - if (sameRegister(result, y)) { - emit(crb, masm, opcode, result, x, null); - } else { - PTXMove.move(crb, masm, result, x); - emit(crb, masm, opcode, result, y, null); - } - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, y); - } - } - - public static class ShiftOp extends PTXLIRInstruction { - @Opcode private final PTXArithmetic opcode; - @Def({REG, HINT}) protected Value result; - @Use({REG, STACK, CONST}) protected Value x; - @Alive({REG, CONST}) protected Value y; - - public ShiftOp(PTXArithmetic opcode, Value result, Value x, Value y) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(crb, masm, opcode, result, x, y, null); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, x); - assert y.getKind().getStackKind() == Kind.Int; - } - } - - public static class DivOp extends PTXLIRInstruction { - @Opcode private final PTXArithmetic opcode; - @Def protected Value result; - @Use protected Value x; - @Alive protected Value y; - @State protected LIRFrameState state; - - public DivOp(PTXArithmetic opcode, Value result, Value x, Value y, LIRFrameState state) { - this.opcode = opcode; - this.result = result; - this.x = x; - this.y = y; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(crb, masm, opcode, result, y, state); - } - - @Override - public void verify() { - super.verify(); - verifyKind(opcode, result, x, y); - } - } - - public static void emit(CompilationResultBuilder crb, PTXMacroAssembler masm, PTXArithmetic opcode, Value dst, Value src, LIRFrameState info) { - int exceptionOffset = -1; - Variable dest = (Variable) dst; - - if (isVariable(src)) { - Variable source = (Variable) src; - switch (opcode) { - case INEG: - case FNEG: - case DNEG: - new Neg(dest, source).emit(masm); - break; - case INOT: - case LNOT: - new Not(dest, source).emit(masm); - break; - case LSHL: - new Shl(dest, dest, src).emit(masm); - break; - case LSHR: - new Shr(dest, dest, src).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); - } - } else if (isConstant(src)) { - switch (opcode) { - case ISUB: - new Sub(dest, dest, src).emit(masm); - break; - case IAND: - new And(dest, dest, src).emit(masm); - break; - case LSHL: - new Shl(dest, dest, src).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } else { - switch (opcode) { - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - if (info != null) { - assert exceptionOffset != -1; - crb.recordImplicitException(exceptionOffset, info); - } - } - - public static void emit(CompilationResultBuilder crb, PTXMacroAssembler masm, PTXArithmetic opcode, - Value dst, Value src1, Value src2, LIRFrameState info) { - int exceptionOffset = -1; - Variable dest = (Variable) dst; - - switch (opcode) { - case IADD: - case LADD: - case FADD: - case DADD: - new Add(dest, src1, src2).emit(masm); - break; - case IAND: - case LAND: - new And(dest, src1, src2).emit(masm); - break; - case ISUB: - case LSUB: - case FSUB: - case DSUB: - new Sub(dest, src1, src2).emit(masm); - break; - case IMUL: - case LMUL: - case FMUL: - case DMUL: - new Mul(dest, src1, src2).emit(masm); - break; - case IDIV: - case LDIV: - case FDIV: - case DDIV: - new Div(dest, src1, src2).emit(masm); - break; - case IOR: - case LOR: - new Or(dest, src1, src2).emit(masm); - break; - case IXOR: - case LXOR: - new Xor(dest, src1, src2).emit(masm); - break; - case ISHL: - case LSHL: - new Shl(dest, src1, src2).emit(masm); - break; - case ISHR: - case LSHR: - new Shr(dest, src1, src2).emit(masm); - break; - case IUSHR: - case LUSHR: - new Ushr(dest, src1, src2).emit(masm); - break; - case IREM: - case LREM: - case FREM: - case DREM: - new Rem(dest, src1, src2).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); - } - - if (info != null) { - assert exceptionOffset != -1; - crb.recordImplicitException(exceptionOffset, info); - } - } - - private static void verifyKind(PTXArithmetic opcode, Value result, Value x, Value y) { - 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: - rk = result.getKind(); - xk = x.getKind(); - yk = y.getKind(); - assert rk == Kind.Long && xk == Kind.Long && yk == Kind.Long; - break; - case LSHL: - case LSHR: - case LUSHR: - rk = result.getKind(); - xk = x.getKind(); - yk = y.getKind(); - assert rk == Kind.Long && xk == Kind.Long && (yk == Kind.Int || 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 : - "opcode=" + opcode + ", result kind=" + rk + ", x kind=" + xk + ", y kind=" + yk; - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + opcode); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXBitManipulationOp.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXBitManipulationOp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * 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.lir.ptx; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -public class PTXBitManipulationOp extends PTXLIRInstruction { - - public enum IntrinsicOpcode { - IPOPCNT, - LPOPCNT, - IBSR, - LBSR, - BSF; - } - - @Opcode private final IntrinsicOpcode opcode; - @Def protected Value result; - @Use({OperandFlag.REG}) protected Value input; - - public PTXBitManipulationOp(IntrinsicOpcode opcode, Value result, Value input) { - this.opcode = opcode; - this.result = result; - this.input = input; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - Register dst = ValueUtil.asIntReg(result); - Register src = ValueUtil.asRegister(input); - switch (opcode) { - case IPOPCNT: - masm.popc_b32(dst, src); - break; - case LPOPCNT: - masm.popc_b64(dst, src); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXCompare.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXCompare.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2011, 2014, 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.lir.ptx; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXAssembler.Setp; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -public enum PTXCompare { - ICMP, - LCMP, - ACMP, - FCMP, - DCMP; - - public static class CompareOp extends PTXLIRInstruction { - - @Opcode private final PTXCompare opcode; - @Use({REG, STACK, CONST}) protected Value x; - @Use({REG, STACK, CONST}) protected Value y; - // Number of predicate register that would be set by this instruction. - protected int predRegNum; - private final Condition condition; - - public CompareOp(PTXCompare opcode, Condition condition, Value x, Value y, int predReg) { - this.opcode = opcode; - this.condition = condition; - this.x = x; - this.y = y; - predRegNum = predReg; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(masm, opcode, condition, x, y, predRegNum); - } - - @Override - public void verify() { - super.verify(); - assert (name().startsWith("I") && x.getKind() == Kind.Int && 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) || (name().startsWith("D") && x.getKind() == Kind.Double && y.getKind() == Kind.Double); - } - } - - public static void emit(PTXAssembler masm, PTXCompare opcode, Condition condition, Value x, Value y, int p) { - if (isConstant(x)) { - new Setp(condition, x, y, p).emit(masm); - } else if (isConstant(y)) { - switch (opcode) { - case ICMP: - new Setp(condition, x, y, p).emit(masm); - break; - case ACMP: - if (((JavaConstant) y).isNull()) { - new Setp(condition, x, y, p).emit(masm); - } else { - throw GraalInternalError.shouldNotReachHere("Only null object constants are allowed in comparisons"); - } - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } else { - new Setp(condition, x, y, p).emit(masm); - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXControlFlow.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.ptx; - -import static com.oracle.graal.compiler.common.calc.Condition.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.lir.LIRValueUtil.*; - -import com.oracle.graal.api.code.CompilationResult.JumpTable; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.*; -import com.oracle.graal.asm.ptx.PTXAssembler.Global; -import com.oracle.graal.asm.ptx.PTXAssembler.Setp; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Mov; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.BlockEndOp; -import com.oracle.graal.lir.SwitchStrategy.BaseSwitchClosure; -import com.oracle.graal.lir.asm.*; - -public class PTXControlFlow { - - public abstract static class PTXPredicatedLIRInstruction extends PTXLIRInstruction { - private int predRegNum; - - PTXPredicatedLIRInstruction(int regNum) { - predRegNum = regNum; - } - - public int getPredRegNum() { - return predRegNum; - } - } - - public static class ReturnOp extends PTXLIRInstruction { - - @Use({REG, ILLEGAL}) protected Value x; - - public ReturnOp(Value x) { - this.x = x; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - crb.frameContext.leave(crb); - masm.exit(); - } - } - - public static class ReturnNoValOp extends PTXLIRInstruction implements BlockEndOp { - - public ReturnNoValOp() { - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - crb.frameContext.leave(crb); - masm.ret(); - } - } - - public static class BranchOp extends PTXPredicatedLIRInstruction implements StandardOp.BranchOp { - - protected final Condition condition; - protected final LabelRef trueDestination; - protected final LabelRef falseDestination; - - public BranchOp(Condition condition, LabelRef trueDestination, LabelRef falseDestination, int predReg) { - super(predReg); - this.condition = condition; - this.trueDestination = trueDestination; - this.falseDestination = falseDestination; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - if (crb.isSuccessorEdge(trueDestination)) { - masm.bra(masm.nameOf(falseDestination.label()), getPredRegNum(), false); - } else { - masm.bra(masm.nameOf(trueDestination.label()), getPredRegNum(), true); - if (!crb.isSuccessorEdge(falseDestination)) { - masm.jmp(falseDestination.label()); - } - } - } - } - - public static class CondMoveOp extends PTXPredicatedLIRInstruction { - - @Def({REG, HINT}) protected Value result; - @Alive({REG}) protected Value trueValue; - @Use({REG, STACK, CONST}) protected Value falseValue; - private final Condition condition; - - public CondMoveOp(Variable result, Condition condition, Variable trueValue, Value falseValue, int predicateRegister) { - super(predicateRegister); - this.result = result; - this.condition = condition; - this.trueValue = trueValue; - this.falseValue = falseValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - cmove(crb, masm, result, false, condition, false, trueValue, falseValue, getPredRegNum()); - } - } - - public static class FloatCondMoveOp extends PTXPredicatedLIRInstruction { - - @Def({REG}) protected Value result; - @Alive({REG}) protected Value trueValue; - @Alive({REG}) protected Value falseValue; - private final Condition condition; - private final boolean unorderedIsTrue; - - public FloatCondMoveOp(Variable result, Condition condition, boolean unorderedIsTrue, Variable trueValue, Variable falseValue, int predicateRegister) { - super(predicateRegister); - this.result = result; - this.condition = condition; - this.unorderedIsTrue = unorderedIsTrue; - this.trueValue = trueValue; - this.falseValue = falseValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - cmove(crb, masm, result, true, condition, unorderedIsTrue, trueValue, falseValue, getPredRegNum()); - } - } - - private static void cmove(CompilationResultBuilder crb, PTXMacroAssembler asm, Value result, boolean isFloat, Condition condition, boolean unorderedIsTrue, Value trueValue, Value falseValue, - int predicateRegister) { - // check that we don't overwrite an input operand before it is used. - assert !result.equals(trueValue); - - PTXMove.move(crb, asm, result, falseValue); - cmove(asm, result, trueValue, predicateRegister); - - if (isFloat) { - if (unorderedIsTrue && !trueOnUnordered(condition)) { - // cmove(crb, masm, result, ConditionFlag.Parity, trueValue); - throw GraalInternalError.unimplemented(); - } else if (!unorderedIsTrue && trueOnUnordered(condition)) { - // cmove(crb, masm, result, ConditionFlag.Parity, falseValue); - throw GraalInternalError.unimplemented(); - } - } - } - - private static boolean trueOnUnordered(Condition condition) { - switch (condition) { - case NE: - case EQ: - return false; - case LT: - case GE: - return true; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - private static void cmove(PTXMacroAssembler asm, Value result, Value other, int predicateRegister) { - if (isVariable(other)) { - assert !asVariable(other).equals(asVariable(result)) : "other already overwritten by previous move"; - - switch (other.getKind()) { - case Int: - new Mov(asVariable(result), other, predicateRegister).emit(asm); - break; - case Long: - new Mov(asVariable(result), other, predicateRegister).emit(asm); - break; - default: - throw new InternalError("unhandled: " + other.getKind()); - } - } else { - throw GraalInternalError.shouldNotReachHere("cmove: not register"); - } - } - - public static class StrategySwitchOp extends PTXPredicatedLIRInstruction implements BlockEndOp { - - @Use({CONST}) protected JavaConstant[] keyConstants; - private final LabelRef[] keyTargets; - private LabelRef defaultTarget; - @Alive({REG}) protected Value key; - @Temp({REG, ILLEGAL}) protected Value scratch; - private final SwitchStrategy strategy; - - public StrategySwitchOp(SwitchStrategy strategy, LabelRef[] keyTargets, LabelRef defaultTarget, Value key, Value scratch, int predReg) { - super(predReg); - this.strategy = strategy; - this.keyConstants = strategy.keyConstants; - this.keyTargets = keyTargets; - this.defaultTarget = defaultTarget; - this.key = key; - this.scratch = scratch; - assert keyConstants.length == keyTargets.length; - assert keyConstants.length == strategy.keyProbabilities.length; - assert (scratch.getKind() == Kind.Illegal) == (key.getKind() == Kind.Int || key.getKind() == Kind.Long); - } - - @Override - public void emitCode(final CompilationResultBuilder crb, final PTXMacroAssembler masm) { - BaseSwitchClosure closure = new BaseSwitchClosure(crb, masm, keyTargets, defaultTarget) { - @Override - protected void conditionalJump(int index, Condition condition, Label target) { - switch (key.getKind()) { - case Int: - case Long: - if (crb.codeCache.needsDataPatch(keyConstants[index])) { - crb.recordInlineDataInCode(keyConstants[index]); - } - new Setp(EQ, keyConstants[index], key, getPredRegNum()).emit(masm); - break; - case Object: - assert condition == Condition.EQ || condition == Condition.NE; - PTXMove.move(crb, masm, scratch, keyConstants[index]); - new Setp(condition, scratch, key, getPredRegNum()).emit(masm); - break; - default: - throw new GraalInternalError("switch only supported for int, long and object"); - } - masm.bra(masm.nameOf(target), getPredRegNum(), true); - } - }; - strategy.run(closure); - } - } - - public static class TableSwitchOp extends PTXPredicatedLIRInstruction implements BlockEndOp { - - private final int lowKey; - private final LabelRef defaultTarget; - private final LabelRef[] targets; - @Alive protected Value index; - @Temp protected Value scratch; - - public TableSwitchOp(final int lowKey, final LabelRef defaultTarget, final LabelRef[] targets, Variable index, Variable scratch, int predReg) { - super(predReg); - this.lowKey = lowKey; - this.defaultTarget = defaultTarget; - this.targets = targets; - this.index = index; - this.scratch = scratch; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - // Compare index against jump table bounds - - int highKey = lowKey + targets.length - 1; - if (lowKey != 0) { - // subtract the low value from the switch value - // new Sub(value, value, lowKey).emit(masm); - new Setp(GT, index, JavaConstant.forInt(highKey - lowKey), getPredRegNum()).emit(masm); - } else { - new Setp(GT, index, JavaConstant.forInt(highKey), getPredRegNum()).emit(masm); - } - - // Jump to default target if index is not within the jump table - if (defaultTarget != null) { - masm.bra(masm.nameOf(defaultTarget.label()), getPredRegNum(), true); - } - - // address of jump table - int tablePos = masm.position(); - - JumpTable jt = new JumpTable(tablePos, lowKey, highKey, 4); - String name = "jumptable" + jt.position; - - new Global(index, name, targets).emit(masm); - - // bra(Value, name); - - crb.compilationResult.addAnnotation(jt); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXFrameMap.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXFrameMap.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.ptx; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.lir.framemap.*; - -/** - * PTX specific frame map. - * - * This is the format of a PTX stack frame: - * - *
- * TODO stack frame layout
- * 
- */ -public final class PTXFrameMap extends FrameMap { - - public PTXFrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig) { - super(codeCache, registerConfig); - } - - @Override - public int totalFrameSize() { - // FIXME return some sane values - return frameSize(); - } - - @Override - public int currentFrameSize() { - // FIXME return some sane values - return alignFrameSize(outgoingSize + spillSize); - } - - @Override - protected int alignFrameSize(int size) { - // FIXME return some sane values - int x = size + (getTarget().stackAlignment - 1); - return (x / getTarget().stackAlignment) * getTarget().stackAlignment; - } - - @Override - public int offsetToCalleeSaveArea() { - return frameSize() - calleeSaveAreaSize(); - } - - @Override - protected StackSlot allocateNewSpillSlot(LIRKind kind, int additionalOffset) { - return StackSlot.get(kind, -spillSize + additionalOffset, true); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXLIRInstruction.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXLIRInstruction.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -/* - * 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.lir.ptx; - -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -/** - * Convenience class to provide PTXAssembler for the {@link #emitCode} method. - */ -public abstract class PTXLIRInstruction extends LIRInstructionBase { - - @Override - public final void emitCode(CompilationResultBuilder crb) { - emitCode(crb, (PTXMacroAssembler) crb.asm); - } - - public abstract void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm); -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMemOp.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMemOp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.ptx; - -import static com.oracle.graal.asm.ptx.PTXStateSpace.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Ld; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.LoadAddr; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.LoadParam; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.St; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -public class PTXMemOp { - - // Load operation from .global state space - @Opcode("LOAD_REGBASE_DISP") - public static class LoadOp extends PTXLIRInstruction { - - private final Kind kind; - @Def({REG}) protected Variable result; - @Use({COMPOSITE}) protected PTXAddressValue address; - @State protected LIRFrameState state; - - public LoadOp(Kind kind, Variable result, PTXAddressValue address, LIRFrameState state) { - this.kind = kind; - this.result = result; - this.address = address; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - PTXAddress addr = address.toAddress(); - switch (kind) { - case Boolean: - case Byte: - case Short: - case Char: - case Int: - case Long: - case Float: - case Double: - case Object: - new Ld(Global, result, addr.getBase(), JavaConstant.forLong(addr.getDisplacement())).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - // Store operation from .global state space - @Opcode("STORE") - public static class StoreOp extends PTXLIRInstruction { - - private final Kind kind; - @Use({COMPOSITE}) protected PTXAddressValue address; - @Use({REG}) protected Variable input; - @State protected LIRFrameState state; - - public StoreOp(Kind kind, PTXAddressValue address, Variable input, LIRFrameState state) { - this.kind = kind; - this.address = address; - this.input = input; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - PTXAddress addr = address.toAddress(); - switch (kind) { - case Byte: - case Short: - case Int: - case Long: - case Float: - case Double: - case Object: - new St(Global, input, addr.getBase(), JavaConstant.forLong(addr.getDisplacement())).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + address.getKind()); - } - } - } - - // Load operation from .param state space - @Opcode("LOAD_PARAM") - public static class LoadParamOp extends PTXLIRInstruction { - - private final Kind kind; - @Def({REG}) protected Variable result; - @Use({COMPOSITE}) protected PTXAddressValue address; - @State protected LIRFrameState state; - - public LoadParamOp(Kind kind, Variable result, PTXAddressValue address, LIRFrameState state) { - this.kind = kind; - this.result = result; - this.address = address; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - PTXAddress addr = address.toAddress(); - switch (kind) { - case Byte: - case Short: - case Char: - case Int: - case Long: - case Float: - case Double: - case Object: - new LoadParam(Parameter, result, addr.getBase(), JavaConstant.forLong(addr.getDisplacement())).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - // Load contents of return value pointer from return argument in - // .param state space - @Opcode("LOAD_RET_ADDR") - public static class LoadReturnAddrOp extends PTXLIRInstruction { - - private final Kind kind; - @Def({REG}) protected Variable result; - @Use({COMPOSITE}) protected PTXAddressValue address; - @State protected LIRFrameState state; - - public LoadReturnAddrOp(Kind kind, Variable result, PTXAddressValue address, LIRFrameState state) { - this.kind = kind; - this.result = result; - this.address = address; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - PTXAddress addr = address.toAddress(); - switch (kind) { - case Int: - case Long: - case Float: - case Double: - new LoadAddr(Parameter, result, addr.getBase(), JavaConstant.forLong(addr.getDisplacement())).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - } - - // Store operation from .global state space - @Opcode("STORE_RETURN_VALUE") - public static class StoreReturnValOp extends PTXLIRInstruction { - - private final Kind kind; - @Use({COMPOSITE}) protected PTXAddressValue address; - @Use({REG}) protected Variable input; - @State protected LIRFrameState state; - - public StoreReturnValOp(Kind kind, PTXAddressValue address, Variable input, LIRFrameState state) { - this.kind = kind; - this.address = address; - this.input = input; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - PTXAddress addr = address.toAddress(); - - switch (kind) { - case Byte: - case Short: - case Int: - case Long: - case Float: - case Double: - case Object: - new St(Global, input, addr.getBase(), JavaConstant.forLong(addr.getDisplacement())).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + address.getKind()); - } - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMove.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXMove.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.lir.ptx; - -import static com.oracle.graal.api.code.ValueUtil.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; -import static com.oracle.graal.lir.LIRValueUtil.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Mov; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.StandardOp.MoveOp; -import com.oracle.graal.lir.StandardOp.NullCheck; -import com.oracle.graal.lir.asm.*; - -public class PTXMove { - - @Opcode("MOVE") - public static class SpillMoveOp extends PTXLIRInstruction implements MoveOp { - - @Def({REG, STACK}) protected AllocatableValue result; - @Use({REG, STACK, CONST}) protected Value input; - - public SpillMoveOp(AllocatableValue result, Value input) { - this.result = result; - this.input = input; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - move(crb, masm, getResult(), getInput()); - } - - @Override - public Value getInput() { - return input; - } - - @Override - public AllocatableValue getResult() { - return result; - } - } - - @Opcode("MOVE") - public static class MoveToRegOp extends PTXLIRInstruction implements MoveOp { - - @Def({REG, HINT}) protected AllocatableValue result; - @Use({REG, STACK, CONST}) protected Value input; - - public MoveToRegOp(AllocatableValue result, Value input) { - this.result = result; - this.input = input; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - move(crb, masm, getResult(), getInput()); - } - - @Override - public Value getInput() { - return input; - } - - @Override - public AllocatableValue getResult() { - return result; - } - } - - @Opcode("MOVE") - public static class MoveFromRegOp extends PTXLIRInstruction implements MoveOp { - - @Def({REG, STACK}) protected AllocatableValue result; - @Use({REG, CONST, HINT}) protected Value input; - - public MoveFromRegOp(AllocatableValue result, Value input) { - this.result = result; - this.input = input; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - move(crb, masm, getResult(), getInput()); - } - - @Override - public Value getInput() { - return input; - } - - @Override - public AllocatableValue getResult() { - return result; - } - } - - public static class LeaOp extends PTXLIRInstruction { - - @Def({REG}) protected AllocatableValue result; - @Use({COMPOSITE, UNINITIALIZED}) protected PTXAddressValue address; - - public LeaOp(AllocatableValue result, PTXAddressValue address) { - this.result = result; - this.address = address; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - throw new InternalError("NYI"); - } - } - - public static class StackLeaOp extends PTXLIRInstruction { - - @Def({REG}) protected AllocatableValue result; - @Use({STACK, UNINITIALIZED}) protected StackSlot slot; - - public StackLeaOp(AllocatableValue result, StackSlot slot) { - this.result = result; - this.slot = slot; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - throw new InternalError("NYI"); - } - } - - @Opcode("CAS") - public static class CompareAndSwapOp extends PTXLIRInstruction { - - @Def protected AllocatableValue result; - @Use({COMPOSITE}) protected PTXAddressValue address; - @Use protected AllocatableValue cmpValue; - @Use protected AllocatableValue newValue; - - public CompareAndSwapOp(AllocatableValue result, PTXAddressValue address, AllocatableValue cmpValue, AllocatableValue newValue) { - this.result = result; - this.address = address; - this.cmpValue = cmpValue; - this.newValue = newValue; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - compareAndSwap(crb, masm, result, address, cmpValue, newValue); - } - } - - public static void move(CompilationResultBuilder crb, PTXMacroAssembler masm, Value result, Value input) { - if (isVariable(input)) { - if (isVariable(result)) { - reg2reg(masm, result, input); - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } else if (isConstant(input)) { - if (isVariable(result)) { - const2reg(crb, masm, result, (JavaConstant) input); - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } else { - throw GraalInternalError.shouldNotReachHere(); - } - } - - private static void reg2reg(PTXMacroAssembler masm, Value result, Value input) { - Variable dest = (Variable) result; - Variable source = (Variable) input; - - if (dest.index == source.index) { - return; - } - switch (input.getKind()) { - case Int: - case Long: - case Float: - case Double: - case Object: - new Mov(dest, source).emit(masm); - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + input.getKind()); - } - } - - private static void const2reg(CompilationResultBuilder crb, PTXMacroAssembler masm, Value result, JavaConstant input) { - Variable dest = (Variable) result; - - switch (input.getKind().getStackKind()) { - case Int: - case Long: - if (crb.codeCache.needsDataPatch(input)) { - crb.recordInlineDataInCode(input); - } - new Mov(dest, input).emit(masm); - break; - case Object: - if (input.isNull()) { - new Mov(dest, JavaConstant.forLong(0x0L)).emit(masm); - } else if (crb.target.inlineObjects) { - crb.recordInlineDataInCode(input); - new Mov(dest, JavaConstant.forLong(0xDEADDEADDEADDEADL)).emit(masm); - } else { - // new Mov(dest, crb.recordDataReferenceInCode(input, 0, false)); - } - break; - default: - throw GraalInternalError.shouldNotReachHere("missing: " + input.getKind()); - } - } - - @SuppressWarnings("unused") - protected static void compareAndSwap(CompilationResultBuilder crb, PTXAssembler masm, AllocatableValue result, PTXAddressValue address, AllocatableValue cmpValue, AllocatableValue newValue) { - throw new InternalError("NYI"); - } - - public static class NullCheckOp extends PTXLIRInstruction implements NullCheck { - - @Use({REG}) protected AllocatableValue input; - @State protected LIRFrameState state; - - public NullCheckOp(Variable input, LIRFrameState state) { - this.input = input; - this.state = state; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - crb.recordImplicitException(masm.position(), state); - masm.nullCheck(asRegister(input)); - } - - public Value getCheckedValue() { - return input; - } - - public LIRFrameState getState() { - return state; - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXParameterOp.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXParameterOp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * 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.lir.ptx; - -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXMacroAssembler.Param; -import com.oracle.graal.lir.*; -import com.oracle.graal.lir.asm.*; - -public class PTXParameterOp extends LIRInstructionBase { - - @Def({REG}) protected Value[] params; - // True if the parameter list has return argument as the last - // item of the array params. - private boolean hasReturnParam; - - public PTXParameterOp(Value[] params, boolean hasReturn) { - this.params = params; - hasReturnParam = hasReturn; - } - - @Override - public void emitCode(CompilationResultBuilder crb) { - PTXMacroAssembler masm = (PTXMacroAssembler) crb.asm; - // Emit parameter directives for arguments - int argCount = params.length; - for (int i = 0; i < argCount; i++) { - boolean isReturnParam = (hasReturnParam && (i == (argCount - 1))); - new Param((Variable) params[i], isReturnParam).emit(masm, (i == (argCount - 1))); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXTestOp.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXTestOp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2011, 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.lir.ptx; - -import static com.oracle.graal.asm.ptx.PTXAssembler.BooleanOperator.*; -import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.asm.ptx.*; -import com.oracle.graal.asm.ptx.PTXAssembler.Setp; -import com.oracle.graal.compiler.common.calc.*; -import com.oracle.graal.lir.asm.*; - -public class PTXTestOp extends PTXLIRInstruction { - - @Use({REG}) protected Value x; - @Use({REG, STACK, CONST}) protected Value y; - int predicate; - - public PTXTestOp(Value x, Value y, int predicate) { - this.x = x; - this.y = y; - this.predicate = predicate; - } - - @Override - public void emitCode(CompilationResultBuilder crb, PTXMacroAssembler masm) { - emit(masm, x, y, predicate); - } - - @Override - public void verify() { - super.verify(); - assert (x.getKind() == Kind.Int && y.getKind().getStackKind() == Kind.Int) || (x.getKind() == Kind.Long && y.getKind() == Kind.Long) : x + " " + y; - } - - public static void emit(PTXAssembler masm, Value x, Value y, int predicate) { - /* - * This is not yet quite right - as the result for the equivalent in - * ControlPTXText.testIntegerTestBranch2I is wrong. - */ - new Setp(Condition.EQ, AND, x, y, predicate).emit(masm); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/ParallelOver.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/ParallelOver.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * 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.lir.ptx; - -import static com.oracle.graal.lir.ptx.ThreadDimension.*; - -import java.lang.annotation.*; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PARAMETER}) -public @interface ParallelOver { - - String value() default ""; - - ThreadDimension dimension() default X; -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/ThreadDimension.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/ThreadDimension.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -/* - * 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.lir.ptx; - -public enum ThreadDimension { - X, - Y, - Z -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/Warp.java --- a/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/Warp.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * 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.lir.ptx; - -import static com.oracle.graal.lir.ptx.ThreadDimension.*; - -import java.lang.annotation.*; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.PARAMETER}) -public @interface Warp { - - String value() default ""; - - ThreadDimension dimension() default X; -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.ptx/src/com/oracle/graal/ptx/PTX.java --- a/graal/com.oracle.graal.ptx/src/com/oracle/graal/ptx/PTX.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,233 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.ptx; - -import static com.oracle.graal.api.code.MemoryBarriers.*; - -import java.nio.*; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.Register.RegisterCategory; -import com.oracle.graal.api.meta.*; - -/** - * Represents the PTX architecture. - */ -public class PTX extends Architecture { - - public static final RegisterCategory REG = new RegisterCategory("REG"); - public static final RegisterCategory SREG = new RegisterCategory("SREG"); - public static final RegisterCategory PARAM = new RegisterCategory("PARAM"); - - // @formatter:off - - /* - * Register State Space - * - * Registers (.reg state space) are fast storage locations. The - * number of GPU architectural registers is limited, and will vary - * from platform to platform. When the limit is exceeded, register - * variables will be spilled to memory, causing changes in - * performance. For each architecture, there is a recommended - * maximum number of registers to use (see the "CUDA Programming - * Guide" for details). - * - * TODD: XXX - * - * However, PTX supports virtual registers. So, the generated PTX - * code does not need to use a specified number of registers. Till - * we figure out how to model a virtual register set in Graal, we - * will pretend that we can use only 16 registers. - */ - - public static final Register r0 = new Register(0, 0, "r0", REG); - public static final Register r1 = new Register(1, 1, "r1", REG); - public static final Register r2 = new Register(2, 2, "r2", REG); - public static final Register r3 = new Register(3, 3, "r3", REG); - public static final Register r4 = new Register(4, 4, "r4", REG); - public static final Register r5 = new Register(5, 5, "r5", REG); - public static final Register r6 = new Register(6, 6, "r6", REG); - public static final Register r7 = new Register(7, 7, "r7", REG); - - public static final Register r8 = new Register(8, 8, "r8", REG); - public static final Register r9 = new Register(9, 9, "r9", REG); - public static final Register r10 = new Register(10, 10, "r10", REG); - public static final Register r11 = new Register(11, 11, "r11", REG); - public static final Register r12 = new Register(12, 12, "r12", REG); - public static final Register r13 = new Register(13, 13, "r13", REG); - public static final Register r14 = new Register(14, 14, "r14", REG); - public static final Register r15 = new Register(15, 15, "r15", REG); - - public static final Register[] gprRegisters = { - r0, r1, r2, r3, r4, r5, r6, r7, - r8, r9, r10, r11, r12, r13, r14, r15 - }; - - /* Parameter State Space - * - * The parameter (.param) state space is used (1) to pass input - * arguments from the host to the kernel, (2a) to declare formal - * input and return parameters for device functions called from - * within kernel execution, and (2b) to declare locally-scoped - * byte array variables that serve as function call arguments, - * typically for passing large structures by value to a function. - * - * TODO: XXX - * The parameters are virtual symbols - just like registers. Bit, - * Till we figure out how to model a virtual register set in Graal, - * we will pretend that we can use only 8 parameters. - */ - - public static final Register param0 = new Register(16, 16, "param0", PARAM); - public static final Register param1 = new Register(17, 17, "param1", PARAM); - public static final Register param2 = new Register(18, 18, "param2", PARAM); - public static final Register param3 = new Register(19, 19, "param3", PARAM); - public static final Register param4 = new Register(20, 20, "param4", PARAM); - public static final Register param5 = new Register(21, 21, "param5", PARAM); - public static final Register param6 = new Register(22, 22, "param6", PARAM); - public static final Register param7 = new Register(23, 23, "param7", PARAM); - - public static final Register[] paramRegisters = { - param0, param1, param2, param3, param4, param5, param6, param7 - }; - - // Define a virtual register that holds return value - public static final Register retReg = new Register(24, 24, "retReg", REG); - - // PTX ISA Manual: Section 9:. Special Registers - - // PTX includes a number of predefined, read-only variables, which - // are visible as special registers and accessed through mov or - // cvt instructions. - // Thread identifier within a Co-operative Thread Array (CTA) - %tid - public static final Register tid = new Register(100, 100, "tid", SREG); - // Number of thread IDs per CTA - %ntid - public static final Register ntid = new Register(101, 101, "ntid", SREG); - // Lane identifier - public static final Register laneid = new Register(102, 102, "laneid", SREG); - // Warp identifier - public static final Register warpid = new Register(103, 103, "warid", SREG); - // Number of warp IDs - public static final Register nwarpid = new Register(104, 104, "nwarpid", SREG); - // CTA identifier - public static final Register ctaid = new Register(105, 105, "ctaid", SREG); - // Number of CTA IDs per grid - public static final Register nctaid = new Register(106, 106, "nctaid", SREG); - // Single Multiprocessor (SM) ID - public static final Register smid = new Register(107, 107, "smid", SREG); - // Number of SM IDs - public static final Register nsmid = new Register(108, 108, "nsmid", SREG); - // Grid ID - public static final Register gridid = new Register(109, 109, "gridid", SREG); - // 32-bit mask with bit set in position equal to thread's lane number in the warp - public static final Register lanemask_eq = new Register(110, 110, "lanemask_eq", SREG); - // 32-bit mask with bits set in positions less than or equal to thread's lane number in the warp - public static final Register lanemask_le = new Register(111, 111, "lanemask_le", SREG); - // 32-bit mask with bits set in positions less than thread's lane number in the warp - public static final Register lanemask_lt = new Register(112, 112, "lanemask_lt", SREG); - // 32-bit mask with bits set in positions greater than or equal to thread's lane number in the warp - public static final Register lanemask_ge = new Register(113, 113, "lanemask_ge", SREG); - // 32-bit mask with bits set in positions greater than thread's lane number in the warp - public static final Register lanemask_gt = new Register(114, 114, "lanemask_gt", SREG); - // A predefined, read-only 32-bit unsigned 32-bit unsigned cycle counter - public static final Register clock = new Register(114, 114, "clock", SREG); - // A predefined, read-only 64-bit unsigned 32-bit unsigned cycle counter - public static final Register clock64 = new Register(115, 115, "clock64", SREG); - // Performance monitoring registers - public static final Register pm0 = new Register(116, 116, "pm0", SREG); - public static final Register pm1 = new Register(117, 117, "pm1", SREG); - public static final Register pm2 = new Register(118, 118, "pm2", SREG); - public static final Register pm3 = new Register(119, 119, "pm3", SREG); - public static final Register pm4 = new Register(120, 120, "pm4", SREG); - public static final Register pm5 = new Register(121, 121, "pm5", SREG); - public static final Register pm6 = new Register(122, 122, "pm6", SREG); - public static final Register pm7 = new Register(123, 123, "pm7", SREG); - // TODO: Add Driver-defined read-only %envreg<32> - // and %globaltimer, %globaltimer_lo and %globaltimer_hi - - public static final Register[] specialRegisters = { - tid, ntid, laneid, warpid, nwarpid, ctaid, - nctaid, smid, nsmid, gridid, - lanemask_eq, lanemask_le, lanemask_lt, lanemask_ge, lanemask_gt, - clock, clock64, - pm0, pm1, pm2, pm3, pm4, pm5, pm6, pm7 - }; - - public static final Register[] allRegisters = { - // Parameter State Space - param0, param1, param2, param3, - param4, param5, param6, param7, - // Register State Space - r0, r1, r2, r3, r4, r5, r6, r7, - r8, r9, r10, r11, r12, r13, r14, r15, - // return register - retReg, - // Special Register State Space - SREG - tid, ntid, laneid, warpid, nwarpid, ctaid, - nctaid, smid, nsmid, gridid, - lanemask_eq, lanemask_le, lanemask_lt, lanemask_ge, lanemask_gt, - clock, clock64, - pm0, pm1, pm2, pm3, pm4, pm5, pm6, pm7 - }; - - // @formatter:on - - public PTX() { - super("PTX", 8, ByteOrder.LITTLE_ENDIAN, false, allRegisters, LOAD_STORE | STORE_STORE, 0, r15.encoding + 1, 8); - } - - @Override - public boolean canStoreValue(RegisterCategory category, PlatformKind lirKind) { - if (!(lirKind instanceof Kind)) { - return false; - } - - Kind kind = (Kind) lirKind; - if (category.equals(REG)) { - switch (kind) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - case Long: - case Object: - case Float: - case Double: - return true; - } - } - - return false; - } - - @Override - public PlatformKind getLargestStorableKind(RegisterCategory category) { - if (category.equals(REG)) { - return Kind.Double; - } else { - return Kind.Illegal; - } - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathIntrinsicsNode.java --- a/graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathIntrinsicsNode.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2013, 2014, 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.replacements.hsail; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.compiler.common.*; -import com.oracle.graal.compiler.common.type.*; -import com.oracle.graal.compiler.hsail.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.graph.spi.*; -import com.oracle.graal.lir.gen.*; -import com.oracle.graal.lir.hsail.*; -import com.oracle.graal.nodeinfo.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.spi.*; - -/** - * This node implements HSAIL intrinsics for specific {@link Math} routines. - */ -@NodeInfo -public class HSAILMathIntrinsicsNode extends FloatingNode implements Canonicalizable, ArithmeticLIRLowerable { - - /** - * The parameter passed to the math operation that this node represents. - */ - @Input ValueNode param; - - /** - * The math operation that this Node represents. - */ - protected final HSAILArithmetic operation; - - /** - * Gets the parameter passed to the math operation that this node represents. - * - * @return the parameter - */ - public ValueNode getParameter() { - return param; - } - - /** - * Returns the math operation represented by this node. - * - * @return the operation - */ - public HSAILArithmetic operation() { - return operation; - } - - public HSAILMathIntrinsicsNode(ValueNode x, HSAILArithmetic op) { - super(StampFactory.forKind(x.getKind())); - this.param = x; - this.operation = op; - } - - /** - * Generates the LIR instructions for the math operation represented by this node. - */ - @Override - public void generate(NodeMappableLIRBuilder builder, ArithmeticLIRGenerator gen) { - Value input = builder.operand(getParameter()); - Value result; - switch (operation()) { - case ABS: - result = gen.emitMathAbs(input); - break; - case CEIL: - result = ((HSAILLIRGenerator) gen).emitMathCeil(input); - break; - case FLOOR: - result = ((HSAILLIRGenerator) gen).emitMathFloor(input); - break; - case RINT: - result = ((HSAILLIRGenerator) gen).emitMathRint(input); - break; - case SQRT: - result = gen.emitMathSqrt(input); - break; - - default: - throw GraalInternalError.shouldNotReachHere(); - } - builder.setResult(this, result); - } - - /** - * Converts the result of the math operation to a boxed Double constant node. - */ - @Override - public Node canonical(CanonicalizerTool tool) { - if (getParameter().isConstant()) { - double ret = compute(getParameter().asJavaConstant().asDouble(), operation()); - return ConstantNode.forDouble(ret); - } - return this; - } - - // The routines below are node intrinsics. A call to any of these routines is replaced by a - // HSAILMathIntrinsicNode to handle the Math library operation represented by the - // HSAILArithmetic argument. - - /** - * Node intrinsic for {@link Math} routines taking a single int parameter. - * - * @param value - * @param op the math operation - * @return the result of the operation - */ - @NodeIntrinsic - public static native int compute(int value, @ConstantNodeParameter HSAILArithmetic op); - - /** - * Node intrinsic for {@link Math} routines taking a single double parameter. - * - * @param value the input parameter - * @param op the math operation - * @return the result of the operation - */ - @NodeIntrinsic - public static native long compute(long value, @ConstantNodeParameter HSAILArithmetic op); - - /** - * Node intrinsic for {@link Math} routines taking a single float parameter. - * - * @param value the input parameter - * @param op the math operation - * @return the result of the operation - */ - @NodeIntrinsic - public static native float compute(float value, @ConstantNodeParameter HSAILArithmetic op); - - /** - * Node intrinsic for {@link Math} routines taking a single double parameter. - * - * @param value the input parameter - * @param op the math operation - * - * @return the result of the operation - */ - @NodeIntrinsic - public static native double compute(double value, @ConstantNodeParameter HSAILArithmetic op); - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathSubstitutions.java --- a/graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/HSAILMathSubstitutions.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,221 +0,0 @@ -/* - * 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.replacements.hsail; - -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.lir.hsail.*; - -/** - * Substitutions for {@link Math} methods. For any calls to the routines listed below and annotated - * with {@link MethodSubstitution}, Graal replaces the call with a {@link HSAILMathIntrinsicsNode}. - */ -@ClassSubstitution(java.lang.Math.class) -public class HSAILMathSubstitutions { - - /** - * Substitution for {@link Math#abs(int)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static int abs(int x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); - } - - /** - * Substitution for {@link Math#abs(long)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static long abs(long x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); - } - - /** - * Substitution for {@link Math#abs(float)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static float abs(float x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); - } - - /** - * Substitution for {@link Math#abs(double)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static double abs(double x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.ABS); - } - - /** - * Substitution for Math.ceil(double). - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static double ceil(double x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.CEIL); - } - - /** - * Substitution for {@link Math#floor(double)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static double floor(double x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.FLOOR); - } - - /** - * Substitution for {@link Math#rint(double)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static double rint(double x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.RINT); - } - - /** - * Substitution for {@link Math#sqrt(double)}. - * - * @param x the input - * @return the result of the computation - */ - @MethodSubstitution - public static double sqrt(double x) { - return HSAILMathIntrinsicsNode.compute(x, HSAILArithmetic.SQRT); - } - - /** - * Methods below this point are more complicated transcendentals and such and use - * {@link JStrictMath} for method substitution. - */ - - @MethodSubstitution - public static double sin(double x) { - return JStrictMath.sin(x); - } - - @MethodSubstitution - public static double cos(double x) { - return JStrictMath.cos(x); - } - - @MethodSubstitution - public static double tan(double x) { - return JStrictMath.tan(x); - } - - @MethodSubstitution - public static double exp(double x) { - return JStrictMath.exp(x); - } - - @MethodSubstitution - public static double expm1(double x) { - return JStrictMath.expm1(x); - } - - @MethodSubstitution - public static double log(double x) { - return JStrictMath.log(x); - } - - @MethodSubstitution - public static double log10(double x) { - return JStrictMath.log10(x); - } - - @MethodSubstitution - public static double cbrt(double x) { - return JStrictMath.cbrt(x); - } - - @MethodSubstitution - public static double asin(double x) { - return JStrictMath.asin(x); - } - - @MethodSubstitution - public static double acos(double x) { - return JStrictMath.acos(x); - } - - @MethodSubstitution - public static double atan(double x) { - return JStrictMath.atan(x); - } - - @MethodSubstitution - public static double atan2(double x, double y) { - return JStrictMath.atan2(x, y); - } - - @MethodSubstitution - public static double pow(double x, double y) { - return JStrictMath.pow(x, y); - } - - // Checkstyle: stop - @MethodSubstitution - public static double IEEEremainder(double x, double y) { - return JStrictMath.IEEEremainder(x, y); - } - - // Checkstyle: resume - - @MethodSubstitution - public static double sinh(double x) { - return JStrictMath.sinh(x); - } - - @MethodSubstitution - public static double cosh(double x) { - return JStrictMath.cosh(x); - } - - @MethodSubstitution - public static double tanh(double x) { - return JStrictMath.tanh(x); - } - - @MethodSubstitution - public static double hypot(double x, double y) { - return JStrictMath.hypot(x, y); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/JStrictMath.java --- a/graal/com.oracle.graal.replacements.hsail/src/com/oracle/graal/replacements/hsail/JStrictMath.java Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3393 +0,0 @@ -/* - * Copyright (c) 2014, 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.replacements.hsail; - -import java.util.*; - -import sun.misc.*; - -import com.oracle.graal.api.replacements.*; - -// Checkstyle: stop - -/** - * This class contains methods for performing basic numeric operations such as the elementary - * exponential, logarithm, square root, and trigonometric functions. It is a Java port of the native - * methods in {@link StrictMath} and can thus be used by Graal backends to provide - * {@link MethodSubstitution}s for the native methods. - * - *

- * To help ensure portability of Java programs, the definitions of some of the numeric functions in - * this package require that they produce the same results as certain published algorithms. These - * algorithms are available from the well-known network library {@code netlib} as the package - * "Freely Distributable Math Library," {@code fdlibm} - * . These algorithms, which were originally written in the C programming language, are then to - * be understood as executed with all floating-point operations following the rules of Java - * floating-point arithmetic. - * - *

- * The Java math library is defined with respect to {@code fdlibm} version 5.3. Where {@code fdlibm} - * provides more than one definition for a function (such as {@code acos}), use the - * "IEEE 754 core function" version (residing in a file whose name begins with the letter {@code e} - * ). The methods which require {@code fdlibm} semantics are {@link #sin}, {@link #cos}, - * {@link #tan}, {@link #asin}, {@link #acos}, {@link #atan}, {@link #exp}, {@link #log}, - * {@link #log10}, {@link #cbrt}, {@link #atan2}, {@link #pow}, {@link #sinh}, {@link #cosh}, - * {@link #tanh}, {@link #hypot}, {@link #expm1}, and {@link #log1p}. - * - * @author Gustav Trede (port to Java) - */ -// JaCoCo Exclude -public final class JStrictMath { - - /** - * Don't let anyone instantiate this class. - */ - private JStrictMath() { - } - - /** - * The {@code double} value that is closer than any other to e, the base of the natural - * logarithms. - */ - public static final double E = 2.7182818284590452354; - /** - * The {@code double} value that is closer than any other to pi, the ratio of the - * circumference of a circle to its diameter. - */ - public static final double PI = 3.14159265358979323846; - - /** - * Returns the trigonometric sine of an angle. Special cases: - *

    - *
  • If the argument is NaN or an infinity, then the result is NaN. - *
  • If the argument is zero, then the result is a zero with the same sign as the argument. - *
- * - * @param a an angle, in radians. - * @return the sine of the argument. - */ - @SuppressWarnings("javadoc") - public static double sin(double x) { - int hx = (int) (Double.doubleToRawLongBits(x) >> 32); - int ix = hx & 0x7fffffff; - if (ix >= 0x7ff00000) { - // x is inf or NaN - return Double.NaN; - } - return ix <= 0x3fe921fb ? __kernel_sin_(x, ix) : __ieee754_rem_pio2_(x, hx, sintype); - } - - /** - * Returns the trigonometric cosine of an angle. Special cases: - *
    - *
  • If the argument is NaN or an infinity, then the result is NaN. - *
- * - * @param x an angle, in radians. - * @return the cosine of the argument. - */ - public static double cos(double x) { - int hx = (int) (Double.doubleToRawLongBits(x) >> 32); - int ix = hx & 0x7fffffff; - if (ix >= 0x7ff00000) { - // x is inf or NaN - return Double.NaN; - } - return ix <= 0x3fe921fb ? __kernel_cos_(x, 0, ix) : __ieee754_rem_pio2_(x, hx, costype); - } - - /** - * Returns the trigonometric tangent of an angle. Special cases: - *
    - *
  • If the argument is NaN or an infinity, then the result is NaN. - *
  • If the argument is zero, then the result is a zero with the same sign as the argument. - *
- * - * @param x an angle, in radians. - * @return the tangent of the argument. - */ - public static double tan(double x) { - final int hx = (int) (Double.doubleToRawLongBits(x) >> 32); - int ix = hx & 0x7fffffff; - if (ix >= 0x7ff00000) { - // x is inf or NaN - return Double.NaN; - } - return ix <= 0x3fe921fb ? __kernel_tan(x, 0d, 1, hx) : __ieee754_rem_pio2_(x, hx, tantype); - } - - /** - * kernel tan function on [-pi/4, pi/4], pi/4 ~ 0.7854 - * - * Algorithm 1. Since tan(-x) = -tan(x), we need only to consider positive x. 2. if x < 2^-28 - * (hx<0x3e300000 0), return x with inexact if x!=0. 3. tan(x) is approximated by a odd - * polynomial of degree 27 on [0,0.67434] 3 27 tan(x) ~ x + T1*x + ... + T13*x where - * - * |tan(x) 2 4 26 | -59.2 |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2 | x | - * - * Note: tan(x+y) = tan(x) + tan'(x)*y ~ tan(x) + (1+x*x)*y Therefore, for better accuracy in - * computing tan(x+y), let 3 2 2 2 2 r = x *(T2+x *(T3+x *(...+x *(T12+x *T13)))) then 3 2 - * tan(x+y) = x + (T1*x + (x *(r+y)+y)) - * - * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then tan(x) = tan(pi/4-y) = - * (1-tan(y))/(1+tan(y)) = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) - * - * @param xx is assumed to be bounded by ~pi/4 in magnitude. - * @param yy is the tail of x - * @param k indicates whether tan (if k=1) or -1/tan (if k= -1) is returned. - * @param hx high bits of x - * @return - */ - @SuppressWarnings("javadoc") - private static double __kernel_tan(double xx, double yy, int k, int hx) { - double w, r; - double x = xx; - double y = yy; - final int ix = hx & 0x7fffffff; - if (ix < 0x3e300000 && (int) x == 0) { // |x| < 2**-28 - if (k == 1) { - return x; - } - if ((ix | hx) == 0) { - return one / abs(x); // generate inexact - } - // compute -1 / (x+y) carefully - r = y; - w = x + y; - } else { - if (ix >= 0x3FE59428) { // |x|>=0.67434 - if (hx < 0) { - x = 0.0d - x; - y = 0.0d - y; - } - x = (pio4 - x) + (pio4lo - y); - y = 0.0; - } - final double z = x * x; - w = z * z; - - /* - * Break x^5*(T[1]+x^2*T[2]+...) into x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + - * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) - */ - - final double s = z * x; - double v = z * (T2 + w * (T4 + w * (T6 + w * (T8 + w * (T10 + w * T12))))); - r = (y + z * (s * ((T1 + w * (T3 + w * (T5 + w * (T7 + w * (T9 + w * T11))))) + v) + y)) + T0 * s; - w = x + r; - if (ix >= 0x3FE59428) { - v = k; - return (1 - ((hx >> 30) & 2)) * (v - 2.0d * (x - (((w * w) / (w + v)) - r))); - } - if (k == 1) { - return w; - } - // if allow error up to 2 ulp, simply return -1.0/(x+r) here - } - // compute -1.0/(x+r) accurately - final double a = negone / w; - final double t = clearLow32bits(a); - final double z = clearLow32bits(w); - return t + a * ((1.0d + t * z) + t * (r - (z - x))); - } - - private static final double S1 = -1.66666666666666324348e-01, S2 = 8.33333333332248946124e-03, /* - * 0x3F811111 - * , - * 0x1110F8A6 - */ - S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ - S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ - S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ - S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ - - /** - * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 Input x is assumed to be bounded by ~pi/4 - * in magnitude. Input y is the tail of x. Input iy indicates whether y is 0. (if iy=0, y assume - * to be 0). - * - * Algorithm 1. Since sin(-x) = -sin(x), we need only to consider positive x. 2. if x < 2^-27 - * (hx<0x3e400000 0), return x with inexact if x!=0. 3. sin(x) is approximated by a polynomial - * of degree 13 on [0,pi/4] 3 13 sin(x) ~ x + S1*x + ... + S6*x where - * - * |sin(x) 2 4 6 8 10 12 | -58 |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 | x | - * - * 4. sin(x+y) = sin(x) + sin'(x')*y ~ sin(x) + (1-x*x/2)*y For better accuracy, let 3 2 2 2 2 r - * = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) then 3 2 sin(x) = x + (S1*x + (x *(r-y/2)+y)) - * - * @param x - * @param y - * @return - */ - @SuppressWarnings("javadoc") - private static double __kernel_sin(double x, double y, int ix) { - if (ix < 0x3e400000 && (int) x == 0) { - return x; // |x| < 2**-27 generate inexact - } - final double z = x * x; - final double v = z * x; - final double r = v * (S2 + z * (S3 + z * (S4 + z * (S5 + z * S6)))); - return x - ((z * (half * y - r) - y) - v * S1); - } - - private static double __kernel_sin_(double x, int ix) { - if (ix < 0x3e400000 && (int) x == 0) { - return x; // |x| < 2**-27 generate inexact - } - final double z = x * x; - return x + (z * x) * (S1 + z * (S2 + z * (S3 + z * (S4 + z * (S5 + z * S6))))); - } - - private static final double two = 2.0d, one = Double.longBitsToDouble(0x3ff0000000000000L), negone = -one, C1 = 4.16666666666666019037e-02, C2 = -1.38888888888741095749e-03, - C3 = 2.48015872894767294178e-05, C4 = -2.75573143513906633035e-07, C5 = 2.08757232129817482790e-09, C6 = -1.13596475577881948265e-11; - - /** - * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 Input x is assumed to be bounded by - * ~pi/4 in magnitude. Input y is the tail of x. - * - * Algorithm 1. Since cos(-x) = cos(x), we need only to consider positive x. 2. if x < 2^-27 - * (hx<0x3e400000 0), return 1 with inexact if x!=0. 3. cos(x) is approximated by a polynomial - * of degree 14 on [0,pi/4] 4 14 cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x where the remez error is - * - * | 2 4 6 8 10 12 14 | -58 |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 | | - * - * 4 6 8 10 12 14 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then cos(x) = 1 - x*x/2 + r - * since cos(x+y) ~ cos(x) - sin(x)*y ~ cos(x) - x*y, a correction term is necessary in cos(x) - * and hence cos(x+y) = 1 - (x*x/2 - (r - x*y)) For better accuracy when x > 0.3, let qx = |x|/4 - * with the last 32 bits mask off, and if x > 0.78125, let qx = 0.28125. Then cos(x+y) = (1-qx) - * - ((x*x/2-qx) - (r-x*y)). Note that 1-qx and (x*x/2-qx) is EXACT here, and the magnitude of - * the latter is at least a quarter of x*x/2, thus, reducing the rounding error in the - * subtraction. - * - * @param x - * @param y - * @param ix - * @return - */ - @SuppressWarnings("javadoc") - private static double __kernel_cos_(double x, double y, int ix) { - if (ix < 0x3e400000 && ((int) x) == 0) { - return one; // x < 2**27 generate inexact - } - final double z = x * x; - double r = z * (z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * C6)))))) - x * y; - if (ix < 0x3FD33333) { // |x| < 0.3 - return one - (0.5 * z - r); - } - final double qx = ix > 0x3fe90000 ? 0.28125 : // x > 0.78125 - Double.longBitsToDouble((long) (ix - 0x00200000) << 32); // x/4 - return (one - qx) - ((0.5 * z - qx) - r); - } - - private static final int sintype = 0; - private static final int costype = 1; - private static final int tantype = 3; - - /** - * Returns final values for tan , cos and sin. - * - * @param trigtype - * @param NN - * @param y0 - * @param y1 - * @author gustav trede - * @return - */ - @SuppressWarnings("javadoc") - private static double getTrigres(int trigtype, int NN, double y0, double y1) { - int N = NN; - int hx = ((int) (Double.doubleToRawLongBits(y0) >> 32)); - if (trigtype == tantype) { - return __kernel_tan(y0, y1, 1 - ((N & 1) << 1), hx); - } - hx &= 0x7fffffff; - N = (N & 3) - trigtype; - double v = (N == 0 || N == 2) ? __kernel_sin(y0, y1, hx) : __kernel_cos_(y0, y1, hx); - - if (N == 0 || N == 1) { - return trigtype == 0 ? v : 0.0d - v; - } - return trigtype == 0 ? 0.0d - v : v; - } - - private static final double pio4 = 7.85398163397448278999e-01, pio4lo = 3.06161699786838301793e-17, T0 = 3.33333333333334091986e-01, T1 = 1.33333333333201242699e-01, - T2 = 5.39682539762260521377e-02, T3 = 2.18694882948595424599e-02, T4 = 8.86323982359930005737e-03, T5 = 3.59207910759131235356e-03, T6 = 1.45620945432529025516e-03, - T7 = 5.88041240820264096874e-04, T8 = 2.46463134818469906812e-04, T9 = 7.81794442939557092300e-05, T10 = 7.14072491382608190305e-05, T11 = -1.85586374855275456654e-05, - T12 = 2.59073051863633712884e-05; - - /* - * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi - */ - private static final int[] two_over_pi = {0xa2f983, 0x6e4e44, 0x1529fc, 0x2757d1, 0xf534dd, 0xc0db62, 0x95993c, 0x439041, 0xfe5163, 0xabdebb, 0xc561b7, 0x246e3a, 0x424dd2, 0xe00649, 0x2eea09, - 0xd1921c, 0xfe1deb, 0x1cb129, 0xa73ee8, 0x8235f5, 0x2ebb44, 0x84e99c, 0x7026b4, 0x5f7e41, 0x3991d6, 0x398353, 0x39f49c, 0x845f8b, 0xbdf928, 0x3b1ff8, 0x97ffde, 0x05980f, 0xef2f11, - 0x8b5a0a, 0x6d1f6d, 0x367ecf, 0x27cb09, 0xb74f46, 0x3f669e, 0x5fea2d, 0x7527ba, 0xc7ebe5, 0xf17b3d, 0x0739f7, 0x8a5292, 0xea6bfb, 0x5fb11f, 0x8d5d08, 0x560330, 0x46fc7b, 0x6babf0, - 0xcfbc20, 0x9af436, 0x1da9e3, 0x91615e, 0xe61b08, 0x659985, 0x5f14a0, 0x68408d, 0xffd880, 0x4d7327, 0x310606, 0x1556ca, 0x73a8c9, 0x60e27b, 0xc08c6b}; - - private static final int[] npio2_hw = {0x3ff921fb, 0x400921fb, 0x4012d97c, 0x401921fb, 0x401f6a7a, 0x4022d97c, 0x4025fdbb, 0x402921fb, 0x402c463a, 0x402f6a7a, 0x4031475c, 0x4032d97c, 0x40346b9c, - 0x4035fdbb, 0x40378fdb, 0x403921fb, 0x403ab41b, 0x403c463a, 0x403dd85a, 0x403f6a7a, 0x40407e4c, 0x4041475c, 0x4042106c, 0x4042d97c, 0x4043a28c, 0x40446b9c, 0x404534ac, 0x4045fdbb, - 0x4046c6cb, 0x40478fdb, 0x404858eb, 0x404921fb}; - - private static final double zero = 0.00000000000000000000e+00, half = 5.00000000000000000000e-01, - /* 1.67772160000000000000e+07 */ - two24 = Double.longBitsToDouble(0x4170000000000000L), - /* 6.36619772367581382433e-01 53 bits of 2/pi */ - invpio2 = Double.longBitsToDouble(0x3fe45f306dc9c883L), - /* 1.57079632673412561417e+00 first 33 bit of pi/2 */ - pio2_1 = Double.longBitsToDouble(0x3ff921fb54400000L), - /* 6.07710050650619224932e-11 pi/2 - pio2_1 */ - pio2_1t = Double.longBitsToDouble(0x3dd0b4611a626331L), - /* 6.07710050630396597660e-11 second 33 bit of pi/2 */ - pio2_2 = Double.longBitsToDouble(0x3dd0b4611a600000L), - /* 2.02226624879595063154e-21 pi/2 - (pio2_1+pio2_2) */ - pio2_2t = Double.longBitsToDouble(0x3ba3198a2e037073L), - /* 2.02226624871116645580e-21 third 33 bit of pi/2 */ - pio2_3 = Double.longBitsToDouble(0x3ba3198a2e000000L), - /* 8.47842766036889956997e-32 pi/2 - (pio2_1+pio2_2+pio2_3) */ - pio2_3t = Double.longBitsToDouble(0x397b839a252049c1L); - - private static double __ieee754_rem_pio2_(double xx, int hx, int trigtype) { - double x = xx; - int ix = hx & 0x7fffffff; - if (ix <= 0x413921fb) { // |x| ~<= 2^19*(pi/2) - double y0, y1; - int n; - if (ix < 0x4002d97c) { // |x| < 3pi/4, special case with n=+-1 - if (hx > 0) { - x -= pio2_1; - if (ix != 0x3ff921fb) { // 33+53 bit pi is good enough - y0 = x - pio2_1t; - y1 = (x - y0) - pio2_1t; - } else { // near pi/2, use 33+33+53 bit pi - x -= pio2_2; - y0 = x - pio2_2t; - y1 = (x - y0) - pio2_2t; - } - n = 1; - } else { // negative x - x += pio2_1; - if (ix != 0x3ff921fb) { // 33+53 bit pi is good enough - y0 = x + pio2_1t; - y1 = (x - y0) + pio2_1t; - } else { // near pi/2, use 33+33+53 bit pi - x += pio2_2; - y0 = x + pio2_2t; - y1 = (x - y0) + pio2_2t; - } - n = -1; - } - } else { - double t = abs(x); - n = (int) (t * invpio2 + half); - final double fn = n; - double w = fn * pio2_1t; // 1st round good to 85 bit - double r = t - fn * pio2_1; - y0 = r - w; - // quick check no cancellation - if (n >= 32 || ix == npio2_hw[n - 1]) { - int i = ix - (((int) (Double.doubleToRawLongBits(y0) >> 32)) & (0x7ff << 20)); - if (i > (16 << 20)) { // 2nd iteration needed, good to 118 - w = fn * pio2_2; - t = r; - r -= w; - w = fn * pio2_2t - ((t - r) - w); - y0 = r - w; - i = ix - (((int) (Double.doubleToRawLongBits(y0) >> 32)) & (0x7ff << 20)); - if (i > (49 << 20)) {// 3rd iteration need, 151 bits acc - w = fn * pio2_3; - t = r; - r -= w; - w = fn * pio2_3t - ((t - r) - w); - y0 = r - w; - } - } - } - y1 = (r - y0) - w; - if (hx < 0) { - y1 = 0.0d - y1; - y0 = 0.0d - y0; - n = -n; - } - } - return getTrigres(trigtype, n, y0, y1); - } - - return ix >= 0x7ff00000 ? x - x : // x is inf or NaN - __kernel_rem_pio2(x, hx, trigtype); - } - - private static final double[] PIo2 = {1.57079625129699707031e+00, 7.54978941586159635335e-08, 5.39030252995776476554e-15, 3.28200341580791294123e-22, 1.27065575308067607349e-29, - 1.22933308981111328932e-36, 2.73370053816464559624e-44, 2.16741683877804819444e-51}; - - private static final double twon24 = 5.96046447753906250000e-08; - - /** - * Used for tlocal storage to save __kernel_rem_pio2 from major mem allocs. - * - * @author gustav trede - */ - private static class Rempiostruct { - final double[] f = new double[20]; - final double[] q = new double[20]; - final double[] fq = new double[20]; - final double[] x = new double[3]; - final int[] iq = new int[20]; - } - - /******* - * private static final ThreadLocal rempstruct = new ThreadLocal() { - * - * @Override protected Rempiostruct initialValue() { return new Rempiostruct(); } }; - *******/ - - private static class RempStructAcccessor { - Rempiostruct get() { - return new Rempiostruct(); - } - } - - static RempStructAcccessor rempstruct; - - /** - * - * __kernel_rem_pio2 return the last three digits of N with y = x - N*pi/2 so that |y| < pi/2. - * - * The method is to compute the integer (mod 8) and fraction parts of (2/pi)*x without doing the - * full multiplication. In general we skip the part of the product that are known to be a huge - * integer (more accurately, = 0 mod 8 ). Thus the number of operations are independent of the - * exponent of the input. - * - * (2/pi) is represented by an array of 24-bit integers in two_over_pi[]. - * - * Input parameters: x[] The input value (must be positive) is broken into nx pieces of 24-bit - * integers in double precision format. x[i] will be the i-th 24 bit of x. The scaled exponent - * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 match x's up to 24 bits. - * - * Example of breaking a double positive z into x[0]+x[1]+x[2]: e0 = ilogb(z)-23 z = - * scalbn(z,-e0) for i = 0,1,2 x[i] = floor(z) z = (z-x[i])*2**24 - * - * - * y[] ouput result in an array of double precision numbers. The dimension of y[] is: 24-bit - * precision 1 53-bit precision 2 64-bit precision 2 113-bit precision 3 The actual value is the - * sum of them. Thus for 113-bit precison, one may have to do something like: - * - * long double t,w,r_head, r_tail; t = (long double)y[2] + (long double)y[1]; w = (long - * double)y[0]; r_head = t+w; r_tail = w - (r_head - t); - * - * e0 The exponent of x[0] - * - * nx dimension of x[] - * - * prec an integer indicating the precision: 0 24 bits (single) 1 53 bits (double) 2 64 bits - * (extended) 3 113 bits (quad) - * - * two_over_pi[] integer array, contains the (24*i)-th to (24*i+23)-th bit of 2/pi after binary - * point. The corresponding floating value is - * - * two_over_pi[i] * 2^(-24(i+1)). - * - * External function: double scalbn(), floor(); - * - * - * Here is the description of some local variables: - * - * jk jk+1 is the initial number of terms of two_over_pi[] needed in the computation. The - * recommended value is 2,3,4, 6 for single, double, extended,and quad. - * - * jz local integer variable indicating the number of terms of two_over_pi[] used. - * - * jx nx - 1 - * - * jv index for pointing to the suitable two_over_pi[] for the computation. In general, we want - * ( 2^e0*x[0] * two_over_pi[jv-1]*2^(-24jv) )/8 is an integer. Thus e0-3-24*jv >= 0 or - * (e0-3)/24 >= jv Hence jv = max(0,(e0-3)/24). - * - * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. - * - * q[] double array with integral value, representing the 24-bits chunk of the product of x and - * 2/pi. - * - * q0 the corresponding exponent of q[0]. Note that the exponent for q[i] would be q0-24*i. - * - * PIo2[] double precision array, obtained by cutting pi/2 into 24 bits chunks. - * - * f[] two_over_pi[] in floating point - * - * iq[] integer array by breaking up q[] in 24-bits chunk. - * - * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] - * - * ih integer. If >0 it indicates q[] is >= 0.5, hence it also indicates the *sign* of the - * result. - * - * @param xv - * @param hx - * @param trig trigtype - * @return - */ - @SuppressWarnings("javadoc") - private static double __kernel_rem_pio2(double xv, int hx, final int trig) { - Rempiostruct rmp = rempstruct.get(); - double[] x = rmp.x; - double[] f = rmp.f; - double[] q = rmp.q; - double[] fq = rmp.fq; - int[] iq = rmp.iq; - - /* set z = scalbn(|x|,ilogb(x)-23) */ - long lx = Double.doubleToRawLongBits(xv); - long exp = ((lx & 0x7ff0000000000000L) >> 52) - 1046; - lx = (lx - (exp << 52)) & 0x7fffffffffffffffL; - double zz = Double.longBitsToDouble(lx); - for (int i = 0; i < 2; i++) { - x[i] = (int) zz; - zz = (zz - x[i]) * two24; - } - x[2] = zz; - int nx = 3; - while (x[nx - 1] == zero) { /* skip zero term */ - nx--; - } - double z, fw; - int ih, n; - int jk = 4; - int jp = jk; - /* determine jx,jv,q0, note that 3>q0 */ - int jx = nx - 1; - int e0 = (int) exp; - int jv = (e0 - 3) / 24; - if (jv < 0) { - jv = 0; - } - int q0 = e0 - (24 * (jv + 1)); - /* set up f[0] to f[jx+jk] where f[jx+jk] = two_over_pi[jv+jk] */ - int j = jv - jx; - int m = jx + jk; - for (int i = 0; i <= m; i++, j++) { - f[i] = ((j < 0) ? zero : two_over_pi[j]); - } - - /* compute q[0],q[1],...q[jk] */ - for (int i = 0; i <= jk; i++) { - for (j = 0, fw = 0.0; j <= jx; j++) { - fw += (x[j] * f[(jx + i) - j]); - } - q[i] = fw; - } - int jz = jk; - while (true) { // recompute: - /* distill q[] into iq[] reversingly */ - j = jz; - z = q[jz]; - for (int i = 0; j > 0; i++, j--) { - fw = ((int) (twon24 * z)); - iq[i] = (int) (z - (two24 * fw)); - z = q[j - 1] + fw; - } - /* compute n */ - z = scalb(z, q0); /* actual value of z */ - z -= (8.0 * floor(z * 0.125)); /* trim off integer >= 8 */ - n = (int) z; - z -= n; - ih = 0; - if (q0 > 0) { /* need iq[jz-1] to determine n */ - int i = (iq[jz - 1] >> (24 - q0)); - n += i; - iq[jz - 1] -= (i << (24 - q0)); - ih = iq[jz - 1] >> (23 - q0); - } else if (q0 == 0) { - ih = iq[jz - 1] >> 23; - } else if (z >= 0.5) { - ih = 2; - } - if (ih > 0) { /* q > 0.5 */ - n += 1; - int carry = 0; - for (int i = 0; i < jz; i++) { /* compute 1-q */ - j = iq[i]; - if (carry == 0) { - if (j != 0) { - carry = 1; - iq[i] = 0x1000000 - j; - } - } else { - iq[i] = 0xffffff - j; - } - } - /* rare case: chance is 1 in 12 */ - if (q0 == 1) { - iq[jz - 1] &= 0x7fffff; - } else if (q0 == 2) { - iq[jz - 1] &= 0x3fffff; - } - if (ih == 2) { - z = one - z; - if (carry != 0) { - z -= scalb(one, q0); - } - } - } - /* check if recomputation is needed */ - if (z == zero) { - j = 0; - for (int i = jz - 1; i >= jk; i--) { - j |= iq[i]; - } - if (j == 0) { /* need recomputation */ - int k = 1; - for (; iq[jk - k] == 0; k++) { - }/* k = no. of terms needed */ - for (int i = jz + 1; i <= (jz + k); i++) { - // add q[jz+1] to q[jz+k] - f[jx + i] = two_over_pi[jv + i]; - for (j = 0, fw = 0.0; j <= jx; j++) { - fw += (x[j] * f[(jx + i) - j]); - } - q[i] = fw; - } - jz += k; - continue; - } - } - break; - } - /* chop off zero terms */ - if (z == 0.0d) { - jz--; - q0 -= 24; - while (iq[jz] == 0) { - jz--; - q0 -= 24; - } - } else { /* break z into 24-bit if necessary */ - z = scalb(z, -q0); - if (z >= two24) { - fw = (int) (twon24 * z); - iq[jz] = (int) (z - (two24 * fw)); - jz++; - q0 += 24; - iq[jz] = (int) fw; - } else { - iq[jz] = (int) z; - } - } - /* convert integer "bit" chunk to floating-point value */ - fw = scalb(one, q0); - for (int i = jz; i >= 0; i--) { - q[i] = fw * iq[i]; - fw *= twon24; - } - /* compute PIo2[0,...,jp]*q[jz,...,0] */ - for (int i = jz; i >= 0; i--) { - int k = 0; - for (fw = 0.0; (k <= jp) && (k <= (jz - i)); k++) { - fw += PIo2[k] * q[i + k]; - } - fq[jz - i] = fw; - } - /* compress fq[] into y[] */ - fw = 0.0d; - for (int i = jz; i >= 0; i--) { - fw += fq[i]; - } - double y0 = (ih == 0) ? fw : (0.0d - fw); - fw = fq[0] - fw; - for (int i = 1; i <= jz; i++) { - fw += fq[i]; - } - double y1 = ((ih == 0) ? fw : (0.0d - fw)); - n &= 7; - if (hx < 0) { - y0 = 0.0d - y0; - y1 = 0.0d - y1; - n = -n; - } - return getTrigres(trig, n, y0, y1); - } - - private static final double pio2_hi = 1.57079632679489655800e+00; - private static final double pio2_lo = 6.12323399573676603587e-17; - private static final double pio4_hi = 7.85398163397448278999e-01; - private static final double PIret = PI + 2.0 * pio2_lo; - - /* coefficient for R(x^2) */ - private static final double pS0 = 1.66666666666666657415e-01; - private static final double pS1 = -3.25565818622400915405e-01; - private static final double pS2 = 2.01212532134862925881e-01; - private static final double pS3 = -4.00555345006794114027e-02; - private static final double pS4 = 7.91534994289814532176e-04; - private static final double pS5 = 3.47933107596021167570e-05; - private static final double qS1 = -2.40339491173441421878e+00; - private static final double qS2 = 2.02094576023350569471e+00; - private static final double qS3 = -6.88283971605453293030e-01; - private static final double qS4 = 7.70381505559019352791e-02; - - /** - * Returns the arc sine of a value; the returned angle is in the range -pi/2 through - * pi/2. Special cases: - *
    - *
  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN. - *
  • If the argument is zero, then the result is a zero with the same sign as the argument. - *
- * - * @param a the value whose arc sine is to be returned. - * @return the arc sine of the argument. - */ - public static double asin(double a) { - /* - * asin(x) Method : Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... we approximate - * asin(x) on [0,0.5] by asin(x) = x + x*x^2*R(x^2) where R(x^2) is a rational approximation - * of (asin(x)-x)/x^3 and its remez error is bounded by |(asin(x)-x)/x^3 - R(x^2)| < - * 2^(-58.75) - * - * For x in [0.5,1] asin(x) = pi/2-2*asin(sqrt((1-x)/2)) Let y = (1-x), z = y/2, s := - * sqrt(z),and pio2_hi+pio2_lo=pi/2; then for x>0.98 asin(x) = pi/2 - 2*(s+s*z*R(z)) = - * pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) For x<=0.98, let pio4_hi = pio2_hi/2, then f = hi - * part of s; c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) and asin(x) = pi/2 - - * 2*(s+s*z*R(z)) = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) = - * pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) - * - * Special cases: if x is NaN, return x itself; if |x|>1, return NaN with invalid signal. - */ - int hx = __HI(a); - int ix = hx & 0x7fffffff; - if (ix >= 0x3ff00000) { /* |x|>= 1 */ - return ((ix - 0x3ff00000) | __LO(a)) == 0 ? a * pio2_hi + a * pio2_lo : // asin(1)=+-pi/2 - // with inexact - (a - a) / (a - a); // asin(|x|>1) is NaN - } - if (ix < 0x3fe00000) { /* |x|<0.5 */ - if (ix < 0x3e400000) { /* if |x| < 2**-27 */ - if (huge + a > one) - return a; /* return x with inexact if x!=0 */ - } else - return a + (a * getPdivQ(a * a)); - } - // 1> |x|>= 0.5 - double t = (one - abs(a)) * 0.5; - double pdivq = getPdivQ(t); - double s = java.lang.Math.sqrt(t); - if (ix >= 0x3FEF3333) { /* if |x| > 0.975 */ - t = pio2_hi - (2.0 * (s + s * pdivq) - pio2_lo); - } else { - double w = clearLow32bits(s); - double p = 2.0d * s * pdivq - (pio2_lo - 2.0d * ((t - (w * w)) / (s + w))); - t = pio4_hi - (p - (pio4_hi - 2.0d * w)); - } - return hx > 0 ? t : -t; - } - - /** - * Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. - * Special case: - *
    - *
  • If the argument is NaN or its absolute value is greater than 1, then the result is NaN. - *
- * - * @param a the value whose arc cosine is to be returned. - * @return the arc cosine of the argument. - */ - public static double acos(double a) { - /* - * Method : acos(x) = pi/2 - asin(x) acos(-x) = pi/2 + asin(x) For |x|<=0.5 acos(x) = pi/2 - - * (x + x*x^2*R(x^2)) (see asin.c) For x>0.5 acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) - * = 2asin(sqrt((1-x)/2)) = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) = 2f + (2c + 2s*z*R(z)) - * where f=hi part of s, and c= (z-f*f)/(s+f) is the correction term for f so that f+c ~ - * sqrt(z). For x<-0.5 acos(x) = pi - 2asin(sqrt((1-|x|)/2)) = pi - 0.5*(s+s*z*R(z)), where - * z=(1-|x|)/2,s=sqrt(z) - * - * Special cases: if x is NaN, return x itself; if |x|>1, return NaN with invalid signal. - */ - - final int hx = __HI(a); - final int ix = hx & 0x7fffffff; - if (ix >= 0x3ff00000) { // |x| >= 1 - if (((ix - 0x3ff00000) | __LO(a)) == 0) { // |x|==1 - return a > 0 ? 0.0 : PIret; - } - return (a - a) / (a - a); // acos(|x|>1) is NaN - } - - if (ix < 0x3fe00000) { // |x| < 0.5 - return ix <= 0x3c600000 ? pio2_hi + pio2_lo : // |x|<2**-57 - pio2_hi - (a - (pio2_lo - a * getPdivQ(a * a))); - } - - final double z = 0.5 * ((hx < 0) ? (one + a) : (one - a)); - final double s = java.lang.Math.sqrt(z); - final double pdivq = s * getPdivQ(z); - - if (hx < 0) { // x < -0.5 - return PI - 2.0 * (s + (pdivq - pio2_lo)); - } - // x > 0.5 - final double df = clearLow32bits(s); - return 2.0 * (df + (pdivq + (z - df * df) / (s + df))); - } - - private static double getPdivQ(double z) { - return (z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))))) / (one + z * (qS1 + z * (qS2 + (z * (qS3 + (z * qS4)))))); - } - - private static final double atanhi[] = {4.63647609000806093515e-01, // atan(0.5)hi - 7.85398163397448278999e-01, // atan(1.0)hi - 9.82793723247329054082e-01, // atan(1.5)hi - 1.57079632679489655800e+00};// atan(inf)hi - - private static final double atanlo[] = {2.26987774529616870924e-17, // atan(0.5)lo - 3.06161699786838301793e-17, // atan(1.0)lo - 1.39033110312309984516e-17, // atan(1.5)lo - 6.12323399573676603587e-17};// atan(inf)lo) - - private static final double ln2_hi = 6.93147180369123816490e-01, ln2_lo = 1.90821492927058770002e-10, Lg1 = 6.666666666666735130e-01, Lg2 = 3.999999999940941908e-01, - Lg3 = 2.857142874366239149e-01, Lg4 = 2.222219843214978396e-01, Lg5 = 1.818357216161805012e-01, Lg6 = 1.531383769920937332e-01, Lg7 = 1.479819860511658591e-01, - two54 = 1.80143985094819840000e+16, aT0 = 3.33333333333329318027e-01, aT1 = -1.99999999998764832476e-01, aT2 = 1.42857142725034663711e-01, aT3 = -1.11111104054623557880e-01, - aT4 = 9.09088713343650656196e-02, aT5 = -7.69187620504482999495e-02, aT6 = 6.66107313738753120669e-02, aT7 = -5.83357013379057348645e-02, aT8 = 4.97687799461593236017e-02, - aT9 = -3.65315727442169155270e-02, aT10 = 1.62858201153657823623e-02, atanhi3PLUSatanlo3 = atanhi[3] + atanlo[3], negatanhi3MINUSatanlo3 = -atanhi[3] - atanlo[3], - pi_o_4 = 7.8539816339744827900e-01, pi_o_2 = 1.5707963267948965580e+00, pi_lo = 1.2246467991473531772e-16, huge = 1.0e+300, tiny = 1.0e-300; - - /** - * Returns the arc tangent of a value; the returned angle is in the range -pi/2 through - * pi/2. Special cases: - *
    - *
  • If the argument is NaN, then the result is NaN. - *
  • If the argument is zero, then the result is a zero with the same sign as the argument. - *
- * - * @param aa the value whose arc tangent is to be returned. - * @return the arc tangent of the argument. - */ - public static double atan(double aa) { - /* - * Method 1. Reduce x to positive by atan(x) = -atan(-x). 2. According to the integer - * k=4t+0.25 chopped, t=x, the argument is further reduced to one of the following intervals - * and the arctangent of t is evaluated by the corresponding formula: - * - * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) [7/16,11/16] atan(x) = - * atan(1/2) + atan( (t-0.5)/(1+t/2) ) [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) - * ) [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) [39/16,INF] atan(x) = - * atan(INF) + atan( -1/t ) - */ - - double a = aa; - int hx = __HI(a); - int ix = hx & 0x7fffffff; - if (ix >= 0x44100000) { /* if |x| >= 2^66 */ - if ((ix > 0x7ff00000) || (ix == 0x7ff00000 && __LO(a) != 0)) { - return a + a; /* NaN */ - } - return hx > 0 ? atanhi3PLUSatanlo3 : negatanhi3MINUSatanlo3; - } - int id; - if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ - if (ix < 0x3e200000 && /* |x| < 2^-29 */ - (huge + a > one)) { - return a; /* raise inexact */ - } - id = -1; - } else { - a = abs(a); - if (ix < 0x3ff30000) { /* |x| < 1.1875 */ - if (ix < 0x3fe60000) { /* 7/16 <=|x|<11/16 */ - id = 0; - a = (2.0d * a - one) / (2.0d + a); - } else { /* 11/16<=|x|< 19/16 */ - id = 1; - a = (a - one) / (a + one); - } - } else { - if (ix < 0x40038000) { /* |x| < 2.4375 */ - id = 2; - a = (a - 1.5d) / (one + 1.5d * a); - } else { /* 2.4375 <= |x| < 2^66 */ - id = 3; - a = negone / a; - } - } - } - - /* end of argument reduction */ - double z = a * a; - double w = z * z; - - /* break sum from i=0 to 10 aTi z**(i+1) into odd and even poly */ - double ss = a * (z * (aT0 + w * (aT2 + w * (aT4 + w * (aT6 + w * (aT8 + w * aT10))))) + w * (aT1 + w * (aT3 + w * (aT5 + w * (aT7 + w * aT9))))); - if (id < 0) { - return a - ss; - } - z = atanhi[id] - ((ss - atanlo[id]) - a); - return hx < 0 ? 0.0d - z : z; - } - - /** - * Converts an angle measured in degrees to an approximately equivalent angle measured in - * radians. The conversion from degrees to radians is generally inexact. - * - * @param angdeg an angle, in degrees - * @return the measurement of the angle {@code angdeg} in radians. - */ - public static strictfp double toRadians(double angdeg) { - return angdeg / 180.0 * PI; - } - - /** - * Converts an angle measured in radians to an approximately equivalent angle measured in - * degrees. The conversion from radians to degrees is generally inexact; users should not - * expect {@code cos(toRadians(90.0))} to exactly equal {@code 0.0}. - * - * @param angrad an angle, in radians - * @return the measurement of the angle {@code angrad} in degrees. - */ - public static strictfp double toDegrees(double angrad) { - return angrad * 180.0 / PI; - } - - private static final double ivln10 = 4.34294481903251816668e-01, log10_2hi = 3.01029995663611771306e-01, log10_2lo = 3.69423907715893078616e-13, halF[] = {0.5, -0.5}, - twom1000 = 9.33263618503218878990e-302,// 2**-1000=0x01700000,0 - o_threshold = 7.09782712893383973096e+02, u_threshold = -7.45133219101941108420e+02, ln2HI[] = {6.93147180369123816490e-01, -6.93147180369123816490e-01,}, ln2LO[] = { - 1.90821492927058770002e-10, -1.90821492927058770002e-10,}, invln2 = 1.44269504088896338700e+00, ln2HI0 = ln2HI[0], ln2LO0 = ln2LO[0]; - - /** - * Returns Euler's number e raised to the power of a {@code double} value. Special cases: - *
    - *
  • If the argument is NaN, the result is NaN. - *
  • If the argument is positive infinity, then the result is positive infinity. - *
  • If the argument is negative infinity, then the result is positive zero. - *
- * - * @param aa the exponent to raise e to. - * @return the value e{@code a}, where e is the base of the natural - * logarithms. - */ - public static double exp(double aa) { - /* - * exp(x) Returns the exponential of x. - * - * Method 1. Argument reduction: Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. Given x, - * find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2. - * - * Here r will be represented as r = hi-lo for better accuracy. - * - * 2. Approximation of exp(r) by a special rational function on the interval [0,0.34658]: - * Write R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... We use a special - * Reme algorithm on [0,0.34658] to generate a polynomial of degree 5 to approximate R. The - * maximum error of this polynomial approximation is bounded by 2**-59. In other words, R(z) - * ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 (where z=r*r, and the values of P1 - * to P5 are listed below) and | 5 | -59 | 2.0+P1*z+...+P5*z - R(z) | <= 2 | | The - * computation of exp(r) thus becomes 2*r exp(r) = 1 + ------- R - r r*R1(r) = 1 + r + - * ----------- (for better accuracy) 2 - R1(r) where 2 4 10 R1(r) = r - (P1*r + P2*r + ... + - * P5*r ). - * - * 3. Scale back to obtain exp(x): From step 1, we have exp(x) = 2^k * exp(r) - * - * Special cases: exp(INF) is INF, exp(NaN) is NaN; exp(-INF) is 0, and for finite argument, - * only exp(0)=1 is exact. - * - * Accuracy: according to an error analysis, the error is always less than 1 ulp (unit in - * the last place). - * - * Misc. info. For IEEE double if x > 7.09782712893383973096e+02 then exp(x) overflow if x < - * -7.45133219101941108420e+02 then exp(x) underflow - */ - double a = aa; - int hx = __HI(a); /* high word of x */ - final int xsb = (hx >>> 31) & 1; /* sign bit of x */ - final boolean xsb0 = xsb == 0; - hx &= 0x7fffffff; /* high word of |x| */ - // preliminary check for Nan or Infinity - if (hx >= 0x7ff00000) { - // aa is inf or NaN - if (xsb0) { // aa == Double.NaN || aa == Double.POSITIVE_INFINITY) - return aa; - } else { - // negative infinity? - return 0.0; - } - } - - /* filter out non-finite argument */ - if (hx >= 0x40862E42) { /* if |x|>=709.78... */ - if (hx >= 0x7ff00000) { - if (((hx & 0xfffff) | __LO(a)) != 0) { - return a + a; /* NaN */ - } - return xsb0 ? a : 0.0d; /* exp(+-inf)={inf,0} */ - } - if (a > o_threshold) { - return huge * huge; /* overflow */ - } - if (a < u_threshold) { - return twom1000 * twom1000; /* underflow */ - } - } - - double hi = 0; - double lo = 0; - int k = 0; - /* argument reduction */ - if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - hi = a - ln2HI[xsb]; - lo = ln2LO[xsb]; - k = 1 - xsb - xsb; - } else { - k = (int) (invln2 * a + halF[xsb]); - double t = k; - hi = a - t * ln2HI0; /* t*ln2HI is exact here */ - lo = t * ln2LO0; - } - a = hi - lo; - } else if (hx < 0x3e300000) { /* when |x|<2**-28 */ - if (huge + a > one) { - return one + a; /* trigger inexact */ - } - } - - /* x is now in primary range */ - final double t = a * a; - final double c = a - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); - if (k == 0) { - return one - (((a * c) / (c - 2.0)) - a); - } - final long ybits = Double.doubleToRawLongBits(one - ((lo - ((a * c) / (2.0 - c))) - hi)); - return (k >= -1021) ? addToHighBits(ybits, k << 20) : addToHighBits(ybits, (k + 1000) << 20) * twom1000; - } - - /** - * Returns the natural logarithm (base e) of a {@code double} value. Special cases: - *
    - *
  • If the argument is NaN or less than zero, then the result is NaN. - *
  • If the argument is positive infinity, then the result is positive infinity. - *
  • If the argument is positive zero or negative zero, then the result is negative infinity. - *
- * - * @param xx a value - * @return the value ln {@code a}, the natural logarithm of {@code a}. - */ - public static double log(double xx) { - /* - * __ieee754_log(x) Return the logrithm of x - * - * Method : 1. Argument Reduction: find k and f such that x = 2^k * (1+f), where sqrt(2)/2 < - * 1+f < sqrt(2) . - * - * 2. Approximation of log(1+f). Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) = - * 2s + 2/3 s**3 + 2/5 s**5 + ....., = 2s + s*R We use a special Reme algorithm on - * [0,0.1716] to generate a polynomial of degree 14 to approximate R The maximum error of - * this polynomial approximation is bounded by 2**-58.45. In other words, 2 4 6 8 10 12 14 - * R(z) ~ Lg1*s +Lg2*s +Lg3*s +Lg4*s +Lg5*s +Lg6*s +Lg7*s (the values of Lg1 to Lg7 are - * listed in the program) and | 2 14 | -58.45 | Lg1*s +...+Lg7*s - R(z) | <= 2 | | Note that - * 2s = f - s*f = f -hfsq + s*hfsq, where hfsq = f*f/2. In order to guarantee error in log - * below 1ulp, we compute log by log(1+f) = f - s*(f - R) (if f is not too large) log(1+f) = - * f - (hfsq - s*(hfsq+R)). (better accuracy) - * - * 3. Finally, log(x) =k*ln2 + log(1+f). =k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) Here ln2 - * is split into two floating point number: ln2_hi + ln2_lo, where n*ln2_hi is always exact - * for |n| < 2000. - * - * Special cases: log(x) is NaN with signal if x < 0 (including -INF) ; log(+INF) is +INF; - * log(0) is -INF with signal; log(NaN) is that NaN with no signal. - * - * Accuracy: according to an error analysis, the error is always less than 1 ulp (unit in - * the last place). - */ - double x = xx; - int hx = (int) (Double.doubleToRawLongBits(x) >> 32); - int k = 0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - if (((hx & 0x7fffffff) | (__LO(x) & 0xFFFFFFFF)) == 0) { - return Double.NEGATIVE_INFINITY; // -two54 / zero; /* log(+-0)=-inf */ - } - if (hx < 0) { - return Double.NaN; // (x - x) / zero; /* log(-#) = NaN */ - } - k = -54; - x *= two54; /* subnormal number, scale up x */ - hx = __HI(x); /* high word of x */ - } - if (hx >= 0x7ff00000) { - return x + x; - } - k += (hx >> 20) - 1023; - hx &= 0x000fffff; - final int i = (hx + 0x95f64) & 0x100000; - k += i >> 20; - /* normalize x or x/2 */ - final double dkln2hi = k * ln2_hi; - final double dkln2lo = k * ln2_lo; - final boolean KisZero = k == 0; - final double f = setHigh32bits(x, hx | (i ^ 0x3ff00000)) - 1.0; - if ((0x000fffff & (2 + hx)) < 3) { /* |f| < 2**-20 */ - if (f == zero) { - return KisZero ? zero : dkln2hi + dkln2lo; - } - double R = f * f * (0.5 - (0.33333333333333333 * f)); - return KisZero ? f - R : dkln2hi - ((R - dkln2lo) - f); - } - double s = f / (2.0 + f); - final double z = s * s; - final double w = z * z; - final double R = w * (Lg2 + w * (Lg4 + w * Lg6)) + z * (Lg1 + w * (Lg3 + w * (Lg5 + w * Lg7))); - if (((hx - 0x6147a) | (0x6b851 - hx)) > 0) { - double hfsq = 0.5 * f * f; - s *= hfsq + R; - return KisZero ? f - (hfsq - s) : dkln2hi - ((hfsq - (s + dkln2lo)) - f); - } - s *= f - R; - return KisZero ? f - s : dkln2hi - ((s - dkln2lo) - f); - } - - /** - * Returns the base 10 logarithm of a {@code double} value. Special cases: - * - *
    - *
  • If the argument is NaN or less than zero, then the result is NaN. - *
  • If the argument is positive infinity, then the result is positive infinity. - *
  • If the argument is positive zero or negative zero, then the result is negative infinity. - *
  • If the argument is equal to 10n for integer n, then the result - * is n. - *
- * - * @param aa a value - * @return the base 10 logarithm of {@code a}. - * @since 1.5 - */ - public static double log10(double aa) { - /* - * __ieee754_log10(x) Return the base 10 logarithm of x - * - * Method : Let log10_2hi = leading 40 bits of log10(2) and log10_2lo = log10(2) - - * log10_2hi, ivln10 = 1/log(10) rounded. Then n = ilogb(x), if(n<0) n = n+1; x = - * scalbn(x,-n); log10(x) := n*log10_2hi + (n*log10_2lo + ivln10*log(x)) - * - * Note 1: To guarantee log10(10**n)=n, where 10**n is normal, the rounding mode must set to - * Round-to-Nearest. Note 2: [1/log(10)] rounded to 53 bits has error .198 ulps; log10 is - * monotonic at all binary break points. - * - * Special cases: log10(x) is NaN with signal if x < 0; log10(+INF) is +INF with no signal; - * log10(0) is -INF with signal; log10(NaN) is that NaN with no signal; log10(10**N) = N for - * N=0,1,...,22. - */ - double a = aa; - int hx = (int) (Double.doubleToRawLongBits(a) >> 32); - int k = 0; - if (hx < 0x00100000) { /* x < 2**-1022 */ - // unsigned low bits - if (((hx & 0x7fffffff) | (__LO(a) & 0xFFFFFFFF)) == 0) { - return Double.NEGATIVE_INFINITY; // -two54 / zero; /* log(+-0)=-inf */ - } - if (hx < 0) { - return Double.NaN; // (x - x) / zero; /* log(-#) = NaN */ - } - k = -54; - a *= two54; /* subnormal number, scale up x */ - hx = __HI(a); /* high word of x */ - } - if (hx >= 0x7ff00000) { - return a + a; - } - k += (hx >> 20) - 1023; - // i = ((unsigned)k&0x80000000)>>31; - final int i = (k & 0x80000000) >>> 31; - hx = (hx & 0x000fffff) | ((0x3ff - i) << 20); - final double y = k + i; - return (y * log10_2lo + ivln10 * log(setHigh32bits(a, hx))) + y * log10_2hi; - } - - /** - * Returns the correctly rounded positive square root of a {@code double} value. Special cases: - *
    - *
  • If the argument is NaN or less than zero, then the result is NaN. - *
  • If the argument is positive infinity, then the result is positive infinity. - *
  • If the argument is positive zero or negative zero, then the result is the same as the - * argument. - *
- * Otherwise, the result is the {@code double} value closest to the true mathematical square - * root of the argument value. - * - * @param a a value. - * @return the positive square root of {@code a}. - */ - public static native double sqrt(double a); - - private static final int B1 = 715094163;// B1 = (682-0.03306235651)*2**20 - private static final long B2highbits = 696219795L << 32;// (664-0.03306235651)*2**20 << 32 - - private static final double C_ = 5.42857142857142815906e-01, // 19/35 = 0x3FE15F15, 0xF15F15F1 - D_ = -7.05306122448979611050e-01,// -864/1225= 0xBFE691DE, 0x2532C834 - E_ = 1.41428571428571436819e+00, // 99/70 = 0x3FF6A0EA, 0x0EA0EA0F - F_ = 1.60714285714285720630e+00, // 45/28 = 0x3FF9B6DB, 0x6DB6DB6E - G_ = 3.57142857142857150787e-01, // 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 - TWOpow54 = Double.longBitsToDouble(0x43500000L << 32); - - /** - * Returns the cube root of a {@code double} value. For positive finite {@code x}, - * {@code cbrt(-x) == - * -cbrt(x)}; that is, the cube root of a negative value is the negative of the cube root of - * that value's magnitude. Special cases: - * - *
    - * - *
  • If the argument is NaN, then the result is NaN. - * - *
  • If the argument is infinite, then the result is an infinity with the same sign as the - * argument. - * - *
  • If the argument is zero, then the result is a zero with the same sign as the argument. - * - *
- * - * @param xx x value. - * @return the cube root of {@code xx}. - * @since 1.5 - */ - public static double cbrt(double xx) { - double x = xx; - long xb = Double.doubleToRawLongBits(x); - long hx = xb >> 32; // todo check if faster to not store sign - final long sign = hx & 0x80000000;// unsigned in c /* sign= sign(x) */ - hx ^= sign; - if (hx >= 0x7ff00000L) { - return x + x; /* cbrt(NaN,INF) is itself */ - } - if ((hx | (xb & 0x00000000FFFFFFFFL)) == 0) { - return x; /* cbrt(0) is itself */ - } - - x = setHigh32bits(xb, hx); /* x <- |x| */ - /* rough cbrt to 5 bits */ - if (hx < 0x00100000L) { /* subnormal number */ - // HI(t)=0x43500000; /* set t= 2**54 */ - // t*=x; __HI(t)=__HI(t)/3+B2; - long tb = Double.doubleToRawLongBits(TWOpow54 * x); - hx = (tb & 0x00000000FFFFFFFFL) | (tb / 3 + B2highbits); - } else { - hx = (hx / 3 + B1) << 32; - } - double t = Double.longBitsToDouble(hx); - - /* new cbrt to 23 bits, may be implemented in single precision */ - final double s = C_ + (t * t / x) * t; - t *= G_ + F_ / (s + E_ + D_ / s); - - /* chopped to 20 bits and make it larger than cbrt(x) */ - // __LO(t)=0; __HI(t)+=0x00000001; - t = Double.longBitsToDouble(((Double.doubleToRawLongBits(t) >> 32) + 0x00000001) << 32); - // one step newton iteration to 53 bits with error less than 0.667 ulps - final double r = x / (t * t); /* t*t is exact */ - t += t * ((r - t) / ((t + t) + r)); /* r-s is exact */ - /* retore the sign bit */ - return Double.longBitsToDouble(Double.doubleToRawLongBits(t) | (sign << 32)); - } - - /** - * Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. The - * remainder value is mathematically equal to f1 - f2 - *  × n, where n is the mathematical integer closest to the exact - * mathematical value of the quotient {@code f1/f2}, and if two mathematical integers are - * equally close to {@code f1/f2}, then n is the integer that is even. If the remainder - * is zero, its sign is the same as the sign of the first argument. Special cases: - *
    - *
  • If either argument is NaN, or the first argument is infinite, or the second argument is - * positive zero or negative zero, then the result is NaN. - *
  • If the first argument is finite and the second argument is infinite, then the result is - * the same as the first argument. - *
- * - * @param f1in the dividend. - * @param f2in the divisor. - * @return the remainder when {@code f1} is divided by {@code f2}. - */ - public static double IEEEremainder(double f1in, double f2in) { - /* - * __ieee754_remainder(x,p) Return : returns x REM p = x - [x/p]*p as if in infinite precise - * arithmetic, where [x/p] is the (infinite bit) integer nearest x/p (in half way case - * choose the even one). Method : Based on fmod() return x-[x/p]chopped*p exactlp. - */ - double f1 = f1in; - double f2 = f2in; - // todo need to verify that this implementation works. - long t = Double.doubleToRawLongBits(f1); - int hx = (int) (t >> 32); - final long sx = (long) (hx & 0x80000000) << 32; // unsigned in c - hx &= 0x7fffffff; - - int lx = (int) t; // unsigned in c - t = Double.doubleToRawLongBits(f2); - int hp = (int) (t >> 32) & 0x7fffffff; - int lp = (int) t; // unsigned in c - - /* purge off exception values */ - if (((hp | lp) == 0) || /* p = 0 */ - (hx >= 0x7ff00000) || /* x not finite */ - ((hp >= 0x7ff00000) && /* p is NaN */ - (((hp - 0x7ff00000) | lp) != 0))) { - return (f1 * f2) / (f1 * f2); - } - - if (hp <= 0x7fdfffff) { - // f1 = __ieee754_fmod(f1,f2+f2); /* now x < 2p */ - // f1 = f1 % (f2 + f2); /* now x < 2p */ - // until we get the DREM bytecode working, call fmod here - f1 = fmod(f1, f2 + f2); /* now x < 2p */ - } - - if (((hx - hp) | (lx - lp)) == 0) { - return zero * f1; - } - - f1 = abs(f1); - f2 = abs(f2); - if (hp < 0x00200000) { - if ((f1 + f1) > f2) { - f1 -= f2; - if ((f1 + f1) >= f2) { - f1 -= f2; - } - } - } else { - final double p_half = 0.5 * f2; - if (f1 > p_half) { - f1 -= f2; - if (f1 >= p_half) { - f1 -= f2; - } - } - } - return setHigh32bitsXOR(f1, sx); - } - - /** - * Returns the smallest (closest to negative infinity) {@code double} value that is greater than - * or equal to the argument and is equal to a mathematical integer. Special cases: - *
    - *
  • If the argument value is already equal to a mathematical integer, then the result is the - * same as the argument. - *
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result - * is the same as the argument. - *
  • If the argument value is less than zero but greater than -1.0, then the result is - * negative zero. - *
- * Note that the value of {@code JStrictMath.ceil(x)} is exactly the value of - * {@code -JStrictMath.floor(-x)}. - * - * @param a a value. - * @return the smallest (closest to negative infinity) floating-point value that is greater than - * or equal to the argument and is equal to a mathematical integer. - */ - public static double ceil(double a) { - return Math.ceil(a); - // return floorOrCeil(a, false); - } - - /** - * Returns the largest (closest to positive infinity) {@code double} value that is less than or - * equal to the argument and is equal to a mathematical integer. Special cases: - *
    - *
  • If the argument value is already equal to a mathematical integer, then the result is the - * same as the argument. - *
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result - * is the same as the argument. - *
- * - * @param a a value. - * @return the largest (closest to positive infinity) floating-point value that less than or - * equal to the argument and is equal to a mathematical integer. - */ - public static double floor(double a) { - return Math.floor(a); - // return floorOrCeil(a, true); - } - - /** - * FDLIBM 5.3 s_ceil.c and s_floor.c combined in one method. - * - * @param x value to perform floor or ceil on. - * @param isfloor true if floor operation, false if ceil - * @author gustav trede - * @return - */ - @SuppressWarnings("javadoc") - private static double floorOrCeil(double x, boolean isfloor) { - long xb = Double.doubleToRawLongBits(x); - long i0 = xb >> 32; - long i1 = (int) xb; - final int j0 = (int) (((i0 >> 20) & 0x7ff) - 0x3ff); - if (j0 < 20) { - if (j0 < 0) { /* raise inexact if x != 0 */ - if (huge + x > 0.0d) {/* return 0*sign(x) if |x|<1 */ - if (isfloor) { // floor version - if (i0 >= 0) { - i0 = i1 = 0; - } else if (((i0 & 0x7fffffff) | i1) != 0) { - i0 = 0xbff00000; - i1 = 0; - } - } else { // ceil version - if (i0 < 0) { - i0 = 0x80000000; - i1 = 0; - } else if ((i0 | i1) != 0) { - i0 = 0x3ff00000; - i1 = 0; - } - } - } - } else { - int i = (0x000fffff) >>> j0; // unsigned declared in c - if (((i0 & i) | i1) == 0) { - return x; /* x is integral */ - } - if (huge + x > 0.0d) { /* raise inexact flag */ - if (isfloor && i0 < 0 || !isfloor && i0 > 0) { - i0 += (0x00100000) >> j0; - } - i0 &= (~i); - i1 = 0; - } - } - } else if (j0 > 51) { - return j0 == 0x400 ? x + x : x; /* inf or NaN , integral */ - } else { - // i = ((unsigned)(0xffffffff))>>(j0-20); - int i = 0xffffffff >>> (j0 - 20); // unsigned declared in c - if ((i1 & i) == 0) { - return x; /* x is integral */ - } - if (huge + x > 0.0d) { /* raise inexact flag */ - if (isfloor && i0 < 0 || !isfloor && i0 > 0) { - if (j0 == 20) { - i0 += 1; - } else { - // unsigned j = i1+(1<<(52-j0)); - // if(j - *
  • If the argument value is already equal to a mathematical integer, then the result is the - * same as the argument. - *
  • If the argument is NaN or an infinity or positive zero or negative zero, then the result - * is the same as the argument. - * - * - * @param aa a value. - * @return the closest floating-point value to {@code a} that is equal to a mathematical - * integer. - * @author Joseph D. Darcy - */ - @SuppressWarnings("deprecation") - public static double rint(double aa) { - /* - * If the absolute value of a is not less than 2^52, it is either a finite integer (the - * double format does not have enough significand bits for a number that large to have any - * fractional portion), an infinity, or a NaN. In any of these cases, rint of the argument - * is the argument. - * - * Otherwise, the sum (twoToThe52 + a ) will properly round away any fractional portion of a - * since ulp(twoToThe52) == 1.0; subtracting out twoToThe52 from this sum will then be exact - * and leave the rounded integer portion of a. - * - * This method does *not* need to be declared strictfp to get fully reproducible results. - * Whether or not a method is declared strictfp can only make a difference in the returned - * result if some operation would overflow or underflow with strictfp semantics. The - * operation (twoToThe52 + a ) cannot overflow since large values of a are screened out; the - * add cannot underflow since twoToThe52 is too large. The subtraction ((twoToThe52 + a ) - - * twoToThe52) will be exact as discussed above and thus cannot overflow or meaningfully - * underflow. Finally, the last multiply in the return statement is by plus or minus 1.0, - * which is exact too. - */ - double a = aa; - double twoToThe52 = 1L << 52; // 2^52 - double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info - a = Math.abs(a); - - if (a < twoToThe52) { // E_min <= ilogb(a) <= 51 - a = ((twoToThe52 + a) - twoToThe52); - } - - return sign * a; // restore original sign - } - - /** - * Returns the angle theta from the conversion of rectangular coordinates ({@code x} - * , {@code y}) to polar coordinates (r, theta). This method computes the phase - * theta by computing an arc tangent of {@code y/x} in the range of -pi to - * pi. Special cases: - *
      - *
    • If either argument is NaN, then the result is NaN. - *
    • If the first argument is positive zero and the second argument is positive, or the first - * argument is positive and finite and the second argument is positive infinity, then the result - * is positive zero. - *
    • If the first argument is negative zero and the second argument is positive, or the first - * argument is negative and finite and the second argument is positive infinity, then the result - * is negative zero. - *
    • If the first argument is positive zero and the second argument is negative, or the first - * argument is positive and finite and the second argument is negative infinity, then the result - * is the {@code double} value closest to pi. - *
    • If the first argument is negative zero and the second argument is negative, or the first - * argument is negative and finite and the second argument is negative infinity, then the result - * is the {@code double} value closest to -pi. - *
    • If the first argument is positive and the second argument is positive zero or negative - * zero, or the first argument is positive infinity and the second argument is finite, then the - * result is the {@code double} value closest to pi/2. - *
    • If the first argument is negative and the second argument is positive zero or negative - * zero, or the first argument is negative infinity and the second argument is finite, then the - * result is the {@code double} value closest to -pi/2. - *
    • If both arguments are positive infinity, then the result is the {@code double} value - * closest to pi/4. - *
    • If the first argument is positive infinity and the second argument is negative infinity, - * then the result is the {@code double} value closest to 3*pi/4. - *
    • If the first argument is negative infinity and the second argument is positive infinity, - * then the result is the {@code double} value closest to -pi/4. - *
    • If both arguments are negative infinity, then the result is the {@code double} value - * closest to -3*pi/4. - *
    - * - * @param y the ordinate coordinate - * @param x the abscissa coordinate - * @return the theta component of the point (rtheta) in polar - * coordinates that corresponds to the point (xy) in Cartesian - * coordinates. - */ - public static double atan2(double y, double x) { - /* - * __ieee754_atan2(y,x) Method : 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). 2. - * Reduce x to positive by (if x and y are unexceptional): ARG (x+iy) = arctan(y/x) ... if x - * > 0, ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, - * - * Special cases: - * - * ATAN2((anything), NaN ) is NaN; ATAN2(NAN , (anything) ) is NaN; ATAN2(+-0, +(anything - * but NaN)) is +-0 ; ATAN2(+-0, -(anything but NaN)) is +-pi ; ATAN2(+-(anything but 0 and - * NaN), 0) is +-pi/2; ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; ATAN2(+-(anything - * but INF and NaN), -INF) is +-pi; ATAN2(+-INF,+INF ) is +-pi/4 ; ATAN2(+-INF,-INF ) is - * +-3pi/4; ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; - */ - long t = Double.doubleToRawLongBits(x); - int hx = (int) (t >> 32); - int lx = (int) t; - int ix = hx & 0x7fffffff; - t = Double.doubleToRawLongBits(y); - int hy = (int) (t >> 32); - int ly = (int) t; - int iy = hy & 0x7fffffff; - if (((ix | ((lx | -lx) >>> 31)) > 0x7ff00000) || ((iy | ((ly | -ly) >>> 31)) > 0x7ff00000)) {/* - * x - * or - * y - * is - * NaN - */ - return x + y; - } - if (((hx - 0x3ff00000) | lx) == 0) { - return atan(y); /* x=1.0 */ - } - int m = ((hy >> 31) & 1) | ((hx >> 30) & 2); /* 2*sign(x)+sign(y) */ - - /* when y = 0 */ - if ((iy | ly) == 0) { - switch (m) { - case 0: - case 1: - return y; /* atan(+-0,+anything)=+-0 */ - case 2: - return PI + tiny; /* atan(+0,-anything) = pi */ - case 3: - return -PI - tiny; /* atan(-0,-anything) =-pi */ - } - } - - /* when x = 0 */ - if ((ix | lx) == 0) { - return hy < 0 ? -pi_o_2 - tiny : pi_o_2 + tiny; - } - - /* when x is INF */ - if (ix == 0x7ff00000) { - if (iy == 0x7ff00000) { - switch (m) { - case 0: - return pi_o_4 + tiny; /* atan(+INF,+INF) */ - case 1: - return -pi_o_4 - tiny; /* atan(-INF,+INF) */ - case 2: - return (3.0 * pi_o_4) + tiny; /* atan(+INF,-INF) */ - case 3: - return (-3.0 * pi_o_4) - tiny; /* atan(-INF,-INF) */ - } - } else { - switch (m) { - case 0: - return zero; /* atan(+...,+INF) */ - case 1: - return -zero; /* atan(-...,+INF) */ - case 2: - return PI + tiny; /* atan(+...,-INF) */ - case 3: - return -PI - tiny; /* atan(-...,-INF) */ - } - } - } - - /* when y is INF */ - if (iy == 0x7ff00000) { - return hy < 0 ? -pi_o_2 - tiny : pi_o_2 + tiny; - } - - /* compute y/x */ - double z; - int k = (iy - ix) >> 20; - if (k > 60) { /* |y/x| > 2**60 */ - z = pi_o_2 + (0.5 * pi_lo); - } else if ((hx < 0) && (k < -60)) { - z = 0.0; /* |y|/x < -2**60 */ - } else { - z = atan(abs(y / x)); /* safe to do y/x */ - } - - switch (m) { - case 0: - return z; /* atan(+,+) */ - case 1: - return setHigh32bitsXOR(z, (0x80000000L << 32));// atan(-,+) - case 2: - return PI - (z - pi_lo); /* atan(+,-) */ - default: - return (z - pi_lo) - PI; /* atan(-,-) */ - } - } - - private static final double bp[] = {1.0, 1.5,}, dp_h[] = {0.0, 5.84962487220764160156e-01,}, dp_l[] = {0.0, 1.35003920212974897128e-08,}, two53 = 9007199254740992.0, - /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ - L1 = 5.99999999999994648725e-01, L2 = 4.28571428578550184252e-01, L3 = 3.33333329818377432918e-01, L4 = 2.72728123808534006489e-01, L5 = 2.30660745775561754067e-01, - L6 = 2.06975017800338417784e-01, P1 = 1.66666666666666019037e-01, P2 = -2.77777777770155933842e-03, P3 = 6.61375632143793436117e-05, P4 = -1.65339022054652515390e-06, - P5 = 4.13813679705723846039e-08, lg2 = 6.93147180559945286227e-01, lg2_h = 6.93147182464599609375e-01, lg2_l = -1.90465429995776804525e-09, ovt = 8.0085662595372944372e-0017,// -(1024-log2(ovfl+.5ulp)) - cp = 9.61796693925975554329e-01, // =2/(3ln2) - cp_h = 9.61796700954437255859e-01, // =(float)cp - cp_l = -7.02846165095275826516e-09,// =tail of cp_h - ivln2 = 1.44269504088896338700e+00, // =1/ln2 - ivln2_h = 1.44269502162933349609e+00,// =24b 1/ln2 - ivln2_l = 1.92596299112661746887e-08;// =1/ln2 tail - - /** - * Returns the value of the first argument raised to the power of the second argument. Special - * cases: - * - *
      - *
    • If the second argument is positive or negative zero, then the result is 1.0. - *
    • If the second argument is 1.0, then the result is the same as the first argument. - *
    • If the second argument is NaN, then the result is NaN. - *
    • If the first argument is NaN and the second argument is nonzero, then the result is NaN. - * - *
    • If - *
        - *
      • the absolute value of the first argument is greater than 1 and the second argument is - * positive infinity, or - *
      • the absolute value of the first argument is less than 1 and the second argument is - * negative infinity, - *
      - * then the result is positive infinity. - * - *
    • If - *
        - *
      • the absolute value of the first argument is greater than 1 and the second argument is - * negative infinity, or - *
      • the absolute value of the first argument is less than 1 and the second argument is - * positive infinity, - *
      - * then the result is positive zero. - * - *
    • If the absolute value of the first argument equals 1 and the second argument is infinite, - * then the result is NaN. - * - *
    • If - *
        - *
      • the first argument is positive zero and the second argument is greater than zero, or - *
      • the first argument is positive infinity and the second argument is less than zero, - *
      - * then the result is positive zero. - * - *
    • If - *
        - *
      • the first argument is positive zero and the second argument is less than zero, or - *
      • the first argument is positive infinity and the second argument is greater than zero, - *
      - * then the result is positive infinity. - * - *
    • If - *
        - *
      • the first argument is negative zero and the second argument is greater than zero but not - * a finite odd integer, or - *
      • the first argument is negative infinity and the second argument is less than zero but not - * a finite odd integer, - *
      - * then the result is positive zero. - * - *
    • If - *
        - *
      • the first argument is negative zero and the second argument is a positive finite odd - * integer, or - *
      • the first argument is negative infinity and the second argument is a negative finite odd - * integer, - *
      - * then the result is negative zero. - * - *
    • If - *
        - *
      • the first argument is negative zero and the second argument is less than zero but not a - * finite odd integer, or - *
      • the first argument is negative infinity and the second argument is greater than zero but - * not a finite odd integer, - *
      - * then the result is positive infinity. - * - *
    • If - *
        - *
      • the first argument is negative zero and the second argument is a negative finite odd - * integer, or - *
      • the first argument is negative infinity and the second argument is a positive finite odd - * integer, - *
      - * then the result is negative infinity. - * - *
    • If the first argument is finite and less than zero - *
        - *
      • if the second argument is a finite even integer, the result is equal to the result of - * raising the absolute value of the first argument to the power of the second argument - * - *
      • if the second argument is a finite odd integer, the result is equal to the negative of - * the result of raising the absolute value of the first argument to the power of the second - * argument - * - *
      • if the second argument is finite and not an integer, then the result is NaN. - *
      - * - *
    • If both arguments are integers, then the result is exactly equal to the mathematical - * result of raising the first argument to the power of the second argument if that result can - * in fact be represented exactly as a {@code double} value. - *
    - * - *

    - * (In the foregoing descriptions, a floating-point value is considered to be an integer if and - * only if it is finite and a fixed point of the method {@link #ceil ceil} or, equivalently, a - * fixed point of the method {@link #floor floor}. A value is a fixed point of a one-argument - * method if and only if the result of applying the method to the value is equal to the value.) - * - * @param x base. - * @param y the exponent. - * @return the value {@code a}{@code b}. - */ - public static double pow(double x, double y) { - /* - * __ieee754_pow(x,y) return x**y - * - * n Method: Let x = 2 * (1+f) 1. Compute and return log2(x) in two pieces: log2(x) = w1 + - * w2, where w1 has 53-24 = 29 bit trailing zeros. 2. Perform y*log2(x) = n+y' by simulating - * muti-precision arithmetic, where |y'|<=0.5. 3. Return x**y = 2**n*exp(y'*log2) - * - * Special cases: 1. (anything) ** 0 is 1 2. (anything) ** 1 is itself 3. (anything) ** NAN - * is NAN 4. NAN ** (anything except 0) is NAN 5. +-(|x| > 1) ** +INF is +INF 6. +-(|x| > 1) - * ** -INF is +0 7. +-(|x| < 1) ** +INF is +0 8. +-(|x| < 1) ** -INF is +INF 9. +-1 ** +-INF - * is NAN 10. +0 ** (+anything except 0, NAN) is +0 11. -0 ** (+anything except 0, NAN, odd - * integer) is +0 12. +0 ** (-anything except 0, NAN) is +INF 13. -0 ** (-anything except 0, - * NAN, odd integer) is +INF 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) 15. +INF ** - * (+anything except 0,NAN) is +INF 16. +INF ** (-anything except 0,NAN) is +0 17. -INF ** - * (anything) = -0 ** (-anything) 18. (-anything) ** (integer) is - * (-1)**(integer)*(+anything**integer) 19. (-anything except 0 and inf) ** (non-integer) is - * NAN - * - * Accuracy: pow(x,y) returns x**y nearly rounded. In particular pow(integer,integer) always - * returns the correct integer provided it is representable. - */ - - // i0 = ((*(int*)&one)>>29)^1; i1=1-i0; - - long xb = Double.doubleToRawLongBits(x); - int hx = (int) (xb >> 32); - int lx = (int) xb & 0x7fffffff; // unsigned - int ix = hx & 0x7fffffff; - xb = Double.doubleToRawLongBits(y); - int hy = (int) (xb >> 32); - int ly = (int) xb & 0x7fffffff; // unsigned - int iy = hy & 0x7fffffff; - - /* y==zero: x**0 = 1 */ - if ((iy | ly) == 0) - return one; - - /* +-NaN return x+y */ - if (ix > 0x7ff00000 || ((ix == 0x7ff00000) && (lx != 0)) || iy > 0x7ff00000 || ((iy == 0x7ff00000) && (ly != 0))) - return x + y; - - /* - * determine if y is an odd int when x < 0 yisint = 0 ... y is not an integer yisint = 1 ... - * y is an odd int yisint = 2 ... y is an even int - */ - int yisint = 0; - if (hx < 0) { - if (iy >= 0x43400000) - yisint = 2; /* even integer y */ - else if (iy >= 0x3ff00000) { - int k = (iy >> 20) - 0x3ff; /* exponent */ - if (k > 20) { - int j = ly >> (52 - k); - if ((j << (52 - k)) == ly) - yisint = 2 - (j & 1); - } else if (ly == 0) { - int j = iy >> (20 - k); - if ((j << (20 - k)) == iy) - yisint = 2 - (j & 1); - } - } - } - - /* special value of y */ - if (ly == 0) { - if (iy == 0x7ff00000) { /* y is +-inf */ - if (((ix - 0x3ff00000) | lx) == 0) - return y - y; /* inf**+-1 is NaN */ - return (ix >= 0x3ff00000) ? /* (|x|>1)**+-inf = inf,0 */ - (hy >= 0) ? y : zero : /* (|x|<1)**-,+inf = inf,0 */ - (hy < 0) ? -y : zero; - } - if (iy == 0x3ff00000) { /* y is +-1 */ - return (hy < 0) ? one / x : x; - } - if (hy == 0x40000000) - return x * x; /* y is 2 */ - if (hy == 0x3fe00000) { /* y is 0.5 */ - if (hx >= 0) /* x >= +0 */ - return Math.sqrt(x); - } - } - - double ax = abs(x); - /* special value of x */ - if (lx == 0) { - if (ix == 0x7ff00000 || ix == 0 || ix == 0x3ff00000) { - double z = ax; /* x is +-0,+-inf,+-1 */ - if (hy < 0) - z = one / z; /* z = (1/|x|) */ - if (hx < 0) { - if (((ix - 0x3ff00000) | yisint) == 0) { - z = (z - z) / (z - z); /* (-1)**non-int is NaN */ - } else if (yisint == 1) - z = -z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - } - - int n = (hx >> 31) + 1; - - /* (x<0)**(non-int) is NaN */ - if ((n | yisint) == 0) - return (x - x) / (x - x); - - double s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ - if ((n | (yisint - 1)) == 0) - s = -one;/* (-ve)**(odd int) */ - - double t1, t2; - /* |y| is huge */ - if (iy > 0x41e00000) { /* if |y| > 2**31 */ - if (iy > 0x43f00000) { /* if |y| > 2**64, must o/uflow */ - if (ix <= 0x3fefffff) - return (hy < 0) ? huge * huge : tiny * tiny; - if (ix >= 0x3ff00000) - return (hy > 0) ? huge * huge : tiny * tiny; - } - /* over/underflow if x is not close to one */ - if (ix < 0x3fefffff) - return (hy < 0) ? s * huge * huge : s * tiny * tiny; - if (ix > 0x3ff00000) - return (hy > 0) ? s * huge * huge : s * tiny * tiny; - /* - * now |1-x| is tiny <= 2**-20, suffice to compute log(x) by x-x^2/2+x^3/3-x^4/4 - */ - double t = ax - one; /* t has 20 trailing zeros */ - double w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25)); - double u = ivln2_h * t; /* ivln2_h has 21 sig. bits */ - double v = t * ivln2_l - w * ivln2; - t1 = clearLow32bits(u + v); - t2 = v - (t1 - u); - } else { - n = 0; - /* take care subnormal number */ - if (ix < 0x00100000) { - ax *= two53; - n -= 53; - ix = __HI(ax); - } - n += ((ix) >> 20) - 0x3ff; - int j = ix & 0x000fffff; - /* determine interval */ - ix = j | 0x3ff00000; /* normalize ix */ - int k = 0; - if (j <= 0x3988E) - k = 0; /* |x|>1)|0x20000000)+0x00080000+(k<<18); - double t_h = setHigh32bitsDontMask(zerobitshigh, ((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18)); - double s_l = v * ((u - s_h * t_h) - s_h * (ax - (t_h - bp[k]))); - /* compute log(ax) */ - double s2 = ss * ss; - double r = s2 * s2 * (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))) + s_l * (s_h + ss); - s2 = s_h * s_h; - t_h = clearLow32bits(3.0 + s2 + r); - /* u+v = ss*(1+...) */ - u = s_h * t_h; - v = s_l * t_h + (r - ((t_h - 3.0) - s2)) * ss; - /* 2/(3log2)*(ss+...) */ - double p_h = clearLow32bits(u + v); // __LO(p_h) = 0; - double z_h = cp_h * p_h; /* cp_h+cp_l = 2/(3*log2) */ - double z_l = cp_l * p_h + (v - (p_h - u)) * cp + dp_l[k]; - /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - double t = n; - t1 = clearLow32bits((((z_h + z_l) + dp_h[k]) + t)); // __LO(t1) = 0; - t2 = z_l - (((t1 - t) - dp_h[k]) - z_h); - } - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - double y1 = clearLow32bits(y); // __LO(y1) = 0; - double p_l = (y - y1) * t1 + y * t2; - double p_h = y1 * t1; - double z = p_l + p_h; - long zb = Double.doubleToRawLongBits(z); - int j = (int) (zb >> 32); - if (j >= 0x40900000) { /* z >= 1024 */ - if (((j - 0x40900000) | ((int) zb)) != 0) /* if z > 1024 */ - return s * huge * huge; /* overflow */ - else { - if (p_l + ovt > z - p_h) - return s * huge * huge; /* overflow */ - } - } else if ((j & 0x7fffffff) >= 0x4090cc00) { /* z <= -1075 */ - if (((j - 0xc090cc00) | ((int) zb)) != 0) /* z < -1075 */ - return s * tiny * tiny; /* underflow */ - else { - if (p_l <= z - p_h) - return s * tiny * tiny; /* underflow */ - } - } - /* - * compute 2**(p_h+p_l) - */ - int i = j & 0x7fffffff; - n = 0; - if (i > 0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j + (0x00100000 >> ((i >> 20) - 0x3ff + 1)); - final int k = ((n & 0x7fffffff) >> 20) - 0x3ff; /* new k for n */ - double t = setHigh32bitsDontMask(zerobitshigh, (n & ~(0x000fffff >> k))); - n = ((n & 0x000fffff) | 0x00100000) >> (20 - k); - if (j < 0) - n = -n; - p_h -= t; - } - double t = clearLow32bits(p_l + p_h);// __LO(t) = 0; - double u = t * lg2_h; - double v = (p_l - (t - p_h)) * lg2 + t * lg2_l; - z = u + v; - double w = v - (z - u); - t = z * z; - t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); - z = one - (((z * t1) / (t1 - two) - (w + z * w)) - z); - j = __HI(z) + (n << 20); - return s * ((j >> 20) <= 0 ? scalb(z, n) : /* subnormal output */ - addToHighBits(z, (long) n << (20)));// __HI(z) += (n<<20); - } - - /** - * Returns the closest {@code int} to the argument. The result is rounded to an integer by - * adding 1/2, taking the floor of the result, and casting the result to type {@code int}. In - * other words, the result is equal to the value of the expression: - *

    - * {@code (int)Math.floor(a + 0.5f)} - * - *

    - * Special cases: - *

      - *
    • If the argument is NaN, the result is 0. - *
    • If the argument is negative infinity or any value less than or equal to the value of - * {@code Integer.MIN_VALUE}, the result is equal to the value of {@code Integer.MIN_VALUE}. - *
    • If the argument is positive infinity or any value greater than or equal to the value of - * {@code Integer.MAX_VALUE}, the result is equal to the value of {@code Integer.MAX_VALUE}. - *
    - * - * @param a a floating-point value to be rounded to an integer. - * @return the value of the argument rounded to the nearest {@code int} value. - * @see java.lang.Integer#MAX_VALUE - * @see java.lang.Integer#MIN_VALUE - */ - public static int round(float a) { - return (int) floor(a + 0.5f); - } - - /** - * Returns the closest {@code long} to the argument. The result is rounded to an integer by - * adding 1/2, taking the floor of the result, and casting the result to type {@code long}. In - * other words, the result is equal to the value of the expression: - *

    - * {@code (long)Math.floor(a + 0.5d)} - * - *

    - * Special cases: - *

      - *
    • If the argument is NaN, the result is 0. - *
    • If the argument is negative infinity or any value less than or equal to the value of - * {@code Long.MIN_VALUE}, the result is equal to the value of {@code Long.MIN_VALUE}. - *
    • If the argument is positive infinity or any value greater than or equal to the value of - * {@code Long.MAX_VALUE}, the result is equal to the value of {@code Long.MAX_VALUE}. - *
    - * - * @param a a floating-point value to be rounded to a {@code long}. - * @return the value of the argument rounded to the nearest {@code long} value. - * @see java.lang.Long#MAX_VALUE - * @see java.lang.Long#MIN_VALUE - */ - public static long round(double a) { - return (long) floor(a + 0.5d); - } - - private static Random randomNumberGenerator; - - private static synchronized void initRNG() { - if (randomNumberGenerator == null) { - randomNumberGenerator = new Random(); - } - } - - /** - * Returns a {@code double} value with a positive sign, greater than or equal to {@code 0.0} and - * less than {@code 1.0}. Returned values are chosen pseudorandomly with (approximately) uniform - * distribution from that range. - * - *

    - * When this method is first called, it creates a single new pseudorandom-number generator, - * exactly as if by the expression

    {@code new java.util.Random}
    This - * new pseudorandom-number generator is used thereafter for all calls to this method and is used - * nowhere else. - * - *

    - * This method is properly synchronized to allow correct use by more than one thread. However, - * if many threads need to generate pseudorandom numbers at a great rate, it may reduce - * contention for each thread to have its own pseudorandom number generator. - * - * @return a pseudorandom {@code double} greater than or equal to {@code 0.0} and less than - * {@code 1.0}. - * @see java.util.Random#nextDouble() - */ - public static double random() { - if (randomNumberGenerator == null) { - initRNG(); - } - return randomNumberGenerator.nextDouble(); - } - - /** - * Returns the absolute value of an {@code int} value.. If the argument is not negative, the - * argument is returned. If the argument is negative, the negation of the argument is returned. - * - *

    - * Note that if the argument is equal to the value of {@link Integer#MIN_VALUE}, the most - * negative representable {@code int} value, the result is that same value, which is negative. - * - * @param a the argument whose absolute value is to be determined. - * @return the absolute value of the argument. - */ - public static int abs(int a) { - return Math.abs(a); - // return (a < 0) ? -a : a; - } - - /** - * Returns the absolute value of a {@code long} value. If the argument is not negative, the - * argument is returned. If the argument is negative, the negation of the argument is returned. - * - *

    - * Note that if the argument is equal to the value of {@link Long#MIN_VALUE}, the most negative - * representable {@code long} value, the result is that same value, which is negative. - * - * @param a the argument whose absolute value is to be determined. - * @return the absolute value of the argument. - */ - public static long abs(long a) { - return Math.abs(a); - // return (a < 0) ? -a : a; - } - - /** - * Returns the absolute value of a {@code float} value. If the argument is not negative, the - * argument is returned. If the argument is negative, the negation of the argument is returned. - * Special cases: - *

      - *
    • If the argument is positive zero or negative zero, the result is positive zero. - *
    • If the argument is infinite, the result is positive infinity. - *
    • If the argument is NaN, the result is NaN. - *
    - * In other words, the result is the same as the value of the expression: - *

    - * {@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))} - * - * @param a the argument whose absolute value is to be determined - * @return the absolute value of the argument. - */ - public static float abs(float a) { - return Math.abs(a); - // return (a <= 0.0F) ? 0.0F - a : a; - } - - /** - * Returns the absolute value of a {@code double} value. If the argument is not negative, the - * argument is returned. If the argument is negative, the negation of the argument is returned. - * Special cases: - *

      - *
    • If the argument is positive zero or negative zero, the result is positive zero. - *
    • If the argument is infinite, the result is positive infinity. - *
    • If the argument is NaN, the result is NaN. - *
    - * In other words, the result is the same as the value of the expression: - *

    - * {@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)} - * - * @param a the argument whose absolute value is to be determined - * @return the absolute value of the argument. - */ - public static double abs(double a) { - return Math.abs(a); - // return (a <= 0.0D) ? 0.0D - a : a; - } - - /** - * Returns the greater of two {@code int} values. That is, the result is the argument closer to - * the value of {@link Integer#MAX_VALUE}. If the arguments have the same value, the result is - * that same value. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static int max(int a, int b) { - return Math.max(a, b); - // return (a >= b) ? a : b; - } - - /** - * Returns the greater of two {@code long} values. That is, the result is the argument closer to - * the value of {@link Long#MAX_VALUE}. If the arguments have the same value, the result is that - * same value. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static long max(long a, long b) { - return Math.max(a, b); - // return (a >= b) ? a : b; - } - - private final static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f), negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d); - - /** - * Returns the greater of two {@code float} values. That is, the result is the argument closer - * to positive infinity. If the arguments have the same value, the result is that same value. If - * either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this - * method considers negative zero to be strictly smaller than positive zero. If one argument is - * positive zero and the other negative zero, the result is positive zero. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static float max(float a, float b) { - return Math.max(a, b); - /***** - * if (a != a) { return a; // a is NaN } if ((a == 0.0f) && (b == 0.0f) && - * (Float.floatToIntBits(a) == negativeZeroFloatBits)) { return b; } return (a >= b) ? a : - * b; - *****/ - } - - /** - * Returns the greater of two {@code double} values. That is, the result is the argument closer - * to positive infinity. If the arguments have the same value, the result is that same value. If - * either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this - * method considers negative zero to be strictly smaller than positive zero. If one argument is - * positive zero and the other negative zero, the result is positive zero. - * - * @param a an argument. - * @param b another argument. - * @return the larger of {@code a} and {@code b}. - */ - public static double max(double a, double b) { - return Math.max(a, b); - /****** - * if (a != a) { return a; // a is NaN } if ((a == 0.0d) && (b == 0.0d) && - * (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) { return b; } return (a >= b) ? a - * : b; - ******/ - } - - /** - * Returns the smaller of two {@code int} values. That is, the result the argument closer to the - * value of {@link Integer#MIN_VALUE}. If the arguments have the same value, the result is that - * same value. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b}. - */ - public static int min(int a, int b) { - return Math.min(a, b); - // return (a <= b) ? a : b; - } - - /** - * Returns the smaller of two {@code long} values. That is, the result is the argument closer to - * the value of {@link Long#MIN_VALUE}. If the arguments have the same value, the result is that - * same value. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b}. - */ - public static long min(long a, long b) { - return Math.min(a, b); - // return (a <= b) ? a : b; - } - - /** - * Returns the smaller of two {@code float} values. That is, the result is the value closer to - * negative infinity. If the arguments have the same value, the result is that same value. If - * either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this - * method considers negative zero to be strictly smaller than positive zero. If one argument is - * positive zero and the other is negative zero, the result is negative zero. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b.} - */ - public static float min(float a, float b) { - return Math.min(a, b); - /******* - * if (a != a) { return a; // a is NaN } if ((a == 0.0f) && (b == 0.0f) && - * (Float.floatToIntBits(b) == negativeZeroFloatBits)) { return b; } return (a <= b) ? a : - * b; - *****/ - } - - /** - * Returns the smaller of two {@code double} values. That is, the result is the value closer to - * negative infinity. If the arguments have the same value, the result is that same value. If - * either value is NaN, then the result is NaN. Unlike the numerical comparison operators, this - * method considers negative zero to be strictly smaller than positive zero. If one argument is - * positive zero and the other is negative zero, the result is negative zero. - * - * @param a an argument. - * @param b another argument. - * @return the smaller of {@code a} and {@code b}. - */ - public static double min(double a, double b) { - return Math.min(a, b); - /********* - * if (a != a) { return a; // a is NaN } if ((a == 0.0d) && (b == 0.0d) && - * (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) { return b; } return (a <= b) ? a - * : b; - *******/ - } - - /** - * Returns the size of an ulp of the argument. An ulp of a {@code double} value is the positive - * distance between this floating-point value and the {@code double} value next larger in - * magnitude. Note that for non-NaN x, ulp(-x) == ulp(x). - * - *

    - * Special Cases: - *

      - *
    • If the argument is NaN, then the result is NaN. - *
    • If the argument is positive or negative infinity, then the result is positive infinity. - *
    • If the argument is positive or negative zero, then the result is {@code Double.MIN_VALUE}. - *
    • If the argument is ±{@code Double.MAX_VALUE}, then the result is equal to - * 2971. - *
    - * - * @param d the floating-point value whose ulp is to be returned - * @return the size of an ulp of the argument - * @author Joseph D. Darcy - * @since 1.5 - */ - @SuppressWarnings("deprecation") - public static double ulp(double d) { - return sun.misc.FpUtils.ulp(d); - } - - /** - * Returns the size of an ulp of the argument. An ulp of a {@code float} value is the positive - * distance between this floating-point value and the {@code float} value next larger in - * magnitude. Note that for non-NaN x, ulp(-x) == ulp(x). - * - *

    - * Special Cases: - *

      - *
    • If the argument is NaN, then the result is NaN. - *
    • If the argument is positive or negative infinity, then the result is positive infinity. - *
    • If the argument is positive or negative zero, then the result is {@code Float.MIN_VALUE}. - *
    • If the argument is ±{@code Float.MAX_VALUE}, then the result is equal to - * 2104. - *
    - * - * @param f the floating-point value whose ulp is to be returned - * @return the size of an ulp of the argument - * @author Joseph D. Darcy - * @since 1.5 - */ - @SuppressWarnings("deprecation") - public static float ulp(float f) { - return sun.misc.FpUtils.ulp(f); - } - - /** - * Returns the signum function of the argument; zero if the argument is zero, 1.0 if the - * argument is greater than zero, -1.0 if the argument is less than zero. - * - *

    - * Special Cases: - *

      - *
    • If the argument is NaN, then the result is NaN. - *
    • If the argument is positive zero or negative zero, then the result is the same as the - * argument. - *
    - * - * @param d the floating-point value whose signum is to be returned - * @return the signum function of the argument - * @author Joseph D. Darcy - * @since 1.5 - */ - @SuppressWarnings("deprecation") - public static double signum(double d) { - return sun.misc.FpUtils.signum(d); - } - - /** - * Returns the signum function of the argument; zero if the argument is zero, 1.0f if the - * argument is greater than zero, -1.0f if the argument is less than zero. - * - *

    - * Special Cases: - *

      - *
    • If the argument is NaN, then the result is NaN. - *
    • If the argument is positive zero or negative zero, then the result is the same as the - * argument. - *
    - * - * @param f the floating-point value whose signum is to be returned - * @return the signum function of the argument - * @author Joseph D. Darcy - * @since 1.5 - */ - @SuppressWarnings("deprecation") - public static float signum(float f) { - return sun.misc.FpUtils.signum(f); - } - - private static final double shuge = 1.0e307; - - /** - * Returns the hyperbolic sine of a {@code double} value. The hyperbolic sine of x is - * defined to be (ex - e-x)/2 where e is - * {@linkplain Math#E Euler's number}. - * - *

    - * Special cases: - *

      - * - *
    • If the argument is NaN, then the result is NaN. - * - *
    • If the argument is infinite, then the result is an infinity with the same sign as the - * argument. - * - *
    • If the argument is zero, then the result is a zero with the same sign as the argument. - * - *
    - * - * @param x The number whose hyperbolic sine is to be returned. - * @return The hyperbolic sine of {@code x}. - * @since 1.5 - */ - public static double sinh(double x) { - /* - * __ieee754_sinh(x) Method : mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2 1. - * Replace x by |x| (sinh(-x) = -sinh(x)). 2. E + E/(E+1) 0 <= x <= 22 : sinh(x) := - * --------------, E=expm1(x) 2 - * - * 22 <= x <= lnovft : sinh(x) := exp(x)/2 lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * - * exp(x/2) ln2ovft < x : sinh(x) := x*shuge (overflow) - * - * Special cases: sinh(x) is |x| if x is +INF, -INF, or NaN. only sinh(0)=0 is exact for - * finite x. - */ - - final long xb = Double.doubleToLongBits(x); - final double h = (xb >> 32) < 0 ? -0.5 : 0.5; - final int ix = (int) ((xb >> 32) & 0x7fffffff); - - if (ix >= 0x7ff00000) { /* x is INF or NaN */ - return x + x; - } - - /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */ - if (ix < 0x40360000) { /* |x|<22 */ - if (ix < 0x3e300000) /* |x|<2**-28 */ - if (shuge + x > one) { - return x;/* sinh(tiny) = tiny with inexact */ - } - final double t = expm1(abs(x)); - return (ix < 0x3ff00000) ? h * (2.0 * t - t * t / (t + one)) : h * (t + t / (t + one)); - } - - /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ - if (ix < 0x40862E42) - return h * exp(abs(x)); - - // |x| in [log(Double.MAX_VALUE), overflowthreshold] - if (ix < 0x408633ce || (ix == 0x408633ce && (xb & 0x00000000ffffffffL) <= 0x8fb9f87dL)) { - final double w = exp(0.5 * abs(x)); - return (h * w) * w; - } - /* |x| > overflowthresold, sinh(x) overflow */ - return x * shuge; - - } - - /** - * Returns the hyperbolic cosine of a {@code double} value. The hyperbolic cosine of x is - * defined to be (ex + e-x)/2 where e is - * {@linkplain Math#E Euler's number}. - * - *

    - * Special cases: - *

      - * - *
    • If the argument is NaN, then the result is NaN. - * - *
    • If the argument is infinite, then the result is positive infinity. - * - *
    • If the argument is zero, then the result is {@code 1.0}. - * - *
    - * - * @param x The number whose hyperbolic cosine is to be returned. - * @return The hyperbolic cosine of {@code x}. - * @since 1.5 - */ - public static double cosh(double x) { - /* - * __ieee754_cosh(x) Method : mathematically cosh(x) if defined to be (exp(x)+exp(-x))/2 1. - * Replace x by |x| (cosh(x) = cosh(-x)). 2. [ exp(x) - 1 ]^2 0 <= x <= ln2/2 : cosh(x) := 1 - * + ------------------- 2*exp(x) - * - * exp(x) + 1/exp(x) ln2/2 <= x <= 22 : cosh(x) := ------------------- 2 22 <= x <= lnovft : - * cosh(x) := exp(x)/2 lnovft <= x <= ln2ovft: cosh(x) := exp(x/2)/2 * exp(x/2) ln2ovft < x - * : cosh(x) := huge*huge (overflow) - * - * Special cases: cosh(x) is |x| if x is +INF, -INF, or NaN. only cosh(0)=1 is exact for - * finite x. - */ - - final long xb = Double.doubleToRawLongBits(x); - final int ix = ((int) (xb >> 32)) & 0x7fffffff; - - /* x is INF or NaN */ - if (ix >= 0x7ff00000) { - return x * x; - } - - /* |x| in [0,0.5*ln2], return 1+expm1(|x|)^2/(2*exp(|x|)) */ - if (ix < 0x3fd62e43) { - final double t = expm1(abs(x)); - final double w = one + t; - // for tiny arguments return 1. - return (ix < 0x3c800000) ? w : one + (t * t) / (w + w); - } - - /* |x| in [0.5*ln2,22], return (exp(|x|)+1/exp(|x|)/2; */ - if (ix < 0x40360000) { - final double t = exp(abs(x)); - return half * t + half / t; - } - - /* |x| in [22, log(maxdouble)] return half*exp(|x|) */ - if (ix < 0x40862e42) { - return half * exp(abs(x)); - } - - /* |x| in [log(maxdouble), overflowthresold] */ - if (ix < 0x408633ce || (ix == 0x408633ce && (xb & 0x00000000ffffffffL) <= 0x8fb9f87dL)) { - final double w = exp(half * abs(x)); - return (half * w) * w; - } - /* |x| > overflowthresold, cosh(x) overflow */ - return huge * huge; - } - - /** - * Returns the hyperbolic tangent of a {@code double} value. The hyperbolic tangent of x - * is defined to be - * (ex - e-x)/(ex +  - * ;e-x), in other words, {@linkplain Math#sinh sinh(x)}/ - * {@linkplain Math#cosh cosh(x)}. Note that the absolute value of the exact tanh is - * always less than 1. - * - *

    - * Special cases: - *

      - * - *
    • If the argument is NaN, then the result is NaN. - * - *
    • If the argument is zero, then the result is a zero with the same sign as the argument. - * - *
    • If the argument is positive infinity, then the result is {@code +1.0}. - * - *
    • If the argument is negative infinity, then the result is {@code -1.0}. - * - *
    - * - * @param xx The number whose hyperbolic tangent is to be returned. - * @return The hyperbolic tangent of {@code x}. - * @since 1.5 - */ - public static double tanh(double xx) { - /* - * Tanh(x) Return the Hyperbolic Tangent of x - * - * Method : x -x e - e 0. tanh(x) is defined to be ----------- x -x e + e 1. reduce x to - * non-negative by tanh(-x) = -tanh(x). 2. 0 <= x <= 2**-55 : tanh(x) := x*(one+x) -t 2**-55 - * < x <= 1 : tanh(x) := -----; t = expm1(-2x) t + 2 2 1 <= x <= 22.0 : tanh(x) := 1- ----- - * ; t=expm1(2x) t + 2 22.0 < x <= INF : tanh(x) := 1. - * - * Special cases: tanh(NaN) is NaN; only tanh(0)=0 is exact for finite argument. - */ - - double x = xx; - /* High word of |x|. */ - final int hx = (int) (Double.doubleToRawLongBits(x) >> 32); - final int ix = hx & 0x7fffffff; - - /* x is INF or NaN */ - if (ix >= 0x7ff00000) { - return hx >= 0 ? one / x + one : /* tanh(+-inf)=+-1 */ - one / x - one; /* tanh(NaN) = NaN */ - } - - double z; - /* |x| < 22 */ - if (ix < 0x40360000) { /* |x|<22 */ - if (ix < 0x3c800000) { /* |x|<2**-55 */ - return x * (one + x); /* tanh(small) = small */ - } - x = abs(x); - if (ix >= 0x3ff00000) { /* |x|>=1 */ - z = one - two / (expm1(2.0d * x) + two); - } else { - double t = expm1(-two * x); - z = -t / (t + two); - } - /* |x| > 22, return +-1 */ - } else { - z = one - tiny; /* raised inexact flag */ - } - return hx >= 0 ? z : 0.0d - z; - } - - private static final double TWOpow1022 = setHigh32bits(0x7fd00000); - private static final long onebits = Double.doubleToLongBits(one), clearHighmask = 0x00000000FFFFFFFFL, onebitshigh = onebits & clearHighmask, zerobitshigh = Double.doubleToLongBits(zero) & - clearHighmask; - - /** - * Returns sqrt(x2 +y2) without intermediate overflow - * or underflow. - * - *

    - * Special cases: - *

      - * - *
    • If either argument is infinite, then the result is positive infinity. - * - *
    • If either argument is NaN and neither argument is infinite, then the result is NaN. - * - *
    - * - * @param aa a value - * @param bb a value - * @return sqrt(x2 +y2) without intermediate overflow - * or underflow - * @since 1.5 - */ - public static double hypot(double aa, double bb) { - /* - * __ieee754_hypot(x,y) - * - * Method : If (assume round-to-nearest) z=x*x+y*y has error less than sqrt(2)/2 ulp, than - * sqrt(z) has error less than 1 ulp (exercise). - * - * So, compute sqrt(x*x+y*y) with some care as follows to get the error below 1 ulp: - * - * Assume x>y>0; (if possible, set rounding to round-to-nearest) 1. if x > 2y use - * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y where x1 = x with lower 32 bits cleared, x2 = x-x1; - * else 2. if x <= 2y use t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) where t1 = 2x with lower 32 bits - * cleared, t2 = 2x-t1, y1= y with lower 32 bits chopped, y2 = y-y1. - * - * NOTE: scaling may be necessary if some argument is too large or too tiny - * - * Special cases: hypot(x,y) is INF if x or y is +INF or -INF; else hypot(x,y) is NAN if x - * or y is NAN. - * - * Accuracy: hypot(x,y) returns sqrt(x^2+y^2) with error less than 1 ulps (units in the last - * place) - */ - - double a = aa; - double b = bb; - long hx = (Double.doubleToRawLongBits(a) >>> 32) & 0x7fffffff; - long hy = (Double.doubleToRawLongBits(b) >>> 32) & 0x7fffffff; - if (hy > hx) { - double at = a; - a = b; - b = at; - long j = hx; - hx = hy; - hy = j; - } - - a = abs(a); - b = abs(b); - - // a = setHigh32bits(a,hx); - // b = setHigh32bits(b,hy); - - // System.err.println("a1 "); - if (hx - hy > 0x3c00000) { - return a + b; - } /* x/y > 2**60 */ - // System.err.println("a2"); - int k = 0; - if (hx > 0x5f300000) { /* a>2**500 */ - // System.err.println("b1 "+hx +" >= "+ 0x7ff00000); - if (hx >= 0x7ff00000) { /* Inf or NaN */ - // System.err.println("b2"); - return Double.isInfinite(a) || Double.isInfinite(b) ? Double.POSITIVE_INFINITY : Double.NaN; - } - /* scale a and b by 2**-600 */ - k = 600; - a = setHigh32bits(a, hx -= 0x25800000); - b = setHigh32bits(b, hy -= 0x25800000); - } - if (hy < 0x20b00000) { /* b < 2**-500 */ - if (hy <= 0x000fffff) { /* subnormal b or 0 */ - // if ((hy | (bbits&clearHighmask)) == 0) { - if ((hy | __LO(b)) == 0) { - return a; - } - b *= TWOpow1022; - a *= TWOpow1022; - k -= 1022; - } else { /* scale a and b by 2^600 */ - k -= 600; - a = setHigh32bits(a, hx += 0x25800000); /* a *= 2^600 */ - b = setHigh32bits(b, hy += 0x25800000); /* b *= 2^600 */ - } - } - - /* medium size a and b */ - double w = a - b; - if (w > b) { - final double t1 = Double.longBitsToDouble(hx << 32); - w = t1 * t1 - (b * -b - (a - t1) * (a + t1)); - } else { - final double y1 = Double.longBitsToDouble(hy << 32); - final double t1 = Double.longBitsToDouble((hx + 0x00100000) << 32); - w = t1 * y1 - (w * -w - (t1 * (b - y1) + b * ((a + a) - t1))); - } - w = java.lang.Math.sqrt(w); - return k != 0 ? w * setHhighbitsAddSome(onebits, (long) k << (20 + 32)) : w; - } - - /* scaled coefficients related to expm1 */ - private static final double Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ - Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ - Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ - Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ - Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ - - /** - * Returns ex -1. Note that for values of x near 0, the exact sum - * of {@code expm1(x)} + 1 is much closer to the true result of ex - * than {@code exp(x)}. - * - *

    - * Special cases: - *

      - *
    • If the argument is NaN, the result is NaN. - * - *
    • If the argument is positive infinity, then the result is positive infinity. - * - *
    • If the argument is negative infinity, then the result is -1.0. - * - *
    • If the argument is zero, then the result is a zero with the same sign as the argument. - * - *
    - * - * @param xx the exponent to raise e to in the computation of e{@code x} - *  -1. - * @return the value e{@code x} - 1. - * @since 1.5 - */ - public static double expm1(double xx) { - /* - * expm1(x) Returns exp(x)-1, the exponential of x minus 1. - * - * Method 1. Argument reduction: Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 - * - * Here a correction term c will be computed to compensate the error in r when rounded to a - * floating-point number. - * - * 2. Approximating expm1(r) by a special rational function on the interval [0,0.34658]: - * Since r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... we define R1(r*r) by - * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) That is, R1(r**2) = 6/r - * *((exp(r)+1)/(exp(r)-1) - 2/r) = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) = 1 - r^2/60 + - * r^4/2520 - r^6/100800 + ... We use a special Reme algorithm on [0,0.347] to generate a - * polynomial of degree 5 in r*r to approximate R1. The maximum error of this polynomial - * approximation is bounded by 2**-61. In other words, R1(z) ~ 1.0 + Q1*z + Q2*z**2 + - * Q3*z**3 + Q4*z**4 + Q5*z**5 where Q1 = -1.6666666666666567384E-2, Q2 = - * 3.9682539681370365873E-4, Q3 = -9.9206344733435987357E-6, Q4 = 2.5051361420808517002E-7, - * Q5 = -6.2843505682382617102E-9; (where z=r*r, and the values of Q1 to Q5 are listed - * below) with error bounded by | 5 | -61 | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 | | - * - * expm1(r) = exp(r)-1 is then computed by the following specific way which minimize the - * accumulation rounding error: 2 3 r r [ 3 - (R1 + R1*r/2) ] expm1(r) = r + --- + --- * - * [--------------------] 2 2 [ 6 - r*(3 - R1*r/2) ] - * - * To compensate the error in the argument reduction, we use expm1(r+c) = expm1(r) + c + - * expm1(r)*c ~ expm1(r) + c + r*c Thus c+r*c will be added in as the correction terms for - * expm1(r+c). Now rearrange the term to avoid optimization screw up: ( 2 2 ) ({ ( r [ R1 - - * (3 - R1*r/2) ] ) } r ) expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) ({ - * ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) ( ) - * - * = r - E 3. Scale back to obtain expm1(x): From step 1, we have expm1(x) = either - * 2^k*[expm1(r)+1] - 1 = or 2^k*[expm1(r) + (1-2^-k)] 4. Implementation notes: (A). To save - * one multiplication, we scale the coefficient Qi to Qi*2^i, and replace z by (x^2)/2. (B). - * To achieve maximum accuracy, we compute expm1(x) by (i) if x < -56*ln2, return -1.0, - * (raise inexact if x!=inf) (ii) if k=0, return r-E (iii) if k=-1, return 0.5*(r-E)-0.5 - * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) else return 1.0+2.0*(r-E); (v) if - * (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) (vi) if k <= 20, return - * 2^k((1-2^-k)-(E-r)), else (vii) return 2^k(1-((E+2^-k)-r)) - * - * Special cases: expm1(INF) is INF, expm1(NaN) is NaN; expm1(-INF) is -1, and for finite - * argument, only expm1(0)=0 is exact. - * - * Accuracy: according to an error analysis, the error is always less than 1 ulp (unit in - * the last place). - * - * Misc. info. For IEEE double if x > 7.09782712893383973096e+02 then expm1(x) overflow - * - * Constants: The hexadecimal values are the intended ones for the following constants. The - * decimal values may be used, provided that the compiler will convert from decimal to - * binary accurately enough to produce the hexadecimal values shown. - */ - - double x = xx; - long xb = Double.doubleToRawLongBits(x); - int hx = (int) (xb >> 32); /* high word of x UNSIGNED */ - final boolean xsbzero = (hx & 0x80000000) == 0; /* sign bit of x */ - // double y = xsbzero ? x : 0.0d - x; /* y = |x| */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out huge and non-finite argument */ - if (hx >= 0x4043687A) { /* if |x|>=56*ln2 */ - if (hx >= 0x40862E42) { /* if |x|>=709.78... */ - if (hx >= 0x7ff00000) { - return (((hx & 0xfffff) | (int) xb) != 0) ? x + x : /* NaN */ - xsbzero ? x : -1.0; /* exp(+-inf)={inf,-1} */ - } - if (x > o_threshold) { - return huge * huge; /* overflow */ - } - } - /* x < -56*ln2, return -1.0 with inexact */ - if (!xsbzero && (x + tiny < 0.0)) { /* raise inexact */ - return tiny - one; /* return -1 */ - } - } - - double hi, lo, c = 0; - int k = 0; - /* argument reduction */ - if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - if (xsbzero) { - hi = x - ln2_hi; - lo = ln2_lo; - k = 1; - } else { - hi = x + ln2_hi; - lo = -ln2_lo; - k = -1; - } - } else { - // loss of precision here ?: - k = (int) (invln2 * x + (xsbzero ? 0.5 : -0.5)); - hi = x - k * ln2_hi; /* t*ln2_hi is exact here */ - lo = k * ln2_lo; - } - x = hi - lo; - c = (hi - x) - lo; - } else if (hx < 0x3c900000) { /* when |x|<2**-54, return x */ - /* return x with inexact flags when x!=0 */ - return x - ((huge + x) - (huge + x)); - } - - /* x is now in primary range */ - final double hfx = 0.5 * x; - final double hxs = x * hfx; - final double r1 = one + hxs * (Q1 + hxs * (Q2 + hxs * (Q3 + hxs * (Q4 + hxs * Q5)))); - final double t = 3.0 - r1 * hfx; - double e = hxs * ((r1 - t) / (6.0 - x * t)); - if (k == 0) { - return x - (x * e - hxs); /* c is 0 */ - } - e = (x * (e - c) - c) - hxs; - if (k == -1) { - return 0.5 * (x - e) - 0.5; - } - if (k == 1) { - return x < -0.25 ? -2.0 * (e - (x + 0.5)) : one + 2.0 * (x - e); - } - if (k <= -2 || k > 56) { /* suffice to return exp(x)-1 */ - /* add k to y's exponent */ - return setHhighbitsAddSome(one - (e - x), (long) k << (20 + 32)) - one; - } - final double y = k < 20 ? /* 1-2^-k */ - setHigh32bitsDontMask(onebitshigh, 0x3ff00000 - (0x200000 >> k)) - (e - x) : (x - (e + setHigh32bitsDontMask(onebitshigh, (0x3ff - k) << 20))) + one;// 2^-k - /* add k to y's exponent */ - return setHhighbitsAddSome(y, (long) k << (20 + 32)); - } - - private static final double Lp1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ - Lp2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ - Lp3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ - Lp4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ - Lp5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ - Lp6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ - Lp7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ - - /** - * Returns the natural logarithm of the sum of the argument and 1. Note that for small values - * {@code x}, the result of {@code log1p(x)} is much closer to the true result of ln(1 + - * {@code x}) than the floating-point evaluation of {@code log(1.0+x)}. - * - *

    - * Special cases: - *

      - * - *
    • If the argument is NaN or less than -1, then the result is NaN. - * - *
    • If the argument is positive infinity, then the result is positive infinity. - * - *
    • If the argument is negative one, then the result is negative infinity. - * - *
    • If the argument is zero, then the result is a zero with the same sign as the argument. - * - *
    - * - * @param x a value - * @return the value ln({@code x} + 1), the natural log of {@code x} + 1 - * @since 1.5 - */ - @SuppressWarnings("cast") - public static double log1p(double x) { - /* - * double log1p(double x) - * - * Method : 1. Argument Reduction: find k and f such that 1+x = 2^k * (1+f), where sqrt(2)/2 - * < 1+f < sqrt(2) . - * - * Note. If k=0, then f=x is exact. However, if k!=0, then f may not be representable - * exactly. In that case, a correction term is need. Let u=1+x rounded. Let c = (1+x)-u, - * then log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), and add back the - * correction term c/u. (Note: when x > 2**53, one can simply return log(x)) - * - * 2. Approximation of log1p(f). Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) = - * 2s + 2/3 s**3 + 2/5 s**5 + ....., = 2s + s*R We use a special Reme algorithm on - * [0,0.1716] to generate a polynomial of degree 14 to approximate R The maximum error of - * this polynomial approximation is bounded by 2**-58.45. In other words, 2 4 6 8 10 12 14 - * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s (the values of Lp1 to Lp7 are - * listed in the program) and | 2 14 | -58.45 | Lp1*s +...+Lp7*s - R(z) | <= 2 | | Note that - * 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. In order to guarantee error in log - * below 1ulp, we compute log by log1p(f) = f - (hfsq - s*(hfsq+R)). - * - * 3. Finally, log1p(x) = k*ln2 + log1p(f). = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) Here - * ln2 is split into two floating point number: ln2_hi + ln2_lo, where n*ln2_hi is always - * exact for |n| < 2000. - * - * Special cases: log1p(x) is NaN with signal if x < -1 (including -INF) ; log1p(+INF) is - * +INF; log1p(-1) is -INF with signal; log1p(NaN) is that NaN with no signal. - * - * Accuracy: according to an error analysis, the error is always less than 1 ulp (unit in - * the last place). - * - * Constants: The hexadecimal values are the intended ones for the following constants. The - * decimal values may be used, provided that the compiler will convert from decimal to - * binary accurately enough to produce the hexadecimal values shown. - * - * Note: Assuming log() return accurate answer, the following algorithm can be used to - * compute log1p(x) to within a few ULP: - * - * u = 1+x; if(u==1.0) return x ; else return log(u)*(x/(u-1.0)); - * - * See HP-15C Advanced Functions Handbook, p.193. - */ - double f = 0; - int k = 1, hu = 0; - final int hx = __HI(x); /* high word of x */ - final int ax = hx & 0x7fffffff; - if (hx < 0x3FDA827A) { /* x < 0.41422 */ - if (ax >= 0x3ff00000) { /* x <= -1.0 */ - return x == -1.0d ? -two54 / zero : /* log1p(-1)=-inf */ - (x - x) / (x - x); /* log1p(x<-1)=NaN */ - } - if (ax < 0x3e200000) { /* |x| < 2**-29 */ - if (two54 + x > zero /* raise inexact */ - && ax < 0x3c900000) /* |x| < 2**-54 */{ - return x; - } - return x - x * x * 0.5; - } - if (hx > 0 || hx <= ((int) 0xbfd2bec3)) { /* -0.2929= 0x7ff00000) { - return x + x; - } - double c; - if (k != 0) { - final double u = hx < 0x43400000 ? 1.0 + x : x; - long ub = Double.doubleToRawLongBits(u); - hu = (int) (ub >> 32); /* high word of u */ - k = (hu >> 20) - 1023; - c = hx < 0x43400000 ? (k > 0 ? 1.0 - (u - x) : x - (u - 1.0)) / u : 0; - int newhu; - if ((hu &= 0x000fffff) < 0x6a09e) { - newhu = hu | 0x3ff00000; /* normalize u */ - } else { - k += 1; - newhu = hu | 0x3fe00000; /* normalize u/2 */ - hu = (0x00100000 - hu) >> 2; - } - f = setHigh32bits(ub, newhu) - 1.0; - } else - c = 0; - - double hfsq = 0.5 * f * f; - if (hu == 0) { /* |f| < 2**-20 */ - if (f == zero) { - return k == 0 ? zero : k * ln2_hi + (c + k * ln2_lo); - } - final double R = hfsq * (1.0 - 0.66666666666666666 * f); - return k == 0 ? f - R : k * ln2_hi - ((R - (k * ln2_lo + c)) - f); - } - final double s = f / (2.0 + f); - final double z = s * s; - final double R = s * (hfsq + z * (Lp1 + z * (Lp2 + z * (Lp3 + z * (Lp4 + z * (Lp5 + z * (Lp6 + z * Lp7))))))); - return k == 0 ? f - (hfsq - R) : k * ln2_hi - ((hfsq - (R + (k * ln2_lo + c))) - f); - } - - /** - * Returns the first floating-point argument with the sign of the second floating-point - * argument. For this method, a NaN {@code sign} argument is always treated as if it were - * positive. - * - * @param magnitude the parameter providing the magnitude of the result - * @param sign the parameter providing the sign of the result - * @return a value with the magnitude of {@code magnitude} and the sign of {@code sign}. - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static double copySign(double magnitude, double sign) { - return sun.misc.FpUtils.copySign(magnitude, sign); - } - - /** - * Returns the first floating-point argument with the sign of the second floating-point - * argument. For this method, a NaN {@code sign} argument is always treated as if it were - * positive. - * - * @param magnitude the parameter providing the magnitude of the result - * @param sign the parameter providing the sign of the result - * @return a value with the magnitude of {@code magnitude} and the sign of {@code sign}. - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static float copySign(float magnitude, float sign) { - return sun.misc.FpUtils.copySign(magnitude, sign); - } - - /** - * Returns the unbiased exponent used in the representation of a {@code float}. Special cases: - * - *
      - *
    • If the argument is NaN or infinite, then the result is {@link Float#MAX_EXPONENT} + 1. - *
    • If the argument is zero or subnormal, then the result is {@link Float#MIN_EXPONENT} -1. - *
    - * - * @param f a {@code float} value - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static int getExponent(float f) { - return sun.misc.FpUtils.getExponent(f); - } - - /** - * Returns the unbiased exponent used in the representation of a {@code double}. Special cases: - * - *
      - *
    • If the argument is NaN or infinite, then the result is {@link Double#MAX_EXPONENT} + 1. - *
    • If the argument is zero or subnormal, then the result is {@link Double#MIN_EXPONENT} -1. - *
    - * - * @param d a {@code double} value - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static int getExponent(double d) { - return sun.misc.FpUtils.getExponent(d); - } - - /** - * Returns the floating-point number adjacent to the first argument in the direction of the - * second argument. If both arguments compare as equal the second argument is returned. - * - *

    - * Special cases: - *

      - *
    • If either argument is a NaN, then NaN is returned. - * - *
    • If both arguments are signed zeros, {@code direction} is returned unchanged (as implied - * by the requirement of returning the second argument if the arguments compare as equal). - * - *
    • If {@code start} is ±{@link Double#MIN_VALUE} and {@code direction} has a value - * such that the result should have a smaller magnitude, then a zero with the same sign as - * {@code start} is returned. - * - *
    • If {@code start} is infinite and {@code direction} has a value such that the result - * should have a smaller magnitude, {@link Double#MAX_VALUE} with the same sign as {@code start} - * is returned. - * - *
    • If {@code start} is equal to ± {@link Double#MAX_VALUE} and {@code direction} has - * a value such that the result should have a larger magnitude, an infinity with same sign as - * {@code start} is returned. - *
    - * - * @param start starting floating-point value - * @param direction value indicating which of {@code start}'s neighbors or {@code start} should - * be returned - * @return The floating-point number adjacent to {@code start} in the direction of - * {@code direction}. - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static double nextAfter(double start, double direction) { - return sun.misc.FpUtils.nextAfter(start, direction); - } - - /** - * Returns the floating-point number adjacent to the first argument in the direction of the - * second argument. If both arguments compare as equal a value equivalent to the second argument - * is returned. - * - *

    - * Special cases: - *

      - *
    • If either argument is a NaN, then NaN is returned. - * - *
    • If both arguments are signed zeros, a value equivalent to {@code direction} is returned. - * - *
    • If {@code start} is ±{@link Float#MIN_VALUE} and {@code direction} has a value - * such that the result should have a smaller magnitude, then a zero with the same sign as - * {@code start} is returned. - * - *
    • If {@code start} is infinite and {@code direction} has a value such that the result - * should have a smaller magnitude, {@link Float#MAX_VALUE} with the same sign as {@code start} - * is returned. - * - *
    • If {@code start} is equal to ± {@link Float#MAX_VALUE} and {@code direction} has a - * value such that the result should have a larger magnitude, an infinity with same sign as - * {@code start} is returned. - *
    - * - * @param start starting floating-point value - * @param direction value indicating which of {@code start}'s neighbors or {@code start} should - * be returned - * @return The floating-point number adjacent to {@code start} in the direction of - * {@code direction}. - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static float nextAfter(float start, double direction) { - return sun.misc.FpUtils.nextAfter(start, direction); - } - - /** - * Returns the floating-point value adjacent to {@code d} in the direction of positive infinity. - * This method is semantically equivalent to {@code nextAfter(d, - * Double.POSITIVE_INFINITY)}; however, a {@code nextUp} implementation may run faster than its - * equivalent {@code nextAfter} call. - * - *

    - * Special Cases: - *

      - *
    • If the argument is NaN, the result is NaN. - * - *
    • If the argument is positive infinity, the result is positive infinity. - * - *
    • If the argument is zero, the result is {@link Double#MIN_VALUE} - * - *
    - * - * @param d starting floating-point value - * @return The adjacent floating-point value closer to positive infinity. - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static double nextUp(double d) { - return sun.misc.FpUtils.nextUp(d); - } - - /** - * Returns the floating-point value adjacent to {@code f} in the direction of positive infinity. - * This method is semantically equivalent to {@code nextAfter(f, - * Float.POSITIVE_INFINITY)}; however, a {@code nextUp} implementation may run faster than its - * equivalent {@code nextAfter} call. - * - *

    - * Special Cases: - *

      - *
    • If the argument is NaN, the result is NaN. - * - *
    • If the argument is positive infinity, the result is positive infinity. - * - *
    • If the argument is zero, the result is {@link Float#MIN_VALUE} - * - *
    - * - * @param f starting floating-point value - * @return The adjacent floating-point value closer to positive infinity. - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static float nextUp(float f) { - return sun.misc.FpUtils.nextUp(f); - } - - /** - * Return {@code d} × 2{@code scaleFactor} rounded as if performed by a single - * correctly rounded floating-point multiply to a member of the double value set. See the Java - * Language Specification for a discussion of floating-point value sets. If the exponent of the - * result is between {@link Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the answer is - * calculated exactly. If the exponent of the result would be larger than - * {@code Double.MAX_EXPONENT}, an infinity is returned. Note that if the result is subnormal, - * precision may be lost; that is, when {@code scalb(x, n)} is subnormal, - * {@code scalb(scalb(x, n), -n)} may not equal x. When the result is non-NaN, the result - * has the same sign as {@code d}. - * - *

    - * Special cases: - *

      - *
    • If the first argument is NaN, NaN is returned. - *
    • If the first argument is infinite, then an infinity of the same sign is returned. - *
    • If the first argument is zero, then a zero of the same sign is returned. - *
    - * - * @param d number to be scaled by a power of two. - * @param scaleFactor power of 2 used to scale {@code d} - * @return {@code d} × 2{@code scaleFactor} - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static double scalb(double d, int scaleFactor) { - return sun.misc.FpUtils.scalb(d, scaleFactor); - } - - /** - * Return {@code f} × 2{@code scaleFactor} rounded as if performed by a single - * correctly rounded floating-point multiply to a member of the float value set. See the Java - * Language Specification for a discussion of floating-point value sets. If the exponent of the - * result is between {@link Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the answer is - * calculated exactly. If the exponent of the result would be larger than - * {@code Float.MAX_EXPONENT}, an infinity is returned. Note that if the result is subnormal, - * precision may be lost; that is, when {@code scalb(x, n)} is subnormal, - * {@code scalb(scalb(x, n), -n)} may not equal x. When the result is non-NaN, the result - * has the same sign as {@code f}. - * - *

    - * Special cases: - *

      - *
    • If the first argument is NaN, NaN is returned. - *
    • If the first argument is infinite, then an infinity of the same sign is returned. - *
    • If the first argument is zero, then a zero of the same sign is returned. - *
    - * - * @param f number to be scaled by a power of two. - * @param scaleFactor power of 2 used to scale {@code f} - * @return {@code f} × 2{@code scaleFactor} - * @since 1.6 - */ - @SuppressWarnings("deprecation") - public static float scalb(float f, int scaleFactor) { - return sun.misc.FpUtils.scalb(f, scaleFactor); - } - - public static double setHhighbitsAddSome(double x, long highadd) { - return setHhighbitsAddSome(Double.doubleToRawLongBits(x), highadd); - } - - public static double setHhighbitsORSome(double x, long highOR) { - return Double.longBitsToDouble(Double.doubleToRawLongBits(x) | (highOR << 32)); - } - - public static double setHhighbitsAddSome(long xl, long highadd) { - return Double.longBitsToDouble((xl & clearHighmask) | (xl + highadd)); - } - - private static int __HI(double x) { - return (int) (Double.doubleToRawLongBits(x) >> 32); - } - - private static int __LO(double x) { - return (int) Double.doubleToRawLongBits(x); - } - - private static double clearLow32bits(double x) { - return Double.longBitsToDouble(Double.doubleToRawLongBits(x) & 0xFFFFFFFF00000000L); - } - - private static double setHigh32bits(double x, long newhigh) { - return setHigh32bits(Double.doubleToRawLongBits(x), newhigh); - } - - private static double setHigh32bitsXOR(double x, long toXor) { - return Double.longBitsToDouble((Double.doubleToRawLongBits(x)) ^ toXor); - } - - private static double addToHighBits(double x, long toadd) { - return addToHighBits(Double.doubleToRawLongBits(x), toadd); - } - - private static double addToHighBits(long x, long toadd) { - return Double.longBitsToDouble((x & clearHighmask) | (((x >> 32) + toadd) << 32)); - } - - private static double setHigh32bits(long x, long newhigh) { - return Double.longBitsToDouble((x & clearHighmask) | (newhigh << 32)); - } - - private static double setHigh32bitsDontMask(long x, long newhigh) { - return Double.longBitsToDouble(x | (newhigh << 32)); - } - - private static double setHigh32bits(long newhigh) { - return Double.longBitsToDouble((newhigh << 32)); - } - - private static double ldexp(double x, int exp) { - double r = x; - // set exponent of result to exp - long ir = Double.doubleToRawLongBits(r); - long oldexp = Math.getExponent(r); - long newexpbits = (oldexp + exp + DoubleConsts.EXP_BIAS) << (DoubleConsts.SIGNIFICAND_WIDTH - 1); - // clear exp bits to zero - ir &= ~DoubleConsts.EXP_BIT_MASK; - ir |= newexpbits; - return Double.longBitsToDouble(ir); - } - - @SuppressWarnings("deprecation") - private static double fmod(double x, double y) { - int ir, iy; - double r, w; - - if ((y == 0.0) || FpUtils.isNaN(y) || !FpUtils.isFinite(x)) { - return (x * y) / (x * y); - } - - r = Math.abs(x); - double absy = Math.abs(y); - iy = getExponent(absy); - while (r >= absy) { - ir = getExponent(r); - w = ldexp(absy, ir - iy); - r -= (w <= r ? w : w * 0.5); - } - return (x >= 0.0 ? r : -r); - } - -} diff -r c8fc6e2d128b -r 8f2fb6bec986 hotspot/.project --- a/hotspot/.project Thu Jan 22 23:16:17 2015 +0100 +++ b/hotspot/.project Fri Jan 23 10:54:21 2015 +0100 @@ -111,11 +111,6 @@ PARENT-1-PROJECT_LOC/build/linux/linux_amd64_graal/generated - hsail - 2 - PARENT-1-PROJECT_LOC/src/gpu/hsail/vm - - linux 2 PARENT-1-PROJECT_LOC/src/os/linux/vm @@ -136,11 +131,6 @@ WORKSPACE_LOC/make - ptx - 2 - PARENT-1-PROJECT_LOC/src/gpu/ptx/vm - - sparc 2 PARENT-1-PROJECT_LOC/src/cpu/sparc/vm diff -r c8fc6e2d128b -r 8f2fb6bec986 make/bsd/makefiles/buildtree.make --- a/make/bsd/makefiles/buildtree.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/bsd/makefiles/buildtree.make Fri Jan 23 10:54:21 2015 +0100 @@ -243,10 +243,6 @@ echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/posix/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu/ptx/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/ptx/vm)" \\; \ - echo "$(call gamma-path,altsrc,gpu/hsail/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/hsail/vm)"; \ echo; \ echo "Src_Dirs_I = \\"; \ echo "$(call gamma-path,altsrc,share/vm/prims) \\"; \ @@ -263,8 +259,6 @@ echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/posix/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu) \\"; \ - echo "$(call gamma-path,commonsrc,gpu)"; \ [ -n "$(CFLAGS_BROWSE)" ] && \ echo && echo "CFLAGS_BROWSE = $(CFLAGS_BROWSE)"; \ [ -n "$(ENABLE_FULL_DEBUG_SYMBOLS)" ] && \ diff -r c8fc6e2d128b -r 8f2fb6bec986 make/bsd/makefiles/vm.make --- a/make/bsd/makefiles/vm.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/bsd/makefiles/vm.make Fri Jan 23 10:54:21 2015 +0100 @@ -180,8 +180,6 @@ SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm -SOURCE_PATHS+=$(HS_COMMON_SRC)/gpu/ptx/vm -SOURCE_PATHS+=$(HS_COMMON_SRC)/gpu/hsail/vm CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path)) CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/tracefiles @@ -204,9 +202,7 @@ SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/graal) -GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/gpu/ptx/vm) GRAAL_PATHS += $(HS_COMMON_SRC)/share/vm/graal -GRAAL_PATHS += $(HS_COMMON_SRC)/gpu/ptx/vm # Include dirs per type. Src_Dirs/CORE := $(CORE_PATHS) @@ -225,10 +221,8 @@ ifneq ($(INCLUDE_GRAAL), true) GRAAL_SPECIFIC_FILES := graal\* - GRAAL_SPECIFIC_GPU_FILES := gpu\* ptx\* hsail\* else GRAAL_SPECIFIC_FILES := - GRAAL_SPECIFIC_GPU_FILES := Src_Dirs_I += $(HS_COMMON_SRC)/../graal/com.oracle.graal.hotspot/src_gen/hotspot endif @@ -236,12 +230,12 @@ Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp # Exclude per type. -Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) +Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) Src_Files_EXCLUDE/GRAAL := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp Src_Files_EXCLUDE += $(Src_Files_EXCLUDE/$(TYPE)) diff -r c8fc6e2d128b -r 8f2fb6bec986 make/linux/makefiles/buildtree.make --- a/make/linux/makefiles/buildtree.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/linux/makefiles/buildtree.make Fri Jan 23 10:54:21 2015 +0100 @@ -240,10 +240,6 @@ echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/posix/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu/ptx/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/ptx/vm)" \\; \ - echo "$(call gamma-path,altsrc,gpu/hsail/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/hsail/vm)"; \ echo; \ echo "Src_Dirs_I = \\"; \ echo "$(call gamma-path,altsrc,share/vm/prims) \\"; \ @@ -259,12 +255,6 @@ echo "$(call gamma-path,altsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/posix/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu/ptx/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/ptx/vm)" \\; \ - echo "$(call gamma-path,altsrc,gpu/hsail/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/hsail/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu) \\"; \ - echo "$(call gamma-path,commonsrc,gpu)"; \ [ -n "$(CFLAGS_BROWSE)" ] && \ echo && echo "CFLAGS_BROWSE = $(CFLAGS_BROWSE)"; \ [ -n "$(ENABLE_FULL_DEBUG_SYMBOLS)" ] && \ diff -r c8fc6e2d128b -r 8f2fb6bec986 make/linux/makefiles/vm.make --- a/make/linux/makefiles/vm.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/linux/makefiles/vm.make Fri Jan 23 10:54:21 2015 +0100 @@ -160,8 +160,6 @@ SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm -SOURCE_PATHS+=$(HS_COMMON_SRC)/gpu/ptx/vm -SOURCE_PATHS+=$(HS_COMMON_SRC)/gpu/hsail/vm CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path)) CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/tracefiles @@ -184,11 +182,7 @@ SHARK_PATHS := $(GAMMADIR)/src/share/vm/shark GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/graal) -GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/gpu/ptx/vm) -GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/gpu/hsail/vm) GRAAL_PATHS += $(HS_COMMON_SRC)/share/vm/graal -GRAAL_PATHS += $(HS_COMMON_SRC)/gpu/ptx/vm -GRAAL_PATHS += $(HS_COMMON_SRC)/gpu/hsail/vm # Include dirs per type. Src_Dirs/CORE := $(CORE_PATHS) @@ -207,10 +201,8 @@ ifneq ($(INCLUDE_GRAAL), true) GRAAL_SPECIFIC_FILES := graal\* - GRAAL_SPECIFIC_GPU_FILES := gpu\* ptx\* hsail\* else GRAAL_SPECIFIC_FILES := - GRAAL_SPECIFIC_GPU_FILES := Src_Dirs_I += $(HS_COMMON_SRC)/../graal/com.oracle.graal.hotspot/src_gen/hotspot endif @@ -218,12 +210,12 @@ Src_Files_EXCLUDE += jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp # Exclude per type. -Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) +Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) Src_Files_EXCLUDE/GRAAL := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp Src_Files_EXCLUDE += $(Src_Files_EXCLUDE/$(TYPE)) diff -r c8fc6e2d128b -r 8f2fb6bec986 make/solaris/makefiles/buildtree.make --- a/make/solaris/makefiles/buildtree.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/solaris/makefiles/buildtree.make Fri Jan 23 10:54:21 2015 +0100 @@ -230,10 +230,6 @@ echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,altsrc,os/posix/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/posix/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu/ptx/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/ptx/vm)" \\; \ - echo "$(call gamma-path,altsrc,gpu/hsail/vm) \\"; \ - echo "$(call gamma-path,commonsrc,gpu/hsail/vm)"; \ echo; \ echo "Src_Dirs_I = \\"; \ echo "$(call gamma-path,altsrc,share/vm/prims) \\"; \ @@ -249,8 +245,6 @@ echo "$(call gamma-path,altsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/$(OS_FAMILY)/vm) \\"; \ echo "$(call gamma-path,commonsrc,os/posix/vm) \\"; \ - echo "$(call gamma-path,altsrc,gpu) \\"; \ - echo "$(call gamma-path,commonsrc,gpu)"; \ [ -n "$(CFLAGS_BROWSE)" ] && \ echo && echo "CFLAGS_BROWSE = $(CFLAGS_BROWSE)"; \ [ -n "$(ENABLE_FULL_DEBUG_SYMBOLS)" ] && \ diff -r c8fc6e2d128b -r 8f2fb6bec986 make/solaris/makefiles/vm.make --- a/make/solaris/makefiles/vm.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/solaris/makefiles/vm.make Fri Jan 23 10:54:21 2015 +0100 @@ -182,8 +182,6 @@ SOURCE_PATHS+=$(HS_COMMON_SRC)/os/posix/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/cpu/$(Platform_arch)/vm SOURCE_PATHS+=$(HS_COMMON_SRC)/os_cpu/$(Platform_os_arch)/vm -SOURCE_PATHS+=$(HS_COMMON_SRC)/gpu/ptx/vm -SOURCE_PATHS+=$(HS_COMMON_SRC)/gpu/hsail/vm CORE_PATHS=$(foreach path,$(SOURCE_PATHS),$(call altsrc,$(path)) $(path)) CORE_PATHS+=$(GENERATED)/jvmtifiles $(GENERATED)/tracefiles @@ -204,9 +202,7 @@ COMPILER2_PATHS += $(GENERATED)/adfiles GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/share/vm/graal) -GRAAL_PATHS += $(call altsrc,$(HS_COMMON_SRC)/gpu/ptx/vm) GRAAL_PATHS += $(HS_COMMON_SRC)/share/vm/graal -GRAAL_PATHS += $(HS_COMMON_SRC)/gpu/ptx/vm # Include dirs per type. Src_Dirs/CORE := $(CORE_PATHS) @@ -225,10 +221,8 @@ ifneq ($(INCLUDE_GRAAL), true) GRAAL_SPECIFIC_FILES := graal\* - GRAAL_SPECIFIC_GPU_FILES := gpu\* ptx\* hsail\* else GRAAL_SPECIFIC_FILES := - GRAAL_SPECIFIC_GPU_FILES := Src_Dirs_I += $(HS_COMMON_SRC)/../graal/com.oracle.graal.hotspot/src_gen/hotspot endif @@ -236,12 +230,12 @@ Src_Files_EXCLUDE := dtrace jsig.c jvmtiEnvRecommended.cpp jvmtiEnvStub.cpp # Exclude per type. -Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) -Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) ciTypeFlow.cpp -Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) $(GRAAL_SPECIFIC_GPU_FILES) +Src_Files_EXCLUDE/CORE := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER1 := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/COMPILER2 := $(COMPILER1_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/TIERED := $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) +Src_Files_EXCLUDE/ZERO := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) ciTypeFlow.cpp +Src_Files_EXCLUDE/SHARK := $(COMPILER1_SPECIFIC_FILES) $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(GRAAL_SPECIFIC_FILES) Src_Files_EXCLUDE/GRAAL := $(COMPILER2_SPECIFIC_FILES) $(ZERO_SPECIFIC_FILES) $(SHARK_SPECIFIC_FILES) ciTypeFlow.cpp Src_Files_EXCLUDE += $(Src_Files_EXCLUDE/$(TYPE)) diff -r c8fc6e2d128b -r 8f2fb6bec986 make/windows/makefiles/projectcreator.make --- a/make/windows/makefiles/projectcreator.make Thu Jan 22 23:16:17 2015 +0100 +++ b/make/windows/makefiles/projectcreator.make Fri Jan 23 10:54:21 2015 +0100 @@ -56,7 +56,6 @@ -relativeInclude src\os\windows\vm \ -relativeInclude src\os_cpu\windows_$(Platform_arch)\vm \ -relativeInclude src\cpu\$(Platform_arch)\vm \ - -relativeInclude src\gpu \ -relativeInclude graal\com.oracle.graal.hotspot\src_gen\hotspot \ -absoluteInclude $(HOTSPOTBUILDSPACE)/%f/generated \ -relativeSrcInclude src \ diff -r c8fc6e2d128b -r 8f2fb6bec986 mx/suite.py --- a/mx/suite.py Thu Jan 22 23:16:17 2015 +0100 +++ b/mx/suite.py Fri Jan 23 10:54:21 2015 +0100 @@ -292,15 +292,6 @@ "workingSets" : "Graal,AMD64", }, - "com.oracle.graal.ptx" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.api.code"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,PTX", - }, - "com.oracle.graal.sparc" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -396,35 +387,6 @@ "workingSets" : "Graal,HotSpot,SPARC", }, - "com.oracle.graal.hotspot.ptx" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.ptx", - "com.oracle.graal.compiler.ptx", - "com.oracle.graal.hotspot", - "com.oracle.graal.gpu", - ], - "checkstyle" : "com.oracle.graal.graph", - "annotationProcessors" : ["com.oracle.graal.service.processor"], - "javaCompliance" : "1.8", - "workingSets" : "Graal,HotSpot,PTX", - }, - - "com.oracle.graal.hotspot.hsail" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.replacements.hsail", - "com.oracle.graal.hotspot", - "com.oracle.graal.gpu", - ], - "checkstyle" : "com.oracle.graal.graph", - "annotationProcessors" : ["com.oracle.graal.service.processor"], - "javaCompliance" : "1.8", - "workingSets" : "Graal,HotSpot,PTX", - }, - "com.oracle.graal.hotspot.server" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -583,15 +545,6 @@ "workingSets" : "Graal,LIR,AMD64", }, - "com.oracle.graal.lir.ptx" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.asm.ptx"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,LIR,PTX", - }, - "com.oracle.graal.lir.sparc" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -650,15 +603,6 @@ "workingSets" : "Graal,Replacements,AMD64", }, - "com.oracle.graal.replacements.hsail" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.compiler.hsail"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Replacements,HSAIL", - }, - "com.oracle.graal.replacements.test" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -803,30 +747,6 @@ "workingSets" : "Graal,AMD64,Test", }, - "com.oracle.graal.compiler.ptx" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.lir.ptx", - "com.oracle.graal.compiler", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,PTX", - }, - - "com.oracle.graal.compiler.ptx.test" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.hotspot.ptx", - "com.oracle.graal.compiler.test", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,PTX,Test", - }, - "com.oracle.graal.compiler.sparc" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -1020,91 +940,6 @@ "workingSets" : "Graal,Assembler,AMD64,Test", }, - "com.oracle.graal.gpu" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.nodes"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - }, - - "com.oracle.graal.hsail" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.api.code"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - }, - - "com.oracle.graal.lir.hsail" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.lir", - "com.oracle.graal.asm.hsail", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - }, - - "com.oracle.graal.compiler.hsail" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.compiler", - "com.oracle.graal.lir.hsail", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - }, - - "com.oracle.graal.compiler.hsail.test.infra" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.test", - "com.oracle.graal.hotspot.hsail", - "OKRA_WITH_SIM", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - }, - - "com.oracle.graal.compiler.hsail.test" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.compiler.hsail.test.infra", - "com.oracle.graal.compiler.test", - "VECMATH", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "jacoco" : "exclude", - }, - - "com.oracle.graal.asm.hsail" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : [ - "com.oracle.graal.hsail", - "OKRA", - "com.oracle.graal.asm", - "com.oracle.graal.compiler.common", - ], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - }, - - "com.oracle.graal.asm.ptx" : { - "subDir" : "graal", - "sourceDirs" : ["src"], - "dependencies" : ["com.oracle.graal.lir"], - "checkstyle" : "com.oracle.graal.graph", - "javaCompliance" : "1.8", - "workingSets" : "Graal,Assembler,PTX", - }, - "com.oracle.graal.asm.sparc" : { "subDir" : "graal", "sourceDirs" : ["src"], @@ -1307,11 +1142,9 @@ "sourcesPath" : "build/graal.src.zip", "dependencies" : [ "com.oracle.graal.hotspot.amd64", - "com.oracle.graal.hotspot.ptx", "com.oracle.graal.hotspot.sparc", "com.oracle.graal.hotspot", "com.oracle.graal.hotspot.jfr", - "com.oracle.graal.hotspot.hsail", ], "exclude" : ["FINDBUGS"], }, diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/gpu_hsail.cpp --- a/src/gpu/hsail/vm/gpu_hsail.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,481 +0,0 @@ -/* - * 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. - * - */ - -#include "precompiled.hpp" -#include "runtime/javaCalls.hpp" -#include "runtime/gpu.hpp" -#include "runtime/deoptimization.hpp" -#include "gpu_hsail.hpp" -#include "utilities/debug.hpp" -#include "utilities/exceptions.hpp" -#include "hsail/vm/gpu_hsail.hpp" -#include "utilities/globalDefinitions.hpp" -#include "utilities/ostream.hpp" -#include "graal/graalEnv.hpp" -#include "graal/graalRuntime.hpp" -#include "graal/graalJavaAccess.hpp" -#include "hsailKernelArguments.hpp" -#include "hsailJavaCallArguments.hpp" -#include "code/pcDesc.hpp" -#include "code/scopeDesc.hpp" -#include "gpu_hsail_Frame.hpp" - -// Entry to GPU native method implementation that transitions current thread to '_thread_in_vm'. -#define GPU_VMENTRY(result_type, name, signature) \ - JNIEXPORT result_type JNICALL name signature { \ - GRAAL_VM_ENTRY_MARK; \ - -// Entry to GPU native method implementation that calls a JNI function -// and hence cannot transition current thread to '_thread_in_vm'. -#define GPU_ENTRY(result_type, name, signature) \ - JNIEXPORT result_type JNICALL name signature { \ - -#define GPU_END } - -#define CC (char*) /*cast a literal from (const char*)*/ -#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f)) - -#define OBJECT "Ljava/lang/Object;" -#define STRING "Ljava/lang/String;" -#define JLTHREAD "Ljava/lang/Thread;" -#define HS_INSTALLED_CODE "Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;" -#define HS_COMPILED_NMETHOD "Lcom/oracle/graal/hotspot/HotSpotCompiledNmethod;" -#define HS_NMETHOD "Lcom/oracle/graal/hotspot/meta/HotSpotNmethod;" - -JNINativeMethod Hsail::HSAIL_methods[] = { - {CC"initialize", CC"()Z", FN_PTR(Hsail::initialize)}, - {CC"generateKernel", CC"([B" STRING ")J", FN_PTR(Hsail::generate_kernel)}, - {CC"executeKernel0", CC"("HS_INSTALLED_CODE"I["OBJECT"II[I)Z", FN_PTR(Hsail::execute_kernel_void_1d)}, -}; - -void* Hsail::_device_context = NULL; -jint Hsail::_notice_safepoints = false; - -Hsail::okra_get_context_func_t Hsail::_okra_get_context; -Hsail::okra_create_kernel_func_t Hsail::_okra_create_kernel; -Hsail::okra_push_pointer_func_t Hsail::_okra_push_pointer; -Hsail::okra_push_boolean_func_t Hsail::_okra_push_boolean; -Hsail::okra_push_byte_func_t Hsail::_okra_push_byte; -Hsail::okra_push_double_func_t Hsail::_okra_push_double; -Hsail::okra_push_float_func_t Hsail::_okra_push_float; -Hsail::okra_push_int_func_t Hsail::_okra_push_int; -Hsail::okra_push_long_func_t Hsail::_okra_push_long; -Hsail::okra_execute_kernel_func_t Hsail::_okra_execute_kernel; -Hsail::okra_clear_args_func_t Hsail::_okra_clear_args; -Hsail::okra_dispose_kernel_func_t Hsail::_okra_dispose_kernel; -Hsail::okra_dispose_context_func_t Hsail::_okra_dispose_context; - -//static jint in_kernel = 0; - -void Hsail::notice_safepoints() { - _notice_safepoints = true; -// if (TraceGPUInteraction) { -// tty->print_cr("[HSAIL] Notice safepoint in_kernel=%d", in_kernel); -// } -} - -void Hsail::ignore_safepoints() { - _notice_safepoints = false; -} - -GPU_VMENTRY(jboolean, Hsail::execute_kernel_void_1d, (JNIEnv* env, jclass, jobject kernel_handle, jint dimX, jobject args, - jint num_tlabs, jint allocBytesPerWorkitem, jobject oop_map_array)) - - ResourceMark rm; - jlong nmethodValue = InstalledCode::address(kernel_handle); - if (nmethodValue == 0) { - SharedRuntime::throw_and_post_jvmti_exception(JavaThread::current(), vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL); - } - nmethod* nm = (nmethod*) (address) nmethodValue; - methodHandle mh = nm->method(); - Symbol* signature = mh->signature(); - - void* kernel = (void*) HotSpotInstalledCode::codeStart(kernel_handle); - if (kernel == NULL) { - SharedRuntime::throw_and_post_jvmti_exception(JavaThread::current(), vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException(), NULL); - } - -return execute_kernel_void_1d_internal((address) kernel, dimX, args, mh, nm, num_tlabs, allocBytesPerWorkitem, oop_map_array, CHECK_0); -GPU_END - -static void showRanges(jboolean* a, int len) { - // show ranges - bool lookFor = true; - for (int i = 0; i < len; i++) { - if ((lookFor == true) && (a[i] != 0)) { - tty->print("%d", i); - lookFor = false; - } else if ((lookFor == false) && (a[i] == 0)) { - tty->print_cr("-%d", i-1); - lookFor = true; - } - } - if (lookFor == false) { - tty->print_cr("-%d", len-1); - } -} - -jboolean Hsail::execute_kernel_void_1d_internal(address kernel, int dimX, jobject args, methodHandle& mh, nmethod* nm, - jint num_tlabs, int allocBytesPerWorkitem, jobject oop_map_array, TRAPS) { - ResourceMark rm(THREAD); - objArrayOop argsArray = (objArrayOop) JNIHandles::resolve(args); - // Note this length does not include the iteration variable since it is replaced by the HSA workitemid - int argsArrayLength = argsArray->length(); - assert(THREAD->is_Java_thread(), "must be a JavaThread"); - - // We avoid HSAILAllocationInfo logic if kernel does not allocate - // in which case the num_tlabs passed in will be 0 - HSAILAllocationInfo* allocInfo = (num_tlabs == 0 ? NULL : new HSAILAllocationInfo(num_tlabs, dimX, allocBytesPerWorkitem)); - - // Reset the kernel arguments - _okra_clear_args(kernel); - - JavaThread* thread = (JavaThread*)THREAD; - HSAILDeoptimizationInfo* e; - if (UseHSAILDeoptimization) { - // get how many bytes per deopt save area are required - int saveAreaCounts = HSAILOopMapHelper::get_save_area_counts(oop_map_array); - int numSRegs = saveAreaCounts & 0xff; - int numDRegs = (saveAreaCounts >> 8) & 0xff; - int numStackSlots = (saveAreaCounts >> 16); - int bytesPerSaveArea = numSRegs * 4 + (numDRegs + numStackSlots) * 8; - - e = new (MAX_DEOPT_SLOTS, bytesPerSaveArea) HSAILDeoptimizationInfo(MAX_DEOPT_SLOTS, bytesPerSaveArea, dimX, allocInfo, oop_map_array); - // copy cur_tlab_infos - if (allocInfo != NULL) { - e->set_cur_tlabInfos(allocInfo->getCurTlabInfos()); - } - // set deopt info in thread so gc oops_do processing can find it - thread->set_gpu_hsail_deopt_info(e); - } - - // This object sets up the kernel arguments - HSAILKernelArguments hka((address) kernel, mh->signature(), argsArray, mh->is_static(), e); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] range=%d", dimX); - } - - // If any object passed was null, throw an exception here. Doing this - // means the kernel code can avoid null checks on the object parameters. - if (hka.getFirstNullParameterIndex() >= 0) { - char buf[64]; - sprintf(buf, "Null Kernel Parameter seen, Parameter Index: %d", hka.getFirstNullParameterIndex()); - thread->set_gpu_exception_bci(0); - thread->set_gpu_exception_method(mh()); - THROW_MSG_0(vmSymbols::java_lang_NullPointerException(), buf); - } - - // Run the kernel - jboolean success = false; - { - TraceTime t("execute kernel", TraceGPUInteraction); - graal_okra_range_t kernel_range = {0}; - - //in_kernel = 1; - // Run the kernel - kernel_range.dimension = 1; - kernel_range.global_size[0] = dimX; - success = _okra_execute_kernel(_device_context, kernel, &kernel_range); - //in_kernel = 0; - } - - // avoid HSAILAllocationInfo logic if kernel does not allocate - if (allocInfo != NULL) { - allocInfo->postKernelCleanup(); - } - - if (UseHSAILDeoptimization) { - // check if any workitem requested a deopt - int deoptcode = e->deopt_occurred(); - if (deoptcode != 1) { - if (deoptcode == 0) { - if (TraceGPUInteraction && _notice_safepoints != 0) { - tty->print_cr("[HSAIL] observed safepoint during kernel"); - } - } else { - // error condition detected in deopt code - char msg[200]; - sprintf(msg, "deopt error detected, slot for workitem %d was not empty", -1 * (deoptcode + 1)); - guarantee(deoptcode == 1, msg); - } - } else { - { - TraceTime t3("handle deoptimizing workitems", TraceGPUInteraction); - if (TraceGPUInteraction) { - tty->print_cr("deopt happened."); - HSAILKernelDeoptimization* pdeopt = e->get_deopt_save_state(0); - tty->print_cr("first deopter was workitem %d", pdeopt->workitem()); - } - - // Handle any deopting workitems. - int count_deoptimized = 0; - for (int k = 0; k < e->num_deopts(); k++) { - HSAILKernelDeoptimization* pdeopt = e->get_deopt_save_state(k); - - jint workitem = pdeopt->workitem(); - if (workitem != -1) { - int deoptId = pdeopt->pc_offset(); - HSAILFrame* hsailFrame = pdeopt->first_frame(); - - JavaValue result(T_VOID); - JavaCallArguments javaArgs; - javaArgs.set_alternative_target(nm); - javaArgs.push_int(deoptId); - javaArgs.push_long((jlong) hsailFrame); - - // Override the deoptimization action with Action_none until we decide - // how to handle the other actions. - int myActionReason = Deoptimization::make_trap_request(Deoptimization::trap_request_reason(pdeopt->reason()), Deoptimization::Action_none); - javaArgs.push_int(myActionReason); - javaArgs.push_oop((oop) NULL); - javaArgs.push_int(mh->size_of_parameters()); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] Deoptimizing to host for workitem=%d (slot=%d) with deoptId=%d, frame=" INTPTR_FORMAT ", actionAndReason=%d", workitem, k, deoptId, p2i(hsailFrame), myActionReason); - // show the $d registers or stack slots containing references - int maxOopBits = hsailFrame->num_d_regs() + hsailFrame->num_stack_slots(); - HSAILOopMapHelper oopMapHelper(oop_map_array); - int pc_offset = hsailFrame->pc_offset(); - for (int bit = 0; bit < maxOopBits; bit++) { - if (oopMapHelper.is_oop(pc_offset, bit)) { - if (bit < hsailFrame->num_d_regs()) { - // show $d reg oop - tty->print_cr(" oop $d%d = " PTR64_FORMAT, bit, hsailFrame->get_oop_for_bit(bit)); - } else { - // show stack slot oop - int stackOffset = (bit - hsailFrame->num_d_regs()) * 8; // 8 bytes per stack slot - tty->print_cr(" oop stk:%d = " PTR64_FORMAT, stackOffset, hsailFrame->get_oop_for_bit(bit)); - } - } - } - } - JavaCalls::call(&result, mh, &javaArgs, THREAD); - count_deoptimized++; - e->set_deopt_work_index(k + 1); - } - } - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] Deoptimizing to host completed for %d workitems", count_deoptimized); - } - } - } - // when we are done with the deopts, we don't need to oops_do anything - // in the saved state anymore - thread->set_gpu_hsail_deopt_info(NULL); - - // Handle any never_ran workitems if there were any - { - TraceTime t("handle never-rans ", TraceGPUInteraction); - int count_never_ran = 0; - bool handleNeverRansHere = true; - // turn off verbose trace stuff for javacall arg setup - bool savedTraceGPUInteraction = TraceGPUInteraction; - TraceGPUInteraction = false; - jboolean* never_ran_array = e->never_ran_array(); - if (handleNeverRansHere) { - for (int k = 0; k < dimX; k++) { - if (never_ran_array[k]) { - // run it as a javaCall - KlassHandle methKlass = mh->method_holder(); - Thread* THREAD = Thread::current(); - JavaValue result(T_VOID); - // Add the iteration variable to the HSA args length - JavaCallArguments javaArgs(argsArrayLength + 1); - // re-resolve the args_handle here - objArrayOop resolvedArgsArray = (objArrayOop) JNIHandles::resolve(args); - - // This object sets up the javaCall arguments. The way - // argsArray is set up, this should work for instance - // methods as well (the receiver will be the first oop pushed) - HSAILJavaCallArguments hjca(&javaArgs, k, mh->signature(), resolvedArgsArray, mh->is_static()); - if (mh->is_static()) { - JavaCalls::call_static(&result, methKlass, mh->name(), mh->signature(), &javaArgs, THREAD); - } else { - JavaCalls::call_virtual(&result, methKlass, mh->name(), mh->signature(), &javaArgs, THREAD); - } - count_never_ran++; - } - } - TraceGPUInteraction = savedTraceGPUInteraction; - if (TraceGPUInteraction && (count_never_ran > 0)) { - tty->print_cr("%d workitems never ran, have been run via JavaCall", count_never_ran); - showRanges(never_ran_array, dimX); - } - } // end of never-ran handling - } - - delete e; - delete allocInfo; - } - return success; -} - -GPU_ENTRY(jlong, Hsail::generate_kernel, (JNIEnv* env, jclass, jbyteArray code_handle, jstring name_handle)) - guarantee(_okra_create_kernel != NULL, "[HSAIL] Okra not linked"); - ResourceMark rm; - jsize name_len = env->GetStringLength(name_handle); - jsize code_len = env->GetArrayLength(code_handle); - - char* name = NEW_RESOURCE_ARRAY(char, name_len + 1); - unsigned char* code = NEW_RESOURCE_ARRAY(unsigned char, code_len + 1); - - code[code_len] = 0; - name[name_len] = 0; - - env->GetByteArrayRegion(code_handle, 0, code_len, (jbyte*) code); - env->GetStringUTFRegion(name_handle, 0, name_len, name); - - // The kernel entrypoint is always run for the time being - const char* entryPointName = "&run"; - jlong okra_kernel; - { - TraceTime t("generate kernel ", TraceGPUInteraction); - jint okra_status = _okra_create_kernel(_device_context, code, entryPointName, (void**)&okra_kernel); - guarantee(okra_status==0, "_okra_create_kernel failed"); - } - return (jlong) okra_kernel; -GPU_END - -#if defined(LINUX) -static const char* okra_library_name = "libokra_x86_64.so"; -#elif defined(_WINDOWS) -static char const* okra_library_name = "okra_x86_64.dll"; -#else -static char const* okra_library_name = NULL; -#endif - -#define STRINGIFY(x) #x - -#define LOOKUP_OKRA_FUNCTION(name, alias) \ - _##alias = \ - CAST_TO_FN_PTR(alias##_func_t, os::dll_lookup(okra_lib_handle, STRINGIFY(name))); \ - if (_##alias == NULL) { \ - tty->print_cr("[HSAIL] ***** Error: Failed to lookup %s in %s, wrong version of OKRA?", STRINGIFY(name), okra_library_name); \ - return false; \ - } \ - -GPU_ENTRY(jboolean, Hsail::initialize, (JNIEnv* env, jclass)) - if (okra_library_name == NULL) { - if (TraceGPUInteraction) { - tty->print_cr("Unsupported HSAIL platform"); - } - return false; - } - - // here we know we have a valid okra_library_name to try to load - char ebuf[O_BUFLEN]; - char* okra_lib_name_from_env_var = getenv("_OKRA_SIM_LIB_PATH_"); - if (okra_lib_name_from_env_var != NULL) { - okra_library_name = okra_lib_name_from_env_var; - } - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] library is %s", okra_library_name); - } - void* okra_lib_handle = NULL; -#if defined(LINUX) - // Check first if the Okra library is already loaded. - // TODO: Figure out how to do this on other OSes. - okra_lib_handle = ::dlopen(okra_library_name, RTLD_LAZY | RTLD_NOLOAD); -#endif - // If Okra library is not already loaded, load it here - if (okra_lib_handle == NULL) { - okra_lib_handle = os::dll_load(okra_library_name, ebuf, O_BUFLEN); - } - if (okra_lib_handle == NULL) { - // Unable to open Okra library - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] library load failed."); - } - return false; - } - - guarantee(_okra_get_context == NULL, "cannot repeat GPU initialization"); - - // At this point we know okra_lib_handle is valid whether we loaded - // here or earlier. In either case, we can lookup the functions. - LOOKUP_OKRA_FUNCTION(okra_get_context, okra_get_context); - LOOKUP_OKRA_FUNCTION(okra_create_kernel, okra_create_kernel); - LOOKUP_OKRA_FUNCTION(okra_push_pointer, okra_push_pointer); - LOOKUP_OKRA_FUNCTION(okra_push_boolean, okra_push_boolean); - LOOKUP_OKRA_FUNCTION(okra_push_byte, okra_push_byte); - LOOKUP_OKRA_FUNCTION(okra_push_double, okra_push_double); - LOOKUP_OKRA_FUNCTION(okra_push_float, okra_push_float); - LOOKUP_OKRA_FUNCTION(okra_push_int, okra_push_int); - LOOKUP_OKRA_FUNCTION(okra_push_long, okra_push_long); - LOOKUP_OKRA_FUNCTION(okra_execute_kernel, okra_execute_kernel); - LOOKUP_OKRA_FUNCTION(okra_clear_args, okra_clear_args); - LOOKUP_OKRA_FUNCTION(okra_dispose_kernel, okra_dispose_kernel); - LOOKUP_OKRA_FUNCTION(okra_dispose_context, okra_dispose_context); - // if we made it this far, real success - - Gpu::initialized_gpu(new Hsail()); - - // There is 1 context per process - jint result = _okra_get_context(&_device_context); - guarantee(result==0, "get context failed"); - - return true; -GPU_END - - -bool Hsail::register_natives(JNIEnv* env) { - jclass klass = env->FindClass("com/oracle/graal/hotspot/hsail/HSAILHotSpotBackend"); - if (klass == NULL) { - if (TraceGPUInteraction) { - tty->print_cr("HSAILHotSpotBackend class not found"); - } - return false; - } - jint status = env->RegisterNatives(klass, HSAIL_methods, sizeof(HSAIL_methods) / sizeof(JNINativeMethod)); - if (status != JNI_OK) { - if (TraceGPUInteraction) { - tty->print_cr("Error registering natives for HSAILHotSpotBackend: %d", status); - } - return false; - } - return true; -} - - -void Hsail::HSAILDeoptimizationInfo::oops_do(OopClosure* f) { - int unprocessed_deopts = num_deopts() - deopt_work_index(); - if (TraceGPUInteraction) { - tty->print_cr("HSAILDeoptimizationInfo::oops_do deopt_occurred=%d, total_deopts=%d, unprocessed_deopts=%d, oop_map_array=" INTPTR_FORMAT, _deopt_occurred, num_deopts(), unprocessed_deopts, p2i(_oop_map_array)); - } - if (num_deopts() == 0 || unprocessed_deopts <= 0) { - return; // nothing to do - } - HSAILOopMapHelper oopMapHelper(_oop_map_array); - oopMapHelper.resolve_arrays(); // resolve once before processing - - // go thru the unprocessed deopt frames, finding each oop and applying the closre - for (int k = deopt_work_index(); k < num_deopts(); k++) { - HSAILKernelDeoptimization* pdeopt = get_deopt_save_state(k); - assert (pdeopt->workitem() >= 0, "bad workitem in deopt"); - if (TraceGPUInteraction) { - tty->print_cr(" deopt %d, workitem %d, pc %d", k, pdeopt->workitem(), pdeopt->pc_offset()); - } - HSAILFrame* hsailFrame = pdeopt->first_frame(); - hsailFrame->oops_do(f, &oopMapHelper); - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/gpu_hsail.hpp --- a/src/gpu/hsail/vm/gpu_hsail.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,259 +0,0 @@ -/* - * 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. - * - */ - -#ifndef GPU_HSAIL_VM_GPU_HSAIL_HPP -#define GPU_HSAIL_VM_GPU_HSAIL_HPP - -#include "runtime/gpu.hpp" -#include "utilities/exceptions.hpp" -#include "graal/graalEnv.hpp" -#include "gpu_hsail_OopMapHelper.hpp" -#include "gpu_hsail_Frame.hpp" -#include "gpu_hsail_Tlab.hpp" - -struct HSAILKernelStats { - int _dispatches; - int _deopts; - int _overflows; - bool _changeSeen; - -public: - HSAILKernelStats() { - _dispatches = _deopts = _overflows = 0; - _changeSeen = false; - } - - void incDeopts() { - _deopts++; - _changeSeen = true; - } - void incOverflows() { - _overflows++; - _changeSeen = true; - } - - void finishDispatch() { - _dispatches++; - if (_changeSeen) { - // print(); - _changeSeen = false; - } - } - - void print() { - tty->print_cr("Disp=%d, Deopts=%d, Ovflows=%d", _dispatches, _deopts, _overflows); - } -}; - -class Hsail : public Gpu { - - public: - class HSAILKernelDeoptimization VALUE_OBJ_CLASS_SPEC { - friend class VMStructs; - private: - // TODO: separate workitemid and actionAndReason out - // since they are there only once even if there are multiple frames - // for now, though we only ever have one hsail frame - jint _workitemid; - jint _actionAndReason; - // the first (innermost) "hsail frame" starts after the above fields - - public: - inline jint workitem() { return _workitemid; } - inline jint reason() { return _actionAndReason; } - inline jint pc_offset() { return first_frame()->pc_offset(); } - inline HSAILFrame* first_frame() { - // starts after the "header" fields - return (HSAILFrame*) (((jbyte*) this) + sizeof(*this)); - } - }; - -// 8 compute units * 40 waves per cu * wavesize 64 -// TODO: query the device to get this number -#define MAX_DEOPT_SLOTS (8 * 40 * 64) - - - class HSAILDeoptimizationInfo : public CHeapObj { - friend class VMStructs; - private: - jint* _notice_safepoints; - jint _deopt_occurred; - jint _deopt_next_index; - jint _num_slots; - jint _deopt_span; - jint _deopt_work_index; // how far we are in processing the deopts - HSAILTlabInfo** _cur_tlab_info; // copy of what was in the HSAILAllocationInfo, to avoid an extra indirection - HSAILAllocationInfo* _alloc_info; - char _ignore; - jobject _oop_map_array; - // keep a pointer last so save area following it is word aligned - jboolean* _never_ran_array; - - public: - // static HSAILKernelStats kernelStats; - HSAILKernelDeoptimization _deopt_save_states[1]; // number and size of these can vary per kernel - - static inline size_t hdr_size() { - return sizeof(HSAILDeoptimizationInfo); - } - - inline jbyte* save_area_start() { - return (jbyte*) (this) + hdr_size(); - } - - inline HSAILDeoptimizationInfo(int numSlots, int bytesPerSaveArea, int dimX, HSAILAllocationInfo* allocInfo, jobject oop_map_array) { - _notice_safepoints = &Hsail::_notice_safepoints; - _deopt_occurred = 0; - _deopt_next_index = 0; - _deopt_work_index = 0; - _num_slots = numSlots; - _never_ran_array = NEW_C_HEAP_ARRAY(jboolean, dimX, mtInternal); - memset(_never_ran_array, 0, dimX * sizeof(jboolean)); - _alloc_info = allocInfo; - _oop_map_array = oop_map_array; - _deopt_span = sizeof(HSAILKernelDeoptimization) + sizeof(HSAILFrame) + bytesPerSaveArea; - if (TraceGPUInteraction) { - tty->print_cr("HSAILDeoptimizationInfo allocated, %d slots of size %d total size = " SIZE_FORMAT_HEX " bytes", - _num_slots, _deopt_span, (_num_slots * _deopt_span + sizeof(HSAILDeoptimizationInfo))); - } - } - - inline ~HSAILDeoptimizationInfo() { - FREE_C_HEAP_ARRAY(jboolean, _never_ran_array, mtInternal); - } - - inline jint deopt_occurred() { - return _deopt_occurred; - } - inline jint num_deopts() { return _deopt_next_index; } - inline jboolean* never_ran_array() { return _never_ran_array; } - inline jint num_slots() {return _num_slots;} - inline void set_deopt_work_index(int val) { _deopt_work_index = val; } - inline jint deopt_work_index() { return _deopt_work_index; } - - inline HSAILKernelDeoptimization* get_deopt_save_state(int slot) { - // use _deopt_span to index into _deopt_states - return (HSAILKernelDeoptimization*) (save_area_start() + _deopt_span * slot); - } - - void set_cur_tlabInfos(HSAILTlabInfo** ptlabInfos) { - _cur_tlab_info = ptlabInfos; - } - - void oops_do(OopClosure* f); - - void* operator new (size_t hdrSize, int numSlots, int bytesPerSaveArea) { - assert(hdrSize <= hdr_size(), ""); - size_t totalSizeBytes = hdr_size() + numSlots * (sizeof(HSAILKernelDeoptimization) + sizeof(HSAILFrame) + bytesPerSaveArea); - return NEW_C_HEAP_ARRAY(char, totalSizeBytes, mtInternal); - } - - void operator delete (void* ptr) { - FREE_C_HEAP_ARRAY(char, ptr, mtInternal); - } - }; - -private: - - static JNINativeMethod HSAIL_methods[]; - - // static native boolean initialize(); - JNIEXPORT static jboolean JNICALL initialize(JNIEnv* env, jclass); - - // static native long generateKernel(byte[] targetCode, String name); - JNIEXPORT static jlong JNICALL generate_kernel(JNIEnv* env, jclass, jbyteArray code_handle, jstring name_handle); - - // static native boolean executeKernel0(HotSpotInstalledCode kernel, int jobSize, Object[] args); - JNIEXPORT static jboolean JNICALL execute_kernel_void_1d(JNIEnv* env, jclass, jobject hotspotInstalledCode, jint dimX, jobject args, - jint num_tlabs, int allocBytesPerWorkitem, jobject oop_map_array); - - static jboolean execute_kernel_void_1d_internal(address kernel, int dimX, jobject args, methodHandle& mh, nmethod* nm, - jint num_tlabs, int allocBytesPerWorkitem, jobject oop_map_array, TRAPS); - - static GraalEnv::CodeInstallResult install_code(Handle& compiled_code, CodeBlob*& cb, Handle installed_code, Handle triggered_deoptimizations); - -public: - - // Registers the implementations for the native methods in HSAILHotSpotBackend - static bool register_natives(JNIEnv* env); - - virtual const char* name() { return "HSAIL"; } - - virtual void notice_safepoints(); - virtual void ignore_safepoints(); - -#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) - typedef unsigned long long CUdeviceptr; -#else - typedef unsigned int CUdeviceptr; -#endif - -private: - - /* - * Kernel launch options from okra.h - */ - typedef struct graal_okra_range_s { - uint32_t dimension; //max value is 3 - uint32_t global_size[3]; - uint32_t group_size[3]; - uint32_t reserved; //For future use - } graal_okra_range_t; - - typedef jint (*okra_get_context_func_t)(void**); - typedef jint (*okra_create_kernel_func_t)(void*, unsigned char*, const char*, void**); - typedef jint (*okra_push_pointer_func_t)(void*, void*); - typedef jint (*okra_push_boolean_func_t)(void*, jboolean); - typedef jint (*okra_push_byte_func_t)(void*, jbyte); - typedef jint (*okra_push_double_func_t)(void*, jdouble); - typedef jint (*okra_push_float_func_t)(void*, jfloat); - typedef jint (*okra_push_int_func_t)(void*, jint); - typedef jint (*okra_push_long_func_t)(void*, jlong); - typedef jint (*okra_execute_kernel_func_t)(void*, void*, graal_okra_range_t*); - typedef jint (*okra_clear_args_func_t)(void*); - typedef jint (*okra_dispose_kernel_func_t)(void*); - typedef jint (*okra_dispose_context_func_t)(void*); - -public: - static okra_get_context_func_t _okra_get_context; - static okra_create_kernel_func_t _okra_create_kernel; - static okra_push_pointer_func_t _okra_push_pointer; - static okra_push_boolean_func_t _okra_push_boolean; - static okra_push_byte_func_t _okra_push_byte; - static okra_push_double_func_t _okra_push_double; - static okra_push_float_func_t _okra_push_float; - static okra_push_int_func_t _okra_push_int; - static okra_push_long_func_t _okra_push_long; - static okra_execute_kernel_func_t _okra_execute_kernel; - static okra_clear_args_func_t _okra_clear_args; - static okra_dispose_kernel_func_t _okra_dispose_kernel; - static okra_dispose_context_func_t _okra_dispose_context; - -protected: - static void* _device_context; - - // true if safepoints are activated - static jint _notice_safepoints; -}; -#endif // GPU_HSAIL_VM_GPU_HSAIL_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/gpu_hsail_Frame.hpp --- a/src/gpu/hsail/vm/gpu_hsail_Frame.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2014, 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. - * - */ - -#ifndef GPU_HSAIL_VM_GPU_HSAIL_FRAME_HPP -#define GPU_HSAIL_VM_GPU_HSAIL_FRAME_HPP - -#include "graal/graalEnv.hpp" -#include "code/debugInfo.hpp" -#include "code/location.hpp" - -class HSAILFrame VALUE_OBJ_CLASS_SPEC { - friend class VMStructs; -private: - jint _pc_offset; // The HSAIL "pc_offset" where the exception happens - jbyte _num_s_regs; - jbyte _num_d_regs; - jshort _num_stack_slots; - - jbyte* data_start() {return (jbyte*) this + sizeof(*this); } - int sreg_ofst_start() { return 0; } - int dreg_ofst_start() { return sreg_ofst_start() + num_s_regs() * sizeof(jint); } - int stackslot_ofst_start() { return dreg_ofst_start() + num_d_regs() * sizeof(jlong); } - - int sreg_ofst(int idx) { - assert(idx >= 0 && idx < num_s_regs(), "bad sreg index"); - return sreg_ofst_start() + idx * sizeof(jint); - } - - int dreg_ofst(int idx) { - assert(idx >= 0 && idx < num_d_regs(), "bad dreg index"); - return dreg_ofst_start() + idx * sizeof(jlong); - } - - int stackslot_ofst(int stackOffset) { - assert(stackOffset >= 0 && (unsigned int) stackOffset < num_stack_slots() * sizeof(jlong), "bad stackoffset"); - return stackslot_ofst_start() + stackOffset; - } - - // the _ptr versions just return a pointer to the indicated d reg or stackslot64 - // some of these are used for oops_do processing - jint* get_s_reg_ptr(int idx) { - return((jint*) (data_start() + sreg_ofst(idx))); - } - - jlong* get_d_reg_ptr(int idx) { - return((jlong*) (data_start() + dreg_ofst(idx))); - } - - jlong* get_stackslot64_ptr(int stackOffset) { - return((jlong*) (data_start() + stackslot_ofst(stackOffset))); - } - - jint* get_stackslot32_ptr(int stackOffset) { - return((jint*) (data_start() + stackslot_ofst(stackOffset))); - } - - void* get_oop_ptr_for_bit(int bit) { - void* oop_ptr; - if (bit < num_d_regs()) { - // d register - oop_ptr = (void*) get_d_reg_ptr(bit); - } else { - // stack slot - int stackOffset = (bit - num_d_regs()) * 8; // 8 bytes per stack slot - oop_ptr = (void*) get_stackslot64_ptr(stackOffset); - } - return oop_ptr; - } - -public: - // Accessors - jint pc_offset() { return _pc_offset; } - jint num_s_regs() {return _num_s_regs; } - jint num_d_regs() {return _num_d_regs; } - jint num_stack_slots() {return _num_stack_slots; } - - jlong get_oop_for_bit(int bit) { - return * (jlong *) get_oop_ptr_for_bit(bit); - } - - // do the oops from this frame - void oops_do(OopClosure* f, HSAILOopMapHelper* oopMapHelper) { - int oops_per_deopt = num_d_regs() + num_stack_slots(); - - // handle the dregister and stackSlot based oops - for (int bit = 0; bit < oops_per_deopt; bit++) { - if (oopMapHelper->is_oop(pc_offset(), bit)) { - void* oop_ptr = get_oop_ptr_for_bit(bit); - // the oops we are dealing with here in the hsailFrame are always uncompressed - oop old_oop = oopDesc::load_heap_oop((oop *)oop_ptr); - f->do_oop((oop*) oop_ptr); - if (TraceGPUInteraction) { - oop new_oop = oopDesc::load_heap_oop((oop *)oop_ptr); - tty->print_cr("bit=%d, oop_ptr=%p, old=%p, new=%p", bit, oop_ptr, (void *)old_oop, (void *)new_oop); - } - } - } - } -}; - -#endif // GPU_HSAIL_VM_GPU_HSAIL_FRAME_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/gpu_hsail_OopMapHelper.hpp --- a/src/gpu/hsail/vm/gpu_hsail_OopMapHelper.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2014, 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. - * - */ - -#ifndef GPU_HSAIL_VM_GPU_HSAIL_OOPMAPHELPER_HPP -#define GPU_HSAIL_VM_GPU_HSAIL_OOPMAPHELPER_HPP - -#include "graal/graalEnv.hpp" -#include "code/debugInfo.hpp" -#include "code/location.hpp" - -// Takes the jobject for the array of ints created by the java side -// and decodes the information based on pc_offset to find oops -class HSAILOopMapHelper : public StackObj { -private: - jobject _oop_map_array_jobject; - typeArrayOop _oop_map_array; - int _last_pcoffset; - int _last_idx; - - enum { - SAVEAREACOUNTS_OFST=0, - SPAN_OFST=1, - HEADERSIZE=2 - }; - int mapPcOffsetToIndex(int pcOffset) { - if (pcOffset == _last_pcoffset) { - return _last_idx; - } - int span = _oop_map_array->int_at(SPAN_OFST); - for (int idx = HEADERSIZE; idx < _oop_map_array->length(); idx += span) { - int ofst = _oop_map_array->int_at(idx); - if (ofst == pcOffset) { - _last_pcoffset = pcOffset; - _last_idx = idx + 1; - return _last_idx; - } - } - ShouldNotReachHere(); - return -1; - } - -public: - HSAILOopMapHelper(jobject oop_map_array_jobject) { - _oop_map_array_jobject = oop_map_array_jobject; - _last_pcoffset = -1; - resolve_arrays(); - } - - void resolve_arrays() { - _oop_map_array = (typeArrayOop) JNIHandles::resolve(_oop_map_array_jobject); - } - - static int get_save_area_counts(jobject oop_map_array_jobject) { - typeArrayOop oop_map_array_resolved = (typeArrayOop) JNIHandles::resolve(oop_map_array_jobject); - return oop_map_array_resolved->int_at(SAVEAREACOUNTS_OFST); - } - - bool is_oop(int pcOffset, int bit){ - int bits_int_idx = mapPcOffsetToIndex(pcOffset) + (bit / 32); - int bitpos = bit % 32; - int bits = _oop_map_array->int_at(bits_int_idx); - return ((bits & (1 << bitpos)) != 0); - } - -}; - -#endif // GPU_HSAIL_VM_GPU_HSAIL_OOPMAPHELPER_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/gpu_hsail_Tlab.hpp --- a/src/gpu/hsail/vm/gpu_hsail_Tlab.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,255 +0,0 @@ -/* - * Copyright (c) 2014, 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. - * - */ - -#ifndef GPU_HSAIL_VM_GPU_HSAIL_TLAB_HPP -#define GPU_HSAIL_VM_GPU_HSAIL_TLAB_HPP - -#include "graal/graalEnv.hpp" -#include "code/debugInfo.hpp" -#include "code/location.hpp" -#include "gpu_hsail.hpp" - -class HSAILAllocationInfo; - -class HSAILTlabInfo VALUE_OBJ_CLASS_SPEC { - friend class VMStructs; -public: - // uses only the necessary fields from a full TLAB - HeapWord* _start; - HeapWord* _top; - HeapWord* _end; - HeapWord* _last_good_top; - HeapWord* _original_top; - ThreadLocalAllocBuffer* _tlab; // tlab associated with this tlabInfo - HSAILAllocationInfo* _alloc_info; // same as what is in HSAILDeoptimizationInfo - - // Accessors - HeapWord* start() { return _start; } - HeapWord* top() { return _top; } - HeapWord* end() { return _end; } - HeapWord* last_good_top() { return _last_good_top; } - HeapWord* original_top() { return _original_top; } - ThreadLocalAllocBuffer* tlab() { return _tlab; } - void initialize(HeapWord* start, HeapWord* top, HeapWord* end, ThreadLocalAllocBuffer* tlab, HSAILAllocationInfo* allocInfo) { - _start = start; - _top = _original_top = top; - _end = end; - _tlab = tlab; - _alloc_info = allocInfo; - } -}; - - -class HSAILAllocationInfo : public CHeapObj { - friend class VMStructs; -private: - jint _num_tlabs; - size_t _tlab_align_reserve_bytes; // filled in from ThreadLocalAllocBuffer::alignment_reserve_in_bytes() - HSAILTlabInfo** _cur_tlab_infos; // array of current tlab info pointers, one per num_tlabs - HSAILTlabInfo* _tlab_infos_pool_start; // pool for new tlab_infos - HSAILTlabInfo* _tlab_infos_pool_next; // where next will be allocated from - HSAILTlabInfo* _tlab_infos_pool_end; // where next will be allocated from - -public: - HSAILAllocationInfo(jint num_tlabs, int dimX, int allocBytesPerWorkitem) { - _num_tlabs = num_tlabs; - // if this thread doesn't have gpu_hsail_tlabs allocated yet, do so now - JavaThread* thread = JavaThread::current(); - if (thread->get_gpu_hsail_tlabs_count() == 0) { - thread->initialize_gpu_hsail_tlabs(num_tlabs); - if (TraceGPUInteraction) { - for (int i = 0; i < num_tlabs; i++) { - ThreadLocalAllocBuffer* tlab = thread->get_gpu_hsail_tlab_at(i); - tty->print("initialized gpu_hsail_tlab %d at %p -> ", i, tlab); - printTlabInfoFromThread(tlab); - } - } - } - - // Compute max_tlab_infos based on amount of free heap space - size_t max_tlab_infos; - { - ThreadLocalAllocBuffer* tlab = &thread->tlab(); - size_t new_tlab_size = tlab->compute_size(0); - size_t heap_bytes_free = Universe::heap()->unsafe_max_tlab_alloc(thread); - if (new_tlab_size != 0) { - max_tlab_infos = MIN2(heap_bytes_free / new_tlab_size, (size_t)(64 * _num_tlabs)); - } else { - max_tlab_infos = 8 * _num_tlabs; // an arbitrary multiple - } - if (TraceGPUInteraction) { - tty->print_cr("heapFree = " SIZE_FORMAT ", newTlabSize=" SIZE_FORMAT ", tlabInfos allocated = " SIZE_FORMAT, - heap_bytes_free, new_tlab_size, max_tlab_infos); - } - } - - _cur_tlab_infos = NEW_C_HEAP_ARRAY(HSAILTlabInfo*, _num_tlabs, mtInternal); - _tlab_infos_pool_start = NEW_C_HEAP_ARRAY(HSAILTlabInfo, max_tlab_infos, mtInternal); - _tlab_infos_pool_next = &_tlab_infos_pool_start[_num_tlabs]; - _tlab_infos_pool_end = &_tlab_infos_pool_start[max_tlab_infos]; - _tlab_align_reserve_bytes = ThreadLocalAllocBuffer::alignment_reserve_in_bytes(); - - // we will fill the first N tlabInfos from the gpu_hsail_tlabs - for (int i = 0; i < _num_tlabs; i++) { - ThreadLocalAllocBuffer* tlab = thread->get_gpu_hsail_tlab_at(i); - if (TraceGPUInteraction) { - tty->print("gpu_hsail_tlab %d at %p -> ", i, tlab); - printTlabInfoFromThread(tlab); - } - - // Here we try to get a new tlab if current one is null. Note: - // eventually we may want to test if the size is too small based - // on some heuristic where we see how much this kernel tends to - // allocate, but for now we can just let it overflow and let the - // GPU allocate new tlabs. Actually, if we can't prime a tlab - // here, it might make sense to do a gc now rather than to start - // the kernel and have it deoptimize. How to do that? - if (tlab->end() == NULL) { - bool success = getNewGpuHsailTlab(tlab); - if (TraceGPUInteraction) { - if (success) { - tty->print("gpu_hsail_tlab %d, refilled tlab, -> ", i); - printTlabInfoFromThread(tlab); - } else { - tty->print("gpu_hsail_tlab %d, could not refill tlab, left as ", i); - printTlabInfoFromThread(tlab); - } - } - } - - // extract the necessary tlab fields into a TlabInfo record - HSAILTlabInfo* pTlabInfo = &_tlab_infos_pool_start[i]; - _cur_tlab_infos[i] = pTlabInfo; - pTlabInfo->initialize(tlab->start(), tlab->top(), tlab->end(), tlab, this); - } - } - - ~HSAILAllocationInfo() { - FREE_C_HEAP_ARRAY(HSAILTlabInfo*, _cur_tlab_infos, mtInternal); - FREE_C_HEAP_ARRAY(HSAILTlabInfo, _tlab_infos_pool_start, mtInternal); - } - - void postKernelCleanup() { - // go thru all the tlabInfos, fix up any tlab tops that overflowed - // complete the tlabs if they overflowed - // update the gpu_hsail_tlabs when appropriate - bool anyOverflows = false; - size_t bytesAllocated = 0; - // if there was an overflow in allocating tlabInfos, correct it here - if (_tlab_infos_pool_next > _tlab_infos_pool_end) { - if (TraceGPUInteraction) { - int overflowAmount = _tlab_infos_pool_next - _tlab_infos_pool_end; - tty->print_cr("tlabInfo allocation overflowed by %d units", overflowAmount); - } - _tlab_infos_pool_next = _tlab_infos_pool_end; - } - for (HSAILTlabInfo* tlabInfo = _tlab_infos_pool_start; tlabInfo < _tlab_infos_pool_next; tlabInfo++) { - if (TraceGPUInteraction) { - tty->print_cr("postprocess tlabInfo %p, start=%p, top=%p, end=%p, last_good_top=%p", tlabInfo, - tlabInfo->start(), tlabInfo->top(), tlabInfo->end(), tlabInfo->last_good_top()); - } - ThreadLocalAllocBuffer* tlab = tlabInfo->tlab(); - bool overflowed = false; - // if a tlabInfo has NULL fields, i.e. we could not prime it on entry, - // or we could not get a tlab from the gpu, so ignore tlabInfo here - if (tlabInfo->start() != NULL) { - if (tlabInfo->top() > tlabInfo->end()) { - anyOverflows = true; - overflowed = true; - if (TraceGPUInteraction) { - long overflowAmount = (long) tlabInfo->top() - (long) tlabInfo->last_good_top(); - tty->print_cr("tlabInfo %p (tlab = %p) overflowed by %ld bytes, setting last good top to %p", tlabInfo, tlab, overflowAmount, tlabInfo->last_good_top()); - } - tlabInfo->_top = tlabInfo->last_good_top(); - } - - // fill the gpu_hsail_tlab with the tlabInfo information - // we do this even if it will get overwritten by a later tlabinfo - // because it helps with tlab statistics for that tlab - tlab->fill(tlabInfo->start(), tlabInfo->top(), (tlabInfo->end() - tlabInfo->start()) + tlab->alignment_reserve()); - - // if there was an overflow, make it parsable with retire = true - if (overflowed) { - tlab->make_parsable(true); - } - - size_t delta = (long)(tlabInfo->top()) - (long)(tlabInfo->original_top()); - if (TraceGPUInteraction) { - tty->print_cr(SIZE_FORMAT " bytes were allocated by tlabInfo %p (start %p, top %p, end %p", - delta, tlabInfo, tlabInfo->start(), tlabInfo->top(), tlabInfo->end()); - } - bytesAllocated += delta; - } - } - if (TraceGPUInteraction) { - tty->print_cr(SIZE_FORMAT" total bytes were allocated in this kernel", bytesAllocated); - } - if (anyOverflows) { - // Hsail::kernelStats.incOverflows(); - } - } - - HSAILTlabInfo** getCurTlabInfos() { - return _cur_tlab_infos; - } - -private: - // fill and retire old tlab and get a new one - // if we can't get one, no problem someone will eventually do a gc - bool getNewGpuHsailTlab(ThreadLocalAllocBuffer* tlab) { - - tlab->clear_before_allocation(); // fill and retire old tlab (will also check for null) - - // get a size for a new tlab that is based on the desired_size - size_t new_tlab_size = tlab->compute_size(0); - if (new_tlab_size == 0) return false; - - HeapWord* tlab_start = Universe::heap()->allocate_new_tlab(new_tlab_size); - if (tlab_start == NULL) return false; - - // ..and clear it if required - if (ZeroTLAB) { - Copy::zero_to_words(tlab_start, new_tlab_size); - } - // and init the tlab pointers - tlab->fill(tlab_start, tlab_start, new_tlab_size); - return true; - } - - void printTlabInfoFromThread (ThreadLocalAllocBuffer* tlab) { - HeapWord* start = tlab->start(); - HeapWord* top = tlab->top(); - HeapWord* end = tlab->end(); - // sizes are in bytes - size_t tlabFree = tlab->free() * HeapWordSize; - size_t tlabUsed = tlab->used() * HeapWordSize; - size_t tlabSize = tlabFree + tlabUsed; - double freePct = 100.0 * (double) tlabFree/(double) tlabSize; - tty->print_cr("(%p, %p, %p), siz=" SIZE_FORMAT ", free=" SIZE_FORMAT " (%f%%)", - start, top, end, tlabSize, tlabFree, freePct); - } - -}; - -#endif // GPU_HSAIL_VM_GPU_HSAIL_TLAB_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/hsailArgumentsBase.cpp --- a/src/gpu/hsail/vm/hsailArgumentsBase.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -/* - * 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. - * - */ - -#include "precompiled.hpp" -#include "hsailArgumentsBase.hpp" -#include "runtime/javaCalls.hpp" - - -// Get next java argument -oop HSAILArgumentsBase::next_arg(BasicType expectedType) { - assert(_index < _args->length(), "out of bounds"); - - oop arg = ((objArrayOop) (_args))->obj_at(_index++); - assert(expectedType == T_OBJECT || - java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch"); - - return arg; -} - -void HSAILArgumentsBase::collectArgs() { - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, sig:%s args length=%d", argsBuilderName(), _signature->as_C_string(), _length); - } - if (!_is_static) { - // First object in args should be 'this' - oop arg = _args->obj_at(_index++); - assert(arg->is_instance() && (!arg->is_array()), "First arg should be 'this'"); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s, instance method, this " INTPTR_FORMAT ", is a %s", argsBuilderName(), p2i(arg), arg->klass()->external_name()); - } - pushObject(arg); - } else { - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s, static method", argsBuilderName()); - } - } - // Iterate over the entire signature - iterate(); - - pushTrailingArgs(); -} - -void HSAILArgumentsBase::do_bool() { - // Get the boxed value - oop arg = _args->obj_at(_index++); - assert(java_lang_boxing_object::is_instance(arg, T_BOOLEAN), "arg type mismatch"); - - jvalue jValue; - java_lang_boxing_object::get_value(arg, &jValue); - - pushBool(jValue.z); -} - -void HSAILArgumentsBase::do_byte() { - // Get the boxed value - oop arg = _args->obj_at(_index++); - assert(java_lang_boxing_object::is_instance(arg, T_BYTE), "arg type mismatch"); - - jvalue jValue; - java_lang_boxing_object::get_value(arg, &jValue); - - pushByte(jValue.b); -} - -void HSAILArgumentsBase::do_double() { - // Get the boxed value - oop arg = _args->obj_at(_index++); - assert(java_lang_boxing_object::is_instance(arg, T_DOUBLE), "arg type mismatch"); - - jvalue jValue; - java_lang_boxing_object::get_value(arg, &jValue); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::do_double, _index=%d, value = %e", argsBuilderName(), _index - 1, jValue.d); - } - pushDouble(jValue.d); -} - -void HSAILArgumentsBase::do_float() { - // Get the boxed value - oop arg = _args->obj_at(_index++); - assert(java_lang_boxing_object::is_instance(arg, T_FLOAT), "arg type mismatch"); - - jvalue jValue; - java_lang_boxing_object::get_value(arg, &jValue); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::do_float, _index=%d, value = %f", argsBuilderName(), _index - 1, jValue.f); - } - pushFloat(jValue.f); -} - -void HSAILArgumentsBase::do_int() { - // If the last parameter is an int, it is handled in a special way - // For kernel arguments we don't pass it since we use the HSAIL workitemid in place of that int value - // For javaCall arguments we pass the actual workitemid - if (isLastParameter()) { - handleFinalIntParameter(); - return; - } - - // not the final int parameter, Get the boxed int - oop arg = _args->obj_at(_index++); - assert(java_lang_boxing_object::is_instance(arg, T_INT), "arg type mismatch"); - - jvalue jValue; - java_lang_boxing_object::get_value(arg, &jValue); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::do_int, _index=%d, value = %d", argsBuilderName(), _index - 1, jValue.i); - } - - pushInt(jValue.i); -} - -void HSAILArgumentsBase::do_long() { - // Get the boxed value - oop arg = _args->obj_at(_index++); - assert(java_lang_boxing_object::is_instance(arg, T_LONG), "arg type mismatch"); - - jvalue jValue; - java_lang_boxing_object::get_value(arg, &jValue); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::do_long, _index=%d, value = " JLONG_FORMAT, argsBuilderName(), _index - 1, jValue.j); - } - - pushLong(jValue.j); -} - -void HSAILArgumentsBase::do_array(int begin, int end) { - oop arg = _args->obj_at(_index++); - if (arg == NULL) { - recordNullObjectParameter(); - } else { - assert(arg->is_array(), "arg type mismatch"); - } - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::do_array, _index=%d, 0x" INTPTR_FORMAT ", is a %s", argsBuilderName(), _index - 1, p2i(arg), - arg == NULL ? "null" : arg->klass()->external_name()); - } - - pushObject(arg); -} - -void HSAILArgumentsBase::do_object() { - bool isLastParam = isLastParameter(); // determine this before incrementing _index - - oop arg = _args->obj_at(_index++); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::do_object, _index=%d, 0x" INTPTR_FORMAT " is a %s", argsBuilderName(), _index - 1, p2i(arg), - arg == NULL ? "null" : arg->klass()->external_name()); - } - if (arg == NULL) { - recordNullObjectParameter(); - } - - // check if this is last arg in signature - // an object as last parameter requires special handling - if (isLastParam) { - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s, trailing object ref should be object source array ref", argsBuilderName()); - } - assert(arg->is_objArray(), "arg type mismatch"); - handleFinalObjParameter(arg); - } else { - // not the final parameter, just push - pushObject(arg); - } -} - -void HSAILArgumentsBase::do_object(int begin, int end) { - do_object(); -} - -void HSAILArgumentsBase::do_void() { - return; -} - -// TODO implement other do_* - diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/hsailArgumentsBase.hpp --- a/src/gpu/hsail/vm/hsailArgumentsBase.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -/* - * 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. - * - */ - -#ifndef GPU_HSAIL_VM_HSAIL_ARGUMENTS_BASE_HPP -#define GPU_HSAIL_VM_HSAIL_ARGUMENTS_BASE_HPP - -#include "runtime/signature.hpp" - - -// Base class which iterates thru a signature and pulls from a -// objArrayOop of boxed values. Used as base for HSAILKernelArguments -// and HSAILJavaCallArguments The derived classes specify how to push -// args onto their data structure -class HSAILArgumentsBase : public SignatureIterator { - -public: - -private: - // Array of java argument oops - objArrayOop _args; - // Length of args array - int _length; - // Current index into _args - int _index; - // number of parameters in the signature - int _parameter_count; - - Symbol* _signature; - bool _is_static; - - // records first null parameter seen - int _first_null_parameter_index; - - // Get next java argument - oop next_arg(BasicType expectedType); - - virtual char* argsBuilderName() = 0; - virtual void pushObject(void* obj) = 0; - virtual void pushBool(jboolean z) = 0; - virtual void pushByte(jbyte b) = 0; - virtual void pushDouble(jdouble d) = 0; - virtual void pushFloat(jfloat f) = 0; - virtual void pushInt(jint i) = 0; - virtual void pushLong(jlong j) = 0; - virtual void handleFinalIntParameter() = 0; - virtual void handleFinalObjParameter(void* obj) = 0; - virtual void pushTrailingArgs() = 0; - - public: - HSAILArgumentsBase(Symbol* signature, objArrayOop args, bool is_static) : SignatureIterator(signature) { - this->_return_type = T_ILLEGAL; - _index = 0; - _args = args; - _is_static = is_static; - _signature = signature; - - _length = args->length(); - _parameter_count = ArgumentCount(signature).size(); - - _first_null_parameter_index = -1; - - } - - void recordNullObjectParameter() { - if (_first_null_parameter_index == -1) { - _first_null_parameter_index = _parameter_index; - } - } - - bool is_static() { - return _is_static; - } - - int length() { - return _length; - } - - objArrayOop args() { - return _args; - } - - int getFirstNullParameterIndex() { - return _first_null_parameter_index; - } - - virtual void collectArgs(); - - void do_bool(); - void do_byte(); - void do_double(); - void do_float(); - void do_int(); - void do_long(); - void do_array(int begin, int end); - void do_object(); - void do_object(int begin, int end); - - void do_void(); - - inline void do_char() { - /* TODO : To be implemented */ - guarantee(false, "do_char:NYI"); - } - inline void do_short() { - /* TODO : To be implemented */ - guarantee(false, "do_short:NYI"); - } - - bool isLastParameter() { - return (_index == (_is_static ? _parameter_count - 1 : _parameter_count)); - } - -}; - -#endif // GPU_HSAIL_VM_HSAIL_ARGUMENTS_BASE_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/hsailJavaCallArguments.hpp --- a/src/gpu/hsail/vm/hsailJavaCallArguments.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,81 +0,0 @@ -/* - * 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. - * - */ - -#ifndef GPU_HSAIL_VM_HSAIL_JAVACALL_ARGUMENTS_HPP -#define GPU_HSAIL_VM_HSAIL_JAVACALL_ARGUMENTS_HPP - -#include "hsailArgumentsBase.hpp" -#include "runtime/javaCalls.hpp" - -class HSAILJavaCallArguments : public HSAILArgumentsBase { - -public: - -private: - // JavaCall args to push into - JavaCallArguments* _javaArgs; - int _workitemid; - public: - HSAILJavaCallArguments(JavaCallArguments* javaArgs, int workitemid, Symbol* signature, objArrayOop args, bool is_static) : HSAILArgumentsBase(signature, args, is_static) { - _javaArgs = javaArgs; - _workitemid = workitemid; - collectArgs(); - } - virtual char* argsBuilderName() {return (char*)"HSAILJavaCallArguments";} - virtual void pushObject(void* obj) { _javaArgs->push_oop((oop) obj); } - virtual void pushBool(jboolean z) { pushInt(z); } - virtual void pushByte(jbyte b) { pushInt(b); } - virtual void pushDouble(jdouble d) { _javaArgs->push_double(d); } - virtual void pushFloat(jfloat f) { _javaArgs->push_float(f); } - virtual void pushInt(jint i) { _javaArgs->push_int(i); } - virtual void pushLong(jlong j) { _javaArgs->push_long(j); } - virtual void pushTrailingArgs() { } - - // For javaCall the final int parameter gets replaced with the workitemid - // which was passed back in the deopt info - virtual void handleFinalIntParameter() { - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] HSAILJavaCallArguments, passing workitemid %d as trailing int parameter", _workitemid); - } - pushInt(_workitemid); - } - // for kernel arguments, final obj parameter should be an object - // stream source array (already checked in the base class) so for - // a javacall we need to extract the correct obj from it based on - // the workitemid - virtual void handleFinalObjParameter(void* arg) { - objArrayOop objArrayArg = (objArrayOop) arg; - oop extractedObj = objArrayArg->obj_at(_workitemid); - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] HSAILJavaCallArguments, extracted obj #%d from array, " INTPTR_FORMAT " is a %s", - _workitemid, p2i(extractedObj), - (extractedObj == NULL ? "null" : extractedObj->klass()->external_name())); - } - pushObject(extractedObj); - } - -}; - -#endif // GPU_HSAIL_VM_HSAIL_JAVACALL_ARGUMENTS_HPP - diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/hsailKernelArguments.cpp --- a/src/gpu/hsail/vm/hsailKernelArguments.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2014, 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. - * - */ -#include "precompiled.hpp" -#include "hsailKernelArguments.hpp" - -void HSAILKernelArguments::collectArgs() { - int index = 0; - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, args length=%d", argsBuilderName(), length()); - } - - // Manually iterate over the actual args array without looking at method signature - while (index < length()) { - oop arg = args()->obj_at(index++); - jvalue jValue; - if (arg == NULL) { - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs object, _index=%d, value = " PTR_FORMAT " is a %s", argsBuilderName(), index, p2i(arg), "null"); - } - recordNullObjectParameter(); - pushObject(arg); - } else { - java_lang_boxing_object::get_value(arg, &jValue); - BasicType basic_type = java_lang_boxing_object::basic_type(arg); - if (basic_type == T_ILLEGAL && (!(arg->is_array()))) { - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs object, _index=%d, value = " PTR_FORMAT " is a %s", argsBuilderName(), index, p2i(arg), arg == NULL ? "null" : arg->klass()->external_name()); - } - pushObject(arg); - } else if (arg->is_array()) { - if (TraceGPUInteraction) { - int array_length = ((objArrayOop) arg)->length(); - tty->print_cr("[HSAIL] %s::collectArgs array, length=%d, _index=%d, value = " PTR_FORMAT, argsBuilderName(), array_length, index, p2i(arg)); - } - pushObject(arg); - } else { - switch (basic_type) { - case T_INT: - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, T_INT _index=%d, value = %d", argsBuilderName(), index, jValue.i); - } - pushInt(jValue.i); - break; - case T_LONG: - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, T_LONG _index=%d, value = " JLONG_FORMAT, argsBuilderName(), index, jValue.j); - } - pushLong(jValue.j); - break; - case T_FLOAT: - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, T_FLOAT _index=%d, value = %f", argsBuilderName(), index, jValue.f); - } - pushFloat(jValue.f); - break; - case T_DOUBLE: - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, T_DOUBLE _index=%d, value = %lf", argsBuilderName(), index, jValue.d); - } - pushDouble(jValue.d); - break; - case T_BYTE: - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, T_BYTE _index=%d, value = %d", argsBuilderName(), index, jValue.b); - } - pushByte(jValue.b); - break; - case T_BOOLEAN: - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] %s::collectArgs, T_BOOLEAN _index=%d, value = %d", argsBuilderName(), index, jValue.z); - } - pushBool(jValue.z); - break; - } - } - } - } - - pushTrailingArgs(); -} - diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/hsailKernelArguments.hpp --- a/src/gpu/hsail/vm/hsailKernelArguments.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * 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. - * - */ - -#ifndef GPU_HSAIL_VM_HSAIL_KERNEL_ARGUMENTS_HPP -#define GPU_HSAIL_VM_HSAIL_KERNEL_ARGUMENTS_HPP - -#include "gpu_hsail.hpp" -#include "runtime/signature.hpp" -#include "hsailArgumentsBase.hpp" - -class HSAILKernelArguments : public HSAILArgumentsBase { - friend class Hsail; - -public: - -private: - // Kernel to push into - address _kernel; - void* _exceptionHolder; - - public: - HSAILKernelArguments(address kernel, Symbol* signature, objArrayOop args, bool is_static, void* exceptionHolder) : HSAILArgumentsBase(signature, args, is_static) { - _kernel = kernel; - _exceptionHolder = exceptionHolder; - collectArgs(); - } - virtual char* argsBuilderName() {return (char*)"HSAILKernelArguments";} - virtual void pushObject(void* obj) { - jint status = Hsail::_okra_push_pointer(_kernel, obj); - assert(status == 0, "arg push failed"); - } - virtual void pushBool(jboolean z) { - jint status = Hsail::_okra_push_boolean(_kernel, z); - assert(status == 0, "arg push failed"); - } - virtual void pushByte(jbyte b) { - jint status = Hsail::_okra_push_byte(_kernel, b); - assert(status == 0, "arg push failed"); - } - - virtual void pushDouble(jdouble d) { - jint status = Hsail::_okra_push_double(_kernel, d); - assert(status == 0, "arg push failed"); - } - - virtual void pushFloat(jfloat f) { - jint status = Hsail::_okra_push_float(_kernel, f); - assert(status == 0, "arg push failed"); - } - - virtual void pushInt(jint i) { - jint status = Hsail::_okra_push_int(_kernel, i); - assert(status == 0, "arg push failed"); - } - - virtual void pushLong(jlong j) { - jint status = Hsail::_okra_push_long(_kernel, j); - assert(status == 0, "arg push failed"); - } - virtual void pushTrailingArgs() { - if (UseHSAILDeoptimization) { - // Last argument is the exception info block - if (TraceGPUInteraction) { - tty->print_cr("[HSAIL] exception block=" INTPTR_FORMAT, p2i(_exceptionHolder)); - } - pushObject(_exceptionHolder); - } - } - - // For kernel arguments we don't pass the final int parameter - // since we use the HSAIL workitemid instruction in place of that int value - virtual void handleFinalIntParameter() { - ShouldNotReachHere(); - } - - // For kernel arguments, final obj parameter should be an object - // stream source array (already checked in the base class) so here we just pass it - virtual void handleFinalObjParameter(void* arg) { - ShouldNotReachHere(); - } - - virtual void collectArgs(); - -}; - -#endif // GPU_HSAIL_VM_HSAIL_KERNEL_ARGUMENTS_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/hsail/vm/vmStructs_hsail.hpp --- a/src/gpu/hsail/vm/vmStructs_hsail.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2001, 2010, 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. - * - */ - -#ifndef GPU_HSAIL_VM_VMSTRUCTS_HSAIL_HPP -#define GPU_HSAIL_VM_VMSTRUCTS_HSAIL_HPP - -#include "gpu_hsail.hpp" -#include "gpu_hsail_Frame.hpp" - -// These are the CPU-specific fields, types and integer -// constants required by the Serviceability Agent. This file is -// referenced by vmStructs.cpp. - -#define VM_STRUCTS_GPU_HSAIL(nonstatic_field) \ - nonstatic_field(HSAILFrame, _pc_offset, jint) \ - nonstatic_field(HSAILFrame, _num_s_regs, jbyte) \ - nonstatic_field(HSAILFrame, _num_d_regs, jbyte) \ - nonstatic_field(HSAILFrame, _num_stack_slots, jshort) \ - \ - nonstatic_field(Hsail::HSAILKernelDeoptimization, _workitemid, jint) \ - nonstatic_field(Hsail::HSAILKernelDeoptimization, _actionAndReason, jint) \ - \ - nonstatic_field(Hsail::HSAILDeoptimizationInfo, _notice_safepoints, jint*) \ - nonstatic_field(Hsail::HSAILDeoptimizationInfo, _deopt_occurred, jint) \ - nonstatic_field(Hsail::HSAILDeoptimizationInfo, _deopt_next_index, jint) \ - nonstatic_field(Hsail::HSAILDeoptimizationInfo, _cur_tlab_info, HSAILTlabInfo**) \ - nonstatic_field(Hsail::HSAILDeoptimizationInfo, _alloc_info, HSAILAllocationInfo*) \ - nonstatic_field(Hsail::HSAILDeoptimizationInfo, _never_ran_array, jboolean*) \ - \ - nonstatic_field(HSAILAllocationInfo, _tlab_infos_pool_start, HSAILTlabInfo*) \ - nonstatic_field(HSAILAllocationInfo, _tlab_infos_pool_next, HSAILTlabInfo*) \ - nonstatic_field(HSAILAllocationInfo, _tlab_infos_pool_end, HSAILTlabInfo*) \ - nonstatic_field(HSAILAllocationInfo, _tlab_align_reserve_bytes, size_t) \ - \ - nonstatic_field(HSAILTlabInfo, _start, HeapWord*) \ - nonstatic_field(HSAILTlabInfo, _top, HeapWord*) \ - nonstatic_field(HSAILTlabInfo, _end, HeapWord*) \ - nonstatic_field(HSAILTlabInfo, _last_good_top, HeapWord*) \ - nonstatic_field(HSAILTlabInfo, _original_top, HeapWord*) \ - nonstatic_field(HSAILTlabInfo, _alloc_info, HSAILAllocationInfo*) \ - nonstatic_field(HSAILTlabInfo, _tlab, ThreadLocalAllocBuffer*) \ - -#define VM_TYPES_GPU_HSAIL(declare_type, declare_toplevel_type) \ - declare_toplevel_type(HSAILFrame) \ - declare_toplevel_type(HSAILFrame*) \ - declare_toplevel_type(Hsail::HSAILKernelDeoptimization) \ - declare_toplevel_type(HSAILAllocationInfo) \ - declare_toplevel_type(HSAILTlabInfo) \ - declare_toplevel_type(Hsail::HSAILDeoptimizationInfo) - -#endif // GPU_HSAIL_VM_VMSTRUCTS_HSAIL_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/ptx/vm/gpu_ptx.cpp --- a/src/gpu/ptx/vm/gpu_ptx.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,808 +0,0 @@ -/* - * 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. - * - */ - -#include "precompiled.hpp" -#include "runtime/javaCalls.hpp" -#include "runtime/gpu.hpp" -#include "ptx/vm/gpu_ptx.hpp" -#include "utilities/globalDefinitions.hpp" -#include "utilities/ostream.hpp" -#include "memory/allocation.hpp" -#include "memory/allocation.inline.hpp" -#include "memory/gcLocker.inline.hpp" -#include "runtime/interfaceSupport.hpp" -#include "runtime/vframe.hpp" -#include "graal/graalEnv.hpp" -#include "graal/graalRuntime.hpp" - -#define T_BYTE_SIZE 1 -#define T_BOOLEAN_SIZE 4 -#define T_INT_BYTE_SIZE 4 -#define T_FLOAT_BYTE_SIZE 4 -#define T_DOUBLE_BYTE_SIZE 8 -#define T_LONG_BYTE_SIZE 8 -#define T_OBJECT_BYTE_SIZE sizeof(intptr_t) -#define T_ARRAY_BYTE_SIZE sizeof(intptr_t) - -// Entry to GPU native method implementation that transitions current thread to '_thread_in_vm'. -#define GPU_VMENTRY(result_type, name, signature) \ - JNIEXPORT result_type JNICALL name signature { \ - if (TraceGPUInteraction) tty->print_cr("[CUDA] " #name); \ - GRAAL_VM_ENTRY_MARK; \ - -// Entry to GPU native method implementation that calls a JNI function -// and hence cannot transition current thread to '_thread_in_vm'. -#define GPU_ENTRY(result_type, name, signature) \ - JNIEXPORT result_type JNICALL name signature { \ - if (TraceGPUInteraction) tty->print_cr("[CUDA] Ptx::" #name); \ - -#define GPU_END } - -#define CC (char*) /*cast a literal from (const char*)*/ -#define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(f)) - -#define STRING "Ljava/lang/String;" - -JNINativeMethod Ptx::PTX_methods[] = { - {CC"initialize", CC"()Z", FN_PTR(Ptx::initialize)}, - {CC"generateKernel", CC"([B" STRING ")J", FN_PTR(Ptx::generate_kernel)}, - {CC"getLaunchKernelAddress", CC"()J", FN_PTR(Ptx::get_execute_kernel_from_vm_address)}, - {CC"getAvailableProcessors0", CC"()I", FN_PTR(Ptx::get_total_cores)}, - {CC"destroyContext", CC"()V", FN_PTR(Ptx::destroy_ptx_context)}, -}; - -void * Ptx::_device_context = 0; -int Ptx::_cu_device = 0; - -Ptx::cuda_cu_init_func_t Ptx::_cuda_cu_init; -Ptx::cuda_cu_ctx_create_func_t Ptx::_cuda_cu_ctx_create; -Ptx::cuda_cu_ctx_destroy_func_t Ptx::_cuda_cu_ctx_destroy; -Ptx::cuda_cu_ctx_synchronize_func_t Ptx::_cuda_cu_ctx_synchronize; -Ptx::cuda_cu_ctx_get_current_func_t Ptx::_cuda_cu_ctx_get_current; -Ptx::cuda_cu_ctx_set_current_func_t Ptx::_cuda_cu_ctx_set_current; -Ptx::cuda_cu_device_get_count_func_t Ptx::_cuda_cu_device_get_count; -Ptx::cuda_cu_device_get_name_func_t Ptx::_cuda_cu_device_get_name; -Ptx::cuda_cu_device_get_func_t Ptx::_cuda_cu_device_get; -Ptx::cuda_cu_device_compute_capability_func_t Ptx::_cuda_cu_device_compute_capability; -Ptx::cuda_cu_device_get_attribute_func_t Ptx::_cuda_cu_device_get_attribute; -Ptx::cuda_cu_launch_kernel_func_t Ptx::_cuda_cu_launch_kernel; -Ptx::cuda_cu_module_get_function_func_t Ptx::_cuda_cu_module_get_function; -Ptx::cuda_cu_module_load_data_ex_func_t Ptx::_cuda_cu_module_load_data_ex; -Ptx::cuda_cu_memcpy_htod_func_t Ptx::_cuda_cu_memcpy_htod; -Ptx::cuda_cu_memcpy_dtoh_func_t Ptx::_cuda_cu_memcpy_dtoh; -Ptx::cuda_cu_memalloc_func_t Ptx::_cuda_cu_memalloc; -Ptx::cuda_cu_memfree_func_t Ptx::_cuda_cu_memfree; -Ptx::cuda_cu_mem_host_register_func_t Ptx::_cuda_cu_mem_host_register; -Ptx::cuda_cu_mem_host_get_device_pointer_func_t Ptx::_cuda_cu_mem_host_get_device_pointer; -Ptx::cuda_cu_mem_host_unregister_func_t Ptx::_cuda_cu_mem_host_unregister; - -#define STRINGIFY(x) #x - -#define LOOKUP_CUDA_FUNCTION(name, alias) \ - _##alias = \ - CAST_TO_FN_PTR(alias##_func_t, os::dll_lookup(handle, STRINGIFY(name))); \ - if (_##alias == NULL) { \ - tty->print_cr("[CUDA] ***** Error: Failed to lookup %s", STRINGIFY(name)); \ - return false; \ - } \ - -#define LOOKUP_CUDA_V2_FUNCTION(name, alias) LOOKUP_CUDA_FUNCTION(name##_v2, alias) - -/* - * see http://en.wikipedia.org/wiki/CUDA#Supported_GPUs - */ -int Ptx::ncores(int major, int minor) { - int device_type = (major << 4) + minor; - - switch (device_type) { - case 0x10: return 8; - case 0x11: return 8; - case 0x12: return 8; - case 0x13: return 8; - case 0x20: return 32; - case 0x21: return 48; - case 0x30: return 192; - case 0x35: return 192; - default: - tty->print_cr("[CUDA] Warning: Unhandled device %x", device_type); - return 0; - } -} - -bool Ptx::register_natives(JNIEnv* env) { - jclass klass = env->FindClass("com/oracle/graal/hotspot/ptx/PTXHotSpotBackend"); - if (klass == NULL) { - if (TraceGPUInteraction) { - tty->print_cr("PTXHotSpotBackend class not found"); - } - return false; - } - jint status = env->RegisterNatives(klass, PTX_methods, sizeof(PTX_methods) / sizeof(JNINativeMethod)); - if (status != JNI_OK) { - if (true || TraceGPUInteraction) { - tty->print_cr("Error registering natives for PTXHotSpotBackend: %d", status); - } - return false; - } - return true; -} - -GPU_ENTRY(jboolean, Ptx::initialize, (JNIEnv *env, jclass)) - - if (!link()) { - return false; - } - - /* Initialize CUDA driver API */ - int status = _cuda_cu_init(0); - if (status != GRAAL_CUDA_SUCCESS) { - if (TraceGPUInteraction) { - tty->print_cr("Failed to initialize CUDA device: %d", status); - } - return false; - } - - if (TraceGPUInteraction) { - tty->print_cr("CUDA driver initialization: Success"); - } - - /* Get the number of compute-capable device count */ - int device_count = 0; - status = _cuda_cu_device_get_count(&device_count); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get compute-capable device count"); - return false; - } - - if (device_count == 0) { - tty->print_cr("[CUDA] Found no device supporting CUDA"); - return false; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Number of compute-capable devices found: %d", device_count); - } - - /* Get the handle to the first compute device */ - int device_id = 0; - /* Compute-capable device handle */ - status = _cuda_cu_device_get(&_cu_device, device_id); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get handle of first compute-capable device i.e., the one at ordinal: %d", device_id); - return false; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Got the handle of first compute-device"); - } - - /* Get device attributes */ - int minor, major; - int unified_addressing; - float version = 0.0; - - /* Get the compute capability of the device found */ - status = _cuda_cu_device_get_attribute(&minor, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, _cu_device); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device); - return false; - } - status = _cuda_cu_device_get_attribute(&major, GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, _cu_device); - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device); - return false; - } - - /* Check if the device supports atleast GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION */ - version = (float) major + ((float) minor)/10; - - if (version < GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION) { - tty->print_cr("[CUDA] Only cuda compute capability %.1f and later supported. Device %d supports %.1f", - (float) GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION, _cu_device, version); - return false; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Device %d supports cuda compute capability %.1f", _cu_device, version); - } - - status = _cuda_cu_device_get_attribute(&unified_addressing, GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING, _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to query unified addressing mode of device: %d", _cu_device); - return false; - } - /* The CUDA driver runtime interaction and generated code as implemented requires - that the device supports Unified Addressing. - */ - if (unified_addressing == 0) { - tty->print_cr("[CUDA] CUDA device %d does NOT have required Unified Addressing support.", _cu_device); - return false; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Device %d has Unified Addressing support", _cu_device); - } - - /* Get device name */ - char device_name[256]; - status = _cuda_cu_device_get_name(device_name, 256, _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get name of device: %d", _cu_device); - return false; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Using %s", device_name); - } - - // Create CUDA context to compile and execute the kernel - - status = _cuda_cu_ctx_create(&_device_context, GRAAL_CU_CTX_MAP_HOST, _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to create CUDA context for device(%d): %d", _cu_device, status); - return false; - } - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: Created context for device: %d", _cu_device); - } - - Gpu::initialized_gpu(new Ptx()); - - return true; -GPU_END - -GPU_ENTRY(jint, Ptx::get_total_cores, (JNIEnv *env, jobject)) - - int minor, major, nmp; - int status = _cuda_cu_device_get_attribute(&minor, - GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get minor attribute of device: %d", _cu_device); - return 0; - } - - status = _cuda_cu_device_get_attribute(&major, - GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get major attribute of device: %d", _cu_device); - return 0; - } - - status = _cuda_cu_device_get_attribute(&nmp, - GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get number of MPs on device: %d", _cu_device); - return 0; - } - - int total = nmp * ncores(major, minor); - - int max_threads_per_block, warp_size, async_engines, can_map_host_memory, concurrent_kernels; - - status = _cuda_cu_device_get_attribute(&max_threads_per_block, - GRAAL_CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK: %d", _cu_device); - return 0; - } - - status = _cuda_cu_device_get_attribute(&warp_size, - GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE: %d", _cu_device); - return 0; - } - - status = _cuda_cu_device_get_attribute(&async_engines, - GRAAL_CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE: %d", _cu_device); - return 0; - } - - status = _cuda_cu_device_get_attribute(&can_map_host_memory, - GRAAL_CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY: %d", _cu_device); - return 0; - } - - status = _cuda_cu_device_get_attribute(&concurrent_kernels, - GRAAL_CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS, - _cu_device); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to get GRAAL_CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS: %d", _cu_device); - return 0; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Number of cores: %d async engines: %d can map host mem: %d concurrent kernels: %d", - total, async_engines, can_map_host_memory, concurrent_kernels); - tty->print_cr("[CUDA] Max threads per block: %d warp size: %d", max_threads_per_block, warp_size); - } - return total; -GPU_END - -GPU_ENTRY(jlong, Ptx::generate_kernel, (JNIEnv *env, jclass, jbyteArray code_handle, jstring name_handle)) - ResourceMark rm; - jsize name_len = env->GetStringLength(name_handle); - jsize code_len = env->GetArrayLength(code_handle); - - char* name = NEW_RESOURCE_ARRAY(char, name_len + 1); - unsigned char *code = NEW_RESOURCE_ARRAY(unsigned char, code_len + 1); - - code[code_len] = 0; - name[name_len] = 0; - - env->GetByteArrayRegion(code_handle, 0, code_len, (jbyte*) code); - env->GetStringUTFRegion(name_handle, 0, name_len, name); - - struct CUmod_st * cu_module; - // Use three JIT compiler options - const unsigned int jit_num_options = 3; - int *jit_options = NEW_RESOURCE_ARRAY(int, jit_num_options); - void **jit_option_values = NEW_RESOURCE_ARRAY(void *, jit_num_options); - - // Set up PTX JIT compiler options - // 1. set size of compilation log buffer - int jit_log_buffer_size = 1024; - jit_options[0] = GRAAL_CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES; - jit_option_values[0] = (void *)(size_t)jit_log_buffer_size; - - // 2. set pointer to compilation log buffer - char *jit_log_buffer = NEW_RESOURCE_ARRAY(char, jit_log_buffer_size); - jit_options[1] = GRAAL_CU_JIT_INFO_LOG_BUFFER; - jit_option_values[1] = jit_log_buffer; - - // 3. set pointer to set the maximum number of registers (32) for the kernel - int jit_register_count = 32; - jit_options[2] = GRAAL_CU_JIT_MAX_REGISTERS; - jit_option_values[2] = (void *)(size_t)jit_register_count; - - // Set CUDA context to compile and execute the kernel - - if (_device_context == NULL) { - tty->print_cr("[CUDA] Encountered uninitialized CUDA context for device(%d)", _cu_device); - return 0L; - } - - int status = _cuda_cu_ctx_set_current(_device_context); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] Failed to set current context for device: %d", _cu_device); - return 0L; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: Set current context for device: %d", _cu_device); - tty->print_cr("[CUDA] PTX Kernel\n%s", code); - tty->print_cr("[CUDA] Function name : %s", name); - } - - /* Load module's data with compiler options */ - status = _cuda_cu_module_load_data_ex(&cu_module, (void*) code, jit_num_options, - jit_options, (void **)jit_option_values); - if (status != GRAAL_CUDA_SUCCESS) { - if (status == GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU) { - tty->print_cr("[CUDA] Check for malformed PTX kernel or incorrect PTX compilation options"); - } - tty->print_cr("[CUDA] *** Error (%d) Failed to load module data with online compiler options for method %s", - status, name); - return 0L; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Loaded data for PTX Kernel"); - } - - struct CUfunc_st* cu_function; - status = _cuda_cu_module_get_function(&cu_function, cu_module, name); - - if (status != GRAAL_CUDA_SUCCESS) { - tty->print_cr("[CUDA] *** Error: Failed to get function %s", name); - return 0L; - } - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Got function handle for %s kernel address %p", name, cu_function); - } - return (jlong) cu_function; -GPU_END - -// A PtxCall is used to manage executing a GPU kernel. In addition to launching -// the kernel, this class releases resources allocated for the execution. -class PtxCall: StackObj { - private: - JavaThread* _thread; // the thread on which this call is made - address _buffer; // buffer containing parameters and _return_value - int _buffer_size; // size (in bytes) of _buffer - oop* _pinned; // objects that have been pinned with cuMemHostRegister - int _pinned_length; // length of _pinned - Ptx::CUdeviceptr _ret_value; // pointer to slot in GPU memory holding the return value - int _ret_type_size; // size of the return type value - bool _ret_is_object; // specifies if the return type is Object - bool _gc_locked; // denotes when execution has locked GC - - bool check(int status, const char *action) { - if (status != GRAAL_CUDA_SUCCESS) { - Thread* THREAD = _thread; - ResourceMark rm(THREAD); - char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, O_BUFLEN + 1); - jio_snprintf(message, O_BUFLEN, "[CUDA] *** Error (status=%d): %s", status, action); - if (TraceGPUInteraction) { - tty->print_raw_cr(message); - } - if (!HAS_PENDING_EXCEPTION) { - SharedRuntime::throw_and_post_jvmti_exception(_thread, vmSymbols::java_lang_RuntimeException(), message); - } - return false; - } - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: %s", action); - } - return true; - } - - public: - PtxCall(JavaThread* thread, address buffer, int buffer_size, oop* pinned, int encodedReturnTypeSize) : _thread(thread), _gc_locked(false), - _buffer(buffer), _buffer_size(buffer_size), _pinned(pinned), _pinned_length(0), _ret_value(0), _ret_is_object(encodedReturnTypeSize < 0) { - _ret_type_size = _ret_is_object ? -encodedReturnTypeSize : encodedReturnTypeSize; - } - - bool is_object_return() { return _ret_is_object; } - - void alloc_return_value() { - if (_ret_type_size != 0) { - if (check(Ptx::_cuda_cu_memalloc(&_ret_value, _ret_type_size), "Allocate device memory for return value")) { - Ptx::CUdeviceptr* retValuePtr = (Ptx::CUdeviceptr*) ((_buffer + _buffer_size) - sizeof(_ret_value)); - *retValuePtr = _ret_value; - } - } - } - - void pin_objects(int count, int* objectOffsets) { - if (count == 0) { - return; - } - // Once we start pinning objects, no GC must occur - // until the kernel has completed. This is a big - // hammer for ensuring we can safely pass objects - // to the GPU. - GC_locker::lock_critical(_thread); - _gc_locked = true; - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Locked GC"); - } - - for (int i = 0; i < count; i++) { - int offset = objectOffsets[i]; - oop* argPtr = (oop*) (_buffer + offset); - oop obj = *argPtr; - if (obj != NULL) { - // Size (in bytes) of object - int objSize = obj->size() * HeapWordSize; - //tty->print_cr("Pinning object %d at offset %d: %p", i, offset, obj); - if (!check(Ptx::_cuda_cu_mem_host_register(obj, objSize, GRAAL_CU_MEMHOSTREGISTER_DEVICEMAP), "Pin object")) { - return; - } - - // Record original oop so that its memory can be unpinned - _pinned[_pinned_length++] = obj; - - // Replace host pointer to object with device pointer - // to object in kernel parameters buffer - if (!check(Ptx::_cuda_cu_mem_host_get_device_pointer((Ptx::CUdeviceptr*) argPtr, obj, 0), "Get device pointer for pinned object")) { - return; - } - } - } - } - - void launch(address kernel, jint dimX, jint dimY, jint dimZ) { - // grid dimensionality - unsigned int gridX = 1; - unsigned int gridY = 1; - unsigned int gridZ = 1; - void * config[] = { - GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER, (char*) (address) _buffer, - GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE, &_buffer_size, - GRAAL_CU_LAUNCH_PARAM_END - }; - if (check(Ptx::_cuda_cu_launch_kernel((struct CUfunc_st*) (address) kernel, - gridX, gridY, gridZ, - dimX, dimY, dimZ, - 0, NULL, NULL, (void**) &config), "Launch kernel")) { - } - } - - void synchronize() { - check(Ptx::_cuda_cu_ctx_synchronize(), "Synchronize kernel"); - } - - void unpin_objects() { - while (_pinned_length > 0) { - oop obj = _pinned[--_pinned_length]; - assert(obj != NULL, "npe"); - //tty->print_cr("Unpinning object %d: %p", _pinned_length, obj); - if (!check(Ptx::_cuda_cu_mem_host_unregister(obj), "Unpin object")) { - return; - } - } - } - - oop get_object_return_value() { - oop return_val; - check(Ptx::_cuda_cu_memcpy_dtoh(&return_val, _ret_value, T_OBJECT_BYTE_SIZE), "Copy return value from device"); - return return_val; - } - - jlong get_primitive_return_value() { - jlong return_val; - check(Ptx::_cuda_cu_memcpy_dtoh(&return_val, _ret_value, _ret_type_size), "Copy return value from device"); - return return_val; - } - - void free_return_value() { - if (_ret_value != 0) { - check(Ptx::_cuda_cu_memfree(_ret_value), "Free device memory"); - _ret_value = 0; - } - } - - ~PtxCall() { - unpin_objects(); - free_return_value(); - if (_gc_locked) { - GC_locker::unlock_critical(_thread); - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Unlocked GC"); - } - _gc_locked = false; - } - } -}; - -// Prints values in the kernel arguments buffer -class KernelArgumentsPrinter: public SignatureIterator { - Method* _method; - address _buffer; - size_t _bufferOffset; - outputStream* _st; - -private: - - // Get next java argument - oop next_arg(BasicType expectedType); - - public: - KernelArgumentsPrinter(Method* method, address buffer, outputStream* st) : SignatureIterator(method->signature()), - _method(method), _buffer(buffer), _bufferOffset(0), _st(st) { - if (!method->is_static()) { - print_oop(); - } - iterate(); - } - - address next(size_t dataSz) { - if (is_return_type()) { - return _buffer; - } - if (_bufferOffset != 0) { - _st->print(", "); - } - _bufferOffset = align_size_up_(_bufferOffset, dataSz); - address result = _buffer + _bufferOffset; - _bufferOffset += dataSz; - return result; - } - - void print_oop() { - oop obj = *((oop*) next(sizeof(oop))); - if (obj != NULL) { - char type[256]; - obj->klass()->name()->as_C_string(type, 256); - _st->print("oop "INTPTR_FORMAT" (%s)", p2i(obj), type); - } else { - _st->print("oop null"); - } - } - - bool skip() { - return is_return_type(); - } - - void do_bool () { if (!skip()) _st->print("bool %d", *((jboolean*) next(sizeof(jboolean)))); } - void do_char () { if (!skip()) _st->print("char %c", *((jchar*) next(sizeof(jchar)))); } - void do_float () { if (!skip()) _st->print("float %g", *((jfloat*) next(sizeof(jfloat)))); } - void do_double() { if (!skip()) _st->print("double %g", *((jdouble*) next(sizeof(jdouble)))); } - void do_byte () { if (!skip()) _st->print("byte %d", *((jbyte*) next(sizeof(jbyte)))); } - void do_short () { if (!skip()) _st->print("short %d", *((jshort*) next(sizeof(jshort)))); } - void do_int () { if (!skip()) _st->print("int %d", *((jint*) next(sizeof(jint)))); } - void do_long () { if (!skip()) _st->print("long "JLONG_FORMAT, *((jlong*) next(sizeof(jlong)))); } - void do_void () { } - void do_object(int begin, int end) { if (!skip()) print_oop(); } - void do_array (int begin, int end) { if (!skip()) print_oop(); } -}; - -static void printKernelArguments(JavaThread* thread, address buffer) { - for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) { - Method* m = vfst.method(); - if (m != NULL) { - ResourceMark rm; - stringStream st(O_BUFLEN); - st.print("[CUDA] Call: %s.%s(", m->method_holder()->name()->as_C_string(), m->name()->as_C_string()); - KernelArgumentsPrinter kap(m, buffer, &st); - tty->print_cr("%s)", st.as_string()); - return; - } - } -} - -GPU_VMENTRY(void, Ptx::destroy_ptx_context, (void)) - if (_device_context != NULL) { - int status = _cuda_cu_ctx_destroy(_device_context); - if (status != GRAAL_CUDA_SUCCESS) { - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Error(%d) : Failed to destroy context", status); - } - _device_context = NULL; - } else { - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Destroyed context"); - } - } - } - -GPU_END - -GPU_VMENTRY(jlong, Ptx::get_execute_kernel_from_vm_address, (JNIEnv *env, jclass)) - return (jlong) Ptx::execute_kernel_from_vm; -GPU_END - -JRT_ENTRY(jlong, Ptx::execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ, - jlong buffer, - jint bufferSize, - jint objectParametersCount, - jlong objectParametersOffsets, - jlong pinnedObjects, - int encodedReturnTypeSize)) - if (kernel == 0L) { - SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException(), NULL); - return 0L; - } - - if (TraceGPUInteraction) { - printKernelArguments(thread, (address) buffer); - } - - PtxCall call(thread, (address) buffer, bufferSize, (oop*) (address) pinnedObjects, encodedReturnTypeSize); - -#define TRY(action) do { \ - action; \ - if (HAS_PENDING_EXCEPTION) return 0L; \ -} while (0) - - TRY(call.alloc_return_value()); - - TRY(call.pin_objects(objectParametersCount, (int*) (address) objectParametersOffsets)); - - TRY(call.launch((address) kernel, dimX, dimY, dimZ)); - - TRY(call.synchronize()); - - if (call.is_object_return()) { - oop return_val; - TRY(return_val = call.get_object_return_value()); - thread->set_vm_result(return_val); - return 0L; - } - - jlong return_val; - TRY(return_val = call.get_primitive_return_value()); - return return_val; - -#undef TRY - -JRT_END - -#if defined(LINUX) -static const char cuda_library_name[] = "/usr/lib/libcuda.so"; -#elif defined(__APPLE__) -static char const cuda_library_name[] = "/usr/local/cuda/lib/libcuda.dylib"; -#else -static char const cuda_library_name[] = ""; -#endif - -bool Ptx::link() { - if (cuda_library_name == NULL) { - if (TraceGPUInteraction) { - tty->print_cr("Failed to find CUDA linkage"); - } - return false; - } - char ebuf[O_BUFLEN]; - void *handle = os::dll_load(cuda_library_name, ebuf, O_BUFLEN); - if (handle == NULL) { - if (TraceGPUInteraction) { - tty->print_cr("Unsupported CUDA platform: %s", ebuf); - } - return false; - } - - LOOKUP_CUDA_FUNCTION(cuInit, cuda_cu_init); - LOOKUP_CUDA_FUNCTION(cuCtxSynchronize, cuda_cu_ctx_synchronize); - LOOKUP_CUDA_FUNCTION(cuCtxGetCurrent, cuda_cu_ctx_get_current); - LOOKUP_CUDA_FUNCTION(cuCtxSetCurrent, cuda_cu_ctx_set_current); - LOOKUP_CUDA_FUNCTION(cuDeviceGetCount, cuda_cu_device_get_count); - LOOKUP_CUDA_FUNCTION(cuDeviceGetName, cuda_cu_device_get_name); - LOOKUP_CUDA_FUNCTION(cuDeviceGet, cuda_cu_device_get); - LOOKUP_CUDA_FUNCTION(cuDeviceComputeCapability, cuda_cu_device_compute_capability); - LOOKUP_CUDA_FUNCTION(cuDeviceGetAttribute, cuda_cu_device_get_attribute); - LOOKUP_CUDA_FUNCTION(cuModuleGetFunction, cuda_cu_module_get_function); - LOOKUP_CUDA_FUNCTION(cuModuleLoadDataEx, cuda_cu_module_load_data_ex); - LOOKUP_CUDA_FUNCTION(cuLaunchKernel, cuda_cu_launch_kernel); - LOOKUP_CUDA_FUNCTION(cuMemHostRegister, cuda_cu_mem_host_register); - LOOKUP_CUDA_FUNCTION(cuMemHostUnregister, cuda_cu_mem_host_unregister); -#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) - LOOKUP_CUDA_V2_FUNCTION(cuCtxCreate, cuda_cu_ctx_create); - LOOKUP_CUDA_V2_FUNCTION(cuCtxDestroy, cuda_cu_ctx_destroy); - LOOKUP_CUDA_V2_FUNCTION(cuMemAlloc, cuda_cu_memalloc); - LOOKUP_CUDA_V2_FUNCTION(cuMemFree, cuda_cu_memfree); - LOOKUP_CUDA_V2_FUNCTION(cuMemcpyHtoD, cuda_cu_memcpy_htod); - LOOKUP_CUDA_V2_FUNCTION(cuMemcpyDtoH, cuda_cu_memcpy_dtoh); - LOOKUP_CUDA_V2_FUNCTION(cuMemHostGetDevicePointer, cuda_cu_mem_host_get_device_pointer); -#else - LOOKUP_CUDA_FUNCTION(cuCtxCreate, cuda_cu_ctx_create); - LOOKUP_CUDA_FUNCTION(cuCtxDestroy, cuda_cu_ctx_destroy); - LOOKUP_CUDA_FUNCTION(cuMemAlloc, cuda_cu_memalloc); - LOOKUP_CUDA_FUNCTION(cuMemFree, cuda_cu_memfree); - LOOKUP_CUDA_FUNCTION(cuMemcpyHtoD, cuda_cu_memcpy_htod); - LOOKUP_CUDA_FUNCTION(cuMemcpyDtoH, cuda_cu_memcpy_dtoh); - LOOKUP_CUDA_FUNCTION(cuMemHostGetDevicePointer, cuda_cu_mem_host_get_device_pointer); -#endif - - if (TraceGPUInteraction) { - tty->print_cr("[CUDA] Success: library linkage"); - } - return true; -} diff -r c8fc6e2d128b -r 8f2fb6bec986 src/gpu/ptx/vm/gpu_ptx.hpp --- a/src/gpu/ptx/vm/gpu_ptx.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +0,0 @@ -/* - * 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. - * - */ - -#ifndef GPU_PTX_HPP -#define GPU_PTX_HPP - -/* - * Some useful macro definitions from publicly available cuda.h. - * These definitions are for convenience. - */ -#define GRAAL_CUDA_SUCCESS 0 -/**< Device shares a unified address space with the host */ -#define GRAAL_CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK 1 -#define GRAAL_CU_DEVICE_ATTRIBUTE_UNIFIED_ADDRESSING 41 -#define GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR 75 -#define GRAAL_CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MINOR 76 -#define GRAAL_CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT 16 -#define GRAAL_CU_DEVICE_ATTRIBUTE_WARP_SIZE 10 -#define GRAAL_CU_DEVICE_ATTRIBUTE_CAN_MAP_HOST_MEMORY 19 -#define GRAAL_CU_DEVICE_ATTRIBUTE_CONCURRENT_KERNELS 31 -#define GRAAL_CU_DEVICE_ATTRIBUTE_ASYNC_ENGINE_COUNT 40 -#define GRAAL_CU_JIT_MAX_REGISTERS 0 -#define GRAAL_CU_JIT_THREADS_PER_BLOCK 1 -#define GRAAL_CU_JIT_INFO_LOG_BUFFER 3 -#define GRAAL_CU_JIT_INFO_LOG_BUFFER_SIZE_BYTES 4 -#define GRAAL_CUDA_ERROR_NO_BINARY_FOR_GPU 209 - -/* - * Flags for cuMemHostRegister - */ - -#define GRAAL_CU_MEMHOSTREGISTER_PORTABLE 1 -#define GRAAL_CU_MEMHOSTREGISTER_DEVICEMAP 2 - -/** - * End of array terminator for the extra parameter to - * ::cuLaunchKernel - */ -#define GRAAL_CU_LAUNCH_PARAM_END ((void*) 0x00) - -/** - * Indicator that the next value in the extra parameter to - * ::cuLaunchKernel will be a pointer to a buffer containing all kernel - * parameters used for launching kernel f. This buffer needs to - * honor all alignment/padding requirements of the individual parameters. - * If ::GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE is not also specified in the - * extra array, then ::GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER will have no - * effect. - */ -#define GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER ((void*) 0x01) - -/** - * Indicator that the next value in the extra parameter to - * ::cuLaunchKernel will be a pointer to a size_t which contains the - * size of the buffer specified with ::GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER. - * It is required that ::GRAAL_CU_LAUNCH_PARAM_BUFFER_POINTER also be specified - * in the extra array if the value associated with - * ::GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE is not zero. - */ -#define GRAAL_CU_LAUNCH_PARAM_BUFFER_SIZE ((void*) 0x02) - -/* - * Context creation flags - */ - -#define GRAAL_CU_CTX_MAP_HOST 0x08 -#define GRAAL_CU_CTX_SCHED_BLOCKING_SYNC 0x04 - -/** - * Support compute capability 3.0 and later - */ - -#define GRAAL_SUPPORTED_COMPUTE_CAPABILITY_VERSION 3.0 - -class Ptx : public Gpu { - friend class PtxCall; - -private: - - static JNINativeMethod PTX_methods[]; - - // static native boolean initialize(); - JNIEXPORT static jboolean JNICALL initialize(JNIEnv* env, jclass); - - // static native long generateKernel(byte[] targetCode, String name); - JNIEXPORT static jlong JNICALL generate_kernel(JNIEnv *env, jclass, jbyteArray code_handle, jstring name_handle); - - // static native long getLaunchKernelAddress(); - JNIEXPORT static jlong JNICALL get_execute_kernel_from_vm_address(JNIEnv *env, jclass); - - // static native int getAvailableProcessors0(); - JNIEXPORT static jint JNICALL get_total_cores(JNIEnv *env, jobject); - - JNIEXPORT static void JNICALL destroy_ptx_context(); - - // Links the CUDA driver library functions - static bool link(); - - static int ncores(int major, int minor); - -public: - - virtual const char* name() { return "PTX"; } - - // Registers the implementations for the native methods in PTXHotSpotBackend - static bool register_natives(JNIEnv* env); - -#if defined(__x86_64) || defined(AMD64) || defined(_M_AMD64) - typedef unsigned long long CUdeviceptr; -#else - typedef unsigned int CUdeviceptr; -#endif - -typedef int CUdevice; /* CUDA device */ - - static jlong execute_kernel_from_vm(JavaThread* thread, jlong kernel, jint dimX, jint dimY, jint dimZ, - jlong buffer, - jint bufferSize, - jint objectParametersCount, - jlong objectParametersOffsets, - jlong pinnedObjects, - int encodedReturnTypeSize); - -private: - typedef int (*cuda_cu_init_func_t)(unsigned int); - typedef int (*cuda_cu_ctx_create_func_t)(void*, unsigned int, CUdevice); - typedef int (*cuda_cu_ctx_destroy_func_t)(void*); - typedef int (*cuda_cu_ctx_synchronize_func_t)(void); - typedef int (*cuda_cu_ctx_get_current_func_t)(void*); - typedef int (*cuda_cu_ctx_set_current_func_t)(void*); - typedef int (*cuda_cu_device_get_count_func_t)(int*); - typedef int (*cuda_cu_device_get_name_func_t)(char*, int, int); - typedef int (*cuda_cu_device_get_func_t)(int*, int); - typedef int (*cuda_cu_device_compute_capability_func_t)(int*, int*, int); - typedef int (*cuda_cu_device_get_attribute_func_t)(int*, int, int); - typedef int (*cuda_cu_launch_kernel_func_t)(struct CUfunc_st*, - unsigned int, unsigned int, unsigned int, - unsigned int, unsigned int, unsigned int, - unsigned int, void*, void**, void**); - typedef int (*cuda_cu_module_get_function_func_t)(void*, void*, const char*); - typedef int (*cuda_cu_module_load_data_ex_func_t)(void*, void*, unsigned int, void*, void**); - typedef int (*cuda_cu_memalloc_func_t)(Ptx::CUdeviceptr*, size_t); - typedef int (*cuda_cu_memfree_func_t)(Ptx::CUdeviceptr); - typedef int (*cuda_cu_memcpy_htod_func_t)(Ptx::CUdeviceptr, const void*, unsigned int); - typedef int (*cuda_cu_memcpy_dtoh_func_t)(const void*, Ptx::CUdeviceptr, unsigned int); - typedef int (*cuda_cu_mem_host_register_func_t)(void*, size_t, unsigned int); - typedef int (*cuda_cu_mem_host_get_device_pointer_func_t)(Ptx::CUdeviceptr*, void*, unsigned int); - typedef int (*cuda_cu_mem_host_unregister_func_t)(void*); - -public: - static cuda_cu_init_func_t _cuda_cu_init; - static cuda_cu_ctx_create_func_t _cuda_cu_ctx_create; - static cuda_cu_ctx_destroy_func_t _cuda_cu_ctx_destroy; - static cuda_cu_ctx_synchronize_func_t _cuda_cu_ctx_synchronize; - static cuda_cu_device_get_count_func_t _cuda_cu_device_get_count; - static cuda_cu_device_get_name_func_t _cuda_cu_device_get_name; - static cuda_cu_device_get_func_t _cuda_cu_device_get; - static cuda_cu_device_compute_capability_func_t _cuda_cu_device_compute_capability; /* Deprecated as of CUDA 5.0 */ - static cuda_cu_device_get_attribute_func_t _cuda_cu_device_get_attribute; - static cuda_cu_launch_kernel_func_t _cuda_cu_launch_kernel; - static cuda_cu_module_get_function_func_t _cuda_cu_module_get_function; - static cuda_cu_module_load_data_ex_func_t _cuda_cu_module_load_data_ex; - static cuda_cu_memalloc_func_t _cuda_cu_memalloc; - static cuda_cu_memfree_func_t _cuda_cu_memfree; - static cuda_cu_memcpy_htod_func_t _cuda_cu_memcpy_htod; - static cuda_cu_memcpy_dtoh_func_t _cuda_cu_memcpy_dtoh; - static cuda_cu_ctx_get_current_func_t _cuda_cu_ctx_get_current; - static cuda_cu_ctx_set_current_func_t _cuda_cu_ctx_set_current; - static cuda_cu_mem_host_register_func_t _cuda_cu_mem_host_register; - static cuda_cu_mem_host_get_device_pointer_func_t _cuda_cu_mem_host_get_device_pointer; - static cuda_cu_mem_host_unregister_func_t _cuda_cu_mem_host_unregister; - -protected: - static void* _device_context; - static int _cu_device; -}; -#endif // GPU_PTX_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/os/bsd/vm/gpu_bsd.cpp --- a/src/os/bsd/vm/gpu_bsd.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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. - * - */ - -#include "runtime/gpu.hpp" -#include "ptx/vm/gpu_ptx.hpp" -#include "hsail/vm/gpu_hsail.hpp" -#include "utilities/ostream.hpp" - -jobject Gpu::probe_gpus(JNIEnv* env) { -#ifdef __APPLE__ - /* - * Let the CUDA driver initialization be the gate to GPU for now, pending - * a better detection solution for NVIDA PTX and AMD HSAIL. - */ - if (Ptx::register_natives(env)) { - if (TraceGPUInteraction) { - tty->print_cr("Assuming NVidia/PTX support (APPLE)"); - } - return env->NewStringUTF("PTX"); - } -#else - if (TraceGPUInteraction) { - tty->print_cr("Assuming no GPU (not APPLE)"); - } -#endif - return env->NewStringUTF(""); -} - diff -r c8fc6e2d128b -r 8f2fb6bec986 src/os/linux/vm/gpu_linux.cpp --- a/src/os/linux/vm/gpu_linux.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * 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. - * - */ - -#include "runtime/gpu.hpp" -#include "ptx/vm/gpu_ptx.hpp" -#include "hsail/vm/gpu_hsail.hpp" -#include "utilities/ostream.hpp" - -/* - * Probe for CUDA device on PCI bus using /proc/bus/pci/devices. Do - * not rely on CUDA tool kit being installed. We will check if CUDA - * library is installed later. - */ - -static unsigned int nvidia_vendor_id = 0x10de; -static unsigned int amd_vendor_id = 0x1002; - -#define PCI_DRIVER_NAME_START_POS 255 - -jobject Gpu::probe_gpus(JNIEnv* env) { - bool hsail = false; - bool ptx = false; - - if (Hsail::register_natives(env)) { - hsail = true; - } - - /* - * Open /proc/bus/pci/devices to look for the first GPU device. For - * now, we will just find the first GPU device. Will need to revisit - * this to support execution on multiple GPU devices, if they exist. - */ - FILE *pci_devices = fopen("/proc/bus/pci/devices", "r"); - char contents[4096]; - unsigned int bus_num_devfn_ign; - unsigned int vendor; - unsigned int device; - const char *driver_name_string = "nvidia"; - const int driver_name_string_len = strlen(driver_name_string); - - if (pci_devices == NULL) { - tty->print_cr("*** Failed to open /proc/bus/pci/devices"); - return NULL; - } - - while (fgets(contents, sizeof(contents)-1, pci_devices)) { - sscanf(contents, "%04x%04x%04x", &bus_num_devfn_ign, &vendor, &device); - if (vendor == nvidia_vendor_id) { - /* Check if this device is registered to be using nvidia driver */ - if (strncmp(&contents[PCI_DRIVER_NAME_START_POS], - driver_name_string, driver_name_string_len) == 0) { - if (TraceGPUInteraction) { - tty->print_cr("Found supported nVidia device [vendor=0x%04x, device=0x%04x]", vendor, device); - } - if (!ptx && Ptx::register_natives(env)) { - ptx = true; - } - } - } - } - - // Close file pointer. - fclose(pci_devices); - - const char* gpus = ""; - if (ptx && hsail) { - gpus = "PTX,HSAIL"; - } else if (ptx) { - gpus = "PTX"; - } else if (hsail) { - gpus = "HSAIL"; - } - return env->NewStringUTF(gpus); -} diff -r c8fc6e2d128b -r 8f2fb6bec986 src/os/windows/vm/gpu_windows.cpp --- a/src/os/windows/vm/gpu_windows.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * 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. - * - */ - -#include "precompiled.hpp" -#include "runtime/gpu.hpp" -#include "hsail/vm/gpu_hsail.hpp" -#include "utilities/ostream.hpp" - -jobject Gpu::probe_gpus(JNIEnv* env) { - // TODO: add detection of PTX/NVidia - if (Hsail::register_natives(env)) { - return env->NewStringUTF("HSAIL"); - } - return env->NewStringUTF(""); -} diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/classfile/javaClasses.cpp --- a/src/share/vm/classfile/javaClasses.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/classfile/javaClasses.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -1566,18 +1566,6 @@ return; } -#ifdef GRAAL - // Check for gpu exception to add as top frame - Method* gpu_method = thread->get_gpu_exception_method(); - if (gpu_method != NULL) { - jint gpu_bci = thread->get_gpu_exception_bci(); - bt.push(gpu_method, gpu_bci, CHECK); - // Clear the gpu exception state, it is not used after here - thread->set_gpu_exception_bci(0); - thread->set_gpu_exception_method(NULL); - } -#endif - // Instead of using vframe directly, this version of fill_in_stack_trace // basically handles everything by hand. This significantly improved the // speed of this method call up to 28.5% on Solaris sparc. 27.1% on Windows. diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/classfile/systemDictionary.hpp --- a/src/share/vm/classfile/systemDictionary.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/classfile/systemDictionary.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -223,7 +223,6 @@ GRAAL_ONLY(do_klass(CompilationResult_Mark_klass, com_oracle_graal_api_code_CompilationResult_Mark, Graal)) \ GRAAL_ONLY(do_klass(CompilationResult_Infopoint_klass, com_oracle_graal_api_code_CompilationResult_Infopoint, Graal)) \ GRAAL_ONLY(do_klass(CompilationResult_Site_klass, com_oracle_graal_api_code_CompilationResult_Site, Graal)) \ - GRAAL_ONLY(do_klass(ExternalCompilationResult_klass, com_oracle_graal_gpu_ExternalCompilationResult, Graal)) \ GRAAL_ONLY(do_klass(InfopointReason_klass, com_oracle_graal_api_code_InfopointReason, Graal)) \ GRAAL_ONLY(do_klass(InstalledCode_klass, com_oracle_graal_api_code_InstalledCode, Graal)) \ GRAAL_ONLY(do_klass(code_Register_klass, com_oracle_graal_api_code_Register, Graal)) \ diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/classfile/vmSymbols.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -349,7 +349,6 @@ GRAAL_ONLY(template(com_oracle_graal_api_code_RegisterSaveLayout, "com/oracle/graal/api/code/RegisterSaveLayout")) \ GRAAL_ONLY(template(com_oracle_graal_api_code_InvalidInstalledCodeException, "com/oracle/graal/api/code/InvalidInstalledCodeException")) \ GRAAL_ONLY(template(com_oracle_graal_api_code_SpeculationLog, "com/oracle/graal/api/code/SpeculationLog")) \ - GRAAL_ONLY(template(com_oracle_graal_gpu_ExternalCompilationResult, "com/oracle/graal/gpu/ExternalCompilationResult")) \ GRAAL_ONLY(template(compileMetaspaceMethod_name, "compileMetaspaceMethod")) \ GRAAL_ONLY(template(compileMetaspaceMethod_signature, "(JIJI)V")) \ GRAAL_ONLY(template(graal_mirror_name, "graal_mirror")) \ diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/code/nmethod.hpp --- a/src/share/vm/code/nmethod.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/code/nmethod.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -182,7 +182,6 @@ unsigned int _has_method_handle_invokes:1; // Has this method MethodHandle invokes? unsigned int _lazy_critical_native:1; // Lazy JNI critical native unsigned int _has_wide_vectors:1; // Preserve wide vectors at safepoints - unsigned int _external_method:1; // Set for GPU methods // Protected by Patching_lock volatile unsigned char _state; // {alive, not_entrant, zombie, unloaded} @@ -477,9 +476,6 @@ bool has_method_handle_invokes() const { return _has_method_handle_invokes; } void set_has_method_handle_invokes(bool z) { _has_method_handle_invokes = z; } - bool is_external_method() const { return _external_method; } - void set_external_method(bool z) { _external_method = z; } - bool is_lazy_critical_native() const { return _lazy_critical_native; } void set_lazy_critical_native(bool z) { _lazy_critical_native = z; } diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/gc_interface/collectedHeap.cpp --- a/src/share/vm/gc_interface/collectedHeap.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/gc_interface/collectedHeap.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -526,12 +526,7 @@ "Attempt to fill tlabs before main thread has been added" " to threads list is doomed to failure!"); for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) { - if (use_tlab) { - thread->tlab().make_parsable(retire_tlabs); -#ifdef GRAAL - thread->gpu_hsail_tlabs_make_parsable(retire_tlabs); -#endif - } + if (use_tlab) thread->tlab().make_parsable(retire_tlabs); #if defined(COMPILER2) || defined(GRAAL) // The deferred store barriers must all have been flushed to the // card-table (or other remembered set structure) before GC starts diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/gc_interface/collectedHeap.hpp --- a/src/share/vm/gc_interface/collectedHeap.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/gc_interface/collectedHeap.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -84,7 +84,6 @@ class CollectedHeap : public CHeapObj { friend class VMStructs; friend class IsGCActiveMark; // Block structured external access to _is_gc_active - friend class HSAILAllocationInfo; // access to allocate_new_tlab #ifdef ASSERT static int _fire_out_of_memory_count; diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -43,7 +43,6 @@ #include "runtime/vframe.hpp" #include "runtime/vframe_hp.hpp" #include "runtime/vmStructs.hpp" -#include "runtime/gpu.hpp" // Entry to native method implementation that transitions current thread to '_thread_in_vm'. @@ -477,12 +476,7 @@ InstalledCode::set_address(installed_code_handle, (jlong) cb); InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1); oop comp_result = HotSpotCompiledCode::comp(compiled_code_handle); - if (comp_result->is_a(ExternalCompilationResult::klass())) { - if (TraceGPUInteraction) { - tty->print_cr("installCode0: ExternalCompilationResult"); - } - HotSpotInstalledCode::set_codeStart(installed_code_handle, ExternalCompilationResult::entryPoint(comp_result)); - } else if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) { + if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) { HotSpotInstalledCode::set_size(installed_code_handle, cb->size()); HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin()); HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size()); @@ -716,18 +710,6 @@ return (jlongArray) JNIHandles::make_local(arrayOop); C2V_END -// In general we should avoid using regular JNI methods to interact with the JVM but this -// particular case is just about registering JNI methods so it should be a regular native -// method. -JNIEXPORT jobject JNICALL c2v_getGPUs (JNIEnv* env, jobject) { - TRACE_graal_3("CompilerToVM::getGPUs" ); -#if defined(TARGET_OS_FAMILY_bsd) || defined(TARGET_OS_FAMILY_linux) || defined(TARGET_OS_FAMILY_windows) - return Gpu::probe_gpus(env); -#else - return env->NewStringUTF(""); -#endif -} - C2V_VMENTRY(int, allocateCompileId, (JNIEnv*, jobject, jlong metaspace_method, int entry_bci)) HandleMark hm; ResourceMark rm; @@ -1091,7 +1073,6 @@ {CC"readUnsafeKlassPointer", CC"("OBJECT")J", FN_PTR(readUnsafeKlassPointer)}, {CC"readUnsafeOop", CC"("OBJECT"JZ)"OBJECT, FN_PTR(readUnsafeOop)}, {CC"collectCounters", CC"()[J", FN_PTR(collectCounters)}, - {CC"getGPUs", CC"()"STRING, FN_PTR(getGPUs)}, {CC"allocateCompileId", CC"("METASPACE_METHOD"I)I", FN_PTR(allocateCompileId)}, {CC"isMature", CC"("METASPACE_METHOD_DATA")Z", FN_PTR(isMature)}, {CC"hasCompiledCodeForOSR", CC"("METASPACE_METHOD"II)Z", FN_PTR(hasCompiledCodeForOSR)}, diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/graal/graalEnv.cpp --- a/src/share/vm/graal/graalEnv.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/graal/graalEnv.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -556,10 +556,6 @@ } } - - if (TraceGPUInteraction && HotSpotNmethod::isExternal(installed_code())) { - tty->print_cr("External method:%s", method()->name_and_sig_as_C_string()); - } } } // JVMTI -- compiled method notification (must be done outside lock) diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/graal/graalGlobals.hpp --- a/src/share/vm/graal/graalGlobals.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/graal/graalGlobals.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -96,19 +96,6 @@ \ develop(bool, TraceUncollectedSpeculations, false, \ "Print message when a failed speculation was not collected") \ - \ - product(bool, UseHSAILDeoptimization, true, \ - "Code gen and runtime support for deoptimizing HSAIL kernels") \ - \ - product(bool, UseHSAILSafepoints, true, \ - "Code gen and runtime support for safepoints in HSAIL kernels") \ - \ - product(bool, GPUOffload, false, \ - "Offload execution to GPU whenever possible") \ - \ - product(bool, TraceGPUInteraction, false, \ - "Trace external GPU Interaction") \ - \ // Read default values for Graal globals diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/graal/graalJavaAccess.hpp --- a/src/share/vm/graal/graalJavaAccess.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/graal/graalJavaAccess.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -66,7 +66,6 @@ end_class \ start_class(HotSpotNmethod) \ boolean_field(HotSpotNmethod, isDefault) \ - boolean_field(HotSpotNmethod, isExternal) \ end_class \ start_class(HotSpotCompiledCode) \ oop_field(HotSpotCompiledCode, comp, "Lcom/oracle/graal/api/code/CompilationResult;") \ @@ -93,9 +92,6 @@ start_class(HotSpotForeignCallLinkageImpl) \ long_field(HotSpotForeignCallLinkageImpl, address) \ end_class \ - start_class(ExternalCompilationResult) \ - long_field(ExternalCompilationResult, entryPoint) \ - end_class \ start_class(CompilationResult) \ int_field(CompilationResult, totalFrameSize) \ int_field(CompilationResult, customStackAreaOffset) \ diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/memory/threadLocalAllocBuffer.cpp --- a/src/share/vm/memory/threadLocalAllocBuffer.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/memory/threadLocalAllocBuffer.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -54,13 +54,6 @@ for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) { thread->tlab().accumulate_statistics(); thread->tlab().initialize_statistics(); -#ifdef GRAAL - for (jint i = 0; i < thread->get_gpu_hsail_tlabs_count(); i++) { - thread->get_gpu_hsail_tlab_at(i)->accumulate_statistics(); - thread->get_gpu_hsail_tlab_at(i)->initialize_statistics(); - } -#endif - } // Publish new stats if some allocation occurred. @@ -147,11 +140,6 @@ if (ResizeTLAB) { for (JavaThread *thread = Threads::first(); thread != NULL; thread = thread->next()) { thread->tlab().resize(); -#ifdef GRAAL - for (jint i = 0; i < thread->get_gpu_hsail_tlabs_count(); i++) { - thread->get_gpu_hsail_tlab_at(i)->resize(); - } -#endif } } } @@ -209,12 +197,11 @@ invariants(); } -void ThreadLocalAllocBuffer::initialize(Thread* owning_thread) { +void ThreadLocalAllocBuffer::initialize() { initialize(NULL, // start NULL, // top NULL); // end - _owning_thread = owning_thread; set_desired_size(initial_desired_size()); // Following check is needed because at startup the main (primordial) @@ -243,7 +230,7 @@ // During jvm startup, the main (primordial) thread is initialized // before the heap is initialized. So reinitialize it now. guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread"); - Thread::current()->tlab().initialize(Thread::current()); + Thread::current()->tlab().initialize(); if (PrintTLAB && Verbose) { gclog_or_tty->print("TLAB min: " SIZE_FORMAT " initial: " SIZE_FORMAT " max: " SIZE_FORMAT "\n", @@ -307,7 +294,9 @@ } Thread* ThreadLocalAllocBuffer::myThread() { - return _owning_thread; + return (Thread*)(((char *)this) + + in_bytes(start_offset()) - + in_bytes(Thread::tlab_start_offset())); } diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/memory/threadLocalAllocBuffer.hpp --- a/src/share/vm/memory/threadLocalAllocBuffer.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/memory/threadLocalAllocBuffer.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -38,9 +38,6 @@ // used to make it available for such multiplexing. class ThreadLocalAllocBuffer: public CHeapObj { friend class VMStructs; -#ifdef GRAAL - friend class HSAILAllocationInfo; -#endif private: HeapWord* _start; // address of TLAB HeapWord* _top; // address after last allocation @@ -58,7 +55,6 @@ unsigned _slow_refill_waste; unsigned _gc_waste; unsigned _slow_allocations; - Thread* _owning_thread; AdaptiveWeightedAverage _allocation_fraction; // fraction of eden allocated in tlabs @@ -160,7 +156,7 @@ static void resize_all_tlabs(); void fill(HeapWord* start, HeapWord* top, size_t new_size); - void initialize(Thread* owning_thread); + void initialize(); static size_t refill_waste_limit_increment() { return TLABWasteIncrement; } diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/compilationPolicy.cpp --- a/src/share/vm/runtime/compilationPolicy.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/compilationPolicy.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -45,9 +45,6 @@ #include "runtime/vm_operations.hpp" #include "utilities/events.hpp" #include "utilities/globalDefinitions.hpp" -#ifdef GRAAL -#include "runtime/gpu.hpp" -#endif CompilationPolicy* CompilationPolicy::_policy; elapsedTimer CompilationPolicy::_accumulated_time; diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/gpu.cpp --- a/src/share/vm/runtime/gpu.cpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * 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. - * - */ - -#include "precompiled.hpp" -#include "runtime/gpu.hpp" -#include "runtime/handles.hpp" - -int Gpu::_initialized_gpus_count = 0; -Gpu* Gpu::_initialized_gpus[MAX_GPUS]; - -void Gpu::initialized_gpu(Gpu* gpu) { - // GPUs are always initialized on the same thread so no need for locking - guarantee(_initialized_gpus_count < MAX_GPUS, "oob"); - _initialized_gpus[_initialized_gpus_count++] = gpu; - if (TraceGPUInteraction) { - tty->print_cr("[GPU] registered initialization of %s (total initialized: %d)", gpu->name(), _initialized_gpus_count); - } -} - -void Gpu::safepoint_event(SafepointEvent event) { - for (int i = 0; i < _initialized_gpus_count; i++) { - if (event == SafepointBegin) { - _initialized_gpus[i]->notice_safepoints(); - } else { - _initialized_gpus[i]->ignore_safepoints(); - } - } -} diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/gpu.hpp --- a/src/share/vm/runtime/gpu.hpp Thu Jan 22 23:16:17 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * 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. - * - */ - -#ifndef SHARE_VM_RUNTIME_GPU_HPP -#define SHARE_VM_RUNTIME_GPU_HPP - -#include "runtime/atomic.hpp" -#include "oops/symbol.hpp" -#include "utilities/array.hpp" - -#define MAX_GPUS 2 - -// Defines the interface to the graphics processor(s). -class Gpu : public CHeapObj { - private: - static int _initialized_gpus_count; - static Gpu* _initialized_gpus[MAX_GPUS]; - - public: - - // Notification of a GPU device that has been initialized. - static void initialized_gpu(Gpu* gpu); - - // Gets a comma separated list of supported GPU architecture names. - static jobject probe_gpus(JNIEnv* env); - - // Gets the number of GPU devices that have been initialized. - static int initialized_gpus() { return _initialized_gpus_count; } - - enum SafepointEvent { - SafepointBegin, - SafepointEnd - }; - - // Called when a safepoint has been activated. - static void safepoint_event(SafepointEvent event); - - // Name of this GPU - virtual const char* name() = 0; - - // Called when a safepoint has been activated. - virtual void notice_safepoints() {}; - - // Called when a safepoint has been deactivated. - virtual void ignore_safepoints() {}; -}; - -#endif // SHARE_VM_RUNTIME_GPU_HPP diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/javaCalls.cpp --- a/src/share/vm/runtime/javaCalls.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/javaCalls.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -48,7 +48,7 @@ // ----------------------------------------------------- // Implementation of JavaCallWrapper -JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, JavaValue* result, TRAPS) { +JavaCallWrapper::JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS) { JavaThread* thread = (JavaThread *)THREAD; bool clear_pending_exception = true; @@ -79,9 +79,10 @@ // Make sure to set the oop's after the thread transition - since we can block there. No one is GC'ing // the JavaCallWrapper before the entry frame is on the stack. _callee_method = callee_method(); + _receiver = receiver(); #ifdef CHECK_UNHANDLED_OOPS - // THREAD->allow_unhandled_oop(&_receiver); + THREAD->allow_unhandled_oop(&_receiver); #endif // CHECK_UNHANDLED_OOPS _thread = (JavaThread *)thread; @@ -145,6 +146,7 @@ void JavaCallWrapper::oops_do(OopClosure* f) { + f->do_oop((oop*)&_receiver); handles()->oops_do(f); } @@ -321,7 +323,7 @@ // Check if we need to wrap a potential OS exception handler around thread // This is used for e.g. Win32 structured exception handlers assert(THREAD->is_Java_thread(), "only JavaThreads can make JavaCalls"); - // Need to wrap each and everytime, since there might be native code down the + // Need to wrap each and every time, since there might be native code down the // stack that has installed its own exception handlers os::os_exception_wrapper(call_helper, result, &method, args, THREAD); } @@ -337,25 +339,18 @@ CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops();) -#ifdef GRAAL - nmethod* nm = args->alternative_target(); - if (nm == NULL) { -#endif // Verify the arguments if (CheckJNICalls) { args->verify(method, result->get_type(), thread); } else debug_only(args->verify(method, result->get_type(), thread)); -#ifdef GRAAL - } -#else + // Ignore call if method is empty if (method->is_empty_method()) { assert(result->get_type() == T_VOID, "an empty method must return a void value"); return; } -#endif #ifdef ASSERT @@ -363,7 +358,7 @@ // A klass might not be initialized since JavaCall's might be used during the executing of // the . For example, a Thread.start might start executing on an object that is // not fully initialized! (bad Java programming style) - assert(holder->is_linked(), "rewritting must have taken place"); + assert(holder->is_linked(), "rewriting must have taken place"); } #endif @@ -392,6 +387,9 @@ // the call to call_stub, the optimizer produces wrong code. intptr_t* result_val_address = (intptr_t*)(result->get_value_addr()); + // Find receiver + Handle receiver = (!method->is_static()) ? args->receiver() : Handle(); + // When we reenter Java, we need to reenable the yellow zone which // might already be disabled when we are in VM. if (thread->stack_yellow_zone_disabled()) { @@ -410,15 +408,11 @@ } #ifdef GRAAL + nmethod* nm = args->alternative_target(); if (nm != NULL) { if (nm->is_alive()) { ((JavaThread*) THREAD)->set_graal_alternate_call_target(nm->verified_entry_point()); - oop graalInstalledCode = nm->graal_installed_code(); - if (graalInstalledCode != NULL && graalInstalledCode->is_a(HotSpotNmethod::klass()) && HotSpotNmethod::isExternal(graalInstalledCode)) { - entry_point = GraalRuntime::get_external_deopt_i2c_entry(); - } else { - entry_point = method->adapter()->get_i2c_entry(); - } + entry_point = method->adapter()->get_i2c_entry(); } else { THROW(vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException()); } @@ -426,7 +420,7 @@ #endif // do call - { JavaCallWrapper link(method, result, CHECK); + { JavaCallWrapper link(method, receiver, result, CHECK); { HandleMark hm(thread); // HandleMark used by HandleMarkCleaner StubRoutines::call_stub()( diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/javaCalls.hpp --- a/src/share/vm/runtime/javaCalls.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/javaCalls.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -57,6 +57,7 @@ JavaThread* _thread; // the thread to which this call belongs JNIHandleBlock* _handles; // the saved handle block Method* _callee_method; // to be able to collect arguments if entry frame is top frame + oop _receiver; // the receiver of the call (if a non-static call) JavaFrameAnchor _anchor; // last thread anchor state that we must restore @@ -64,7 +65,7 @@ public: // Construction/destruction - JavaCallWrapper(methodHandle callee_method, JavaValue* result, TRAPS); + JavaCallWrapper(methodHandle callee_method, Handle receiver, JavaValue* result, TRAPS); ~JavaCallWrapper(); // Accessors @@ -76,6 +77,7 @@ JavaValue* result() const { return _result; } // GC support Method* callee_method() { return _callee_method; } + oop receiver() { return _receiver; } void oops_do(OopClosure* f); bool is_first_frame() const { return _anchor.last_Java_sp() == NULL; } diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/safepoint.cpp --- a/src/share/vm/runtime/safepoint.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/safepoint.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -39,7 +39,6 @@ #include "runtime/compilationPolicy.hpp" #include "runtime/deoptimization.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/gpu.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/osThread.hpp" @@ -208,12 +207,6 @@ os::make_polling_page_unreadable(); } -#ifdef GRAAL - if (UseHSAILSafepoints) { - Gpu::safepoint_event(Gpu::SafepointBegin); - } -#endif - // Consider using active_processor_count() ... but that call is expensive. int ncpus = os::processor_count() ; @@ -447,12 +440,6 @@ // Remove safepoint check from interpreter Interpreter::ignore_safepoints(); -#ifdef GRAAL - if (UseHSAILSafepoints) { - Gpu::safepoint_event(Gpu::SafepointEnd); - } -#endif - { MutexLocker mu(Safepoint_lock); diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/thread.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -54,10 +54,6 @@ #include "runtime/deoptimization.hpp" #include "runtime/fprofiler.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/gpu.hpp" -#ifdef GRAAL -# include "hsail/vm/gpu_hsail.hpp" -#endif #include "runtime/init.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" @@ -1479,13 +1475,6 @@ clear_must_deopt_id(); set_monitor_chunks(NULL); set_next(NULL); -#ifdef GRAAL - set_gpu_exception_bci(0); - set_gpu_exception_method(NULL); - set_gpu_hsail_deopt_info(NULL); - _gpu_hsail_tlabs_count = 0; - _gpu_hsail_tlabs = NULL; -#endif set_thread_state(_thread_new); #if INCLUDE_NMT set_recorder(NULL); @@ -1704,8 +1693,6 @@ } FREE_C_HEAP_ARRAY(jlong, _graal_counters, mtInternal); } - - delete_gpu_hsail_tlabs(); #endif // GRAAL } @@ -1980,7 +1967,7 @@ remove_stack_guard_pages(); if (UseTLAB) { - tlabs_make_parsable(true); // retire TLABs, if any + tlab().make_parsable(true); // retire TLAB } if (JvmtiEnv::environments_might_exist()) { @@ -2059,7 +2046,7 @@ remove_stack_guard_pages(); if (UseTLAB) { - tlabs_make_parsable(true); // retire TLABs, if any + tlab().make_parsable(true); // retire TLAB, if any } #if INCLUDE_ALL_GCS @@ -2865,13 +2852,6 @@ // a scan. cf->do_code_blob(_scanned_nmethod); } - -#ifdef GRAAL - Hsail::HSAILDeoptimizationInfo* gpu_hsail_deopt_info = (Hsail::HSAILDeoptimizationInfo*) get_gpu_hsail_deopt_info(); - if (gpu_hsail_deopt_info != NULL) { - gpu_hsail_deopt_info->oops_do(f); - } -#endif } void JavaThread::nmethods_do(CodeBlobClosure* cf) { @@ -4791,54 +4771,3 @@ VMThread* thread = VMThread::vm_thread(); if (thread != NULL) thread->verify(); } - -void JavaThread::tlabs_make_parsable(bool retire) { - // do the primary tlab for this thread - tlab().make_parsable(retire); -#ifdef GRAAL - // do the gpu_hsail tlabs if any - gpu_hsail_tlabs_make_parsable(retire); -#endif -} - - -#ifdef GRAAL -void JavaThread::initialize_gpu_hsail_tlabs(jint count) { - if (!UseTLAB) return; - // create tlabs - _gpu_hsail_tlabs = NEW_C_HEAP_ARRAY(ThreadLocalAllocBuffer*, count, mtInternal); - // initialize - for (jint i = 0; i < count; i++) { - _gpu_hsail_tlabs[i] = new ThreadLocalAllocBuffer(); - _gpu_hsail_tlabs[i]->initialize(Thread::current()); - } - _gpu_hsail_tlabs_count = count; -} - -ThreadLocalAllocBuffer* JavaThread::get_gpu_hsail_tlab_at(jint idx) { - assert(idx >= 0 && idx < get_gpu_hsail_tlabs_count(), "illegal gpu tlab index"); - return _gpu_hsail_tlabs[idx]; -} - -void JavaThread::gpu_hsail_tlabs_make_parsable(bool retire) { - for (jint i = 0; i < get_gpu_hsail_tlabs_count(); i++) { - get_gpu_hsail_tlab_at(i)->make_parsable(retire); - } -} - -void JavaThread::delete_gpu_hsail_tlabs() { - if (!UseTLAB) return; - if (_gpu_hsail_tlabs_count == 0) return; - - gpu_hsail_tlabs_make_parsable(true); - for (jint i = 0; i < get_gpu_hsail_tlabs_count(); i++) { - delete get_gpu_hsail_tlab_at(i); - } - FREE_C_HEAP_ARRAY(ThreadLocalAllocBuffer*, _gpu_hsail_tlabs, mtInternal); - _gpu_hsail_tlabs = NULL; - _gpu_hsail_tlabs_count = 0; -} - - -#endif - diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/thread.hpp --- a/src/share/vm/runtime/thread.hpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/thread.hpp Fri Jan 23 10:54:21 2015 +0100 @@ -432,7 +432,7 @@ ThreadLocalAllocBuffer& tlab() { return _tlab; } void initialize_tlab() { if (UseTLAB) { - tlab().initialize(this); + tlab().initialize(); } } @@ -944,36 +944,7 @@ volatile address _exception_handler_pc; // PC for handler of exception volatile int _is_method_handle_return; // true (== 1) if the current exception PC is a MethodHandle call site. -#ifdef GRAAL - // Record the method and bci from a gpu kernel exception so - // it can be added into the exception stack trace - jint _gpu_exception_bci; - Method* _gpu_exception_method; - // Record the hsailDeoptimization info so gc oops_do processing can find it - void* _gpu_hsail_deopt_info; - jint _gpu_hsail_tlabs_count; - ThreadLocalAllocBuffer** _gpu_hsail_tlabs; -#endif - - public: -#ifdef GRAAL - void set_gpu_exception_bci(jint bci) { _gpu_exception_bci = bci; } - jint get_gpu_exception_bci() { return _gpu_exception_bci; } - void set_gpu_exception_method(Method* method) { _gpu_exception_method = method; } - Method* get_gpu_exception_method() { return _gpu_exception_method; } - void set_gpu_hsail_deopt_info(void * deoptInfo) { _gpu_hsail_deopt_info = deoptInfo; } - void* get_gpu_hsail_deopt_info() { return _gpu_hsail_deopt_info; } - jint get_gpu_hsail_tlabs_count() { return _gpu_hsail_tlabs_count; } - - void initialize_gpu_hsail_tlabs(jint count); - ThreadLocalAllocBuffer* get_gpu_hsail_tlab_at(jint idx); - void gpu_hsail_tlabs_make_parsable(bool retire); - void delete_gpu_hsail_tlabs(); -#endif - private: - void tlabs_make_parsable(bool retire); - // support for JNI critical regions jint _jni_active_critical; // count of entries into JNI critical region diff -r c8fc6e2d128b -r 8f2fb6bec986 src/share/vm/runtime/vmStructs.cpp --- a/src/share/vm/runtime/vmStructs.cpp Thu Jan 22 23:16:17 2015 +0100 +++ b/src/share/vm/runtime/vmStructs.cpp Fri Jan 23 10:54:21 2015 +0100 @@ -93,7 +93,6 @@ #include "runtime/deoptimization.hpp" #include "runtime/vframeArray.hpp" #include "runtime/globals.hpp" -#include "runtime/gpu.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" #include "runtime/perfMemory.hpp" @@ -110,7 +109,6 @@ #ifdef GRAAL # include "graal/graalRuntime.hpp" # include "graal/vmStructs_graal.hpp" -# include "hsail/vm/vmStructs_hsail.hpp" #endif #ifdef TARGET_ARCH_x86 # include "vmStructs_x86.hpp" @@ -3054,10 +3052,6 @@ GENERATE_C1_UNCHECKED_STATIC_VM_STRUCT_ENTRY, GENERATE_C2_UNCHECKED_STATIC_VM_STRUCT_ENTRY) -#ifdef GRAAL - VM_STRUCTS_GPU_HSAIL(GENERATE_NONSTATIC_VM_STRUCT_ENTRY) -#endif - VM_STRUCTS_OS_CPU(GENERATE_NONSTATIC_VM_STRUCT_ENTRY, GENERATE_STATIC_VM_STRUCT_ENTRY, GENERATE_UNCHECKED_NONSTATIC_VM_STRUCT_ENTRY, @@ -3108,11 +3102,6 @@ GENERATE_C2_VM_TYPE_ENTRY, GENERATE_C2_TOPLEVEL_VM_TYPE_ENTRY) -#ifdef GRAAL - VM_TYPES_GPU_HSAIL(GENERATE_VM_TYPE_ENTRY, - GENERATE_TOPLEVEL_VM_TYPE_ENTRY) -#endif - VM_TYPES_OS_CPU(GENERATE_VM_TYPE_ENTRY, GENERATE_TOPLEVEL_VM_TYPE_ENTRY, GENERATE_OOP_VM_TYPE_ENTRY, @@ -3218,10 +3207,6 @@ CHECK_NO_OP, CHECK_NO_OP); -#ifdef GRAAL - VM_STRUCTS_GPU_HSAIL(CHECK_NONSTATIC_VM_STRUCT_ENTRY) -#endif - VM_STRUCTS_OS_CPU(CHECK_NONSTATIC_VM_STRUCT_ENTRY, CHECK_STATIC_VM_STRUCT_ENTRY, CHECK_NO_OP, @@ -3262,11 +3247,6 @@ CHECK_C2_VM_TYPE_ENTRY, CHECK_C2_TOPLEVEL_VM_TYPE_ENTRY); -#ifdef GRAAL - VM_TYPES_GPU_HSAIL(CHECK_VM_TYPE_ENTRY, - CHECK_SINGLE_ARG_VM_TYPE_NO_OP); -#endif - VM_TYPES_OS_CPU(CHECK_VM_TYPE_ENTRY, CHECK_SINGLE_ARG_VM_TYPE_NO_OP, CHECK_SINGLE_ARG_VM_TYPE_NO_OP,