Random NOP bytes in my binary

Programming, for all ages and all languages.
Post Reply
angods
Member
Member
Posts: 26
Joined: Sat Oct 23, 2021 5:36 am

Random NOP bytes in my binary

Post 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
Octocontrabass
Member
Member
Posts: 5486
Joined: Mon Mar 25, 2013 7:01 pm

Re: Random NOP bytes in my binary

Post 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.
angods
Member
Member
Posts: 26
Joined: Sat Oct 23, 2021 5:36 am

Re: Random NOP bytes in my binary

Post 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
Post Reply