Skip to content

Commit

Permalink
Accelerate Unsafe CAS Intrinsics on Power and X
Browse files Browse the repository at this point in the history
Adds lbarx, lharx, stbcx_r and sthcx_r instruction support for Power. These
instructions are not currently in use but will be needed for future
enhancements targetting CAS on byte and short length data.

Updates willBeEvaluatedAsCallByCodeGen to reflect the new acceleration of
Unsafe compareAndExchange methods on X.

Signed-off-by: jimmyk <[email protected]>
  • Loading branch information
IBMJimmyk committed Sep 11, 2024
1 parent 10fdf65 commit df7fc8c
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 7 deletions.
11 changes: 9 additions & 2 deletions compiler/optimizer/RedundantAsyncCheckRemoval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,15 @@ bool TR_RedundantAsyncCheckRemoval::callDoesAnImplicitAsyncCheck(TR::Node *callN
if (symbol->isNative() &&
((symbol->getRecognizedMethod()==TR::sun_misc_Unsafe_compareAndSwapInt_jlObjectJII_Z) ||
(symbol->getRecognizedMethod()==TR::sun_misc_Unsafe_compareAndSwapLong_jlObjectJJJ_Z) ||
(symbol->getRecognizedMethod()==TR::sun_misc_Unsafe_compareAndSwapObject_jlObjectJjlObjectjlObject_Z))
)
(symbol->getRecognizedMethod()==TR::sun_misc_Unsafe_compareAndSwapObject_jlObjectJjlObjectjlObject_Z)))
return false;

if (symbol->isNative() &&
(comp()->target().cpu.isPower() || comp()->target().cpu.isX86()) &&
((symbol->getRecognizedMethod()==TR::jdk_internal_misc_Unsafe_compareAndExchangeInt) ||
(symbol->getRecognizedMethod()==TR::jdk_internal_misc_Unsafe_compareAndExchangeLong) ||
(symbol->getRecognizedMethod()==TR::jdk_internal_misc_Unsafe_compareAndExchangeObject) ||
(symbol->getRecognizedMethod()==TR::jdk_internal_misc_Unsafe_compareAndExchangeReference)))
return false;
#endif
return true;
Expand Down
6 changes: 5 additions & 1 deletion compiler/p/codegen/OMRInstOpCode.enum
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
fsubs, // Floating subtract single
isync, // Instruction synchronize
lbz, // Load byte and zero extend
lbarx, // Load byte and reserve indexed
lbzu, // Load byte and zero extend with update
lbzux, // Load byte and zero extend with update indexed
lbzx, // Load byte and zero extend indexed
Expand All @@ -247,6 +248,7 @@
lfsux, // Load floating short with update indexed
lfsx, // Load floating short indexed
lha, // Load half word algebraic
lharx, // Load half word and reserve indexed
lhau, // Load half word algebraic
lhaux, // Load half word algebraic
lhax, // Load half word algebraic
Expand Down Expand Up @@ -390,11 +392,12 @@
srw, // Shift right word
srw_r, // Shift right word Rc=1
stb, // Store byte
stbcx_r, // Store byte conditional indexed
stbu, // Store byte with update
stbux, // Store byte with update indexed
stbx, // Store byte indexed
std, // Store dword
stdcx_r, // Store word conditional indexed
stdcx_r, // Store dword conditional indexed
stdu, // Store dword with update
stdux, // Store dword with update indexed
stdx, // Store dword indexed
Expand All @@ -411,6 +414,7 @@
stfsx, // Store float single indexed
sth, // Store half word
sthbrx, // Store half word byte reversed indexed
sthcx_r, // Store half word conditional indexed
sthu, // Store half word with update
sthux, // Store half word with update indexed
sthx, // Store half word indexed
Expand Down
52 changes: 51 additions & 1 deletion compiler/p/codegen/OMRInstOpCodeProperties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2506,6 +2506,18 @@
PPCOpProp_ExcludeR0ForRA,
},

{
/* .mnemonic = */ OMR::InstOpCode::lbarx,
/* .name = */ "lbarx",
/* .description = "Load byte and reserve indexed", */
/* .prefix = */ 0x00000000,
/* .opcode = */ 0x7C000068,
/* .format = */ FORMAT_RT_RA_RB_MEM,
/* .minimumALS = */ OMR_PROCESSOR_PPC_P7,
/* .properties = */ PPCOpProp_IsLoad |
PPCOpProp_ExcludeR0ForRA,
},

{
/* .mnemonic = */ OMR::InstOpCode::lbzu,
/* .name = */ "lbzu",
Expand Down Expand Up @@ -2780,6 +2792,18 @@
PPCOpProp_ExcludeR0ForRA,
},

{
/* .mnemonic = */ OMR::InstOpCode::lharx,
/* .name = */ "lharx",
/* .description = "Load half word and reserve indexed", */
/* .prefix = */ 0x00000000,
/* .opcode = */ 0x7C0000E8,
/* .format = */ FORMAT_RT_RA_RB_MEM,
/* .minimumALS = */ OMR_PROCESSOR_PPC_P7,
/* .properties = */ PPCOpProp_IsLoad |
PPCOpProp_ExcludeR0ForRA,
},

{
/* .mnemonic = */ OMR::InstOpCode::lhau,
/* .name = */ "lhau",
Expand Down Expand Up @@ -4460,6 +4484,19 @@
PPCOpProp_ExcludeR0ForRA,
},

{
/* .mnemonic = */ OMR::InstOpCode::stbcx_r,
/* .name = */ "stbcx.",
/* .description = "Store byte conditional indexed", */
/* .prefix = */ 0x00000000,
/* .opcode = */ 0x7C00056D,
/* .format = */ FORMAT_RS_RA_RB_MEM,
/* .minimumALS = */ OMR_PROCESSOR_PPC_P7,
/* .properties = */ PPCOpProp_IsStore |
PPCOpProp_ExcludeR0ForRA |
PPCOpProp_IsRecordForm,
},

{
/* .mnemonic = */ OMR::InstOpCode::stbu,
/* .name = */ "stbu",
Expand Down Expand Up @@ -4514,7 +4551,7 @@
{
/* .mnemonic = */ OMR::InstOpCode::stdcx_r,
/* .name = */ "stdcx.",
/* .description = "Store word conditional indexed", */
/* .description = "Store dword conditional indexed", */
/* .prefix = */ 0x00000000,
/* .opcode = */ 0x7C0001AD,
/* .format = */ FORMAT_RS_RA_RB_MEM,
Expand Down Expand Up @@ -4733,6 +4770,19 @@
PPCOpProp_ExcludeR0ForRA,
},

{
/* .mnemonic = */ OMR::InstOpCode::sthcx_r,
/* .name = */ "sthcx.",
/* .description = "Store half word conditional indexed", */
/* .prefix = */ 0x00000000,
/* .opcode = */ 0x7C0005AD,
/* .format = */ FORMAT_RS_RA_RB_MEM,
/* .minimumALS = */ OMR_PROCESSOR_PPC_P7,
/* .properties = */ PPCOpProp_IsStore |
PPCOpProp_ExcludeR0ForRA |
PPCOpProp_IsRecordForm,
},

{
/* .mnemonic = */ OMR::InstOpCode::sthu,
/* .name = */ "sthu",
Expand Down
10 changes: 7 additions & 3 deletions compiler/x/codegen/OMRCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,12 +761,16 @@ bool OMR::X86::CodeGenerator::willBeEvaluatedAsCallByCodeGen(TR::Node *node, TR:
TR::MethodSymbol *methodSymbol = callSymRef->getSymbol()->castToMethodSymbol();
switch (methodSymbol->getRecognizedMethod())
{
case TR::sun_misc_Unsafe_compareAndSwapLong_jlObjectJJJ_Z:
return willNotInlineCompareAndSwapNative(node, 8, comp);
case TR::sun_misc_Unsafe_compareAndSwapInt_jlObjectJII_Z:
case TR::jdk_internal_misc_Unsafe_compareAndExchangeInt:
return willNotInlineCompareAndSwapNative(node, 4, comp);
case TR::sun_misc_Unsafe_compareAndSwapLong_jlObjectJJJ_Z:
case TR::jdk_internal_misc_Unsafe_compareAndExchangeLong:
return willNotInlineCompareAndSwapNative(node, 8, comp);
case TR::sun_misc_Unsafe_compareAndSwapObject_jlObjectJjlObjectjlObject_Z:
return willNotInlineCompareAndSwapNative(node, (comp->target().is64Bit() && !comp->useCompressedPointers()) ? 8 : 4, comp);
case TR::jdk_internal_misc_Unsafe_compareAndExchangeObject:
case TR::jdk_internal_misc_Unsafe_compareAndExchangeReference:
return willNotInlineCompareAndSwapNative(node, TR::Compiler->om.sizeofReferenceField(), comp);

default:
break;
Expand Down
20 changes: 20 additions & 0 deletions fvtest/compilerunittest/p/BinaryEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3918,6 +3918,10 @@ INSTANTIATE_TEST_CASE_P(LoadDisp, PPCRecordFormSanityTest, ::testing::Values(
));

INSTANTIATE_TEST_CASE_P(LoadIndex, PPCTrg1MemEncodingTest, ::testing::ValuesIn(*TRTest::MakeVector<std::tuple<TR::InstOpCode::Mnemonic, TR::RealRegister::RegNum, MemoryReference, TRTest::BinaryInstruction, bool>>(
std::make_tuple(TR::InstOpCode::lbarx, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c000068"), false),
std::make_tuple(TR::InstOpCode::lbarx, TR::RealRegister::gr31, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7fe00068"), false),
std::make_tuple(TR::InstOpCode::lbarx, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c1f0068"), false),
std::make_tuple(TR::InstOpCode::lbarx, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr31), TRTest::BinaryInstruction("7c00f868"), false),
std::make_tuple(TR::InstOpCode::lbzux, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c0100ee"), false),
std::make_tuple(TR::InstOpCode::lbzux, TR::RealRegister::gr31, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7fe100ee"), false),
std::make_tuple(TR::InstOpCode::lbzux, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c1f00ee"), false),
Expand Down Expand Up @@ -3966,6 +3970,10 @@ INSTANTIATE_TEST_CASE_P(LoadIndex, PPCTrg1MemEncodingTest, ::testing::ValuesIn(*
std::make_tuple(TR::InstOpCode::lfsx, TR::RealRegister::fp31, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7fe0042e"), false),
std::make_tuple(TR::InstOpCode::lfsx, TR::RealRegister::fp0, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c1f042e"), false),
std::make_tuple(TR::InstOpCode::lfsx, TR::RealRegister::fp0, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr31), TRTest::BinaryInstruction("7c00fc2e"), false),
std::make_tuple(TR::InstOpCode::lharx, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c0000e8"), false),
std::make_tuple(TR::InstOpCode::lharx, TR::RealRegister::gr31, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7fe000e8"), false),
std::make_tuple(TR::InstOpCode::lharx, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c1f00e8"), false),
std::make_tuple(TR::InstOpCode::lharx, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr31), TRTest::BinaryInstruction("7c00f8e8"), false),
std::make_tuple(TR::InstOpCode::lhaux, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c0102ee"), false),
std::make_tuple(TR::InstOpCode::lhaux, TR::RealRegister::gr31, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7fe102ee"), false),
std::make_tuple(TR::InstOpCode::lhaux, TR::RealRegister::gr0, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TRTest::BinaryInstruction("7c1f02ee"), false),
Expand Down Expand Up @@ -4070,6 +4078,7 @@ INSTANTIATE_TEST_CASE_P(LoadIndex, PPCTrg1MemEncodingTest, ::testing::ValuesIn(*
)));

INSTANTIATE_TEST_CASE_P(LoadIndex, PPCRecordFormSanityTest, ::testing::Values(
std::make_tuple(TR::InstOpCode::lbarx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lbzux, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lbzx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::ldarx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
Expand All @@ -4082,6 +4091,7 @@ INSTANTIATE_TEST_CASE_P(LoadIndex, PPCRecordFormSanityTest, ::testing::Values(
std::make_tuple(TR::InstOpCode::lfiwzx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lfsux, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lfsx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lharx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lhaux, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lhax, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::lhbrx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
Expand Down Expand Up @@ -4482,6 +4492,10 @@ INSTANTIATE_TEST_CASE_P(StoreDisp, PPCRecordFormSanityTest, ::testing::Values(
));

INSTANTIATE_TEST_CASE_P(StoreIndex, PPCMemSrc1EncodingTest, ::testing::ValuesIn(*TRTest::MakeVector<std::tuple<TR::InstOpCode::Mnemonic, MemoryReference, TR::RealRegister::RegNum, TRTest::BinaryInstruction, bool>>(
std::make_tuple(TR::InstOpCode::stbcx_r, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c00056d"), false),
std::make_tuple(TR::InstOpCode::stbcx_r, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c1f056d"), false),
std::make_tuple(TR::InstOpCode::stbcx_r, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr31), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c00fd6d"), false),
std::make_tuple(TR::InstOpCode::stbcx_r, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TR::RealRegister::gr31, TRTest::BinaryInstruction("7fe0056d"), false),
std::make_tuple(TR::InstOpCode::stbux, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c0101ee"), false),
std::make_tuple(TR::InstOpCode::stbux, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c1f01ee"), false),
std::make_tuple(TR::InstOpCode::stbux, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr31), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c01f9ee"), false),
Expand Down Expand Up @@ -4526,6 +4540,10 @@ INSTANTIATE_TEST_CASE_P(StoreIndex, PPCMemSrc1EncodingTest, ::testing::ValuesIn(
std::make_tuple(TR::InstOpCode::sthbrx, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c1f072c"), false),
std::make_tuple(TR::InstOpCode::sthbrx, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr31), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c00ff2c"), false),
std::make_tuple(TR::InstOpCode::sthbrx, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TR::RealRegister::gr31, TRTest::BinaryInstruction("7fe0072c"), false),
std::make_tuple(TR::InstOpCode::sthcx_r, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c0005ad"), false),
std::make_tuple(TR::InstOpCode::sthcx_r, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c1f05ad"), false),
std::make_tuple(TR::InstOpCode::sthcx_r, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr31), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c00fdad"), false),
std::make_tuple(TR::InstOpCode::sthcx_r, MemoryReference(TR::RealRegister::gr0, TR::RealRegister::gr0 ), TR::RealRegister::gr31, TRTest::BinaryInstruction("7fe005ad"), false),
std::make_tuple(TR::InstOpCode::sthux, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c01036e"), false),
std::make_tuple(TR::InstOpCode::sthux, MemoryReference(TR::RealRegister::gr31, TR::RealRegister::gr0 ), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c1f036e"), false),
std::make_tuple(TR::InstOpCode::sthux, MemoryReference(TR::RealRegister::gr1, TR::RealRegister::gr31), TR::RealRegister::gr0, TRTest::BinaryInstruction("7c01fb6e"), false),
Expand Down Expand Up @@ -4608,6 +4626,7 @@ INSTANTIATE_TEST_CASE_P(StoreIndex, PPCMemSrc1EncodingTest, ::testing::ValuesIn(
)));

INSTANTIATE_TEST_CASE_P(StoreIndex, PPCRecordFormSanityTest, ::testing::Values(
std::make_tuple(TR::InstOpCode::bad, TR::InstOpCode::stbcx_r, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::stbux, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::stbx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::bad, TR::InstOpCode::stdcx_r, TRTest::BinaryInstruction()),
Expand All @@ -4619,6 +4638,7 @@ INSTANTIATE_TEST_CASE_P(StoreIndex, PPCRecordFormSanityTest, ::testing::Values(
std::make_tuple(TR::InstOpCode::stfsux, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::stfsx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::sthbrx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::bad, TR::InstOpCode::sthcx_r, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::sthux, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::sthx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
std::make_tuple(TR::InstOpCode::stvx, TR::InstOpCode::bad, TRTest::BinaryInstruction()),
Expand Down

0 comments on commit df7fc8c

Please sign in to comment.