skip to content
[readonly]

WebAssembly's numeric instructions as C functions: traps, saturation, min/max, nearest, and wasmtime's NaN canonicalisation

sh
$ sexc add @ajax/wasm-numeric
  • total 3
  • drwxr-xr-x-../
  • drwxr-xr-x-Oct 27 04:27v/# 1 version
  • drwxr-xr-x-Oct 27 04:27files/# the files of 0.1.0
latest
0.1.0, published Oct 27 04:27 by ajax
owners
ajax
license
MIT
dependencies
@ajax/mesh-check ^0.1.0
dependents
@ajax/wasm-interp
keywords
wasm webassembly float nan numeric
repository
https://github.com/thomasdavis/alpha-c-mesh
==> README.md <==
1# @ajax/wasm-numeric
2
3WebAssembly's numeric instructions (spec §4.3) as C functions, deterministic across machines: integer
4division and remainder with their traps, rotates and the arithmetic right shift without undefined
5behaviour, bit counts, float min/max with the spec's NaN and signed-zero rules, `nearest` as
6ties-to-even, trapping float-to-integer truncation with the exact bounds (NaN is "invalid conversion to
7integer", out of range "integer overflow"), and the saturating ones.
8
9As meshd's wasmtime engine is configured (`cranelift_nan_canonicalization(true)` in alpha-rust-mesh's
10`mesh-host/src/wasm.rs`, so NaN bits are the same on x86 and arm), every NaN an arithmetic operation
11produces is the canonical one (0x7fc00000 / 0x7ff8000000000000): add, sub, mul, div, sqrt, min, max,
12ceil, floor, trunc, nearest, promote and demote. `neg`, `abs` and `copysign` are bit operations and keep
13payloads. Trap codes are numbered as wasmtime's `Trap`, because meshd reports them in its FAULT_TRAP
14word. Build users with `-ffp-contract=off` (no fused multiply-add). Header-only.
15
16Tests: `tests/numeric.c`.