Skip to content

Commit bbf4508

Browse files
committed
Implement _mm_srai_epi* and _mm256_srai_epi*
1 parent 71cb045 commit bbf4508

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/intrinsics/llvm_x86.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,23 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
180180
_ => fx.bcx.ins().iconst(types::I32, 0),
181181
});
182182
}
183+
"llvm.x86.sse2.psrai.d" => {
184+
let (a, imm8) = match args {
185+
[a, imm8] => (a, imm8),
186+
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
187+
};
188+
let a = codegen_operand(fx, a);
189+
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8)
190+
.expect("llvm.x86.sse2.psrai.d imm8 not const");
191+
192+
simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8
193+
.try_to_bits(Size::from_bytes(4))
194+
.unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8))
195+
{
196+
imm8 if imm8 < 32 => fx.bcx.ins().sshr_imm(lane, i64::from(imm8 as u8)),
197+
_ => fx.bcx.ins().iconst(types::I32, 0),
198+
});
199+
}
183200
"llvm.x86.sse2.pslli.d" => {
184201
let (a, imm8) = match args {
185202
[a, imm8] => (a, imm8),
@@ -214,6 +231,23 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
214231
_ => fx.bcx.ins().iconst(types::I32, 0),
215232
});
216233
}
234+
"llvm.x86.sse2.psrai.w" => {
235+
let (a, imm8) = match args {
236+
[a, imm8] => (a, imm8),
237+
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
238+
};
239+
let a = codegen_operand(fx, a);
240+
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8)
241+
.expect("llvm.x86.sse2.psrai.d imm8 not const");
242+
243+
simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8
244+
.try_to_bits(Size::from_bytes(4))
245+
.unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8))
246+
{
247+
imm8 if imm8 < 16 => fx.bcx.ins().sshr_imm(lane, i64::from(imm8 as u8)),
248+
_ => fx.bcx.ins().iconst(types::I32, 0),
249+
});
250+
}
217251
"llvm.x86.sse2.pslli.w" => {
218252
let (a, imm8) = match args {
219253
[a, imm8] => (a, imm8),
@@ -248,6 +282,23 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
248282
_ => fx.bcx.ins().iconst(types::I32, 0),
249283
});
250284
}
285+
"llvm.x86.avx.psrai.d" => {
286+
let (a, imm8) = match args {
287+
[a, imm8] => (a, imm8),
288+
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
289+
};
290+
let a = codegen_operand(fx, a);
291+
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8)
292+
.expect("llvm.x86.avx.psrai.d imm8 not const");
293+
294+
simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8
295+
.try_to_bits(Size::from_bytes(4))
296+
.unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8))
297+
{
298+
imm8 if imm8 < 32 => fx.bcx.ins().sshr_imm(lane, i64::from(imm8 as u8)),
299+
_ => fx.bcx.ins().iconst(types::I32, 0),
300+
});
301+
}
251302
"llvm.x86.avx.pslli.d" => {
252303
let (a, imm8) = match args {
253304
[a, imm8] => (a, imm8),
@@ -282,6 +333,23 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
282333
_ => fx.bcx.ins().iconst(types::I32, 0),
283334
});
284335
}
336+
"llvm.x86.avx2.psrai.w" => {
337+
let (a, imm8) = match args {
338+
[a, imm8] => (a, imm8),
339+
_ => bug!("wrong number of args for intrinsic {intrinsic}"),
340+
};
341+
let a = codegen_operand(fx, a);
342+
let imm8 = crate::constant::mir_operand_get_const_val(fx, imm8)
343+
.expect("llvm.x86.avx.psrai.w imm8 not const");
344+
345+
simd_for_each_lane(fx, a, ret, &|fx, _lane_ty, _res_lane_ty, lane| match imm8
346+
.try_to_bits(Size::from_bytes(4))
347+
.unwrap_or_else(|| panic!("imm8 not scalar: {:?}", imm8))
348+
{
349+
imm8 if imm8 < 16 => fx.bcx.ins().sshr_imm(lane, i64::from(imm8 as u8)),
350+
_ => fx.bcx.ins().iconst(types::I32, 0),
351+
});
352+
}
285353
"llvm.x86.avx2.pslli.w" => {
286354
let (a, imm8) = match args {
287355
[a, imm8] => (a, imm8),

0 commit comments

Comments
 (0)