Skip to content

Commit 0007890

Browse files
committed
Refactor avx512f: mask operations
1 parent e51bd72 commit 0007890

File tree

2 files changed

+200
-12
lines changed

2 files changed

+200
-12
lines changed

crates/core_arch/missing-x86.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,10 @@
149149

150150
<details><summary>["AVX512F"]</summary><p>
151151

152-
* [ ] [`_cvtmask16_u32`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_cvtmask16_u32)
153-
* [ ] [`_cvtu32_mask16`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_cvtu32_mask16)
154-
* [ ] [`_kortest_mask16_u8`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_kortest_mask16_u8)
155-
* [ ] [`_kortestc_mask16_u8`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_kortestc_mask16_u8)
156-
* [ ] [`_kortestz_mask16_u8`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_kortestz_mask16_u8)
157-
* [ ] [`_kshiftli_mask16`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_kshiftli_mask16)
158-
* [ ] [`_kshiftri_mask16`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_kshiftri_mask16)
159-
* [ ] [`_load_mask16`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_load_mask16)
160152
* [ ] [`_mm512_i32logather_epi64`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_i32logather_epi64)
161153
* [ ] [`_mm512_i32logather_pd`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_i32logather_pd)
162154
* [ ] [`_mm512_i32loscatter_epi64`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_i32loscatter_epi64)
163155
* [ ] [`_mm512_i32loscatter_pd`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_i32loscatter_pd)
164-
* [ ] [`_mm512_kortestz`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_kortestz)
165156
* [ ] [`_mm512_mask_i32logather_epi64`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_mask_i32logather_epi64)
166157
* [ ] [`_mm512_mask_i32logather_pd`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_mask_i32logather_pd)
167158
* [ ] [`_mm512_mask_i32loscatter_epi64`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm512_mask_i32loscatter_epi64)
@@ -173,7 +164,6 @@
173164
* [ ] [`_mm_mask_store_ss`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mask_store_ss)
174165
* [ ] [`_mm_maskz_load_sd`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_maskz_load_sd)
175166
* [ ] [`_mm_maskz_load_ss`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_maskz_load_ss)
176-
* [ ] [`_store_mask16`](https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_store_mask16)
177167
</p></details>
178168

179169

crates/core_arch/src/x86/avx512f.rs

Lines changed: 200 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25327,7 +25327,7 @@ pub unsafe fn _mm512_cvtsi512_si32(a: __m512i) -> i32 {
2532725327
#[inline]
2532825328
#[target_feature(enable = "avx512f")]
2532925329
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
25330-
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(vmovd))]
25330+
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(vmovss))]
2533125331
pub unsafe fn _mm512_cvtss_f32(a: __m512) -> f32 {
2533225332
simd_extract!(a, 0)
2533325333
}
@@ -25338,7 +25338,7 @@ pub unsafe fn _mm512_cvtss_f32(a: __m512) -> f32 {
2533825338
#[inline]
2533925339
#[target_feature(enable = "avx512f")]
2534025340
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
25341-
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(vmovd))]
25341+
#[cfg_attr(all(test, not(target_env = "msvc")), assert_instr(vmovsd))]
2534225342
pub unsafe fn _mm512_cvtsd_f64(a: __m512d) -> f64 {
2534325343
simd_extract!(a, 0)
2534425344
}
@@ -27276,6 +27276,26 @@ pub unsafe fn _mm512_andnot_si512(a: __m512i, b: __m512i) -> __m512i {
2727627276
_mm512_and_epi64(_mm512_xor_epi64(a, _mm512_set1_epi64(u64::MAX as i64)), b)
2727727277
}
2727827278

27279+
/// Convert 16-bit mask a into an integer value, and store the result in dst.
27280+
///
27281+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_cvtmask16_u32)
27282+
#[inline]
27283+
#[target_feature(enable = "avx512f")]
27284+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27285+
pub unsafe fn _cvtmask16_u32(a: __mmask16) -> u32 {
27286+
a as u32
27287+
}
27288+
27289+
/// Convert 32-bit integer value a to an 16-bit mask and store the result in dst.
27290+
///
27291+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_cvtu32_mask16)
27292+
#[inline]
27293+
#[target_feature(enable = "avx512f")]
27294+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27295+
pub unsafe fn _cvtu32_mask16(a: u32) -> __mmask16 {
27296+
a as __mmask16
27297+
}
27298+
2727927299
/// Compute the bitwise AND of 16-bit masks a and b, and store the result in k.
2728027300
///
2728127301
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=kand_mask16&expand=3212)
@@ -27406,6 +27426,83 @@ pub unsafe fn _mm512_kxnor(a: __mmask16, b: __mmask16) -> __mmask16 {
2740627426
_mm512_knot(_mm512_kxor(a, b))
2740727427
}
2740827428

27429+
/// Compute the bitwise OR of 16-bit masks a and b. If the result is all zeros, store 1 in dst, otherwise
27430+
/// store 0 in dst. If the result is all ones, store 1 in all_ones, otherwise store 0 in all_ones.
27431+
///
27432+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_kortest_mask16_u8)
27433+
#[inline]
27434+
#[target_feature(enable = "avx512f")]
27435+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27436+
pub unsafe fn _kortest_mask16_u8(a: __mmask16, b: __mmask16, all_ones: *mut u8) -> u8 {
27437+
let tmp = _kor_mask16(a, b);
27438+
*all_ones = (tmp == 0xff) as u8;
27439+
(tmp == 0) as u8
27440+
}
27441+
27442+
/// Compute the bitwise OR of 16-bit masks a and b. If the result is all ones, store 1 in dst, otherwise
27443+
/// store 0 in dst.
27444+
///
27445+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_kortestc_mask16_u8)
27446+
#[inline]
27447+
#[target_feature(enable = "avx512f")]
27448+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27449+
pub unsafe fn _kortestc_mask16_u8(a: __mmask16, b: __mmask16) -> u8 {
27450+
(_kor_mask16(a, b) == 0xff) as u8
27451+
}
27452+
27453+
/// Compute the bitwise OR of 16-bit masks a and b. If the result is all zeros, store 1 in dst, otherwise
27454+
/// store 0 in dst.
27455+
///
27456+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_kortestz_mask16_u8)
27457+
#[inline]
27458+
#[target_feature(enable = "avx512f")]
27459+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27460+
pub unsafe fn _kortestz_mask16_u8(a: __mmask16, b: __mmask16) -> u8 {
27461+
(_kor_mask16(a, b) == 0) as u8
27462+
}
27463+
27464+
/// Shift 16-bit mask a left by count bits while shifting in zeros, and store the result in dst.
27465+
///
27466+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_kshiftli_mask16)
27467+
#[inline]
27468+
#[target_feature(enable = "avx512f")]
27469+
#[rustc_legacy_const_generics(1)]
27470+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27471+
pub unsafe fn _kshiftli_mask16<const COUNT: u32>(a: __mmask16) -> __mmask16 {
27472+
a << COUNT
27473+
}
27474+
27475+
/// Shift 16-bit mask a right by count bits while shifting in zeros, and store the result in dst.
27476+
///
27477+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_kshiftri_mask16)
27478+
#[inline]
27479+
#[target_feature(enable = "avx512f")]
27480+
#[rustc_legacy_const_generics(1)]
27481+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27482+
pub unsafe fn _kshiftri_mask16<const COUNT: u32>(a: __mmask16) -> __mmask16 {
27483+
a >> COUNT
27484+
}
27485+
27486+
/// Load 16-bit mask from memory
27487+
///
27488+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_load_mask16)
27489+
#[inline]
27490+
#[target_feature(enable = "avx512f")]
27491+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27492+
pub unsafe fn _load_mask16(mem_addr: *const __mmask16) -> __mmask16 {
27493+
*mem_addr
27494+
}
27495+
27496+
/// Store 16-bit mask to memory
27497+
///
27498+
/// [Intel's Documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_store_mask16)
27499+
#[inline]
27500+
#[target_feature(enable = "avx512f")]
27501+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27502+
pub unsafe fn _store_mask16(mem_addr: *mut __mmask16, a: __mmask16) {
27503+
*mem_addr = a;
27504+
}
27505+
2740927506
/// Copy 16-bit mask a to k.
2741027507
///
2741127508
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=mm512_kmov&expand=3228)
@@ -27465,6 +27562,22 @@ pub unsafe fn _mm512_kortestc(a: __mmask16, b: __mmask16) -> i32 {
2746527562
}
2746627563
}
2746727564

27565+
/// Performs bitwise OR between k1 and k2, storing the result in dst. ZF flag is set if dst is 0.
27566+
///
27567+
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=512_kortestz)
27568+
#[inline]
27569+
#[target_feature(enable = "avx512f")]
27570+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
27571+
#[cfg_attr(test, assert_instr(xor))] // generate normal and code instead of kortestw
27572+
pub unsafe fn _mm512_kortestz(a: __mmask16, b: __mmask16) -> i32 {
27573+
let r = a | b;
27574+
if r == 0 {
27575+
1
27576+
} else {
27577+
0
27578+
}
27579+
}
27580+
2746827581
/// Compute the bitwise AND of packed 32-bit integers in a and b, producing intermediate 32-bit values, and set the corresponding bit in result mask k if the intermediate value is non-zero.
2746927582
///
2747027583
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_test_epi32_mask&expand=5890)
@@ -54081,6 +54194,22 @@ mod tests {
5408154194
assert_eq_m128i(r, e);
5408254195
}
5408354196

54197+
#[simd_test(enable = "avx512f")]
54198+
unsafe fn test_cvtmask16_u32() {
54199+
let a: __mmask16 = 0b11001100_00110011;
54200+
let r = _cvtmask16_u32(a);
54201+
let e: u32 = 0b11001100_00110011;
54202+
assert_eq!(r, e);
54203+
}
54204+
54205+
#[simd_test(enable = "avx512f")]
54206+
unsafe fn test_cvtu32_mask16() {
54207+
let a: u32 = 0b11001100_00110011;
54208+
let r = _cvtu32_mask16(a);
54209+
let e: __mmask16 = 0b11001100_00110011;
54210+
assert_eq!(r, e);
54211+
}
54212+
5408454213
#[simd_test(enable = "avx512f")]
5408554214
unsafe fn test_mm512_kand() {
5408654215
let a: u16 = 0b11001100_00110011;
@@ -54187,6 +54316,65 @@ mod tests {
5418754316
assert_eq!(r, e);
5418854317
}
5418954318

54319+
#[simd_test(enable = "avx512dq")]
54320+
unsafe fn test_kortest_mask16_u8() {
54321+
let a: __mmask16 = 0b0110100101101001;
54322+
let b: __mmask16 = 0b1011011010110110;
54323+
let mut all_ones: u8 = 0;
54324+
let r = _kortest_mask16_u8(a, b, &mut all_ones);
54325+
assert_eq!(r, 0);
54326+
assert_eq!(all_ones, 1);
54327+
}
54328+
54329+
#[simd_test(enable = "avx512dq")]
54330+
unsafe fn test_kortestc_mask16_u8() {
54331+
let a: __mmask16 = 0b0110100101101001;
54332+
let b: __mmask16 = 0b1011011010110110;
54333+
let r = _kortestc_mask16_u8(a, b);
54334+
assert_eq!(r, 1);
54335+
}
54336+
54337+
#[simd_test(enable = "avx512dq")]
54338+
unsafe fn test_kortestz_mask16_u8() {
54339+
let a: __mmask16 = 0b0110100101101001;
54340+
let b: __mmask16 = 0b1011011010110110;
54341+
let r = _kortestz_mask16_u8(a, b);
54342+
assert_eq!(r, 0);
54343+
}
54344+
54345+
#[simd_test(enable = "avx512dq")]
54346+
unsafe fn test_kshiftli_mask16() {
54347+
let a: __mmask16 = 0b1001011011000011;
54348+
let r = _kshiftli_mask16::<3>(a);
54349+
let e: __mmask16 = 0b1011011000011000;
54350+
assert_eq!(r, e);
54351+
}
54352+
54353+
#[simd_test(enable = "avx512dq")]
54354+
unsafe fn test_kshiftri_mask16() {
54355+
let a: __mmask16 = 0b0110100100111100;
54356+
let r = _kshiftri_mask16::<3>(a);
54357+
let e: __mmask16 = 0b0000110100100111;
54358+
assert_eq!(r, e);
54359+
}
54360+
54361+
#[simd_test(enable = "avx512f")]
54362+
unsafe fn test_load_mask16() {
54363+
let a: __mmask16 = 0b1001011011000011;
54364+
let r = _load_mask16(&a);
54365+
let e: __mmask16 = 0b1001011011000011;
54366+
assert_eq!(r, e);
54367+
}
54368+
54369+
#[simd_test(enable = "avx512f")]
54370+
unsafe fn test_store_mask16() {
54371+
let a: __mmask16 = 0b0110100100111100;
54372+
let mut r = 0;
54373+
_store_mask16(&mut r, a);
54374+
let e: __mmask16 = 0b0110100100111100;
54375+
assert_eq!(r, e);
54376+
}
54377+
5419054378
#[simd_test(enable = "avx512f")]
5419154379
unsafe fn test_mm512_kmov() {
5419254380
let a: u16 = 0b11001100_00110011;
@@ -54231,6 +54419,16 @@ mod tests {
5423154419
assert_eq!(r, 1);
5423254420
}
5423354421

54422+
#[simd_test(enable = "avx512f")]
54423+
unsafe fn test_mm512_kortestz() {
54424+
let a: u16 = 0b11001100_00110011;
54425+
let b: u16 = 0b00101110_00001011;
54426+
let r = _mm512_kortestz(a, b);
54427+
assert_eq!(r, 0);
54428+
let r = _mm512_kortestz(0, 0);
54429+
assert_eq!(r, 1);
54430+
}
54431+
5423454432
#[simd_test(enable = "avx512f")]
5423554433
unsafe fn test_mm512_test_epi32_mask() {
5423654434
let a = _mm512_set1_epi32(1 << 0);

0 commit comments

Comments
 (0)