Skip to content

Commit

Permalink
Use fmul in log10 intrinsic
Browse files Browse the repository at this point in the history
Fixes #199.
  • Loading branch information
LegNeato committed Jan 6, 2025
1 parent 562dff9 commit dc57057
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed 🩹

- [PR#200](https://github.com/Rust-GPU/rust-gpu/pull/200) fixed [#199](https://github.com/Rust-GPU/rust-gpu/issues/199) by correctly generating an `fmul` in the `log10` intrinsic
- [PR#174](https://github.com/Rust-GPU/rust-gpu/pull/174) fixed [#169](https://github.com/Rust-GPU/rust-gpu/issues/169) by handling signed integers in the `bswap` intrinsic
- [PR#1129](https://github.com/EmbarkStudios/rust-gpu/pull/1129) fixed [#1062](https://github.com/EmbarkStudios/rust-gpu/issues/1062) by not flipping the comparison of the rotate amount with zero

Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
// log10(x) == (1 / ln(10)) * ln(x)
let mul = self.constant_float(args[0].immediate().ty, 1.0 / 10.0f64.ln());
let ln = self.gl_op(GLOp::Log, ret_ty, [args[0].immediate()]);
self.mul(mul, ln)
self.fmul(mul, ln)
}
sym::fmaf32 | sym::fmaf64 => self.gl_op(GLOp::Fma, ret_ty, [
args[0].immediate(),
Expand Down
2 changes: 1 addition & 1 deletion crates/rustc_codegen_spirv/src/builder/libm_intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Builder<'_, '_> {
// log10(x) == (1 / ln(10)) * ln(x)
let mul = self.constant_float(args[0].ty, 1.0 / 10.0f64.ln());
let ln = self.gl_op(GLOp::Log, result_type, [args[0]]);
self.mul(mul, ln)
self.fmul(mul, ln)
}
LibmIntrinsic::Custom(LibmCustomIntrinsic::Log1p) => {
assert_eq!(args.len(), 1);
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/lang/core/intrinsics/log10.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Test log10 intrinsic
// build-pass

#![allow(internal_features)]
#![feature(core_intrinsics)]
#![no_std]

use spirv_std::num_traits::Float as _;
use spirv_std::spirv;

#[spirv(compute(threads(1)))]
pub fn main(
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] input: &[f32],
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] output: &mut [f32],
) {
output[0] = input[0].log10();
}

0 comments on commit dc57057

Please sign in to comment.