examine x86 instructions to find suboptimal encodings and sequences
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
Makefile
README.md
asmlint.c
asmlint.h
asmlint_test.c

README.md

asmlint

asmlint examines x86 instructions to find suboptimal encodings and sequences. For example, add eax, 1 can encode with either an 8- or 32-bit immediate:

83C0 01
81C0 01000000

Using the former can result in smaller and faster code. asmlint can help compiler writers generate better code and documents the complexity of x86.

Analyses

  • implicit EAX
    • 81C0 00010000 instead of 05 00010000 (ADD EAX, 1)
  • oversized immediates
    • 81C0 01000000 instead of 83C0 01 (ADD EAX, 1)
  • suboptimal zero register
    • MOV EAX, 0 instead of XOR EAX, EAX
  • unnecessary REX prefix
    • 40C9 instead of C9 (LEAVE)

Possible analyses

single-instruction

  • CMP vs. TEST
  • nonsense instructions
    • MOV RAX, RAX
  • strength reduce MUL with immediate to LEA
  • unneeded LOCK prefix
    • XCHG

peephole

Compilation

First install the Intel x86 encoder decoder:

git clone https://github.com/intelxed/xed.git xed
git clone https://github.com/intelxed/mbuild.git mbuild
cd xed
./mfile.py install --install-dir=kits/xed-install

Next build asmlint:

git clone https://github.com/gaul/asmlint.git asmlint
cd asmlint
XED_PATH=/path/to/xed make all

References

License

Copyright (C) 2018 Andrew Gaul

Licensed under the Apache License, Version 2.0