Skip to content

Commit 854e9ba

Browse files
committed
Use fmul in log10 intrinsic
Fixes #199.
1 parent 562dff9 commit 854e9ba

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4848

4949
### Fixed 🩹
5050

51+
- [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
5152
- [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
5253
- [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
5354

crates/rustc_codegen_spirv/src/builder/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'a, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'tcx> {
174174
// log10(x) == (1 / ln(10)) * ln(x)
175175
let mul = self.constant_float(args[0].immediate().ty, 1.0 / 10.0f64.ln());
176176
let ln = self.gl_op(GLOp::Log, ret_ty, [args[0].immediate()]);
177-
self.mul(mul, ln)
177+
self.fmul(mul, ln)
178178
}
179179
sym::fmaf32 | sym::fmaf64 => self.gl_op(GLOp::Fma, ret_ty, [
180180
args[0].immediate(),

crates/rustc_codegen_spirv/src/builder/libm_intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl Builder<'_, '_> {
240240
// log10(x) == (1 / ln(10)) * ln(x)
241241
let mul = self.constant_float(args[0].ty, 1.0 / 10.0f64.ln());
242242
let ln = self.gl_op(GLOp::Log, result_type, [args[0]]);
243-
self.mul(mul, ln)
243+
self.fmul(mul, ln)
244244
}
245245
LibmIntrinsic::Custom(LibmCustomIntrinsic::Log1p) => {
246246
assert_eq!(args.len(), 1);
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Test log10 intrinsic
2+
// build-pass
3+
4+
#![allow(internal_features)]
5+
#![feature(core_intrinsics)]
6+
#![no_std]
7+
8+
use spirv_std::num_traits::Float as _;
9+
use spirv_std::spirv;
10+
11+
#[spirv(compute(threads(1)))]
12+
pub fn main(
13+
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] input: &[f32],
14+
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] output: &mut [f32],
15+
) {
16+
output[0] = input[0].log10();
17+
}

0 commit comments

Comments
 (0)