足迹

能看不尽景,始是不凡人

 

CPU二则

CPU二则

aligned load & unaligned load

看CPU指令手册的时候,会看到有两条指令:vmovups & vmovaps,这两条指令都是为了mov packed single point data between memory/AVX register。不一样的地方是就一个是u,一个是a。u的意思是unaligned,a的意思是aligned。这里的aligned的意思是什么呢? 经过查阅,发现它是指内存地址与AVX register的长度align(如AVX-2的话就是32 byte align, AVX-512的话就是64 byte align etc.)。那这两条指令的 performance有什么区别呢?答案是:自Nehalem以后,没有什么区别了。Intel对两条指令进行了优化,消除了vmovups的性能penalty。可以看下手册里两条指令的latency和throughput加深一下印象(8是latency,0.5是reciprocal throughput)。结论就是在任何场合可以直接使用vmovups就OK了。

Alt text

non-temporal store(streaming store)

vmovntps中的”nt”指的是non-temporal,意思就是说告诉CPU,我现在写的这个数据不遵守时间局部性,写完后不会读它,所以就不要遵循原来“读进cache(Read For Ownership)->写cache->写memory”的规则了,直接写memory就行了,免得污染cache,反而把那些需要用cache的程序的数据驱逐出去。这种方式也叫write around,即绕过cache写内存。如果cache policy是write through的话,如果遇到大块的写操作,write around肯定是比write through好的。但现在Xeon的cache policy是write back,这个有没有好处就需要实验来确定了。

Alt text

参考文献

  1. Nehalem - Everything You Need to Know about Intel’s New Architecture
  2. SKX Instruction Set Latency and Throughput Manual
  3. A case for the non-temporal store

posted on 2018-08-29 08:21  姚伟峰  阅读(1654)  评论(0编辑  收藏  举报

导航