Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add #[inline] on fallback functions #61

Merged
merged 1 commit into from Dec 30, 2022

Conversation

Shnatsel
Copy link
Contributor

I've been inspecting the stack traces in a profiler and noticed that the fallback conversion functions are not inlined.

The #[inline] attribute in Rust is not transitive, and the fallbacks will not be inlined if they are not marked #[inline] explicitly.

I've verified that everything in the call stack up to this point is already marked #[inline].

@Shnatsel
Copy link
Contributor Author

Cuts the execution of the following test case in half, without the nightly-only feature for using intrinsics:

use std::{time::Instant, hint::black_box};

const ITERS: u32 = 500_000;

fn main() {
    let data = gen_data();

    let start_time = Instant::now();
    for i in 0..ITERS {
        for f in &data {
            let input = *f;
            black_box(input);
            let result = half::f16::from_f32(input);
            black_box(result);
        }
    }
    println!("Took {} ms", start_time.elapsed().as_millis());
}


fn gen_data() -> Vec<f32> {
    (0u32..1000u32).map(|i| i as f32).collect()
}

@starkat99
Copy link
Owner

Felt they were too non-trivial to inline without profiling it first, just never got around to doing that, so thanks for doing it!

@starkat99 starkat99 merged commit a28a562 into starkat99:main Dec 30, 2022
@Shnatsel Shnatsel deleted the inline-fallbacks branch December 31, 2022 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants