-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebIDL Binder does not support the full range of values for unsigned integers #22134
Comments
Im not aware of any performance issues with associated with HEAPU32. @kripken perhaps you can elaborate? |
Historically some JS engines optimize JS Numbers when they are "small integers", which are typically 32-bit signed integers. Using HEAP32 ensures we fall into that range, and the unsigned heap might cause the optimization to fail and return to modeling that variable as a Number (double). I am actually not sure how significant this is these days - perhaps optimizations have improved? In any case, @isaac-mason , in general when you care about the difference between signed and unsigned values then you need to cast on the boundary. Using |
Will reading values larger than 2^31 from HEAPU32 still require |
I confirmed you don't need the |
Thanks @kripken @sbc100 for the information! I misunderstood the I'm happy to contribute a change to the webidl binder docs to explain this behaviour.
Are there suitable existing benchmarks in the emscripten repo that we could try answering this with? |
Hmm, it's hard to measure this as it depends on a bunch of heuristics JS engines have. I don't think we have any good benchmarks for it. In general "use 31-bit integers" was a JS best practice for performance back in the day, but even then it was not entirely reliable. Doc improvements would be welcome! |
Is it possible to opt-in to representing an unsigned int using HEAPU32 with the webidl binder?
When using the webidl binder and binding an attribute or function that uses
unsigned int
, the max unsigned int value0xffffffff
is returned as-1
in javascript.It appears this is because unsigned integers are treated as signed integers.
This behaviour can be seen in the webidl binder tests:
emscripten/test/webidl/test_ALL.out
Line 85 in bb220d8
Looking at some past commits, it appears this behaviour is intentional for performance reasons: f1c42f4
I am using the webidl binder to create bindings for a library which uses
0xffffffff
as a constant with a special meaning. Right now to work around this issue, in javascript I check for the value-1
. This is a fine workaround for my case but feels like a hack, and would stop working if I needed to check for other values in the upper unsupported range.Version of emscripten/emsdk:
The text was updated successfully, but these errors were encountered: