Implement simd_extract

This commit is contained in:
bjorn3 2019-08-05 16:28:27 +02:00
parent a1dd460714
commit 7602a46bb9
2 changed files with 19 additions and 0 deletions

View File

@ -72,6 +72,7 @@ unsafe fn test_simd() {
test_mm_add_epi8();
test_mm_add_pd();
test_mm_cvtepi8_epi16();
test_mm_cvtsi128_si64();
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
assert_eq!(mask1, 1);
@ -174,6 +175,12 @@ pub unsafe fn assert_eq_m128d(a: __m128d, b: __m128d) {
}
}
#[target_feature(enable = "sse2")]
unsafe fn test_mm_cvtsi128_si64() {
let r = _mm_cvtsi128_si64(std::mem::transmute::<[i64; 2], _>([5, 0]));
assert_eq!(r, 5);
}
#[target_feature(enable = "sse4.1")]
unsafe fn test_mm_cvtepi8_epi16() {
let a = _mm_set1_epi8(10);

View File

@ -953,6 +953,18 @@ fn swap(bcx: &mut FunctionBuilder, v: Value) -> Value {
}
};
simd_extract, (c v, o idx) {
let idx_const = crate::constant::mir_operand_get_const_val(fx, idx).expect("simd_extract* idx not const");
let idx = idx_const.val.try_to_bits(Size::from_bytes(4 /* u32*/)).expect(&format!("kind not scalar: {:?}", idx_const));
let (_lane_type, lane_count) = lane_type_and_count(fx, v.layout(), intrinsic);
if idx >= lane_count.into() {
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_extract] idx {} >= lane_count {}", idx, lane_count));
}
let ret_lane = v.value_field(fx, mir::Field::new(idx.try_into().unwrap()));
ret.write_cvalue(fx, ret_lane);
};
simd_add, (c x, c y) {
simd_int_flt_binop!(fx, intrinsic, iadd|fadd(x, y) -> ret);
};