本文介绍了像Denormals-Are-Zero(DAZ)这样的异常标志是否会影响相等性的比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有2个具有不同位模式的非正规浮点数并比较它们是否相等,结果是否会受到Denormals-Are-Zero标志,Flush-to-Zero标志或常用处理器上的其他标志的影响?

If I have 2 denormal floating point numbers with different bit patterns and compare them for equality, can the result be affected by the Denormals-Are-Zero flag, the Flush-to-Zero flag, or other flags on commonly used processors?

还是这些标志仅影响计算而不影响相等性检查?

Or do these flags only affect computation and not equality checks?

推荐答案

DAZ(异常 Are 零)会影响读取输入,因此 DAZ会影响比较.根据其符号,所有异常值都按字面意义被视为 -0.0 +0.0 .

DAZ (Denormals Are Zero) affects reading input, so DAZ affects compares. All denormals are literally treated as -0.0 or +0.0, according to their sign.

FTZ(刷新为零)仅影响写入输出,因此 FTZ不影响比较.比较不会产生FP输出,因此无需刷新.

FTZ (Flush To Zero) affects only writing output, so FTZ doesn't affect compares. Compares don't produce an FP output, so there's nothing to flush.

(DAZ和FTZ是SSE MXCSR控制/状态寄存器中的标志.x87没有等效项.)

(DAZ and FTZ are flags in the SSE MXCSR control/status register. There is no equivalent for x87.)

为什么两个标志分别存在,而不是一个标志同时控制两个事物?我不知道,但是您肯定需要两种效果.

Why do both flags exist separately, instead of one flag controlling both things? I don't know, but you definitely need both effects.

您可能正在从文件或网络中读取FP数据,因此您可以直接获得非正规输入,而不是计算结果.因此,您需要DAZ.

You might be reading FP data from a file, or from the network, so you could get denormal inputs directly, not the result of your calculations. So you need DAZ for that.

产生正确的异常输出(例如,减去附近的正常数或将两个小的正常数相乘)可能会很慢,因此您需要FTZ允许CPU仅下溢到 +-0.0 微码辅助以获取正确的值的方法.

Producing a correct denormal output (e.g. from subtracting nearby normal numbers, or multiplying two small normal numbers) is potentially slow, so you need FTZ to allow the CPU to just underflow to +-0.0 instead of taking a microcode assist to get the right value.

或者您可能使一个线程运行快速数学(FTZ + DAZ),而另一个线程运行精确数学以进行某些需要它的计算.如果快速数学线程读取精确线程产生的数据,则这些数字可能是反常数.

Or you might have one thread run with fast-math (FTZ+DAZ), while another thread runs with precise math for some computations that require it. If the fast-math thread reads data produced by the precise thread, those numbers might be denormals.

我不确定设置DAZ而不是FTZ的用例,反之亦然.当然,这将涉及读取您自己未生成的数据,或为您自己之外的读者编写数据,否则,只有FTZ才能避免任何速度下降.

I'm not sure what a use-case would be for setting DAZ but not FTZ, or vice versa. It would certainly involve reading data you didn't produce yourself, or writing data for readers other than yourself, otherwise just FTZ is sufficient to avoid any slowdowns.

(仅DAZ是不够的:即使下一个操作将其视为0,从正常输入产生异常输出仍然很慢.)

(Just DAZ alone is not sufficient: producing a denormal output from normal inputs is still slow, even if the next operation treats it as 0.)

这篇关于像Denormals-Are-Zero(DAZ)这样的异常标志是否会影响相等性的比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 09:00