Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
4 : * This source code is subject to the terms of the BSD 2 Clause License and
5 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 : * was not distributed with this source code in the LICENSE file, you can
7 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 : * Media Patent License 1.0 was not distributed with this source code in the
9 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 : */
11 :
12 : #include "EbDefinitions.h"
13 : #include "aom_dsp_rtcd.h"
14 :
15 : #ifdef __cplusplus
16 : extern "C" {
17 : #endif
18 : typedef uint32_t(*high_variance_fn_t)(const uint16_t *src, int32_t src_stride,
19 : const uint16_t *ref, int32_t ref_stride,
20 : uint32_t *sse, int32_t *sum);
21 :
22 : uint32_t aom_highbd_calc8x8var_sse2(const uint16_t *src, int32_t src_stride,
23 : const uint16_t *ref, int32_t ref_stride,
24 : uint32_t *sse, int32_t *sum);
25 :
26 : uint32_t aom_highbd_calc16x16var_sse2(const uint16_t *src, int32_t src_stride,
27 : const uint16_t *ref, int32_t ref_stride,
28 : uint32_t *sse, int32_t *sum);
29 :
30 : #ifdef __cplusplus
31 : }
32 : #endif // __cplusplus
33 0 : static void highbd_8_variance_sse2(const uint16_t *src, int32_t src_stride,
34 : const uint16_t *ref, int32_t ref_stride, int32_t w,
35 : int32_t h, uint32_t *sse, int32_t *sum,
36 : high_variance_fn_t var_fn, int32_t block_size) {
37 : int32_t i, j;
38 :
39 0 : *sse = 0;
40 0 : *sum = 0;
41 :
42 0 : for (i = 0; i < h; i += block_size) {
43 0 : for (j = 0; j < w; j += block_size) {
44 : uint32_t sse0;
45 : int32_t sum0;
46 0 : var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j,
47 : ref_stride, &sse0, &sum0);
48 0 : *sse += sse0;
49 0 : *sum += sum0;
50 : }
51 : }
52 0 : }
53 :
54 0 : static void highbd_10_variance_sse2(const uint16_t *src, int32_t src_stride,
55 : const uint16_t *ref, int32_t ref_stride, int32_t w,
56 : int32_t h, uint32_t *sse, int32_t *sum,
57 : high_variance_fn_t var_fn, int32_t block_size) {
58 : int32_t i, j;
59 0 : uint64_t sse_long = 0;
60 0 : int32_t sum_long = 0;
61 :
62 0 : for (i = 0; i < h; i += block_size) {
63 0 : for (j = 0; j < w; j += block_size) {
64 : uint32_t sse0;
65 : int32_t sum0;
66 0 : var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j,
67 : ref_stride, &sse0, &sum0);
68 0 : sse_long += sse0;
69 0 : sum_long += sum0;
70 : }
71 : }
72 0 : *sum = ROUND_POWER_OF_TWO(sum_long, 2);
73 0 : *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4);
74 0 : }
75 :
76 0 : static void highbd_12_variance_sse2(const uint16_t *src, int32_t src_stride,
77 : const uint16_t *ref, int32_t ref_stride, int32_t w,
78 : int32_t h, uint32_t *sse, int32_t *sum,
79 : high_variance_fn_t var_fn, int32_t block_size) {
80 : int32_t i, j;
81 0 : uint64_t sse_long = 0;
82 0 : int32_t sum_long = 0;
83 :
84 0 : for (i = 0; i < h; i += block_size) {
85 0 : for (j = 0; j < w; j += block_size) {
86 : uint32_t sse0;
87 : int32_t sum0;
88 0 : var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j,
89 : ref_stride, &sse0, &sum0);
90 0 : sse_long += sse0;
91 0 : sum_long += sum0;
92 : }
93 : }
94 0 : *sum = ROUND_POWER_OF_TWO(sum_long, 4);
95 0 : *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8);
96 0 : }
97 :
98 : #define HIGH_GET_VAR(S) \
99 : void eb_aom_highbd_get##S##x##S##var_sse2(const uint8_t *src8, int32_t src_stride, \
100 : const uint8_t *ref8, int32_t ref_stride, \
101 : uint32_t *sse, int32_t *sum) { \
102 : uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
103 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
104 : aom_highbd_calc##S##x##S##var_sse2(src, src_stride, ref, ref_stride, sse, \
105 : sum); \
106 : } \
107 : \
108 : void eb_aom_highbd_10_get##S##x##S##var_sse2( \
109 : const uint8_t *src8, int32_t src_stride, const uint8_t *ref8, \
110 : int32_t ref_stride, uint32_t *sse, int32_t *sum) { \
111 : uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
112 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
113 : aom_highbd_calc##S##x##S##var_sse2(src, src_stride, ref, ref_stride, sse, \
114 : sum); \
115 : *sum = ROUND_POWER_OF_TWO(*sum, 2); \
116 : *sse = ROUND_POWER_OF_TWO(*sse, 4); \
117 : } \
118 : \
119 : void eb_aom_highbd_12_get##S##x##S##var_sse2( \
120 : const uint8_t *src8, int32_t src_stride, const uint8_t *ref8, \
121 : int32_t ref_stride, uint32_t *sse, int32_t *sum) { \
122 : uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
123 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
124 : aom_highbd_calc##S##x##S##var_sse2(src, src_stride, ref, ref_stride, sse, \
125 : sum); \
126 : *sum = ROUND_POWER_OF_TWO(*sum, 4); \
127 : *sse = ROUND_POWER_OF_TWO(*sse, 8); \
128 : }
129 :
130 0 : HIGH_GET_VAR(16);
131 0 : HIGH_GET_VAR(8);
132 :
133 : #undef HIGH_GET_VAR
134 :
135 : #define VAR_FN(w, h, block_size, shift) \
136 : uint32_t eb_aom_highbd_8_variance##w##x##h##_sse2( \
137 : const uint8_t *src8, int32_t src_stride, const uint8_t *ref8, \
138 : int32_t ref_stride, uint32_t *sse) { \
139 : int32_t sum; \
140 : uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
141 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
142 : highbd_8_variance_sse2( \
143 : src, src_stride, ref, ref_stride, w, h, sse, &sum, \
144 : aom_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
145 : return *sse - (uint32_t)(((int64_t)sum * sum) >> shift); \
146 : } \
147 : \
148 : uint32_t eb_aom_highbd_10_variance##w##x##h##_sse2( \
149 : const uint8_t *src8, int32_t src_stride, const uint8_t *ref8, \
150 : int32_t ref_stride, uint32_t *sse) { \
151 : int32_t sum; \
152 : int64_t var; \
153 : uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
154 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
155 : highbd_10_variance_sse2( \
156 : src, src_stride, ref, ref_stride, w, h, sse, &sum, \
157 : aom_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
158 : var = (int64_t)(*sse) - (((int64_t)sum * sum) >> shift); \
159 : return (var >= 0) ? (uint32_t)var : 0; \
160 : } \
161 : \
162 : uint32_t eb_aom_highbd_12_variance##w##x##h##_sse2( \
163 : const uint8_t *src8, int32_t src_stride, const uint8_t *ref8, \
164 : int32_t ref_stride, uint32_t *sse) { \
165 : int32_t sum; \
166 : int64_t var; \
167 : uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
168 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
169 : highbd_12_variance_sse2( \
170 : src, src_stride, ref, ref_stride, w, h, sse, &sum, \
171 : aom_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
172 : var = (int64_t)(*sse) - (((int64_t)sum * sum) >> shift); \
173 : return (var >= 0) ? (uint32_t)var : 0; \
174 : }
175 :
176 0 : VAR_FN(64, 64, 16, 12);
177 0 : VAR_FN(64, 32, 16, 11);
178 0 : VAR_FN(32, 64, 16, 11);
179 0 : VAR_FN(32, 32, 16, 10);
180 0 : VAR_FN(32, 16, 16, 9);
181 0 : VAR_FN(16, 32, 16, 9);
182 0 : VAR_FN(16, 16, 16, 8);
183 0 : VAR_FN(16, 8, 8, 7);
184 0 : VAR_FN(8, 16, 8, 7);
185 0 : VAR_FN(8, 8, 8, 6);
186 0 : VAR_FN(16, 4, 16, 6);
187 0 : VAR_FN(8, 32, 8, 8);
188 0 : VAR_FN(32, 8, 8, 8);
189 0 : VAR_FN(16, 64, 16, 10);
190 0 : VAR_FN(64, 16, 16, 10);
191 :
192 : #undef VAR_FN
193 :
194 0 : void eb_aom_highbd_8_mse16x16_sse2(const uint8_t *src8, int32_t src_stride,
195 : const uint8_t *ref8, int32_t ref_stride,
196 : uint32_t *sse) {
197 : int32_t sum;
198 0 : uint16_t *src = CONVERT_TO_SHORTPTR(src8);
199 0 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
200 :
201 : /*TODO: Remove calculate unused sum.*/
202 0 : highbd_8_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum,
203 : aom_highbd_calc16x16var_sse2, 16);
204 0 : }
|