13.07.2015 Views

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

Intel® 64 and IA-32 Architectures Optimization Reference Manual

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

GENERAL OPTIMIZATION GUIDELINESCMP <strong>and</strong> TEST can not be fused when comparing MEM-IMM (e.g. CMP [EAX],0x80; JZlabel). Macro-fusion is not supported in <strong>64</strong>-bit mode.Assembly/Compiler Coding Rule 19. (M impact, ML generality) Employmacro-fusion where possible using instruction pairs that support macro-fusion.Prefer TEST over CMP if possible. Use unsigned variables <strong>and</strong> unsigned jumps whenpossible. Try to logically verify that a variable is non-negative at the time ofcomparison. Avoid CMP or TEST of MEM-IMM flavor when possible. However, do notadd other instructions to avoid using the MEM-IMM flavor.Example 3-11. Macro-fusion, Unsigned Iteration CountWithout Macro-fusionWith Macro-fusionC codeDisassemblyfor (int 1 i = 0; i < 1000; i++)a++;for (int i = 0; i < 1000; i++)mov dword ptr [ i ], 0jmp FirstLoop:mov eax, dword ptr [ i ]add eax, 1mov dword ptr [ i ], eaxFirst:cmp dword ptr [ i ], 3E8H 3jge Enda++;mov eax, dword ptr [ a ]addqq eax,1mov dword ptr [ a ], eaxjmp LoopEnd:NOTES:1. Signed iteration count inhibits macro-fusion2. Unsigned iteration count is compatible with macro-fusion3. CMP MEM-IMM, JGE inhibit macro-fusion4. CMP REG-IMM, JAE permits macro-fusionfor ( unsigned int 2 i = 0; i < 1000; i++)a++;for ( unsigned int i = 0; i < 1000; i++)mov dword ptr [ i ], 0jmp FirstLoop:mov eax, dword ptr [ i ]add eax, 1mov dword ptr [ i ], eaxFirst:cmp eax, 3E8H 4jae Enda++;mov eax, dword ptr [ a ]add eax, 1mov dword ptr [ a ], eaxjmp LoopEnd:3-19

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!