Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add builtins forf16/f128 float conversions#593

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Amanieu merged 1 commit intorust-lang:masterfrombeetrees:fix-f16-conv-c
May 2, 2024

Conversation

@beetrees
Copy link
Contributor

Adds builtins for float conversions to/fromf16/f128, which will solverust-lang/rust#123885. I also updated theREADME.md to reflect thatf16/f128 are being added to Rust.

@tgross35 this should save you some work on#587.

I'm not sure if the new functions need the#[avr_skip] attribute like the existing extend/truncate builtins do, but thought it was better to add it and accidentally cause linker errors if the builtin is needed and not supplied bylibgcc rather than not having the attribute and accidentally causing subtle ABI bugs if a special ABI is required on AVR.@Patryk27 who added the original#[avr_skip]s.

tgross35, Patryk27, usamoi, and Enselic reacted with heart emoji
@Patryk27
Copy link
Contributor

Yeah, I'm not sure on AVR's ABI here, so probably better to keep those#[avr_skip] 🙂

@beetreesbeetreesforce-pushed thefix-f16-conv-c branch 2 times, most recently from6dd8caf to4878c32CompareApril 14, 2024 22:46
tgross35 added a commit to tgross35/compiler-builtins that referenced this pull requestApr 15, 2024
@tgross35
Copy link
Contributor

Should this also be settingCOMPILER_RT_HAS_FLOAT16 for the C build, in case that winds up being used as a fallback in the future?

@tgross35
Copy link
Contributor

Since this will probably land before#587, you might have to add the feature gate that@bjorn3 requested#587 (comment)

@beetrees
Copy link
ContributorAuthor

I've added ano-f16-f128 feature (following the convention set by the existingno-asm feature). I've also added aCOMPILER_RT_HAS_FLOAT16 define whencompiler-rt is being built, with a comment explaining why it is there.

tgross35 reacted with thumbs up emoji

@tgross35
Copy link
Contributor

Thanks, that part looks great to me. Looks like tests might be missing? Like

// PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
#[cfg(not(target_arch ="powerpc64"))]
#[test]
fnfloat_extend(){
use compiler_builtins::float::extend::__extendsfdf2;
extend!(f32,f64, __extendsfdf2);
}
/
#[test]
fnfloat_trunc(){
use compiler_builtins::float::trunc::__truncdfsf2;
trunc!(f64,f32, __truncdfsf2);
}
#[cfg(target_arch ="arm")]
#[test]
fnfloat_trunc_arm(){
use compiler_builtins::float::trunc::__truncdfsf2vfp;
trunc!(f64,f32, __truncdfsf2vfp);
}

tgross35 added a commit to tgross35/compiler-builtins that referenced this pull requestApr 17, 2024
tgross35 added a commit to tgross35/compiler-builtins that referenced this pull requestApr 19, 2024
@beetreesbeetreesforce-pushed thefix-f16-conv-c branch 2 times, most recently from201f826 to11c1eedCompareApril 21, 2024 15:55
@beetrees
Copy link
ContributorAuthor

As the builtins aren't present everywhere at the moment (and therefore comparing against the builtin compiler float conversions would cause test failures on platforms where they're currently unavailable or miscompiled), I've instead added tests comparingcompiler_builtins float conversions to those inrustc_apfloat, the (heavily tested) soft float library ported from LLVM for use inrustc. I've also fixed a copy-paste error and some shift overflow bugs (that only show up now the destination type can be larger than 32 bits) intrunc.rs that I discovered by running the tests, and moved the float conversion tests frommisc.rs toconv.rs.

@tgross35
Copy link
Contributor

I've instead added tests comparingcompiler_builtins float conversions to those inrustc_apfloat

Great idea, I can probably do the same on#587. Everything here looks reasonable to my understanding, probably ready for a look from@Amanieu.

@beetreesbeetreesforce-pushed thefix-f16-conv-c branch 2 times, most recently from76e648a toefd5d7dCompareApril 28, 2024 16:38
abs_result =(a_abs >> sign_bits_delta).cast();
let tmp = src_exp_bias.wrapping_sub(dst_exp_bias) <<R::SIGNIFICAND_BITS;
abs_result = abs_result.wrapping_sub(tmp.cast());
// Cast before shifting to prevent overflow.
Copy link
Member

Choose a reason for hiding this comment

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

I'm having trouble understand how exactly this helps prevent overflows. Aren't you casting to a smaller size (u16) here instead of operating as a u32?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@Amanieu This is indeed not an issue for truncation tof16. However, the__trunctfdf2 builtin also implemented in this PR truncates fromf128 tof64, meaningR::Int is au64 andR::SIGNIFICAND_BITS is52.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I missed that. LGTM.

nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestMay 16, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestMay 27, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestMay 30, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestMay 30, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc.
bors added a commit to rust-lang-ci/rust that referenced this pull requestMay 30, 2024
Update compiler_builtins to 0.1.112The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestMay 30, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc.
bors added a commit to rust-lang-ci/rust that referenced this pull requestJun 4, 2024
…iler-errorsUpdate compiler_builtins to 0.1.112The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestJun 4, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestJun 4, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestJun 8, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
bors added a commit to rust-lang-ci/rust that referenced this pull requestJun 17, 2024
Update compiler_builtins to 0.1.112The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
tgross35 pushed a commit to tgross35/rust that referenced this pull requestJun 21, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestJun 25, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
bors added a commit to rust-lang-ci/rust that referenced this pull requestJun 26, 2024
Update compiler_builtins to 0.1.112The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull requestJun 26, 2024
…anieuUpdate compiler_builtins to 0.1.113The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull requestJun 26, 2024
…anieuUpdate compiler_builtins to 0.1.113The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
tgross35 pushed a commit to tgross35/rust that referenced this pull requestJul 10, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
tgross35 pushed a commit to tgross35/rust that referenced this pull requestJul 18, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
nicholasbishop added a commit to nicholasbishop/rust that referenced this pull requestJul 29, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
bors added a commit to rust-lang-ci/rust that referenced this pull requestJul 29, 2024
…ss35Update compiler_builtins to 0.1.114The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
Mrmaxmeier pushed a commit to Mrmaxmeier/rust that referenced this pull requestJul 29, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
github-actionsbot pushed a commit to rust-lang/miri that referenced this pull requestJul 30, 2024
Update compiler_builtins to 0.1.114The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull requestAug 2, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull requestAug 2, 2024
Update compiler_builtins to 0.1.114The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
GuillaumeGomez pushed a commit to GuillaumeGomez/rustc_codegen_gcc that referenced this pull requestAug 6, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
GuillaumeGomez pushed a commit to GuillaumeGomez/rustc_codegen_gcc that referenced this pull requestAug 6, 2024
Update compiler_builtins to 0.1.114The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
GuillaumeGomez pushed a commit to GuillaumeGomez/rustc_codegen_gcc that referenced this pull requestAug 12, 2024
The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the`compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, somebuiltins for f16/f128 were added. These don't work for all compilerbackends, so add a `compiler-builtins-no-f16-f128` feature and disableit for cranelift and gcc. Also disable it for LLVM targets that don'tsupport it.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull requestAug 13, 2024
Update compiler_builtins to 0.1.114The `weak-intrinsics` feature was removed from compiler_builtins inrust-lang/compiler-builtins#598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.Inrust-lang/compiler-builtins#593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@AmanieuAmanieuAmanieu left review comments

@tgross35tgross35tgross35 left review comments

+2 more reviewers

@RalfJungRalfJungRalfJung left review comments

@bjorn3bjorn3bjorn3 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@beetrees@Patryk27@tgross35@Amanieu@RalfJung@bjorn3

[8]ページ先頭

©2009-2025 Movatter.jp