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 (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 (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 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.
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.
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.
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.
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.
(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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With