Repository navigation
Implement all core_float_math functions using core::intrinsics - #668
mikwielgus wants to merge 1 commit into
Conversation
c97b527 to
3f6a1a9
Compare
This implements all the methods listed in rust-lang/rust#137578 for `f32` and `f64` in a no-`std` environment using functions from `core::intrinsics` and with the help of the `#[rustc_allow_incoherent_impl]` internal rustc attribute. For test coverage, I have updated the math_ops difftest to use the new functions (for that I used Cursor Auto). `powi` test output again marginally changed, so I blessed it again. These are not all missing functions yet. There is also `log`, `log10`, `exp`, and a few more, which are not part of `core_float_math`. These will probably follow afterwards. Follow-up from c087f99.
3f6a1a9 to
aa642e1
Compare
|
Any reason to limit this to |
No reason, I'm only splitting these changes into multiple PRs for easier review. My goal is to replace all of these functions, so that I can remove |
|
Feel free to just expand this PR into adding all of them, makes it easier to review since I can just scan core's |
|
I've re-read your message.
Just to be sure: in this PR, you don't want me to just implement the remaining mathematical functions using If yes, then I'd still prefer doing this in another PR, because that's going to be more advanced and as such could merit a separate review. |
|
I'd also be fine merging this as is and take the rest as a later PR. I'll delay the actual merge a tiny bit as I want to make a release today / tomorrow. While I look over rust-gpu maintenance, I'm not too familiar with how our libm functions work, so feel free to correct me on this. So we've got our table of libm overwrites here containing functions such as My brain immediately screams DRY and wants to get rid of one of them. So why shouldn't we get rid of the libm path and just do this for the remaining functions? #[cfg(target_arch = "spirv")]
impl f32 {
pub fn sin(self) -> f32 {
intrinsics::sin(self)
}
}This should end up calling our However, when you look at So I'd assume if we impl this and get rid of our libm overwrites, I can prep some compiletest to make sure our codegen doesn't worsen. On inline assembly: We could very much also use inline SPIR-V asm to implement these functions instead of going via the codegen backend. Here's a quick (tested) mockup, you'll find the IDs (13 for sin) in https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html #[inline]
pub fn sin(a: f32) -> f32 {
let mut result;
unsafe {
asm!(
"%glsl = OpExtInstImport \"GLSL.std.450\"",
"{result} = OpExtInst typeof*{result} %glsl 13 {a}",
a = in(reg) a,
result = out(reg) result,
);
}
result
} |
Yes (but I haven't tested this). But |
This implements all the methods listed in
rust-lang/rust#137578
for
f32andf64in a no-stdenvironment using functions fromcore::intrinsicsand with the help of the#[rustc_allow_incoherent_impl]internal rustc attribute.For test coverage, I have updated the math_ops difftest to use the new functions (for that I used Cursor Auto).
powitest output again marginally changed, so I blessed it again.These are not all missing functions yet. There is also
log,log10,exp, and a few more, which are not part ofcore_float_math. These will probably follow afterwards.Follow-up from c087f99.