asm-js / validator

A reference validator for asm.js.
Apache License 2.0
1.78k stars 148 forks source link

return type cannot be unsigned #52

Closed jlongster closed 10 years ago

jlongster commented 11 years ago

Why is it that the return statement is not valid if using the unsigned type annotation (>>> 0)?

http://asmjs.org/spec/latest/#return-type-annotations

This means that we can't return unsigned integers.

curiousdannii commented 11 years ago

If it's passing out of asm.js land, then it must be signed, as JS doesn't have unsigned integers. If the function is being called by another asm.js function, then my guess would be that the |0 is a nop, but I'm not certain on that.

jlongster commented 11 years ago

JavaScript does have unsigned integers, as forced with the >>> operator: -1 >>> 0 == 4294967295, as far as I know. But I am mostly talking about code within the asm.js land.

kripken commented 11 years ago

For simplicity, we use signed values both when entering an asm.js function and when exiting. Standardizing on that is simpler, and matches what JS engines optimize well today anyhow (32-bit signed integers are faster than 32-bit unsigned ones, which often become doubles).

cscott commented 11 years ago

I believe this issue can be closed.

sunfishcode commented 10 years ago

Closing; see kripken's explanation above. The functionality of unsigned return types can be achieved by casting unsigned values to signed for the return, and casting them back to unsigned on the caller side.