Coverage Report

Created: 2026-10-17 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/avm/av2/common/warped_motion.h
Line
Count
Source
1
/*
2
 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
3
 *
4
 * This source code is subject to the terms of the BSD 3-Clause Clear License
5
 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6
 * License was not distributed with this source code in the LICENSE file, you
7
 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/.  If the
8
 * Alliance for Open Media Patent License 1.0 was not distributed with this
9
 * source code in the PATENTS file, you can obtain it at
10
 * aomedia.org/license/patent-license/.
11
 */
12
13
#ifndef AVM_AV2_COMMON_WARPED_MOTION_H_
14
#define AVM_AV2_COMMON_WARPED_MOTION_H_
15
16
#include <stdio.h>
17
#include <stdlib.h>
18
#include <memory.h>
19
#include <math.h>
20
#include <assert.h>
21
#include <stdbool.h>
22
23
#include "config/avm_config.h"
24
25
#include "avm_ports/mem.h"
26
#include "avm_dsp/avm_dsp_common.h"
27
#include "av2/common/mv.h"
28
#include "av2/common/convolve.h"
29
#include "av2/common/blockd.h"
30
31
0
#define LEAST_SQUARES_SAMPLES_MAX_BITS 3
32
0
#define LEAST_SQUARES_SAMPLES_MAX (1 << LEAST_SQUARES_SAMPLES_MAX_BITS)
33
#define SAMPLES_ARRAY_SIZE (LEAST_SQUARES_SAMPLES_MAX * 2)
34
#define WARPED_MOTION_DEBUG 0
35
0
#define DEFAULT_WMTYPE AFFINE
36
#define WARP_ERROR_BLOCK_LOG 5
37
#define WARP_ERROR_BLOCK (1 << WARP_ERROR_BLOCK_LOG)
38
39
0
#define EXT_WARP_TAPS 6
40
#define EXT_WARP_PHASES_LOG2 6
41
#define EXT_WARP_PHASES (1 << EXT_WARP_PHASES_LOG2)
42
#define EXT_WARP_ROUND_BITS (WARPEDMODEL_PREC_BITS - EXT_WARP_PHASES_LOG2)
43
44
// The extended warp filter is a 6-tap filter, but we store each kernel with
45
// two extra zeros at the end so that each kernel is 16-byte aligned
46
#define EXT_WARP_STORAGE_TAPS 8
47
48
#define DIV_LUT_NUM (1 << DIV_LUT_BITS)
49
50
static const uint16_t div_lut[DIV_LUT_NUM + 1] = {
51
  512, 508, 504, 500, 496, 493, 489, 485, 482, 478, 475, 471, 468, 465, 462,
52
  458, 455, 452, 449, 446, 443, 440, 437, 434, 431, 428, 426, 423, 420, 417,
53
  415, 412, 410, 407, 405, 402, 400, 397, 395, 392, 390, 388, 386, 383, 381,
54
  379, 377, 374, 372, 370, 368, 366, 364, 362, 360, 358, 356, 354, 352, 350,
55
  349, 347, 345, 343, 341, 340, 338, 336, 334, 333, 331, 329, 328, 326, 324,
56
  323, 321, 320, 318, 317, 315, 314, 312, 311, 309, 308, 306, 305, 303, 302,
57
  301, 299, 298, 297, 295, 294, 293, 291, 290, 289, 287, 286, 285, 284, 282,
58
  281, 280, 279, 278, 277, 275, 274, 273, 272, 271, 270, 269, 267, 266, 265,
59
  264, 263, 262, 261, 260, 259, 258, 257, 256
60
};
61
62
// Decomposes a divisor D such that 1/D = y/2^shift, where y is returned
63
// at precision of DIV_LUT_PREC_BITS along with the shift.
64
0
static INLINE int16_t resolve_divisor_64(uint64_t D, int16_t *shift) {
65
0
  int64_t f;
66
0
  *shift = (int16_t)((D >> 32) ? get_msb((unsigned int)(D >> 32)) + 32
67
0
                               : get_msb((unsigned int)D));
68
  // e is obtained from D after resetting the most significant 1 bit.
69
0
  const int64_t e = D - ((uint64_t)1 << *shift);
70
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
71
0
  if (*shift > DIV_LUT_BITS)
72
0
    f = ROUND_POWER_OF_TWO_64(e, *shift - DIV_LUT_BITS);
73
0
  else
74
0
    f = e << (DIV_LUT_BITS - *shift);
75
0
  assert(f <= DIV_LUT_NUM);
76
0
  *shift += DIV_LUT_PREC_BITS;
77
  // Use f as lookup into the precomputed table of multipliers
78
0
  return div_lut[f];
79
0
}
Unexecuted instantiation: av2_dx_iface.c:resolve_divisor_64
Unexecuted instantiation: annexF.c:resolve_divisor_64
Unexecuted instantiation: decodeframe.c:resolve_divisor_64
Unexecuted instantiation: decodemv.c:resolve_divisor_64
Unexecuted instantiation: decoder.c:resolve_divisor_64
Unexecuted instantiation: decodetxb.c:resolve_divisor_64
Unexecuted instantiation: detokenize.c:resolve_divisor_64
Unexecuted instantiation: obu_fgm.c:resolve_divisor_64
Unexecuted instantiation: obu.c:resolve_divisor_64
Unexecuted instantiation: obu_ci.c:resolve_divisor_64
Unexecuted instantiation: obu_atlas.c:resolve_divisor_64
Unexecuted instantiation: obu_lcr.c:resolve_divisor_64
Unexecuted instantiation: obu_ops.c:resolve_divisor_64
Unexecuted instantiation: obu_buf.c:resolve_divisor_64
Unexecuted instantiation: intrapred_avx2.c:resolve_divisor_64
Unexecuted instantiation: annexA.c:resolve_divisor_64
Unexecuted instantiation: alloccommon.c:resolve_divisor_64
Unexecuted instantiation: av2_loopfilter.c:resolve_divisor_64
Unexecuted instantiation: blockd.c:resolve_divisor_64
Unexecuted instantiation: cdef.c:resolve_divisor_64
Unexecuted instantiation: gdf.c:resolve_divisor_64
Unexecuted instantiation: gdf_block.c:resolve_divisor_64
Unexecuted instantiation: cdef_block.c:resolve_divisor_64
Unexecuted instantiation: cfl.c:resolve_divisor_64
Unexecuted instantiation: convolve.c:resolve_divisor_64
Unexecuted instantiation: entropy.c:resolve_divisor_64
Unexecuted instantiation: entropymode.c:resolve_divisor_64
Unexecuted instantiation: entropymv.c:resolve_divisor_64
Unexecuted instantiation: idct.c:resolve_divisor_64
Unexecuted instantiation: level.c:resolve_divisor_64
Unexecuted instantiation: mvref_common.c:resolve_divisor_64
Unexecuted instantiation: pred_common.c:resolve_divisor_64
Unexecuted instantiation: quant_common.c:resolve_divisor_64
Unexecuted instantiation: reconinter.c:resolve_divisor_64
Unexecuted instantiation: reconintra.c:resolve_divisor_64
Unexecuted instantiation: restoration.c:resolve_divisor_64
Unexecuted instantiation: scan.c:resolve_divisor_64
Unexecuted instantiation: thread_common.c:resolve_divisor_64
Unexecuted instantiation: tile_common.c:resolve_divisor_64
Unexecuted instantiation: timing.c:resolve_divisor_64
Unexecuted instantiation: tip.c:resolve_divisor_64
Unexecuted instantiation: txb_common.c:resolve_divisor_64
Unexecuted instantiation: warped_motion.c:resolve_divisor_64
Unexecuted instantiation: intra_matrix.c:resolve_divisor_64
Unexecuted instantiation: intra_dip.cc:resolve_divisor_64(unsigned long, short*)
Unexecuted instantiation: ccso.c:resolve_divisor_64
Unexecuted instantiation: bru.c:resolve_divisor_64
Unexecuted instantiation: obu_qm.c:resolve_divisor_64
Unexecuted instantiation: cfl_sse2.c:resolve_divisor_64
Unexecuted instantiation: cfl_ssse3.c:resolve_divisor_64
Unexecuted instantiation: av2_convolve_horiz_rs_sse4.c:resolve_divisor_64
Unexecuted instantiation: highbd_warp_plane_sse4.c:resolve_divisor_64
Unexecuted instantiation: optflow_refine_sse4.c:resolve_divisor_64
Unexecuted instantiation: affine_optflow_refine_avx2.c:resolve_divisor_64
Unexecuted instantiation: cfl_avx2.c:resolve_divisor_64
Unexecuted instantiation: highbd_ccso_avx2.c:resolve_divisor_64
Unexecuted instantiation: highbd_inv_txfm_avx2.c:resolve_divisor_64
Unexecuted instantiation: highbd_warp_affine_avx2.c:resolve_divisor_64
Unexecuted instantiation: gdf_block_avx2.c:resolve_divisor_64
Unexecuted instantiation: intrapred.c:resolve_divisor_64
Unexecuted instantiation: highbd_intrapred_sse2.c:resolve_divisor_64
80
81
31.3M
static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
82
31.3M
  int32_t f;
83
31.3M
  *shift = get_msb(D);
84
  // e is obtained from D after resetting the most significant 1 bit.
85
31.3M
  const int32_t e = D - ((uint32_t)1 << *shift);
86
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
87
31.3M
  if (*shift > DIV_LUT_BITS)
88
29.8M
    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
89
1.54M
  else
90
1.54M
    f = e << (DIV_LUT_BITS - *shift);
91
31.3M
  assert(f <= DIV_LUT_NUM);
92
31.3M
  *shift += DIV_LUT_PREC_BITS;
93
  // Use f as lookup into the precomputed table of multipliers
94
31.3M
  return div_lut[f];
95
31.3M
}
av2_dx_iface.c:resolve_divisor_32
Line
Count
Source
81
30.0M
static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
82
30.0M
  int32_t f;
83
30.0M
  *shift = get_msb(D);
84
  // e is obtained from D after resetting the most significant 1 bit.
85
30.0M
  const int32_t e = D - ((uint32_t)1 << *shift);
86
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
87
30.0M
  if (*shift > DIV_LUT_BITS)
88
29.8M
    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
89
234k
  else
90
234k
    f = e << (DIV_LUT_BITS - *shift);
91
30.0M
  assert(f <= DIV_LUT_NUM);
92
30.0M
  *shift += DIV_LUT_PREC_BITS;
93
  // Use f as lookup into the precomputed table of multipliers
94
30.0M
  return div_lut[f];
95
30.0M
}
Unexecuted instantiation: annexF.c:resolve_divisor_32
Unexecuted instantiation: decodeframe.c:resolve_divisor_32
Unexecuted instantiation: decodemv.c:resolve_divisor_32
Unexecuted instantiation: decoder.c:resolve_divisor_32
Unexecuted instantiation: decodetxb.c:resolve_divisor_32
Unexecuted instantiation: detokenize.c:resolve_divisor_32
Unexecuted instantiation: obu_fgm.c:resolve_divisor_32
Unexecuted instantiation: obu.c:resolve_divisor_32
Unexecuted instantiation: obu_ci.c:resolve_divisor_32
Unexecuted instantiation: obu_atlas.c:resolve_divisor_32
Unexecuted instantiation: obu_lcr.c:resolve_divisor_32
Unexecuted instantiation: obu_ops.c:resolve_divisor_32
Unexecuted instantiation: obu_buf.c:resolve_divisor_32
Unexecuted instantiation: intrapred_avx2.c:resolve_divisor_32
Unexecuted instantiation: annexA.c:resolve_divisor_32
Unexecuted instantiation: alloccommon.c:resolve_divisor_32
Unexecuted instantiation: av2_loopfilter.c:resolve_divisor_32
Unexecuted instantiation: blockd.c:resolve_divisor_32
Unexecuted instantiation: cdef.c:resolve_divisor_32
Unexecuted instantiation: gdf.c:resolve_divisor_32
Unexecuted instantiation: gdf_block.c:resolve_divisor_32
Unexecuted instantiation: cdef_block.c:resolve_divisor_32
cfl.c:resolve_divisor_32
Line
Count
Source
81
513k
static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
82
513k
  int32_t f;
83
513k
  *shift = get_msb(D);
84
  // e is obtained from D after resetting the most significant 1 bit.
85
513k
  const int32_t e = D - ((uint32_t)1 << *shift);
86
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
87
513k
  if (*shift > DIV_LUT_BITS)
88
0
    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
89
513k
  else
90
513k
    f = e << (DIV_LUT_BITS - *shift);
91
513k
  assert(f <= DIV_LUT_NUM);
92
513k
  *shift += DIV_LUT_PREC_BITS;
93
  // Use f as lookup into the precomputed table of multipliers
94
513k
  return div_lut[f];
95
513k
}
Unexecuted instantiation: convolve.c:resolve_divisor_32
Unexecuted instantiation: entropy.c:resolve_divisor_32
Unexecuted instantiation: entropymode.c:resolve_divisor_32
Unexecuted instantiation: entropymv.c:resolve_divisor_32
Unexecuted instantiation: idct.c:resolve_divisor_32
Unexecuted instantiation: level.c:resolve_divisor_32
Unexecuted instantiation: mvref_common.c:resolve_divisor_32
Unexecuted instantiation: pred_common.c:resolve_divisor_32
Unexecuted instantiation: quant_common.c:resolve_divisor_32
Unexecuted instantiation: reconinter.c:resolve_divisor_32
reconintra.c:resolve_divisor_32
Line
Count
Source
81
55.7k
static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
82
55.7k
  int32_t f;
83
55.7k
  *shift = get_msb(D);
84
  // e is obtained from D after resetting the most significant 1 bit.
85
55.7k
  const int32_t e = D - ((uint32_t)1 << *shift);
86
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
87
55.7k
  if (*shift > DIV_LUT_BITS)
88
0
    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
89
55.7k
  else
90
55.7k
    f = e << (DIV_LUT_BITS - *shift);
91
55.7k
  assert(f <= DIV_LUT_NUM);
92
55.7k
  *shift += DIV_LUT_PREC_BITS;
93
  // Use f as lookup into the precomputed table of multipliers
94
55.7k
  return div_lut[f];
95
55.7k
}
Unexecuted instantiation: restoration.c:resolve_divisor_32
Unexecuted instantiation: scan.c:resolve_divisor_32
Unexecuted instantiation: thread_common.c:resolve_divisor_32
Unexecuted instantiation: tile_common.c:resolve_divisor_32
Unexecuted instantiation: timing.c:resolve_divisor_32
Unexecuted instantiation: tip.c:resolve_divisor_32
Unexecuted instantiation: txb_common.c:resolve_divisor_32
Unexecuted instantiation: warped_motion.c:resolve_divisor_32
Unexecuted instantiation: intra_matrix.c:resolve_divisor_32
Unexecuted instantiation: intra_dip.cc:resolve_divisor_32(unsigned int, short*)
Unexecuted instantiation: ccso.c:resolve_divisor_32
Unexecuted instantiation: bru.c:resolve_divisor_32
Unexecuted instantiation: obu_qm.c:resolve_divisor_32
Unexecuted instantiation: cfl_sse2.c:resolve_divisor_32
Unexecuted instantiation: cfl_ssse3.c:resolve_divisor_32
Unexecuted instantiation: av2_convolve_horiz_rs_sse4.c:resolve_divisor_32
Unexecuted instantiation: highbd_warp_plane_sse4.c:resolve_divisor_32
Unexecuted instantiation: optflow_refine_sse4.c:resolve_divisor_32
Unexecuted instantiation: affine_optflow_refine_avx2.c:resolve_divisor_32
Unexecuted instantiation: cfl_avx2.c:resolve_divisor_32
Unexecuted instantiation: highbd_ccso_avx2.c:resolve_divisor_32
Unexecuted instantiation: highbd_inv_txfm_avx2.c:resolve_divisor_32
Unexecuted instantiation: highbd_warp_affine_avx2.c:resolve_divisor_32
Unexecuted instantiation: gdf_block_avx2.c:resolve_divisor_32
intrapred.c:resolve_divisor_32
Line
Count
Source
81
253k
static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
82
253k
  int32_t f;
83
253k
  *shift = get_msb(D);
84
  // e is obtained from D after resetting the most significant 1 bit.
85
253k
  const int32_t e = D - ((uint32_t)1 << *shift);
86
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
87
253k
  if (*shift > DIV_LUT_BITS)
88
0
    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
89
253k
  else
90
253k
    f = e << (DIV_LUT_BITS - *shift);
91
253k
  assert(f <= DIV_LUT_NUM);
92
253k
  *shift += DIV_LUT_PREC_BITS;
93
  // Use f as lookup into the precomputed table of multipliers
94
253k
  return div_lut[f];
95
253k
}
highbd_intrapred_sse2.c:resolve_divisor_32
Line
Count
Source
81
483k
static INLINE int16_t resolve_divisor_32(uint32_t D, int16_t *shift) {
82
483k
  int32_t f;
83
483k
  *shift = get_msb(D);
84
  // e is obtained from D after resetting the most significant 1 bit.
85
483k
  const int32_t e = D - ((uint32_t)1 << *shift);
86
  // Get the most significant DIV_LUT_BITS (8) bits of e into f
87
483k
  if (*shift > DIV_LUT_BITS)
88
0
    f = ROUND_POWER_OF_TWO(e, *shift - DIV_LUT_BITS);
89
483k
  else
90
483k
    f = e << (DIV_LUT_BITS - *shift);
91
483k
  assert(f <= DIV_LUT_NUM);
92
483k
  *shift += DIV_LUT_PREC_BITS;
93
  // Use f as lookup into the precomputed table of multipliers
94
483k
  return div_lut[f];
95
483k
}
96
97
static INLINE int16_t resolve_divisor_32_CfL(int32_t N, int32_t D,
98
179k
                                             int16_t shift) {
99
179k
  int32_t f_n, f_d;
100
179k
  int ret;
101
102
179k
  assert(D >= 0);
103
179k
  int sign_N = N >= 0 ? 0 : 1;
104
105
179k
  if (sign_N) N = -N;
106
107
179k
  if (N == 0 || D == 0)
108
0
    return 0;
109
179k
  else {
110
179k
    int16_t shift_n = get_msb(N);
111
179k
    int16_t shift_d = get_msb(D);
112
    // e is obtained from D after resetting the most significant 1 bit.
113
179k
    const int32_t e_d = D - ((uint32_t)1 << shift_d);
114
    // Get the most significant DIV_LUT_BITS (8) bits of e into f
115
179k
    if (shift_d > DIV_LUT_BITS)
116
132k
      f_d = ROUND_POWER_OF_TWO(e_d, shift_d - DIV_LUT_BITS);
117
47.4k
    else
118
47.4k
      f_d = e_d << (DIV_LUT_BITS - shift_d);
119
179k
    assert(f_d <= DIV_LUT_NUM);
120
121
179k
    if (shift_n > DIV_LUT_BITS)
122
126k
      f_n = ROUND_POWER_OF_TWO(N, shift_n - DIV_LUT_BITS);
123
52.8k
    else
124
52.8k
      f_n = N << (DIV_LUT_BITS - shift_n);
125
126
179k
    assert(f_d <= DIV_LUT_NUM);
127
179k
    assert(f_n <= DIV_LUT_NUM * 2);
128
129
179k
    const int shift_add = shift_d - shift_n - shift;
130
131
    // The maximum value of `div_lut[f_d] * f_n` is
132
    // `1 << (DIV_LUT_PREC_BITS + DIV_LUT_BITS + 1)`
133
    // Hence `shift_add`below is constrained to be <= 1.
134
179k
    if (shift_add <= 1) {
135
176k
      const int shift0 = DIV_LUT_PREC_BITS + DIV_LUT_BITS + shift_add;
136
176k
      ret = shift0 >= 0 ? (div_lut[f_d] * f_n) >> shift0 : (2 << shift) - 1;
137
176k
    } else {
138
2.98k
      ret = 0;
139
2.98k
    }
140
179k
    if (ret >= (2 << shift) - 1) ret = (2 << shift) - 1;
141
142
179k
    if (sign_N) ret = -ret;
143
179k
    return ret;
144
179k
  }
145
179k
}
Unexecuted instantiation: av2_dx_iface.c:resolve_divisor_32_CfL
Unexecuted instantiation: annexF.c:resolve_divisor_32_CfL
Unexecuted instantiation: decodeframe.c:resolve_divisor_32_CfL
Unexecuted instantiation: decodemv.c:resolve_divisor_32_CfL
Unexecuted instantiation: decoder.c:resolve_divisor_32_CfL
Unexecuted instantiation: decodetxb.c:resolve_divisor_32_CfL
Unexecuted instantiation: detokenize.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_fgm.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_ci.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_atlas.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_lcr.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_ops.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_buf.c:resolve_divisor_32_CfL
Unexecuted instantiation: intrapred_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: annexA.c:resolve_divisor_32_CfL
Unexecuted instantiation: alloccommon.c:resolve_divisor_32_CfL
Unexecuted instantiation: av2_loopfilter.c:resolve_divisor_32_CfL
Unexecuted instantiation: blockd.c:resolve_divisor_32_CfL
Unexecuted instantiation: cdef.c:resolve_divisor_32_CfL
Unexecuted instantiation: gdf.c:resolve_divisor_32_CfL
Unexecuted instantiation: gdf_block.c:resolve_divisor_32_CfL
Unexecuted instantiation: cdef_block.c:resolve_divisor_32_CfL
cfl.c:resolve_divisor_32_CfL
Line
Count
Source
98
165k
                                             int16_t shift) {
99
165k
  int32_t f_n, f_d;
100
165k
  int ret;
101
102
165k
  assert(D >= 0);
103
165k
  int sign_N = N >= 0 ? 0 : 1;
104
105
165k
  if (sign_N) N = -N;
106
107
165k
  if (N == 0 || D == 0)
108
0
    return 0;
109
165k
  else {
110
165k
    int16_t shift_n = get_msb(N);
111
165k
    int16_t shift_d = get_msb(D);
112
    // e is obtained from D after resetting the most significant 1 bit.
113
165k
    const int32_t e_d = D - ((uint32_t)1 << shift_d);
114
    // Get the most significant DIV_LUT_BITS (8) bits of e into f
115
165k
    if (shift_d > DIV_LUT_BITS)
116
126k
      f_d = ROUND_POWER_OF_TWO(e_d, shift_d - DIV_LUT_BITS);
117
38.9k
    else
118
38.9k
      f_d = e_d << (DIV_LUT_BITS - shift_d);
119
165k
    assert(f_d <= DIV_LUT_NUM);
120
121
165k
    if (shift_n > DIV_LUT_BITS)
122
121k
      f_n = ROUND_POWER_OF_TWO(N, shift_n - DIV_LUT_BITS);
123
44.7k
    else
124
44.7k
      f_n = N << (DIV_LUT_BITS - shift_n);
125
126
165k
    assert(f_d <= DIV_LUT_NUM);
127
165k
    assert(f_n <= DIV_LUT_NUM * 2);
128
129
165k
    const int shift_add = shift_d - shift_n - shift;
130
131
    // The maximum value of `div_lut[f_d] * f_n` is
132
    // `1 << (DIV_LUT_PREC_BITS + DIV_LUT_BITS + 1)`
133
    // Hence `shift_add`below is constrained to be <= 1.
134
165k
    if (shift_add <= 1) {
135
162k
      const int shift0 = DIV_LUT_PREC_BITS + DIV_LUT_BITS + shift_add;
136
162k
      ret = shift0 >= 0 ? (div_lut[f_d] * f_n) >> shift0 : (2 << shift) - 1;
137
162k
    } else {
138
2.94k
      ret = 0;
139
2.94k
    }
140
165k
    if (ret >= (2 << shift) - 1) ret = (2 << shift) - 1;
141
142
165k
    if (sign_N) ret = -ret;
143
165k
    return ret;
144
165k
  }
145
165k
}
Unexecuted instantiation: convolve.c:resolve_divisor_32_CfL
Unexecuted instantiation: entropy.c:resolve_divisor_32_CfL
Unexecuted instantiation: entropymode.c:resolve_divisor_32_CfL
Unexecuted instantiation: entropymv.c:resolve_divisor_32_CfL
Unexecuted instantiation: idct.c:resolve_divisor_32_CfL
Unexecuted instantiation: level.c:resolve_divisor_32_CfL
Unexecuted instantiation: mvref_common.c:resolve_divisor_32_CfL
Unexecuted instantiation: pred_common.c:resolve_divisor_32_CfL
Unexecuted instantiation: quant_common.c:resolve_divisor_32_CfL
reconinter.c:resolve_divisor_32_CfL
Line
Count
Source
98
13.6k
                                             int16_t shift) {
99
13.6k
  int32_t f_n, f_d;
100
13.6k
  int ret;
101
102
13.6k
  assert(D >= 0);
103
13.6k
  int sign_N = N >= 0 ? 0 : 1;
104
105
13.6k
  if (sign_N) N = -N;
106
107
13.6k
  if (N == 0 || D == 0)
108
0
    return 0;
109
13.6k
  else {
110
13.6k
    int16_t shift_n = get_msb(N);
111
13.6k
    int16_t shift_d = get_msb(D);
112
    // e is obtained from D after resetting the most significant 1 bit.
113
13.6k
    const int32_t e_d = D - ((uint32_t)1 << shift_d);
114
    // Get the most significant DIV_LUT_BITS (8) bits of e into f
115
13.6k
    if (shift_d > DIV_LUT_BITS)
116
5.17k
      f_d = ROUND_POWER_OF_TWO(e_d, shift_d - DIV_LUT_BITS);
117
8.50k
    else
118
8.50k
      f_d = e_d << (DIV_LUT_BITS - shift_d);
119
13.6k
    assert(f_d <= DIV_LUT_NUM);
120
121
13.6k
    if (shift_n > DIV_LUT_BITS)
122
5.57k
      f_n = ROUND_POWER_OF_TWO(N, shift_n - DIV_LUT_BITS);
123
8.10k
    else
124
8.10k
      f_n = N << (DIV_LUT_BITS - shift_n);
125
126
13.6k
    assert(f_d <= DIV_LUT_NUM);
127
13.6k
    assert(f_n <= DIV_LUT_NUM * 2);
128
129
13.6k
    const int shift_add = shift_d - shift_n - shift;
130
131
    // The maximum value of `div_lut[f_d] * f_n` is
132
    // `1 << (DIV_LUT_PREC_BITS + DIV_LUT_BITS + 1)`
133
    // Hence `shift_add`below is constrained to be <= 1.
134
13.6k
    if (shift_add <= 1) {
135
13.6k
      const int shift0 = DIV_LUT_PREC_BITS + DIV_LUT_BITS + shift_add;
136
13.6k
      ret = shift0 >= 0 ? (div_lut[f_d] * f_n) >> shift0 : (2 << shift) - 1;
137
13.6k
    } else {
138
44
      ret = 0;
139
44
    }
140
13.6k
    if (ret >= (2 << shift) - 1) ret = (2 << shift) - 1;
141
142
13.6k
    if (sign_N) ret = -ret;
143
13.6k
    return ret;
144
13.6k
  }
145
13.6k
}
Unexecuted instantiation: reconintra.c:resolve_divisor_32_CfL
Unexecuted instantiation: restoration.c:resolve_divisor_32_CfL
Unexecuted instantiation: scan.c:resolve_divisor_32_CfL
Unexecuted instantiation: thread_common.c:resolve_divisor_32_CfL
Unexecuted instantiation: tile_common.c:resolve_divisor_32_CfL
Unexecuted instantiation: timing.c:resolve_divisor_32_CfL
Unexecuted instantiation: tip.c:resolve_divisor_32_CfL
Unexecuted instantiation: txb_common.c:resolve_divisor_32_CfL
Unexecuted instantiation: warped_motion.c:resolve_divisor_32_CfL
Unexecuted instantiation: intra_matrix.c:resolve_divisor_32_CfL
Unexecuted instantiation: intra_dip.cc:resolve_divisor_32_CfL(int, int, short)
Unexecuted instantiation: ccso.c:resolve_divisor_32_CfL
Unexecuted instantiation: bru.c:resolve_divisor_32_CfL
Unexecuted instantiation: obu_qm.c:resolve_divisor_32_CfL
Unexecuted instantiation: cfl_sse2.c:resolve_divisor_32_CfL
Unexecuted instantiation: cfl_ssse3.c:resolve_divisor_32_CfL
Unexecuted instantiation: av2_convolve_horiz_rs_sse4.c:resolve_divisor_32_CfL
Unexecuted instantiation: highbd_warp_plane_sse4.c:resolve_divisor_32_CfL
Unexecuted instantiation: optflow_refine_sse4.c:resolve_divisor_32_CfL
Unexecuted instantiation: affine_optflow_refine_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: cfl_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: highbd_ccso_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: highbd_inv_txfm_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: highbd_warp_affine_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: gdf_block_avx2.c:resolve_divisor_32_CfL
Unexecuted instantiation: intrapred.c:resolve_divisor_32_CfL
Unexecuted instantiation: highbd_intrapred_sse2.c:resolve_divisor_32_CfL
146
147
extern const int16_t av2_warped_filter[WARPEDPIXEL_PREC_SHIFTS * 7 + 1][8];
148
149
DECLARE_ALIGNED(8, extern const int8_t,
150
                av2_filter_8bit[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8]);
151
152
extern const int16_t av2_ext_warped_filter[EXT_WARP_PHASES + 1]
153
                                          [EXT_WARP_STORAGE_TAPS];
154
155
static const uint8_t warp_pad_left[14][16] = {
156
  { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
157
  { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
158
  { 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
159
  { 4, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
160
  { 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
161
  { 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
162
  { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
163
  { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15 },
164
  { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 12, 13, 14, 15 },
165
  { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15 },
166
  { 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 15 },
167
  { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15 },
168
  { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15 },
169
  { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 },
170
};
171
172
static const uint8_t warp_pad_right[14][16] = {
173
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14 },
174
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13 },
175
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12 },
176
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11 },
177
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10 },
178
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9 },
179
  { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 },
180
  { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 },
181
  { 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 },
182
  { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 },
183
  { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
184
  { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
185
  { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
186
  { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
187
};
188
189
// Recompute the translational part of a warp model, so that the center
190
// of the current block (determined by `mi_row`, `mi_col`, `bsize`)
191
// has an induced motion vector of `mv`
192
void av2_set_warp_translation(int mi_row, int mi_col, BLOCK_SIZE bsize, MV mv,
193
                              WarpedMotionParams *wm);
194
195
void av2_highbd_warp_plane(WarpedMotionParams *wm, const uint16_t *const ref,
196
                           int width, int height, int stride,
197
                           uint16_t *const pred, int p_col, int p_row,
198
                           int p_width, int p_height, int p_stride,
199
                           int subsampling_x, int subsampling_y, int bd,
200
                           ConvolveParams *conv_params,
201
                           const struct scale_factors *sf, int use_warp_bd_box,
202
                           PadBlock *warp_bd_box);
203
204
void av2_warp_plane(WarpedMotionParams *wm, int bd, const uint16_t *ref,
205
                    int width, int height, int stride, uint16_t *pred,
206
                    int p_col, int p_row, int p_width, int p_height,
207
                    int p_stride, int subsampling_x, int subsampling_y,
208
                    ConvolveParams *conv_params, const struct scale_factors *sf,
209
                    int use_warp_bd_box, PadBlock *warp_bd_box);
210
211
void av2_find_projection(int np, const int *pts1, const int *pts2,
212
                         BLOCK_SIZE bsize, MV mv, WarpedMotionParams *wm_params,
213
                         int mi_row, int mi_col,
214
                         const struct scale_factors *sf);
215
216
void av2_get_shear_params(WarpedMotionParams *wm,
217
                          const struct scale_factors *sf);
218
219
// Reduce the precision of a warp model, ready for use in the warp filter
220
// and for storage. This should be called after the non-translational parameters
221
// are calculated, but before av2_set_warp_translation() or
222
// av2_get_shear_params() are called
223
void av2_reduce_warp_model(WarpedMotionParams *wm);
224
225
// Check if a model is already properly reduced, according to the same logic
226
// used in av2_reduce_warp_model()
227
bool av2_is_warp_model_reduced(WarpedMotionParams *wm);
228
229
int av2_extend_warp_model(const bool neighbor_is_above, const BLOCK_SIZE bsize,
230
                          const MV *center_mv, const int mi_row,
231
                          const int mi_col,
232
                          const WarpedMotionParams *neighbor_wm,
233
                          WarpedMotionParams *wm_params,
234
                          const struct scale_factors *sf);
235
236
// Given a warp model which was initially used at a temporal distance of
237
// `in_distance`, rescale it to a new temporal distance of `out_distance`.
238
// Both distances are allowed to be negative, but they must be nonzero.
239
//
240
// The mathematically ideal way to rescale a warp model from one temporal
241
// distance to another would be to use a matrix exponential: If we write the
242
// input model as a 3x3 matrix M, then the output model should be
243
//
244
//  ideal output = M ^ (out_distance / in_distance)
245
//
246
// However, computing a matrix exponential is complicated, especially in
247
// fixed point, and so would not be very hardware friendly. In addition,
248
// this function is mainly used to predict global motion parameters, with
249
// the true values being coded as a delta from this prediction. As the
250
// global motion will not be perfectly consistent, there's a limit to how
251
// accurate our prediction can be.
252
//
253
// For these reasons, we approximate the matrix exponential using its
254
// first-order Taylor series:
255
//
256
//  output = I + (M - I) * (out_distance / in_distance)
257
//
258
// This is far easier to compute, and provides a "good enough" approximation
259
// for the models we use in practice, which are all reasonably near to the
260
// identity model (all parameters except for the translational part are
261
// within +/- 1/2 of the identity).
262
static INLINE void av2_scale_warp_model(const WarpedMotionParams *in_params,
263
                                        int in_distance,
264
                                        WarpedMotionParams *out_params,
265
0
                                        int out_distance) {
266
0
  static int param_shift[MAX_PARAMDIM] = {
267
0
    GM_TRANS_PREC_DIFF, GM_TRANS_PREC_DIFF, GM_ALPHA_PREC_DIFF,
268
0
    GM_ALPHA_PREC_DIFF, GM_ALPHA_PREC_DIFF, GM_ALPHA_PREC_DIFF
269
0
  };
270
271
0
  static int param_min[MAX_PARAMDIM] = { GM_TRANS_MIN, GM_TRANS_MIN,
272
0
                                         GM_ALPHA_MIN, GM_ALPHA_MIN,
273
0
                                         GM_ALPHA_MIN, GM_ALPHA_MIN };
274
275
0
  static int param_max[MAX_PARAMDIM] = { GM_TRANS_MAX, GM_TRANS_MAX,
276
0
                                         GM_ALPHA_MAX, GM_ALPHA_MAX,
277
0
                                         GM_ALPHA_MAX, GM_ALPHA_MAX };
278
279
  // If in_distance == 0, then we can't meaningfully scale the model because
280
  // this would correspond to a division by 0. So we fall back to using the
281
  // identity model as a reference.
282
  //
283
  // Note: Global motion is disabled for temporal distances of 0, so in this
284
  // situation the input model must be the identity model anyway. Check this
285
  // constraint here to help keep things internally consistent.
286
0
  if (in_distance == 0) {
287
0
    *out_params = default_warp_params;
288
0
    return;
289
0
  }
290
291
  // If out_distance == 0, then global motion is disabled, so we shouldn't
292
  // get to this function
293
0
  assert(out_distance != 0);
294
295
  // Flip signs so that in_distance is positive.
296
  // We do this because
297
  //   scaled_value = (... + divisor/2) / divisor
298
  // is the simplest way to implement division with round-to-nearest in C,
299
  // but it only works correctly if the divisor is positive
300
0
  if (in_distance < 0) {
301
0
    in_distance = -in_distance;
302
0
    out_distance = -out_distance;
303
0
  }
304
0
  const int input_max = (1 << 22) - 1;
305
306
0
  out_params->wmtype = in_params->wmtype;
307
0
  for (int param = 0; param < MAX_PARAMDIM; param++) {
308
0
    int center = default_warp_params.wmmat[param];
309
310
0
    const int input =
311
0
        clamp(in_params->wmmat[param] - center, -input_max, input_max);
312
0
    int16_t shift = 0;
313
0
    int16_t inv_divisor =
314
0
        resolve_divisor_32((uint32_t)abs(in_distance), &shift);
315
0
    if (inv_divisor >= 512) {
316
0
      inv_divisor >>= 1;
317
0
      shift--;
318
0
    }
319
0
    int sign = in_distance < 0 ? -1 : 1;
320
0
    inv_divisor *= sign;
321
    // input: 23 bits, in/out_distance: 8 bits (get_relative_dist output limit)
322
    // Intermediate result is in 32 bits (input: 23 bits, inv_divisor: 9 bits).
323
    // output is in 23 bits because abs(inv_divisor) < (1<<shift)
324
0
    int output = ROUND_POWER_OF_TWO_SIGNED(input * inv_divisor, shift);
325
    // Intermediate result is in 31 bits (23 bits * 8 bits)
326
0
    output =
327
0
        ROUND_POWER_OF_TWO_SIGNED(output * out_distance, param_shift[param]);
328
0
    output = clamp(output, param_min[param], param_max[param]) *
329
0
             (1 << param_shift[param]);
330
331
0
    out_params->wmmat[param] = center + output;
332
0
  }
333
0
}
Unexecuted instantiation: av2_dx_iface.c:av2_scale_warp_model
Unexecuted instantiation: annexF.c:av2_scale_warp_model
Unexecuted instantiation: decodeframe.c:av2_scale_warp_model
Unexecuted instantiation: decodemv.c:av2_scale_warp_model
Unexecuted instantiation: decoder.c:av2_scale_warp_model
Unexecuted instantiation: decodetxb.c:av2_scale_warp_model
Unexecuted instantiation: detokenize.c:av2_scale_warp_model
Unexecuted instantiation: obu_fgm.c:av2_scale_warp_model
Unexecuted instantiation: obu.c:av2_scale_warp_model
Unexecuted instantiation: obu_ci.c:av2_scale_warp_model
Unexecuted instantiation: obu_atlas.c:av2_scale_warp_model
Unexecuted instantiation: obu_lcr.c:av2_scale_warp_model
Unexecuted instantiation: obu_ops.c:av2_scale_warp_model
Unexecuted instantiation: obu_buf.c:av2_scale_warp_model
Unexecuted instantiation: intrapred_avx2.c:av2_scale_warp_model
Unexecuted instantiation: annexA.c:av2_scale_warp_model
Unexecuted instantiation: alloccommon.c:av2_scale_warp_model
Unexecuted instantiation: av2_loopfilter.c:av2_scale_warp_model
Unexecuted instantiation: blockd.c:av2_scale_warp_model
Unexecuted instantiation: cdef.c:av2_scale_warp_model
Unexecuted instantiation: gdf.c:av2_scale_warp_model
Unexecuted instantiation: gdf_block.c:av2_scale_warp_model
Unexecuted instantiation: cdef_block.c:av2_scale_warp_model
Unexecuted instantiation: cfl.c:av2_scale_warp_model
Unexecuted instantiation: convolve.c:av2_scale_warp_model
Unexecuted instantiation: entropy.c:av2_scale_warp_model
Unexecuted instantiation: entropymode.c:av2_scale_warp_model
Unexecuted instantiation: entropymv.c:av2_scale_warp_model
Unexecuted instantiation: idct.c:av2_scale_warp_model
Unexecuted instantiation: level.c:av2_scale_warp_model
Unexecuted instantiation: mvref_common.c:av2_scale_warp_model
Unexecuted instantiation: pred_common.c:av2_scale_warp_model
Unexecuted instantiation: quant_common.c:av2_scale_warp_model
Unexecuted instantiation: reconinter.c:av2_scale_warp_model
Unexecuted instantiation: reconintra.c:av2_scale_warp_model
Unexecuted instantiation: restoration.c:av2_scale_warp_model
Unexecuted instantiation: scan.c:av2_scale_warp_model
Unexecuted instantiation: thread_common.c:av2_scale_warp_model
Unexecuted instantiation: tile_common.c:av2_scale_warp_model
Unexecuted instantiation: timing.c:av2_scale_warp_model
Unexecuted instantiation: tip.c:av2_scale_warp_model
Unexecuted instantiation: txb_common.c:av2_scale_warp_model
Unexecuted instantiation: warped_motion.c:av2_scale_warp_model
Unexecuted instantiation: intra_matrix.c:av2_scale_warp_model
Unexecuted instantiation: intra_dip.cc:av2_scale_warp_model(WarpedMotionParams const*, int, WarpedMotionParams*, int)
Unexecuted instantiation: ccso.c:av2_scale_warp_model
Unexecuted instantiation: bru.c:av2_scale_warp_model
Unexecuted instantiation: obu_qm.c:av2_scale_warp_model
Unexecuted instantiation: cfl_sse2.c:av2_scale_warp_model
Unexecuted instantiation: cfl_ssse3.c:av2_scale_warp_model
Unexecuted instantiation: av2_convolve_horiz_rs_sse4.c:av2_scale_warp_model
Unexecuted instantiation: highbd_warp_plane_sse4.c:av2_scale_warp_model
Unexecuted instantiation: optflow_refine_sse4.c:av2_scale_warp_model
Unexecuted instantiation: affine_optflow_refine_avx2.c:av2_scale_warp_model
Unexecuted instantiation: cfl_avx2.c:av2_scale_warp_model
Unexecuted instantiation: highbd_ccso_avx2.c:av2_scale_warp_model
Unexecuted instantiation: highbd_inv_txfm_avx2.c:av2_scale_warp_model
Unexecuted instantiation: highbd_warp_affine_avx2.c:av2_scale_warp_model
Unexecuted instantiation: gdf_block_avx2.c:av2_scale_warp_model
Unexecuted instantiation: intrapred.c:av2_scale_warp_model
Unexecuted instantiation: highbd_intrapred_sse2.c:av2_scale_warp_model
334
335
int_mv get_warp_motion_vector_xy_pos(const MACROBLOCKD *xd,
336
                                     const WarpedMotionParams *model,
337
                                     const int x, const int y,
338
                                     MvSubpelPrecision precision);
339
int get_model_from_corner_mvs(WarpedMotionParams *derive_model, int *pts,
340
                              int np, int *mvs, const BLOCK_SIZE bsize,
341
                              const struct scale_factors *sf);
342
#endif  // AVM_AV2_COMMON_WARPED_MOTION_H_