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.

OPTIMIZING CACHE USAGEThe use of weakly-ordered memory types can be important under certain datasharing relationships (such as a producer-consumer relationship). Using weaklyorderedmemory can make assembling the data more efficient, but care must betaken to ensure that the consumer obtains the data that the producer intended to see.Some common usage models may be affected by weakly-ordered stores. Examplesare:• Library functions, which use weakly-ordered memory to write results• Compiler-generated code, which also benefits from writing weakly-orderedresults• H<strong>and</strong>-crafted codeThe degree to which a consumer of data knows that the data is weakly-ordered canvary for different cases. As a result, SFENCE should be used to ensure orderingbetween routines that produce weakly-ordered data <strong>and</strong> routines that consume thisdata.9.5.4.2 LFENCE InstructionThe LFENCE (LOAD FENCE) instruction makes it possible for every LOAD instructionthat precedes the LFENCE instruction in program order to be globally visible beforeany LOAD instruction that follows the LFENCE.The LFENCE instruction provides a means of segregating LOAD instructions fromother LOADs.9.5.4.3 MFENCE InstructionThe MFENCE (MEMORY FENCE) instruction makes it possible for every LOAD/STOREinstruction preceding MFENCE in program order to be globally visible before anyLOAD/STORE following MFENCE. MFENCE provides a means of segregating certainmemory instructions from other memory references.The use of a LFENCE <strong>and</strong> SFENCE is not equivalent to the use of a MFENCE since theload <strong>and</strong> store fences are not ordered with respect to each other. In other words, theload fence can be executed before prior stores <strong>and</strong> the store fence can be executedbefore prior loads.MFENCE should be used whenever the cache line flush instruction (CLFLUSH) is usedto ensure that speculative memory references generated by the processor do notinterfere with the flush. See Section 9.5.5, “CLFLUSH Instruction.”9-11

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

Saved successfully!

Ooh no, something went wrong!