Skip to content

Commit c3ef307

Browse files
committed
Merge fabsfN into fabs::<F>
Add `bounds::FloatPrimitive` Exhaustive float pattern match Fix GCC use span bugs
1 parent 6b8bdc9 commit c3ef307

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

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);

0 commit comments

Comments
 (0)