Skip to content

Commit edc0a34

Browse files
committed
Implement simd_insert
1 parent 0b211be commit edc0a34

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

example/std_example.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ unsafe fn test_simd() {
146146

147147
// FIXME(#666) implement `#[rustc_arg_required_const(..)]` support
148148
//test_mm_extract_epi8();
149+
//test_mm_insert_epi16();
149150

150151
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)));
151152
assert_eq!(mask1, 1);
@@ -279,6 +280,14 @@ unsafe fn test_mm_extract_epi8() {
279280
assert_eq!(r2, 3);
280281
}
281282

283+
#[target_feature(enable = "sse2")]
284+
unsafe fn test_mm_insert_epi16() {
285+
let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
286+
let r = _mm_insert_epi16(a, 9, 0);
287+
let e = _mm_setr_epi16(9, 1, 2, 3, 4, 5, 6, 7);
288+
assert_eq_m128i(r, e);
289+
}
290+
282291
fn test_checked_mul() {
283292
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
284293
assert_eq!(u, None);

src/intrinsics/simd.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
3333
});
3434
};
3535

36+
// FIXME support float comparisons
3637
simd_eq, (c x, c y) {
3738
validate_simd_type!(fx, intrinsic, span, x.layout().ty);
3839
simd_cmp!(fx, Equal(x, y) -> ret);
@@ -113,7 +114,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
113114
}
114115
};
115116

116-
simd_insert, (c base, o idx, v _val) {
117+
simd_insert, (c base, o idx, c val) {
117118
// FIXME validate
118119
let idx_const = if let Some(idx_const) = crate::constant::mir_operand_get_const_val(fx, idx) {
119120
idx_const
@@ -132,13 +133,9 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
132133
fx.tcx.sess.span_fatal(fx.mir.span, &format!("[simd_insert] idx {} >= lane_count {}", idx, lane_count));
133134
}
134135

135-
// FIXME implement this
136-
fx.tcx.sess.span_warn(
137-
fx.mir.span,
138-
"`simd_insert` is not yet implemented. Calling this function will panic.",
139-
);
140-
let val = crate::trap::trap_unimplemented_ret_value(fx, ret.layout(), "`simd_insert` is not yet implemented");
141-
ret.write_cvalue(fx, val);
136+
ret.write_cvalue(fx, base);
137+
let ret_lane = ret.place_field(fx, mir::Field::new(idx.try_into().unwrap()));
138+
ret_lane.write_cvalue(fx, val);
142139
};
143140

144141
simd_extract, (c v, o idx) {
@@ -233,5 +230,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
233230
validate_simd_type!(fx, intrinsic, span, x.layout().ty);
234231
simd_flt_binop!(fx, fmax(x, y) -> ret);
235232
};
233+
234+
// simd_fabs
235+
// simd_saturating_add
236+
// simd_bitmask
237+
// simd_select
238+
// simd_reduce_add_{,un}ordered
239+
// simd_rem
236240
}
237241
}

0 commit comments

Comments
 (0)