zlacker

[parent] [thread] 49 comments
1. dahart+(OP)[view] [source] 2024-01-16 15:05:15
Why do you say almost never? Don’t let the name scare you; all floating point math is inaccurate. Fast math is only slightly less accurate, I think typically it’s a 1 or maybe 2 LSB difference. At least in CUDA it is, and I think many (most?) people & situations can tolerate 22 bits of mantissa compared to 23, and many (most?) people/situations aren’t paying attention to inf/nan/exception issues at all.

I deal with a lot of floating point professionally day to day, and I use fast math all the time, since the tradeoff for higher performance and the relatively small loss of accuracy are acceptable. Maybe the biggest issue I run into is lack of denorms with CUDA fast-math, and it’s pretty rare for me to care about numbers smaller than 10^-38. Heck, I’d say I can tolerate 8 or 16 bits of mantissa most of the time, and fast-math floats are way more accurate than that. And we know a lot of neural network training these days can tolerate less than 8 bits of mantissa.

replies(4): >>mort96+42 >>useful+J9 >>jcranm+Wd >>light_+WS
2. mort96+42[view] [source] 2024-01-16 15:14:44
>>dahart+(OP)
The scary thing IMO is: your code might be fine with unsafe math optimisations, but maybe you're using a library which is written to do operations in a certain order to minimise numerical error, and unsafe math operations changes the code which are mathematically equivalent but which results in many orders of magnitude more numerical error. It's probably fine most of the time, but it's kinda scary.
replies(1): >>dahart+t3
◧◩
3. dahart+t3[view] [source] [discussion] 2024-01-16 15:22:16
>>mort96+42
It shouldn’t be scary. Any library that is sensitive to order of operations will hopefully have a big fat warning on it. And it can be compiled separately with fast-math disabled. I don’t know of any such libraries off the top of my head, and it’s quite rare to find situations that result in orders of magnitude more error, though I grant you it can happen, and it can be contrived pretty easily.
replies(2): >>planed+Y3 >>mort96+Pa
◧◩◪
4. planed+Y3[view] [source] [discussion] 2024-01-16 15:24:50
>>dahart+t3
You can't fully disable fast-math per-library, moreover a library compiled with fast-math might also introduce inaccuracies in a seemingly unrelated library or application code in the same executable. The reason is that fast-math enables some dynamic initialization of the library that changes the floating point environment in some ways.
replies(2): >>london+a7 >>dahart+L9
◧◩◪◨
5. london+a7[view] [source] [discussion] 2024-01-16 15:37:15
>>planed+Y3
you're gonna hive to give us a concrete real world example to convince most of us...
6. useful+J9[view] [source] 2024-01-16 15:46:10
>>dahart+(OP)
> Fast math is only slightly less accurate

'slightly'? Last I checked, -Ofast completely breaks std::isnan and std::isinf--they always return false.

replies(2): >>dahart+kb >>xigoi+cF
◧◩◪◨
7. dahart+L9[view] [source] [discussion] 2024-01-16 15:46:14
>>planed+Y3
> You can’t fully disable fast-math per library

Can you elaborate? What fast-math can sneak into a library that disabled fast-math at compile time?

> fast-math enables some dynamic initialization of the library that changes the floating point environment in some ways.

I wasn’t aware of this, I would love to see some documentation discussing exactly what happens, can you send a link?

replies(2): >>mort96+eb >>jcranm+Qf
◧◩◪
8. mort96+Pa[view] [source] [discussion] 2024-01-16 15:51:17
>>dahart+t3
I don't typically thoroughly read through the documentation for all the dependencies which my dependencies are using.

But you're correct that it's probably usually fine in practice.

replies(1): >>dahart+ce
◧◩◪◨⬒
9. mort96+eb[view] [source] [discussion] 2024-01-16 15:53:07
>>dahart+L9
> Can you elaborate? What fast-math can sneak into a library that disabled fast-math at compile time?

A lot of library code is in headers (especially in C++!). The code in headers is compiled by your compiler using your compile options.

replies(1): >>dahart+Qb
◧◩
10. dahart+kb[view] [source] [discussion] 2024-01-16 15:53:31
>>useful+J9
Hopefully it was clear from the rest of my comment that I was talking about in-range floats there. I wouldn’t necessarily call inf & nan handling an accuracy issue, that’s more about exceptional cases, but to your point I would have to agree that losing std::isinf is kinda bad since divide by zero is probably near the very top of the list of things most people using floats casually might have to deal with.

Which compiler are you using where std::isinf breaks? Hopefully it was also clear that my experience leans toward CUDA, and I think the inf & nan support works there in the presence of NVCC’s fast-math.

replies(1): >>useful+oi
◧◩◪◨⬒⬓
11. dahart+Qb[view] [source] [discussion] 2024-01-16 15:55:06
>>mort96+eb
Ah, of course, very good point. A header-only library doesn’t have separate compile options. This is a great reason for a float-sensitive library to not be header-only, right?
replies(1): >>mort96+vd
◧◩◪◨⬒⬓⬔
12. mort96+vd[view] [source] [discussion] 2024-01-16 16:02:17
>>dahart+Qb
It's not just about being header-only, lots of libraries which aren't header-only still have code in headers. The library may choose to put certain functions in headers for performance reasons (to let compiler inline them), or, in C++, function templates and class templates generally have to be in headers.

But yeah, it's probably a good idea to not put code which breaks under -ffast-math in headers if possible.

13. jcranm+Wd[view] [source] 2024-01-16 16:04:36
>>dahart+(OP)
Here are some of the problems with fast-math:

* It links in an object file that enables denormal flushing globally, so that it affects all libraries linked into your application, even if said library explicitly doesn't want fast-math. This is seriously one of the most user-hostile things a compiler can do.

* The results of your program will vary depending on the exact make of your compiler and other random attributes of your compile environment, which can wreak havoc if you have code that absolutely wants bit-identical results. This doesn't matter for everybody, but there are some domains where this can be a non-starter (e.g., multiplayer game code).

* Fast-math precludes you from being able to use NaN or infinities, and often even being able to defensively test for NaN or infinity. Sure, there are times where this is useful, but an option you might generally prefer to suggest for an uninformed programmer would rather be a "floating-point code can't overflow" option rather than "infinity doesn't exist and it's UB if it does exist".

* Fast-math can cause hard range guarantees to fail. Maybe you've got code that you can prove that, even with rounding error, the result will still be >= 0. With fast-math, the code might be adjusted so that the result is instead, say, -1e-10. And if you pass that to a function with a hard domain error at 0 (like sqrt), you now go from the result being 0 to the result being NaN. And see above about what happens when you get NaN.

Fast-math is a tradeoff, and if you're willing to except the tradeoff it offers, it's a fine option to use. But most programmers don't even know what the tradeoffs are, and the failure mode can be absolutely catastrophic. It's definitely an option that is in the "you must be this knowledgeable to use" camp.

replies(2): >>dahart+pi >>fl0ki+Z51
◧◩◪◨
14. dahart+ce[view] [source] [discussion] 2024-01-16 16:05:41
>>mort96+Pa
That’s fair. Ideally transitive dependencies should be completely hidden from you. Hopefully the author of the library you include directly has heeded the instructions of libraries they depend on.

Hey I grant and acknowledge that using fast-math carries a little risk of surprises, we don’t necessarily need to try to think of corner cases. I’m mostly pushing back a little because using floats at all carries almost as much risk. A lot of people seem to use floats without knowing how inaccurate floats are, and a lot of people aren’t doing precision analysis or handling the exceptional cases… and don’t really need to.

replies(1): >>ska+aE
◧◩◪◨⬒
15. jcranm+Qf[view] [source] [discussion] 2024-01-16 16:12:20
>>dahart+L9
https://github.com/llvm/llvm-project/issues/57589

Turn on fast-math, it flips the FTZ/DAZ bit for the entire application. Even if you turned it on for just a shared library!

replies(1): >>accoun+M23
◧◩◪
16. useful+oi[view] [source] [discussion] 2024-01-16 16:27:52
>>dahart+kb
My experience is with gcc and clang on x86. I generally agree with you regarding accuracy, which is why I was quite surprised when I first discovered that -Ofast breaks isnan/isinf.

Even if I don't care about the accuracy differences, I still need a way to check for invalid input data. The upshot is that I had to roll my own isnan and isinf to be able to use -Ofast (because it's actually the underlying __builtin_xxx intrinsics that are broken), which still seems wrong to me.

◧◩
17. dahart+pi[view] [source] [discussion] 2024-01-16 16:28:01
>>jcranm+Wd
Thank you, great points. I’d have to agree that disabling denorms globally is pretty bad, even if (or maybe especially if) caring about denorms is rare.

> Fast-math can cause hard range guarantees to fail. Maybe you’ve got code that you can prove that, even with rounding error, the result will still be >= 0.

Floats do this too, it’s pretty routine to bump into epsilon out-of-range issues without fast-math. Most people don’t prove things about their rounding error, and if they do, it’s easy for them to account for 3 ULPs of fast-math error compared to 1/2 ULP for the more accurate operations. Like, nobody who knows what they’re doing will call sqrt() on a number that is fresh out of a multiplier and might be anywhere near zero without testing for zero explicitly, right? I’m sure someone has done it, but I’ve never seen it, and it ranks high on the list of bad ideas even if you steer completely clear of fast-math, no?

I guess I just wanted to resist the unspecific parts of the FUD just a little bit. I like your list a lot because it’s specific. Fast-math does carry some additional risks for accuracy sensitive code, and clearly as you and others showed, can infect and impact your whole app, and it can sometimes lead to situations where things break that wouldn’t have happened otherwise. But I think in the grand scheme these situations are quite rare compared to how often people mess up regular floating point math. For a very wide swath of people doing casual arithmetic, fast-math is not likely to cause more problems than floats cause, but it’s fair to want to be careful and pay attention.

replies(1): >>PaulDa+wy
◧◩◪
18. PaulDa+wy[view] [source] [discussion] 2024-01-16 17:38:43
>>dahart+pi
> I’d have to agree that disabling denorms globally is pretty bad,

and yet, for audio processing, this is an option that most DAWs either implement silently, or offer users the choice, because denormals are inevitable in reverb tails and on most Intel processors they slow things by orders of magnitude.

replies(2): >>dahart+591 >>mabste+BI1
◧◩◪◨⬒
19. ska+aE[view] [source] [discussion] 2024-01-16 18:09:04
>>dahart+ce
> A lot of people seem to use floats without knowing how inaccurate floats are,

Small nit, but floats aren't inaccurate, they have non uniform precision. Some float operations can be inaccurate, but that's rather path dependent...

One problem with -ffast-math is that a) it sounds appealing and b) people don't understand floats, so lots of people turn it on without understanding what it does, and that can introduce subtle problems in code they didn't write.

Sometimes in computational code it makes sense e.g. to get rid of denorms, but a very small fraction of programmers understand this properly, or ever will.

I wish they had named it something scary sounding.

replies(2): >>dahart+n81 >>accoun+U53
◧◩
20. xigoi+cF[view] [source] [discussion] 2024-01-16 18:15:27
>>useful+J9
They are talking about -ffast-math, not -Ofast.
replies(1): >>gumby+411
21. light_+WS[view] [source] 2024-01-16 19:05:30
>>dahart+(OP)
Nah, you don't deal with floats. You do machine learning which just happens to use floats. I do both numerical computing and machine learning. And oh boy are you wrong!

People who deal with actual numerical computing know that the statement "fast math is only slightly less accurate" is absurd. Fast math is unbounded in its inaccuracy! It can reorder your computations so that something that used to sum to 1 now sums to 0, it can cause catastrophic cancellation, etc.

Please stop giving people terrible advice on a topic you're totally unfamiliar with.

replies(3): >>alexey+bg1 >>thecha+kg1 >>dahart+Jy1
◧◩◪
22. gumby+411[view] [source] [discussion] 2024-01-16 19:36:35
>>xigoi+cF
From the gcc manual:

-Ofast

Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard-compliant programs. It turns on -ffast-math, -fallow-store-data-races and the Fortran-specific -fstack-arrays, unless -fmax-stack-var-size is specified, and -fno-protect-parens. It turns off -fsemantic-interposition.

◧◩
23. fl0ki+Z51[view] [source] [discussion] 2024-01-16 19:56:09
>>jcranm+Wd
> The results of your program will vary depending on the exact make of your compiler and other random attributes of your compile environment, which can wreak havoc if you have code that absolutely wants bit-identical results. This doesn't matter for everybody, but there are some domains where this can be a non-starter (e.g., multiplayer game code).

This already shouldn't be assumed, because even the same code, compiler, and flags can produce different floating point results on different CPU targets. With the world increasingly split over x86_64 and aarch64, with more to come, it would be unwise to assume they produce the same exact numbers.

Often this comes down to acceptable implementation defined behavior, e.g. temporarily using an 80-bit floating register despite the result being coerced to 64 bits, or using an FMA instruction that loses less precision than separate multiply and add instructions.

Portable results should come from integers (even if used to simulate rationals and fixed point), not floats. I understand that's not easy with multiplayer games, but doing so with floats is simply impossible because of what is left as implementation-defined in our language standards.

replies(2): >>Ashame+Gb1 >>jcranm+Pc1
◧◩◪◨⬒⬓
24. dahart+n81[view] [source] [discussion] 2024-01-16 20:08:13
>>ska+aE
I am talking about float operations, of course. And they’re all inaccurate, generally speaking, because they round. Fast math rounding error is not much larger than rounding error without fast mast.
◧◩◪◨
25. dahart+591[view] [source] [discussion] 2024-01-16 20:10:53
>>PaulDa+wy
I would think for audio, there’s no audible difference between a denorm and a flushed zero. Are there cases where denorms are important to audio?
replies(1): >>PaulDa+eG1
◧◩◪
26. Ashame+Gb1[view] [source] [discussion] 2024-01-16 20:22:05
>>fl0ki+Z51
> Often this comes down to acceptable implementation defined behavior,

I believe this is "always" rather than often when it comes to the actual operations defined by the FP standard. gcc does play it fast and loose (as -ffast-math is not yet enabled by default, and FMA on the other hand is), but this is technically illegal and at least can be easily configured to be in standards-compliant mode.

I think the bigger problem comes from what is _not_ documented by the standard. E.g. transcendental functions. A program calling plain old sqrt(x) can find itself behaving differently _even between different stepping of the same core_, not to mention that there are well-known differences between AMD vs Intel. This is all using the same binary.

replies(1): >>mabste+DH1
◧◩◪
27. jcranm+Pc1[view] [source] [discussion] 2024-01-16 20:26:59
>>fl0ki+Z51
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+ee1 >>fl0ki+nh1 >>Ashame+ci1 >>accoun+mU2
◧◩◪◨
28. zozbot+ee1[view] [source] [discussion] 2024-01-16 20:33:37
>>jcranm+Pc1
> 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+yf1 >>lifthr+Jn2
◧◩◪◨⬒
29. jcranm+yf1[view] [source] [discussion] 2024-01-16 20:40:14
>>zozbot+ee1
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.)

◧◩
30. alexey+bg1[view] [source] [discussion] 2024-01-16 20:43:43
>>light_+WS
> It can reorder your computations so that something that used to sum to 1 now sums to 0, it can cause catastrophic cancellation, etc.

Yes, and it could very well be that the correct answer is actually 0 and not 1.

Unless you write your code to explicitly account for fp associativity effects, in which case you don't need generic forum advice about fast-math.

◧◩
31. thecha+kg1[view] [source] [discussion] 2024-01-16 20:44:17
>>light_+WS
+1. I'm years away from fp-analysis, but do the transcendental expansions even converge in the presence of fast-math? No `sin()`, no `cos()`, no `exp()`, ...
replies(1): >>dahart+UA1
◧◩◪◨
32. fl0ki+nh1[view] [source] [discussion] 2024-01-16 20:50:22
>>jcranm+Pc1
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/
◧◩◪◨
33. Ashame+ci1[view] [source] [discussion] 2024-01-16 20:54:01
>>jcranm+Pc1
> 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.

◧◩
34. dahart+Jy1[view] [source] [discussion] 2024-01-16 22:25:44
>>light_+WS
I only do numeric computation, I don’t work in machine learning. Sorry your assumptions are incorrect, maybe it’s best not to assume or attack. I didn’t exactly advise using fast math either, I asked for reasoning and pointed out that most casual uses of float aren’t highly sensitive to precision.

It’s easy to have wrong sums and catastrophic cancellation without fast math, and it’s relatively rare for fast math to cause those issues when an underlying issue didn’t already exist.

I’ve been working in some code that does a couple of quadratic solves and has high order intermediate terms, and I’ve tried using Kahan’s algorithm repeatedly to improve the precision of the discriminants, but it has never helped at all. On the other hand I’ve used a few other tricks that improve the precision enough that the fast math version is higher precision than the naive one without fast math. I get to have my cake and eat it too.

Fast math is a tradeoff. Of course it’s a good idea to know what it does and what the risks of using it are, but at least in terms of the accuracy of fast math in CUDA, it’s not an opinion whether the accuracy is relatively close to slow math, it’s reasonably well documented. You can see for yourself that most fast math ops are in the single digit ulps of rounding error. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index....

◧◩◪
35. dahart+UA1[view] [source] [discussion] 2024-01-16 22:40:01
>>thecha+kg1
Well there are library implementations of fast-math trancendentals that offer bounded error, and a million different fast sine approximation algorithms, so, yes? This is why you shouldn’t listen to FUD. The corner cases are indeed frustrating for a few people, but most never hit them, and the world doesn’t suddenly break when fast math is enabled. I am paid to do some FP analysis, btw.
◧◩◪◨⬒
36. PaulDa+eG1[view] [source] [discussion] 2024-01-16 23:08:06
>>dahart+591
They are important in the negative sense: Intel processors are appalling at handling them, and they can break realtime code because of this.

My DAW uses both "denormals are zero" and "flush denormals to zero" to try to avoid them; it also offers a "DC Bias" option where extremely small values are added to samples to avoid denormals.

◧◩◪◨
37. mabste+DH1[view] [source] [discussion] 2024-01-16 23:17:13
>>Ashame+Gb1
I'm surprised by this, regarding sqrt. The standard stipulates correct rounding for simple arithmetic, including sqrt ever since 754 1985.

Unless of course we are talking about the 80 bit format.

If that's not the case, would be interested to know where they differ.

Unfortunately for the transcendental function the accuracy still hasn't been pinned down, especially since that's still an ongoing research problem.

There's been some great strides in figuring out the worst cases for binary floating point up to doubles so hopefully an upcoming standard will stipulate 0.5 ULP for transcendentals. But decimal floating point still has a long way to go.

replies(1): >>Ashame+TW1
◧◩◪◨
38. mabste+BI1[view] [source] [discussion] 2024-01-16 23:23:38
>>PaulDa+wy
For game development we had them off as well because of performance issues. Most stuff calculates around 0 so it was pretty common to trigger denorms.

The slowing down on Intel platforms has always frustrated me because denorms provide nice smoothing around 0.

At the same time it was nice only having to consider normal floating point when trying to get more accuracy out of calculations, etc.

◧◩◪◨⬒
39. Ashame+TW1[view] [source] [discussion] 2024-01-17 00:45:26
>>mabste+DH1
Because compilers can and have implemented sqrt in terms of rsqrt which is .. fun to work with. This also on SSE.
replies(2): >>mabste+7l2 >>jcranm+nn2
◧◩◪◨⬒⬓
40. mabste+7l2[view] [source] [discussion] 2024-01-17 03:45:57
>>Ashame+TW1
I spent most of my career working with rsqrt haha. And had my fair share of non-754 architectures too!

Every 754 architecture (including SSE) I've worked on has an accurate sqrt().

I'm assuming you're talking about with "fast math" enabled? In which case all bets are off anyway!

replies(1): >>Ashame+vz4
◧◩◪◨⬒⬓
41. jcranm+nn2[view] [source] [discussion] 2024-01-17 04:06:33
>>Ashame+TW1
sqrt is a fundamental IEEE 754 operation, required to be correctly rounded, and many architectures implement a dedicated, correctly rounded sqrt instruction.

Now, there is also often an approximate rsqrt and approximate reciprocal, with varying degrees of accuracy, and that can be "fun."

◧◩◪◨⬒
42. lifthr+Jn2[view] [source] [discussion] 2024-01-17 04:10:17
>>zozbot+ee1
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+5s2
◧◩◪◨⬒⬓
43. jcranm+5s2[view] [source] [discussion] 2024-01-17 04:50:21
>>lifthr+Jn2
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+xt2
◧◩◪◨⬒⬓⬔
44. lifthr+xt2[view] [source] [discussion] 2024-01-17 05:08:04
>>jcranm+5s2
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...

◧◩◪◨
45. accoun+mU2[view] [source] [discussion] 2024-01-17 09:01:52
>>jcranm+Pc1
> 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...

◧◩◪◨⬒⬓
46. accoun+M23[view] [source] [discussion] 2024-01-17 10:02:51
>>jcranm+Qf
That's only one small part of -ffast-math/-Ofast though and not a very scary one at that.
replies(1): >>mort96+6w5
◧◩◪◨⬒⬓
47. accoun+U53[view] [source] [discussion] 2024-01-17 10:27:47
>>ska+aE
> Sometimes in computational code it makes sense e.g. to get rid of denorms, but a very small fraction of programmers understand this properly, or ever will.

"Some times" here being almost all the time. It is rare that your code will break without denormals if it doesn't already have precision problems with them.

◧◩◪◨⬒⬓⬔
48. Ashame+vz4[view] [source] [discussion] 2024-01-17 18:36:23
>>mabste+7l2
No; compilers have done this even without fast-math. Gcc does not seem to do this anymore, but still does plenty of unsafe optimizations by default, like FMA.

Or maybe the library you use...

replies(1): >>mabste+949
◧◩◪◨⬒⬓⬔
49. mort96+6w5[view] [source] [discussion] 2024-01-17 23:39:43
>>accoun+M23
But it's an example of -ffast-math affecting separately compiled libraries.
◧◩◪◨⬒⬓⬔⧯
50. mabste+949[view] [source] [discussion] 2024-01-18 22:37:14
>>Ashame+vz4
Argh, sounds really frustrating! It's hard enough to get accuracy when you can control operations never mind when the compiler is doing magic behind the scenes!

FMAs were difficult. The Visual Studio compiler in particular didn't support purposeful FMAs for SSE instructions so you had to rely on the compiler to recognise and replace multiply-additions. Generally I want FMAs because they're more accurate but I want to control where they go.

[go to top]