Stacked on #1 (i64 support); the base is geordi/add-i64-support, so retarget to main once that merges.
What
Adds the f32 and f64 value types: params/results/locals/globals/block types, constants, loads/stores, comparisons, abs/neg/copysign, ceil/floor/trunc/nearest, sqrt, add/sub/mul/div, min/max, int<->float conversions, demote/promote and reinterpret.
Why
After i64, floats were the remaining numeric types the compiler rejected, so any module using them failed to compile.
Details
Floats live in the existing 8-byte stack slots as raw bits and are computed with scalar SSE ops through xmm0/xmm1, so locals, globals, calls, select and memory needed little change.
Comparisons are NaN-correct (all false except ne).
min/max follow wasm semantics: NaN propagates and -0 < +0.
Rounding uses roundss/roundsd, which needs SSE4.1.
Trapping float->int truncation traps on NaN (new "invalid conversion to integer" message) and on out-of-range values. Unsigned 64-bit conversions in both directions are handled explicitly.
Not included: trunc_sat, clz/ctz/popcnt, v128 and reference types.
Testing
New examples/float.wat has 52 self-checks (arithmetic, NaN comparisons, rounding, signed-zero min/max, all conversions, memory, globals) and exits 0.
New examples/fptrap.wat checks that an out-of-range truncation traps (exit 134). I also checked NaN, +/-2^63, 2^64 and f32 2^31 boundaries by hand.
i64 and the older examples give the same results as before.
wasm-tools wasn't available here, so I assembled the .wat files with the npm wabt package; moon test and just examples were not run.
Stacked on #1 (i64 support); the base is `geordi/add-i64-support`, so retarget to `main` once that merges.
## What
Adds the f32 and f64 value types: params/results/locals/globals/block types, constants, loads/stores, comparisons, `abs`/`neg`/`copysign`, `ceil`/`floor`/`trunc`/`nearest`, `sqrt`, `add`/`sub`/`mul`/`div`, `min`/`max`, int<->float conversions, `demote`/`promote` and `reinterpret`.
## Why
After i64, floats were the remaining numeric types the compiler rejected, so any module using them failed to compile.
## Details
- Floats live in the existing 8-byte stack slots as raw bits and are computed with scalar SSE ops through xmm0/xmm1, so locals, globals, calls, `select` and memory needed little change.
- Comparisons are NaN-correct (all false except `ne`).
- `min`/`max` follow wasm semantics: NaN propagates and -0 < +0.
- Rounding uses `roundss`/`roundsd`, which needs SSE4.1.
- Trapping float->int truncation traps on NaN (new "invalid conversion to integer" message) and on out-of-range values. Unsigned 64-bit conversions in both directions are handled explicitly.
- Not included: `trunc_sat`, clz/ctz/popcnt, v128 and reference types.
## Testing
- New `examples/float.wat` has 52 self-checks (arithmetic, NaN comparisons, rounding, signed-zero min/max, all conversions, memory, globals) and exits 0.
- New `examples/fptrap.wat` checks that an out-of-range truncation traps (exit 134). I also checked NaN, +/-2^63, 2^64 and f32 2^31 boundaries by hand.
- i64 and the older examples give the same results as before.
- `wasm-tools` wasn't available here, 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)
Floats live in the existing 8-byte stack slots as raw bits and are computed
with scalar SSE ops via xmm0/xmm1. Adds consts, loads/stores, comparisons
(NaN-correct), abs/neg/copysign, ceil/floor/trunc/nearest (roundss/sd),
sqrt, add/sub/mul/div, wasm-semantics min/max (NaN propagating, -0 < +0),
int<->float conversions (incl. unsigned 64-bit), demote/promote,
reinterpret, and float globals. Trapping truncation traps on NaN
(new 'invalid conversion to integer' message) and on out-of-range values.
Adds examples/float.wat (52 self-checks) and examples/fptrap.wat.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
nandi
merged commit cc8516a369 into geordi/add-i64-support2026-11-21 09:56:35 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Stacked on #1 (i64 support); the base is
geordi/add-i64-support, so retarget tomainonce that merges.What
Adds the f32 and f64 value types: params/results/locals/globals/block types, constants, loads/stores, comparisons,
abs/neg/copysign,ceil/floor/trunc/nearest,sqrt,add/sub/mul/div,min/max, int<->float conversions,demote/promoteandreinterpret.Why
After i64, floats were the remaining numeric types the compiler rejected, so any module using them failed to compile.
Details
selectand memory needed little change.ne).min/maxfollow wasm semantics: NaN propagates and -0 < +0.roundss/roundsd, which needs SSE4.1.trunc_sat, clz/ctz/popcnt, v128 and reference types.Testing
examples/float.wathas 52 self-checks (arithmetic, NaN comparisons, rounding, signed-zero min/max, all conversions, memory, globals) and exits 0.examples/fptrap.watchecks that an out-of-range truncation traps (exit 134). I also checked NaN, +/-2^63, 2^64 and f32 2^31 boundaries by hand.wasm-toolswasn't available here, so I assembled the.watfiles with the npmwabtpackage;moon testandjust exampleswere not run.🤖 Generated with Claude Code