/src/aom/av1/encoder/x86/encodetxb_avx2.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018, Alliance for Open Media. All rights reserved. |
3 | | * |
4 | | * This source code is subject to the terms of the BSD 2 Clause License and |
5 | | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
6 | | * was not distributed with this source code in the LICENSE file, you can |
7 | | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
8 | | * Media Patent License 1.0 was not distributed with this source code in the |
9 | | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
10 | | */ |
11 | | |
12 | | #include <assert.h> |
13 | | #include <emmintrin.h> // SSE2 |
14 | | #include <smmintrin.h> /* SSE4.1 */ |
15 | | #include <immintrin.h> /* AVX2 */ |
16 | | |
17 | | #include "aom/aom_integer.h" |
18 | | #include "aom_dsp/x86/mem_sse2.h" |
19 | | #include "av1/common/av1_common_int.h" |
20 | | #include "av1/common/txb_common.h" |
21 | | #include "aom_dsp/x86/synonyms.h" |
22 | | #include "aom_dsp/x86/synonyms_avx2.h" |
23 | | |
24 | | void av1_txb_init_levels_avx2(const tran_low_t *const coeff, const int width, |
25 | 0 | const int height, uint8_t *const levels) { |
26 | 0 | const int stride = height + TX_PAD_HOR; |
27 | 0 | const __m256i y_zeros = _mm256_setzero_si256(); |
28 | |
|
29 | 0 | const int32_t bottom_len = sizeof(*levels) * (TX_PAD_BOTTOM * stride); |
30 | 0 | uint8_t *bottom_buf_end = levels + (width + TX_PAD_BOTTOM) * stride; |
31 | 0 | uint8_t *bottom_buf = bottom_buf_end - ((bottom_len + 31) & (~31)); |
32 | |
|
33 | 0 | do { |
34 | 0 | yy_storeu_256(bottom_buf, y_zeros); |
35 | 0 | bottom_buf += 32; |
36 | 0 | } while (bottom_buf < bottom_buf_end); |
37 | |
|
38 | 0 | int i = 0; |
39 | 0 | uint8_t *ls = levels; |
40 | 0 | const tran_low_t *cf = coeff; |
41 | 0 | if (height == 4) { |
42 | 0 | do { |
43 | 0 | const __m256i c0 = yy_loadu_256(cf); |
44 | 0 | const __m256i c1 = yy_loadu_256(cf + 8); |
45 | 0 | const __m256i abs01 = _mm256_abs_epi16(_mm256_packs_epi32(c0, c1)); |
46 | 0 | const __m256i abs01_8 = _mm256_packs_epi16(abs01, y_zeros); |
47 | 0 | const __m256i res_ = _mm256_shuffle_epi32(abs01_8, 0xd8); |
48 | 0 | const __m256i res = _mm256_permute4x64_epi64(res_, 0xd8); |
49 | 0 | yy_storeu_256(ls, res); |
50 | 0 | ls += 32; |
51 | 0 | cf += 16; |
52 | 0 | i += 4; |
53 | 0 | } while (i < width); |
54 | 0 | } else if (height == 8) { |
55 | 0 | do { |
56 | 0 | const __m256i coeffA = yy_loadu_256(cf); |
57 | 0 | const __m256i coeffB = yy_loadu_256(cf + 8); |
58 | 0 | const __m256i coeffC = yy_loadu_256(cf + 16); |
59 | 0 | const __m256i coeffD = yy_loadu_256(cf + 24); |
60 | 0 | const __m256i coeffAB = _mm256_packs_epi32(coeffA, coeffB); |
61 | 0 | const __m256i coeffCD = _mm256_packs_epi32(coeffC, coeffD); |
62 | 0 | const __m256i absAB = _mm256_abs_epi16(coeffAB); |
63 | 0 | const __m256i absCD = _mm256_abs_epi16(coeffCD); |
64 | 0 | const __m256i absABCD = _mm256_packs_epi16(absAB, absCD); |
65 | 0 | const __m256i res_ = _mm256_permute4x64_epi64(absABCD, 0xd8); |
66 | 0 | const __m256i res = _mm256_shuffle_epi32(res_, 0xd8); |
67 | 0 | const __m128i res0 = _mm256_castsi256_si128(res); |
68 | 0 | const __m128i res1 = _mm256_extracti128_si256(res, 1); |
69 | 0 | xx_storel_64(ls, res0); |
70 | 0 | *(int32_t *)(ls + height) = 0; |
71 | 0 | xx_storel_64(ls + stride, _mm_srli_si128(res0, 8)); |
72 | 0 | *(int32_t *)(ls + height + stride) = 0; |
73 | 0 | xx_storel_64(ls + stride * 2, res1); |
74 | 0 | *(int32_t *)(ls + height + stride * 2) = 0; |
75 | 0 | xx_storel_64(ls + stride * 3, _mm_srli_si128(res1, 8)); |
76 | 0 | *(int32_t *)(ls + height + stride * 3) = 0; |
77 | 0 | cf += 32; |
78 | 0 | ls += stride << 2; |
79 | 0 | i += 4; |
80 | 0 | } while (i < width); |
81 | 0 | } else if (height == 16) { |
82 | 0 | do { |
83 | 0 | const __m256i coeffA = yy_loadu_256(cf); |
84 | 0 | const __m256i coeffB = yy_loadu_256(cf + 8); |
85 | 0 | const __m256i coeffC = yy_loadu_256(cf + 16); |
86 | 0 | const __m256i coeffD = yy_loadu_256(cf + 24); |
87 | 0 | const __m256i coeffAB = _mm256_packs_epi32(coeffA, coeffB); |
88 | 0 | const __m256i coeffCD = _mm256_packs_epi32(coeffC, coeffD); |
89 | 0 | const __m256i absAB = _mm256_abs_epi16(coeffAB); |
90 | 0 | const __m256i absCD = _mm256_abs_epi16(coeffCD); |
91 | 0 | const __m256i absABCD = _mm256_packs_epi16(absAB, absCD); |
92 | 0 | const __m256i res_ = _mm256_permute4x64_epi64(absABCD, 0xd8); |
93 | 0 | const __m256i res = _mm256_shuffle_epi32(res_, 0xd8); |
94 | 0 | xx_storeu_128(ls, _mm256_castsi256_si128(res)); |
95 | 0 | xx_storeu_128(ls + stride, _mm256_extracti128_si256(res, 1)); |
96 | 0 | cf += 32; |
97 | 0 | *(int32_t *)(ls + height) = 0; |
98 | 0 | *(int32_t *)(ls + stride + height) = 0; |
99 | 0 | ls += stride << 1; |
100 | 0 | i += 2; |
101 | 0 | } while (i < width); |
102 | 0 | } else { |
103 | 0 | do { |
104 | 0 | const __m256i coeffA = yy_loadu_256(cf); |
105 | 0 | const __m256i coeffB = yy_loadu_256(cf + 8); |
106 | 0 | const __m256i coeffC = yy_loadu_256(cf + 16); |
107 | 0 | const __m256i coeffD = yy_loadu_256(cf + 24); |
108 | 0 | const __m256i coeffAB = _mm256_packs_epi32(coeffA, coeffB); |
109 | 0 | const __m256i coeffCD = _mm256_packs_epi32(coeffC, coeffD); |
110 | 0 | const __m256i absAB = _mm256_abs_epi16(coeffAB); |
111 | 0 | const __m256i absCD = _mm256_abs_epi16(coeffCD); |
112 | 0 | const __m256i absABCD = _mm256_packs_epi16(absAB, absCD); |
113 | 0 | const __m256i res_ = _mm256_permute4x64_epi64(absABCD, 0xd8); |
114 | 0 | const __m256i res = _mm256_shuffle_epi32(res_, 0xd8); |
115 | 0 | yy_storeu_256(ls, res); |
116 | 0 | cf += 32; |
117 | 0 | *(int32_t *)(ls + height) = 0; |
118 | 0 | ls += stride; |
119 | 0 | i += 1; |
120 | 0 | } while (i < width); |
121 | 0 | } |
122 | 0 | } |