Skip to content

Commit b01b28f

Browse files
authored
Add #[rustc_args_required_const] annotations (#319)
Support isn't quite in nightly to make this work yet, but using a local build this gets everything passing again! This also implements native verification that we have the attribute in the right place
1 parent 9873942 commit b01b28f

File tree

16 files changed

+245
-34
lines changed

16 files changed

+245
-34
lines changed

coresimd/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#![feature(const_fn, link_llvm_intrinsics, platform_intrinsics, repr_simd,
1515
simd_ffi, target_feature, cfg_target_feature, i128_type, asm,
1616
integer_atomics, stmt_expr_attributes, core_intrinsics,
17-
crate_in_paths)]
18-
#![cfg_attr(test, feature(proc_macro, test, attr_literals, abi_vectorcall))]
17+
crate_in_paths, attr_literals, rustc_attrs)]
18+
#![cfg_attr(test, feature(proc_macro, test, abi_vectorcall))]
1919
#![cfg_attr(feature = "cargo-clippy",
2020
allow(inline_always, too_many_arguments, cast_sign_loss,
2121
cast_lossless, cast_possible_wrap,

coresimd/src/x86/i586/avx.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub unsafe fn _mm256_or_ps(a: __m256, b: __m256) -> __m256 {
9696
#[inline]
9797
#[target_feature(enable = "avx")]
9898
#[cfg_attr(test, assert_instr(vshufpd, imm8 = 0x1))]
99+
#[rustc_args_required_const(2)]
99100
pub unsafe fn _mm256_shuffle_pd(a: __m256d, b: __m256d, imm8: i32) -> __m256d {
100101
let imm8 = (imm8 & 0xFF) as u8;
101102
macro_rules! shuffle4 {
@@ -138,6 +139,7 @@ pub unsafe fn _mm256_shuffle_pd(a: __m256d, b: __m256d, imm8: i32) -> __m256d {
138139
#[inline]
139140
#[target_feature(enable = "avx")]
140141
#[cfg_attr(test, assert_instr(vshufps, imm8 = 0x0))]
142+
#[rustc_args_required_const(2)]
141143
pub unsafe fn _mm256_shuffle_ps(a: __m256, b: __m256, imm8: i32) -> __m256 {
142144
let imm8 = (imm8 & 0xFF) as u8;
143145
macro_rules! shuffle4 {
@@ -330,6 +332,7 @@ pub unsafe fn _mm256_div_pd(a: __m256d, b: __m256d) -> __m256d {
330332
#[inline]
331333
#[target_feature(enable = "avx")]
332334
#[cfg_attr(test, assert_instr(vroundpd, b = 0x3))]
335+
#[rustc_args_required_const(1)]
333336
pub unsafe fn _mm256_round_pd(a: __m256d, b: i32) -> __m256d {
334337
macro_rules! call {
335338
($imm8:expr) => { roundpd256(a, $imm8) }
@@ -369,6 +372,7 @@ pub unsafe fn _mm256_floor_pd(a: __m256d) -> __m256d {
369372
#[inline]
370373
#[target_feature(enable = "avx")]
371374
#[cfg_attr(test, assert_instr(vroundps, b = 0x00))]
375+
#[rustc_args_required_const(1)]
372376
pub unsafe fn _mm256_round_ps(a: __m256, b: i32) -> __m256 {
373377
macro_rules! call {
374378
($imm8:expr) => {
@@ -419,6 +423,7 @@ pub unsafe fn _mm256_sqrt_pd(a: __m256d) -> __m256d {
419423
#[inline]
420424
#[target_feature(enable = "avx")]
421425
#[cfg_attr(test, assert_instr(vblendpd, imm8 = 9))]
426+
#[rustc_args_required_const(2)]
422427
pub unsafe fn _mm256_blend_pd(a: __m256d, b: __m256d, imm8: i32) -> __m256d {
423428
let imm8 = (imm8 & 0xFF) as u8;
424429
macro_rules! blend4 {
@@ -461,6 +466,7 @@ pub unsafe fn _mm256_blend_pd(a: __m256d, b: __m256d, imm8: i32) -> __m256d {
461466
#[inline]
462467
#[target_feature(enable = "avx")]
463468
#[cfg_attr(test, assert_instr(vblendps, imm8 = 9))]
469+
#[rustc_args_required_const(2)]
464470
pub unsafe fn _mm256_blend_ps(a: __m256, b: __m256, imm8: i32) -> __m256 {
465471
let imm8 = (imm8 & 0xFF) as u8;
466472
macro_rules! blend4 {
@@ -531,6 +537,7 @@ pub unsafe fn _mm256_blendv_ps(a: __m256, b: __m256, c: __m256) -> __m256 {
531537
#[inline]
532538
#[target_feature(enable = "avx")]
533539
#[cfg_attr(test, assert_instr(vdpps, imm8 = 0x0))]
540+
#[rustc_args_required_const(2)]
534541
pub unsafe fn _mm256_dp_ps(a: __m256, b: __m256, imm8: i32) -> __m256 {
535542
macro_rules! call {
536543
($imm8:expr) => { vdpps(a, b, $imm8) }
@@ -678,6 +685,7 @@ pub const _CMP_TRUE_US: i32 = 0x1f;
678685
#[inline]
679686
#[target_feature(enable = "avx,sse2")]
680687
#[cfg_attr(test, assert_instr(vcmpeqpd, imm8 = 0))] // TODO Validate vcmppd
688+
#[rustc_args_required_const(2)]
681689
pub unsafe fn _mm_cmp_pd(a: __m128d, b: __m128d, imm8: i32) -> __m128d {
682690
macro_rules! call {
683691
($imm8:expr) => { vcmppd(a, b, $imm8) }
@@ -691,6 +699,7 @@ pub unsafe fn _mm_cmp_pd(a: __m128d, b: __m128d, imm8: i32) -> __m128d {
691699
#[inline]
692700
#[target_feature(enable = "avx")]
693701
#[cfg_attr(test, assert_instr(vcmpeqpd, imm8 = 0))] // TODO Validate vcmppd
702+
#[rustc_args_required_const(2)]
694703
pub unsafe fn _mm256_cmp_pd(a: __m256d, b: __m256d, imm8: i32) -> __m256d {
695704
macro_rules! call {
696705
($imm8:expr) => { vcmppd256(a, b, $imm8) }
@@ -704,6 +713,7 @@ pub unsafe fn _mm256_cmp_pd(a: __m256d, b: __m256d, imm8: i32) -> __m256d {
704713
#[inline]
705714
#[target_feature(enable = "avx,sse")]
706715
#[cfg_attr(test, assert_instr(vcmpeqps, imm8 = 0))] // TODO Validate vcmpps
716+
#[rustc_args_required_const(2)]
707717
pub unsafe fn _mm_cmp_ps(a: __m128, b: __m128, imm8: i32) -> __m128 {
708718
macro_rules! call {
709719
($imm8:expr) => { vcmpps(a, b, $imm8) }
@@ -717,6 +727,7 @@ pub unsafe fn _mm_cmp_ps(a: __m128, b: __m128, imm8: i32) -> __m128 {
717727
#[inline]
718728
#[target_feature(enable = "avx")]
719729
#[cfg_attr(test, assert_instr(vcmpeqps, imm8 = 0))] // TODO Validate vcmpps
730+
#[rustc_args_required_const(2)]
720731
pub unsafe fn _mm256_cmp_ps(a: __m256, b: __m256, imm8: i32) -> __m256 {
721732
macro_rules! call {
722733
($imm8:expr) => { vcmpps256(a, b, $imm8) }
@@ -732,6 +743,7 @@ pub unsafe fn _mm256_cmp_ps(a: __m256, b: __m256, imm8: i32) -> __m256 {
732743
#[inline]
733744
#[target_feature(enable = "avx,sse2")]
734745
#[cfg_attr(test, assert_instr(vcmpeqsd, imm8 = 0))] // TODO Validate vcmpsd
746+
#[rustc_args_required_const(2)]
735747
pub unsafe fn _mm_cmp_sd(a: __m128d, b: __m128d, imm8: i32) -> __m128d {
736748
macro_rules! call {
737749
($imm8:expr) => { vcmpsd(a, b, $imm8) }
@@ -747,6 +759,7 @@ pub unsafe fn _mm_cmp_sd(a: __m128d, b: __m128d, imm8: i32) -> __m128d {
747759
#[inline]
748760
#[target_feature(enable = "avx,sse")]
749761
#[cfg_attr(test, assert_instr(vcmpeqss, imm8 = 0))] // TODO Validate vcmpss
762+
#[rustc_args_required_const(2)]
750763
pub unsafe fn _mm_cmp_ss(a: __m128, b: __m128, imm8: i32) -> __m128 {
751764
macro_rules! call {
752765
($imm8:expr) => { vcmpss(a, b, $imm8) }
@@ -830,7 +843,8 @@ pub unsafe fn _mm256_cvttps_epi32(a: __m256) -> __m256i {
830843
/// floating-point elements) from `a`, selected with `imm8`.
831844
#[inline]
832845
#[target_feature(enable = "avx")]
833-
#[cfg_attr(test, assert_instr(vextractf128))]
846+
#[cfg_attr(test, assert_instr(vextractf128, imm8 = 1))]
847+
#[rustc_args_required_const(1)]
834848
pub unsafe fn _mm256_extractf128_ps(a: __m256, imm8: i32) -> __m128 {
835849
match imm8 & 1 {
836850
0 => simd_shuffle4(a, _mm256_undefined_ps(), [0, 1, 2, 3]),
@@ -842,7 +856,8 @@ pub unsafe fn _mm256_extractf128_ps(a: __m256, imm8: i32) -> __m128 {
842856
/// floating-point elements) from `a`, selected with `imm8`.
843857
#[inline]
844858
#[target_feature(enable = "avx")]
845-
#[cfg_attr(test, assert_instr(vextractf128))]
859+
#[cfg_attr(test, assert_instr(vextractf128, imm8 = 1))]
860+
#[rustc_args_required_const(1)]
846861
pub unsafe fn _mm256_extractf128_pd(a: __m256d, imm8: i32) -> __m128d {
847862
match imm8 & 1 {
848863
0 => simd_shuffle2(a, _mm256_undefined_pd(), [0, 1]),
@@ -853,7 +868,8 @@ pub unsafe fn _mm256_extractf128_pd(a: __m256d, imm8: i32) -> __m128d {
853868
/// Extract 128 bits (composed of integer data) from `a`, selected with `imm8`.
854869
#[inline]
855870
#[target_feature(enable = "avx")]
856-
#[cfg_attr(test, assert_instr(vextractf128))]
871+
#[cfg_attr(test, assert_instr(vextractf128, imm8 = 1))]
872+
#[rustc_args_required_const(1)]
857873
pub unsafe fn _mm256_extractf128_si256(a: __m256i, imm8: i32) -> __m128i {
858874
let b = _mm256_undefined_si256().as_i64x4();
859875
let dst: i64x2 = match imm8 & 1 {
@@ -903,6 +919,7 @@ pub unsafe fn _mm_permutevar_ps(a: __m128, b: __m128i) -> __m128 {
903919
#[inline]
904920
#[target_feature(enable = "avx")]
905921
#[cfg_attr(test, assert_instr(vpermilps, imm8 = 9))]
922+
#[rustc_args_required_const(1)]
906923
pub unsafe fn _mm256_permute_ps(a: __m256, imm8: i32) -> __m256 {
907924
let imm8 = (imm8 & 0xFF) as u8;
908925
macro_rules! shuffle4 {
@@ -955,6 +972,7 @@ pub unsafe fn _mm256_permute_ps(a: __m256, imm8: i32) -> __m256 {
955972
#[inline]
956973
#[target_feature(enable = "avx,sse")]
957974
#[cfg_attr(test, assert_instr(vpermilps, imm8 = 9))]
975+
#[rustc_args_required_const(1)]
958976
pub unsafe fn _mm_permute_ps(a: __m128, imm8: i32) -> __m128 {
959977
let imm8 = (imm8 & 0xFF) as u8;
960978
macro_rules! shuffle4 {
@@ -1025,6 +1043,7 @@ pub unsafe fn _mm_permutevar_pd(a: __m128d, b: __m128i) -> __m128d {
10251043
#[inline]
10261044
#[target_feature(enable = "avx")]
10271045
#[cfg_attr(test, assert_instr(vpermilpd, imm8 = 0x1))]
1046+
#[rustc_args_required_const(1)]
10281047
pub unsafe fn _mm256_permute_pd(a: __m256d, imm8: i32) -> __m256d {
10291048
let imm8 = (imm8 & 0xFF) as u8;
10301049
macro_rules! shuffle4 {
@@ -1067,6 +1086,7 @@ pub unsafe fn _mm256_permute_pd(a: __m256d, imm8: i32) -> __m256d {
10671086
#[inline]
10681087
#[target_feature(enable = "avx,sse2")]
10691088
#[cfg_attr(test, assert_instr(vpermilpd, imm8 = 0x1))]
1089+
#[rustc_args_required_const(1)]
10701090
pub unsafe fn _mm_permute_pd(a: __m128d, imm8: i32) -> __m128d {
10711091
let imm8 = (imm8 & 0xFF) as u8;
10721092
macro_rules! shuffle2 {
@@ -1093,6 +1113,7 @@ pub unsafe fn _mm_permute_pd(a: __m128d, imm8: i32) -> __m128d {
10931113
#[inline]
10941114
#[target_feature(enable = "avx")]
10951115
#[cfg_attr(test, assert_instr(vperm2f128, imm8 = 0x5))]
1116+
#[rustc_args_required_const(2)]
10961117
pub unsafe fn _mm256_permute2f128_ps(
10971118
a: __m256, b: __m256, imm8: i32
10981119
) -> __m256 {
@@ -1107,6 +1128,7 @@ pub unsafe fn _mm256_permute2f128_ps(
11071128
#[inline]
11081129
#[target_feature(enable = "avx")]
11091130
#[cfg_attr(test, assert_instr(vperm2f128, imm8 = 0x31))]
1131+
#[rustc_args_required_const(2)]
11101132
pub unsafe fn _mm256_permute2f128_pd(
11111133
a: __m256d, b: __m256d, imm8: i32
11121134
) -> __m256d {
@@ -1121,6 +1143,7 @@ pub unsafe fn _mm256_permute2f128_pd(
11211143
#[inline]
11221144
#[target_feature(enable = "avx")]
11231145
#[cfg_attr(test, assert_instr(vperm2f128, imm8 = 0x31))]
1146+
#[rustc_args_required_const(2)]
11241147
pub unsafe fn _mm256_permute2f128_si256(
11251148
a: __m256i, b: __m256i, imm8: i32
11261149
) -> __m256i {
@@ -1184,6 +1207,7 @@ pub unsafe fn _mm256_broadcast_pd(a: &__m128d) -> __m256d {
11841207
#[inline]
11851208
#[target_feature(enable = "avx")]
11861209
#[cfg_attr(test, assert_instr(vinsertf128, imm8 = 1))]
1210+
#[rustc_args_required_const(2)]
11871211
pub unsafe fn _mm256_insertf128_ps(a: __m256, b: __m128, imm8: i32) -> __m256 {
11881212
let b = _mm256_castps128_ps256(b);
11891213
match imm8 & 1 {
@@ -1198,6 +1222,7 @@ pub unsafe fn _mm256_insertf128_ps(a: __m256, b: __m128, imm8: i32) -> __m256 {
11981222
#[inline]
11991223
#[target_feature(enable = "avx")]
12001224
#[cfg_attr(test, assert_instr(vinsertf128, imm8 = 1))]
1225+
#[rustc_args_required_const(2)]
12011226
pub unsafe fn _mm256_insertf128_pd(
12021227
a: __m256d, b: __m128d, imm8: i32
12031228
) -> __m256d {
@@ -1212,6 +1237,7 @@ pub unsafe fn _mm256_insertf128_pd(
12121237
#[inline]
12131238
#[target_feature(enable = "avx")]
12141239
#[cfg_attr(test, assert_instr(vinsertf128, imm8 = 1))]
1240+
#[rustc_args_required_const(2)]
12151241
pub unsafe fn _mm256_insertf128_si256(
12161242
a: __m256i, b: __m128i, imm8: i32
12171243
) -> __m256i {
@@ -1228,6 +1254,7 @@ pub unsafe fn _mm256_insertf128_si256(
12281254
#[inline]
12291255
#[target_feature(enable = "avx")]
12301256
// This intrinsic has no corresponding instruction.
1257+
#[rustc_args_required_const(2)]
12311258
pub unsafe fn _mm256_insert_epi8(a: __m256i, i: i8, index: i32) -> __m256i {
12321259
mem::transmute(simd_insert(a.as_i8x32(), (index as u32) & 31, i))
12331260
}
@@ -1237,6 +1264,7 @@ pub unsafe fn _mm256_insert_epi8(a: __m256i, i: i8, index: i32) -> __m256i {
12371264
#[inline]
12381265
#[target_feature(enable = "avx")]
12391266
// This intrinsic has no corresponding instruction.
1267+
#[rustc_args_required_const(2)]
12401268
pub unsafe fn _mm256_insert_epi16(a: __m256i, i: i16, index: i32) -> __m256i {
12411269
mem::transmute(simd_insert(a.as_i16x16(), (index as u32) & 15, i))
12421270
}
@@ -1246,6 +1274,7 @@ pub unsafe fn _mm256_insert_epi16(a: __m256i, i: i16, index: i32) -> __m256i {
12461274
#[inline]
12471275
#[target_feature(enable = "avx")]
12481276
// This intrinsic has no corresponding instruction.
1277+
#[rustc_args_required_const(2)]
12491278
pub unsafe fn _mm256_insert_epi32(a: __m256i, i: i32, index: i32) -> __m256i {
12501279
mem::transmute(simd_insert(a.as_i32x8(), (index as u32) & 7, i))
12511280
}

0 commit comments

Comments
 (0)