implement simd_add

This commit is contained in:
Ralf Jung 2021-11-18 09:36:01 -05:00
parent 8c700f544c
commit 0766da6fbe
2 changed files with 26 additions and 0 deletions

View File

@ -305,6 +305,24 @@ fn call_intrinsic(
this.write_scalar(res, dest)?;
}
// SIMD operations
"simd_add" => {
let &[ref left, ref right] = check_arg_count(args)?;
let (left, left_len) = this.operand_to_simd(left)?;
let (right, right_len) = this.operand_to_simd(right)?;
let (dest, dest_len) = this.place_to_simd(dest)?;
assert_eq!(dest_len, left_len);
assert_eq!(dest_len, right_len);
for i in 0..dest_len {
let left = this.read_immediate(&this.mplace_index(&left, i)?.into())?;
let right = this.read_immediate(&this.mplace_index(&right, i)?.into())?;
let dest = this.mplace_index(&dest, i)?.into();
this.binop_ignore_overflow(mir::BinOp::Add, &left, &right, &dest)?;
}
}
// Atomic operations
"atomic_load" => this.atomic_load(args, dest, AtomicReadOp::SeqCst)?,
"atomic_load_relaxed" => this.atomic_load(args, dest, AtomicReadOp::Relaxed)?,

View File

@ -0,0 +1,8 @@
#![feature(portable_simd)]
use std::simd::*;
fn main() {
let a = f32x4::splat(10.0);
let b = f32x4::from_array([1.0, 2.0, 3.0, 4.0]);
assert_eq!(a + b, f32x4::from_array([11.0, 12.0, 13.0, 14.0]));
}