From 3ea0e6e3fbdc0bdd84a5669efec7b38c21f84f8e Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Thu, 27 Jul 2023 23:04:14 -0400 Subject: [PATCH 1/4] Add simd_bswap intrinsic --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 22 ++++++++++ .../rustc_hir_analysis/src/check/intrinsic.rs | 1 + compiler/rustc_span/src/symbol.rs | 1 + .../ui/simd/intrinsic/generic-arithmetic-2.rs | 7 +++ .../intrinsic/generic-arithmetic-2.stderr | 44 ++++++++++++------- .../simd/intrinsic/generic-arithmetic-pass.rs | 4 ++ 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 6df1b708ccd45..c30cb6801da69 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -2074,6 +2074,28 @@ fn generic_simd_intrinsic<'ll, 'tcx>( 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(|| { diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index e076b1fc68cc2..68c99c4f24eea 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -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 diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 54eb7bef5f205..445bcd58426cd 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1369,6 +1369,7 @@ symbols! { simd_arith_offset, simd_as, simd_bitmask, + simd_bswap, simd_cast, simd_cast_ptr, simd_ceil, diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs index 3576eed71ab50..310d5cab843be 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs @@ -27,6 +27,7 @@ extern "platform-intrinsic" { fn simd_xor(x: T, y: T) -> T; fn simd_neg(x: T) -> T; + fn simd_bswap(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` } } diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr index 0f0a7ea6652d0..efc6f05d39d02 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr @@ -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`. diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs index c507b8d31ecb4..ca3bae99fea41 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs @@ -47,6 +47,7 @@ extern "platform-intrinsic" { fn simd_xor(x: T, y: T) -> T; fn simd_neg(x: T) -> T; + fn simd_bswap(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])); + } } From 4c02b4cf4cea24028a37d8e24c1376f7e5db808a Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Thu, 27 Jul 2023 23:53:45 -0400 Subject: [PATCH 2/4] Add SIMD bitreverse, ctlz, cttz intrinsics --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 32 +++++++-- .../rustc_hir_analysis/src/check/intrinsic.rs | 3 + compiler/rustc_span/src/symbol.rs | 3 + .../ui/simd/intrinsic/generic-arithmetic-2.rs | 21 ++++++ .../intrinsic/generic-arithmetic-2.stderr | 72 ++++++++++++++----- .../simd/intrinsic/generic-arithmetic-pass.rs | 11 +++ 6 files changed, 117 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index c30cb6801da69..187214a93dd79 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -2074,7 +2074,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>( simd_neg: Int => neg, Float => fneg; } - if name == sym::simd_bswap { + // Unary integer intrinsics + if matches!(name, sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctlz | sym::simd_cttz) { let vec_ty = bx.cx.type_vector( match *in_elem.kind() { ty::Int(i) => bx.cx.type_int_from_ty(i), @@ -2088,12 +2089,29 @@ fn generic_simd_intrinsic<'ll, 'tcx>( }, 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); + let intrinsic_name = match name { + sym::simd_bswap => "bswap", + sym::simd_bitreverse => "bitreverse", + sym::simd_ctlz => "ctlz", + sym::simd_cttz => "cttz", + _ => unreachable!(), + }; + let llvm_intrinsic = &format!( + "llvm.{}.v{}i{}", + 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) { + let fn_ty = bx.type_func(&[vec_ty, bx.type_bool()], vec_ty); + let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); + bx.call(fn_ty, None, None, f, &[args[0].immediate(), bx.const_bool(false)], None) + } else { + let fn_ty = bx.type_func(&[vec_ty], vec_ty); + let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); + bx.call(fn_ty, None, None, f, &[args[0].immediate()], None) + }); } if name == sym::simd_arith_offset { diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 68c99c4f24eea..064021b1ea429 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -522,6 +522,9 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) sym::simd_arith_offset => (2, vec![param(0), param(1)], param(0)), sym::simd_neg | sym::simd_bswap + | sym::simd_bitreverse + | sym::simd_ctlz + | sym::simd_cttz | sym::simd_fsqrt | sym::simd_fsin | sym::simd_fcos diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 445bcd58426cd..35f8b99ffb27f 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1369,10 +1369,13 @@ symbols! { simd_arith_offset, simd_as, simd_bitmask, + simd_bitreverse, simd_bswap, simd_cast, simd_cast_ptr, simd_ceil, + simd_ctlz, + simd_cttz, simd_div, simd_eq, simd_expose_addr, diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs index 310d5cab843be..62fb5238bbd0f 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.rs @@ -28,6 +28,9 @@ extern "platform-intrinsic" { fn simd_neg(x: T) -> T; fn simd_bswap(x: T) -> T; + fn simd_bitreverse(x: T) -> T; + fn simd_ctlz(x: T) -> T; + fn simd_cttz(x: T) -> T; } fn main() { @@ -67,6 +70,12 @@ fn main() { simd_neg(z); simd_bswap(x); simd_bswap(y); + simd_bitreverse(x); + simd_bitreverse(y); + simd_ctlz(x); + simd_ctlz(y); + simd_cttz(x); + simd_cttz(y); simd_add(0, 0); @@ -92,6 +101,12 @@ fn main() { //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_bswap(0); //~^ ERROR expected SIMD input type, found non-SIMD `i32` + simd_bitreverse(0); + //~^ ERROR expected SIMD input type, found non-SIMD `i32` + simd_ctlz(0); + //~^ ERROR expected SIMD input type, found non-SIMD `i32` + simd_cttz(0); + //~^ ERROR expected SIMD input type, found non-SIMD `i32` simd_shl(z, z); @@ -105,6 +120,12 @@ fn main() { simd_xor(z, z); //~^ ERROR unsupported operation on `f32x4` with element `f32` simd_bswap(z); +//~^ ERROR unsupported operation on `f32x4` with element `f32` + simd_bitreverse(z); +//~^ ERROR unsupported operation on `f32x4` with element `f32` + simd_ctlz(z); +//~^ ERROR unsupported operation on `f32x4` with element `f32` + simd_cttz(z); //~^ ERROR unsupported operation on `f32x4` with element `f32` } } diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr index efc6f05d39d02..db26f3417c95e 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr +++ b/tests/ui/simd/intrinsic/generic-arithmetic-2.stderr @@ -1,105 +1,141 @@ error[E0511]: invalid monomorphization of `simd_add` intrinsic: expected SIMD input type, found non-SIMD `i32` - --> $DIR/generic-arithmetic-2.rs:72:9 + --> $DIR/generic-arithmetic-2.rs:81: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:74:9 + --> $DIR/generic-arithmetic-2.rs:83: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:76:9 + --> $DIR/generic-arithmetic-2.rs:85: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:78:9 + --> $DIR/generic-arithmetic-2.rs:87: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:80:9 + --> $DIR/generic-arithmetic-2.rs:89: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:82:9 + --> $DIR/generic-arithmetic-2.rs:91: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:84:9 + --> $DIR/generic-arithmetic-2.rs:93: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:86:9 + --> $DIR/generic-arithmetic-2.rs:95: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:88:9 + --> $DIR/generic-arithmetic-2.rs:97: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:91:9 + --> $DIR/generic-arithmetic-2.rs:100: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 + --> $DIR/generic-arithmetic-2.rs:102:9 | LL | simd_bswap(0); | ^^^^^^^^^^^^^ +error[E0511]: invalid monomorphization of `simd_bitreverse` intrinsic: expected SIMD input type, found non-SIMD `i32` + --> $DIR/generic-arithmetic-2.rs:104:9 + | +LL | simd_bitreverse(0); + | ^^^^^^^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_ctlz` intrinsic: expected SIMD input type, found non-SIMD `i32` + --> $DIR/generic-arithmetic-2.rs:106:9 + | +LL | simd_ctlz(0); + | ^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_cttz` intrinsic: expected SIMD input type, found non-SIMD `i32` + --> $DIR/generic-arithmetic-2.rs:108:9 + | +LL | simd_cttz(0); + | ^^^^^^^^^^^^ + error[E0511]: invalid monomorphization of `simd_shl` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:97:9 + --> $DIR/generic-arithmetic-2.rs:112: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:99:9 + --> $DIR/generic-arithmetic-2.rs:114: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:101:9 + --> $DIR/generic-arithmetic-2.rs:116: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:103:9 + --> $DIR/generic-arithmetic-2.rs:118: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:105:9 + --> $DIR/generic-arithmetic-2.rs:120:9 | LL | simd_xor(z, z); | ^^^^^^^^^^^^^^ error[E0511]: invalid monomorphization of `simd_bswap` intrinsic: unsupported operation on `f32x4` with element `f32` - --> $DIR/generic-arithmetic-2.rs:107:9 + --> $DIR/generic-arithmetic-2.rs:122:9 | LL | simd_bswap(z); | ^^^^^^^^^^^^^ -error: aborting due to 17 previous errors +error[E0511]: invalid monomorphization of `simd_bitreverse` intrinsic: unsupported operation on `f32x4` with element `f32` + --> $DIR/generic-arithmetic-2.rs:124:9 + | +LL | simd_bitreverse(z); + | ^^^^^^^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_ctlz` intrinsic: unsupported operation on `f32x4` with element `f32` + --> $DIR/generic-arithmetic-2.rs:126:9 + | +LL | simd_ctlz(z); + | ^^^^^^^^^^^^ + +error[E0511]: invalid monomorphization of `simd_cttz` intrinsic: unsupported operation on `f32x4` with element `f32` + --> $DIR/generic-arithmetic-2.rs:128:9 + | +LL | simd_cttz(z); + | ^^^^^^^^^^^^ + +error: aborting due to 23 previous errors For more information about this error, try `rustc --explain E0511`. diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs index ca3bae99fea41..1168e6aae0f2f 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs @@ -48,6 +48,9 @@ extern "platform-intrinsic" { fn simd_neg(x: T) -> T; fn simd_bswap(x: T) -> T; + fn simd_bitreverse(x: T) -> T; + fn simd_ctlz(x: T) -> T; + fn simd_cttz(x: T) -> T; } fn main() { @@ -136,5 +139,13 @@ fn main() { all_eq!(simd_bswap(x1), i32x4(0x01000000, 0x02000000, 0x03000000, 0x04000000)); all_eq_!(simd_bswap(y1), U32::<4>([0x01000000, 0x02000000, 0x03000000, 0x04000000])); + all_eq!(simd_bitreverse(x1), i32x4(0x80000000u32 as i32, 0x40000000, 0xc0000000u32 as i32, 0x20000000)); + all_eq_!(simd_bitreverse(y1), U32::<4>([0x80000000, 0x40000000, 0xc0000000, 0x20000000])); + + all_eq!(simd_ctlz(x1), i32x4(31, 30, 30, 29)); + all_eq_!(simd_ctlz(y1), U32::<4>([31, 30, 30, 29])); + + all_eq!(simd_cttz(x1), i32x4(0, 1, 0, 2)); + all_eq_!(simd_cttz(y1), U32::<4>([0, 1, 0, 2])); } } From 4709ca2bed491523c06e5b674822a965e3649fea Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Fri, 28 Jul 2023 00:09:04 -0400 Subject: [PATCH 3/4] Format test --- .../simd/intrinsic/generic-arithmetic-pass.rs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs index 1168e6aae0f2f..f021ee4710a93 100644 --- a/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs +++ b/tests/ui/simd/intrinsic/generic-arithmetic-pass.rs @@ -1,8 +1,6 @@ // run-pass #![allow(non_camel_case_types)] - // ignore-emscripten FIXME(#45351) hits an LLVM assert - #![feature(repr_simd, platform_intrinsics)] #[repr(simd)] @@ -22,7 +20,7 @@ macro_rules! all_eq { let a = $a; let b = $b; assert!(a.0 == b.0 && a.1 == b.1 && a.2 == b.2 && a.3 == b.3); - }} + }}; } macro_rules! all_eq_ { @@ -30,10 +28,9 @@ macro_rules! all_eq_ { let a = $a; let b = $b; assert!(a.0 == b.0); - }} + }}; } - extern "platform-intrinsic" { fn simd_add(x: T, y: T) -> T; fn simd_sub(x: T, y: T) -> T; @@ -88,8 +85,8 @@ fn main() { all_eq_!(simd_div(y1, y1), U32::<4>([1, 1, 1, 1])); all_eq_!(simd_div(U32::<4>([2, 4, 6, 8]), U32::<4>([2, 2, 2, 2])), y1); all_eq!(simd_div(z1, z1), f32x4(1.0, 1.0, 1.0, 1.0)); - all_eq!(simd_div(z1, z2), f32x4(1.0/2.0, 2.0/3.0, 3.0/4.0, 4.0/5.0)); - all_eq!(simd_div(z2, z1), f32x4(2.0/1.0, 3.0/2.0, 4.0/3.0, 5.0/4.0)); + all_eq!(simd_div(z1, z2), f32x4(1.0 / 2.0, 2.0 / 3.0, 3.0 / 4.0, 4.0 / 5.0)); + all_eq!(simd_div(z2, z1), f32x4(2.0 / 1.0, 3.0 / 2.0, 4.0 / 3.0, 5.0 / 4.0)); all_eq!(simd_rem(x1, x1), i32x4(0, 0, 0, 0)); all_eq!(simd_rem(x2, x1), i32x4(0, 1, 1, 1)); @@ -113,8 +110,10 @@ fn main() { // ensure we get logical vs. arithmetic shifts correct let (a, b, c, d) = (-12, -123, -1234, -12345); all_eq!(simd_shr(i32x4(a, b, c, d), x1), i32x4(a >> 1, b >> 2, c >> 3, d >> 4)); - all_eq_!(simd_shr(U32::<4>([a as u32, b as u32, c as u32, d as u32]), y1), - U32::<4>([(a as u32) >> 1, (b as u32) >> 2, (c as u32) >> 3, (d as u32) >> 4])); + all_eq_!( + simd_shr(U32::<4>([a as u32, b as u32, c as u32, d as u32]), y1), + U32::<4>([(a as u32) >> 1, (b as u32) >> 2, (c as u32) >> 3, (d as u32) >> 4]) + ); all_eq!(simd_and(x1, x2), i32x4(0, 2, 0, 4)); all_eq!(simd_and(x2, x1), i32x4(0, 2, 0, 4)); @@ -139,7 +138,10 @@ fn main() { all_eq!(simd_bswap(x1), i32x4(0x01000000, 0x02000000, 0x03000000, 0x04000000)); all_eq_!(simd_bswap(y1), U32::<4>([0x01000000, 0x02000000, 0x03000000, 0x04000000])); - all_eq!(simd_bitreverse(x1), i32x4(0x80000000u32 as i32, 0x40000000, 0xc0000000u32 as i32, 0x20000000)); + all_eq!( + simd_bitreverse(x1), + i32x4(0x80000000u32 as i32, 0x40000000, 0xc0000000u32 as i32, 0x20000000) + ); all_eq_!(simd_bitreverse(y1), U32::<4>([0x80000000, 0x40000000, 0xc0000000, 0x20000000])); all_eq!(simd_ctlz(x1), i32x4(31, 30, 30, 29)); From ce4a48f41f4555ad56be404e2e28c86ed4fea4c6 Mon Sep 17 00:00:00 2001 From: Caleb Zulawski Date: Fri, 28 Jul 2023 09:46:16 -0400 Subject: [PATCH 4/4] Use i1 instead of bool --- compiler/rustc_codegen_llvm/src/intrinsic.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 187214a93dd79..623c08ce86b8f 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -2104,9 +2104,16 @@ fn generic_simd_intrinsic<'ll, 'tcx>( ); return Ok(if matches!(name, sym::simd_ctlz | sym::simd_cttz) { - let fn_ty = bx.type_func(&[vec_ty, bx.type_bool()], 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); - bx.call(fn_ty, None, None, f, &[args[0].immediate(), bx.const_bool(false)], None) + bx.call( + fn_ty, + None, + None, + f, + &[args[0].immediate(), bx.const_int(bx.type_i1(), 0)], + None, + ) } else { let fn_ty = bx.type_func(&[vec_ty], vec_ty); let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty);