Skip to content

Use native scalar fma instruction #1267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ fn codegen_float_intrinsic_call<'tcx>(

let layout = fx.layout_of(ty);
let res = match intrinsic {
sym::fmaf32 | sym::fmaf64 => {
let a = args[0].load_scalar(fx);
let b = args[1].load_scalar(fx);
let c = args[2].load_scalar(fx);
CValue::by_val(fx.bcx.ins().fma(a, b, c), layout)
}
sym::copysignf32 | sym::copysignf64 => {
let a = args[0].load_scalar(fx);
let b = args[1].load_scalar(fx);
Expand Down
18 changes: 6 additions & 12 deletions src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,21 +397,15 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(

let layout = a.layout();
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
let res_lane_layout = fx.layout_of(lane_ty);

for lane in 0..lane_count {
let a_lane = a.value_lane(fx, lane);
let b_lane = b.value_lane(fx, lane);
let c_lane = c.value_lane(fx, lane);
let a_lane = a.value_lane(fx, lane).load_scalar(fx);
let b_lane = b.value_lane(fx, lane).load_scalar(fx);
let c_lane = c.value_lane(fx, lane).load_scalar(fx);

let res_lane = match lane_ty.kind() {
ty::Float(FloatTy::F32) => {
fx.easy_call("fmaf", &[a_lane, b_lane, c_lane], lane_ty)
}
ty::Float(FloatTy::F64) => {
fx.easy_call("fma", &[a_lane, b_lane, c_lane], lane_ty)
}
_ => unreachable!(),
};
let res_lane = fx.bcx.ins().fma(a_lane, b_lane, c_lane);
let res_lane = CValue::by_val(res_lane, res_lane_layout);

ret.place_lane(fx, lane).write_cvalue(fx, res_lane);
}
Expand Down