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

x86: Implement Integer/Long . compress/expand intrinsics #19751

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions runtime/compiler/codegen/J9CodeGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,25 @@ void addMonClass(TR::Node* monNode, TR_OpaqueClassBlock* clazz);
*/
void setSupportsIntegerToChars() {_j9Flags.set(SupportsIntegerToChars); }

/** \brief
* Determines whether the code generator supports inlining of
* - Integer.compress,
* - Integer.expand,
* - Long.compress,
* - Long.expand,
*/
bool getSupportsParallelBitOperations() { return _j9Flags.testAny(SupportsParallelBitOperations); }


/** \brief
* The code generator supports inlining of
* - Integer.compress,
* - Integer.expand,
* - Long.compress,
* - Long.expand,
*/
void setSupportsParallelBitOperations() {_j9Flags.set(SupportsParallelBitOperations); }

/**
* \brief Determine whether this code generator guarantees resolved direct
* dispatch under AOT with SVM.
Expand Down Expand Up @@ -677,6 +696,7 @@ void addMonClass(TR::Node* monNode, TR_OpaqueClassBlock* clazz);
SavesNonVolatileGPRsForGC = 0x00000800,
SupportsInlineVectorizedMismatch = 0x00001000,
SupportsInlineVectorizedHashCode = 0x00002000,
SupportsParallelBitOperations = 0x00004000,
};

flags32_t _j9Flags;
Expand Down
4 changes: 4 additions & 0 deletions runtime/compiler/codegen/J9RecognizedMethodsEnum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@
java_lang_Integer_reverseBytes,
java_lang_Integer_rotateLeft,
java_lang_Integer_rotateRight,
java_lang_Integer_compress,
java_lang_Integer_expand,
java_lang_Integer_valueOf,
java_lang_Integer_toUnsignedLong,
java_lang_Integer_stringSize,
Expand All @@ -532,6 +534,8 @@
java_lang_Long_reverseBytes,
java_lang_Long_rotateLeft,
java_lang_Long_rotateRight,
java_lang_Long_compress,
java_lang_Long_expand,
java_lang_Short_reverseBytes,
java_lang_Long_stringSize,
java_lang_Long_toString,
Expand Down
4 changes: 4 additions & 0 deletions runtime/compiler/env/j9method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,8 @@ void TR_ResolvedJ9Method::construct()
{x(TR::java_lang_Integer_reverseBytes, "reverseBytes", "(I)I")},
{x(TR::java_lang_Integer_rotateLeft, "rotateLeft", "(II)I")},
{x(TR::java_lang_Integer_rotateRight, "rotateRight", "(II)I")},
{x(TR::java_lang_Integer_compress, "compress", "(II)I")},
{x(TR::java_lang_Integer_expand, "expand", "(II)I")},
{x(TR::java_lang_Integer_valueOf, "valueOf", "(I)Ljava/lang/Integer;")},
{ TR::java_lang_Integer_init, 6, "<init>", (int16_t)-1, "*"},
{x(TR::java_lang_Integer_toUnsignedLong, "toUnsignedLong", "(I)J")},
Expand All @@ -3303,6 +3305,8 @@ void TR_ResolvedJ9Method::construct()
{x(TR::java_lang_Long_reverseBytes, "reverseBytes", "(J)J")},
{x(TR::java_lang_Long_rotateLeft, "rotateLeft", "(JI)J")},
{x(TR::java_lang_Long_rotateRight, "rotateRight", "(JI)J")},
{x(TR::java_lang_Long_compress, "compress", "(JJ)J")},
{x(TR::java_lang_Long_expand, "expand", "(JJ)J")},
{ TR::java_lang_Long_init, 6, "<init>", (int16_t)-1, "*"},
{x(TR::java_lang_Long_stringSize, "stringSize", "(J)I") },
{x(TR::java_lang_Long_toString, "toString", "(J)Ljava/lang/String;") },
Expand Down
9 changes: 9 additions & 0 deletions runtime/compiler/optimizer/InlinerTempForJ9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4874,6 +4874,15 @@ TR_J9InlinerPolicy::supressInliningRecognizedInitialCallee(TR_CallSite* callsite
return true;
}
break;
case TR::java_lang_Integer_expand:
case TR::java_lang_Integer_compress:
case TR::java_lang_Long_expand:
case TR::java_lang_Long_compress:
if (comp->cg()->getSupportsParallelBitOperations())
{
return true;
}
break;
case TR::java_lang_Integer_stringSize:
case TR::java_lang_Long_stringSize:
if (comp->cg()->getSupportsIntegerStringSize())
Expand Down
5 changes: 5 additions & 0 deletions runtime/compiler/x/codegen/J9CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ J9::X86::CodeGenerator::initialize()
cg->setSupportsInlineStringHashCode();
}

if (comp->target().cpu.supportsFeature(OMR_FEATURE_X86_BMI2))
{
cg->setSupportsParallelBitOperations();
}

if (comp->generateArraylets() && !comp->getOptions()->realTimeGC())
{
cg->setSupportsStackAllocationOfArraylets();
Expand Down
51 changes: 51 additions & 0 deletions runtime/compiler/x/codegen/J9TreeEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11580,6 +11580,14 @@ J9::X86::TreeEvaluator::directCallEvaluator(TR::Node *node, TR::CodeGenerator *c
return TR::TreeEvaluator::inlineStringLatin1Inflate(node, cg);
}
break;
case TR::java_lang_Integer_compress:
return inlineParallelBitOperation(node, cg, TR::Int32, true);
case TR::java_lang_Integer_expand:
return inlineParallelBitOperation(node, cg, TR::Int32, false);
case TR::java_lang_Long_compress:
return inlineParallelBitOperation(node, cg, TR::Int64, true);
case TR::java_lang_Long_expand:
return inlineParallelBitOperation(node, cg, TR::Int64, false);
case TR::java_lang_Math_sqrt:
case TR::java_lang_StrictMath_sqrt:
case TR::java_lang_System_nanoTime:
Expand Down Expand Up @@ -11795,6 +11803,49 @@ J9::X86::TreeEvaluator::inlineStringLatin1Inflate(TR::Node *node, TR::CodeGenera
return NULL;
}

TR::Register *
J9::X86::TreeEvaluator::inlineParallelBitOperation(TR::Node *node, TR::CodeGenerator *cg, TR::DataType dt, bool compress)
{
TR::Node *intNode = node->getFirstChild();
TR::Node *maskNode = node->getSecondChild();

TR::Register *intReg = cg->evaluate(intNode);
TR::Register *maskReg = cg->evaluate(maskNode);
TR::Register *result = cg->allocateRegister(TR_GPR);

traceMsg(cg->comp(), "Inlining parallel bits operation");

if (dt == TR::Int32)
{
if (compress)
{
generateRegRegRegInstruction(TR::InstOpCode::PEXT4RegRegReg, node, result, intReg, maskReg, cg);
}
else
{
generateRegRegRegInstruction(TR::InstOpCode::PDEP4RegRegReg, node, result, intReg, maskReg, cg);
}
}
else if (dt == TR::Int64)
{
if (compress)
{
generateRegRegRegInstruction(TR::InstOpCode::PEXT8RegRegReg, node, result, intReg, maskReg, cg);
}
else
{
generateRegRegRegInstruction(TR::InstOpCode::PDEP8RegRegReg, node, result, intReg, maskReg, cg);
}
}
else
{
TR_ASSERT_FATAL(false, "Unsupported data type for parallel bit operation");
}

node->setRegister(result);
return result;
}

TR::Register *
J9::X86::TreeEvaluator::encodeUTF16Evaluator(TR::Node *node, TR::CodeGenerator *cg)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/compiler/x/codegen/J9TreeEvaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class OMR_EXTENSIBLE TreeEvaluator: public J9::TreeEvaluator
static TR::Register *awrtbarEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *awrtbariEvaluator(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *inlineStringLatin1Inflate(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *inlineParallelBitOperation(TR::Node *node, TR::CodeGenerator *cg, TR::DataType dt, bool compress);
static TR::Register *generateConcurrentScavengeSequence(TR::Node *node, TR::CodeGenerator *cg);
static TR::Register *fpConvertToLong(TR::Node *node, TR::SymbolReference *helperSymRef, TR::CodeGenerator *cg);
static TR::Register *f2iEvaluator(TR::Node *node, TR::CodeGenerator *cg);
Expand Down
3 changes: 2 additions & 1 deletion runtime/compiler/x/env/J9CPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ J9::X86::CPU::enableFeatureMasks()
OMR_FEATURE_X86_FMA, OMR_FEATURE_X86_HLE, OMR_FEATURE_X86_RTM,
OMR_FEATURE_X86_SSE3, OMR_FEATURE_X86_AVX2, OMR_FEATURE_X86_AVX512F,
OMR_FEATURE_X86_AVX512VL, OMR_FEATURE_X86_AVX512BW, OMR_FEATURE_X86_AVX512DQ,
OMR_FEATURE_X86_AVX512CD, OMR_FEATURE_X86_SSE4_2};
OMR_FEATURE_X86_AVX512CD, OMR_FEATURE_X86_SSE4_2, OMR_FEATURE_X86_BMI2};

memset(_supportedFeatureMasks.features, 0, OMRPORT_SYSINFO_FEATURES_SIZE*sizeof(uint32_t));
OMRPORT_ACCESS_FROM_OMRPORT(TR::Compiler->omrPortLib);
Expand Down Expand Up @@ -359,6 +359,7 @@ J9::X86::CPU::supports_feature_test(uint32_t feature)
case OMR_FEATURE_X86_AVX512DQ:
case OMR_FEATURE_X86_AVX512CD:
case OMR_FEATURE_X86_FMA:
case OMR_FEATURE_X86_BMI2:
return true;
default:
return false;
Expand Down