Re: [PATCH 0/3] ARM with only 32-bit floats do not have fast 64-bit FMA
Brian Inglis <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Organization | Systematic Software |
| Message-ID | <[email protected]> |
On 2020-09-07 11:16, Keith Packard via Newlib wrote: > Eric Bresie via Newlib <[email protected]> writes: > >> Not directly related (and as I’m not really an expert on these things, nor able to change in any way) but was looking at the code mentioned and saw line like: >> >> if (x == 0.0 || y == 0.0) >> >> return (x * y + z); >> >> If either x or y is zero would it be better to just return z and avoid >> an extra multiplication operation here? > > You want to compute the correct result and get the right exceptions in > all of the delightful IEEE754 corner cases (e.g. 0 × ∞). It's easier to > just execute the two operations than to try and synthesize the right > result (which is implementation-dependent in the case of 0 × ∞ + > qNaN). The key here is that if x or y is zero, then you won't lose any > intermediate precision by performing the operation this way. Can't the "super-smart" compiler use that information to work around your careful approach by conditionally skipping the FMA and conditionally return just z, or even unconditionally return z, as C makes no guarantees? And couldn't the "super-smart" instruction scheduler do similar at the hardware level? -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. [Data in IEC units and prefixes, physical quantities in SI.]