AMD amd64 architecture User Manual

Page of 336
56
General-Purpose Programming
AMD64 Technology
24592—Rev. 3.15—November 2009
SETcc instructions are often used to set logical indicators. Like CMOVcc instructions (page 42),
SETcc instructions can replace two instructions—a conditional jump and a move. Replacing
conditional jumps with conditional sets can help avoid branch-prediction penalties that may be caused
by conditional jumps.
If the logical value True (logical 1) is represented in a high-level language as an integer with all bits set
to 1, software can accomplish such representation by first executing the opposite SETcc instruction—
for example, the opposite of SETZ is SETNZ—and then decrementing the result.
Bounds
BOUND—Check Array Bounds
The BOUND instruction checks whether the value of the first operand, a signed integer index into an
array, is within the minimal and maximal bound values pointed to by the second operand. The values
of array bounds are often stored at the beginning of the array. If the bounds of the range are exceeded,
the processor generates a bound-range exception.
The primary disadvantage of using the BOUND instruction is its use of the time-consuming exception
mechanism to signal a failure of the bounds test.
3.3.9 Logical
The logical instructions perform bitwise operations.
AND—Logical AND
OR—Logical OR
XOR—Exclusive OR
NOT—One’s Complement Negation
The AND, OR, and XOR instructions perform their respective logical operations on the corresponding
bits of both operands and store the result in the first operand. The CF flag and OF flag are cleared to 0,
and the ZF flag, SF flag, and PF flag are set according to the resulting value of the first operand.
The NOT instruction performs logical inversion of all bits of its operand. Each zero bit becomes one
and vice versa. All flags remain unchanged.
Apart from performing logical operations, AND and OR can test a register for a zero or non-zero
value, sign (negative or positive), and parity status of its lowest byte. To do this, both operands must be
the same register. The XOR instruction with two identical operands is an efficient way of loading the
value 0 into a register.
3.3.10 String
The string instructions perform common string operations such as copying, moving, comparing, or
searching strings. These instructions are widely used for processing text.