Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pdModifyPrecision evaluator for even-precision #6

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions runtime/tr.source/trj9/z/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22627,6 +22627,12 @@ J9::Z::TreeEvaluator::simpleWideningOrTruncation(TR::Node *node,
return targetReg;
}

/*
* \brief
* Generate non-exception throwing intructions for pdModifyPrecision node to narrow or widen packed decimals.
* The generated instruction sequence does not validate the source packed decimals. Any invalid packed
* decimals will be loaded as is and modified as if their digits and signs were valid.
*/
TR::Register *
J9::Z::TreeEvaluator::pdModifyPrecisionEvaluator(TR::Node * node, TR::CodeGenerator * cg)
{
Expand All @@ -22640,14 +22646,26 @@ J9::Z::TreeEvaluator::pdModifyPrecisionEvaluator(TR::Node * node, TR::CodeGenera
!TR::Options::getCmdLineOptions()->getOption(TR_DisableVectorBCD)
|| isEnableVectorBCD)
{
// This VPSOP is to truncate packed decimal values and is expected to produce
// decimal overflows. Don't check condition code in this case.
targetReg = vectorPerformSignOperationHelper(node, cg,
true,
node->getDecimalPrecision(),
true,
SignOperationType::maintain,
false, 0, false);
int32_t targetPrec = node->getDecimalPrecision();
targetReg = cg->allocateRegister(TR_VRF);

int32_t imm = 0x0FFFF >> (TR_VECTOR_REGISTER_SIZE - TR::DataType::packedDecimalPrecisionToByteLength(targetPrec));
TR::Register* pdReg = cg->evaluate(node->getFirstChild());
TR::Register* maskReg = cg->allocateRegister(TR_VRF);
generateVRIaInstruction(cg, TR::InstOpCode::VGBM, node, maskReg, imm, 0);

if (targetPrec % 2 == 0)
{
TR::Register* shiftAmountReg = cg->allocateRegister(TR_VRF);
generateVRIaInstruction(cg, TR::InstOpCode::VREPI, node, shiftAmountReg, 4, 0);
generateVRRcInstruction(cg, TR::InstOpCode::VSRL, node, maskReg, maskReg, shiftAmountReg, 0, 0, 0);
cg->stopUsingRegister(shiftAmountReg);
}

generateVRRcInstruction(cg, TR::InstOpCode::VN, node, targetReg, pdReg, maskReg, 0, 0, 0);

cg->stopUsingRegister(maskReg);
cg->decReferenceCount(node->getFirstChild());
}
else
{
Expand Down