/src/zlib-ng/arch/x86/adler32_avx2_p.h
Line | Count | Source |
1 | | /* adler32_avx2_p.h -- adler32 avx2 utility functions |
2 | | * Copyright (C) 2022 Adam Stylinski |
3 | | * For conditions of distribution and use, see copyright notice in zlib.h |
4 | | */ |
5 | | |
6 | | #ifndef ADLER32_AVX2_P_H_ |
7 | | #define ADLER32_AVX2_P_H_ |
8 | | |
9 | | #if defined(X86_AVX2) || defined(X86_AVX512VNNI) |
10 | | |
11 | | /* MSVC has no AVX-VNNI arch flag, so its _mm256_dpbusd_epi32 is always the EVEX AVX512-VNNI |
12 | | * form. The VEX form has its own name and is only wanted when AVX512VL is not already enabled. */ |
13 | | #if defined(_MSC_VER) && !defined(__clang__) && !defined(__AVX512VL__) |
14 | | # define z256_dpbusd_epi32(a, b, c) _mm256_dpbusd_avx_epi32(a, b, c) |
15 | | #else |
16 | 0 | # define z256_dpbusd_epi32(a, b, c) _mm256_dpbusd_epi32(a, b, c) |
17 | | #endif |
18 | | |
19 | | /* 32 bit horizontal sum, adapted from Agner Fog's vector library. */ |
20 | 1.01M | static inline uint32_t hsum256(__m256i x) { |
21 | 1.01M | __m128i sum1 = _mm_add_epi32(_mm256_extracti128_si256(x, 1), |
22 | 1.01M | _mm256_castsi256_si128(x)); |
23 | 1.01M | __m128i sum2 = _mm_add_epi32(sum1, _mm_unpackhi_epi64(sum1, sum1)); |
24 | 1.01M | __m128i sum3 = _mm_add_epi32(sum2, _mm_shuffle_epi32(sum2, 1)); |
25 | 1.01M | return (uint32_t)_mm_cvtsi128_si32(sum3); |
26 | 1.01M | } Line | Count | Source | 20 | 1.01M | static inline uint32_t hsum256(__m256i x) { | 21 | 1.01M | __m128i sum1 = _mm_add_epi32(_mm256_extracti128_si256(x, 1), | 22 | 1.01M | _mm256_castsi256_si128(x)); | 23 | 1.01M | __m128i sum2 = _mm_add_epi32(sum1, _mm_unpackhi_epi64(sum1, sum1)); | 24 | | __m128i sum3 = _mm_add_epi32(sum2, _mm_shuffle_epi32(sum2, 1)); | 25 | 1.01M | return (uint32_t)_mm_cvtsi128_si32(sum3); | 26 | 1.01M | } |
Unexecuted instantiation: adler32_avx2_vnni.c:hsum256 Unexecuted instantiation: adler32_avx512_vnni.c:hsum256 |
27 | | |
28 | 1.01M | static inline uint32_t partial_hsum256(__m256i x) { |
29 | | /* We need a permutation vector to extract every other integer. The |
30 | | * rest are going to be zeros */ |
31 | 1.01M | const __m256i perm_vec = _mm256_setr_epi32(0, 2, 4, 6, 1, 1, 1, 1); |
32 | 1.01M | __m256i non_zero = _mm256_permutevar8x32_epi32(x, perm_vec); |
33 | 1.01M | __m128i non_zero_sse = _mm256_castsi256_si128(non_zero); |
34 | 1.01M | __m128i sum2 = _mm_add_epi32(non_zero_sse,_mm_unpackhi_epi64(non_zero_sse, non_zero_sse)); |
35 | | __m128i sum3 = _mm_add_epi32(sum2, _mm_shuffle_epi32(sum2, 1)); |
36 | 1.01M | return (uint32_t)_mm_cvtsi128_si32(sum3); |
37 | 1.01M | } adler32_avx2.c:partial_hsum256 Line | Count | Source | 28 | 1.01M | static inline uint32_t partial_hsum256(__m256i x) { | 29 | | /* We need a permutation vector to extract every other integer. The | 30 | | * rest are going to be zeros */ | 31 | 1.01M | const __m256i perm_vec = _mm256_setr_epi32(0, 2, 4, 6, 1, 1, 1, 1); | 32 | 1.01M | __m256i non_zero = _mm256_permutevar8x32_epi32(x, perm_vec); | 33 | 1.01M | __m128i non_zero_sse = _mm256_castsi256_si128(non_zero); | 34 | 1.01M | __m128i sum2 = _mm_add_epi32(non_zero_sse,_mm_unpackhi_epi64(non_zero_sse, non_zero_sse)); | 35 | | __m128i sum3 = _mm_add_epi32(sum2, _mm_shuffle_epi32(sum2, 1)); | 36 | 1.01M | return (uint32_t)_mm_cvtsi128_si32(sum3); | 37 | 1.01M | } |
Unexecuted instantiation: adler32_avx2_vnni.c:partial_hsum256 Unexecuted instantiation: adler32_avx512_vnni.c:partial_hsum256 |
38 | | #endif |
39 | | |
40 | | #endif |