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

Faster float conversion operations #464

Merged
merged 2 commits into from
May 26, 2022
Merged

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented May 20, 2022

This supersedes #370

This includes #463

@m-ou-se
Copy link
Member Author

m-ou-se commented May 20, 2022

Currently, compiler_builtins contains two cases where a builtin is implemented by the native conversion on x86_64:

// On x86_64 LLVM will use native instructions for this conversion, we
// can just do it directly
if cfg!(target_arch = "x86_64") {
i as f32
} else {

I'm a bit confused by that. If i as f32 results in native code and not a call to compiler-builtins, then there doesn't seem to be much reason to optimize the version in compiler-builtins.

The version in this PR does not have those special cases. I can put them back if someone thinks they are actually useful.

@bjorn3
Copy link
Member

bjorn3 commented May 20, 2022

I'm a bit confused by that. If i as f32 results in native code and not a call to compiler-builtins, then there doesn't seem to be much reason to optimize the version in compiler-builtins.

as f32 results in an intrinsic call on platforms that don't have a native version of this.

The version in this PR does not have those special cases. I can put them back if someone thinks they are actually useful.

I think it should be put back.

@m-ou-se
Copy link
Member Author

m-ou-se commented May 20, 2022

as f32 results in an intrinsic call on platforms that don't have a native version of this.

Yes.. That's what I said. The special case is for a platform that does have a native version, which means this function wouldn't be called when someone does as f32.

I think it should be put back.

Why? When would it be used on x86_64?

@bjorn3
Copy link
Member

bjorn3 commented May 20, 2022

Looks like it is also used in case of +soft-float. I guess that special case wouldn't be valid then though.

Copy link
Member

@Amanieu Amanieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM apart from a few style nits.

src/float/conv.rs Outdated Show resolved Hide resolved
pub extern "C" fn __floatdidf(i: i64) -> f64 {
// On x86_64 LLVM will use native instructions for this conversion, we
// can just do it directly
if cfg!(target_arch = "x86_64") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this is fine, I'm not even sure why this hack was here in the first place. If LLVM generates a native instruction then this function is never called anyways. Except in the case of soft-float, in which case you specifically don't want to use the built-in instruction.

@Amanieu Amanieu merged commit 8f89148 into rust-lang:master May 26, 2022
@m-ou-se m-ou-se deleted the floatconv2 branch May 26, 2022 20:47
@nickdesaulniers
Copy link

Nice blog post; does it make sense to put any of these implementation in llvm's compiler-rt?

@m-ou-se
Copy link
Member Author

m-ou-se commented Nov 30, 2023

does it make sense to put any of these implementation in llvm's compiler-rt?

@nickdesaulniers Sure! I don't have time for that, but if someone has time to port these implementations, that might benefit a lot of people :)

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.

4 participants