x86 opcode alignment references and guidelines
- by mrjoltcola
I'm generating some opcodes dynamically in a JIT compiler and I'm looking for guidelines for opcode alignment.
1) I've read comments that briefly "recommend" alignment by adding nops after calls
2) I've also read about using nop for optimizing sequences for parallelism.
3) I've read that alignment of ops is good for "cache" performance
Usually these comments don't give any supporting references. Its one thing to read a blog or a comment that says, "its a good idea to do such and such", but its another to actually write a compiler that implements specific op sequences and realize most material online, especially blogs, are not useful for practical application. So I'm a believer in finding things out myself (disassembly, etc. to see what real world apps do). This is one case where I need some outside info.
I notice compilers will usually start an odd byte instruction immediately after whatever previous instruction sequence there was. So the compiler is not taking any special care in most cases. I see "nop" here or there, but usually it seems nop is used sparingly, if at all. How critical is opcode alignment? Can you provide references for cases that I can actually use for implementation? Thanks.