![]() |
|
![]() |
|
> but if you are writing assembly or intrinsics or just C that inspect with Compiler Explorer or objdump, you can look at the output and say "Yep, that'll be consistent". Surely people have written tooling for those checks for various CPUs? Also, is it that ‘simple’? Reading https://github.com/llvm/llvm-project/issues/62479, calculations that the compiler does and that only end up in the executable as constants can make results different between architectures or compilers (possibly even compiler runs, if it runs multi-threaded and constant folding order depends on timing, but I find it hard to imagine how exactly that would happen). So, you’d want to check constants in the code, too, but then, there’s no guarantee that compilers do the same constant folding. You can try to get more consistent by being really diligent in using constexpr, but that doesn’t guarantee that, either. |
![]() |
|
Years ago, I was programming in Ada and ran across a case where the value of a constant in a program differed from the same constant being converted at runtime. Took a while to track that one down.
|
![]() |
|
The same reasoning applies though. The compiler is just another program. Outside of doing constant folding on things that are unspec'ed or not required (like mmsqrtps and most transcendentals), you should get consistent results even between architectures. Of course the specific line linked to in that GH issue is showing that LLVM will attempt constant folding of various trig functions: https://github.com/llvm/llvm-project/blob/faa43a80f70c639f40... but the IEEE-754 spec does also recommend correctly rounded results for those (https://en.wikipedia.org/wiki/IEEE_754#Recommended_operation...). The majority of code I'm talking about though uses constants that are some long, explicit number, and doesn't do any math on them that would then be amenable to constant folding itself. That said, lines like: https://github.com/llvm/llvm-project/blob/faa43a80f70c639f40... are more worrying, since that may differ from what people expect dynamically (though the underlying stuff supports different denormal rules). Either way, thanks for highlighting this! Clearly the answer is to just use LLVM/clang regardless of backend :). |
![]() |
|
Meagher's octree system notably used only integer arithmetic with no integer multiplication/division: > Efficient (linear time) algorithms have been developed for the Boolean operations (union, intersection and difference), geometric operations (translation, scaling and rotation), N-dimensional interference detection, and display from any point in space with hidden surfaces removed. The algorithms require neither floating-point operations, integer multiplications, nor integer divisions. https://doi.org/10.1016/0146-664X(82)90104-6 This facilitated creation of fast, custom VLSI graphics acceleration hardware for octree representation. |
![]() |
|
Most activations functions are based on exponential functions. I don't immediately see how cordic would help you calculate e^(x) unless x is complex valued (which it is usually not). |
![]() |
|
“Lives rent-free in my head” is a horrible cliche. By now, it has the same effect as saying “it’s nice” but uses lots more letters.
|
![]() |
|
And what does this pedantry solve, exactly? It clearly is something the author thinks often enough about and enjoys talking about. Let people enjoy things. |
I started working on such a thing as a fun side project a few years ago but never finished it. One of these days I hope to get back to it.
[0]: https://randomascii.wordpress.com/2013/07/16/floating-point-...