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;
}
}
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;
}
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;
}
Aggregations