When should we use prefetch?

后端 未结 6 1822
花落未央
花落未央 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:07

    There are definitely situations where software prefetch provides significant performance improvements.

    For example, if you are accessing a relatively slow memory device such as Optane DC Persistent Memory, which has access times of several hundred nanoseconds, prefetching can reduce effective latency by 50 percent or more if you can do it far enough in advance of the read or write.

    This isn't a very common case at present but it will become a lot more common if and when such storage devices become mainstream.

提交回复
热议问题