Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 78e0525

Browse files
committed
[WIP] simd_shuffle support
1 parent 1a26891 commit 78e0525

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/intrinsics.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ fn lane_type_and_count<'tcx>(
121121
layout: TyLayout<'tcx>,
122122
intrinsic: &str,
123123
) -> (TyLayout<'tcx>, usize) {
124+
assert!(layout.ty.is_simd());
124125
let lane_count = match layout.fields {
125126
layout::FieldPlacement::Array { stride: _, count } => usize::try_from(count).unwrap(),
126127
_ => panic!("Non vector type {:?} passed to or returned from simd_* intrinsic {}", layout.ty, intrinsic),
@@ -805,6 +806,26 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
805806
simd_cmp!(fx, intrinsic, UnsignedGreaterThanOrEqual|SignedGreaterThanOrEqual(x, y) -> ret);
806807
};
807808

809+
// simd_shuffle32<T, U>(x: T, y: T, idx: [u32; 32]) -> U
810+
_ if intrinsic.starts_with("simd_shuffle"), (c x, c y, c idx) {
811+
let n: usize = intrinsic["simd_shuffle".len()..].parse().unwrap();
812+
813+
assert_eq!(x.layout(), y.layout());
814+
let layout = x.layout();
815+
816+
let (lane_type, lane_count) = lane_type_and_count(fx, layout, intrinsic);
817+
let (ret_lane_type, ret_lane_count) = lane_type_and_count(fx, ret.layout(), intrinsic);
818+
819+
assert_eq!(lane_type, ret_lane_type);
820+
assert_eq!(n, ret_lane_count);
821+
822+
let total_len = lane_count * 2;
823+
824+
// TODO get shuffle indices
825+
fx.tcx.sess.warn("simd_shuffle* not yet implemented");
826+
crate::trap::trap_unimplemented(fx, "simd_shuffle* not yet implemented");
827+
};
828+
808829
simd_add, (c x, c y) {
809830
simd_binop!(fx, intrinsic, iadd(x, y) -> ret);
810831
};
@@ -832,7 +853,7 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
832853
simd_or, (c x, c y) {
833854
simd_binop!(fx, intrinsic, bor(x, y) -> ret);
834855
};
835-
simd_bxor, (c x, c y) {
856+
simd_xor, (c x, c y) {
836857
simd_binop!(fx, intrinsic, bxor(x, y) -> ret);
837858
};
838859

src/llvm_intrinsics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ pub fn codegen_llvm_intrinsic_call<'a, 'tcx: 'a>(
1919
trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
2020
}
2121
}
22+
23+
// llvm.x86.sse2.pmovmskb.128
24+
// llvm.x86.avx2.vperm2i128
25+
// llvm.x86.ssse3.pshuf.b.128
26+
// llvm.x86.avx2.pshuf.b
27+
// llvm.x86.avx2.pmovmskb
28+
// llvm.x86.avx2.psrli.w
29+
// llvm.x86.sse2.psrli.w

0 commit comments

Comments
 (0)