英特尔架构和 IEEE 754 合规性(minNum 和 maxNum)?

Intel architecture and IEEE 754 compliance (minNum and maxNum)?

我查看了 x64 软件开发人员手册,内置的 {MIN|MAX}{S|P}{S|D} 指令似乎没有实现调用的函数IEEE 754 标准中的 minNum 和 maxNum,尽管英特尔在同一文档中声称其 CPU 完全符合标准。

Intel 操作总是 return second 操作数,如果任一操作数是 QNaN 且都不是 SNaN,而 minNum 和 maxNum return other操作数,即:

IEE 754:
minNum(1.0, QNaN) -> 1.0
minNum(QNaN, 1.0) -> 1.0

Intel x64:
MIN(1.0, QNaN) -> QNaN
MIN(QNaN, 1.0) -> 1.0

符合标准的 minNum/maxNum 函数必须通过额外检查第一个操作数来模拟并且不能直接转换为相应的指令,我是否正确?

是的,您将需要额外的说明。

Arch Robinson 在 this comment on a Julia issue thread 中对此进行了讨论:

The semantics of minsd were designed back in the '90s, well before IEEE 754-2008, so that compilers could optimize the common C idiom x<y?x:y.

这个问题继续建议一系列 AVX 指令使其 NaN 中毒。相反,如果您想要 IEEE 行为,则可以使用

VMIN R, a, b           // result is b if a or b are NaN, min(a,b) otherwise
                       // so Nan is not propagated only if a is the NaN
VCMPNEQ M, b, b        // M=11…11  if b is NaN, 0 otherwise
VBLENDV Res, R, a, M   // Res = R if M=0 (b not NaN), otherwise Res=a (if b is NaN)