Add i64 support #1

Merged
nandi merged 4 commits from geordi/add-i64-support into main 2026-11-23 05:42:56 +00:00
Owner

What

Adds the i64 value type to the compiler: params/results/locals/globals/block types, i64.const, comparisons, add/sub/mul/div/rem, bitwise ops, shifts/rotates, i32.wrap_i64 / i64.extend_i32_{s,u}, sign-extension ops, and all i64 loads/stores (including narrow forms). Globals can be initialised with i64.const.

Why

The compiler was i32-only, so any module using i64 was rejected. The value stack, locals and globals were already 8 bytes wide, so supporting i64 mostly meant emitting REX.W variants of the existing instructions.

Details

  • Division traps on a zero divisor and on INT64_MIN / -1; INT64_MIN % -1 returns 0.
  • global.get/set now move 64 bits (works for i32 globals too).
  • Memory-access code was reworked around a per-opcode size/encoding table.
  • Not included: clz/ctz/popcnt (missing for i32 as well), floats.

Testing

  • New examples/i64.wat self-checks 22 cases (fib(40), div/rem edge cases, signed vs unsigned compares, shifts/rotates, conversions, memory, globals) and exits 0 on success; it does.
  • Existing examples produce the same exit codes/traps as before.
  • wasm-tools wasn't available in my environment, so I assembled the .wat files with the npm wabt package; moon test and just examples were not run.

🤖 Generated with Claude Code

## What Adds the i64 value type to the compiler: params/results/locals/globals/block types, `i64.const`, comparisons, add/sub/mul/div/rem, bitwise ops, shifts/rotates, `i32.wrap_i64` / `i64.extend_i32_{s,u}`, sign-extension ops, and all i64 loads/stores (including narrow forms). Globals can be initialised with `i64.const`. ## Why The compiler was i32-only, so any module using i64 was rejected. The value stack, locals and globals were already 8 bytes wide, so supporting i64 mostly meant emitting REX.W variants of the existing instructions. ## Details - Division traps on a zero divisor and on `INT64_MIN / -1`; `INT64_MIN % -1` returns 0. - `global.get/set` now move 64 bits (works for i32 globals too). - Memory-access code was reworked around a per-opcode size/encoding table. - Not included: clz/ctz/popcnt (missing for i32 as well), floats. ## Testing - New `examples/i64.wat` self-checks 22 cases (fib(40), div/rem edge cases, signed vs unsigned compares, shifts/rotates, conversions, memory, globals) and exits 0 on success; it does. - Existing examples produce the same exit codes/traps as before. - `wasm-tools` wasn't available in my environment, so I assembled the `.wat` files with the npm `wabt` package; `moon test` and `just examples` were not run. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nandi added 1 commit 2026-11-21 09:50:20 +00:00
Stack slots, locals and globals were already 8 bytes wide, so i64 is mostly
64-bit encodings of the existing i32 ops: constants, comparisons, arithmetic,
bitwise, shifts/rotates, div/rem (with zero and overflow traps), wrap/extend,
sign-extension ops, i64 loads/stores (incl. narrow forms) and 64-bit globals.
Adds examples/i64.wat, which self-checks and exits 0 on success.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nandi added 1 commit 2026-11-21 09:56:35 +00:00
nandi added 1 commit 2026-11-21 11:37:28 +00:00
nandi added 1 commit 2026-11-23 05:42:47 +00:00
nandi merged commit c69bc2364a into main 2026-11-23 05:42:56 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nandi/wasm2elf-mb#1