Comments (4)
Nice stuff!
I would support adding this as an option here in upstream. If you can, please file a pull request with the proper commit(s).
Note that something very close to this is already possible, with TYPED_ARRAYS == 2. In that case, typed arrays are used with a shared buffer so that you can mix reads and writes of different types, using normal C-style heap access. The generated code is endian-dependent though, and requires a browser that supports typed arrays, which is why I am in favor of adding your approach as an option.
from emscripten.
Thanks! Will prepare a proper pull request to get this into master as an option.
Eh... good that I didn't invest time to understand what the HAS_TYPED_ARRAYS did before as otherwise I might have not cared to implement anything. On the other hand I think that wouldn't work in my case anyway as there could have been unaligned heap accesses for 16 and 32 bit numbers (though I could have adjusted the C code of course - which I tried to stay away, the only thing I added is a check for not doing malloc(0)... but for compatibility I would recommend returning a valid pointer in such a case, just as libc does).
Also I think the generated code my patch is producing is endian dependent as well as it stores the multibyte datatypes in big-endian format and I am not 100% sure it would work as is when compiled from a little-endian machine LLVM output. Like for example how would the ntohl() call work in such a case. I assume it would not flip the endianess correctly and therefore the fact I use big-endian heap would not work correctly. I am thinking right here?
from emscripten.
Yes, endianness is a problem with that kind of code.
I just added a runtime check for the typed arrays = 2 case, since it also depends on endianness. Your new code should do the same I guess.
from emscripten.
Type punning pointers is guaranteed in the typed arrays=2 mode, which asm.js is based on, and we require little endian support (out of practicality and visibility on our dev platforms, not out of necessity really), so it looks like the items discussed here are implemented. If someone wants to champion to add big endian support, let's operate on that as a separate item.
from emscripten.
Related Issues (20)
- Since PR #21775, additional file packages error on load in modularize build when registered for preRun
- Wasm validator error HOT 6
- symbol exported via --export not found: __wasm_init_memory_flag HOT 9
- mimalloc adds >60kb into output artifacts HOT 3
- Are we allowed to pass null as options to navigator_gpu_request_adapter_sync()? HOT 3
- Impossible to run multithread functions without blocking the UI thread. HOT 2
- --preload-file works when running locally but not when deployed as a github page HOT 5
- How to re-generate libdlmalloc.a after changed dlmalloc (system/lib/dlmalloc.c)? HOT 2
- PRINTF_LONG_DOUBLE is not compatible with MAIN_MODULE HOT 6
- Compilation error when binding custom types as field in a value_object HOT 2
- Unable to add _emscripten_thread_exit_joinable to EXPORTED_FUNCTIONS HOT 13
- There are no definitions of functions for working with std::complex and boost::multiprecision::number HOT 1
- Unable to reliably determine memory usage at runtime HOT 2
- Refused to execute script from 'http://localhost/undefined' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled HOT 4
- `charconv` function `to_chars` silently casts `long double` to `double` HOT 2
- `std::log1p(x)` with long double appears to use double precision HOT 7
- Support `rpath` to locate shared libraries? HOT 1
- compile gmp 6.3.0,there are some error HOT 1
- pthread workers 100% CPU usage... HOT 18
- 3.1.61 ignores wasmMemory when creating module 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.