25112 Rev. 3.06 September 2005

Software Optimization Guide for AMD64 Processors

5.15Cache Issues when Writing Instruction Bytes to Memory

Optimization

When writing data consisting of instructions for future execution to memory use streaming store (write-combining) instructions such as MOVNTDQ and MOVNTI.

Application

This optimization applies to:

32-bit software

64-bit software

Rationale

This optimization pertains to software that writes executable instructions to memory for subsequent execution, such as might be done by a just-in-time compiler. If normal store instructions are used to write the code to memory, then the cache lines will be in a modified state (either in L1 data cache or in L2). When the processor eventually tries to execute the code, it will miss in the instruction cache. Because the instruction cache cannot contain cache lines that are in a modified state, the data must be flushed to memory before it can be fetched into the instruction cache. This unneccesarily evicts possibly useful information from the caches. By using write-combining instructions, the contents of the cache is preserved with no performance penalty, and this possibly provides a performance improvement.

Chapter 5

Cache and Memory Optimizations

123

Page 139
Image 139
AMD 250 manual Cache Issues when Writing Instruction Bytes to Memory, 123