假设一个 SSE 寄存器包含一个或多个不能表示为 32 位 int 的压缩值(例如 Inf
或 NaN
),以及一个 convert-to-int被调用,例如_mm_cvtpd_epi32
/cvtpd2dq
。
- 是否安全,即行为是否已定义?
- 它会破坏控制流,还是只是举个旗帜?
- 如果定义了,转换的结果是什么?
最佳答案
这些问题的答案大多可以在 Intel® 64 and IA-32 Architectures Software Developer’s Manual 中找到:
CVTPD2DQ
... If a converted result is larger than the maximum signed doubleword integer, the floating-point invalid exception is raised, and if this exception is masked, the indefinite integer value (80000000H) is returned.
本节中没有明确说明,但这也适用于无穷大和 NaN。所以:
- 是的,行为已定义。
- 在默认的浮点环境下(即在 MXCSR 中屏蔽了无效异常),它不会中断控制流;它只设置一个标志。
- 结果是
0x80000000
。
关于floating-point - SSE/AVX 浮点转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31571543/