Home | Notifications | New Note | Local | Federated | Search | Logout
Note Detail
Reply to @mcc@mastodon.social
mcc@mcc@mastodon.social (2026-10-02 02:58:29)
ME: Hey so is there a way to detect or prevent an integer overflow in multiplication in wasm? Carry flag, saturation, traps, anything?
HELPFUL FRIEND: No, wasm is conservative to the point of being unhelpful and you have to do those kind of checks yourself, they didn't want to commit to integer ops that some CPUs might not support
ME: Well okay I guess that's reasonable
WASM SPEC: Hey guys check it out I made an instruction that counts the number of 1 bits in a number https://developer.mozilla.org/en-US/docs/WebAssembly/Reference/Numeric/popcnt
---Reply---
mcc@mcc@mastodon.social (2026-10-02 02:59:27)
Have you ever got "how would you count the number of 1 bits in a number" as a question in a job interview? I've got that one before. Next time I get it I'm just going to smugly reply "compile to wasm and call i32.popcnt"
Reply
---Replies---
mcc@mcc@mastodon.social (2026-10-02 03:05:07)
Hey wasm question. I understand the stack in wasm is not there because they wanted to write a stack language, it's there because someone at Sun found a very good register allocation algorithm that works best if your bytecode targets a stack machine.
But are there… ANY stack ops? Like access to a DUP would be *so* helpful right now.
I see "local.tee" but that's about it. I'm looking at the Mozilla reference tho (it's… a LOT easier to navigate than the html spec) which I'm not sure is complete.