Coverage Report

Created: 2026-08-14 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/common/txb_common.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2017, 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
#ifndef AOM_AV1_COMMON_TXB_COMMON_H_
13
#define AOM_AV1_COMMON_TXB_COMMON_H_
14
15
#include "av1/common/av1_common_int.h"
16
17
extern const int16_t av1_eob_group_start[12];
18
extern const int16_t av1_eob_offset_bits[12];
19
20
extern const int8_t *av1_nz_map_ctx_offset[TX_SIZES_ALL];
21
22
typedef struct txb_ctx {
23
  int txb_skip_ctx;
24
  int dc_sign_ctx;
25
} TXB_CTX;
26
27
static const int base_level_count_to_index[13] = {
28
  0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
29
};
30
31
static const TX_CLASS tx_type_to_class[TX_TYPES] = {
32
  TX_CLASS_2D,     // DCT_DCT
33
  TX_CLASS_2D,     // ADST_DCT
34
  TX_CLASS_2D,     // DCT_ADST
35
  TX_CLASS_2D,     // ADST_ADST
36
  TX_CLASS_2D,     // FLIPADST_DCT
37
  TX_CLASS_2D,     // DCT_FLIPADST
38
  TX_CLASS_2D,     // FLIPADST_FLIPADST
39
  TX_CLASS_2D,     // ADST_FLIPADST
40
  TX_CLASS_2D,     // FLIPADST_ADST
41
  TX_CLASS_2D,     // IDTX
42
  TX_CLASS_VERT,   // V_DCT
43
  TX_CLASS_HORIZ,  // H_DCT
44
  TX_CLASS_VERT,   // V_ADST
45
  TX_CLASS_HORIZ,  // H_ADST
46
  TX_CLASS_VERT,   // V_FLIPADST
47
  TX_CLASS_HORIZ,  // H_FLIPADST
48
};
49
50
29.3M
static inline int get_txb_bhl(TX_SIZE tx_size) {
51
29.3M
  tx_size = av1_get_adjusted_tx_size(tx_size);
52
29.3M
  return tx_size_high_log2[tx_size];
53
29.3M
}
decodetxb.c:get_txb_bhl
Line
Count
Source
50
29.3M
static inline int get_txb_bhl(TX_SIZE tx_size) {
51
29.3M
  tx_size = av1_get_adjusted_tx_size(tx_size);
52
29.3M
  return tx_size_high_log2[tx_size];
53
29.3M
}
Unexecuted instantiation: entropy.c:get_txb_bhl
Unexecuted instantiation: entropymode.c:get_txb_bhl
Unexecuted instantiation: txb_common.c:get_txb_bhl
54
55
29.4M
static inline int get_txb_wide(TX_SIZE tx_size) {
56
29.4M
  tx_size = av1_get_adjusted_tx_size(tx_size);
57
29.4M
  return tx_size_wide[tx_size];
58
29.4M
}
decodetxb.c:get_txb_wide
Line
Count
Source
55
29.4M
static inline int get_txb_wide(TX_SIZE tx_size) {
56
29.4M
  tx_size = av1_get_adjusted_tx_size(tx_size);
57
29.4M
  return tx_size_wide[tx_size];
58
29.4M
}
Unexecuted instantiation: entropy.c:get_txb_wide
Unexecuted instantiation: entropymode.c:get_txb_wide
Unexecuted instantiation: txb_common.c:get_txb_wide
59
60
29.4M
static inline int get_txb_high(TX_SIZE tx_size) {
61
29.4M
  tx_size = av1_get_adjusted_tx_size(tx_size);
62
29.4M
  return tx_size_high[tx_size];
63
29.4M
}
decodetxb.c:get_txb_high
Line
Count
Source
60
29.4M
static inline int get_txb_high(TX_SIZE tx_size) {
61
29.4M
  tx_size = av1_get_adjusted_tx_size(tx_size);
62
29.4M
  return tx_size_high[tx_size];
63
29.4M
}
Unexecuted instantiation: entropy.c:get_txb_high
Unexecuted instantiation: entropymode.c:get_txb_high
Unexecuted instantiation: txb_common.c:get_txb_high
64
65
29.2M
static inline uint8_t *set_levels(uint8_t *const levels_buf, const int height) {
66
29.2M
  return levels_buf + TX_PAD_TOP * (height + TX_PAD_HOR);
67
29.2M
}
decodetxb.c:set_levels
Line
Count
Source
65
29.2M
static inline uint8_t *set_levels(uint8_t *const levels_buf, const int height) {
66
29.2M
  return levels_buf + TX_PAD_TOP * (height + TX_PAD_HOR);
67
29.2M
}
Unexecuted instantiation: entropy.c:set_levels
Unexecuted instantiation: entropymode.c:set_levels
Unexecuted instantiation: txb_common.c:set_levels
68
69
675M
static inline int get_padded_idx(const int idx, const int bhl) {
70
675M
  return idx + ((idx >> bhl) << TX_PAD_HOR_LOG2);
71
675M
}
decodetxb.c:get_padded_idx
Line
Count
Source
69
675M
static inline int get_padded_idx(const int idx, const int bhl) {
70
675M
  return idx + ((idx >> bhl) << TX_PAD_HOR_LOG2);
71
675M
}
Unexecuted instantiation: entropy.c:get_padded_idx
Unexecuted instantiation: entropymode.c:get_padded_idx
Unexecuted instantiation: txb_common.c:get_padded_idx
72
73
static inline int get_br_ctx_2d(const uint8_t *const levels,
74
                                const int c,  // raster order
75
12.2M
                                const int bhl) {
76
12.2M
  assert(c > 0);
77
12.2M
  const int col = c >> bhl;
78
12.2M
  const int row = c - (col << bhl);
79
12.2M
  const int stride = (1 << bhl) + TX_PAD_HOR;
80
12.2M
  const int pos = col * stride + row;
81
12.2M
  int mag = AOMMIN(levels[pos + 1], MAX_BASE_BR_RANGE) +
82
12.2M
            AOMMIN(levels[pos + stride], MAX_BASE_BR_RANGE) +
83
12.2M
            AOMMIN(levels[pos + 1 + stride], MAX_BASE_BR_RANGE);
84
12.2M
  mag = AOMMIN((mag + 1) >> 1, 6);
85
  //((row | col) < 2) is equivalent to ((row < 2) && (col < 2))
86
12.2M
  if ((row | col) < 2) return mag + 7;
87
9.86M
  return mag + 14;
88
12.2M
}
decodetxb.c:get_br_ctx_2d
Line
Count
Source
75
12.2M
                                const int bhl) {
76
12.2M
  assert(c > 0);
77
12.2M
  const int col = c >> bhl;
78
12.2M
  const int row = c - (col << bhl);
79
12.2M
  const int stride = (1 << bhl) + TX_PAD_HOR;
80
12.2M
  const int pos = col * stride + row;
81
12.2M
  int mag = AOMMIN(levels[pos + 1], MAX_BASE_BR_RANGE) +
82
12.2M
            AOMMIN(levels[pos + stride], MAX_BASE_BR_RANGE) +
83
12.2M
            AOMMIN(levels[pos + 1 + stride], MAX_BASE_BR_RANGE);
84
12.2M
  mag = AOMMIN((mag + 1) >> 1, 6);
85
  //((row | col) < 2) is equivalent to ((row < 2) && (col < 2))
86
12.2M
  if ((row | col) < 2) return mag + 7;
87
9.86M
  return mag + 14;
88
12.2M
}
Unexecuted instantiation: entropy.c:get_br_ctx_2d
Unexecuted instantiation: entropymode.c:get_br_ctx_2d
Unexecuted instantiation: txb_common.c:get_br_ctx_2d
89
90
static AOM_FORCE_INLINE int get_br_ctx_eob(const int c,  // raster order
91
                                           const int bhl,
92
471k
                                           const TX_CLASS tx_class) {
93
471k
  const int col = c >> bhl;
94
471k
  const int row = c - (col << bhl);
95
471k
  if (c == 0) return 0;
96
126k
  if ((tx_class == TX_CLASS_2D && row < 2 && col < 2) ||
97
114k
      (tx_class == TX_CLASS_HORIZ && col == 0) ||
98
113k
      (tx_class == TX_CLASS_VERT && row == 0))
99
13.7k
    return 7;
100
112k
  return 14;
101
126k
}
decodetxb.c:get_br_ctx_eob
Line
Count
Source
92
471k
                                           const TX_CLASS tx_class) {
93
471k
  const int col = c >> bhl;
94
471k
  const int row = c - (col << bhl);
95
471k
  if (c == 0) return 0;
96
126k
  if ((tx_class == TX_CLASS_2D && row < 2 && col < 2) ||
97
114k
      (tx_class == TX_CLASS_HORIZ && col == 0) ||
98
113k
      (tx_class == TX_CLASS_VERT && row == 0))
99
13.7k
    return 7;
100
112k
  return 14;
101
126k
}
Unexecuted instantiation: entropy.c:get_br_ctx_eob
Unexecuted instantiation: entropymode.c:get_br_ctx_eob
Unexecuted instantiation: txb_common.c:get_br_ctx_eob
102
103
static AOM_FORCE_INLINE int get_br_ctx(const uint8_t *const levels,
104
                                       const int c,  // raster order
105
3.84M
                                       const int bhl, const TX_CLASS tx_class) {
106
3.84M
  const int col = c >> bhl;
107
3.84M
  const int row = c - (col << bhl);
108
3.84M
  const int stride = (1 << bhl) + TX_PAD_HOR;
109
3.84M
  const int pos = col * stride + row;
110
3.84M
  int mag = levels[pos + 1];
111
3.84M
  mag += levels[pos + stride];
112
3.84M
  switch (tx_class) {
113
2.86M
    case TX_CLASS_2D:
114
2.86M
      mag += levels[pos + stride + 1];
115
2.86M
      mag = AOMMIN((mag + 1) >> 1, 6);
116
2.86M
      if (c == 0) return mag;
117
14
      if ((row < 2) && (col < 2)) return mag + 7;
118
14
      break;
119
669k
    case TX_CLASS_HORIZ:
120
669k
      mag += levels[pos + (stride << 1)];
121
669k
      mag = AOMMIN((mag + 1) >> 1, 6);
122
669k
      if (c == 0) return mag;
123
605k
      if (col == 0) return mag + 7;
124
359k
      break;
125
359k
    case TX_CLASS_VERT:
126
320k
      mag += levels[pos + 2];
127
320k
      mag = AOMMIN((mag + 1) >> 1, 6);
128
320k
      if (c == 0) return mag;
129
289k
      if (row == 0) return mag + 7;
130
166k
      break;
131
166k
    default: break;
132
3.84M
  }
133
134
529k
  return mag + 14;
135
3.84M
}
decodetxb.c:get_br_ctx
Line
Count
Source
105
3.84M
                                       const int bhl, const TX_CLASS tx_class) {
106
3.84M
  const int col = c >> bhl;
107
3.84M
  const int row = c - (col << bhl);
108
3.84M
  const int stride = (1 << bhl) + TX_PAD_HOR;
109
3.84M
  const int pos = col * stride + row;
110
3.84M
  int mag = levels[pos + 1];
111
3.84M
  mag += levels[pos + stride];
112
3.84M
  switch (tx_class) {
113
2.86M
    case TX_CLASS_2D:
114
2.86M
      mag += levels[pos + stride + 1];
115
2.86M
      mag = AOMMIN((mag + 1) >> 1, 6);
116
2.86M
      if (c == 0) return mag;
117
14
      if ((row < 2) && (col < 2)) return mag + 7;
118
14
      break;
119
669k
    case TX_CLASS_HORIZ:
120
669k
      mag += levels[pos + (stride << 1)];
121
669k
      mag = AOMMIN((mag + 1) >> 1, 6);
122
669k
      if (c == 0) return mag;
123
605k
      if (col == 0) return mag + 7;
124
359k
      break;
125
359k
    case TX_CLASS_VERT:
126
320k
      mag += levels[pos + 2];
127
320k
      mag = AOMMIN((mag + 1) >> 1, 6);
128
320k
      if (c == 0) return mag;
129
289k
      if (row == 0) return mag + 7;
130
166k
      break;
131
166k
    default: break;
132
3.84M
  }
133
134
529k
  return mag + 14;
135
3.84M
}
Unexecuted instantiation: entropy.c:get_br_ctx
Unexecuted instantiation: entropymode.c:get_br_ctx
Unexecuted instantiation: txb_common.c:get_br_ctx
136
137
static const uint8_t clip_max3[256] = {
138
  0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
139
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
140
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
141
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
142
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
143
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
144
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
145
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
146
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
147
  3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3
148
};
149
150
static AOM_FORCE_INLINE int get_nz_mag(const uint8_t *const levels,
151
27.0M
                                       const int bhl, const TX_CLASS tx_class) {
152
27.0M
  int mag;
153
154
  // Note: AOMMIN(level, 3) is useless for decoder since level < 3.
155
27.0M
  mag = clip_max3[levels[(1 << bhl) + TX_PAD_HOR]];  // { 0, 1 }
156
27.0M
  mag += clip_max3[levels[1]];                       // { 1, 0 }
157
158
27.0M
  if (tx_class == TX_CLASS_2D) {
159
8.22M
    mag += clip_max3[levels[(1 << bhl) + TX_PAD_HOR + 1]];          // { 1, 1 }
160
8.22M
    mag += clip_max3[levels[(2 << bhl) + (2 << TX_PAD_HOR_LOG2)]];  // { 0, 2 }
161
8.22M
    mag += clip_max3[levels[2]];                                    // { 2, 0 }
162
18.7M
  } else if (tx_class == TX_CLASS_VERT) {
163
6.30M
    mag += clip_max3[levels[2]];  // { 2, 0 }
164
6.30M
    mag += clip_max3[levels[3]];  // { 3, 0 }
165
6.30M
    mag += clip_max3[levels[4]];  // { 4, 0 }
166
12.4M
  } else {
167
12.4M
    mag += clip_max3[levels[(2 << bhl) + (2 << TX_PAD_HOR_LOG2)]];  // { 0, 2 }
168
12.4M
    mag += clip_max3[levels[(3 << bhl) + (3 << TX_PAD_HOR_LOG2)]];  // { 0, 3 }
169
12.4M
    mag += clip_max3[levels[(4 << bhl) + (4 << TX_PAD_HOR_LOG2)]];  // { 0, 4 }
170
12.4M
  }
171
172
27.0M
  return mag;
173
27.0M
}
decodetxb.c:get_nz_mag
Line
Count
Source
151
27.0M
                                       const int bhl, const TX_CLASS tx_class) {
152
27.0M
  int mag;
153
154
  // Note: AOMMIN(level, 3) is useless for decoder since level < 3.
155
27.0M
  mag = clip_max3[levels[(1 << bhl) + TX_PAD_HOR]];  // { 0, 1 }
156
27.0M
  mag += clip_max3[levels[1]];                       // { 1, 0 }
157
158
27.0M
  if (tx_class == TX_CLASS_2D) {
159
8.22M
    mag += clip_max3[levels[(1 << bhl) + TX_PAD_HOR + 1]];          // { 1, 1 }
160
8.22M
    mag += clip_max3[levels[(2 << bhl) + (2 << TX_PAD_HOR_LOG2)]];  // { 0, 2 }
161
8.22M
    mag += clip_max3[levels[2]];                                    // { 2, 0 }
162
18.7M
  } else if (tx_class == TX_CLASS_VERT) {
163
6.30M
    mag += clip_max3[levels[2]];  // { 2, 0 }
164
6.30M
    mag += clip_max3[levels[3]];  // { 3, 0 }
165
6.30M
    mag += clip_max3[levels[4]];  // { 4, 0 }
166
12.4M
  } else {
167
12.4M
    mag += clip_max3[levels[(2 << bhl) + (2 << TX_PAD_HOR_LOG2)]];  // { 0, 2 }
168
12.4M
    mag += clip_max3[levels[(3 << bhl) + (3 << TX_PAD_HOR_LOG2)]];  // { 0, 3 }
169
12.4M
    mag += clip_max3[levels[(4 << bhl) + (4 << TX_PAD_HOR_LOG2)]];  // { 0, 4 }
170
12.4M
  }
171
172
27.0M
  return mag;
173
27.0M
}
Unexecuted instantiation: entropy.c:get_nz_mag
Unexecuted instantiation: entropymode.c:get_nz_mag
Unexecuted instantiation: txb_common.c:get_nz_mag
174
175
#define NZ_MAP_CTX_0 SIG_COEF_CONTEXTS_2D
176
#define NZ_MAP_CTX_5 (NZ_MAP_CTX_0 + 5)
177
#define NZ_MAP_CTX_10 (NZ_MAP_CTX_0 + 10)
178
179
static const int nz_map_ctx_offset_1d[32] = {
180
  NZ_MAP_CTX_0,  NZ_MAP_CTX_5,  NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10,
181
  NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10,
182
  NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10,
183
  NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10,
184
  NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10,
185
  NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10, NZ_MAP_CTX_10,
186
  NZ_MAP_CTX_10, NZ_MAP_CTX_10,
187
};
188
189
static AOM_FORCE_INLINE int get_nz_map_ctx_from_stats(
190
    const int stats,
191
    const int coeff_idx,  // raster order
192
27.0M
    const int bhl, const TX_SIZE tx_size, const TX_CLASS tx_class) {
193
  // tx_class == 0(TX_CLASS_2D)
194
27.0M
  if ((tx_class | coeff_idx) == 0) return 0;
195
18.7M
  int ctx = (stats + 1) >> 1;
196
18.7M
  ctx = AOMMIN(ctx, 4);
197
18.7M
  switch (tx_class) {
198
0
    case TX_CLASS_2D: {
199
      // This is the algorithm to generate av1_nz_map_ctx_offset[][]
200
      //   const int width = tx_size_wide[tx_size];
201
      //   const int height = tx_size_high[tx_size];
202
      //   if (width < height) {
203
      //     if (row < 2) return 11 + ctx;
204
      //   } else if (width > height) {
205
      //     if (col < 2) return 16 + ctx;
206
      //   }
207
      //   if (row + col < 2) return ctx + 1;
208
      //   if (row + col < 4) return 5 + ctx + 1;
209
      //   return 21 + ctx;
210
0
      return ctx + av1_nz_map_ctx_offset[tx_size][coeff_idx];
211
0
    }
212
12.6M
    case TX_CLASS_HORIZ: {
213
12.6M
      const int col = coeff_idx >> bhl;
214
12.6M
      return ctx + nz_map_ctx_offset_1d[col];
215
0
    }
216
6.30M
    case TX_CLASS_VERT: {
217
6.30M
      const int col = coeff_idx >> bhl;
218
6.30M
      const int row = coeff_idx - (col << bhl);
219
6.30M
      return ctx + nz_map_ctx_offset_1d[row];
220
0
    }
221
0
    default: break;
222
18.7M
  }
223
0
  return 0;
224
18.7M
}
decodetxb.c:get_nz_map_ctx_from_stats
Line
Count
Source
192
27.0M
    const int bhl, const TX_SIZE tx_size, const TX_CLASS tx_class) {
193
  // tx_class == 0(TX_CLASS_2D)
194
27.0M
  if ((tx_class | coeff_idx) == 0) return 0;
195
18.7M
  int ctx = (stats + 1) >> 1;
196
18.7M
  ctx = AOMMIN(ctx, 4);
197
18.7M
  switch (tx_class) {
198
0
    case TX_CLASS_2D: {
199
      // This is the algorithm to generate av1_nz_map_ctx_offset[][]
200
      //   const int width = tx_size_wide[tx_size];
201
      //   const int height = tx_size_high[tx_size];
202
      //   if (width < height) {
203
      //     if (row < 2) return 11 + ctx;
204
      //   } else if (width > height) {
205
      //     if (col < 2) return 16 + ctx;
206
      //   }
207
      //   if (row + col < 2) return ctx + 1;
208
      //   if (row + col < 4) return 5 + ctx + 1;
209
      //   return 21 + ctx;
210
0
      return ctx + av1_nz_map_ctx_offset[tx_size][coeff_idx];
211
0
    }
212
12.6M
    case TX_CLASS_HORIZ: {
213
12.6M
      const int col = coeff_idx >> bhl;
214
12.6M
      return ctx + nz_map_ctx_offset_1d[col];
215
0
    }
216
6.30M
    case TX_CLASS_VERT: {
217
6.30M
      const int col = coeff_idx >> bhl;
218
6.30M
      const int row = coeff_idx - (col << bhl);
219
6.30M
      return ctx + nz_map_ctx_offset_1d[row];
220
0
    }
221
0
    default: break;
222
18.7M
  }
223
0
  return 0;
224
18.7M
}
Unexecuted instantiation: entropy.c:get_nz_map_ctx_from_stats
Unexecuted instantiation: entropymode.c:get_nz_map_ctx_from_stats
Unexecuted instantiation: txb_common.c:get_nz_map_ctx_from_stats
225
226
typedef aom_cdf_prob (*base_cdf_arr)[CDF_SIZE(4)];
227
typedef aom_cdf_prob (*br_cdf_arr)[CDF_SIZE(BR_CDF_SIZE)];
228
229
16.6M
static inline int get_lower_levels_ctx_eob(int bhl, int width, int scan_idx) {
230
16.6M
  if (scan_idx == 0) return 0;
231
9.11M
  if (scan_idx <= (width << bhl) / 8) return 1;
232
4.58M
  if (scan_idx <= (width << bhl) / 4) return 2;
233
3.23M
  return 3;
234
4.58M
}
decodetxb.c:get_lower_levels_ctx_eob
Line
Count
Source
229
16.6M
static inline int get_lower_levels_ctx_eob(int bhl, int width, int scan_idx) {
230
16.6M
  if (scan_idx == 0) return 0;
231
9.11M
  if (scan_idx <= (width << bhl) / 8) return 1;
232
4.58M
  if (scan_idx <= (width << bhl) / 4) return 2;
233
3.23M
  return 3;
234
4.58M
}
Unexecuted instantiation: entropy.c:get_lower_levels_ctx_eob
Unexecuted instantiation: entropymode.c:get_lower_levels_ctx_eob
Unexecuted instantiation: txb_common.c:get_lower_levels_ctx_eob
235
236
static inline int get_lower_levels_ctx_2d(const uint8_t *levels, int coeff_idx,
237
190M
                                          int bhl, TX_SIZE tx_size) {
238
190M
  assert(coeff_idx > 0);
239
190M
  int mag;
240
  // Note: AOMMIN(level, 3) is useless for decoder since level < 3.
241
190M
  levels = levels + get_padded_idx(coeff_idx, bhl);
242
190M
  mag = AOMMIN(levels[(1 << bhl) + TX_PAD_HOR], 3);               // { 0, 1 }
243
190M
  mag += AOMMIN(levels[1], 3);                                    // { 1, 0 }
244
190M
  mag += AOMMIN(levels[(1 << bhl) + TX_PAD_HOR + 1], 3);          // { 1, 1 }
245
190M
  mag += AOMMIN(levels[(2 << bhl) + (2 << TX_PAD_HOR_LOG2)], 3);  // { 0, 2 }
246
190M
  mag += AOMMIN(levels[2], 3);                                    // { 2, 0 }
247
248
190M
  const int ctx = AOMMIN((mag + 1) >> 1, 4);
249
190M
  return ctx + av1_nz_map_ctx_offset[tx_size][coeff_idx];
250
190M
}
decodetxb.c:get_lower_levels_ctx_2d
Line
Count
Source
237
190M
                                          int bhl, TX_SIZE tx_size) {
238
190M
  assert(coeff_idx > 0);
239
190M
  int mag;
240
  // Note: AOMMIN(level, 3) is useless for decoder since level < 3.
241
190M
  levels = levels + get_padded_idx(coeff_idx, bhl);
242
190M
  mag = AOMMIN(levels[(1 << bhl) + TX_PAD_HOR], 3);               // { 0, 1 }
243
190M
  mag += AOMMIN(levels[1], 3);                                    // { 1, 0 }
244
190M
  mag += AOMMIN(levels[(1 << bhl) + TX_PAD_HOR + 1], 3);          // { 1, 1 }
245
190M
  mag += AOMMIN(levels[(2 << bhl) + (2 << TX_PAD_HOR_LOG2)], 3);  // { 0, 2 }
246
190M
  mag += AOMMIN(levels[2], 3);                                    // { 2, 0 }
247
248
190M
  const int ctx = AOMMIN((mag + 1) >> 1, 4);
249
190M
  return ctx + av1_nz_map_ctx_offset[tx_size][coeff_idx];
250
190M
}
Unexecuted instantiation: entropy.c:get_lower_levels_ctx_2d
Unexecuted instantiation: entropymode.c:get_lower_levels_ctx_2d
Unexecuted instantiation: txb_common.c:get_lower_levels_ctx_2d
251
static AOM_FORCE_INLINE int get_lower_levels_ctx(const uint8_t *levels,
252
                                                 int coeff_idx, int bhl,
253
                                                 TX_SIZE tx_size,
254
27.0M
                                                 TX_CLASS tx_class) {
255
27.0M
  const int stats =
256
27.0M
      get_nz_mag(levels + get_padded_idx(coeff_idx, bhl), bhl, tx_class);
257
27.0M
  return get_nz_map_ctx_from_stats(stats, coeff_idx, bhl, tx_size, tx_class);
258
27.0M
}
decodetxb.c:get_lower_levels_ctx
Line
Count
Source
254
27.0M
                                                 TX_CLASS tx_class) {
255
27.0M
  const int stats =
256
27.0M
      get_nz_mag(levels + get_padded_idx(coeff_idx, bhl), bhl, tx_class);
257
27.0M
  return get_nz_map_ctx_from_stats(stats, coeff_idx, bhl, tx_size, tx_class);
258
27.0M
}
Unexecuted instantiation: entropy.c:get_lower_levels_ctx
Unexecuted instantiation: entropymode.c:get_lower_levels_ctx
Unexecuted instantiation: txb_common.c:get_lower_levels_ctx
259
260
static inline int get_lower_levels_ctx_general(int is_last, int scan_idx,
261
                                               int bhl, int width,
262
                                               const uint8_t *levels,
263
                                               int coeff_idx, TX_SIZE tx_size,
264
0
                                               TX_CLASS tx_class) {
265
0
  if (is_last) {
266
0
    if (scan_idx == 0) return 0;
267
0
    if (scan_idx <= (width << bhl) >> 3) return 1;
268
0
    if (scan_idx <= (width << bhl) >> 2) return 2;
269
0
    return 3;
270
0
  }
271
0
  return get_lower_levels_ctx(levels, coeff_idx, bhl, tx_size, tx_class);
272
0
}
Unexecuted instantiation: decodetxb.c:get_lower_levels_ctx_general
Unexecuted instantiation: entropy.c:get_lower_levels_ctx_general
Unexecuted instantiation: entropymode.c:get_lower_levels_ctx_general
Unexecuted instantiation: txb_common.c:get_lower_levels_ctx_general
273
274
16.2M
static inline void set_dc_sign(int *cul_level, int dc_val) {
275
16.2M
  if (dc_val < 0)
276
4.34M
    *cul_level |= 1 << COEFF_CONTEXT_BITS;
277
11.9M
  else if (dc_val > 0)
278
9.40M
    *cul_level += 2 << COEFF_CONTEXT_BITS;
279
16.2M
}
decodetxb.c:set_dc_sign
Line
Count
Source
274
16.2M
static inline void set_dc_sign(int *cul_level, int dc_val) {
275
16.2M
  if (dc_val < 0)
276
4.34M
    *cul_level |= 1 << COEFF_CONTEXT_BITS;
277
11.9M
  else if (dc_val > 0)
278
9.40M
    *cul_level += 2 << COEFF_CONTEXT_BITS;
279
16.2M
}
Unexecuted instantiation: entropy.c:set_dc_sign
Unexecuted instantiation: entropymode.c:set_dc_sign
Unexecuted instantiation: txb_common.c:set_dc_sign
280
281
29.6M
#define MAX_TX_SIZE_UNIT 16
282
static const int8_t kTxbCtxSigns[3] = { 0, -1, 1 };
283
static const int8_t kTxbCtxDcSignContexts[4 * MAX_TX_SIZE_UNIT + 1] = {
284
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
285
  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
286
  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
287
};
288
289
// This is the algorithm to generate table kTxbCtxSkipContexts[top][left].
290
//    const int max = AOMMIN(top | left, 4);
291
//    const int min = AOMMIN(AOMMIN(top, left), 4);
292
//    if (!max)
293
//      txb_skip_ctx = 1;
294
//    else if (!min)
295
//      txb_skip_ctx = 2 + (max > 3);
296
//    else if (max <= 3)
297
//      txb_skip_ctx = 4;
298
//    else if (min <= 3)
299
//      txb_skip_ctx = 5;
300
//    else
301
//      txb_skip_ctx = 6;
302
static const uint8_t kTxbCtxSkipContexts[5][5] = { { 1, 2, 2, 2, 3 },
303
                                                   { 2, 4, 4, 4, 5 },
304
                                                   { 2, 4, 4, 4, 5 },
305
                                                   { 2, 4, 4, 4, 5 },
306
                                                   { 3, 5, 5, 5, 6 } };
307
308
static void get_txb_ctx_general(const BLOCK_SIZE plane_bsize,
309
                                const TX_SIZE tx_size, const int plane,
310
                                const ENTROPY_CONTEXT *const a,
311
                                const ENTROPY_CONTEXT *const l,
312
13.1M
                                TXB_CTX *const txb_ctx) {
313
13.1M
  const int txb_w_unit = tx_size_wide_unit[tx_size];
314
13.1M
  const int txb_h_unit = tx_size_high_unit[tx_size];
315
13.1M
  int dc_sign = 0;
316
13.1M
  int k = 0;
317
318
60.7M
  do {
319
60.7M
    const unsigned int sign = ((uint8_t)a[k]) >> COEFF_CONTEXT_BITS;
320
60.7M
    assert(sign <= 2);
321
60.7M
    dc_sign += kTxbCtxSigns[sign];
322
60.7M
  } while (++k < txb_w_unit);
323
324
13.1M
  k = 0;
325
39.4M
  do {
326
39.4M
    const unsigned int sign = ((uint8_t)l[k]) >> COEFF_CONTEXT_BITS;
327
39.4M
    assert(sign <= 2);
328
39.4M
    dc_sign += kTxbCtxSigns[sign];
329
39.4M
  } while (++k < txb_h_unit);
330
331
13.1M
  txb_ctx->dc_sign_ctx = kTxbCtxDcSignContexts[dc_sign + 2 * MAX_TX_SIZE_UNIT];
332
333
13.1M
  if (plane == 0) {
334
5.44M
    if (plane_bsize == txsize_to_bsize[tx_size]) {
335
4.79M
      txb_ctx->txb_skip_ctx = 0;
336
4.79M
    } else {
337
      // For top and left, we only care about which of the following three
338
      // categories they belong to: { 0 }, { 1, 2, 3 }, or { 4, 5, ... }. The
339
      // spec calculates top and left with the Max() function. We can calculate
340
      // an approximate max with bitwise OR because the real max and the
341
      // approximate max belong to the same category.
342
646k
      int top = 0;
343
646k
      int left = 0;
344
345
646k
      k = 0;
346
7.79M
      do {
347
7.79M
        top |= a[k];
348
7.79M
      } while (++k < txb_w_unit);
349
646k
      top &= COEFF_CONTEXT_MASK;
350
646k
      top = AOMMIN(top, 4);
351
352
646k
      k = 0;
353
7.71M
      do {
354
7.71M
        left |= l[k];
355
7.71M
      } while (++k < txb_h_unit);
356
646k
      left &= COEFF_CONTEXT_MASK;
357
646k
      left = AOMMIN(left, 4);
358
359
646k
      txb_ctx->txb_skip_ctx = kTxbCtxSkipContexts[top][left];
360
646k
    }
361
7.67M
  } else {
362
7.67M
    const int ctx_base = get_entropy_context(tx_size, a, l);
363
7.67M
    const int ctx_offset = (num_pels_log2_lookup[plane_bsize] >
364
7.67M
                            num_pels_log2_lookup[txsize_to_bsize[tx_size]])
365
7.67M
                               ? 10
366
7.67M
                               : 7;
367
7.67M
    txb_ctx->txb_skip_ctx = ctx_base + ctx_offset;
368
7.67M
  }
369
13.1M
}
decodetxb.c:get_txb_ctx_general
Line
Count
Source
312
13.1M
                                TXB_CTX *const txb_ctx) {
313
13.1M
  const int txb_w_unit = tx_size_wide_unit[tx_size];
314
13.1M
  const int txb_h_unit = tx_size_high_unit[tx_size];
315
13.1M
  int dc_sign = 0;
316
13.1M
  int k = 0;
317
318
60.7M
  do {
319
60.7M
    const unsigned int sign = ((uint8_t)a[k]) >> COEFF_CONTEXT_BITS;
320
60.7M
    assert(sign <= 2);
321
60.7M
    dc_sign += kTxbCtxSigns[sign];
322
60.7M
  } while (++k < txb_w_unit);
323
324
13.1M
  k = 0;
325
39.4M
  do {
326
39.4M
    const unsigned int sign = ((uint8_t)l[k]) >> COEFF_CONTEXT_BITS;
327
39.4M
    assert(sign <= 2);
328
39.4M
    dc_sign += kTxbCtxSigns[sign];
329
39.4M
  } while (++k < txb_h_unit);
330
331
13.1M
  txb_ctx->dc_sign_ctx = kTxbCtxDcSignContexts[dc_sign + 2 * MAX_TX_SIZE_UNIT];
332
333
13.1M
  if (plane == 0) {
334
5.44M
    if (plane_bsize == txsize_to_bsize[tx_size]) {
335
4.79M
      txb_ctx->txb_skip_ctx = 0;
336
4.79M
    } else {
337
      // For top and left, we only care about which of the following three
338
      // categories they belong to: { 0 }, { 1, 2, 3 }, or { 4, 5, ... }. The
339
      // spec calculates top and left with the Max() function. We can calculate
340
      // an approximate max with bitwise OR because the real max and the
341
      // approximate max belong to the same category.
342
646k
      int top = 0;
343
646k
      int left = 0;
344
345
646k
      k = 0;
346
7.79M
      do {
347
7.79M
        top |= a[k];
348
7.79M
      } while (++k < txb_w_unit);
349
646k
      top &= COEFF_CONTEXT_MASK;
350
646k
      top = AOMMIN(top, 4);
351
352
646k
      k = 0;
353
7.71M
      do {
354
7.71M
        left |= l[k];
355
7.71M
      } while (++k < txb_h_unit);
356
646k
      left &= COEFF_CONTEXT_MASK;
357
646k
      left = AOMMIN(left, 4);
358
359
646k
      txb_ctx->txb_skip_ctx = kTxbCtxSkipContexts[top][left];
360
646k
    }
361
7.67M
  } else {
362
7.67M
    const int ctx_base = get_entropy_context(tx_size, a, l);
363
7.67M
    const int ctx_offset = (num_pels_log2_lookup[plane_bsize] >
364
7.67M
                            num_pels_log2_lookup[txsize_to_bsize[tx_size]])
365
7.67M
                               ? 10
366
7.67M
                               : 7;
367
7.67M
    txb_ctx->txb_skip_ctx = ctx_base + ctx_offset;
368
7.67M
  }
369
13.1M
}
Unexecuted instantiation: entropy.c:get_txb_ctx_general
Unexecuted instantiation: entropymode.c:get_txb_ctx_general
Unexecuted instantiation: txb_common.c:get_txb_ctx_general
370
371
#define SPECIALIZE_GET_TXB_CTX(w, h)                                          \
372
  static void get_txb_ctx_##w##x##h(                                          \
373
      const BLOCK_SIZE plane_bsize, const int plane,                          \
374
      const ENTROPY_CONTEXT *const a, const ENTROPY_CONTEXT *const l,         \
375
16.5M
      TXB_CTX *const txb_ctx) {                                               \
376
16.5M
    const TX_SIZE tx_size = TX_##w##X##h;                                     \
377
16.5M
    const int txb_w_unit = tx_size_wide_unit[tx_size];                        \
378
16.5M
    const int txb_h_unit = tx_size_high_unit[tx_size];                        \
379
16.5M
    int dc_sign = 0;                                                          \
380
16.5M
    int k = 0;                                                                \
381
16.5M
                                                                              \
382
44.7M
    do {                                                                      \
383
44.7M
      const unsigned int sign = ((uint8_t)a[k]) >> COEFF_CONTEXT_BITS;        \
384
44.7M
      assert(sign <= 2);                                                      \
385
44.7M
      dc_sign += kTxbCtxSigns[sign];                                          \
386
44.7M
    } while (++k < txb_w_unit);                                               \
387
16.5M
                                                                              \
388
16.5M
    k = 0;                                                                    \
389
44.7M
    do {                                                                      \
390
44.7M
      const unsigned int sign = ((uint8_t)l[k]) >> COEFF_CONTEXT_BITS;        \
391
44.7M
      assert(sign <= 2);                                                      \
392
44.7M
      dc_sign += kTxbCtxSigns[sign];                                          \
393
44.7M
    } while (++k < txb_h_unit);                                               \
394
16.5M
                                                                              \
395
16.5M
    txb_ctx->dc_sign_ctx =                                                    \
396
16.5M
        kTxbCtxDcSignContexts[dc_sign + 2 * MAX_TX_SIZE_UNIT];                \
397
16.5M
                                                                              \
398
16.5M
    if (plane == 0) {                                                         \
399
7.43M
      if (plane_bsize == txsize_to_bsize[tx_size]) {                          \
400
2.72M
        txb_ctx->txb_skip_ctx = 0;                                            \
401
4.70M
      } else {                                                                \
402
4.70M
        int top = 0;                                                          \
403
4.70M
        int left = 0;                                                         \
404
4.70M
                                                                              \
405
4.70M
        k = 0;                                                                \
406
7.55M
        do {                                                                  \
407
7.55M
          top |= a[k];                                                        \
408
7.55M
        } while (++k < txb_w_unit);                                           \
409
4.70M
        top &= COEFF_CONTEXT_MASK;                                            \
410
4.70M
        top = AOMMIN(top, 4);                                                 \
411
4.70M
                                                                              \
412
4.70M
        k = 0;                                                                \
413
7.55M
        do {                                                                  \
414
7.55M
          left |= l[k];                                                       \
415
7.55M
        } while (++k < txb_h_unit);                                           \
416
4.70M
        left &= COEFF_CONTEXT_MASK;                                           \
417
4.70M
        left = AOMMIN(left, 4);                                               \
418
4.70M
                                                                              \
419
4.70M
        txb_ctx->txb_skip_ctx = kTxbCtxSkipContexts[top][left];               \
420
4.70M
      }                                                                       \
421
9.06M
    } else {                                                                  \
422
9.06M
      const int ctx_base = get_entropy_context(tx_size, a, l);                \
423
9.06M
      const int ctx_offset = (num_pels_log2_lookup[plane_bsize] >             \
424
9.06M
                              num_pels_log2_lookup[txsize_to_bsize[tx_size]]) \
425
9.06M
                                 ? 10                                         \
426
9.06M
                                 : 7;                                         \
427
9.06M
      txb_ctx->txb_skip_ctx = ctx_base + ctx_offset;                          \
428
9.06M
    }                                                                         \
429
16.5M
  }
Unexecuted instantiation: entropy.c:get_txb_ctx_4x4
Unexecuted instantiation: entropy.c:get_txb_ctx_8x8
Unexecuted instantiation: entropy.c:get_txb_ctx_16x16
Unexecuted instantiation: entropy.c:get_txb_ctx_32x32
Unexecuted instantiation: entropymode.c:get_txb_ctx_4x4
Unexecuted instantiation: entropymode.c:get_txb_ctx_8x8
Unexecuted instantiation: entropymode.c:get_txb_ctx_16x16
Unexecuted instantiation: entropymode.c:get_txb_ctx_32x32
Unexecuted instantiation: txb_common.c:get_txb_ctx_4x4
Unexecuted instantiation: txb_common.c:get_txb_ctx_8x8
Unexecuted instantiation: txb_common.c:get_txb_ctx_16x16
Unexecuted instantiation: txb_common.c:get_txb_ctx_32x32
430
431
7.64M
SPECIALIZE_GET_TXB_CTX(4, 4)
432
3.81M
SPECIALIZE_GET_TXB_CTX(8, 8)
433
2.72M
SPECIALIZE_GET_TXB_CTX(16, 16)
434
2.31M
SPECIALIZE_GET_TXB_CTX(32, 32)
435
436
// Wrapper for get_txb_ctx that calls the specialized version of get_txb_ctc_*
437
// so that the compiler can compile away the while loops.
438
static inline void get_txb_ctx(const BLOCK_SIZE plane_bsize,
439
                               const TX_SIZE tx_size, const int plane,
440
                               const ENTROPY_CONTEXT *const a,
441
                               const ENTROPY_CONTEXT *const l,
442
29.5M
                               TXB_CTX *const txb_ctx) {
443
29.5M
  switch (tx_size) {
444
7.69M
    case TX_4X4: get_txb_ctx_4x4(plane_bsize, plane, a, l, txb_ctx); break;
445
3.81M
    case TX_8X8: get_txb_ctx_8x8(plane_bsize, plane, a, l, txb_ctx); break;
446
2.72M
    case TX_16X16: get_txb_ctx_16x16(plane_bsize, plane, a, l, txb_ctx); break;
447
2.31M
    case TX_32X32: get_txb_ctx_32x32(plane_bsize, plane, a, l, txb_ctx); break;
448
13.1M
    default:
449
13.1M
      get_txb_ctx_general(plane_bsize, tx_size, plane, a, l, txb_ctx);
450
13.1M
      break;
451
29.5M
  }
452
29.5M
}
decodetxb.c:get_txb_ctx
Line
Count
Source
442
29.5M
                               TXB_CTX *const txb_ctx) {
443
29.5M
  switch (tx_size) {
444
7.69M
    case TX_4X4: get_txb_ctx_4x4(plane_bsize, plane, a, l, txb_ctx); break;
445
3.81M
    case TX_8X8: get_txb_ctx_8x8(plane_bsize, plane, a, l, txb_ctx); break;
446
2.72M
    case TX_16X16: get_txb_ctx_16x16(plane_bsize, plane, a, l, txb_ctx); break;
447
2.31M
    case TX_32X32: get_txb_ctx_32x32(plane_bsize, plane, a, l, txb_ctx); break;
448
13.1M
    default:
449
13.1M
      get_txb_ctx_general(plane_bsize, tx_size, plane, a, l, txb_ctx);
450
13.1M
      break;
451
29.5M
  }
452
29.5M
}
Unexecuted instantiation: entropy.c:get_txb_ctx
Unexecuted instantiation: entropymode.c:get_txb_ctx
Unexecuted instantiation: txb_common.c:get_txb_ctx
453
#undef MAX_TX_SIZE_UNIT
454
455
#endif  // AOM_AV1_COMMON_TXB_COMMON_H_