Skip to content

[experiment] remove the portable simd f16 patch - #1675

Draft
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:remove-f16-simd-patch
Draft

[experiment] remove the portable simd f16 patch#1675
folkertdev wants to merge 1 commit into
rust-lang:mainfrom
folkertdev:remove-f16-simd-patch

Conversation

@folkertdev

Copy link
Copy Markdown
Contributor

I believe this will fail but let's see what happens.

@folkertdev

Copy link
Copy Markdown
Contributor Author

As expected

https://triage.rust-lang.org/gha-logs/rust-lang/rustc_codegen_cranelift/86638749132?pr=1675

  = note: C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\a\rustc_codegen_cranelift\rustc_codegen_cranelift\build\portable-simd_target\x86_64-pc-windows-gnu\debug\deps\libproptest-f4ca5451e39982af.rlib(proptest-f4ca5451e39982af.proptest.26d0c0f6a929e698-cgu.05.rcgu.o):proptest.26d0c0f6a929e698-cgu.05.o:(.rdata$.refptr+0x0): undefined reference to `floorf16'
          C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/15.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:\a\rustc_codegen_cranelift\rustc_codegen_cranelift\build\portable-simd_target\x86_64-pc-windows-gnu\debug\deps\libproptest-f4ca5451e39982af.rlib(proptest-f4ca5451e39982af.proptest.26d0c0f6a929e698-cgu.05.rcgu.o):proptest.26d0c0f6a929e698-cgu.05.o:(.rdata$.refptr+0x0): undefined reference to `ceilf16'
          collect2.exe: error: ld returned 1 exit status

So that means we additionally need fallbacks for floorf16 and ceilf16. I'll look into that, seems straightforward.

jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 18, 2026
…, r=tgross35

add a fallback for more `f16` intrinsics

tracking issue: rust-lang#116909

Add several more fallbacks for `f16` intrinsics, so that they will work on platforms without the corresponding libcalls.

related

- rust-lang/rustc_codegen_cranelift#1675
- rust-lang/rustc_codegen_cranelift#1674
- rust-lang#150946
@bjorn3
bjorn3 force-pushed the remove-f16-simd-patch branch from b085bcc to d5b0c74 Compare July 19, 2026 17:52
@folkertdev

Copy link
Copy Markdown
Contributor Author

This is still missing the return false, // has a fallback via f32s that #1674 adds for some of the other functions

@folkertdev
folkertdev force-pushed the remove-f16-simd-patch branch 3 times, most recently from 1da99dd to ad67ef8 Compare July 19, 2026 20:52
@folkertdev

Copy link
Copy Markdown
Contributor Author

Hmm, the changes here are good, but I think we need the the additional gates I added. those are merged into portable_simd but not yet synced.

@rustbot

This comment has been minimized.

@folkertdev

Copy link
Copy Markdown
Contributor Author

I think this needs one more sync, rust-lang/rust#159582 should be in today's nightly.

@rustbot

This comment has been minimized.

@bjorn3

bjorn3 commented Jul 27, 2026

Copy link
Copy Markdown
Member

I've done a sync again.

@folkertdev
folkertdev force-pushed the remove-f16-simd-patch branch from e2b7f80 to c101a23 Compare July 27, 2026 14:27
@folkertdev

folkertdev commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, this fails on non-windows now because it tries to perform f16 SIMD operations. For f32 and f64 this performs libcalls

            simd_for_each_lane(fx, a, ret, &|fx, lane_ty, _ret_lane_ty, lane| {
                let lane_ty = match lane_ty.kind() {
                    ty::Float(FloatTy::F32) => types::F32,
                    ty::Float(FloatTy::F64) => types::F64,
                    _ => unreachable!("{:?}", lane_ty),
                };
                let name = match (intrinsic, lane_ty) {
                    (sym::simd_fsin, types::F32) => "sinf",
                    (sym::simd_fsin, types::F64) => "sin",
                    (sym::simd_fcos, types::F32) => "cosf",
                    (sym::simd_fcos, types::F64) => "cos",
                    (sym::simd_fexp, types::F32) => "expf",
                    (sym::simd_fexp, types::F64) => "exp",
                    (sym::simd_fexp2, types::F32) => "exp2f",
                    (sym::simd_fexp2, types::F64) => "exp2",
                    (sym::simd_flog, types::F32) => "logf",
                    (sym::simd_flog, types::F64) => "log",
                    (sym::simd_flog10, types::F32) => "log10f",
                    (sym::simd_flog10, types::F64) => "log10",
                    (sym::simd_flog2, types::F32) => "log2f",
                    (sym::simd_flog2, types::F64) => "log2",
                    (sym::simd_round, types::F32) => "roundf",
                    (sym::simd_round, types::F64) => "round",
                    (sym::simd_round_ties_even, types::F32) => "rintf",
                    (sym::simd_round_ties_even, types::F64) => "rint",
                    _ => unreachable!("{:?}", intrinsic),
                };
                fx.lib_call(
                    name,
                    vec![AbiParam::new(lane_ty)],
                    vec![AbiParam::new(lane_ty)],
                    &[lane],
                )[0]
            });

But for f16 we want to instead call the fallback body. In fact, perhaps we always want to call the fallback body now, given that it exists. Is there any way to do that from within this code?

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.

3 participants