rust-lang / libm

A port of MUSL's libm to Rust.
Apache License 2.0
536 stars 96 forks source link

Additional intrinsic optimizations? #214

Open Lokathor opened 5 years ago

Lokathor commented 5 years ago

At the moment there's the llvm_intrinsically_optimized! macro which, when using the unstable flag, will call an unstable LLVM intrinsic.

However, there's some opportunities for using intrinsics (edit: hardware intrinsics) in stable, and even in core, if we wanted to reach for SSE / SSE2 / etc when available (compile time detected).

For example, libm defines sqrt with a full software implementation, but if people call it in std they get either (in debug) the sqrtss instruction with some indirection in between or (in release) the sqrtss instruction without any indirection. Based on this, I think it would be fine to have libm also just use the sqrtss instruction when available.

Of course this should probably be behind its own feature flag, but I think it would be a reasonable progression to develop in this direction of using stable hardware intrinsics when possible.

Lokathor commented 5 years ago

Note: this is related to, but not quite the same as, the https://github.com/rust-lang-nursery/libm/issues/145 discussion

alexcrichton commented 5 years ago

I think it's fine to improve on the implementations here at any time basically. These intrinsics may not be used in libstd at this time on all platforms, but having optimized implementations would certainly help, and they'll all be well tested anyway