Skip to content

backend: Properly implement remainder operation for f32 and f64 - #4943

Open
CohenArthur wants to merge 1 commit into
Rust-GCC:masterfrom
CohenArthur:fix-float-remainder
Open

CohenArthur wants to merge 1 commit into
Rust-GCC:masterfrom
CohenArthur:fix-float-remainder

Conversation

@CohenArthur

Copy link
Copy Markdown
Member

When performing the mod/remainder operation on floating point values, we cannot simply make a fold_build2 binary op as this operation is not defined in later passes of GCC for f32 and f64. We have to call the remainder{,f,l} builtins and store the result instead.

This was previously uncaught in our testsuite, and the associated testcase would simply ICE.

gcc/rust/ChangeLog:

* rust-gcc.cc (builtin_remainder_float_call): New function.
(maybe_extend_precision): Likewise.
(arithmetic_or_logical_expression): Call them and adapt logic.

gcc/testsuite/ChangeLog:

* rust/compile/float-rem.rs: New test.

@CohenArthur

Copy link
Copy Markdown
Member Author

This is required to properly implement the frem_fast intrinsic which I will have a PR for in a few minutes

Comment thread gcc/testsuite/rust/compile/float-rem.rs
@CohenArthur
CohenArthur force-pushed the fix-float-remainder branch 3 times, most recently from 2f69b6e to 4cbbbb1 Compare October 2, 2026 12:46
When performing the mod/remainder operation on floating point values, we cannot simply make a
fold_build2 binary op as this operation is not defined in later passes of GCC for f32 and f64.
We have to call the remainder{,f,l} builtins and store the result instead.

This was previously uncaught in our testsuite, and the associated testcase would simply ICE.

gcc/rust/ChangeLog:

	* rust-gcc.cc (builtin_remainder_float_call): New function.
	(maybe_extend_precision): Likewise.
	(arithmetic_or_logical_expression): Call them and adapt logic.

gcc/testsuite/ChangeLog:

	* rust/compile/float-rem.rs: New test.
@powerboat9

Copy link
Copy Markdown
Collaborator

LGTM besides the merge conflicts

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants