Search in sources :

Example 11 with AMD64Kind

use of jdk.vm.ci.amd64.AMD64Kind in project graal by oracle.

the class AMD64NodeMatchRules method emitCompareBranchMemory.

protected ComplexMatchResult emitCompareBranchMemory(IfNode ifNode, CompareNode compare, ValueNode value, LIRLowerableAccess access) {
    Condition cond = compare.condition().asCondition();
    AMD64Kind kind = getMemoryKind(access);
    // For assertion checking
    boolean matchedAsConstant = false;
    if (value.isConstant()) {
        JavaConstant constant = value.asJavaConstant();
        if (constant != null) {
            if (kind == AMD64Kind.QWORD && !constant.getJavaKind().isObject() && !NumUtil.isInt(constant.asLong())) {
                // Only imm32 as long
                return null;
            }
            // A QWORD that can be encoded as int can be embedded as a constant
            matchedAsConstant = kind == AMD64Kind.QWORD && !constant.getJavaKind().isObject() && NumUtil.isInt(constant.asLong());
        }
        if (kind == AMD64Kind.DWORD) {
            // Any DWORD value should be embeddable as a constant
            matchedAsConstant = true;
        }
        if (kind.isXMM()) {
            ifNode.getDebug().log("Skipping constant compares for float kinds");
            return null;
        }
    }
    boolean matchedAsConstantFinal = matchedAsConstant;
    /*
         * emitCompareBranchMemory expects the memory on the right, so mirror the condition if
         * that's not true. It might be mirrored again the actual compare is emitted but that's ok.
         */
    Condition finalCondition = GraphUtil.unproxify(compare.getX()) == access ? cond.mirror() : cond;
    return new ComplexMatchResult() {

        @Override
        public Value evaluate(NodeLIRBuilder builder) {
            LabelRef trueLabel = getLIRBlock(ifNode.trueSuccessor());
            LabelRef falseLabel = getLIRBlock(ifNode.falseSuccessor());
            boolean unorderedIsTrue = compare.unorderedIsTrue();
            double trueLabelProbability = ifNode.probability(ifNode.trueSuccessor());
            Value other = operand(value);
            /*
                 * Check that patterns which were matched as a constant actually end up seeing a
                 * constant in the LIR.
                 */
            assert !matchedAsConstantFinal || !LIRValueUtil.isVariable(other) : "expected constant value " + value;
            AMD64AddressValue address = (AMD64AddressValue) operand(access.getAddress());
            getLIRGeneratorTool().emitCompareBranchMemory(kind, other, address, getState(access), finalCondition, unorderedIsTrue, trueLabel, falseLabel, trueLabelProbability);
            return null;
        }
    };
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) NodeLIRBuilder(org.graalvm.compiler.core.gen.NodeLIRBuilder) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) JavaConstant(jdk.vm.ci.meta.JavaConstant) LabelRef(org.graalvm.compiler.lir.LabelRef)

Example 12 with AMD64Kind

use of jdk.vm.ci.amd64.AMD64Kind in project graal by oracle.

the class AMD64Move method const2stack.

public static void const2stack(CompilationResultBuilder crb, AMD64MacroAssembler masm, Value result, JavaConstant input) {
    AMD64Address dest = (AMD64Address) crb.asAddress(result);
    final long imm;
    switch(input.getJavaKind().getStackKind()) {
        case Int:
            imm = input.asInt();
            break;
        case Long:
            imm = input.asLong();
            break;
        case Float:
            imm = floatToRawIntBits(input.asFloat());
            break;
        case Double:
            imm = doubleToRawLongBits(input.asDouble());
            break;
        case Object:
            if (input.isNull()) {
                imm = 0;
            } else {
                throw GraalError.shouldNotReachHere("Non-null object constants must be in register");
            }
            break;
        default:
            throw GraalError.shouldNotReachHere();
    }
    switch((AMD64Kind) result.getPlatformKind()) {
        case BYTE:
            assert NumUtil.isByte(imm) : "Is not in byte range: " + imm;
            AMD64MIOp.MOVB.emit(masm, OperandSize.BYTE, dest, (int) imm);
            break;
        case WORD:
            assert NumUtil.isShort(imm) : "Is not in short range: " + imm;
            AMD64MIOp.MOV.emit(masm, OperandSize.WORD, dest, (int) imm);
            break;
        case DWORD:
        case SINGLE:
            assert NumUtil.isInt(imm) : "Is not in int range: " + imm;
            masm.movl(dest, (int) imm);
            break;
        case QWORD:
        case DOUBLE:
            masm.movlong(dest, imm);
            break;
        default:
            throw GraalError.shouldNotReachHere("Unknown result Kind: " + result.getPlatformKind());
    }
}
Also used : AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) AMD64Address(org.graalvm.compiler.asm.amd64.AMD64Address)

Example 13 with AMD64Kind

use of jdk.vm.ci.amd64.AMD64Kind in project graal by oracle.

the class AMD64HotSpotLoadAddressOp method emitCode.

@Override
public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
    crb.recordInlineDataInCodeWithNote(constant, note);
    AMD64Kind kind = (AMD64Kind) result.getPlatformKind();
    switch(kind) {
        case DWORD:
            masm.movl(asRegister(result), masm.getPlaceholder(-1));
            break;
        case QWORD:
            masm.movq(asRegister(result), masm.getPlaceholder(-1));
            break;
        default:
            throw GraalError.shouldNotReachHere("unexpected kind: " + kind);
    }
}
Also used : AMD64Kind(jdk.vm.ci.amd64.AMD64Kind)

Example 14 with AMD64Kind

use of jdk.vm.ci.amd64.AMD64Kind in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitNot.

@Override
public Variable emitNot(Value inputVal) {
    AllocatableValue input = getLIRGen().asAllocatable(inputVal);
    Variable result = getLIRGen().newVariable(LIRKind.combine(input));
    switch((AMD64Kind) input.getPlatformKind()) {
        case DWORD:
            getLIRGen().append(new AMD64Unary.MOp(NOT, DWORD, result, input));
            break;
        case QWORD:
            getLIRGen().append(new AMD64Unary.MOp(NOT, QWORD, result, input));
            break;
        default:
            throw GraalError.shouldNotReachHere();
    }
    return result;
}
Also used : AMD64Unary(org.graalvm.compiler.lir.amd64.AMD64Unary) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) Variable(org.graalvm.compiler.lir.Variable) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Example 15 with AMD64Kind

use of jdk.vm.ci.amd64.AMD64Kind in project graal by oracle.

the class AMD64ArithmeticLIRGenerator method emitNegate.

@Override
public Variable emitNegate(Value inputVal) {
    AllocatableValue input = getLIRGen().asAllocatable(inputVal);
    Variable result = getLIRGen().newVariable(LIRKind.combine(input));
    TargetDescription target = getLIRGen().target();
    boolean isAvx = ((AMD64) target.arch).getFeatures().contains(CPUFeature.AVX);
    switch((AMD64Kind) input.getPlatformKind()) {
        case DWORD:
            getLIRGen().append(new AMD64Unary.MOp(NEG, DWORD, result, input));
            break;
        case QWORD:
            getLIRGen().append(new AMD64Unary.MOp(NEG, QWORD, result, input));
            break;
        case SINGLE:
            if (isAvx) {
                getLIRGen().append(new AMD64Binary.DataThreeOp(AVXOp.XOR, PS, result, input, JavaConstant.forFloat(Float.intBitsToFloat(0x80000000)), 16));
            } else {
                getLIRGen().append(new AMD64Binary.DataTwoOp(SSEOp.XOR, PS, result, input, JavaConstant.forFloat(Float.intBitsToFloat(0x80000000)), 16));
            }
            break;
        case DOUBLE:
            if (isAvx) {
                getLIRGen().append(new AMD64Binary.DataThreeOp(AVXOp.XOR, PD, result, input, JavaConstant.forDouble(Double.longBitsToDouble(0x8000000000000000L)), 16));
            } else {
                getLIRGen().append(new AMD64Binary.DataTwoOp(SSEOp.XOR, PD, result, input, JavaConstant.forDouble(Double.longBitsToDouble(0x8000000000000000L)), 16));
            }
            break;
        default:
            throw GraalError.shouldNotReachHere(input.getPlatformKind().toString());
    }
    return result;
}
Also used : AMD64Unary(org.graalvm.compiler.lir.amd64.AMD64Unary) AMD64Kind(jdk.vm.ci.amd64.AMD64Kind) Variable(org.graalvm.compiler.lir.Variable) AMD64Binary(org.graalvm.compiler.lir.amd64.AMD64Binary) TargetDescription(jdk.vm.ci.code.TargetDescription) AllocatableValue(jdk.vm.ci.meta.AllocatableValue)

Aggregations

AMD64Kind (jdk.vm.ci.amd64.AMD64Kind)24 TargetDescription (jdk.vm.ci.code.TargetDescription)9 AMD64AddressValue (org.graalvm.compiler.lir.amd64.AMD64AddressValue)8 Variable (org.graalvm.compiler.lir.Variable)7 LIRKind (org.graalvm.compiler.core.common.LIRKind)6 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)5 RegisterValue (jdk.vm.ci.code.RegisterValue)3 Register (jdk.vm.ci.code.Register)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 Value (jdk.vm.ci.meta.Value)2 AMD64Address (org.graalvm.compiler.asm.amd64.AMD64Address)2 AMD64RMOp (org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64RMOp)2 OperandSize (org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)2 CanonicalCondition (org.graalvm.compiler.core.common.calc.CanonicalCondition)2 Condition (org.graalvm.compiler.core.common.calc.Condition)2 NodeLIRBuilder (org.graalvm.compiler.core.gen.NodeLIRBuilder)2 ComplexMatchResult (org.graalvm.compiler.core.match.ComplexMatchResult)2 LabelRef (org.graalvm.compiler.lir.LabelRef)2 AMD64Move (org.graalvm.compiler.lir.amd64.AMD64Move)2 CompareAndSwapOp (org.graalvm.compiler.lir.amd64.AMD64Move.CompareAndSwapOp)2