linebender / linebender/fearless_simd

Fun, safe math considerations

Open
#4 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
457
Forks
30
Avg merge
1d 10h
Merged PRs (30d)
25

Description

This issue is a proposal for how to systematically deal with the tradeoff between precise semantics and performance. This tradeoff affects rounding behavior, especially in multiply-add combinations, and also NaN handling.

The general principle is as follows: the short, ergonomic name is a method with *relaxed* semantics, optimized for performance. Guarantees are explicitly weaker than, say, the Rust core language.

When applications require it, we will also add a `_precise` version, which is guaranteed to match Rust semantics, but may have degraded performance.

Here are more specific details:

[`mul_add`](https://doc.rust-lang.org/std/primitive.f32.html#method.mul_add) may in general be implemented as `a * b + c` or as fused multiply-add. We'll see the former in x86 versions lower than x86_64-v3, and also in WASM SIMD (until [relaxed_simd](https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md) lands). On aarch64, I'm still researching the situation; both vmla (multiply-add) and vfma (fused multiply-add) instructions exist. The former *may* be higher performance in some implementations, in which case that will be the choice for `mul_add`, but of course the latter for `mul_add_precise`.

`min` and `max` may have different NaN handling. I believe this will affect mostly Intel. The `_precise` variants will be polyfilled by a compare and select combination on Intel, and `vminnm/vmaxnm` on aarch64. If needed, we can also implement [`minimum`](https://doc.rust-lang.org/std/primitive.f32.html#method.minimum) and [`maximum`](https://doc.rust-lang.org/std/primitive.f32.html#method.maximum), which are `vmin` and `vmax` respectively on aarch64.

`round` will typically be implemented as round-ties-even semantics, but that's not guaranteed. If we need more precision, [`round_ties_even`](https://doc.rust-lang.org/std/primitive.f32.html#method.round_ties_even) will guarantee ties-even semantics, and, if needed, `round_precise` will guarantee the same semantics as [`round`](https://doc.rust-lang.org/std/primitive.f32.html#method.round), ie away from 0.0.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading the linked Rust float methods and the WebAssembly relaxed-SIMD proposal, then compare the stated mul_add, min/max, and round tradeoffs across the mentioned architectures. Done means the API naming and semantic guarantees are settled for relaxed and precise variants, including whether minimum, maximum, or round_precise are needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.