Search in sources :

Example 1 with SPARCOP3Op

use of org.graalvm.compiler.lir.sparc.SPARCOP3Op in project graal by oracle.

the class SPARCArithmeticLIRGenerator method emitSignExtend.

@Override
public Value emitSignExtend(Value inputVal, int fromBits, int toBits) {
    assert fromBits <= toBits && toBits <= XWORD.getSizeInBits();
    LIRKind shiftKind = LIRKind.value(WORD);
    LIRKind resultKind = LIRKind.combine(inputVal).changeType(toBits > 32 ? XWORD : WORD);
    int shiftCount = XWORD.getSizeInBits() - fromBits;
    if (fromBits == toBits) {
        return inputVal;
    } else if (isJavaConstant(inputVal)) {
        JavaConstant javaConstant = asJavaConstant(inputVal);
        long constant;
        if (javaConstant.isNull()) {
            constant = 0;
        } else {
            constant = javaConstant.asLong();
        }
        return new ConstantValue(resultKind, JavaConstant.forLong((constant << shiftCount) >> shiftCount));
    } else {
        AllocatableValue inputAllocatable = getLIRGen().asAllocatable(inputVal);
        Variable result = getLIRGen().newVariable(resultKind);
        if (fromBits == WORD.getSizeInBits() && toBits == XWORD.getSizeInBits()) {
            getLIRGen().append(new SPARCOP3Op(Sra, inputAllocatable, g0.asValue(LIRKind.value(WORD)), result));
        } else {
            Variable tmp = getLIRGen().newVariable(resultKind.changeType(XWORD));
            getLIRGen().append(new SPARCOP3Op(Sllx, inputAllocatable, new ConstantValue(shiftKind, JavaConstant.forInt(shiftCount)), tmp));
            getLIRGen().append(new SPARCOP3Op(Srax, tmp, new ConstantValue(shiftKind, JavaConstant.forInt(shiftCount)), result));
        }
        return result;
    }
}
Also used : Variable(org.graalvm.compiler.lir.Variable) JavaConstant(jdk.vm.ci.meta.JavaConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) LIRKind(org.graalvm.compiler.core.common.LIRKind) ConstantValue(org.graalvm.compiler.lir.ConstantValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCOP3Op(org.graalvm.compiler.lir.sparc.SPARCOP3Op)

Example 2 with SPARCOP3Op

use of org.graalvm.compiler.lir.sparc.SPARCOP3Op in project graal by oracle.

the class SPARCArithmeticLIRGenerator method emitZeroExtend.

@Override
public Value emitZeroExtend(Value inputValue, int fromBits, int toBits) {
    assert fromBits <= toBits && toBits <= 64;
    if (fromBits == toBits) {
        return inputValue;
    }
    Variable result = getLIRGen().newVariable(LIRKind.combine(inputValue).changeType(toBits > WORD.getSizeInBits() ? XWORD : WORD));
    AllocatableValue inputAllocatable = getLIRGen().asAllocatable(inputValue);
    if (fromBits == 32) {
        getLIRGen().append(new SPARCOP3Op(Srl, inputAllocatable, g0.asValue(), result));
    } else {
        Value mask = getLIRGen().emitConstant(LIRKind.value(XWORD), forLong(mask(fromBits)));
        getLIRGen().append(new SPARCOP3Op(And, inputAllocatable, mask, result));
    }
    return result;
}
Also used : Variable(org.graalvm.compiler.lir.Variable) ConstantValue(org.graalvm.compiler.lir.ConstantValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCAddressValue(org.graalvm.compiler.lir.sparc.SPARCAddressValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCOP3Op(org.graalvm.compiler.lir.sparc.SPARCOP3Op)

Example 3 with SPARCOP3Op

use of org.graalvm.compiler.lir.sparc.SPARCOP3Op in project graal by oracle.

the class SPARCArithmeticLIRGenerator method emitBitCount.

@Override
public Variable emitBitCount(Value operand) {
    Variable result = getLIRGen().newVariable(LIRKind.combine(operand).changeType(SPARCKind.WORD));
    AllocatableValue usedOperand = getLIRGen().asAllocatable(emitZeroExtend(operand));
    getLIRGen().append(new SPARCOP3Op(Op3s.Popc, g0.asValue(), usedOperand, result));
    return result;
}
Also used : Variable(org.graalvm.compiler.lir.Variable) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) SPARCOP3Op(org.graalvm.compiler.lir.sparc.SPARCOP3Op)

Aggregations

AllocatableValue (jdk.vm.ci.meta.AllocatableValue)3 Variable (org.graalvm.compiler.lir.Variable)3 SPARCOP3Op (org.graalvm.compiler.lir.sparc.SPARCOP3Op)3 ConstantValue (org.graalvm.compiler.lir.ConstantValue)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 Value (jdk.vm.ci.meta.Value)1 LIRKind (org.graalvm.compiler.core.common.LIRKind)1 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)1 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)1 SPARCAddressValue (org.graalvm.compiler.lir.sparc.SPARCAddressValue)1