Skip to content

Commit 5e984a3

Browse files
committed
Use simd instructions for int and float simd intrinsics
1 parent f8e846d commit 5e984a3

File tree

1 file changed

+32
-74
lines changed

1 file changed

+32
-74
lines changed

src/intrinsics/mod.rs

+32-74
Original file line numberDiff line numberDiff line change
@@ -268,93 +268,51 @@ macro simd_cmp {
268268

269269
macro simd_int_binop {
270270
($fx:expr, $intrinsic:expr, $op:ident($x:ident, $y:ident) -> $ret:ident) => {
271-
simd_pair_for_each_lane(
272-
$fx,
273-
$intrinsic,
274-
$x,
275-
$y,
276-
$ret,
277-
|fx, lane_layout, ret_lane_layout, x_lane, y_lane| {
278-
let res_lane = match lane_layout.ty.kind {
279-
ty::Uint(_) | ty::Int(_) => fx.bcx.ins().$op(x_lane, y_lane),
280-
_ => unreachable!("{:?}", lane_layout.ty),
281-
};
282-
CValue::by_val(res_lane, ret_lane_layout)
283-
},
284-
);
271+
simd_int_binop!($fx, $intrinsic, $op|$op($x, $y) -> $ret);
285272
},
286273
($fx:expr, $intrinsic:expr, $op_u:ident|$op_s:ident($x:ident, $y:ident) -> $ret:ident) => {
287-
simd_pair_for_each_lane(
288-
$fx,
289-
$intrinsic,
290-
$x,
291-
$y,
292-
$ret,
293-
|fx, lane_layout, ret_lane_layout, x_lane, y_lane| {
294-
let res_lane = match lane_layout.ty.kind {
295-
ty::Uint(_) => fx.bcx.ins().$op_u(x_lane, y_lane),
296-
ty::Int(_) => fx.bcx.ins().$op_s(x_lane, y_lane),
297-
_ => unreachable!("{:?}", lane_layout.ty),
298-
};
299-
CValue::by_val(res_lane, ret_lane_layout)
300-
},
301-
);
274+
let (lane_layout, lane_count) = lane_type_and_count($fx.tcx, $x.layout());
275+
let x_val = $x.load_vector($fx);
276+
let y_val = $y.load_vector($fx);
277+
278+
let res = match lane_layout.ty.kind {
279+
ty::Uint(_) => $fx.bcx.ins().$op_u(x_val, y_val),
280+
ty::Int(_) => $fx.bcx.ins().$op_s(x_val, y_val),
281+
_ => unreachable!("{:?}", lane_layout.ty),
282+
};
283+
$ret.write_cvalue($fx, CValue::by_val(res, $ret.layout()));
302284
},
303285
}
304286

305287
macro simd_int_flt_binop {
306288
($fx:expr, $intrinsic:expr, $op:ident|$op_f:ident($x:ident, $y:ident) -> $ret:ident) => {
307-
simd_pair_for_each_lane(
308-
$fx,
309-
$intrinsic,
310-
$x,
311-
$y,
312-
$ret,
313-
|fx, lane_layout, ret_lane_layout, x_lane, y_lane| {
314-
let res_lane = match lane_layout.ty.kind {
315-
ty::Uint(_) | ty::Int(_) => fx.bcx.ins().$op(x_lane, y_lane),
316-
ty::Float(_) => fx.bcx.ins().$op_f(x_lane, y_lane),
317-
_ => unreachable!("{:?}", lane_layout.ty),
318-
};
319-
CValue::by_val(res_lane, ret_lane_layout)
320-
},
321-
);
289+
simd_int_flt_binop!($fx, $intrinsic, $op|$op|$op_f($x, $y) -> $ret);
322290
},
323291
($fx:expr, $intrinsic:expr, $op_u:ident|$op_s:ident|$op_f:ident($x:ident, $y:ident) -> $ret:ident) => {
324-
simd_pair_for_each_lane(
325-
$fx,
326-
$intrinsic,
327-
$x,
328-
$y,
329-
$ret,
330-
|fx, lane_layout, ret_lane_layout, x_lane, y_lane| {
331-
let res_lane = match lane_layout.ty.kind {
332-
ty::Uint(_) => fx.bcx.ins().$op_u(x_lane, y_lane),
333-
ty::Int(_) => fx.bcx.ins().$op_s(x_lane, y_lane),
334-
ty::Float(_) => fx.bcx.ins().$op_f(x_lane, y_lane),
335-
_ => unreachable!("{:?}", lane_layout.ty),
336-
};
337-
CValue::by_val(res_lane, ret_lane_layout)
338-
},
339-
);
292+
let (lane_layout, lane_count) = lane_type_and_count($fx.tcx, $x.layout());
293+
let x_val = $x.load_vector($fx);
294+
let y_val = $y.load_vector($fx);
295+
296+
let res = match lane_layout.ty.kind {
297+
ty::Uint(_) => $fx.bcx.ins().$op_u(x_val, y_val),
298+
ty::Int(_) => $fx.bcx.ins().$op_s(x_val, y_val),
299+
ty::Float(_) => $fx.bcx.ins().$op_f(x_val, y_val),
300+
_ => unreachable!("{:?}", lane_layout.ty),
301+
};
302+
$ret.write_cvalue($fx, CValue::by_val(res, $ret.layout()));
340303
},
341304
}
342305

343306
macro simd_flt_binop($fx:expr, $intrinsic:expr, $op:ident($x:ident, $y:ident) -> $ret:ident) {
344-
simd_pair_for_each_lane(
345-
$fx,
346-
$intrinsic,
347-
$x,
348-
$y,
349-
$ret,
350-
|fx, lane_layout, ret_lane_layout, x_lane, y_lane| {
351-
let res_lane = match lane_layout.ty.kind {
352-
ty::Float(_) => fx.bcx.ins().$op(x_lane, y_lane),
353-
_ => unreachable!("{:?}", lane_layout.ty),
354-
};
355-
CValue::by_val(res_lane, ret_lane_layout)
356-
},
357-
);
307+
let (lane_layout, lane_count) = lane_type_and_count($fx.tcx, $x.layout());
308+
let x_val = $x.load_vector($fx);
309+
let y_val = $y.load_vector($fx);
310+
311+
let res = match lane_layout.ty.kind {
312+
ty::Float(_) => $fx.bcx.ins().$op(x_val, y_val),
313+
_ => unreachable!("{:?}", lane_layout.ty),
314+
};
315+
$ret.write_cvalue($fx, CValue::by_val(res, $ret.layout()));
358316
}
359317

360318
pub fn codegen_intrinsic_call<'tcx>(

0 commit comments

Comments
 (0)