| 1 | //! Vectorized Population Count Instructions for Double- and Quadwords (VPOPCNTDQ) |
| 2 | //! |
| 3 | //! The intrinsics here correspond to those in the `immintrin.h` C header. |
| 4 | //! |
| 5 | //! The reference is [Intel 64 and IA-32 Architectures Software Developer's |
| 6 | //! Manual Volume 2: Instruction Set Reference, A-Z][intel64_ref]. |
| 7 | //! |
| 8 | //! [intel64_ref]: https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf |
| 9 | |
| 10 | use crate::core_arch::simd::*; |
| 11 | use crate::core_arch::x86::__m128i; |
| 12 | use crate::core_arch::x86::__m256i; |
| 13 | use crate::core_arch::x86::__m512i; |
| 14 | use crate::core_arch::x86::__mmask8; |
| 15 | use crate::core_arch::x86::__mmask16; |
| 16 | use crate::intrinsics::simd::{simd_ctpop, simd_select_bitmask}; |
| 17 | use crate::mem::transmute; |
| 18 | |
| 19 | #[cfg (test)] |
| 20 | use stdarch_test::assert_instr; |
| 21 | |
| 22 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 23 | /// |
| 24 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_popcnt_epi32) |
| 25 | #[inline ] |
| 26 | #[target_feature (enable = "avx512vpopcntdq" )] |
| 27 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 28 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 29 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 30 | pub const fn _mm512_popcnt_epi32(a: __m512i) -> __m512i { |
| 31 | unsafe { transmute(src:simd_ctpop(a.as_i32x16())) } |
| 32 | } |
| 33 | |
| 34 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 35 | /// |
| 36 | /// Uses the writemask in k - elements are zeroed in the result if the corresponding mask bit is not set. |
| 37 | /// Otherwise the computation result is written into the result. |
| 38 | /// |
| 39 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_maskz_popcnt_epi32) |
| 40 | #[inline ] |
| 41 | #[target_feature (enable = "avx512vpopcntdq" )] |
| 42 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 43 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 44 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 45 | pub const fn _mm512_maskz_popcnt_epi32(k: __mmask16, a: __m512i) -> __m512i { |
| 46 | unsafe { |
| 47 | transmute(src:simd_select_bitmask( |
| 48 | m:k, |
| 49 | yes:simd_ctpop(a.as_i32x16()), |
| 50 | no:i32x16::ZERO, |
| 51 | )) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 56 | /// |
| 57 | /// Uses the writemask in k - elements are copied from src if the corresponding mask bit is not set. |
| 58 | /// Otherwise the computation result is written into the result. |
| 59 | /// |
| 60 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_mask_popcnt_epi32) |
| 61 | #[inline ] |
| 62 | #[target_feature (enable = "avx512vpopcntdq" )] |
| 63 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 64 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 65 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 66 | pub const fn _mm512_mask_popcnt_epi32(src: __m512i, k: __mmask16, a: __m512i) -> __m512i { |
| 67 | unsafe { |
| 68 | transmute(src:simd_select_bitmask( |
| 69 | m:k, |
| 70 | yes:simd_ctpop(a.as_i32x16()), |
| 71 | no:src.as_i32x16(), |
| 72 | )) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 77 | /// |
| 78 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_popcnt_epi32) |
| 79 | #[inline ] |
| 80 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 81 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 82 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 83 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 84 | pub const fn _mm256_popcnt_epi32(a: __m256i) -> __m256i { |
| 85 | unsafe { transmute(src:simd_ctpop(a.as_i32x8())) } |
| 86 | } |
| 87 | |
| 88 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 89 | /// |
| 90 | /// Uses the writemask in k - elements are zeroed in the result if the corresponding mask bit is not set. |
| 91 | /// Otherwise the computation result is written into the result. |
| 92 | /// |
| 93 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maskz_popcnt_epi32) |
| 94 | #[inline ] |
| 95 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 96 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 97 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 98 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 99 | pub const fn _mm256_maskz_popcnt_epi32(k: __mmask8, a: __m256i) -> __m256i { |
| 100 | unsafe { |
| 101 | transmute(src:simd_select_bitmask( |
| 102 | m:k, |
| 103 | yes:simd_ctpop(a.as_i32x8()), |
| 104 | no:i32x8::ZERO, |
| 105 | )) |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 110 | /// |
| 111 | /// Uses the writemask in k - elements are copied from src if the corresponding mask bit is not set. |
| 112 | /// Otherwise the computation result is written into the result. |
| 113 | /// |
| 114 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_popcnt_epi32) |
| 115 | #[inline ] |
| 116 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 117 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 118 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 119 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 120 | pub const fn _mm256_mask_popcnt_epi32(src: __m256i, k: __mmask8, a: __m256i) -> __m256i { |
| 121 | unsafe { |
| 122 | transmute(src:simd_select_bitmask( |
| 123 | m:k, |
| 124 | yes:simd_ctpop(a.as_i32x8()), |
| 125 | no:src.as_i32x8(), |
| 126 | )) |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 131 | /// |
| 132 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_popcnt_epi32) |
| 133 | #[inline ] |
| 134 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 135 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 136 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 137 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 138 | pub const fn _mm_popcnt_epi32(a: __m128i) -> __m128i { |
| 139 | unsafe { transmute(src:simd_ctpop(a.as_i32x4())) } |
| 140 | } |
| 141 | |
| 142 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 143 | /// |
| 144 | /// Uses the writemask in k - elements are zeroed in the result if the corresponding mask bit is not set. |
| 145 | /// Otherwise the computation result is written into the result. |
| 146 | /// |
| 147 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskz_popcnt_epi32) |
| 148 | #[inline ] |
| 149 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 150 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 151 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 152 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 153 | pub const fn _mm_maskz_popcnt_epi32(k: __mmask8, a: __m128i) -> __m128i { |
| 154 | unsafe { |
| 155 | transmute(src:simd_select_bitmask( |
| 156 | m:k, |
| 157 | yes:simd_ctpop(a.as_i32x4()), |
| 158 | no:i32x4::ZERO, |
| 159 | )) |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /// For each packed 32-bit integer maps the value to the number of logical 1 bits. |
| 164 | /// |
| 165 | /// Uses the writemask in k - elements are copied from src if the corresponding mask bit is not set. |
| 166 | /// Otherwise the computation result is written into the result. |
| 167 | /// |
| 168 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_popcnt_epi32) |
| 169 | #[inline ] |
| 170 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 171 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 172 | #[cfg_attr (test, assert_instr(vpopcntd))] |
| 173 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 174 | pub const fn _mm_mask_popcnt_epi32(src: __m128i, k: __mmask8, a: __m128i) -> __m128i { |
| 175 | unsafe { |
| 176 | transmute(src:simd_select_bitmask( |
| 177 | m:k, |
| 178 | yes:simd_ctpop(a.as_i32x4()), |
| 179 | no:src.as_i32x4(), |
| 180 | )) |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 185 | /// |
| 186 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_popcnt_epi64) |
| 187 | #[inline ] |
| 188 | #[target_feature (enable = "avx512vpopcntdq" )] |
| 189 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 190 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 191 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 192 | pub const fn _mm512_popcnt_epi64(a: __m512i) -> __m512i { |
| 193 | unsafe { transmute(src:simd_ctpop(a.as_i64x8())) } |
| 194 | } |
| 195 | |
| 196 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 197 | /// |
| 198 | /// Uses the writemask in k - elements are zeroed in the result if the corresponding mask bit is not set. |
| 199 | /// Otherwise the computation result is written into the result. |
| 200 | /// |
| 201 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_maskz_popcnt_epi64) |
| 202 | #[inline ] |
| 203 | #[target_feature (enable = "avx512vpopcntdq" )] |
| 204 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 205 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 206 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 207 | pub const fn _mm512_maskz_popcnt_epi64(k: __mmask8, a: __m512i) -> __m512i { |
| 208 | unsafe { |
| 209 | transmute(src:simd_select_bitmask( |
| 210 | m:k, |
| 211 | yes:simd_ctpop(a.as_i64x8()), |
| 212 | no:i64x8::ZERO, |
| 213 | )) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 218 | /// |
| 219 | /// Uses the writemask in k - elements are copied from src if the corresponding mask bit is not set. |
| 220 | /// Otherwise the computation result is written into the result. |
| 221 | /// |
| 222 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_mask_popcnt_epi64) |
| 223 | #[inline ] |
| 224 | #[target_feature (enable = "avx512vpopcntdq" )] |
| 225 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 226 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 227 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 228 | pub const fn _mm512_mask_popcnt_epi64(src: __m512i, k: __mmask8, a: __m512i) -> __m512i { |
| 229 | unsafe { |
| 230 | transmute(src:simd_select_bitmask( |
| 231 | m:k, |
| 232 | yes:simd_ctpop(a.as_i64x8()), |
| 233 | no:src.as_i64x8(), |
| 234 | )) |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 239 | /// |
| 240 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_popcnt_epi64) |
| 241 | #[inline ] |
| 242 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 243 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 244 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 245 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 246 | pub const fn _mm256_popcnt_epi64(a: __m256i) -> __m256i { |
| 247 | unsafe { transmute(src:simd_ctpop(a.as_i64x4())) } |
| 248 | } |
| 249 | |
| 250 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 251 | /// |
| 252 | /// Uses the writemask in k - elements are zeroed in the result if the corresponding mask bit is not set. |
| 253 | /// Otherwise the computation result is written into the result. |
| 254 | /// |
| 255 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_maskz_popcnt_epi64) |
| 256 | #[inline ] |
| 257 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 258 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 259 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 260 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 261 | pub const fn _mm256_maskz_popcnt_epi64(k: __mmask8, a: __m256i) -> __m256i { |
| 262 | unsafe { |
| 263 | transmute(src:simd_select_bitmask( |
| 264 | m:k, |
| 265 | yes:simd_ctpop(a.as_i64x4()), |
| 266 | no:i64x4::ZERO, |
| 267 | )) |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 272 | /// |
| 273 | /// Uses the writemask in k - elements are copied from src if the corresponding mask bit is not set. |
| 274 | /// Otherwise the computation result is written into the result. |
| 275 | /// |
| 276 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mask_popcnt_epi64) |
| 277 | #[inline ] |
| 278 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 279 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 280 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 281 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 282 | pub const fn _mm256_mask_popcnt_epi64(src: __m256i, k: __mmask8, a: __m256i) -> __m256i { |
| 283 | unsafe { |
| 284 | transmute(src:simd_select_bitmask( |
| 285 | m:k, |
| 286 | yes:simd_ctpop(a.as_i64x4()), |
| 287 | no:src.as_i64x4(), |
| 288 | )) |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 293 | /// |
| 294 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_popcnt_epi64) |
| 295 | #[inline ] |
| 296 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 297 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 298 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 299 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 300 | pub const fn _mm_popcnt_epi64(a: __m128i) -> __m128i { |
| 301 | unsafe { transmute(src:simd_ctpop(a.as_i64x2())) } |
| 302 | } |
| 303 | |
| 304 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 305 | /// |
| 306 | /// Uses the writemask in k - elements are zeroed in the result if the corresponding mask bit is not set. |
| 307 | /// Otherwise the computation result is written into the result. |
| 308 | /// |
| 309 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maskz_popcnt_epi64) |
| 310 | #[inline ] |
| 311 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 312 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 313 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 314 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 315 | pub const fn _mm_maskz_popcnt_epi64(k: __mmask8, a: __m128i) -> __m128i { |
| 316 | unsafe { |
| 317 | transmute(src:simd_select_bitmask( |
| 318 | m:k, |
| 319 | yes:simd_ctpop(a.as_i64x2()), |
| 320 | no:i64x2::ZERO, |
| 321 | )) |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /// For each packed 64-bit integer maps the value to the number of logical 1 bits. |
| 326 | /// |
| 327 | /// Uses the writemask in k - elements are copied from src if the corresponding mask bit is not set. |
| 328 | /// Otherwise the computation result is written into the result. |
| 329 | /// |
| 330 | /// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mask_popcnt_epi64) |
| 331 | #[inline ] |
| 332 | #[target_feature (enable = "avx512vpopcntdq,avx512vl" )] |
| 333 | #[stable (feature = "stdarch_x86_avx512" , since = "1.89" )] |
| 334 | #[cfg_attr (test, assert_instr(vpopcntq))] |
| 335 | #[rustc_const_unstable (feature = "stdarch_const_x86" , issue = "149298" )] |
| 336 | pub const fn _mm_mask_popcnt_epi64(src: __m128i, k: __mmask8, a: __m128i) -> __m128i { |
| 337 | unsafe { |
| 338 | transmute(src:simd_select_bitmask( |
| 339 | m:k, |
| 340 | yes:simd_ctpop(a.as_i64x2()), |
| 341 | no:src.as_i64x2(), |
| 342 | )) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | #[cfg (test)] |
| 347 | mod tests { |
| 348 | use crate::core_arch::assert_eq_const as assert_eq; |
| 349 | use stdarch_test::simd_test; |
| 350 | |
| 351 | use crate::core_arch::x86::*; |
| 352 | |
| 353 | #[simd_test(enable = "avx512vpopcntdq,avx512f" )] |
| 354 | const fn test_mm512_popcnt_epi32() { |
| 355 | let test_data = _mm512_set_epi32( |
| 356 | 0, |
| 357 | 1, |
| 358 | -1, |
| 359 | 2, |
| 360 | 7, |
| 361 | 0xFF_FE, |
| 362 | 0x7F_FF_FF_FF, |
| 363 | -100, |
| 364 | 0x40_00_00_00, |
| 365 | 103, |
| 366 | 371, |
| 367 | 552, |
| 368 | 432_948, |
| 369 | 818_826_998, |
| 370 | 255, |
| 371 | 256, |
| 372 | ); |
| 373 | let actual_result = _mm512_popcnt_epi32(test_data); |
| 374 | let reference_result = |
| 375 | _mm512_set_epi32(0, 1, 32, 1, 3, 15, 31, 28, 1, 5, 6, 3, 10, 17, 8, 1); |
| 376 | assert_eq_m512i(actual_result, reference_result); |
| 377 | } |
| 378 | |
| 379 | #[simd_test(enable = "avx512vpopcntdq,avx512f" )] |
| 380 | const fn test_mm512_mask_popcnt_epi32() { |
| 381 | let test_data = _mm512_set_epi32( |
| 382 | 0, |
| 383 | 1, |
| 384 | -1, |
| 385 | 2, |
| 386 | 7, |
| 387 | 0xFF_FE, |
| 388 | 0x7F_FF_FF_FF, |
| 389 | -100, |
| 390 | 0x40_00_00_00, |
| 391 | 103, |
| 392 | 371, |
| 393 | 552, |
| 394 | 432_948, |
| 395 | 818_826_998, |
| 396 | 255, |
| 397 | 256, |
| 398 | ); |
| 399 | let mask = 0xFF_00; |
| 400 | let actual_result = _mm512_mask_popcnt_epi32(test_data, mask, test_data); |
| 401 | let reference_result = _mm512_set_epi32( |
| 402 | 0, |
| 403 | 1, |
| 404 | 32, |
| 405 | 1, |
| 406 | 3, |
| 407 | 15, |
| 408 | 31, |
| 409 | 28, |
| 410 | 0x40_00_00_00, |
| 411 | 103, |
| 412 | 371, |
| 413 | 552, |
| 414 | 432_948, |
| 415 | 818_826_998, |
| 416 | 255, |
| 417 | 256, |
| 418 | ); |
| 419 | assert_eq_m512i(actual_result, reference_result); |
| 420 | } |
| 421 | |
| 422 | #[simd_test(enable = "avx512vpopcntdq,avx512f" )] |
| 423 | const fn test_mm512_maskz_popcnt_epi32() { |
| 424 | let test_data = _mm512_set_epi32( |
| 425 | 0, |
| 426 | 1, |
| 427 | -1, |
| 428 | 2, |
| 429 | 7, |
| 430 | 0xFF_FE, |
| 431 | 0x7F_FF_FF_FF, |
| 432 | -100, |
| 433 | 0x40_00_00_00, |
| 434 | 103, |
| 435 | 371, |
| 436 | 552, |
| 437 | 432_948, |
| 438 | 818_826_998, |
| 439 | 255, |
| 440 | 256, |
| 441 | ); |
| 442 | let mask = 0xFF_00; |
| 443 | let actual_result = _mm512_maskz_popcnt_epi32(mask, test_data); |
| 444 | let reference_result = _mm512_set_epi32(0, 1, 32, 1, 3, 15, 31, 28, 0, 0, 0, 0, 0, 0, 0, 0); |
| 445 | assert_eq_m512i(actual_result, reference_result); |
| 446 | } |
| 447 | |
| 448 | #[simd_test(enable = "avx512vpopcntdq,avx512f,avx512vl" )] |
| 449 | const fn test_mm256_popcnt_epi32() { |
| 450 | let test_data = _mm256_set_epi32(0, 1, -1, 2, 7, 0xFF_FE, 0x7F_FF_FF_FF, -100); |
| 451 | let actual_result = _mm256_popcnt_epi32(test_data); |
| 452 | let reference_result = _mm256_set_epi32(0, 1, 32, 1, 3, 15, 31, 28); |
| 453 | assert_eq_m256i(actual_result, reference_result); |
| 454 | } |
| 455 | |
| 456 | #[simd_test(enable = "avx512vpopcntdq,avx512f,avx512vl" )] |
| 457 | const fn test_mm256_mask_popcnt_epi32() { |
| 458 | let test_data = _mm256_set_epi32(0, 1, -1, 2, 7, 0xFF_FE, 0x7F_FF_FF_FF, -100); |
| 459 | let mask = 0xF0; |
| 460 | let actual_result = _mm256_mask_popcnt_epi32(test_data, mask, test_data); |
| 461 | let reference_result = _mm256_set_epi32(0, 1, 32, 1, 7, 0xFF_FE, 0x7F_FF_FF_FF, -100); |
| 462 | assert_eq_m256i(actual_result, reference_result); |
| 463 | } |
| 464 | |
| 465 | #[simd_test(enable = "avx512vpopcntdq,avx512f,avx512vl" )] |
| 466 | const fn test_mm256_maskz_popcnt_epi32() { |
| 467 | let test_data = _mm256_set_epi32(0, 1, -1, 2, 7, 0xFF_FE, 0x7F_FF_FF_FF, -100); |
| 468 | let mask = 0xF0; |
| 469 | let actual_result = _mm256_maskz_popcnt_epi32(mask, test_data); |
| 470 | let reference_result = _mm256_set_epi32(0, 1, 32, 1, 0, 0, 0, 0); |
| 471 | assert_eq_m256i(actual_result, reference_result); |
| 472 | } |
| 473 | |
| 474 | #[simd_test(enable = "avx512vpopcntdq,avx512f,avx512vl" )] |
| 475 | const fn test_mm_popcnt_epi32() { |
| 476 | let test_data = _mm_set_epi32(0, 1, -1, -100); |
| 477 | let actual_result = _mm_popcnt_epi32(test_data); |
| 478 | let reference_result = _mm_set_epi32(0, 1, 32, 28); |
| 479 | assert_eq_m128i(actual_result, reference_result); |
| 480 | } |
| 481 | |
| 482 | #[simd_test(enable = "avx512vpopcntdq,avx512f,avx512vl" )] |
| 483 | const fn test_mm_mask_popcnt_epi32() { |
| 484 | let test_data = _mm_set_epi32(0, 1, -1, -100); |
| 485 | let mask = 0xE; |
| 486 | let actual_result = _mm_mask_popcnt_epi32(test_data, mask, test_data); |
| 487 | let reference_result = _mm_set_epi32(0, 1, 32, -100); |
| 488 | assert_eq_m128i(actual_result, reference_result); |
| 489 | } |
| 490 | |
| 491 | #[simd_test(enable = "avx512vpopcntdq,avx512f,avx512vl" )] |
| 492 | const fn test_mm_maskz_popcnt_epi32() { |
| 493 | let test_data = _mm_set_epi32(0, 1, -1, -100); |
| 494 | let mask = 0xE; |
| 495 | let actual_result = _mm_maskz_popcnt_epi32(mask, test_data); |
| 496 | let reference_result = _mm_set_epi32(0, 1, 32, 0); |
| 497 | assert_eq_m128i(actual_result, reference_result); |
| 498 | } |
| 499 | |
| 500 | #[simd_test(enable = "avx512vpopcntdq,avx512f" )] |
| 501 | const fn test_mm512_popcnt_epi64() { |
| 502 | let test_data = _mm512_set_epi64(0, 1, -1, 2, 7, 0xFF_FE, 0x7F_FF_FF_FF_FF_FF_FF_FF, -100); |
| 503 | let actual_result = _mm512_popcnt_epi64(test_data); |
| 504 | let reference_result = _mm512_set_epi64(0, 1, 64, 1, 3, 15, 63, 60); |
| 505 | assert_eq_m512i(actual_result, reference_result); |
| 506 | } |
| 507 | |
| 508 | #[simd_test(enable = "avx512vpopcntdq,avx512f" )] |
| 509 | const fn test_mm512_mask_popcnt_epi64() { |
| 510 | let test_data = _mm512_set_epi64(0, 1, -1, 2, 7, 0xFF_FE, 0x7F_FF_FF_FF_FF_FF_FF_FF, -100); |
| 511 | let mask = 0xF0; |
| 512 | let actual_result = _mm512_mask_popcnt_epi64(test_data, mask, test_data); |
| 513 | let reference_result = |
| 514 | _mm512_set_epi64(0, 1, 64, 1, 7, 0xFF_FE, 0x7F_FF_FF_FF_FF_FF_FF_FF, -100); |
| 515 | assert_eq_m512i(actual_result, reference_result); |
| 516 | } |
| 517 | |
| 518 | #[simd_test(enable = "avx512vpopcntdq,avx512f" )] |
| 519 | const fn test_mm512_maskz_popcnt_epi64() { |
| 520 | let test_data = _mm512_set_epi64(0, 1, -1, 2, 7, 0xFF_FE, 0x7F_FF_FF_FF_FF_FF_FF_FF, -100); |
| 521 | let mask = 0xF0; |
| 522 | let actual_result = _mm512_maskz_popcnt_epi64(mask, test_data); |
| 523 | let reference_result = _mm512_set_epi64(0, 1, 64, 1, 0, 0, 0, 0); |
| 524 | assert_eq_m512i(actual_result, reference_result); |
| 525 | } |
| 526 | |
| 527 | #[simd_test(enable = "avx512vpopcntdq,avx512vl" )] |
| 528 | const fn test_mm256_popcnt_epi64() { |
| 529 | let test_data = _mm256_set_epi64x(0, 1, -1, -100); |
| 530 | let actual_result = _mm256_popcnt_epi64(test_data); |
| 531 | let reference_result = _mm256_set_epi64x(0, 1, 64, 60); |
| 532 | assert_eq_m256i(actual_result, reference_result); |
| 533 | } |
| 534 | |
| 535 | #[simd_test(enable = "avx512vpopcntdq,avx512vl" )] |
| 536 | const fn test_mm256_mask_popcnt_epi64() { |
| 537 | let test_data = _mm256_set_epi64x(0, 1, -1, -100); |
| 538 | let mask = 0xE; |
| 539 | let actual_result = _mm256_mask_popcnt_epi64(test_data, mask, test_data); |
| 540 | let reference_result = _mm256_set_epi64x(0, 1, 64, -100); |
| 541 | assert_eq_m256i(actual_result, reference_result); |
| 542 | } |
| 543 | |
| 544 | #[simd_test(enable = "avx512vpopcntdq,avx512vl" )] |
| 545 | const fn test_mm256_maskz_popcnt_epi64() { |
| 546 | let test_data = _mm256_set_epi64x(0, 1, -1, -100); |
| 547 | let mask = 0xE; |
| 548 | let actual_result = _mm256_maskz_popcnt_epi64(mask, test_data); |
| 549 | let reference_result = _mm256_set_epi64x(0, 1, 64, 0); |
| 550 | assert_eq_m256i(actual_result, reference_result); |
| 551 | } |
| 552 | |
| 553 | #[simd_test(enable = "avx512vpopcntdq,avx512vl" )] |
| 554 | const fn test_mm_popcnt_epi64() { |
| 555 | let test_data = _mm_set_epi64x(0, 1); |
| 556 | let actual_result = _mm_popcnt_epi64(test_data); |
| 557 | let reference_result = _mm_set_epi64x(0, 1); |
| 558 | assert_eq_m128i(actual_result, reference_result); |
| 559 | let test_data = _mm_set_epi64x(-1, -100); |
| 560 | let actual_result = _mm_popcnt_epi64(test_data); |
| 561 | let reference_result = _mm_set_epi64x(64, 60); |
| 562 | assert_eq_m128i(actual_result, reference_result); |
| 563 | } |
| 564 | |
| 565 | #[simd_test(enable = "avx512vpopcntdq,avx512vl" )] |
| 566 | const fn test_mm_mask_popcnt_epi64() { |
| 567 | let test_data = _mm_set_epi64x(0, -100); |
| 568 | let mask = 0x2; |
| 569 | let actual_result = _mm_mask_popcnt_epi64(test_data, mask, test_data); |
| 570 | let reference_result = _mm_set_epi64x(0, -100); |
| 571 | assert_eq_m128i(actual_result, reference_result); |
| 572 | let test_data = _mm_set_epi64x(-1, 1); |
| 573 | let mask = 0x2; |
| 574 | let actual_result = _mm_mask_popcnt_epi64(test_data, mask, test_data); |
| 575 | let reference_result = _mm_set_epi64x(64, 1); |
| 576 | assert_eq_m128i(actual_result, reference_result); |
| 577 | } |
| 578 | |
| 579 | #[simd_test(enable = "avx512vpopcntdq,avx512vl" )] |
| 580 | const fn test_mm_maskz_popcnt_epi64() { |
| 581 | let test_data = _mm_set_epi64x(0, 1); |
| 582 | let mask = 0x2; |
| 583 | let actual_result = _mm_maskz_popcnt_epi64(mask, test_data); |
| 584 | let reference_result = _mm_set_epi64x(0, 0); |
| 585 | assert_eq_m128i(actual_result, reference_result); |
| 586 | let test_data = _mm_set_epi64x(-1, -100); |
| 587 | let mask = 0x2; |
| 588 | let actual_result = _mm_maskz_popcnt_epi64(mask, test_data); |
| 589 | let reference_result = _mm_set_epi64x(64, 0); |
| 590 | assert_eq_m128i(actual_result, reference_result); |
| 591 | } |
| 592 | } |
| 593 | |