pub enum OptLevel {
None,
Size,
Aggressive,
}Expand description
Optimization level for encoding.
The levels differ in what an optimization is allowed to change, not just in how hard it tries:
| Level | May shrink encodings | May change architectural state |
|---|---|---|
None | no | no |
Size (default) | yes | no |
Aggressive | yes | yes (FLAGS only) |
Size is the default because every transform it performs
is observationally equivalent: the rewritten instruction leaves registers,
memory and FLAGS exactly as the original would.
Aggressive additionally permits rewrites that
clobber FLAGS — notably
the zero idiom mov reg, 0 → xor reg, reg. That is a real semantic
change: it silently breaks sequences such as
cmp eax, ebx
mov eax, 0 ; must not disturb FLAGS
sete also it must be opted into explicitly, and only where FLAGS are known dead.
Variants§
None
No optimizations — byte-for-byte predictable output.
Size
Prefer shortest encodings, but only via transforms that preserve all architectural state including FLAGS (default).
Aggressive
Also allow transforms that clobber FLAGS (e.g. the mov reg, 0 zero
idiom). Only safe when FLAGS are dead after the rewritten instruction.