CalcReg accumulatorRegister,
RexToCalcTranslator translator)
{
assert call.operands.length == 1;
final RexNode operand = call.operands[0];
final CalcProgramBuilder builder = translator.builder;
CalcReg input = translator.implementNode(operand);
CalcReg tempBoolReg = translator.getTempBoolRegister();
//check operand for null if it is nullable
String noReplaceLabel = translator.newLabel();
;
String doReplaceLabel = translator.newLabel();
if (operand.getType().isNullable()) {
CalcProgramBuilder.boolNativeIsNull.add(
translator.builder,
tempBoolReg,
input);
builder.addLabelJumpTrue(noReplaceLabel, tempBoolReg);
CalcProgramBuilder.boolNativeIsNull.add(
translator.builder,
tempBoolReg,
accumulatorRegister);
builder.addLabelJumpTrue(doReplaceLabel, tempBoolReg);
}
InstructionDef compareInstruction =
isMin() ? CalcProgramBuilder.boolLessThan
: CalcProgramBuilder.boolGreaterThan;
if (SqlTypeUtil.inCharFamily(operand.getType())) {
final CalcReg tempInt4 = translator.getTempInt4Register();
final CalcReg zeroReg = translator.builder.newInt4Literal(0);
ExtInstructionDefTable.strCmpA.add(
builder,
tempInt4,
translator.implementNode(operand),
accumulatorRegister);
compareInstruction.add(
builder,
tempBoolReg,
tempInt4,
zeroReg);
} else {
compareInstruction.add(
builder,
tempBoolReg,
translator.implementNode(operand),
accumulatorRegister);
}
builder.addLabelJumpFalse(noReplaceLabel, tempBoolReg);
builder.addLabel(doReplaceLabel);
// Use ref instead of move since could be replacing a null
CalcProgramBuilder.refInstruction.add(
translator.builder,
accumulatorRegister,
input);
builder.addLabel(noReplaceLabel);
}