zlacker

[parent] [thread] 8 comments
1. jcranm+(OP)[view] [source] 2024-01-16 20:26:59
This advice is out-of-date.

All CPU hardware nowadays conforms to IEEE 754 semantics for binary32 and binary64. (I think all the GPUs now have non-denormal-flushing modes, but my GPU knowledge is less deep). All compilers will have a floating-point mode that preserves IEEE 754 semantics assuming that FP exceptions are unobservable and rounding mode is the default, and this is usually the default (icc/icx is unusual in making fast-math the default).

Thus, you have portability of floating-point semantics, subject to caveats:

* The math library functions [1] are not the same between different implementations. If you want portability, you need to ensure that you're using the exact same math library on all platforms.

* NaN payloads are not consistent on different platforms, or necessarily within the same platform due to compiler optimizations. Note that not even IEEE 754 attempts to guarantee NaN payload stability.

* Long double is not the same type on different platforms. Don't use it. Seriously, don't.

* 32-bit x86 support for exact IEEE 754 equivalence is essentially a "known-WONTFIX" bug. (This is why the C standard implemented FLT_EVAL_METHOD). The x87 FPU evaluates everything in 80-bit precision, and while you can make this work for binary32 easily (double rounding isn't an issue), though with some performance cost (the solution involves reading/writing from memory after every operation), it's not so easy for binary64. However, the SSE registers do implement IEEE 754 exactly, and are present on every chip old enough to drink, so it's not really a problem anymore. There's a subsidiary issue that the x86-32 ABI requires floats be returned in x87 registers, which means you can't properly return an sNaN correctly, but sNaN and floating-point exceptions are firmly in the realm of nonportability anyways.

In short, if you don't need to care about 32-bit x86 support (or if you do care but can require SSE2 support), and you don't care about NaNs, and you bring your own libraries along, you can absolutely expect to have floating-point portability.

[1] It's actually not even all math library functions, just those that are like sin, pow, exp, etc., but specifically excluding things like sqrt. I'm still trying to come up with a good term to encompass these.

replies(4): >>zozbot+p1 >>fl0ki+y4 >>Ashame+n5 >>accoun+xH1
2. zozbot+p1[view] [source] 2024-01-16 20:33:37
>>jcranm+(OP)
> It's actually not even all math library functions, just those that are like sin, pow, exp, etc., but specifically excluding things like sqrt. I'm still trying to come up with a good term to encompass these.

Transcendental functions. They're called that because computing an exactly rounded result might be unfeasible for some inputs. https://en.wikipedia.org/wiki/Table-maker%27s_dilemma So standards for numerical compute punt on the issue and allow for some error in the last digit.

replies(2): >>jcranm+J2 >>lifthr+Ua1
◧◩
3. jcranm+J2[view] [source] [discussion] 2024-01-16 20:40:14
>>zozbot+p1
Not all of the functions are transcendental--things like cbrt and rsqrt are in the list, and they're both algebraic.

(The main defining factor is if they're an IEEE 754 §5 operation or not, but IEEE 754 isn't a freely-available standard.)

4. fl0ki+y4[view] [source] 2024-01-16 20:50:22
>>jcranm+(OP)
Not sure if this is a spooky coincidence, but I happened to be reading the Rust 1.75.0 release notes today and fell into this 50-tab rabbit hole: https://github.com/rust-lang/rust/pull/113053/
5. Ashame+n5[view] [source] 2024-01-16 20:54:01
>>jcranm+(OP)
> this is usually the default

No, it's not. gcc itself still defaults to fp-contract=fast. Or at least does in all versions I have ever tried.

◧◩
6. lifthr+Ua1[view] [source] [discussion] 2024-01-17 04:10:17
>>zozbot+p1
While it is a difficult problem, it is not an infeasible problem nowdays, at least for trigonometric, logarithmic and exponential functions. (All possible arguments have been mapped to prove how many additional bits are needed for correct rounding.) Two-argument pow remains an unsolved problem in my knowledge though.
replies(1): >>jcranm+gf1
◧◩◪
7. jcranm+gf1[view] [source] [discussion] 2024-01-17 04:50:21
>>lifthr+Ua1
My understanding is we have exhaustively enumerated the unary binary32 functions and proved the correctness of correct-rounding for them. For binary64, exhaustive enumeration is not a viable strategy, but we generally have a decent idea of what cases end up being hard-to-round, and in a few cases, we may have mechanical proofs of correctness.

There was a paper last year on binary64 pow (https://inria.hal.science/hal-04159652/document) which suggests that they have a correctly-rounded pow implementation, but I don't have enough technical knowledge to assess the validity of the claim.

replies(1): >>lifthr+Ig1
◧◩◪◨
8. lifthr+Ig1[view] [source] [discussion] 2024-01-17 05:08:04
>>jcranm+gf1
For your information, binary64 has been indeed mapped exhaustively for several functions [1], so it is known that at most triple-double representation is enough for correct rounding.

[1] https://inria.hal.science/inria-00072594/document

> There was a paper last year on binary64 pow (https://inria.hal.science/hal-04159652/document) which suggests that they have a correctly-rounded pow implementation, but I don't have enough technical knowledge to assess the validity of the claim.

Thank you for the pointer. These were written by usual folks you'd expect from such papers (e.g. Paul Zimmermann) so I believe they did achieve significant improvement. Unfortunately it is still not complete, the paper notes that the third and final phase may still fail but is unknown whether it indeed occurs or not. So we will have to wait...

9. accoun+xH1[view] [source] 2024-01-17 09:01:52
>>jcranm+(OP)
> All CPU hardware nowadays conforms to IEEE 754 semantics for binary32 and binary64.

Is this out of date?

https://developer.arm.com/documentation/den0018/a/NEON-Instr...

[go to top]