Skip to content

Commit 41b315a

Browse files
committed
Auto merge of #83271 - SparrowLii:simd_neg, r=Amanieu
Add simd_neg platform intrinsic Stdarch needs to add simd_neg to support the implementation of vneg neon instructions. Look [here](rust-lang/stdarch#1087)
2 parents eb9ec31 + b93590e commit 41b315a

File tree

7 files changed

+60
-17
lines changed

7 files changed

+60
-17
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,6 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
276276
// simd_bitmask
277277
// simd_select
278278
// simd_rem
279+
// simd_neg
279280
}
280281
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
16281628
out_elem
16291629
);
16301630
}
1631-
macro_rules! arith {
1631+
macro_rules! arith_binary {
16321632
($($name: ident: $($($p: ident),* => $call: ident),*;)*) => {
16331633
$(if name == sym::$name {
16341634
match in_elem.kind() {
@@ -1644,7 +1644,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
16441644
})*
16451645
}
16461646
}
1647-
arith! {
1647+
arith_binary! {
16481648
simd_add: Uint, Int => add, Float => fadd;
16491649
simd_sub: Uint, Int => sub, Float => fsub;
16501650
simd_mul: Uint, Int => mul, Float => fmul;
@@ -1659,6 +1659,25 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
16591659
simd_fmin: Float => minnum;
16601660

16611661
}
1662+
macro_rules! arith_unary {
1663+
($($name: ident: $($($p: ident),* => $call: ident),*;)*) => {
1664+
$(if name == sym::$name {
1665+
match in_elem.kind() {
1666+
$($(ty::$p(_))|* => {
1667+
return Ok(bx.$call(args[0].immediate()))
1668+
})*
1669+
_ => {},
1670+
}
1671+
require!(false,
1672+
"unsupported operation on `{}` with element `{}`",
1673+
in_ty,
1674+
in_elem)
1675+
})*
1676+
}
1677+
}
1678+
arith_unary! {
1679+
simd_neg: Int => neg, Float => fneg;
1680+
}
16621681

16631682
if name == sym::simd_saturating_add || name == sym::simd_saturating_sub {
16641683
let lhs = args[0].immediate();

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,7 @@ symbols! {
10811081
simd_lt,
10821082
simd_mul,
10831083
simd_ne,
1084+
simd_neg,
10841085
simd_or,
10851086
simd_reduce_add_ordered,
10861087
simd_reduce_add_unordered,

compiler/rustc_typeck/src/check/intrinsic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ pub fn check_platform_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>)
398398
| sym::simd_fpow
399399
| sym::simd_saturating_add
400400
| sym::simd_saturating_sub => (1, vec![param(0), param(0)], param(0)),
401+
sym::simd_neg => (1, vec![param(0)], param(0)),
401402
sym::simd_fsqrt
402403
| sym::simd_fsin
403404
| sym::simd_fcos

src/test/ui/simd-intrinsic/simd-intrinsic-generic-arithmetic.rs

+8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ extern "platform-intrinsic" {
2525
fn simd_and<T>(x: T, y: T) -> T;
2626
fn simd_or<T>(x: T, y: T) -> T;
2727
fn simd_xor<T>(x: T, y: T) -> T;
28+
29+
fn simd_neg<T>(x: T) -> T;
2830
}
2931

3032
fn main() {
@@ -60,6 +62,9 @@ fn main() {
6062
simd_xor(x, x);
6163
simd_xor(y, y);
6264

65+
simd_neg(x);
66+
simd_neg(z);
67+
6368

6469
simd_add(0, 0);
6570
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
@@ -80,6 +85,9 @@ fn main() {
8085
simd_xor(0, 0);
8186
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
8287

88+
simd_neg(0);
89+
//~^ ERROR expected SIMD input type, found non-SIMD `i32`
90+
8391

8492
simd_shl(z, z);
8593
//~^ ERROR unsupported operation on `f32x4` with element `f32`
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,93 @@
11
error[E0511]: invalid monomorphization of `simd_add` intrinsic: expected SIMD input type, found non-SIMD `i32`
2-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:64:9
2+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:69:9
33
|
44
LL | simd_add(0, 0);
55
| ^^^^^^^^^^^^^^
66

77
error[E0511]: invalid monomorphization of `simd_sub` intrinsic: expected SIMD input type, found non-SIMD `i32`
8-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:66:9
8+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:71:9
99
|
1010
LL | simd_sub(0, 0);
1111
| ^^^^^^^^^^^^^^
1212

1313
error[E0511]: invalid monomorphization of `simd_mul` intrinsic: expected SIMD input type, found non-SIMD `i32`
14-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:68:9
14+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:73:9
1515
|
1616
LL | simd_mul(0, 0);
1717
| ^^^^^^^^^^^^^^
1818

1919
error[E0511]: invalid monomorphization of `simd_div` intrinsic: expected SIMD input type, found non-SIMD `i32`
20-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:70:9
20+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:75:9
2121
|
2222
LL | simd_div(0, 0);
2323
| ^^^^^^^^^^^^^^
2424

2525
error[E0511]: invalid monomorphization of `simd_shl` intrinsic: expected SIMD input type, found non-SIMD `i32`
26-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:72:9
26+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:77:9
2727
|
2828
LL | simd_shl(0, 0);
2929
| ^^^^^^^^^^^^^^
3030

3131
error[E0511]: invalid monomorphization of `simd_shr` intrinsic: expected SIMD input type, found non-SIMD `i32`
32-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:74:9
32+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:79:9
3333
|
3434
LL | simd_shr(0, 0);
3535
| ^^^^^^^^^^^^^^
3636

3737
error[E0511]: invalid monomorphization of `simd_and` intrinsic: expected SIMD input type, found non-SIMD `i32`
38-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:76:9
38+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:81:9
3939
|
4040
LL | simd_and(0, 0);
4141
| ^^^^^^^^^^^^^^
4242

4343
error[E0511]: invalid monomorphization of `simd_or` intrinsic: expected SIMD input type, found non-SIMD `i32`
44-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:78:9
44+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:83:9
4545
|
4646
LL | simd_or(0, 0);
4747
| ^^^^^^^^^^^^^
4848

4949
error[E0511]: invalid monomorphization of `simd_xor` intrinsic: expected SIMD input type, found non-SIMD `i32`
50-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:80:9
50+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:85:9
5151
|
5252
LL | simd_xor(0, 0);
5353
| ^^^^^^^^^^^^^^
5454

55+
error[E0511]: invalid monomorphization of `simd_neg` intrinsic: expected SIMD input type, found non-SIMD `i32`
56+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:88:9
57+
|
58+
LL | simd_neg(0);
59+
| ^^^^^^^^^^^
60+
5561
error[E0511]: invalid monomorphization of `simd_shl` intrinsic: unsupported operation on `f32x4` with element `f32`
56-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:84:9
62+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:92:9
5763
|
5864
LL | simd_shl(z, z);
5965
| ^^^^^^^^^^^^^^
6066

6167
error[E0511]: invalid monomorphization of `simd_shr` intrinsic: unsupported operation on `f32x4` with element `f32`
62-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:86:9
68+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:94:9
6369
|
6470
LL | simd_shr(z, z);
6571
| ^^^^^^^^^^^^^^
6672

6773
error[E0511]: invalid monomorphization of `simd_and` intrinsic: unsupported operation on `f32x4` with element `f32`
68-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:88:9
74+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:96:9
6975
|
7076
LL | simd_and(z, z);
7177
| ^^^^^^^^^^^^^^
7278

7379
error[E0511]: invalid monomorphization of `simd_or` intrinsic: unsupported operation on `f32x4` with element `f32`
74-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:90:9
80+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:98:9
7581
|
7682
LL | simd_or(z, z);
7783
| ^^^^^^^^^^^^^
7884

7985
error[E0511]: invalid monomorphization of `simd_xor` intrinsic: unsupported operation on `f32x4` with element `f32`
80-
--> $DIR/simd-intrinsic-generic-arithmetic.rs:92:9
86+
--> $DIR/simd-intrinsic-generic-arithmetic.rs:100:9
8187
|
8288
LL | simd_xor(z, z);
8389
| ^^^^^^^^^^^^^^
8490

85-
error: aborting due to 14 previous errors
91+
error: aborting due to 15 previous errors
8692

8793
For more information about this error, try `rustc --explain E0511`.

src/test/ui/simd/simd-intrinsic-generic-arithmetic.rs

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ extern "platform-intrinsic" {
4545
fn simd_and<T>(x: T, y: T) -> T;
4646
fn simd_or<T>(x: T, y: T) -> T;
4747
fn simd_xor<T>(x: T, y: T) -> T;
48+
49+
fn simd_neg<T>(x: T) -> T;
4850
}
4951

5052
fn main() {
@@ -125,5 +127,10 @@ fn main() {
125127
all_eq_!(simd_xor(y1, y2), U32::<4>([3, 1, 7, 1]));
126128
all_eq_!(simd_xor(y2, y1), U32::<4>([3, 1, 7, 1]));
127129

130+
all_eq!(simd_neg(x1), i32x4(-1, -2, -3, -4));
131+
all_eq!(simd_neg(x2), i32x4(-2, -3, -4, -5));
132+
all_eq!(simd_neg(z1), f32x4(-1.0, -2.0, -3.0, -4.0));
133+
all_eq!(simd_neg(z2), f32x4(-2.0, -3.0, -4.0, -5.0));
134+
128135
}
129136
}

0 commit comments

Comments
 (0)