
Chapter 3: General-Purpose Programming
115
24593—Rev. 3.09—September 2003
AMD 64-Bit Technology
the same location as the prior write. In this case, the read
instruction stalls until the write instruction is committed.
This is because the result of the write instruction is required
by the read instruction for software to operate correctly.
Some system devices might be sensitive to reads. Normally,
applications do not have direct access to system devices, but
instead call an operating-system service routine to perform the
access on the application’s behalf. In this case, it is system
software’s responsibility to enforce strong read-ordering.
Write Ordering.
Writes affect program order because they affect
the state of software-visible resources. The rules governing
write ordering are restrictive:
Generally, out-of-order writes are not allowed.
Write
instructions executed out-of-order cannot
commit
(write)
their result to memory until all previous instructions have
completed in program order. The processor can, however,
hold the result of an out-of-order write instruction in a
private buffer (not visible to software) until that result can
be committed to memory.
System software can create non-cacheable
write-combining
regions in memory when the order of writes is known to not
affect system devices. When writes are performed to write-
combining memory, they can appear to complete out of
order relative to other writes. See “Memory System” in
Volume 2 for additional information.
Speculative writes are not allowed.
As with out-of-order
writes, speculative write instructions cannot commit their
result to memory until all previous instructions have
completed in program order. Processors can hold the result
in a private buffer (not visible to software) until the result
can be committed.
3.9.2
Forcing Memory
Order
Special instructions are provided for application software to
force memory ordering in situations where such ordering is
important. These instructions are:
Load Fence
—The LFENCE instruction forces ordering of
memory loads (reads). All memory loads preceding the
LFENCE (in program order) are completed prior to
completing memory loads following the LFENCE. Memory
loads cannot be reordered around an LFENCE instruction,