Purpose
When specified with -O4, -O5,
or -qipa, specifies the cache configuration for a specific
execution machine.
If you know the type of execution system
for a program, and that system has its instruction or data cache configured
differently from the default case, use this option to specify the
exact cache characteristics. The compiler uses this information to
calculate the benefits of cache-related optimizations.
Syntax

.-:------------------------.
V |
>>- -q--cache--=----+-assoc--=----number---+-+-----------------><
+-auto-----------------+
+-cost--=--cycles------+
+-level--=--+-1-+------+
| +-2-+ |
| '-3-' |
+-line--=--bytes-------+
+-size--=--Kbytes------+
'-type--=--+-c-+-------'
+-d-+
'-i-'
Defaults
Automatically determined by the
setting of the -qtune option.
Parameters
- assoc
- Specifies the set associativity of the cache.
- number
- Is one of:
- 0
- Direct-mapped cache
- 1
- Fully associative cache
- N>1
- n-way set associative cache
- auto
- Automatically detects the specific cache configuration of the
compiling machine. This assumes that the execution environment will
be the same as the compilation environment.
- cost
- Specifies the performance penalty resulting from a cache miss.
- cycles
- level
- Specifies the level of cache affected. If a machine has more than one level of cache, use a separate -qcache option.
- level
- Is one of:
- 1
- Basic cache
- 2
- Level-2 cache or, if there is no level-2
cache, the table lookaside buffer (TLB)
- 3
- TLB
- line
- Specifies the line size of the cache.
- bytes
- An integer representing the number of bytes of the cache line.
- size
- Specifies the total size of the cache.
- Kbytes
- An integer representing the number of kilobytes of the total cache.
- type
- Specifies that the settings apply to the specified cache_type.
- cache_type
- Is one of:
- c
- Combined data and instruction cache
- d
- Data cache
- i
- Instruction cache
Usage
The -qtune setting determines the optimal default -qcache settings for
most typical compilations. You can use the -qcache to override
these default settings. However, if you specify the wrong values for
the cache configuration, or run the program on a machine with a different
configuration, the program will work correctly but may be slightly
slower.
You must specify -O4, -O5, or -qipa with the -qcache option.
Use the following guidelines
when specifying -qcache suboptions:
- Specify information for as many configuration parameters as possible.
- If the target execution system has more than one level of cache,
use a separate -qcache option to describe each cache level.
- If you are unsure of the exact size of the cache(s) on the target
execution machine, specify an estimated cache size on the small side.
It is better to leave some cache memory unused than it is to experience
cache misses or page faults from specifying a cache size larger than
actually present.
- The data cache has a greater effect on program performance than
the instruction cache. If you have limited time available to experiment
with different cache configurations, determine the optimal configuration
specifications for the data cache first.
- If you specify the wrong values for the cache configuration, or
run the program on a machine with a different configuration, program
performance may degrade but program output will still be as expected.
- The -O4 and -O5 optimization
options automatically select the cache characteristics of the compiling
machine. If you specify the -qcache option together with the -O4 or -O5 options, the option specified last takes precedence.
Examples
To tune
performance for a system with a combined instruction and data level-1
cache, where cache is 2-way associative, 8 KB in size and has 64-byte
cache lines, enter:
xlc -O4 -qcache=type=c:level=1:size=8:line=64:assoc=2 file.c