Skip to content

Commit

Permalink
Disable MOV 0 check
Browse files Browse the repository at this point in the history
References #7.
  • Loading branch information
gaul committed Sep 26, 2021
1 parent 5102d3a commit 0b116b7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compiler writers generate better code and documents the complexity of x86.
* oversized immediates
- `81C0 01000000` instead of `83C0 01` (ADD EAX, 1)
* strength-reduce AND with immediate to movzbl
* suboptimal no-ops
* ~~suboptimal no-ops~~, see [#7](https://github.com/gaul/x86lint/issues/7)
- multiple `90` instead of a single `60 90`, etc.
* suboptimal zero register
- MOV EAX, 0 instead of XOR EAX, EAX
Expand Down
3 changes: 3 additions & 0 deletions x86lint.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ int check_instructions(const uint8_t *inst, size_t len)
++errors;
}

// TODO: Disabled due to false positives from CMOV sequences. See #7.
/*
result = check_mov_zero(&xedd);
if (!result) {
printf("suboptimal zero register at offset: %zu\n", offset);
Expand All @@ -562,6 +564,7 @@ int check_instructions(const uint8_t *inst, size_t len)
printf("\n");
++errors;
}
*/

result = check_implicit_register(&xedd);
if (!result) {
Expand Down
5 changes: 4 additions & 1 deletion x86lint_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,18 @@ int main(int argc, char *argv[])
0x48, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // mov rax, 0
0x05, 0x80, 0x00, 0x00, 0x00, // add eax, 0x80
0x40, 0xc9, // leave
// TODO: Disabled due to false positives from CMOV sequences. See #7.
/*
0xB8, 0x00, 0x00, 0x00, 0x00, // mov eax, 0
*/
0x81, 0xC0, 0x00, 0x01, 0x00, 0x00, // add eax, 0x100
0x05, 0x01, 0x00, 0x00, 0x00, // add eax, 1
0xc1, 0xd0, 0x01, // rcl eax, 1
0x83, 0xe0, 0xff, // and eax, 0xff
0x67, 0x0f, 0xc1, 0x18, // xadd [eax], ebx
0xf0, 0x87, 0x07, // lock xchg [eax], ebx
};
int expected = 11;
int expected = 10;
int actual = check_instructions(inst, sizeof(inst));
if (actual != expected) {
printf("Expected %d errors, actual: %d\n", expected, actual);
Expand Down

0 comments on commit 0b116b7

Please sign in to comment.