Use runtime feature detection for fma routines on x86 - #896
Conversation
3a6e471 to
7cb49a7
Compare
|
|
might be nitpicking, but this adds more branches levels of indirection than strictly needed. this is the implementation i had in mind pseudocode (i think data ptr -> fn ptr requires a transmute) fn fma_select() {
let fn_ptr = todo!();
// x86/x86_64 function pointers and data pointers are the same
FMA_DYNAMIC.store(fn_ptr as *mut (), Relaxed);
fn_ptr();
}
static FMA_DYNAMIC: AtomicPtr<()> = AtomicPtr::new(fma_select as fn() as *mut ());
pub fn fma() { (FMA_DYNAMIC.load(Relaxed) as fn())(); } |
|
@tgross35 you might want to edit the magic "Fixes" magic keyword in ur PR description since u have write access to r-l/r, it will also close the r-l/r issue if this PR merges I think |
Not at all, thanks for pointing this out. Updated, that saved another four instructions per invocation (CI runs 500 samples). |
|
|
||
| /// Stores a pointer that is immediately jumped to upon entering $name. By default it | ||
| /// is an init function that sets FUNC to something else. | ||
| static FUNC: AtomicPtr<Func> = AtomicPtr::new({ |
There was a problem hiding this comment.
Rather than holding a pointer to a function pointer, you should instead use an AtomicPtr<()> and hold the function pointer directly.
There was a problem hiding this comment.
Thanks for the catch, I have updated this. Saves a mov per iteration as expected.
34af030 to
f7c4383
Compare
This module is used for both i686 and x86-64.
Get performance closer to the glibc implementations by adding assembly fma routines, with runtime feature detection so they are used even if not compiled with `+fma` (as the distributed standard library is often not). Glibc uses ifuncs, this implementation stores a function pointer in an atomic. Results of CPU flags are also cached in order to avoid repeating the startup time in calls to different functions. The feature detection code is a slightly simplified version of `std-detect`. Musl sources were used as a reference [1]. Fixes: rust-lang/rust#140452 once synced [1]: https://github.com/bminor/musl/blob/c47ad25ea3b484e10326f933e927c0bc8cded3da/src/math/x32/fma.c
Includes the following changes: * Use runtime feature detection for fma routines on x86 [1] Fixes: rust-lang#140452 [1]: rust-lang/compiler-builtins#896
Update `compiler-builtins` to 0.1.157 Includes the following changes: * Use runtime feature detection for fma routines on x86 [1] Fixes: rust-lang#140452 [1]: rust-lang/compiler-builtins#896
Rollup merge of rust-lang#140648 - tgross35:update-builtins, r=tgross35 Update `compiler-builtins` to 0.1.157 Includes the following changes: * Use runtime feature detection for fma routines on x86 [1] Fixes: rust-lang#140452 [1]: rust-lang/compiler-builtins#896
Includes the following changes: * Use runtime feature detection for fma routines on x86 [1] Fixes: rust-lang#140452 [1]: rust-lang/compiler-builtins#896
Update `compiler-builtins` to 0.1.157 Includes the following changes: * Use runtime feature detection for fma routines on x86 [1] Fixes: rust-lang#140452 [1]: rust-lang/compiler-builtins#896
Get performance closer to the glibc implementations by adding assembly fma routines, with runtime feature detection so they are used even if not compiled with
+fma(as the distributed standard library is often not). Glibc uses ifuncs, this implementation stores a function pointer in an atomic.Results of CPU flags are also cached in order to avoid repeating the startup time in calls to different functions. The feature detection code is a slightly simplified version of
std-detect.Fixes with sync: rust-lang/rust#140452