Page 1 of 1

Random NOP bytes in my binary

Posted: Thu Oct 28, 2021 4:32 pm
by angods
My linker (or compiler?) generated strange NOP 9 byte sequences in my code between the functions...

66 0f 1f 84 00 00 00 nop word [rax+rax]
00 00 ---

Why does it put these in there? Alignment (address of the procedure after the bytes happens to be 16-aligned, so I'm guessing that can be the case)?

Is it related to the ICache maybe?

Thanks :D

Re: Random NOP bytes in my binary

Posted: Thu Oct 28, 2021 5:14 pm
by Octocontrabass
It's for alignment. Most CPUs fetch instructions in 16-byte blocks, so aligning functions to 16-byte boundaries means the CPU can decode more instructions before it needs to fetch the next block.

Agner Fog's optimization guides explain it in more detail.

Re: Random NOP bytes in my binary

Posted: Thu Oct 28, 2021 5:25 pm
by angods
Octocontrabass wrote:It's for alignment. Most CPUs fetch instructions in 16-byte blocks, so aligning functions to 16-byte boundaries means the CPU can decode more instructions before it needs to fetch the next block.

Agner Fog's optimization guides explain it in more detail.
Thanks! I thought it might be related to it, but I wasn't sure