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

assembler: Optimize mov rAX,[int32-offset] (64-bit mode) #269

Open
wtfsck opened this issue Feb 16, 2022 · 1 comment
Open

assembler: Optimize mov rAX,[int32-offset] (64-bit mode) #269

wtfsck opened this issue Feb 16, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@wtfsck
Copy link
Member

wtfsck commented Feb 16, 2022

It's currently always using mov rAX,[moffs] but if it fits in an i32, it's shorter to use mov rAX,[m] with a modrm byte.

The generated mov() methods would need to be updated. This is what the generated C# code looks like:

			if (dst.Value == Register.RAX && Bitness == 64 && src.IsDisplacementOnly) {
				code = Code.Mov_RAX_moffs64;

An extra check would need to be added to the first line to check if the displacement fits in an Int32, and if so, don't use mov rax,[moffs].

OpCodeSelectorKind.MemOffs64_RAX => $"{otherArgName}.Value == {GetRegisterString(nameof(Register.RAX))} && Bitness == 64 && {argName}.IsDisplacementOnly",
OpCodeSelectorKind.MemOffs64_EAX => $"{otherArgName}.Value == {GetRegisterString(nameof(Register.EAX))} && Bitness == 64 && {argName}.IsDisplacementOnly",
OpCodeSelectorKind.MemOffs64_AX => $"{otherArgName}.Value == {GetRegisterString(nameof(Register.AX))} && Bitness == 64 && {argName}.IsDisplacementOnly",
OpCodeSelectorKind.MemOffs64_AL => $"{otherArgName}.Value == {GetRegisterString(nameof(Register.AL))} && Bitness == 64 && {argName}.IsDisplacementOnly",

OpCodeSelectorKind.MemOffs64_RAX => $"{otherArgName}.register() == {GetRegisterString(nameof(Register.RAX))} && self.bitness() == 64 && {argName}.is_displacement_only()",
OpCodeSelectorKind.MemOffs64_EAX => $"{otherArgName}.register() == {GetRegisterString(nameof(Register.EAX))} && self.bitness() == 64 && {argName}.is_displacement_only()",
OpCodeSelectorKind.MemOffs64_AX => $"{otherArgName}.register() == {GetRegisterString(nameof(Register.AX))} && self.bitness() == 64 && {argName}.is_displacement_only()",
OpCodeSelectorKind.MemOffs64_AL => $"{otherArgName}.register() == {GetRegisterString(nameof(Register.AL))} && self.bitness() == 64 && {argName}.is_displacement_only()",

@wtfsck wtfsck added enhancement New feature or request help wanted Extra attention is needed labels Feb 16, 2022
@wtfsck wtfsck added this to the v1.17.0 milestone Feb 16, 2022
@wtfsck wtfsck added the good first issue Good for newcomers label Feb 16, 2022
@wtfsck wtfsck removed this from the v1.17.0 milestone Feb 24, 2022
@wtfsck

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant