
116
Chapter 3: General-Purpose Programming
AMD 64-Bit Technology
24593—Rev. 3.09—September 2003
but other non-serializing instructions (such as memory
writes) can be reordered around the LFENCE.
Store Fence
—The SFENCE instruction forces ordering of
memory stores (writes). All memory stores preceding the
SFENCE (in program order) are completed prior to
completing memory stores following the SFENCE. Memory
stores cannot be reordered around an SFENCE instruction,
but other non-serializing instructions (such as memory
loads) can be reordered around the SFENCE.
Memory Fence
—The MFENCE instruction forces ordering of
all memory accesses (reads and writes). All memory accesses
preceding the MFENCE (in program order) are completed
prior to completing any memory access following the
MFENCE. Memory accesses cannot be reordered around an
MFENCE instruction, but other non-serializing instructions
that do not access memory can be reordered around the
MFENCE.
Although they serve different purposes, other instructions can
be used as read/write barriers when the order of memory
accesses must be strictly enforced. These read/write barrier
instructions force all prior reads and writes to complete before
subsequent reads or writes are executed. Unlike the fence
instructions listed above, these other instructions alter the
software-visible state. This makes these instructions less
general and more difficult to use as read/write barriers than the
fence instructions, although their use may reduce the total
number of instructions executed. The following instructions are
usable as read/write barriers:
Serializing instructions
—Serializing instructions force the
processor to commit the serializing instruction and all
previous instructions before the next instruction is fetched
from memory. The serializing instructions available to
applications are CPUID and IRET. A serializing instruction
is committed when the following operations are complete:
-
The instruction has executed.
-
All registers modified by the instruction are updated.
-
All memory updates performed by the instruction are
complete.
-
All data held in the write buffers have been written to
memory. (Write buffers are described in “Write
Buffering” on page 119).