Fix simd_bswap for i8/u8
This commit is contained in:
parent
89acdae9f2
commit
77ed437de8
@ -2096,29 +2096,28 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
|
|||||||
sym::simd_cttz => "cttz",
|
sym::simd_cttz => "cttz",
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let llvm_intrinsic = &format!(
|
let int_size = in_elem.int_size_and_signed(bx.tcx()).0.bits();
|
||||||
"llvm.{}.v{}i{}",
|
let llvm_intrinsic = &format!("llvm.{}.v{}i{}", intrinsic_name, in_len, int_size,);
|
||||||
intrinsic_name,
|
|
||||||
in_len,
|
|
||||||
in_elem.int_size_and_signed(bx.tcx()).0.bits(),
|
|
||||||
);
|
|
||||||
|
|
||||||
return Ok(if matches!(name, sym::simd_ctlz | sym::simd_cttz) {
|
return if name == sym::simd_bswap && int_size == 8 {
|
||||||
|
// byte swap is no-op for i8/u8
|
||||||
|
Ok(args[0].immediate())
|
||||||
|
} else if matches!(name, sym::simd_ctlz | sym::simd_cttz) {
|
||||||
let fn_ty = bx.type_func(&[vec_ty, bx.type_i1()], vec_ty);
|
let fn_ty = bx.type_func(&[vec_ty, bx.type_i1()], vec_ty);
|
||||||
let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
|
let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
|
||||||
bx.call(
|
Ok(bx.call(
|
||||||
fn_ty,
|
fn_ty,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
f,
|
f,
|
||||||
&[args[0].immediate(), bx.const_int(bx.type_i1(), 0)],
|
&[args[0].immediate(), bx.const_int(bx.type_i1(), 0)],
|
||||||
None,
|
None,
|
||||||
)
|
))
|
||||||
} else {
|
} else {
|
||||||
let fn_ty = bx.type_func(&[vec_ty], vec_ty);
|
let fn_ty = bx.type_func(&[vec_ty], vec_ty);
|
||||||
let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
|
let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
|
||||||
bx.call(fn_ty, None, None, f, &[args[0].immediate()], None)
|
Ok(bx.call(fn_ty, None, None, f, &[args[0].immediate()], None))
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if name == sym::simd_arith_offset {
|
if name == sym::simd_arith_offset {
|
||||||
|
22
tests/ui/simd/intrinsic/generic-bswap-byte.rs
Normal file
22
tests/ui/simd/intrinsic/generic-bswap-byte.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// run-pass
|
||||||
|
#![feature(repr_simd, platform_intrinsics)]
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
|
#[repr(simd)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
struct i8x4([i8; 4]);
|
||||||
|
|
||||||
|
#[repr(simd)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
struct u8x4([u8; 4]);
|
||||||
|
|
||||||
|
extern "platform-intrinsic" {
|
||||||
|
fn simd_bswap<T>(x: T) -> T;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
unsafe {
|
||||||
|
assert_eq!(simd_bswap(i8x4([0, 1, 2, 3])).0, [0, 1, 2, 3]);
|
||||||
|
assert_eq!(simd_bswap(u8x4([0, 1, 2, 3])).0, [0, 1, 2, 3]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user