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

Provide support for LZCNT and TZCNT in X86Ops.ins #6978

Merged
merged 1 commit into from
Jun 8, 2023

Conversation

VidushiGit
Copy link
Contributor

No description provided.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for supporting the project, and congratulations on your first contribution! A project committer will shortly review your contribution. In the mean time, if you haven't had a chance please skim over the contribution guidelines which all pull requests must adhere to. If the ECA pull request check fails, have a look at the instructions for signing the ECA in the legal considerations section.

If you run into any problems our community will be happy to assist you in any way we can. There are a number of recommended ways to interact with the community. We encourage you to ask questions, or drop by to say hello.

@0xdaryl
Copy link
Contributor

0xdaryl commented May 5, 2023

@BradleyWood : please review

@0xdaryl
Copy link
Contributor

0xdaryl commented May 5, 2023

Thanks for the contribution. Could you add encodings for the other register sizes as well please? i.e., 16, 32, and 64-bit

@BradleyWood
Copy link
Contributor

BradleyWood commented May 5, 2023

Can you add binary encoding tests like the following?

INSTANTIATE_TEST_CASE_P(GeneralPurposeRegRegTest, XRegRegEncEncodingTest, ::testing::ValuesIn(*TRTest::MakeVector<std::tuple<TR::InstOpCode::Mnemonic, TR::RealRegister::RegNum, TR::RealRegister::RegNum, OMR::X86::Encoding, TRTest::BinaryInstruction>>( std::make_tuple(TR::InstOpCode::LZCNTRegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "<binary encoding>"), std::make_tuple(TR::InstOpCode::TZCNTRegReg, TR::RealRegister::ecx, TR::RealRegister::eax, OMR::X86::Default, "<binary encoding>") )));

Edit: You'll have to fix the formatting above

@VidushiGit
Copy link
Contributor Author

Thanks for the contribution. Could you add encodings for the other register sizes as well please? i.e., 16, 32, and 64-bit

Yes, I will add support for the 16 and 32- bit also. Current implementation is only supporting 64 bits. Thanks

@VidushiGit
Copy link
Contributor Author

Hi Bradley,
I have added the support for 16 and 32-bit registers for the instructions.

Also I have added the test cases for the instructions as suggested. Currently I have added EAX,ECX register pair(in the same order) for testing. Please let us know if we need some other test cases added.

@@ -695,6 +695,14 @@ INSTANTIATE_TEST_CASE_P(AVX512MaskRegSimdEVEX512Test, XRegRegEncEncodingTest, ::
std::make_tuple(TR::InstOpCode::VPMOVB2MRegReg, TR::RealRegister::k2, TR::RealRegister::xmm5, OMR::X86::EVEX_L128, "62f27e0829d5")
)));

INSTANTIATE_TEST_CASE_P(GeneralPurposeRegRegTest, XRegRegEncEncodingTest, ::testing::ValuesIn(*TRTest::MakeVector<std::tuple<TR::InstOpCode::Mnemonic, TR::RealRegister::RegNum, TR::RealRegister::RegNum, OMR::X86::Encoding, TRTest::BinaryInstruction>>(
std::make_tuple(TR::InstOpCode::LZCNT4RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f30fbdc1"),
std::make_tuple(TR::InstOpCode::LZCNT8RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f34c0fbdc1"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f34c0fbdc1 equates to lzcnt r8,rcx which does not match the specified registers

std::make_tuple(TR::InstOpCode::LZCNT8RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f34c0fbdc1"),

std::make_tuple(TR::InstOpCode::TZCNT4RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f30fbcc1"),
std::make_tuple(TR::InstOpCode::TZCNT8RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f34c0fbcc1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'f34c0fbcc1' equates to tzcnt r8,rcx which does not match the specified registers

@VidushiGit
Copy link
Contributor Author

Hi,
I have updated the file : compiler/x/codegen/X86Ops.ins and added IA32OpProp1_LongTarget as a property in to define support for 64-bit target

@VidushiGit
Copy link
Contributor Author

Corrected the test cases' binary encoding string

@BradleyWood
Copy link
Contributor

jenkins build all

@@ -2545,6 +2545,21 @@ INSTRUCTION(LEA8RegMem, lea,
PROPERTY0(IA32OpProp_ModifiesTarget),
PROPERTY1(IA32OpProp1_LongSource | IA32OpProp1_LongTarget | IA32OpProp1_SourceIsMemRef),
FEATURES(0)),
INSTRUCTION(LZCNT2RegReg, lzcnt,
BINARY(VEX_L___, VEX_vNONE, PREFIX_F3, REX__, ESCAPE_0F__, 0xbd, 0, ModRM_RM__, Immediate_0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This form should require the operand size override 0x66 prefix. Perhaps a question for @BradleyWood: in this encoding scheme, how does one encode an instruction that requires both a 0x66 and a 0xf3 prefix? Do we need a new PREFIX_66_F3 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a look over the code, as it currently stands you cannot use both prefixes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR #7020 was merged which provides the capability of specifying multiple prefixes. @VidushiGit, you should pick up that change and use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xdaryl Pulled the latest OMR code changes and added the support/usage for multiple instruction prefixes

@@ -5144,6 +5159,21 @@ INSTRUCTION(TEST8MemReg, test,
PROPERTY0(IA32OpProp_ModifiesOverflowFlag | IA32OpProp_ModifiesSignFlag | IA32OpProp_ModifiesZeroFlag | IA32OpProp_ModifiesParityFlag | IA32OpProp_ModifiesCarryFlag | IA32OpProp_UsesTarget),
PROPERTY1(IA32OpProp1_LongSource | IA32OpProp1_LongTarget | IA32OpProp1_FusableCompare),
FEATURES(0)),
INSTRUCTION(TZCNT2RegReg, tzcnt,
BINARY(VEX_L___, VEX_vNONE, PREFIX_F3, REX__, ESCAPE_0F__, 0xbc, 0, ModRM_RM__, Immediate_0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above for the operand size prefix.

std::make_tuple(TR::InstOpCode::LZCNT8RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f3480fbdc1"),

std::make_tuple(TR::InstOpCode::TZCNT4RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f30fbcc1"),
std::make_tuple(TR::InstOpCode::TZCNT8RegReg, TR::RealRegister::eax, TR::RealRegister::ecx, OMR::X86::Default, "f3480fbcc1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for the 16-bit versions as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for 16-bit version of the instruction

@BradleyWood
Copy link
Contributor

jenkins build all

@BradleyWood
Copy link
Contributor

MacOS failure is #6516

@0xdaryl 0xdaryl self-assigned this Jun 8, 2023
@0xdaryl 0xdaryl merged commit 06fe1c3 into eclipse-omr:master Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants