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

util/libm: replace force_eval! by std::hint::black_box #117

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

martinvonz
Copy link
Contributor

During an internal review of unsafe code at work, @cramertj noticed that the the force_eval! can be replaced by std::hint::black_box, removing the need for unsafe Rust.

@cramertj
Copy link

Related: rust-lang/libm#288

Copy link
Owner

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

It looks like one unsafe was missed.

Otherwise, insomuch as I can judge this, I think this LGTM. However, @Amanieu did say this:

To work around FP precision issues on 32-bit x86 which uses 80-bit float precision internally. This is unfortunately an unavoidable issue on x86 since it has pretty broken FP support.

Which seems to me like it's relying on volatile reads for correctness. But my understanding is that relying on black_box for correctness is bad juju. I don't understand enough about the problem domain here to adjudicate though. I'd be inclined to take a reactive approach here and merge, and revert if folks notice problems in practice.

src/util/libm.rs Outdated Show resolved Hide resolved
During an internal review of unsafe code at work, @cramertj noticed
that the the `force_eval!` can be replaced by `core::hint::black_box`,
removing the need for unsafe Rust.
@BurntSushi BurntSushi merged commit b63d9e6 into BurntSushi:master Aug 28, 2024
17 checks passed
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