首页 / 知识

关于sse:x86中“非临时”内存访问的含义是什么

2023-04-13 18:45:00

关于sse:x86中“非临时”内存访问的含义是什么

What is the meaning of “non temporal” memory accesses in x86

这是一个有点底层的问题。 在x86汇编中,有两个SSE指令:

MOVDQA xmmi, m128

MOVNTDQA xmmi, m128

IA-32软件开发人员手册指出,MOVNTDQA中的NT代表非临时性,否则与MOVDQA相同。

我的问题是,非临时性是什么意思?


非临时性SSE指令(MOVNTI,MOVNTQ等)不遵循常规的缓存一致性规则。因此,非临时存储区后面必须带有SFENCE指令,以便其他处理器及时查看其结果。

当产生数据并且不再(立即)再次使用数据时,内存存储操作会先读取一条完整的缓存行,然后再修改缓存的数据,这一事实不利于性能。此操作将数据从高速缓存中推出,这可能需要再次使用,以支持即将不再使用的数据。这对于大型数据结构(例如矩阵)尤其如此,这些数据结构先被填充然后在以后使用。在填充矩阵的最后一个元素之前,绝对大小会逐出第一个元素,从而使写入的缓存无效。

对于这种情况和类似情况,处理器为非临时写操作提供支持。在这种情况下,非时间意味着数据将不会很快被重用,因此没有理由对其进行缓存。这些非临时写操作不会先读取高速缓存行,然后再对其进行修改。而是将新内容直接写入内存。

资料来源:http://lwn.net/Articles/255364/


埃斯波几乎可以达到目标。只是想加我的两分钱:

"非时间"短语意味着缺少时间局部性。缓存利用两种局部性-空间和时间性,通过使用非时间性指令,您正在向处理器发送信号,告知您您不希望在不久的将来使用该数据项。

我对使用缓存控制指令的手工编码程序集表示怀疑。以我的经验,这些错误导致的臭虫多于任何有效的性能提高。


根据英特尔? 64和IA-32体系结构软件开发人员手册,第1卷:基本体系结构,
"使用Intel Streaming SIMD扩展程序编程(Intel SSE)"一章:

缓存时态与非时态数据

Data referenced by a program can be temporal (data will be used again) or non-temporal (data will be referenced once and not reused in the immediate future). For example, program code is generally temporal, whereas, multimedia data, such as the display list in a 3-D graphics application, is often non-temporal. To make efficient use of the processor’s caches, it is generally desirable to cache temporal data and not cache non-temporal data. Overloading the processor’s caches with non-temporal data is sometimes referred to as"polluting the caches". The SSE and SSE2 cacheability control instructions enable a program to write non-temporal data to memory in a manner that minimizes pollution of caches.

非临时加载和存储指令的描述。
资料来源:英特尔64和IA-32架构软件开发人员手册,第2卷:指令集参考

加载(MOVNTDQA-加载双四字非时间对齐提示)

Loads a double quadword from the source operand (second operand) to the destination operand (first operand) using a non-temporal hint if the memory source is WC (write combining) memory type [...]

[...] the processor does not read the data into the cache hierarchy, nor does it fetch the corresponding cache line from memory into the cache hierarchy.

请注意,正如彼得·科德斯(Peter Cordes)所言,它在当前处理器上的普通WB(回写)内存上没有用,因为NT提示被忽略(可能是因为没有NT感知的硬件预取器),并且采用了完全强序加载语义。 prefetchnta可用作WB存储器的减少污染的负载

存储(MOVNTDQ-使用非时间提示存储打包的整数)

Moves the packed integers in the source operand (second operand) to the destination operand (first operand) using a non-temporal hint to prevent caching of the data during the write to memory.

[...] the processor does not write the data into the cache hierarchy, nor does it fetch the corresponding cache line from memory into the cache hierarchy.

使用在"高速缓存写策略和性能"中定义的术语,可以将它们视为"可写"(无写分配,无写丢失获取)。

最后,回顾一下John McAlpin关于非临时性商店的注释可能会很有趣。


内存指令汇编开发人员

最新内容

相关内容

热门文章

推荐文章

标签云

猜你喜欢