diff --git a/quest/m3/README.md b/quest/m3/README.md index a6efa4235..d9aba5578 100644 --- a/quest/m3/README.md +++ b/quest/m3/README.md @@ -33,6 +33,8 @@ generic std gap is planned here even when moq never calls it. - [Peekable::next_if_eq against another type](/quest/m3/ts-next-if-eq-other.md) - `next_if_eq` with an expected value of another type than the item, such as a `&str` of `String` items, translates - [A closure's () result as a value](/quest/m3/ts-unit-closures.md) - a closure returning `()` whose result is a value, as in a `Vec<()>` collected from `map`, type-checks - [std accessors with no mapping](/quest/m3/ts-unmapped-accessors.md) - `VecDeque::swap_remove_*`, `HashSet::replace`, `BTreeSet::get`, `take`, and `replace`, `Vec::pop_if`, and `Arc` and `Rc::into_inner` translate +- [Integers' little- and native-endian bytes](/quest/m3/ts-int-ne-bytes.md) - each integer's `from_le_bytes`, `to_ne_bytes`, and `from_ne_bytes` translate +- [mul_add rounded once](/quest/m3/ts-mul-add.md) - `f64::mul_add` and `f32::mul_add` translate, rounding once as std's fused multiply-add does - [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form - [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does - [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it diff --git a/quest/m3/ts-int-ne-bytes.md b/quest/m3/ts-int-ne-bytes.md new file mode 100644 index 000000000..428356bc7 --- /dev/null +++ b/quest/m3/ts-int-ne-bytes.md @@ -0,0 +1,35 @@ +# [S] Integers' little- and native-endian bytes + +## Goal + +[rust2-ts](/ts/README.md) translates each integer type's `from_le_bytes`, `to_ne_bytes`, +and `from_ne_bytes` as it does `from_be_bytes`, `to_be_bytes`, and `to_le_bytes`, proven +by differential tests against native wasm32 at every width. + +## Plan + +Found while writing [#296](https://github.com/moq-dev/rust2/pull/296)'s fixture, which +used `to_le_bytes` instead. Planned without a moq consumer, under the maintainer's +2026-10-27 decision that rust2 aims to support all of std. + +Reproduction at `cecbf0d7`, a scratch crate whose roots call each: + +```text +unsupported call to `core::num::::from_le_bytes` at src/lib.rs:2:2 +unsupported call to `core::num::::to_ne_bytes` at src/lib.rs:6:23 +unsupported call to `core::num::::from_ne_bytes` at src/lib.rs:6:2 +``` + +- `library.rs` maps integers' `from_be_bytes`, `to_be_bytes`, and `to_le_bytes`, the last + as the big-endian bytes reversed. wasm32 is little-endian, so `_ne_` is `_le_`, as + `float.rs` already maps a float's `to_ne_bytes` and `from_ne_bytes`. +- `from_le_bytes` must not reverse its argument in place: the caller may still hold that + array. Reverse a copy, or give each width a runtime `fromLeBytes`. +- Test every width, the 64- and 128-bit ones past 2^53 included, in the lang fixture's + `ints` cases. + +Public API: the translator's output. + +## Related + +- [Unsafe code the translator can model](/quest/m3/ts-unsafe.md) - `bytes`' getters also need each integer's `from_le_bytes` and `from_ne_bytes` diff --git a/quest/m3/ts-mul-add.md b/quest/m3/ts-mul-add.md new file mode 100644 index 000000000..276e22d89 --- /dev/null +++ b/quest/m3/ts-mul-add.md @@ -0,0 +1,39 @@ +# [M] mul_add rounded once + +## Goal + +[rust2-ts](/ts/README.md) translates `f64::mul_add` and `f32::mul_add`, rounding +`a * b + c` once as std's fused multiply-add does. Differential tests against native +wasm32 prove it, including operands where rounding the product and then the sum would +give another result. + +## Plan + +Left by [#296](https://github.com/moq-dev/rust2/pull/296), which refused `f32::mul_add` as +`f64`'s already was. Planned without a moq consumer, under the maintainer's 2026-10-27 +decision that rust2 aims to support all of std. + +Reproduction at `cecbf0d7`: the reject fixture's `fma` root, and a scratch crate's +`a.mul_add(b, c)`: + +```text +`f64::mul_add`, which rounds once, where JS would round twice at src/lib.rs:10:4 +``` + +`f32::mul_add` fails the same way once #296 lands. + +- First confirm what native wasm32 runs. wasm has no fused multiply-add, so the call + should be compiler-builtins' software `fma` and `fmaf`, which round once. +- `f32`: a double holds `a * b` exactly (48 bits). Add `c` with TwoSum to get the rounded + sum and its exact error. If the error is nonzero and the sum's last bit is even, step + the sum one double toward the error; that is rounding to odd. Then `Math.fround` rounds + once, since 53 >= 24 + 2. Infinities and NaN take the plain `Math.fround(a * b + c)`. +- `f64`: there is no wider type. Use an error-free product (Dekker's split, or a `BigInt` + of both significands) and TwoSum, with an exact `BigInt` fallback wherever the fast path + can't decide. That covers a product that overflows while the sum does not, and a + subnormal result. Correctness first, since nothing in moq calls it, then report its + cost per call against `a * b + c`. +- Move the reject fixture's `fma` root to another construct that is still refused, or + drop it, and update the README's `mul_add` refusal note. + +Public API: the translator's output.