Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Sep 15, 2024
1 parent 7ad353c commit 21af303
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
3 changes: 3 additions & 0 deletions example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ unsafe fn test_simd() {
test_mm_insert_epi16();
test_mm_shuffle_epi8();

#[cfg(not(jit))]
test_mm_cmpestri();

test_mm256_shuffle_epi8();
Expand Down Expand Up @@ -437,6 +438,7 @@ unsafe fn test_mm_shuffle_epi8() {
// a bit difficult. Rather than `load` and mutate the __m128i,
// it is easier to memcpy the given string to a local slice with
// length 16 and `load` the local slice.
#[cfg(not(jit))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse4.2")]
unsafe fn str_to_m128i(s: &[u8]) -> __m128i {
Expand All @@ -446,6 +448,7 @@ unsafe fn str_to_m128i(s: &[u8]) -> __m128i {
_mm_loadu_si128(slice.as_ptr() as *const _)
}

#[cfg(not(jit))]
#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse4.2")]
unsafe fn test_mm_cmpestri() {
Expand Down
2 changes: 0 additions & 2 deletions src/intrinsics/llvm_x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,6 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
let b = b.load_scalar(fx);
let lb = lb.load_scalar(fx);

panic!();

let imm8 =
if let Some(imm8) = crate::constant::mir_operand_get_const_val(fx, &args[4].node) {
imm8
Expand Down
26 changes: 7 additions & 19 deletions src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
let val = codegen_operand(fx, &val.node);

// FIXME validate
let idx_const = if let Some(idx_const) =
crate::constant::mir_operand_get_const_val(fx, &idx.node)
{
idx_const
let idx_const = if let Some(idx_const) = idx.node.constant() {
crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap()
} else {
fx.tcx.dcx().span_fatal(span, "Index argument for `simd_insert` is not a constant");
};
Expand Down Expand Up @@ -304,22 +302,12 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
return;
}

let idx_const = if let Some(idx_const) =
crate::constant::mir_operand_get_const_val(fx, &idx.node)
{
idx_const
let idx_const = if let Some(idx_const) = idx.node.constant() {
crate::constant::eval_mir_constant(fx, idx_const).0.try_to_scalar_int().unwrap()
} else {
fx.tcx.dcx().span_warn(span, "Index argument for `simd_extract` is not a constant");
let trap_block = fx.bcx.create_block();
let true_ = fx.bcx.ins().iconst(types::I8, 1);
let ret_block = fx.get_block(target);
fx.bcx.ins().brif(true_, trap_block, &[], ret_block, &[]);
fx.bcx.switch_to_block(trap_block);
crate::trap::trap_unimplemented(
fx,
"Index argument for `simd_extract` is not a constant",
);
return;
fx.tcx
.dcx()
.span_fatal(span, "Index argument for `simd_extract` is not a constant");
};

let idx = idx_const.to_u32();
Expand Down

0 comments on commit 21af303

Please sign in to comment.