Home | Notifications | New Note | Local | Federated | Search | Logout
Note Detail
Reply to @mcc@mastodon.social
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---
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.
Reply
---Replies---
mcc@mcc@mastodon.social (2026-10-02 12:13:35)
Alright! That… wasn't so hard!
https://github.com/mcclure/aoc2024/blob/7f6e479c88bcb251bf8fbb7b716da0660c787be2/11-01-stones/src/puzzle.wast
Friendlier than a lot of ASMs, and everything *un*friendly stems from tool ugliness (lack of step debugger; I wound up not using any of the neat LISP argument nesting or parens-optional features bc they broke too easily). After 16 months of being stuck on building WAST at all I wrote the whole "part 1" program in one day.
It doesn't work on the actual puzzle input because I wrote it around u32s and the assigned input needs u64s. FRICKING