performance - 为什么 SSE 指令保留 YMM 寄存器的高 128 位?

标签 performance x86 avx

好像是recurring problem许多英特尔处理器(直到 Skylake,除非我错了)在将 AVX-256 指令与 SSE 指令混合时表现出较差的性能。

根据 Intel's documentation ,这是由于 SSE 指令被定义为保留 YMM 寄存器的高 128 位,因此为了能够通过不使用 AVX 数据路径的高 128 位来节省功率,CPU 在执行 SSE 时将这些位存储起来代码并在输入 AVX 代码时重新加载它们,存储和加载很昂贵。

但是,我找不到明显的原因或解释为什么 SSE 指令需要保留那些高 128 位。相应的 128 位 VEX 指令(使用它可以避免性能损失)通过始终清除 YMM 寄存器的高 128 位而不是保留它们来工作。在我看来,当英特尔定义 AVX 架构时,包括将 XMM 寄存器扩展到 YMM 寄存器,他们可以简单地定义 SSE 指令也将清除高 128 位。显然,由于 YMM 寄存器是新的,因此不可能存在依赖于 SSE 指令保留这些位的遗留代码,而且在我看来,英特尔很容易看到这一点。

那么,Intel 定义 SSE 指令来保留 YMM 寄存器的高 128 位的原因是什么?它曾经有用吗?

最佳答案

为了在现场移动外部资源,我从the link Michael provided in the comments中提取了相关段落。 .

所有的功劳都归于他。
该链接指向了 Agner Fog 在英特尔论坛上提出的一个非常相似的问题。

[Fog in respone to Intel's answer] If I understand you right, you decided that it is necessary to have two versions of all 128-bit instructions in order to avoid destroying the upper part of the YMM registers in case an interrupt calls a device driver using legacy XMM instructions.



英特尔担心,通过使传统的 SSE 指令将 XMM 寄存器的上部归零,ISR 现在会突然
影响新的 YMM 寄存器。
如果不支持保存新的 YMM 上下文,这将使在任何情况下都无法使用 AVX
情况。

然而 Fog 并不完全满意,并指出通过简单地使用 AVX 感知编译器重新编译驱动程序(这样 VEX
指令)将导致相同的结果。

英特尔回答说,他们的目标是避免强制现有软件
改写。

There is no way we could compel the industry to rewrite/fix all of their existing drivers (for example to use XSAVE) and no way to guarantee they would have done so successfully. Consider for example the pain the industry is still going through on the transition from 32 to 64-bit operating systems! The feedback we have from OS vendors also precluded adding overhead to the ISR servicing to add the state management overhead on every interrupt. We didn't want to inflict either of these costs on portions of the industry that don't even typically use wide vectors.



通过使用两个版本的指令,可以像支持 FPU/SSE 一样在驱动程序中实现对 AVX 的支持:

The example given is similar to the current scenario where a ring-0 driver (ISR) vendor attempts to use floating-point state, or accidentally links it in some library, in OSs that do not automatically manage that context at Ring-0. This is a well known source of bugs and I can suggest only the following:

  • On those OSs, driver developers are discouraged from using floating-point or AVX

  • Driver developers should be encouraged to disable hardware features during driver validation (i.e. AVX state can be disabled by drivers in Ring-0 through XSETBV()

关于performance - 为什么 SSE 指令保留 YMM 寄存器的高 128 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41819514/

相关文章:

x86 - Linux/SMP 自旋锁不必要地慢吗?

c - 如何更改处理器堆栈?

c# - 在循环中执行 array.length 或 list.count 是否很昂贵

python - 我正在做很多列表和字典排序......这导致 Python 网站出现内存错误

c# - foreach 循环似乎很慢

assembly - IBM 5150 - int 21h 损坏段寄存器

c++ - shuffle/permute 内在函数如何为 256 位 pd 工作?

c++ - 使用 AVX 内在函数而不是 SSE 并不能提高速度——为什么?

c# - 包含字符串的结构与包含字符串的类的性能