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

This enables math module for riscv32 targets #554

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

mchodzikiewicz
Copy link
Contributor

This is likely a bug fix since in math.rs there are already config attributes that are mentioning this target.

I was pointed here from esp-rs/esp-hal#881

src/lib.rs Outdated
@@ -48,6 +48,7 @@ pub mod int;
all(target_arch = "x86_64", target_os = "none"),
all(target_arch = "x86_64", target_os = "uefi"),
all(target_arch = "arm", target_os = "none"),
all(target_arch = "riscv32", target_os = "none"),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also gate on not(target_feature = "f")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Member

Choose a reason for hiding this comment

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

A fair amount of the intrinsics in libm don't have native instructions even on cpu's that do support floating point operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

huh, my initial thinking was that if there are gates on non-fpu on relevant elements inside math.rs it is ok not to gate it on module inclusion

I'll do whatever you guys tell me, just created this PR to speed things up and have the thing going on somewhere since esp-hal was clearly not a correct place for it

Copy link
Contributor

Choose a reason for hiding this comment

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

A fair amount of the intrinsics in libm don't have native instructions even on cpu's that do support floating point operations.

Is there any point in gating the math module at all then? Presumably, if the backend supports code-generation instead of using an intrinsic it will just do that, and not emit a call to the intrinsic. Compile times I suppose?

Copy link
Member

Choose a reason for hiding this comment

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

Is there any point in gating the math module at all then?

Yes, we must not include it when there is already a libm implementation providing them. This libm implementation is generally part of the system libc. We are allowlisting targets without libc here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, so I brought back the original commit

@mchodzikiewicz mchodzikiewicz force-pushed the fix-math-for-riscv32 branch 2 times, most recently from e36bea1 to e6bbec5 Compare October 30, 2023 21:54
@Amanieu
Copy link
Member

Amanieu commented Oct 31, 2023

Should the same be done for riscv64 bare metal targets?

@mchodzikiewicz
Copy link
Contributor Author

mchodzikiewicz commented Oct 31, 2023

good question, also does

We are allowlisting targets without libc here.

mean that we could skip architecture and go for

all(target_os = "none")

?

@Amanieu
Copy link
Member

Amanieu commented Oct 31, 2023

Yes, actually that would make more sense. It seems the same conclusion was reached for UEFI in #553, we probably shouldn't be checking target_arch at all, only the target OS.

@mchodzikiewicz
Copy link
Contributor Author

Cool! Changed it accordingly. Maybe I should rebase on #553 already?

@Amanieu
Copy link
Member

Amanieu commented Oct 31, 2023

I've merged #553, you can rebase on top of that.

Also we should remove the target_arch checks within the math module. The aim here is that we only want to provide functions that are not already provided by the system libm, which should only depend on the OS, not the architecture.

@mchodzikiewicz
Copy link
Contributor Author

huh, but then what about gating like all(target_arch = "riscv32", not(target_feature = "f"), target_os = "none")? should we also provide these functions for FPU-driven targets?

@Amanieu
Copy link
Member

Amanieu commented Oct 31, 2023

It doesn't hurt to provide them anyways. If they are not used then the linker will simply not include them in the output binary.

This was initially a bugfix that fixed gating math module for riscv32,
but conclusiion is it makes no sense to gate on target architecture.
@mchodzikiewicz
Copy link
Contributor Author

Okay, how about now?

@mchodzikiewicz mchodzikiewicz force-pushed the fix-math-for-riscv32 branch 2 times, most recently from 06a46b7 to ce1e4d2 Compare October 31, 2023 20:24
@mchodzikiewicz
Copy link
Contributor Author

mchodzikiewicz commented Oct 31, 2023

It is not that easy - gating only on taget os "none" enables it for targets that have these symbols already leading to multiple definitions, gating module inclusion seems fine though.

Maybe some other gating scheme would do the trick, but I am not sure if it should be part of this PR

@Amanieu Amanieu merged commit 3dea633 into rust-lang:master Oct 31, 2023
21 checks passed
@mchodzikiewicz mchodzikiewicz deleted the fix-math-for-riscv32 branch October 31, 2023 21:56
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.

4 participants