floating-point - SSE/AVX 浮点转换异常

标签 floating-point sse avx floating-point-exceptions

假设一个 SSE 寄存器包含一个或多个不能表示为 32 位 int 的压缩值(例如 InfNaN),以及一个 convert-to-int被调用,例如_mm_cvtpd_epi32/cvtpd2dq

  1. 是否安全,即行为是否已定义?
  2. 它会破坏控制流,还是只是举个旗帜?
  3. 如果定义了,转换的结果是什么?

最佳答案

这些问题的答案大多可以在 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。所以:

  1. 是的,行为已定义。
  2. 在默认的浮点环境下(即在 MXCSR 中屏蔽了无效异常),它不会中断控制流;它只设置一个标志。
  3. 结果是0x80000000

关于floating-point - SSE/AVX 浮点转换异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31571543/

相关文章:

php - 使用 (int) 和 (double) 一起截断小数时出错

c++ - 微小的 SSE addpd 循环比 AMD Phenom II 上的标量稍慢?

c++ - 英特尔存储故意重叠内存区域的指令

c++ - 内联汇编中的 sse 约束不起作用

c++ - 有符号的 8 位元素的 AVX2 整数乘法,产生有符号的 16 位结果?

c++ - __m256d TRANSPOSE4 等效?

floating-point - 在 double 的 MIN/MAX 范围内是否有 double 不能表示的整数?

c++ - 使用等式比较 float 的情况

c - %g 浮点表示的最大字符串长度是多少?

caching - 我对 AoS 与 SoA 优势/劣势的理解是否正确?