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

Clean up and improve documentation of x86_64 registers #1630

Merged
merged 39 commits into from Nov 21, 2023

Conversation

hainest
Copy link
Contributor

@hainest hainest commented Nov 18, 2023

The values for the RFLAGS fields VM..ID will get updated to the x86 ones after #1629 is merged.

@hainest hainest added code cleanup Bring the code up to modern standards or remove deprecated features dataflowAPI This issue is directly related to dataflowAPI instructionAPI This issue is directly related to instructionAPI dyninstAPI This issue is directly related to dyninstAPI labels Nov 18, 2023
@hainest hainest requested a review from kupsch November 18, 2023 05:24
@hainest hainest self-assigned this Nov 18, 2023
@hainest
Copy link
Contributor Author

hainest commented Nov 21, 2023

Testing fine on all platforms.

Copy link
Contributor

@kupsch kupsch left a comment

Choose a reason for hiding this comment

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

A couple changes in getBaseRegister, then it looks good to me.

If you feel ambitious, you could make and use mask constants and for the components of a register (id, alias/subrange, category, arch), so it is clearer, and less implementation details are spilled everywhere. Even more ambitious would be to create and use functions to get the components of the register that use the masks.

Comment on lines 77 to 78
const signed int YMM = 0x000B0000; // YMM0-YMM7 Registers from AVX2/FMA
const signed int ZMM = 0x000C0000; // ZMM0-ZMM7 Registers from AVX-512
Copy link
Contributor

Choose a reason for hiding this comment

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

update comment, there are 16 YMM and 32 ZMM registers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 76 to 78
const signed int XMM = 0x000A0000; // XMM0-XMM7 Registers from SSE
const signed int YMM = 0x000B0000; // YMM0-YMM7 Registers from AVX2/FMA
const signed int ZMM = 0x000C0000; // ZMM0-ZMM7 Registers from AVX-512
Copy link
Contributor

Choose a reason for hiding this comment

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

update comment, in x86_64 there are 16 YMM and 32 ZMM registers, but should probably say 32 XMM, YMM and ZMM registers as that is what AVX-512 can access.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added notes for the extension that added the registers and the values for AVX-512.

Comment on lines 39 to 63
return MachRegister(reg & 0xfffff0ff);
else if(category == x86_64::FLAG)
return x86_64::flags;
else if(category == x86_64::MMX)
return x86_64::st0;
else if(category == x86_64::XMM)
return x86_64::ymm0;
else if(category == x86_64::YMM)
return x86_64::zmm0;
else
return *this;
Copy link
Contributor

Choose a reason for hiding this comment

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

XMM should return ZMM as it is the largest containing register.

A switch statement would be a better and match the rest of the code.

The return value for MMX, XMM, and YMM should change the category and leave the register number so the base register of xmm5 is zmm5.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

XMM should return ZMM as it is the largest containing register.

Fixed.

A switch statement would be a better and match the rest of the code.

Agreed, but I'll put that off until another PR.

The return value for MMX, XMM, and YMM should change the category and leave the register number so the base register of xmm5 is zmm5.

That makes sense. Updated.

@@ -39,6 +39,12 @@ namespace Dyninst {
return MachRegister(reg & 0xfffff0ff);
Copy link
Contributor

Choose a reason for hiding this comment

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

clear the whole 16-bits of the subrange with a mask of 0xffff00ff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Fixed.

@hainest
Copy link
Contributor Author

hainest commented Nov 21, 2023

A couple changes in getBaseRegister, then it looks good to me.

If you feel ambitious, you could make and use mask constants and for the components of a register (id, alias/subrange, category, arch), so it is clearer, and less implementation details are spilled everywhere. Even more ambitious would be to create and use functions to get the components of the register that use the masks.

I think a small, but useful, first step is to make member functions to get each piece (like regClass() that's never used...). Ultimately, I think putting all of these values into enums and giving MachRegister a real constructor that can deal with types for the fields instead of bits in a signed int.

@hainest
Copy link
Contributor Author

hainest commented Nov 21, 2023

@kupsch Rebased onto #1629 and added 18d78f4.

@kupsch
Copy link
Contributor

kupsch commented Nov 21, 2023

Looks good.

@hainest hainest merged commit 30f08e7 into master Nov 21, 2023
3 checks passed
@hainest hainest deleted the thaines/x86_64_registers branch November 21, 2023 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Bring the code up to modern standards or remove deprecated features dataflowAPI This issue is directly related to dataflowAPI dyninstAPI This issue is directly related to dyninstAPI instructionAPI This issue is directly related to instructionAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants