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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>64</strong>-BIT MODE CODING GUIDELINESFor example, to sign-extend a byte into ESI, use:movsx rsi, BYTE PTR[rax]instead of:movsx esi, BYTE PTR[rax]If the next instruction uses the <strong>32</strong>-bit form of esi register, the result will be the same.This optimization can also be used to break an unintended dependency. For example,if a program writes a 16-bit value to a register <strong>and</strong> then writes the register with an 8-bit value, if bits 15:8 of the destination are not needed, use the sign-extendedversion of writes when available.For example:mov r8w, r9w; Requires a merge to preserve; bits 63:15.mov r8b, r10b; Requires a merge to preserve bits 63:8Can be replaced with:movsx r8, r9w ; If bits 63:8 do not need to be; preserved.movsx r8, r10b ; If bits 63:8 do not need to; be preserved.In the above example, the moves to R8W <strong>and</strong> R8B both require a merge to preservethe rest of the bits in the register. There is an implicit real dependency on R8 betweenthe 'MOV R8W, R9W' <strong>and</strong> 'MOV R8B, R10B'. Using MOVSX breaks the real dependency<strong>and</strong> leaves only the output dependency, which the processor can eliminatethrough renaming.Assembly/Compiler Coding Rule 68. (M impact, M generality) Sign extend to<strong>64</strong>-bits instead of sign extending to <strong>32</strong> bits, even when the destination will be usedas a <strong>32</strong>-bit value.9.3 ALTERNATE CODING RULES FOR <strong>64</strong>-BIT MODE9.3.1 Use <strong>64</strong>-Bit Registers Instead of Two <strong>32</strong>-Bit Registersfor <strong>64</strong>-Bit ArithmeticLegacy <strong>32</strong>-bit mode offers the ability to support extended precision integer arithmetic(such as <strong>64</strong>-bit arithmetic). However, <strong>64</strong>-bit mode offers native support for<strong>64</strong>-bit arithmetic. When <strong>64</strong>-bit integers are desired, use the <strong>64</strong>-bit forms of arithmeticinstructions.In <strong>32</strong>-bit legacy mode, getting a <strong>64</strong>-bit result from a <strong>32</strong>-bit by <strong>32</strong>-bit integer multiplyrequires three registers; the result is stobbred in <strong>32</strong>-bit chunks in the EDX:EAX pair.When the instruction is available in <strong>64</strong>-bit mode, using the <strong>32</strong>-bit version of the9-3

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

Saved successfully!

Ooh no, something went wrong!