Skip to content

Commit dd20b4f

Browse files
committed
Refactor avx512f: mask operations
1 parent aaeb961 commit dd20b4f

File tree

2 files changed

+182
-10
lines changed

2 files changed

+182
-10
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: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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(cmp))] // 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)
@@ -54187,6 +54300,65 @@ mod tests {
5418754300
assert_eq!(r, e);
5418854301
}
5418954302

54303+
#[simd_test(enable = "avx512dq")]
54304+
unsafe fn test_kortest_mask16_u8() {
54305+
let a: __mmask8 = 0b0110100101101001;
54306+
let b: __mmask8 = 0b1011011010110110;
54307+
let mut all_ones: u8 = 0;
54308+
let r = _kortest_mask16_u8(a, b, &mut all_ones);
54309+
assert_eq!(r, 0);
54310+
assert_eq!(all_ones, 1);
54311+
}
54312+
54313+
#[simd_test(enable = "avx512dq")]
54314+
unsafe fn test_kortestc_mask16_u8() {
54315+
let a: __mmask16 = 0b0110100101101001;
54316+
let b: __mmask16 = 0b1011011010110110;
54317+
let r = _kortestc_mask16_u8(a, b);
54318+
assert_eq!(r, 1);
54319+
}
54320+
54321+
#[simd_test(enable = "avx512dq")]
54322+
unsafe fn test_kortestz_mask16_u8() {
54323+
let a: __mmask16 = 0b0110100101101001;
54324+
let b: __mmask16 = 0b1011011010110110;
54325+
let r = _kortestz_mask8_u16(a, b);
54326+
assert_eq!(r, 0);
54327+
}
54328+
54329+
#[simd_test(enable = "avx512dq")]
54330+
unsafe fn test_kshiftli_mask16() {
54331+
let a: __mmask16 = 0b1001011011000011;
54332+
let r = _kshiftli_mask16::<3>(a);
54333+
let e: __mmask16 = 0b1011011000011000;
54334+
assert_eq!(r, e);
54335+
}
54336+
54337+
#[simd_test(enable = "avx512dq")]
54338+
unsafe fn test_kshiftri_mask16() {
54339+
let a: __mmask16 = 0b0110100100111100;
54340+
let r = _kshiftri_mask16::<3>(a);
54341+
let e: __mmask16 = 0b0000110100100111;
54342+
assert_eq!(r, e);
54343+
}
54344+
54345+
#[simd_test(enable = "avx512f")]
54346+
unsafe fn test_load_mask16() {
54347+
let a: __mmask16 = 0b1001011011000011;
54348+
let r = _load_mask16(&a);
54349+
let e: __mmask16 = 0b1001011011000011;
54350+
assert_eq!(r, e);
54351+
}
54352+
54353+
#[simd_test(enable = "avx512f")]
54354+
unsafe fn test_store_mask16() {
54355+
let a: __mmask16 = 0b0110100100111100;
54356+
let mut r = 0;
54357+
_store_mask16(&mut r, a);
54358+
let e: __mmask16 = 0b0110100100111100;
54359+
assert_eq!(r, e);
54360+
}
54361+
5419054362
#[simd_test(enable = "avx512f")]
5419154363
unsafe fn test_mm512_kmov() {
5419254364
let a: u16 = 0b11001100_00110011;
@@ -54231,6 +54403,16 @@ mod tests {
5423154403
assert_eq!(r, 1);
5423254404
}
5423354405

54406+
#[simd_test(enable = "avx512f")]
54407+
unsafe fn test_mm512_kortestz() {
54408+
let a: u16 = 0b11001100_00110011;
54409+
let b: u16 = 0b00101110_00001011;
54410+
let r = _mm512_kortestz(a, b);
54411+
assert_eq!(r, 0);
54412+
let r = _mm512_kortestz(0, 0);
54413+
assert_eq!(r, 1);
54414+
}
54415+
5423454416
#[simd_test(enable = "avx512f")]
5423554417
unsafe fn test_mm512_test_epi32_mask() {
5423654418
let a = _mm512_set1_epi32(1 << 0);

0 commit comments

Comments
 (0)