Skip to content

Make exp, exp2, log, log2, log10 generic - #160989

Open
N1ark wants to merge 3 commits into
rust-lang:mainfrom
N1ark:08-12-generic-float-intrinsincs
Open

Make exp, exp2, log, log2, log10 generic#160989
N1ark wants to merge 3 commits into
rust-lang:mainfrom
N1ark:08-12-generic-float-intrinsincs

Conversation

@N1ark

@N1ark N1ark commented Aug 12, 2026

Copy link
Copy Markdown
Member

Rebased and smaller version of #153934

Following fabs, make the exp, exp2, log, log2 and log10 intrinsics generic over the float type, rather than having four variants per float type.

The first two commits are purely stylistic:

  • reorganised Cranelift code to make following changes simpler
  • moved a misplaced comment in compiler/rustc_codegen_llvm/src/intrinsic.rs that caused x fmt to give up

The last commit actually makes them generic! Most code is a bit simpler, and this will also hopefully simplify adding support for these intrinsics for the future bf16 type :)

Unfortunately both GCC and Cranelift backend changes are a bit churny. Their code is a bit, opaque, to put it kindly, and I didn't want to refactor those here.

r? @folkertdev
cc @RalfJung

Disclosure: I used an LLM to figure out the macro code.

@rustbot

rustbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Aug 12, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 12, 2026
@folkertdev

Copy link
Copy Markdown
Contributor

I suspect it would be better to submit 295e7a3 to the cg_clif repo for better CI coverage.

@rust-log-analyzer

This comment has been minimized.

@N1ark
N1ark force-pushed the 08-12-generic-float-intrinsincs branch from d98ca71 to b3a59f6 Compare August 12, 2026 14:55
@rustbot

rustbot commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Aug 12, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/pass/shims/x86/rounding-error.rs ... ok
tests/pass/shims/x86/intrinsics-x86-gfni.rs ... ok

FAILED TEST: tests/pass/float.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-cHeUEp" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/pass" "tests/pass/float.rs" "--edition" "2021"

error: test got exit status: 1, but expected 0
 = note: compilation failed, but was expected to succeed

error: no output was expected
Execute `./miri test --bless` to update `tests/pass/float.stderr` to the actual output
+++ <stderr output>
error: unsupported operation: Miri can only use intrinsic fallback bodies that exactly reflect the specification: they fully check for UB and are as non-deterministic as possible. After verifying that `exp` does so, add the `#[miri::intrinsic_fallback_is_spec]` attribute to it; also ping @rust-lang/miri when you do that
##[error]  --> /checkout/library/std/src/num/f16.rs:84:9
   |
LL |         intrinsics::exp(self)
   |         ^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
   = note: stack backtrace:
           0: std::f16::<impl f16>::exp
               at /checkout/library/std/src/num/f16.rs:84:9: 84:30
           1: libm
               at tests/pass/float.rs:1136:23: 1136:33
           2: main
               at tests/pass/float.rs:78:5: 78:11
---



full stderr:
error: unsupported operation: Miri can only use intrinsic fallback bodies that exactly reflect the specification: they fully check for UB and are as non-deterministic as possible. After verifying that `exp` does so, add the `#[miri::intrinsic_fallback_is_spec]` attribute to it; also ping @rust-lang/miri when you do that
##[error]  --> /checkout/library/std/src/num/f16.rs:84:9
   |
LL |         intrinsics::exp(self)
   |         ^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
   = note: stack backtrace:
           0: std::f16::<impl f16>::exp
               at /checkout/library/std/src/num/f16.rs:84:9: 84:30
           1: libm
               at tests/pass/float.rs:1136:23: 1136:33
           2: main
               at tests/pass/float.rs:78:5: 78:11
---



FAILED TEST: tests/pass/integer-ops.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-cHeUEp" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/pass" "tests/pass/integer-ops.rs" "-Coverflow-checks=off" "--edition" "2021"

error: test got exit status: 1, but expected 0
 = note: compilation failed, but was expected to succeed

error: no output was expected
Execute `./miri test --bless` to update `tests/pass/integer-ops.stderr` to the actual output
+++ <stderr output>
error: unsupported operation: Miri can only use intrinsic fallback bodies that exactly reflect the specification: they fully check for UB and are as non-deterministic as possible. After verifying that `log` does so, add the `#[miri::intrinsic_fallback_is_spec]` attribute to it; also ping @rust-lang/miri when you do that
##[error]  --> /checkout/library/std/src/num/f32.rs:474:9
   |
LL |         intrinsics::log(self)
   |         ^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
   = note: stack backtrace:
           0: std::f32::<impl f32>::ln
               at /checkout/library/std/src/num/f32.rs:474:9: 474:30
           1: std::f32::<impl f32>::log
               at /checkout/library/std/src/num/f32.rs:511:9: 511:18
           2: main
               at tests/pass/integer-ops.rs:260:45: 260:65

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error



full stderr:
error: unsupported operation: Miri can only use intrinsic fallback bodies that exactly reflect the specification: they fully check for UB and are as non-deterministic as possible. After verifying that `log` does so, add the `#[miri::intrinsic_fallback_is_spec]` attribute to it; also ping @rust-lang/miri when you do that
##[error]  --> /checkout/library/std/src/num/f32.rs:474:9
   |
LL |         intrinsics::log(self)
   |         ^^^^^^^^^^^^^^^^^^^^^ unsupported operation occurred here
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
   = note: stack backtrace:
           0: std::f32::<impl f32>::ln
               at /checkout/library/std/src/num/f32.rs:474:9: 474:30
           1: std::f32::<impl f32>::log
               at /checkout/library/std/src/num/f32.rs:511:9: 511:18
           2: main
               at tests/pass/integer-ops.rs:260:45: 260:65

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
---

Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.7/src/lib.rs:365

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/miri/855274d73082e308/out/ui-855274d73082e308` (exit status: 1)
Bootstrap failed while executing `test --stage 2 miri cargo-miri`
Currently active steps:
test::Miri { target: x86_64-unknown-linux-gnu } at src/bootstrap/src/core/build_steps/test.rs:697
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:197:21
Executed at: src/bootstrap/src/core/build_steps/test.rs:771:19

Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:44:55
  local time: Wed Aug 12 15:44:44 UTC 2026
  network time: Wed, 12 Aug 2026 15:44:44 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

CValue::by_val(codegen_f16_f128::fma_f16(fx, args[0], args[1], args[2]), layout)
}
let val = match intrinsic {
sym::fmaf16 | sym::fmuladdf16 => codegen_f16_f128::fma_f16(fx, args[0], args[1], args[2]),

@bjorn3 bjorn3 Aug 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This conflicts with rust-lang/rustc_codegen_cranelift#1675. I'm planning to do a sync soon.

View changes since the review

@N1ark N1ark Aug 12, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

oh then we can hold off from merging this until you've synced, i dont mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants