Coverage Report

Created: 2026-11-12 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
  assert(TX_PAD_HOR == 4 && TX_PAD_BOTTOM == 4);
27
0
  const __m256i y_zeros = _mm256_setzero_si256();
28
0
  const __m128i zero = _mm256_castsi256_si128(y_zeros);
29
30
0
  uint8_t *ls = levels;
31
0
  const tran_low_t *cf = coeff;
32
33
  // Specialize each transform height with its constant padded stride
34
  // (height + TX_PAD_HOR) and zero the TX_PAD_BOTTOM (4) trailing rows directly
35
  // after the loop.
36
0
  if (height == 4) {
37
0
    assert(width > 0 && width % 4 == 0);
38
    // Padded stride = 4 + 4 = 8; 4 rows of 4 coeffs + 4 zero-pad bytes per
39
    // iter.
40
0
    uint8_t *const ls_end = levels + width * 8;
41
0
    do {
42
0
      const __m256i c0 = yy_loadu_256(cf);
43
0
      const __m256i c1 = yy_loadu_256(cf + 8);
44
0
      const __m256i abs01 = _mm256_abs_epi16(_mm256_packs_epi32(c0, c1));
45
0
      const __m256i abs01_8 = _mm256_packs_epi16(abs01, y_zeros);
46
0
      const __m256i res_ = _mm256_shuffle_epi32(abs01_8, 0xd8);
47
0
      const __m256i res = _mm256_permute4x64_epi64(res_, 0xd8);
48
0
      yy_storeu_256(ls, res);
49
0
      ls += 32;
50
0
      cf += 16;
51
0
    } while (ls < ls_end);
52
    // Zero 4 bottom padding rows (4 * 8 = 32 bytes).
53
0
    yy_storeu_256(ls, y_zeros);
54
0
  } else if (height == 8) {
55
0
    assert(width > 0 && width % 4 == 0);
56
    // Padded stride = 8 + 4 = 12; 4 rows per iteration (4 * 12 = 48 bytes).
57
0
    uint8_t *const ls_end = levels + width * 12;
58
0
    do {
59
0
      const __m256i coeffA = yy_loadu_256(cf);
60
0
      const __m256i coeffB = yy_loadu_256(cf + 8);
61
0
      const __m256i coeffC = yy_loadu_256(cf + 16);
62
0
      const __m256i coeffD = yy_loadu_256(cf + 24);
63
0
      const __m256i coeffAB = _mm256_packs_epi32(coeffA, coeffB);
64
0
      const __m256i coeffCD = _mm256_packs_epi32(coeffC, coeffD);
65
0
      const __m256i absAB = _mm256_abs_epi16(coeffAB);
66
0
      const __m256i absCD = _mm256_abs_epi16(coeffCD);
67
0
      const __m256i absABCD = _mm256_packs_epi16(absAB, absCD);
68
0
      const __m256i res_ = _mm256_permute4x64_epi64(absABCD, 0xd8);
69
0
      const __m256i res = _mm256_shuffle_epi32(res_, 0xd8);
70
0
      const __m128i res0 = _mm256_castsi256_si128(res);
71
0
      const __m128i res1 = _mm256_extracti128_si256(res, 1);
72
73
0
      xx_storel_64(ls, res0);
74
0
      xx_storel_32(ls + 8, zero);
75
0
      xx_storel_64(ls + 12, _mm_srli_si128(res0, 8));
76
0
      xx_storel_32(ls + 20, zero);
77
0
      xx_storel_64(ls + 24, res1);
78
0
      xx_storel_32(ls + 32, zero);
79
0
      xx_storel_64(ls + 36, _mm_srli_si128(res1, 8));
80
0
      xx_storel_32(ls + 44, zero);
81
0
      cf += 32;
82
0
      ls += 48;
83
0
    } while (ls < ls_end);
84
    // Zero 4 bottom padding rows (4 * 12 = 48 bytes).
85
0
    yy_storeu_256(ls, y_zeros);
86
0
    xx_storeu_128(ls + 32, zero);
87
0
  } else if (height == 16) {
88
0
    assert(width > 0 && width % 2 == 0);
89
    // Padded stride = 16 + 4 = 20; 2 rows per iteration (2 * 20 = 40 bytes).
90
0
    uint8_t *const ls_end = levels + width * 20;
91
0
    do {
92
0
      const __m256i coeffA = yy_loadu_256(cf);
93
0
      const __m256i coeffB = yy_loadu_256(cf + 8);
94
0
      const __m256i coeffC = yy_loadu_256(cf + 16);
95
0
      const __m256i coeffD = yy_loadu_256(cf + 24);
96
0
      const __m256i coeffAB = _mm256_packs_epi32(coeffA, coeffB);
97
0
      const __m256i coeffCD = _mm256_packs_epi32(coeffC, coeffD);
98
0
      const __m256i absAB = _mm256_abs_epi16(coeffAB);
99
0
      const __m256i absCD = _mm256_abs_epi16(coeffCD);
100
0
      const __m256i absABCD = _mm256_packs_epi16(absAB, absCD);
101
0
      const __m256i res_ = _mm256_permute4x64_epi64(absABCD, 0xd8);
102
0
      const __m256i res = _mm256_shuffle_epi32(res_, 0xd8);
103
104
0
      xx_storeu_128(ls, _mm256_castsi256_si128(res));
105
0
      xx_storeu_128(ls + 20, _mm256_extracti128_si256(res, 1));
106
0
      cf += 32;
107
0
      xx_storel_32(ls + 16, zero);
108
0
      xx_storel_32(ls + 36, zero);
109
0
      ls += 40;
110
0
    } while (ls < ls_end);
111
    // Zero 4 bottom padding rows (4 * 20 = 80 bytes).
112
0
    yy_storeu_256(ls, y_zeros);
113
0
    yy_storeu_256(ls + 32, y_zeros);
114
0
    xx_storeu_128(ls + 64, zero);
115
0
  } else {
116
0
    assert(height == 32 && width > 0);
117
    // Padded stride = 32 + 4 = 36; 1 row per iteration (36 bytes).
118
0
    uint8_t *const ls_end = levels + width * 36;
119
0
    do {
120
0
      const __m256i coeffA = yy_loadu_256(cf);
121
0
      const __m256i coeffB = yy_loadu_256(cf + 8);
122
0
      const __m256i coeffC = yy_loadu_256(cf + 16);
123
0
      const __m256i coeffD = yy_loadu_256(cf + 24);
124
0
      const __m256i coeffAB = _mm256_packs_epi32(coeffA, coeffB);
125
0
      const __m256i coeffCD = _mm256_packs_epi32(coeffC, coeffD);
126
0
      const __m256i absAB = _mm256_abs_epi16(coeffAB);
127
0
      const __m256i absCD = _mm256_abs_epi16(coeffCD);
128
0
      const __m256i absABCD = _mm256_packs_epi16(absAB, absCD);
129
0
      const __m256i res_ = _mm256_permute4x64_epi64(absABCD, 0xd8);
130
0
      const __m256i res = _mm256_shuffle_epi32(res_, 0xd8);
131
132
0
      yy_storeu_256(ls, res);
133
0
      cf += 32;
134
0
      xx_storel_32(ls + 32, zero);
135
0
      ls += 36;
136
0
    } while (ls < ls_end);
137
    // Zero 4 bottom padding rows (4 * 36 = 144 bytes).
138
0
    yy_storeu_256(ls, y_zeros);
139
0
    yy_storeu_256(ls + 32, y_zeros);
140
0
    yy_storeu_256(ls + 64, y_zeros);
141
0
    yy_storeu_256(ls + 96, y_zeros);
142
0
    xx_storeu_128(ls + 128, zero);
143
0
  }
144
0
}