Skip to content

Commit 2db57c7

Browse files
committed
Sync from rust 48cc71ee88cd0f11217eced958b9930970da998b
2 parents ea7f582 + 90b98b2 commit 2db57c7

5 files changed

Lines changed: 42 additions & 25 deletions

File tree

example/float-minmax-pass.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ fn main() {
3333
let n = f32x4([nan, nan, nan, nan]);
3434

3535
unsafe {
36-
let min0 = simd_fmin(x, y);
37-
let min1 = simd_fmin(y, x);
36+
let min0 = simd_minimum_number_nsz(x, y);
37+
let min1 = simd_minimum_number_nsz(y, x);
3838
assert_eq!(min0.into_array(), min1.into_array());
3939
let e = f32x4([1.0, 1.0, 3.0, 3.0]);
4040
assert_eq!(min0.into_array(), e.into_array());
41-
let minn = simd_fmin(x, n);
41+
let minn = simd_minimum_number_nsz(x, n);
4242
assert_eq!(minn.into_array(), x.into_array());
43-
let minn = simd_fmin(y, n);
43+
let minn = simd_minimum_number_nsz(y, n);
4444
assert_eq!(minn.into_array(), y.into_array());
4545

46-
let max0 = simd_fmax(x, y);
47-
let max1 = simd_fmax(y, x);
46+
let max0 = simd_maximum_number_nsz(x, y);
47+
let max1 = simd_maximum_number_nsz(y, x);
4848
assert_eq!(max0.into_array(), max1.into_array());
4949
let e = f32x4([2.0, 2.0, 4.0, 4.0]);
5050
assert_eq!(max0.into_array(), e.into_array());
51-
let maxn = simd_fmax(x, n);
51+
let maxn = simd_maximum_number_nsz(x, n);
5252
assert_eq!(maxn.into_array(), x.into_array());
53-
let maxn = simd_fmax(y, n);
53+
let maxn = simd_maximum_number_nsz(y, n);
5454
assert_eq!(maxn.into_array(), y.into_array());
5555
}
5656
}

src/driver/aot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ enum OngoingModuleCodegen {
4545
Async(JoinHandle<Result<ModuleCodegenResult, String>>),
4646
}
4747

48-
impl<HCX> HashStable<HCX> for OngoingModuleCodegen {
49-
fn hash_stable(&self, _: &mut HCX, _: &mut StableHasher) {
48+
impl<Hcx> HashStable<Hcx> for OngoingModuleCodegen {
49+
fn hash_stable(&self, _: &mut Hcx, _: &mut StableHasher) {
5050
// do nothing
5151
}
5252
}

src/intrinsics/mod.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,6 @@ fn codegen_float_intrinsic_call<'tcx>(
346346
sym::log10f32 => ("log10f", 1, fx.tcx.types.f32, types::F32),
347347
sym::log10f64 => ("log10", 1, fx.tcx.types.f64, types::F64),
348348
sym::log10f128 => ("log10f128", 1, fx.tcx.types.f128, types::F128),
349-
sym::fabsf16 => ("fabsf16", 1, fx.tcx.types.f16, types::F16),
350-
sym::fabsf32 => ("fabsf", 1, fx.tcx.types.f32, types::F32),
351-
sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64, types::F64),
352-
sym::fabsf128 => ("fabsf128", 1, fx.tcx.types.f128, types::F128),
353349
sym::fmaf16 => ("fmaf16", 3, fx.tcx.types.f16, types::F16),
354350
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32),
355351
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64),
@@ -441,11 +437,7 @@ fn codegen_float_intrinsic_call<'tcx>(
441437
sym::copysignf32 | sym::copysignf64 => {
442438
CValue::by_val(fx.bcx.ins().fcopysign(args[0], args[1]), layout)
443439
}
444-
sym::fabsf16 => CValue::by_val(codegen_f16_f128::abs_f16(fx, args[0]), layout),
445-
sym::fabsf128 => CValue::by_val(codegen_f16_f128::abs_f128(fx, args[0]), layout),
446-
sym::fabsf32
447-
| sym::fabsf64
448-
| sym::floorf32
440+
sym::floorf32
449441
| sym::floorf64
450442
| sym::ceilf32
451443
| sym::ceilf64
@@ -456,7 +448,6 @@ fn codegen_float_intrinsic_call<'tcx>(
456448
| sym::sqrtf32
457449
| sym::sqrtf64 => {
458450
let val = match intrinsic {
459-
sym::fabsf32 | sym::fabsf64 => fx.bcx.ins().fabs(args[0]),
460451
sym::floorf32 | sym::floorf64 => fx.bcx.ins().floor(args[0]),
461452
sym::ceilf32 | sym::ceilf64 => fx.bcx.ins().ceil(args[0]),
462453
sym::truncf32 | sym::truncf64 => fx.bcx.ins().trunc(args[0]),
@@ -1179,6 +1170,28 @@ fn codegen_regular_intrinsic_call<'tcx>(
11791170
ret.write_cvalue(fx, old);
11801171
}
11811172

1173+
sym::fabs => {
1174+
intrinsic_args!(fx, args => (arg); intrinsic);
1175+
let layout = arg.layout();
1176+
let ty::Float(float_ty) = layout.ty.kind() else {
1177+
span_bug!(
1178+
source_info.span,
1179+
"expected float type for fabs intrinsic: {:?}",
1180+
layout.ty
1181+
);
1182+
};
1183+
let x = arg.load_scalar(fx);
1184+
let val = match float_ty {
1185+
FloatTy::F32 | FloatTy::F64 => fx.bcx.ins().fabs(x),
1186+
// FIXME(bytecodealliance/wasmtime#8312): Use `fabsf16` once Cranelift
1187+
// backend lowerings are implemented.
1188+
FloatTy::F16 => codegen_f16_f128::abs_f16(fx, x),
1189+
FloatTy::F128 => codegen_f16_f128::abs_f128(fx, x),
1190+
};
1191+
let val = CValue::by_val(val, layout);
1192+
ret.write_cvalue(fx, val);
1193+
}
1194+
11821195
sym::minimumf16 => {
11831196
intrinsic_args!(fx, args => (a, b); intrinsic);
11841197
let a = a.load_scalar(fx);

src/intrinsics/simd.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
493493
}
494494
}
495495

496-
sym::simd_fmin | sym::simd_fmax => {
496+
sym::simd_minimum_number_nsz | sym::simd_maximum_number_nsz => {
497497
intrinsic_args!(fx, args => (x, y); intrinsic);
498498

499499
if !x.layout().ty.is_simd() {
@@ -508,8 +508,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
508508
_ => unreachable!("{:?}", lane_ty),
509509
}
510510
match intrinsic {
511-
sym::simd_fmin => crate::num::codegen_float_min(fx, x_lane, y_lane),
512-
sym::simd_fmax => crate::num::codegen_float_max(fx, x_lane, y_lane),
511+
sym::simd_minimum_number_nsz => {
512+
crate::num::codegen_float_min(fx, x_lane, y_lane)
513+
}
514+
sym::simd_maximum_number_nsz => {
515+
crate::num::codegen_float_max(fx, x_lane, y_lane)
516+
}
513517
_ => unreachable!(),
514518
}
515519
});

src/num.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ fn codegen_ptr_binop<'tcx>(
500500

501501
// In Rust floating point min and max don't propagate NaN (not even SNaN). In Cranelift they do
502502
// however. For this reason it is necessary to use `a.is_nan() ? b : (a >= b ? b : a)` for
503-
// `minnumf*` and `a.is_nan() ? b : (a <= b ? b : a)` for `maxnumf*`. NaN checks are done by
504-
// comparing a float against itself. Only in case of NaN is it not equal to itself.
503+
// `minimum_number_nsz` and `a.is_nan() ? b : (a <= b ? b : a)` for `maximum_number_nsz`. NaN checks
504+
// are done by comparing a float against itself. Only in case of NaN is it not equal to itself.
505505
pub(crate) fn codegen_float_min(fx: &mut FunctionCx<'_, '_, '_>, a: Value, b: Value) -> Value {
506506
// FIXME(bytecodealliance/wasmtime#8312): Replace with Cranelift `fcmp` once
507507
// `f16`/`f128` backend lowerings have been added to Cranelift.

0 commit comments

Comments
 (0)