dalibocai
dalibocai

Reputation: 2347

How to disable/enable prefetching in GCC?

Does -O3 enable prefetching in GCC? If so, how can I disable prefetching? Is there an option to control the "aggressiveness" of prefetching? For example, the amount of data to prefetch in each iteration.

Upvotes: 3

Views: 3815

Answers (1)

Grzegorz Szpetkowski
Grzegorz Szpetkowski

Reputation: 37944

According to GCC's Data Prefetch Support website currently possible options are:

Existing data prefetch support in GCC includes:

  • A generic prefetch RTL pattern.
  • Target-specific support for several targets.
  • A __builtin_prefetch function that does nothing on targets that do not support prefetch or for which prefetch support has not yet
    been added to GCC.
  • An optimization enabled by -fprefetch-loop-arrays that prefetches arrays used in loops.

Then looking into Optimize Options it looks that -fprefetch-loop-arrays needs to enabled expicitely (that is, it's not enabled even with -O3).

If supported by the target machine, generate instructions to prefetch memory to improve the performance of loops that access large arrays.

This option may generate better or worse code; results are highly dependent on the structure of loops within the source code.

Disabled at level -Os.

Note that GCC's C99 status page claims, that it currently does not take into account C99 static keyword for arrays in context of function declarator (C99 6.7.5.3/7). That means that "large array" size and what it really means is controlled solely by implementation.

Upvotes: 4

Related Questions