Add simd_bswap intrinsic
This commit is contained in:
parent
0eb5efc7ae
commit
3ea0e6e3fb
@ -2074,6 +2074,28 @@ macro_rules! arith_unary {
|
||||
simd_neg: Int => neg, Float => fneg;
|
||||
}
|
||||
|
||||
if name == sym::simd_bswap {
|
||||
let vec_ty = bx.cx.type_vector(
|
||||
match *in_elem.kind() {
|
||||
ty::Int(i) => bx.cx.type_int_from_ty(i),
|
||||
ty::Uint(i) => bx.cx.type_uint_from_ty(i),
|
||||
_ => return_error!(InvalidMonomorphization::UnsupportedOperation {
|
||||
span,
|
||||
name,
|
||||
in_ty,
|
||||
in_elem
|
||||
}),
|
||||
},
|
||||
in_len as u64,
|
||||
);
|
||||
let llvm_intrinsic =
|
||||
&format!("llvm.bswap.v{}i{}", in_len, in_elem.int_size_and_signed(bx.tcx()).0.bits(),);
|
||||
let fn_ty = bx.type_func(&[vec_ty], vec_ty);
|
||||
let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);
|
||||
let v = bx.call(fn_ty, None, None, f, &[args[0].immediate()], None);
|
||||
return Ok(v);
|
||||
}
|
||||
|
||||
if name == sym::simd_arith_offset {
|
||||
// This also checks that the first operand is a ptr type.
|
||||
let pointee = in_elem.builtin_deref(true).unwrap_or_else(|| {
|
||||
|
@ -521,6 +521,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
|
||||
| sym::simd_saturating_sub => (1, vec![param(0), param(0)], param(0)),
|
||||
sym::simd_arith_offset => (2, vec![param(0), param(1)], param(0)),
|
||||
sym::simd_neg
|
||||
| sym::simd_bswap
|
||||
| sym::simd_fsqrt
|
||||
| sym::simd_fsin
|
||||
| sym::simd_fcos
|
||||
|
@ -1369,6 +1369,7 @@
|
||||
simd_arith_offset,
|
||||
simd_as,
|
||||
simd_bitmask,
|
||||
simd_bswap,
|
||||
simd_cast,
|
||||
simd_cast_ptr,
|
||||
simd_ceil,
|
||||
|
@ -27,6 +27,7 @@
|
||||
fn simd_xor<T>(x: T, y: T) -> T;
|
||||
|
||||
fn simd_neg<T>(x: T) -> T;
|
||||
fn simd_bswap<T>(x: T) -> T;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -64,6 +65,8 @@ fn main() {
|
||||
|
||||
simd_neg(x);
|
||||
simd_neg(z);
|
||||
simd_bswap(x);
|
||||
simd_bswap(y);
|
||||
|
||||
|
||||
simd_add(0, 0);
|
||||
@ -87,6 +90,8 @@ fn main() {
|
||||
|
||||
simd_neg(0);
|
||||
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
|
||||
simd_bswap(0);
|
||||
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
|
||||
|
||||
|
||||
simd_shl(z, z);
|
||||
@ -98,6 +103,8 @@ fn main() {
|
||||
simd_or(z, z);
|
||||
//~^ ERROR unsupported operation on `f32x4` with element `f32`
|
||||
simd_xor(z, z);
|
||||
//~^ ERROR unsupported operation on `f32x4` with element `f32`
|
||||
simd_bswap(z);
|
||||
//~^ ERROR unsupported operation on `f32x4` with element `f32`
|
||||
}
|
||||
}
|
||||
|
@ -1,93 +1,105 @@
|
||||
error[E0511]: invalid monomorphization of `simd_add` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:69:9
|
||||
--> $DIR/generic-arithmetic-2.rs:72:9
|
||||
|
|
||||
LL | simd_add(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_sub` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:71:9
|
||||
--> $DIR/generic-arithmetic-2.rs:74:9
|
||||
|
|
||||
LL | simd_sub(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_mul` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:73:9
|
||||
--> $DIR/generic-arithmetic-2.rs:76:9
|
||||
|
|
||||
LL | simd_mul(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_div` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:75:9
|
||||
--> $DIR/generic-arithmetic-2.rs:78:9
|
||||
|
|
||||
LL | simd_div(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_shl` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:77:9
|
||||
--> $DIR/generic-arithmetic-2.rs:80:9
|
||||
|
|
||||
LL | simd_shl(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_shr` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:79:9
|
||||
--> $DIR/generic-arithmetic-2.rs:82:9
|
||||
|
|
||||
LL | simd_shr(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_and` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:81:9
|
||||
--> $DIR/generic-arithmetic-2.rs:84:9
|
||||
|
|
||||
LL | simd_and(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_or` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:83:9
|
||||
--> $DIR/generic-arithmetic-2.rs:86:9
|
||||
|
|
||||
LL | simd_or(0, 0);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_xor` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:85:9
|
||||
--> $DIR/generic-arithmetic-2.rs:88:9
|
||||
|
|
||||
LL | simd_xor(0, 0);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_neg` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:88:9
|
||||
--> $DIR/generic-arithmetic-2.rs:91:9
|
||||
|
|
||||
LL | simd_neg(0);
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_bswap` intrinsic: expected SIMD input type, found non-SIMD `i32`
|
||||
--> $DIR/generic-arithmetic-2.rs:93:9
|
||||
|
|
||||
LL | simd_bswap(0);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_shl` intrinsic: unsupported operation on `f32x4` with element `f32`
|
||||
--> $DIR/generic-arithmetic-2.rs:92:9
|
||||
--> $DIR/generic-arithmetic-2.rs:97:9
|
||||
|
|
||||
LL | simd_shl(z, z);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_shr` intrinsic: unsupported operation on `f32x4` with element `f32`
|
||||
--> $DIR/generic-arithmetic-2.rs:94:9
|
||||
--> $DIR/generic-arithmetic-2.rs:99:9
|
||||
|
|
||||
LL | simd_shr(z, z);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_and` intrinsic: unsupported operation on `f32x4` with element `f32`
|
||||
--> $DIR/generic-arithmetic-2.rs:96:9
|
||||
--> $DIR/generic-arithmetic-2.rs:101:9
|
||||
|
|
||||
LL | simd_and(z, z);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_or` intrinsic: unsupported operation on `f32x4` with element `f32`
|
||||
--> $DIR/generic-arithmetic-2.rs:98:9
|
||||
--> $DIR/generic-arithmetic-2.rs:103:9
|
||||
|
|
||||
LL | simd_or(z, z);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error[E0511]: invalid monomorphization of `simd_xor` intrinsic: unsupported operation on `f32x4` with element `f32`
|
||||
--> $DIR/generic-arithmetic-2.rs:100:9
|
||||
--> $DIR/generic-arithmetic-2.rs:105:9
|
||||
|
|
||||
LL | simd_xor(z, z);
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error[E0511]: invalid monomorphization of `simd_bswap` intrinsic: unsupported operation on `f32x4` with element `f32`
|
||||
--> $DIR/generic-arithmetic-2.rs:107:9
|
||||
|
|
||||
LL | simd_bswap(z);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 17 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0511`.
|
||||
|
@ -47,6 +47,7 @@ macro_rules! all_eq_ {
|
||||
fn simd_xor<T>(x: T, y: T) -> T;
|
||||
|
||||
fn simd_neg<T>(x: T) -> T;
|
||||
fn simd_bswap<T>(x: T) -> T;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@ -132,5 +133,8 @@ fn main() {
|
||||
all_eq!(simd_neg(z1), f32x4(-1.0, -2.0, -3.0, -4.0));
|
||||
all_eq!(simd_neg(z2), f32x4(-2.0, -3.0, -4.0, -5.0));
|
||||
|
||||
all_eq!(simd_bswap(x1), i32x4(0x01000000, 0x02000000, 0x03000000, 0x04000000));
|
||||
all_eq_!(simd_bswap(y1), U32::<4>([0x01000000, 0x02000000, 0x03000000, 0x04000000]));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user