Intel ARCHITECTURE IA-32 User Manual Page 159

  • Download
  • Add to my manuals
  • Print
  • Page
    / 568
  • Table of contents
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 158
General Optimization Guidelines 2
2-87
Clearing Registers
Pentium 4 processor provides special support to xor, sub, or pxor
operations when executed within the same register. This recognizes that
clearing a register does not depend on the old value of the register. The
xorps and xorpd instructions do not have this special support. They
cannot be used to break dependence chains.
In Intel Core Solo and Intel Core Duo processors; the
xor, sub, xorps,
or
pxor instructions can be used to clear execution dependencies on the
zero evaluation of the destination register.
Assembly/Compiler Coding Rule 51. (M impact, ML generality) Use xor,
sub, or pxor to set a register to 0, or to break a false dependence chain
resulting from re-use of registers. In contexts where the condition codes must
be preserved, move
0 into the register instead. This requires more code space
than using xor and sub, but avoids setting the condition codes.
Compares
Use test when comparing a value in a register with zero. Test
essentially
ands the operands together without writing to a destination
register.
Test is preferred over and because and produces an extra result
register.
Test is better than cmp ..., 0 because the instruction size is
smaller.
Use
test when comparing the result of a logical and with an immediate
constant for equality or inequality if the register is
eax for cases such
as:
if (avar & 8) { }
The test instruction can also be used to detect rollover of modulo a
power of 2. For example, the C code:
if ( (avar % 16) == 0 ) { }
can be implemented using:
test eax, 0x0F
jnz AfterIf
Page view 158
1 2 ... 154 155 156 157 158 159 160 161 162 163 164 ... 567 568

Comments to this Manuals

No comments