av1_quantize.c 74.3 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4
5
6
7
8
9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10
11
12
 */

#include <math.h>
Yaowu Xu's avatar
Yaowu Xu committed
13
#include "./aom_dsp_rtcd.h"
14
#include "aom_dsp/quantize.h"
Yaowu Xu's avatar
Yaowu Xu committed
15
#include "aom_mem/aom_mem.h"
16
#include "aom_ports/mem.h"
Jingning Han's avatar
Jingning Han committed
17

18
#include "av1/common/idct.h"
19
20
21
#include "av1/common/quant_common.h"
#include "av1/common/scan.h"
#include "av1/common/seg_common.h"
Jingning Han's avatar
Jingning Han committed
22

23
#include "av1/encoder/av1_quantize.h"
24
25
#include "av1/encoder/encoder.h"
#include "av1/encoder/rd.h"
Jingning Han's avatar
Jingning Han committed
26

27
#if CONFIG_NEW_QUANT
28
29
30
31
32
static INLINE int quantize_coeff_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t quant_shift,
    const int16_t dequant, const tran_low_t *cuml_bins_ptr,
    const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
    tran_low_t *dqcoeff_ptr) {
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
    if (tmp < cuml_bins_ptr[i]) {
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
    tmp -= cuml_bins_ptr[NUQ_KNOTS - 1];
    q = NUQ_KNOTS + (((((tmp * quant) >> 16) + tmp) * quant_shift) >> 16);
  }
  if (q) {
Yaowu Xu's avatar
Yaowu Xu committed
49
    *dqcoeff_ptr = av1_dequant_abscoeff_nuq(q, dequant, dequant_val);
50
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
51
52
53
54
55
56
57
58
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

59
60
61
62
static INLINE int quantize_coeff_bigtx_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t quant_shift,
    const int16_t dequant, const tran_low_t *cuml_bins_ptr,
    const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
63
    tran_low_t *dqcoeff_ptr, int logsizeby16) {
64
65
66
67
68
69
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
70
    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], logsizeby16)) {
71
72
73
74
75
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
76
    tmp -= ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1], logsizeby16);
77
    q = NUQ_KNOTS +
78
        (((((tmp * quant) >> 16) + tmp) * quant_shift) >> (16 - logsizeby16));
79
80
  }
  if (q) {
81
    *dqcoeff_ptr = ROUND_POWER_OF_TWO(
82
        av1_dequant_abscoeff_nuq(q, dequant, dequant_val), logsizeby16);
Yaowu Xu's avatar
Yaowu Xu committed
83
    // *dqcoeff_ptr = av1_dequant_abscoeff_nuq(q, dequant, dequant_val) >>
84
    // (logsizeby16);
85
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
86
87
88
89
90
91
92
93
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

94
95
96
97
static INLINE int quantize_coeff_fp_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t dequant,
    const tran_low_t *cuml_bins_ptr, const tran_low_t *dequant_val,
    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr) {
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
    if (tmp < cuml_bins_ptr[i]) {
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
    q = NUQ_KNOTS +
        ((((int64_t)tmp - cuml_bins_ptr[NUQ_KNOTS - 1]) * quant) >> 16);
  }
  if (q) {
Yaowu Xu's avatar
Yaowu Xu committed
114
    *dqcoeff_ptr = av1_dequant_abscoeff_nuq(q, dequant, dequant_val);
115
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
116
117
118
119
120
121
122
123
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

124
125
126
static INLINE int quantize_coeff_bigtx_fp_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t dequant,
    const tran_low_t *cuml_bins_ptr, const tran_low_t *dequant_val,
127
    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, int logsizeby16) {
128
129
130
131
132
133
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int tmp = clamp(abs_coeff, INT16_MIN, INT16_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
134
    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], logsizeby16)) {
135
136
137
138
139
140
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
    q = NUQ_KNOTS +
141
        ((((int64_t)tmp -
142
           ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1], logsizeby16)) *
143
          quant) >>
144
         (16 - logsizeby16));
145
146
  }
  if (q) {
147
    *dqcoeff_ptr = ROUND_POWER_OF_TWO(
148
        av1_dequant_abscoeff_nuq(q, dequant, dequant_val), logsizeby16);
Yaowu Xu's avatar
Yaowu Xu committed
149
    // *dqcoeff_ptr = av1_dequant_abscoeff_nuq(q, dequant, dequant_val) >>
150
    // (logsizeby16);
151
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
152
153
154
155
156
157
158
159
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

160
161
162
void quantize_dc_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                     int skip_block, const int16_t quant,
                     const int16_t quant_shift, const int16_t dequant,
163
                     const tran_low_t *cuml_bins_ptr,
164
165
                     const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
                     tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
166
167
168
169
170
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
171
172
    if (quantize_coeff_nuq(coeff_ptr[rc], quant, quant_shift, dequant,
                           cuml_bins_ptr, dequant_val, qcoeff_ptr, dqcoeff_ptr))
173
174
175
176
177
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

178
179
180
181
182
void quantize_dc_fp_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                        int skip_block, const int16_t quant,
                        const int16_t dequant, const tran_low_t *cuml_bins_ptr,
                        const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
                        tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
183
184
185
186
187
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
188
189
    if (quantize_coeff_fp_nuq(coeff_ptr[rc], quant, dequant, cuml_bins_ptr,
                              dequant_val, qcoeff_ptr, dqcoeff_ptr))
190
191
192
193
194
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

195
196
197
void quantize_dc_32x32_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                           int skip_block, const int16_t quant,
                           const int16_t quant_shift, const int16_t dequant,
198
199
                           const tran_low_t *cuml_bins_ptr,
                           const tran_low_t *dequant_val,
200
                           tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
201
202
203
204
205
206
                           uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
207
208
    if (quantize_coeff_bigtx_nuq(coeff_ptr[rc], quant, quant_shift, dequant,
                                 cuml_bins_ptr, dequant_val, qcoeff_ptr,
209
                                 dqcoeff_ptr, get_tx_scale(TX_32X32)))
210
211
212
213
214
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

215
216
void quantize_dc_32x32_fp_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                              int skip_block, const int16_t quant,
217
218
219
                              const int16_t dequant,
                              const tran_low_t *cuml_bins_ptr,
                              const tran_low_t *dequant_val,
220
                              tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
221
222
223
224
225
226
                              uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
227
228
    if (quantize_coeff_bigtx_fp_nuq(coeff_ptr[rc], quant, dequant,
                                    cuml_bins_ptr, dequant_val, qcoeff_ptr,
229
                                    dqcoeff_ptr, get_tx_scale(TX_32X32)))
230
231
232
233
234
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#if CONFIG_TX64X64
void quantize_dc_64x64_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                           int skip_block, const int16_t quant,
                           const int16_t quant_shift, const int16_t dequant,
                           const tran_low_t *cuml_bins_ptr,
                           const tran_low_t *dequant_val,
                           tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                           uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
    if (quantize_coeff_bigtx_nuq(coeff_ptr[rc], quant, quant_shift, dequant,
                                 cuml_bins_ptr, dequant_val, qcoeff_ptr,
                                 dqcoeff_ptr, get_tx_scale(TX_64X64)))
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

void quantize_dc_64x64_fp_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                              int skip_block, const int16_t quant,
                              const int16_t dequant,
                              const tran_low_t *cuml_bins_ptr,
                              const tran_low_t *dequant_val,
                              tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                              uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
    if (quantize_coeff_bigtx_fp_nuq(coeff_ptr[rc], quant, dequant,
                                    cuml_bins_ptr, dequant_val, qcoeff_ptr,
                                    dqcoeff_ptr, get_tx_scale(TX_64X64)))
      eob = 0;
  }
  *eob_ptr = eob + 1;
}
#endif  // CONFIG_TX64X64

277
278
279
void quantize_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                    int skip_block, const int16_t *quant_ptr,
                    const int16_t *quant_shift_ptr, const int16_t *dequant_ptr,
280
281
                    const cuml_bins_type_nuq *cuml_bins_ptr,
                    const dequant_val_type_nuq *dequant_val,
282
283
                    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                    uint16_t *eob_ptr, const int16_t *scan,
284
285
286
287
288
289
290
291
                    const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
292
293
294
295
      if (quantize_coeff_nuq(coeff_ptr[rc], quant_ptr[rc != 0],
                             quant_shift_ptr[rc != 0], dequant_ptr[rc != 0],
                             cuml_bins_ptr[band[i]], dequant_val[band[i]],
                             &qcoeff_ptr[rc], &dqcoeff_ptr[rc]))
296
297
298
299
300
301
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

302
303
void quantize_fp_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                       int skip_block, const int16_t *quant_ptr,
304
305
306
                       const int16_t *dequant_ptr,
                       const cuml_bins_type_nuq *cuml_bins_ptr,
                       const dequant_val_type_nuq *dequant_val,
307
308
                       tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                       uint16_t *eob_ptr, const int16_t *scan,
309
310
311
312
313
314
315
316
                       const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
317
318
319
      if (quantize_coeff_fp_nuq(coeff_ptr[rc], quant_ptr[rc != 0],
                                dequant_ptr[rc != 0], cuml_bins_ptr[band[i]],
                                dequant_val[band[i]], &qcoeff_ptr[rc],
320
321
322
323
324
325
326
                                &dqcoeff_ptr[rc]))
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

327
328
void quantize_32x32_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                          int skip_block, const int16_t *quant_ptr,
329
330
331
332
                          const int16_t *quant_shift_ptr,
                          const int16_t *dequant_ptr,
                          const cuml_bins_type_nuq *cuml_bins_ptr,
                          const dequant_val_type_nuq *dequant_val,
333
334
                          tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                          uint16_t *eob_ptr, const int16_t *scan,
335
336
337
338
339
340
341
342
                          const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
Yaowu Xu's avatar
Yaowu Xu committed
343
344
345
346
347
      if (quantize_coeff_bigtx_nuq(coeff_ptr[rc], quant_ptr[rc != 0],
                                   quant_shift_ptr[rc != 0],
                                   dequant_ptr[rc != 0], cuml_bins_ptr[band[i]],
                                   dequant_val[band[i]], &qcoeff_ptr[rc],
                                   &dqcoeff_ptr[rc], get_tx_scale(TX_32X32)))
348
349
350
351
352
353
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

354
355
void quantize_32x32_fp_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                             int skip_block, const int16_t *quant_ptr,
356
357
358
                             const int16_t *dequant_ptr,
                             const cuml_bins_type_nuq *cuml_bins_ptr,
                             const dequant_val_type_nuq *dequant_val,
359
360
                             tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                             uint16_t *eob_ptr, const int16_t *scan,
361
362
363
364
365
366
367
368
                             const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
369
370
371
      if (quantize_coeff_bigtx_fp_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], dequant_ptr[rc != 0],
              cuml_bins_ptr[band[i]], dequant_val[band[i]], &qcoeff_ptr[rc],
372
              &dqcoeff_ptr[rc], get_tx_scale(TX_32X32)))
373
374
375
376
377
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395

#if CONFIG_TX64X64
void quantize_64x64_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                          int skip_block, const int16_t *quant_ptr,
                          const int16_t *quant_shift_ptr,
                          const int16_t *dequant_ptr,
                          const cuml_bins_type_nuq *cuml_bins_ptr,
                          const dequant_val_type_nuq *dequant_val,
                          tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                          uint16_t *eob_ptr, const int16_t *scan,
                          const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
Yaowu Xu's avatar
Yaowu Xu committed
396
397
398
399
400
      if (quantize_coeff_bigtx_nuq(coeff_ptr[rc], quant_ptr[rc != 0],
                                   quant_shift_ptr[rc != 0],
                                   dequant_ptr[rc != 0], cuml_bins_ptr[band[i]],
                                   dequant_val[band[i]], &qcoeff_ptr[rc],
                                   &dqcoeff_ptr[rc], get_tx_scale(TX_64X64)))
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

void quantize_64x64_fp_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                             int skip_block, const int16_t *quant_ptr,
                             const int16_t *dequant_ptr,
                             const cuml_bins_type_nuq *cuml_bins_ptr,
                             const dequant_val_type_nuq *dequant_val,
                             tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                             uint16_t *eob_ptr, const int16_t *scan,
                             const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
      if (quantize_coeff_bigtx_fp_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], dequant_ptr[rc != 0],
              cuml_bins_ptr[band[i]], dequant_val[band[i]], &qcoeff_ptr[rc],
              &dqcoeff_ptr[rc], get_tx_scale(TX_64X64)))
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}
#endif  // CONFIG_TX64X64
432
433
#endif  // CONFIG_NEW_QUANT

Yaowu Xu's avatar
Yaowu Xu committed
434
435
void av1_quantize_skip(intptr_t n_coeffs, tran_low_t *qcoeff_ptr,
                       tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
Angie Chiang's avatar
Angie Chiang committed
436
437
438
439
440
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  *eob_ptr = 0;
}

Yaowu Xu's avatar
Yaowu Xu committed
441
442
443
444
void av1_quantize_fp_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                            const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                            const MACROBLOCKD_PLANE *pd,
                            tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
445
                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam) {
Angie Chiang's avatar
Angie Chiang committed
446
447
  // obsolete skip_block
  const int skip_block = 0;
448
449
450
451
#if CONFIG_AOM_QM
  const qm_val_t *qm_ptr = qparam->qmatrix;
  const qm_val_t *iqm_ptr = qparam->iqmatrix;
#endif  // CONFIG_AOM_QM
Angie Chiang's avatar
Angie Chiang committed
452

453
454
  switch (qparam->log_scale) {
    case 0:
455
      if (n_coeffs < 16) {
456
457
        // TODO(jingning): Need SIMD implementation for smaller block size
        // quantization.
458
459
460
        av1_quantize_fp_c(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round_fp,
                          p->quant_fp, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
                          pd->dequant, eob_ptr, sc->scan, sc->iscan
461
#if CONFIG_AOM_QM
462
463
                          ,
                          qm_ptr, iqm_ptr
464
#endif
465
466
467
468
469
470
471
472
473
474
475
                          );
      } else {
        av1_quantize_fp(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round_fp,
                        p->quant_fp, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
                        pd->dequant, eob_ptr, sc->scan, sc->iscan
#if CONFIG_AOM_QM
                        ,
                        qm_ptr, iqm_ptr
#endif
                        );
      }
476
477
478
479
480
481
      break;
    case 1:
      av1_quantize_fp_32x32(coeff_ptr, n_coeffs, skip_block, p->zbin,
                            p->round_fp, p->quant_fp, p->quant_shift,
                            qcoeff_ptr, dqcoeff_ptr, pd->dequant, eob_ptr,
                            sc->scan, sc->iscan
482
#if CONFIG_AOM_QM
483
484
                            ,
                            qm_ptr, iqm_ptr
485
#endif
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
                            );
      break;
#if CONFIG_TX64X64
    case 2:
      av1_quantize_fp_64x64(coeff_ptr, n_coeffs, skip_block, p->zbin,
                            p->round_fp, p->quant_fp, p->quant_shift,
                            qcoeff_ptr, dqcoeff_ptr, pd->dequant, eob_ptr,
                            sc->scan, sc->iscan
#if CONFIG_AOM_QM
                            ,
                            qm_ptr, iqm_ptr
#endif
                            );
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
502
  }
Angie Chiang's avatar
Angie Chiang committed
503
504
}

Yaowu Xu's avatar
Yaowu Xu committed
505
506
507
void av1_quantize_b_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                           const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                           const MACROBLOCKD_PLANE *pd, tran_low_t *dqcoeff_ptr,
508
                           uint16_t *eob_ptr, const SCAN_ORDER *sc,
509
                           const QUANT_PARAM *qparam) {
Angie Chiang's avatar
Angie Chiang committed
510
511
  // obsolete skip_block
  const int skip_block = 0;
512
513
514
515
#if CONFIG_AOM_QM
  const qm_val_t *qm_ptr = qparam->qmatrix;
  const qm_val_t *iqm_ptr = qparam->iqmatrix;
#endif  // CONFIG_AOM_QM
Angie Chiang's avatar
Angie Chiang committed
516

517
518
519
520
521
  switch (qparam->log_scale) {
    case 0:
      aom_quantize_b(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round,
                     p->quant, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
                     pd->dequant, eob_ptr, sc->scan, sc->iscan
522
#if CONFIG_AOM_QM
523
524
                     ,
                     qm_ptr, iqm_ptr
525
#endif
526
527
528
529
530
531
                     );
      break;
    case 1:
      aom_quantize_b_32x32(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round,
                           p->quant, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
                           pd->dequant, eob_ptr, sc->scan, sc->iscan
532
#if CONFIG_AOM_QM
533
534
535
536
537
538
539
540
541
542
543
544
545
                           ,
                           qm_ptr, iqm_ptr
#endif
                           );
      break;
#if CONFIG_TX64X64
    case 2:
      aom_quantize_b_64x64(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round,
                           p->quant, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
                           pd->dequant, eob_ptr, sc->scan, sc->iscan
#if CONFIG_AOM_QM
                           ,
                           qm_ptr, iqm_ptr
546
#endif
547
548
549
550
                           );
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
551
  }
Angie Chiang's avatar
Angie Chiang committed
552
553
}

Yaowu Xu's avatar
Yaowu Xu committed
554
555
556
557
void av1_quantize_dc_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                            const MACROBLOCK_PLANE *p, tran_low_t *qcoeff_ptr,
                            const MACROBLOCKD_PLANE *pd,
                            tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
558
                            const SCAN_ORDER *sc, const QUANT_PARAM *qparam) {
Angie Chiang's avatar
Angie Chiang committed
559
560
  // obsolete skip_block
  const int skip_block = 0;
561
562
563
564
565
#if CONFIG_AOM_QM
  const qm_val_t *qm_ptr = qparam->qmatrix;
  const qm_val_t *iqm_ptr = qparam->iqmatrix;
#endif  // CONFIG_AOM_QM

Angie Chiang's avatar
Angie Chiang committed
566
  (void)sc;
567
568
569
570
571
572

  switch (qparam->log_scale) {
    case 0:
      aom_quantize_dc(coeff_ptr, (int)n_coeffs, skip_block, p->round,
                      p->quant_fp[0], qcoeff_ptr, dqcoeff_ptr, pd->dequant[0],
                      eob_ptr
573
#if CONFIG_AOM_QM
574
575
                      ,
                      qm_ptr, iqm_ptr
576
#endif
577
578
579
580
581
582
583
584
585
586
587
588
589
590
                      );
      break;
    case 1:
      aom_quantize_dc_32x32(coeff_ptr, skip_block, p->round, p->quant_fp[0],
                            qcoeff_ptr, dqcoeff_ptr, pd->dequant[0], eob_ptr
#if CONFIG_AOM_QM
                            ,
                            qm_ptr, iqm_ptr
#endif
                            );
      break;
#if CONFIG_TX64X64
      aom_quantize_dc_64x64(coeff_ptr, skip_block, p->round, p->quant_fp[0],
                            qcoeff_ptr, dqcoeff_ptr, pd->dequant[0], eob_ptr
591
#if CONFIG_AOM_QM
592
593
                            ,
                            qm_ptr, iqm_ptr
594
#endif
595
596
597
598
                            );
    case 2: break;
#endif  // CONFIG_TX64X64
    default: assert(0);
599
  }
Angie Chiang's avatar
Angie Chiang committed
600
601
}

602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
#if CONFIG_NEW_QUANT
void av1_quantize_b_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                               const MACROBLOCK_PLANE *p,
                               tran_low_t *qcoeff_ptr,
                               const MACROBLOCKD_PLANE *pd,
                               tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                               const SCAN_ORDER *sc,
                               const QUANT_PARAM *qparam) {
  // obsolete skip_block
  const int skip_block = 0;
  const uint8_t *band = get_band_translate(qparam->tx_size);
  int dq = qparam->dq;

  switch (qparam->log_scale) {
    case 0:
      quantize_nuq(coeff_ptr, n_coeffs, skip_block, p->quant, p->quant_shift,
                   pd->dequant,
                   (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
                   (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
                   qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
    case 1:
      quantize_32x32_nuq(coeff_ptr, n_coeffs, skip_block, p->quant,
                         p->quant_shift, pd->dequant,
                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
                         (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
                         qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#if CONFIG_TX64X64
    case 2:
      quantize_64x64_nuq(coeff_ptr, n_coeffs, skip_block, p->quant,
                         p->quant_shift, pd->dequant,
                         (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
                         (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
                         qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
  }
}

void av1_quantize_fp_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                                const MACROBLOCK_PLANE *p,
                                tran_low_t *qcoeff_ptr,
                                const MACROBLOCKD_PLANE *pd,
                                tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                const SCAN_ORDER *sc,
                                const QUANT_PARAM *qparam) {
  // obsolete skip_block
  const int skip_block = 0;
  const uint8_t *band = get_band_translate(qparam->tx_size);
  int dq = qparam->dq;

  switch (qparam->log_scale) {
    case 0:
      quantize_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
                      (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
                      (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
                      qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
    case 1:
      quantize_32x32_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#if CONFIG_TX64X64
    case 2:
      quantize_64x64_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
  }
}

void av1_quantize_dc_nuq_facade(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                                const MACROBLOCK_PLANE *p,
                                tran_low_t *qcoeff_ptr,
                                const MACROBLOCKD_PLANE *pd,
                                tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                const SCAN_ORDER *sc,
                                const QUANT_PARAM *qparam) {
  // obsolete skip_block
  const int skip_block = 0;
  int dq = qparam->dq;
  (void)sc;

  switch (qparam->log_scale) {
    case 0:
      quantize_dc_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
                         pd->dequant[0], p->cuml_bins_nuq[dq][0],
                         pd->dequant_val_nuq[dq][0], qcoeff_ptr, dqcoeff_ptr,
                         eob_ptr);
      break;
    case 1:
      quantize_dc_32x32_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
                               pd->dequant[0], p->cuml_bins_nuq[dq][0],
                               pd->dequant_val_nuq[dq][0], qcoeff_ptr,
                               dqcoeff_ptr, eob_ptr);
      break;
#if CONFIG_TX64X64
    case 2:
      quantize_dc_64x64_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
                               pd->dequant[0], p->cuml_bins_nuq[dq][0],
                               pd->dequant_val_nuq[dq][0], qcoeff_ptr,
                               dqcoeff_ptr, eob_ptr);
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
  }
}
#endif  // CONFIG_NEW_QUANT

Yaowu Xu's avatar
Yaowu Xu committed
720
#if CONFIG_AOM_HIGHBITDEPTH
721
722
723
724
725
726
727
void av1_highbd_quantize_fp_facade(const tran_low_t *coeff_ptr,
                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
                                   tran_low_t *qcoeff_ptr,
                                   const MACROBLOCKD_PLANE *pd,
                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                   const SCAN_ORDER *sc,
                                   const QUANT_PARAM *qparam) {
Angie Chiang's avatar
Angie Chiang committed
728
729
  // obsolete skip_block
  const int skip_block = 0;
730
731
732
733
#if CONFIG_AOM_QM
  const qm_val_t *qm_ptr = qparam->qmatrix;
  const qm_val_t *iqm_ptr = qparam->iqmatrix;
#endif  // CONFIG_AOM_QM
Angie Chiang's avatar
Angie Chiang committed
734

735
  if (n_coeffs < 16) {
736
737
    // TODO(jingning): Need SIMD implementation for smaller block size
    // quantization.
738
739
740
741
742
743
744
745
746
747
748
    av1_highbd_quantize_fp_c(coeff_ptr, n_coeffs, skip_block, p->zbin,
                             p->round_fp, p->quant_fp, p->quant_shift,
                             qcoeff_ptr, dqcoeff_ptr, pd->dequant, eob_ptr,
                             sc->scan, sc->iscan,
#if CONFIG_AOM_QM
                             qm_ptr, iqm_ptr,
#endif
                             qparam->log_scale);
    return;
  }

Yaowu Xu's avatar
Yaowu Xu committed
749
750
  av1_highbd_quantize_fp(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round_fp,
                         p->quant_fp, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
751
                         pd->dequant, eob_ptr, sc->scan, sc->iscan,
752
753
754
#if CONFIG_AOM_QM
                         qm_ptr, iqm_ptr,
#endif
755
                         qparam->log_scale);
Angie Chiang's avatar
Angie Chiang committed
756
757
}

758
759
760
761
762
763
764
void av1_highbd_quantize_b_facade(const tran_low_t *coeff_ptr,
                                  intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
                                  tran_low_t *qcoeff_ptr,
                                  const MACROBLOCKD_PLANE *pd,
                                  tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                  const SCAN_ORDER *sc,
                                  const QUANT_PARAM *qparam) {
Yaowu Xu's avatar
Yaowu Xu committed
765
766
  // obsolete skip_block
  const int skip_block = 0;
767
768
769
770
#if CONFIG_AOM_QM
  const qm_val_t *qm_ptr = qparam->qmatrix;
  const qm_val_t *iqm_ptr = qparam->iqmatrix;
#endif  // CONFIG_AOM_QM
Yaowu Xu's avatar
Yaowu Xu committed
771
772
773
774

  av1_highbd_quantize_b(coeff_ptr, n_coeffs, skip_block, p->zbin, p->round,
                        p->quant, p->quant_shift, qcoeff_ptr, dqcoeff_ptr,
                        pd->dequant, eob_ptr, sc->scan, sc->iscan,
775
776
777
#if CONFIG_AOM_QM
                        qm_ptr, iqm_ptr,
#endif
Yaowu Xu's avatar
Yaowu Xu committed
778
779
780
                        qparam->log_scale);
}

781
782
783
784
785
#if CONFIG_AOM_HIGHBITDEPTH
static INLINE void highbd_quantize_dc(
    const tran_low_t *coeff_ptr, int n_coeffs, int skip_block,
    const int16_t *round_ptr, const int16_t quant, tran_low_t *qcoeff_ptr,
    tran_low_t *dqcoeff_ptr, const int16_t dequant_ptr, uint16_t *eob_ptr,
786
#if CONFIG_AOM_QM
787
    const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr,
788
#endif
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
    const int log_scale) {
  int eob = -1;

  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
#if CONFIG_AOM_QM
  (void)qm_ptr;
  (void)iqm_ptr;
#endif
  if (!skip_block) {
    const int coeff = coeff_ptr[0];
    const int coeff_sign = (coeff >> 31);
    const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
    const int64_t tmp = abs_coeff + round_ptr[0];
    const uint32_t abs_qcoeff = (uint32_t)((tmp * quant) >> (16 - log_scale));
    qcoeff_ptr[0] = (tran_low_t)((abs_qcoeff ^ coeff_sign) - coeff_sign);
    dqcoeff_ptr[0] = qcoeff_ptr[0] * dequant_ptr / (1 << log_scale);
    if (abs_qcoeff) eob = 0;
  }
  *eob_ptr = eob + 1;
}
#endif  // CONFIG_AOM_HIGHBITDEPTH

void av1_highbd_quantize_dc_facade(const tran_low_t *coeff_ptr,
                                   intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
                                   tran_low_t *qcoeff_ptr,
                                   const MACROBLOCKD_PLANE *pd,
                                   tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                   const SCAN_ORDER *sc,
                                   const QUANT_PARAM *qparam) {
Angie Chiang's avatar
Angie Chiang committed
819
820
  // obsolete skip_block
  const int skip_block = 0;
821
822
823
824
#if CONFIG_AOM_QM
  const qm_val_t *qm_ptr = qparam->qmatrix;
  const qm_val_t *iqm_ptr = qparam->iqmatrix;
#endif  // CONFIG_AOM_QM
Angie Chiang's avatar
Angie Chiang committed
825
826
827

  (void)sc;

828
829
830
  highbd_quantize_dc(coeff_ptr, (int)n_coeffs, skip_block, p->round,
                     p->quant_fp[0], qcoeff_ptr, dqcoeff_ptr, pd->dequant[0],
                     eob_ptr,
831
#if CONFIG_AOM_QM
832
                     qm_ptr, iqm_ptr,
833
#endif
834
                     qparam->log_scale);
Angie Chiang's avatar
Angie Chiang committed
835
}
836
837

#if CONFIG_NEW_QUANT
838
839
840
841
842
static INLINE int highbd_quantize_coeff_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t quant_shift,
    const int16_t dequant, const tran_low_t *cuml_bins_ptr,
    const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
    tran_low_t *dqcoeff_ptr) {
843
844
845
846
847
848
849
850
851
852
853
854
855
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
    if (tmp < cuml_bins_ptr[i]) {
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
    tmp -= cuml_bins_ptr[NUQ_KNOTS - 1];
856
    q = NUQ_KNOTS + (int)(((((tmp * quant) >> 16) + tmp) * quant_shift) >> 16);
857
858
  }
  if (q) {
Yaowu Xu's avatar
Yaowu Xu committed
859
    *dqcoeff_ptr = av1_dequant_abscoeff_nuq(q, dequant, dequant_val);
860
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
861
862
863
864
865
866
867
868
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

869
870
871
872
static INLINE int highbd_quantize_coeff_fp_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t dequant,
    const tran_low_t *cuml_bins_ptr, const tran_low_t *dequant_val,
    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr) {
873
874
875
876
877
878
879
880
881
882
883
884
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
    if (tmp < cuml_bins_ptr[i]) {
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
885
    q = NUQ_KNOTS + (int)(((tmp - cuml_bins_ptr[NUQ_KNOTS - 1]) * quant) >> 16);
886
887
  }
  if (q) {
Yaowu Xu's avatar
Yaowu Xu committed
888
    *dqcoeff_ptr = av1_dequant_abscoeff_nuq(q, dequant, dequant_val);
889
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
890
891
892
893
894
895
896
897
898
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

static INLINE int highbd_quantize_coeff_bigtx_fp_nuq(
899
900
    const tran_low_t coeffv, const int16_t quant, const int16_t dequant,
    const tran_low_t *cuml_bins_ptr, const tran_low_t *dequant_val,
901
    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, int logsizeby16) {
902
903
904
905
906
907
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
908
    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], logsizeby16)) {
909
910
911
912
913
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
914
    q = NUQ_KNOTS +
915
916
        (int)(((tmp -
                ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1], logsizeby16)) *
917
               quant) >>
918
              (16 - logsizeby16));
919
920
  }
  if (q) {
921
    *dqcoeff_ptr = ROUND_POWER_OF_TWO(
922
        av1_dequant_abscoeff_nuq(q, dequant, dequant_val), logsizeby16);
923
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
924
925
926
927
928
929
930
931
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

932
933
934
935
static INLINE int highbd_quantize_coeff_bigtx_nuq(
    const tran_low_t coeffv, const int16_t quant, const int16_t quant_shift,
    const int16_t dequant, const tran_low_t *cuml_bins_ptr,
    const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
936
    tran_low_t *dqcoeff_ptr, int logsizeby16) {
937
938
939
940
941
942
  const int coeff = coeffv;
  const int coeff_sign = (coeff >> 31);
  const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
  int i, q;
  int64_t tmp = clamp(abs_coeff, INT32_MIN, INT32_MAX);
  for (i = 0; i < NUQ_KNOTS; i++) {
943
    if (tmp < ROUND_POWER_OF_TWO(cuml_bins_ptr[i], logsizeby16)) {
944
945
946
947
948
      q = i;
      break;
    }
  }
  if (i == NUQ_KNOTS) {
949
    tmp -= ROUND_POWER_OF_TWO(cuml_bins_ptr[NUQ_KNOTS - 1], logsizeby16);
950
    q = NUQ_KNOTS + (int)(((((tmp * quant) >> 16) + tmp) * quant_shift) >>
951
                          (16 - logsizeby16));
952
953
  }
  if (q) {
954
    *dqcoeff_ptr = ROUND_POWER_OF_TWO(
955
        av1_dequant_abscoeff_nuq(q, dequant, dequant_val), logsizeby16);
956
    *qcoeff_ptr = (q ^ coeff_sign) - coeff_sign;
957
958
959
960
961
962
963
964
    *dqcoeff_ptr = *qcoeff_ptr < 0 ? -*dqcoeff_ptr : *dqcoeff_ptr;
  } else {
    *qcoeff_ptr = 0;
    *dqcoeff_ptr = 0;
  }
  return (q != 0);
}

965
966
967
void highbd_quantize_dc_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                            int skip_block, const int16_t quant,
                            const int16_t quant_shift, const int16_t dequant,
968
969
                            const tran_low_t *cuml_bins_ptr,
                            const tran_low_t *dequant_val,
970
                            tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
971
972
973
974
975
976
                            uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
977
978
    if (highbd_quantize_coeff_nuq(coeff_ptr[rc], quant, quant_shift, dequant,
                                  cuml_bins_ptr, dequant_val, qcoeff_ptr,
979
980
981
982
983
984
                                  dqcoeff_ptr))
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

985
986
void highbd_quantize_dc_fp_nuq(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                               int skip_block, const int16_t quant,
987
988
989
                               const int16_t dequant,
                               const tran_low_t *cuml_bins_ptr,
                               const tran_low_t *dequant_val,
990
                               tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
991
992
993
994
995
996
                               uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
997
998
    if (highbd_quantize_coeff_fp_nuq(coeff_ptr[rc], quant, dequant,
                                     cuml_bins_ptr, dequant_val, qcoeff_ptr,
999
1000
1001
1002
1003
1004
                                     dqcoeff_ptr))
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

1005
1006
void highbd_quantize_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                           int skip_block, const int16_t *quant_ptr,
1007
1008
1009
1010
                           const int16_t *quant_shift_ptr,
                           const int16_t *dequant_ptr,
                           const cuml_bins_type_nuq *cuml_bins_ptr,
                           const dequant_val_type_nuq *dequant_val,
1011
1012
                           tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                           uint16_t *eob_ptr, const int16_t *scan,
1013
1014
1015
1016
1017
1018
1019
1020
                           const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
1021
1022
1023
1024
      if (highbd_quantize_coeff_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], quant_shift_ptr[rc != 0],
              dequant_ptr[rc != 0], cuml_bins_ptr[band[i]],
              dequant_val[band[i]], &qcoeff_ptr[rc], &dqcoeff_ptr[rc]))
1025
1026
1027
1028
1029
1030
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

1031
1032
void highbd_quantize_32x32_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                                 int skip_block, const int16_t *quant_ptr,
1033
1034
1035
1036
1037
                                 const int16_t *quant_shift_ptr,
                                 const int16_t *dequant_ptr,
                                 const cuml_bins_type_nuq *cuml_bins_ptr,
                                 const dequant_val_type_nuq *dequant_val,
                                 tran_low_t *qcoeff_ptr,
1038
1039
                                 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                 const int16_t *scan, const uint8_t *band) {
1040
1041
1042
1043
1044
1045
1046
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
1047
1048
1049
      if (highbd_quantize_coeff_bigtx_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], quant_shift_ptr[rc != 0],
              dequant_ptr[rc != 0], cuml_bins_ptr[band[i]],
1050
1051
              dequant_val[band[i]], &qcoeff_ptr[rc], &dqcoeff_ptr[rc],
              get_tx_scale(TX_32X32)))
1052
1053
1054
1055
1056
1057
1058
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

void highbd_quantize_32x32_fp_nuq_c(const tran_low_t *coeff_ptr,
1059
                                    intptr_t n_coeffs, int skip_block,
1060
1061
1062
1063
1064
                                    const int16_t *quant_ptr,
                                    const int16_t *dequant_ptr,
                                    const cuml_bins_type_nuq *cuml_bins_ptr,
                                    const dequant_val_type_nuq *dequant_val,
                                    tran_low_t *qcoeff_ptr,
1065
1066
                                    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                    const int16_t *scan, const uint8_t *band) {
1067
1068
1069
1070
1071
1072
1073
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
1074
1075
1076
      if (highbd_quantize_coeff_bigtx_fp_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], dequant_ptr[rc != 0],
              cuml_bins_ptr[band[i]], dequant_val[band[i]], &qcoeff_ptr[rc],
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
              &dqcoeff_ptr[rc], get_tx_scale(TX_32X32)))
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

#if CONFIG_TX64X64
void highbd_quantize_64x64_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                                 int skip_block, const int16_t *quant_ptr,
                                 const int16_t *quant_shift_ptr,
                                 const int16_t *dequant_ptr,
                                 const cuml_bins_type_nuq *cuml_bins_ptr,
                                 const dequant_val_type_nuq *dequant_val,
                                 tran_low_t *qcoeff_ptr,
                                 tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                 const int16_t *scan, const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
      if (highbd_quantize_coeff_bigtx_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], quant_shift_ptr[rc != 0],
              dequant_ptr[rc != 0], cuml_bins_ptr[band[i]],
              dequant_val[band[i]], &qcoeff_ptr[rc], &dqcoeff_ptr[rc],
              get_tx_scale(TX_64X64)))
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

void highbd_quantize_64x64_fp_nuq_c(const tran_low_t *coeff_ptr,
                                    intptr_t n_coeffs, int skip_block,
                                    const int16_t *quant_ptr,
                                    const int16_t *dequant_ptr,
                                    const cuml_bins_type_nuq *cuml_bins_ptr,
                                    const dequant_val_type_nuq *dequant_val,
                                    tran_low_t *qcoeff_ptr,
                                    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr,
                                    const int16_t *scan, const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
      if (highbd_quantize_coeff_bigtx_fp_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], dequant_ptr[rc != 0],
              cuml_bins_ptr[band[i]], dequant_val[band[i]], &qcoeff_ptr[rc],
              &dqcoeff_ptr[rc], get_tx_scale(TX_64X64)))
1132
1133
1134
1135
1136
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}
1137
#endif  // CONFIG_TX64X64
1138

1139
1140
void highbd_quantize_fp_nuq_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                              int skip_block, const int16_t *quant_ptr,
1141
1142
1143
                              const int16_t *dequant_ptr,
                              const cuml_bins_type_nuq *cuml_bins_ptr,
                              const dequant_val_type_nuq *dequant_val,
1144
1145
                              tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr,
                              uint16_t *eob_ptr, const int16_t *scan,
1146
1147
1148
1149
1150
1151
1152
1153
                              const uint8_t *band) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    int i;
    for (i = 0; i < n_coeffs; i++) {
      const int rc = scan[i];
1154
1155
1156
1157
      if (highbd_quantize_coeff_fp_nuq(
              coeff_ptr[rc], quant_ptr[rc != 0], dequant_ptr[rc != 0],
              cuml_bins_ptr[band[i]], dequant_val[band[i]], &qcoeff_ptr[rc],
              &dqcoeff_ptr[rc]))
1158
1159
1160
1161
1162
1163
        eob = i;
    }
  }
  *eob_ptr = eob + 1;
}

1164
1165
1166
1167
1168
void highbd_quantize_dc_32x32_nuq(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block,
    const int16_t quant, const int16_t quant_shift, const int16_t dequant,
    const tran_low_t *cuml_bins_ptr, const tran_low_t *dequant_val,
    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
1169
1170
1171
1172
1173
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
Yaowu Xu's avatar
Yaowu Xu committed
1174
1175
1176
    if (highbd_quantize_coeff_bigtx_nuq(
            coeff_ptr[rc], quant, quant_shift, dequant, cuml_bins_ptr,
            dequant_val, qcoeff_ptr, dqcoeff_ptr, get_tx_scale(TX_32X32)))
1177
1178
1179
1180
1181
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

1182
1183
1184
1185
1186
void highbd_quantize_dc_32x32_fp_nuq(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block,
    const int16_t quant, const int16_t dequant, const tran_low_t *cuml_bins_ptr,
    const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
1187
1188
1189
1190
1191
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
Yaowu Xu's avatar
Yaowu Xu committed
1192
1193
1194
    if (highbd_quantize_coeff_bigtx_fp_nuq(
            coeff_ptr[rc], quant, dequant, cuml_bins_ptr, dequant_val,
            qcoeff_ptr, dqcoeff_ptr, get_tx_scale(TX_32X32)))
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
      eob = 0;
  }
  *eob_ptr = eob + 1;
}

#if CONFIG_TX64X64
void highbd_quantize_dc_64x64_nuq(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block,
    const int16_t quant, const int16_t quant_shift, const int16_t dequant,
    const tran_low_t *cuml_bins_ptr, const tran_low_t *dequant_val,
    tran_low_t *qcoeff_ptr, tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
Yaowu Xu's avatar
Yaowu Xu committed
1211
1212
1213
    if (highbd_quantize_coeff_bigtx_nuq(
            coeff_ptr[rc], quant, quant_shift, dequant, cuml_bins_ptr,
            dequant_val, qcoeff_ptr, dqcoeff_ptr, get_tx_scale(TX_64X64)))
1214
1215
1216
1217
      eob = 0;
  }
  *eob_ptr = eob + 1;
}
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228

void highbd_quantize_dc_64x64_fp_nuq(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, int skip_block,
    const int16_t quant, const int16_t dequant, const tran_low_t *cuml_bins_ptr,
    const tran_low_t *dequant_val, tran_low_t *qcoeff_ptr,
    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr) {
  int eob = -1;
  memset(qcoeff_ptr, 0, n_coeffs * sizeof(*qcoeff_ptr));
  memset(dqcoeff_ptr, 0, n_coeffs * sizeof(*dqcoeff_ptr));
  if (!skip_block) {
    const int rc = 0;
Yaowu Xu's avatar
Yaowu Xu committed
1229
1230
1231
    if (highbd_quantize_coeff_bigtx_fp_nuq(
            coeff_ptr[rc], quant, dequant, cuml_bins_ptr, dequant_val,
            qcoeff_ptr, dqcoeff_ptr, get_tx_scale(TX_64X64)))
1232
1233
1234
1235
1236
      eob = 0;
  }
  *eob_ptr = eob + 1;
}
#endif  // CONFIG_TX64X64
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347

void av1_highbd_quantize_b_nuq_facade(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
    const QUANT_PARAM *qparam) {
  // obsolete skip_block
  const int skip_block = 0;
  const uint8_t *band = get_band_translate(qparam->tx_size);
  const int dq = qparam->dq;

  switch (qparam->log_scale) {
    case 0:
      highbd_quantize_nuq(coeff_ptr, n_coeffs, skip_block, p->quant,
                          p->quant_shift, pd->dequant,
                          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
                          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq],
                          qcoeff_ptr, dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
    case 1:
      highbd_quantize_32x32_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant, p->quant_shift,
          pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#if CONFIG_TX64X64
    case 2:
      highbd_quantize_64x64_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant, p->quant_shift,
          pd->dequant, (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
  }
}

void av1_highbd_quantize_fp_nuq_facade(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
    const QUANT_PARAM *qparam) {
  // obsolete skip_block
  const int skip_block = 0;
  const uint8_t *band = get_band_translate(qparam->tx_size);
  const int dq = qparam->dq;

  switch (qparam->log_scale) {
    case 0:
      highbd_quantize_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
    case 1:
      highbd_quantize_32x32_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#if CONFIG_TX64X64
    case 2:
      highbd_quantize_64x64_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp, pd->dequant,
          (const cuml_bins_type_nuq *)p->cuml_bins_nuq[dq],
          (const dequant_val_type_nuq *)pd->dequant_val_nuq[dq], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr, sc->scan, band);
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
  }
}

void av1_highbd_quantize_dc_nuq_facade(
    const tran_low_t *coeff_ptr, intptr_t n_coeffs, const MACROBLOCK_PLANE *p,
    tran_low_t *qcoeff_ptr, const MACROBLOCKD_PLANE *pd,
    tran_low_t *dqcoeff_ptr, uint16_t *eob_ptr, const SCAN_ORDER *sc,
    const QUANT_PARAM *qparam) {
  // obsolete skip_block
  const int skip_block = 0;
  const int dq = qparam->dq;
  (void)sc;

  switch (qparam->log_scale) {
    case 0:
      highbd_quantize_dc_fp_nuq(coeff_ptr, n_coeffs, skip_block, p->quant_fp[0],
                                pd->dequant[0], p->cuml_bins_nuq[dq][0],
                                pd->dequant_val_nuq[dq][0], qcoeff_ptr,
                                dqcoeff_ptr, eob_ptr);
      break;
    case 1:
      highbd_quantize_dc_32x32_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp[0], pd->dequant[0],
          p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr);
      break;
#if CONFIG_TX64X64
    case 2:
      highbd_quantize_dc_64x64_fp_nuq(
          coeff_ptr, n_coeffs, skip_block, p->quant_fp[0], pd->dequant[0],
          p->cuml_bins_nuq[dq][0], pd->dequant_val_nuq[dq][0], qcoeff_ptr,
          dqcoeff_ptr, eob_ptr);
      break;
#endif  // CONFIG_TX64X64
    default: assert(0);
  }
}
1348
#endif  // CONFIG_NEW_QUANT
Yaowu Xu's avatar
Yaowu Xu committed
1349
1350
1351
1352
1353
1354
1355
1356
1357
#endif  // CONFIG_AOM_HIGHBITDEPTH

void av1_quantize_fp_c(const tran_low_t *coeff_ptr, intptr_t n_coeffs,
                       int skip_block, const int16_t *zbin_ptr,
                       const int16_t *round_ptr, const int16_t *quant_ptr,
                       const int16_t *quant_shift_ptr, tran_low_t *qcoeff_ptr,
                       tran_low_t *dqcoeff_ptr, const int16_t *dequant_ptr,
                       uint16_t *eob_ptr, const int16_t *scan,
                       const int16_t *iscan
1358
#if CONFIG_AOM_QM
Yaowu Xu's avatar
Yaowu Xu committed
1359
1360
                       ,
                       const qm_val_t *qm_ptr, const qm_val_t *iqm_ptr
1361
#endif
Yaowu Xu's avatar
Yaowu Xu committed
1362
                       ) {