Comments (6)
You can use four backticks to properly escape multiline code like that.
I assume the issue is that sometimes optimizations end up avoiding a store to memory. When stored to f32, rounding occurs, but when still in a variable, it doesn't. Yes, this can be surprising.
The only real solution is to enable PRECISE_F32
, which as you mention works. Disabling llvm opts on the specific file you see the issue on can also be a workaround. But if your code is this sensitive to floating point values, I think enabling PRECISE_F32
is the best solution by far. It should be quite fast in modern browsers, but not always in older ones.
from emscripten-fastcomp.
Thank you for the fast answer.
My solution for now will be to enable PRECISE_F32 and disable it only where performances will be potentially an issue.
from emscripten-fastcomp.
You can find more about this behavior in floating point and the nonguarantees there from http://gcc.gnu.org/wiki/x87note , which discusses the same behavior in native x87 fpu. Instead of 80bit vs 32/64bit issue in native, in Emscripten when compiling without PRECISE_F32, the "cpu register" contains a 64bit float, and the memory contains a 32bit float. That behavior is valid by the IEEE floating point spec, although it is extremely unintuitive and difficult to reason about. A good rule of thumb to avoid these issues is to follow these rules:
- comparing floats for equality or inequality with
==
or!=
is undefined, except in the special case where the float was first explicitly assigned a small integer literal value (float f = 0;
), and the comparison is afterwards done against that same literal value (if (f == 0)
) without having done any computation on it in between. - any two sequences of operations (float <-> double cast being an operation as well) that are mathematically the same, but where the operations are permuted or reordered, will not be guaranteed to give the same result. This means that the commutativity, associativity and transitivity rules don't apply.
- when comparing floats that are a result of computation instead of direct assignment of a small integer value, always compare against an epsilon threshold.
It seems that these rules, although being quite on the strict side of assumptions, avoid the float issues in practice.
from emscripten-fastcomp.
Perhaps we should add this (or a link to this) to the FAQ?
from emscripten-fastcomp.
I agree that this would be very useful to have in a FAQ.
from emscripten-fastcomp.
Yeah agreed. I'll write a note about this, since this does seem to come up quite often.
from emscripten-fastcomp.
Related Issues (20)
- no `gtest` library check from CMakeLists.txt HOT 2
- LLVM ERROR: Unsupported integer vector type with numElems: 32, primitiveSize: 8! HOT 4
- Could not verify LLVM version and clang not found HOT 3
- test/CodeGen/JS/simd-shift.ll is failing on incoming branch
- Compiler crashes when linking some SIMD code compiled with -O3
- Could not verify LLVM version: [Error 2] No such fil or directory HOT 2
- Reduce size of fastcomp repository HOT 3
- llc crashes in NaCL ExpandLargeIntegers.cpp HOT 2
- Branch divergence in JSBackend target? HOT 1
- Error: Undefined symbol HOT 2
- Error building project with llvm_root using fastcomp HOT 1
- Issue while manually building fastcomp in Windows HOT 2
- Undefined Symbol : Qt wasm build HOT 1
- [question] How to use the externally installed llvm? HOT 9
- llvm-config: error: missing libgtest.a HOT 4
- AssertionError: SIMD is used, but not supported in WASM mode yet HOT 7
- CommandLine Error: Option `help-list` registered more than once! HOT 2
- Will you make tags in this repo again which are in sync with emscripten? HOT 26
- Error message displays when i excute 'wasm-pack build' HOT 3
- emscript 1.39.X can't be built if using libjpeg HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emscripten-fastcomp.