4 ms·
> Ok not link but include header. Sorry to disappoint but Rust can’t include C++ headers. Even if it could, they wouldn’t work, because intrinsics are not libr
by Const-me 7y ago
> Ok not link but include header.
Sorry to disappoint but Rust can’t include C++ headers. Even if it could, they wouldn’t work, because intrinsics are not library functions.
> See the explicit section of the faster project.
These aren’t C intrinsics, they are library functions exported from stdsimd crate. Which in turn forwards them to LLVM. Requires Rust nighty. Also I’m not sure that many levels of indirection are good for performance. You usually want these m128/m256 values to stay in registers. In C++, I sometimes have to write __forceinline to achieve that, or the compiler breaks performance by making function calls, or referencing RAM.
- adamnemecek 7y ago> Sorry to disappoint but Rust can’t include C++ headers. You are pedantic. https://doc.rust-lang.org/1.29.0/std/arch/#static-cpu-feature-detection https://doc.rust-lang.org/1.29.0/std/arch/#static-cpu-featur...
- Const-me 7y agoThat’s library functions from stdsimd crate. Looks like significant overhead over C intrinsics. Two calls to transmute() for every instruction. And other calls for every instruction, stuff like as_i32x4. It’s technically possible every last one of them compile into nothing at all, and emits just a single desired instruction. I don’t believe these optimizations are 100% reliable, however. They aren’t reliable in clang or vc++, I sometimes have to use trickery to force compilers to inline stuff, keep data in registers instead of loads/stores, and otherwise not screw up the performance.
- adamnemecek 7y agoThere's no transmute. Look I don't have time for this.
- Const-me 7y ago> There's no transmute. That crate calls transmute twice, for every single instruction. https://github.com/rust-lang-nursery/stdsimd/blob/master/crates/core_arch/src/x86/sse2.rs#L94-L103 https://github.com/rust-lang-nursery/stdsimd/blob/master/cra... https://github.com/rust-lang-nursery/stdsimd/blob/master/crates/core_arch/src/x86/mod.rs#L389-L392 https://github.com/rust-lang-nursery/stdsimd/blob/master/cra...
- adamnemecek 7y agoCheck the actual compiler output.
- steveklabnik 7y agoWhat he’s trying to say is that transmute is also an intrinsic. They correspond to the machine instructions, that’s their entire purpose. That’s also why they’re intrinsics.