When should we use prefetch?

后端 未结 6 1825
花落未央
花落未央 2020-12-03 12:27

Some CPU and compilers supply prefetch instructions. Eg: __builtin_prefetch in GCC Document. Although there is a comment in GCC\'s document, but it\'s too short to me.

6条回答
  •  余生分开走
    2020-12-03 13:22

    The article 'What Every Programmer Should Know About Memory Ulrich Drepper' discusses situations where pre-fetching is advantageous; http://www.akkadia.org/drepper/cpumemory.pdf , warning: this is quite a long article that discusses things like memory architecture / how the cpu works, etc.

    prefetching gives something if the data is aligned to cache lines; and if you are loading data that is about to be accessed by the algorithm;

    In any event one should do this when trying to optimize highly used code; benchmarking is a must and things usually work out differently than one might use to think.

提交回复
热议问题