rust-lang / compiler-builtins

Porting `compiler-rt` intrinsics to Rust
https://github.com/rust-lang/rust/issues/35437
Other
359 stars 207 forks source link

Use the trifecta div algorithm for 128-bit div on wasm #685

Closed alexcrichton closed 4 weeks ago

alexcrichton commented 4 weeks ago

This commit updates the #[cfg] annotations used to select the implementation of 128-bit division in compiler-builtins on wasm targets. This is done with relation to https://github.com/WebAssembly/128-bit-arithmetic where performance of 128-bit operations is being investigated on WebAssembly. While I don't know much about the particulars of the two algorithms involved here the comments indicate that the "trifecta" variant is preferred if possible but it's not selected on 32-bit architectures. This rationale isn't as applicable to WebAssembly targets because despite the 32-bit pointer width there are often wider-than-pointer operations available as it's typically run on 64-bit machines.

Locally in testing a benchmark that performs division with a Rust-based bignum libraries whent from 350% slower-than-native to 220% slower-than-native with this change, a nice increase in speed. While this was tested with Wasmtime other runtimes are likely to see an improvement as well.

tgross35 commented 4 weeks ago

Makes sense, thanks!

tgross35 commented 4 weeks ago

Once https://github.com/rust-lang/compiler-builtins/pull/684 merges you can send a PR to rust-lang/rust updating to v0.1.125

alexcrichton commented 4 weeks ago

Happy to do so, and thanks!