Skip to content

Commit

Permalink
Merge pull request #15807 from Akira1Saitoh/aarch64InlineMathMinMax
Browse files Browse the repository at this point in the history
AArch64: Inline Math.min and max
  • Loading branch information
knn-k authored Aug 31, 2022
2 parents f8c5cbd + 88017f6 commit c5c4418
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
7 changes: 6 additions & 1 deletion runtime/compiler/aarch64/codegen/J9CodeGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2021 IBM Corp. and others
* Copyright (c) 2019, 2022 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -215,5 +215,10 @@ J9::ARM64::CodeGenerator::supportsInliningOfIsInstance()
bool
J9::ARM64::CodeGenerator::suppressInliningOfRecognizedMethod(TR::RecognizedMethod method)
{
if (method == TR::java_lang_Math_min_F ||
method == TR::java_lang_Math_max_F)
{
return true;
}
return false;
}
49 changes: 49 additions & 0 deletions runtime/compiler/aarch64/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5094,6 +5094,34 @@ static TR::Register *VMinlineCompareAndSwapObject(TR::Node *node, TR::CodeGenera
return resultReg;
}

/**
* @brief Generates instruction sequence for java/lang/Math.min and max
*
* @param[in] node: node
* @param[in] isMax: true if operation is max
* @param[in] isDouble: true if type is double
* @param[in] cg: CodeGenerator
* @return the result register
*/
static TR::Register *
VMinlineMathMinMax(TR::Node *node, bool isMax, bool isDouble, TR::CodeGenerator *cg)
{
TR::Node *firstChild = node->getFirstChild();
TR::Node *secondChild = node->getSecondChild();
TR::Register *lhsReg = cg->evaluate(firstChild);
TR::Register *rhsReg = cg->evaluate(secondChild);
TR::Register *resReg = cg->allocateRegister(TR_FPR);
TR::InstOpCode::Mnemonic op = isMax ? (isDouble ? TR::InstOpCode::fmaxd : TR::InstOpCode::fmaxs) :
(isDouble ? TR::InstOpCode::fmind : TR::InstOpCode::fmins);
generateTrg1Src2Instruction(cg, op, node, resReg, lhsReg, rhsReg);

node->setRegister(resReg);
cg->decReferenceCount(firstChild);
cg->decReferenceCount(secondChild);

return resReg;
}

bool
J9::ARM64::CodeGenerator::inlineDirectCall(TR::Node *node, TR::Register *&resultReg)
{
Expand Down Expand Up @@ -5135,6 +5163,27 @@ J9::ARM64::CodeGenerator::inlineDirectCall(TR::Node *node, TR::Register *&result
return true;
}

case TR::java_lang_Math_max_D:
{
resultReg = VMinlineMathMinMax(node, true, true, cg);
return true;
}
case TR::java_lang_Math_max_F:
{
resultReg = VMinlineMathMinMax(node, true, false, cg);
return true;
}
case TR::java_lang_Math_min_D:
{
resultReg = VMinlineMathMinMax(node, false, true, cg);
return true;
}
case TR::java_lang_Math_min_F:
{
resultReg = VMinlineMathMinMax(node, false, false, cg);
return true;
}

case TR::sun_misc_Unsafe_compareAndSwapInt_jlObjectJII_Z:
{
// In Java9 and newer this can be either the jdk.internal JNI method or the sun.misc Java wrapper.
Expand Down

0 comments on commit c5c4418

Please sign in to comment.