Skip to content

Commit 8d8b489

Browse files
committed
Add intrinsics for SIMD arithmetic.
1 parent ecb3df5 commit 8d8b489

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/librustc_trans/trans/intrinsic.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,5 +1496,35 @@ fn generic_simd_intrinsic<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
14961496
}
14971497
require!(false, "SIMD cast intrinsic monomorphised with incompatible cast");
14981498
}
1499+
macro_rules! arith {
1500+
($($name: ident: $($($p: ident),* => $call: expr),*;)*) => {
1501+
$(
1502+
if name == stringify!($name) {
1503+
let in_ = arg_tys[0].simd_type(tcx);
1504+
match in_.sty {
1505+
$(
1506+
$(ty::$p(_))|* => {
1507+
return $call(bcx, llargs[0], llargs[1], call_debug_location)
1508+
}
1509+
)*
1510+
_ => {},
1511+
}
1512+
require!(false,
1513+
"{} intrinsic monomorphised with invalid type",
1514+
name)
1515+
})*
1516+
}
1517+
}
1518+
arith! {
1519+
simd_add: TyUint, TyInt => Add, TyFloat => FAdd;
1520+
simd_sub: TyUint, TyInt => Sub, TyFloat => FSub;
1521+
simd_mul: TyUint, TyInt => Mul, TyFloat => FMul;
1522+
simd_div: TyFloat => FDiv;
1523+
simd_shl: TyUint, TyInt => Shl;
1524+
simd_shr: TyUint => LShr, TyInt => AShr;
1525+
simd_and: TyUint, TyInt => And;
1526+
simd_or: TyUint, TyInt => Or;
1527+
simd_xor: TyUint, TyInt => Xor;
1528+
}
14991529
bcx.sess().span_bug(call_info.span, "unknown SIMD intrinsic");
15001530
}

src/librustc_typeck/check/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5344,6 +5344,11 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
53445344
"simd_eq" | "simd_ne" | "simd_lt" | "simd_le" | "simd_gt" | "simd_ge" => {
53455345
(2, vec![param(ccx, 0), param(ccx, 0)], param(ccx, 1))
53465346
}
5347+
"simd_add" | "simd_sub" | "simd_mul" |
5348+
"simd_div" | "simd_shl" | "simd_shr" |
5349+
"simd_and" | "simd_or" | "simd_xor" => {
5350+
(1, vec![param(ccx, 0), param(ccx, 0)], param(ccx, 0))
5351+
}
53475352
"simd_insert" => (2, vec![param(ccx, 0), tcx.types.u32, param(ccx, 1)], param(ccx, 0)),
53485353
"simd_extract" => (2, vec![param(ccx, 0), tcx.types.u32], param(ccx, 1)),
53495354
"simd_cast" => (2, vec![param(ccx, 0)], param(ccx, 1)),

0 commit comments

Comments
 (0)