Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | #include <stdlib.h> |
| 13 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 14 | #include "config/aom_config.h" |
Tom Finegan | 44702c8 | 2018-05-22 13:00:39 -0700 | [diff] [blame] | 15 | #include "config/aom_dsp_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 18 | #include "aom_ports/mem.h" |
David Barker | c155e01 | 2017-05-11 13:54:54 +0100 | [diff] [blame] | 19 | #include "aom_dsp/blend.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | |
| 21 | /* Sum the difference between every corresponding element of the buffers. */ |
| 22 | static INLINE unsigned int sad(const uint8_t *a, int a_stride, const uint8_t *b, |
| 23 | int b_stride, int width, int height) { |
| 24 | int y, x; |
| 25 | unsigned int sad = 0; |
| 26 | |
| 27 | for (y = 0; y < height; y++) { |
| 28 | for (x = 0; x < width; x++) sad += abs(a[x] - b[x]); |
| 29 | |
| 30 | a += a_stride; |
| 31 | b += b_stride; |
| 32 | } |
| 33 | return sad; |
| 34 | } |
| 35 | |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 36 | #define sadMxh(m) \ |
| 37 | unsigned int aom_sad##m##xh_c(const uint8_t *a, int a_stride, \ |
| 38 | const uint8_t *b, int b_stride, int width, \ |
| 39 | int height) { \ |
| 40 | return sad(a, a_stride, b, b_stride, width, height); \ |
| 41 | } |
| 42 | |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 43 | #define sadMxN(m, n) \ |
| 44 | unsigned int aom_sad##m##x##n##_c(const uint8_t *src, int src_stride, \ |
| 45 | const uint8_t *ref, int ref_stride) { \ |
| 46 | return sad(src, src_stride, ref, ref_stride, m, n); \ |
| 47 | } \ |
| 48 | unsigned int aom_sad##m##x##n##_avg_c(const uint8_t *src, int src_stride, \ |
| 49 | const uint8_t *ref, int ref_stride, \ |
| 50 | const uint8_t *second_pred) { \ |
| 51 | uint8_t comp_pred[m * n]; \ |
| 52 | aom_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \ |
| 53 | return sad(src, src_stride, comp_pred, m, m, n); \ |
| 54 | } \ |
| 55 | unsigned int aom_jnt_sad##m##x##n##_avg_c( \ |
| 56 | const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ |
| 57 | const uint8_t *second_pred, const JNT_COMP_PARAMS *jcp_param) { \ |
| 58 | uint8_t comp_pred[m * n]; \ |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 59 | aom_jnt_comp_avg_pred_c(comp_pred, second_pred, m, n, ref, ref_stride, \ |
| 60 | jcp_param); \ |
Cheng Chen | f78632e | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 61 | return sad(src, src_stride, comp_pred, m, m, n); \ |
| 62 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | |
Kyle Siefring | ef6e2df | 2018-04-10 14:51:35 -0400 | [diff] [blame] | 64 | // Calculate sad against 4 reference locations and store each in sad_array |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 65 | #define sadMxNx4D(m, n) \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 66 | void aom_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | const uint8_t *const ref_array[], \ |
| 68 | int ref_stride, uint32_t *sad_array) { \ |
| 69 | int i; \ |
| 70 | for (i = 0; i < 4; ++i) \ |
| 71 | sad_array[i] = \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 72 | aom_sad##m##x##n##_c(src, src_stride, ref_array[i], ref_stride); \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /* clang-format off */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | // 128x128 |
| 77 | sadMxN(128, 128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | sadMxNx4D(128, 128) |
| 79 | |
| 80 | // 128x64 |
| 81 | sadMxN(128, 64) |
| 82 | sadMxNx4D(128, 64) |
| 83 | |
| 84 | // 64x128 |
| 85 | sadMxN(64, 128) |
| 86 | sadMxNx4D(64, 128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 87 | |
| 88 | // 64x64 |
| 89 | sadMxN(64, 64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | sadMxNx4D(64, 64) |
| 91 | |
| 92 | // 64x32 |
| 93 | sadMxN(64, 32) |
| 94 | sadMxNx4D(64, 32) |
| 95 | |
| 96 | // 32x64 |
| 97 | sadMxN(32, 64) |
| 98 | sadMxNx4D(32, 64) |
| 99 | |
| 100 | // 32x32 |
| 101 | sadMxN(32, 32) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 102 | sadMxNx4D(32, 32) |
| 103 | |
| 104 | // 32x16 |
| 105 | sadMxN(32, 16) |
| 106 | sadMxNx4D(32, 16) |
| 107 | |
| 108 | // 16x32 |
| 109 | sadMxN(16, 32) |
| 110 | sadMxNx4D(16, 32) |
| 111 | |
| 112 | // 16x16 |
| 113 | sadMxN(16, 16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 114 | sadMxNx4D(16, 16) |
| 115 | |
| 116 | // 16x8 |
| 117 | sadMxN(16, 8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 118 | sadMxNx4D(16, 8) |
| 119 | |
| 120 | // 8x16 |
| 121 | sadMxN(8, 16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 122 | sadMxNx4D(8, 16) |
| 123 | |
| 124 | // 8x8 |
| 125 | sadMxN(8, 8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 126 | sadMxNx4D(8, 8) |
| 127 | |
| 128 | // 8x4 |
| 129 | sadMxN(8, 4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 130 | sadMxNx4D(8, 4) |
| 131 | |
| 132 | // 4x8 |
| 133 | sadMxN(4, 8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | sadMxNx4D(4, 8) |
| 135 | |
| 136 | // 4x4 |
| 137 | sadMxN(4, 4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 138 | sadMxNx4D(4, 4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 139 | |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 140 | sadMxh(128); |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 141 | sadMxh(64); |
| 142 | sadMxh(32); |
| 143 | sadMxh(16); |
| 144 | sadMxh(8); |
| 145 | sadMxh(4); |
Cheng Chen | d0179a6 | 2017-11-16 17:02:53 -0800 | [diff] [blame] | 146 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 147 | sadMxN(4, 16) |
| 148 | sadMxNx4D(4, 16) |
| 149 | sadMxN(16, 4) |
| 150 | sadMxNx4D(16, 4) |
| 151 | sadMxN(8, 32) |
| 152 | sadMxNx4D(8, 32) |
| 153 | sadMxN(32, 8) |
| 154 | sadMxNx4D(32, 8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 155 | sadMxN(16, 64) |
| 156 | sadMxNx4D(16, 64) |
| 157 | sadMxN(64, 16) |
| 158 | sadMxNx4D(64, 16) |
Tom Finegan | 9a7278f | 2018-05-25 10:20:55 -0700 | [diff] [blame] | 159 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 160 | /* clang-format on */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 162 | static INLINE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 163 | unsigned int highbd_sad(const uint8_t *a8, int a_stride, const uint8_t *b8, |
| 164 | int b_stride, int width, int height) { |
| 165 | int y, x; |
| 166 | unsigned int sad = 0; |
| 167 | const uint16_t *a = CONVERT_TO_SHORTPTR(a8); |
| 168 | const uint16_t *b = CONVERT_TO_SHORTPTR(b8); |
| 169 | for (y = 0; y < height; y++) { |
| 170 | for (x = 0; x < width; x++) sad += abs(a[x] - b[x]); |
| 171 | |
| 172 | a += a_stride; |
| 173 | b += b_stride; |
| 174 | } |
| 175 | return sad; |
| 176 | } |
| 177 | |
| 178 | static INLINE unsigned int highbd_sadb(const uint8_t *a8, int a_stride, |
| 179 | const uint16_t *b, int b_stride, |
| 180 | int width, int height) { |
| 181 | int y, x; |
| 182 | unsigned int sad = 0; |
| 183 | const uint16_t *a = CONVERT_TO_SHORTPTR(a8); |
| 184 | for (y = 0; y < height; y++) { |
| 185 | for (x = 0; x < width; x++) sad += abs(a[x] - b[x]); |
| 186 | |
| 187 | a += a_stride; |
| 188 | b += b_stride; |
| 189 | } |
| 190 | return sad; |
| 191 | } |
| 192 | |
Cheng Chen | bf3d496 | 2017-11-01 14:48:52 -0700 | [diff] [blame] | 193 | #define highbd_sadMxN(m, n) \ |
| 194 | unsigned int aom_highbd_sad##m##x##n##_c(const uint8_t *src, int src_stride, \ |
| 195 | const uint8_t *ref, \ |
| 196 | int ref_stride) { \ |
| 197 | return highbd_sad(src, src_stride, ref, ref_stride, m, n); \ |
| 198 | } \ |
| 199 | unsigned int aom_highbd_sad##m##x##n##_avg_c( \ |
| 200 | const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ |
| 201 | const uint8_t *second_pred) { \ |
| 202 | uint16_t comp_pred[m * n]; \ |
| 203 | aom_highbd_comp_avg_pred(comp_pred, second_pred, m, n, ref, ref_stride); \ |
| 204 | return highbd_sadb(src, src_stride, comp_pred, m, m, n); \ |
| 205 | } \ |
| 206 | unsigned int aom_highbd_jnt_sad##m##x##n##_avg_c( \ |
| 207 | const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ |
| 208 | const uint8_t *second_pred, const JNT_COMP_PARAMS *jcp_param) { \ |
| 209 | uint16_t comp_pred[m * n]; \ |
| 210 | aom_highbd_jnt_comp_avg_pred(comp_pred, second_pred, m, n, ref, \ |
| 211 | ref_stride, jcp_param); \ |
| 212 | return highbd_sadb(src, src_stride, comp_pred, m, m, n); \ |
| 213 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 214 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 215 | #define highbd_sadMxNx4D(m, n) \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 216 | void aom_highbd_sad##m##x##n##x4d_c(const uint8_t *src, int src_stride, \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 217 | const uint8_t *const ref_array[], \ |
| 218 | int ref_stride, uint32_t *sad_array) { \ |
| 219 | int i; \ |
| 220 | for (i = 0; i < 4; ++i) { \ |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 221 | sad_array[i] = aom_highbd_sad##m##x##n##_c(src, src_stride, \ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 222 | ref_array[i], ref_stride); \ |
| 223 | } \ |
| 224 | } |
| 225 | |
| 226 | /* clang-format off */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 227 | // 128x128 |
| 228 | highbd_sadMxN(128, 128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 229 | highbd_sadMxNx4D(128, 128) |
| 230 | |
| 231 | // 128x64 |
| 232 | highbd_sadMxN(128, 64) |
| 233 | highbd_sadMxNx4D(128, 64) |
| 234 | |
| 235 | // 64x128 |
| 236 | highbd_sadMxN(64, 128) |
| 237 | highbd_sadMxNx4D(64, 128) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 238 | |
| 239 | // 64x64 |
| 240 | highbd_sadMxN(64, 64) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 241 | highbd_sadMxNx4D(64, 64) |
| 242 | |
| 243 | // 64x32 |
| 244 | highbd_sadMxN(64, 32) |
| 245 | highbd_sadMxNx4D(64, 32) |
| 246 | |
| 247 | // 32x64 |
| 248 | highbd_sadMxN(32, 64) |
| 249 | highbd_sadMxNx4D(32, 64) |
| 250 | |
| 251 | // 32x32 |
| 252 | highbd_sadMxN(32, 32) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | highbd_sadMxNx4D(32, 32) |
| 254 | |
| 255 | // 32x16 |
| 256 | highbd_sadMxN(32, 16) |
| 257 | highbd_sadMxNx4D(32, 16) |
| 258 | |
| 259 | // 16x32 |
| 260 | highbd_sadMxN(16, 32) |
| 261 | highbd_sadMxNx4D(16, 32) |
| 262 | |
| 263 | // 16x16 |
| 264 | highbd_sadMxN(16, 16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 265 | highbd_sadMxNx4D(16, 16) |
| 266 | |
| 267 | // 16x8 |
| 268 | highbd_sadMxN(16, 8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 269 | highbd_sadMxNx4D(16, 8) |
| 270 | |
| 271 | // 8x16 |
| 272 | highbd_sadMxN(8, 16) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 273 | highbd_sadMxNx4D(8, 16) |
| 274 | |
| 275 | // 8x8 |
| 276 | highbd_sadMxN(8, 8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | highbd_sadMxNx4D(8, 8) |
| 278 | |
| 279 | // 8x4 |
| 280 | highbd_sadMxN(8, 4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | highbd_sadMxNx4D(8, 4) |
| 282 | |
| 283 | // 4x8 |
| 284 | highbd_sadMxN(4, 8) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | highbd_sadMxNx4D(4, 8) |
| 286 | |
| 287 | // 4x4 |
| 288 | highbd_sadMxN(4, 4) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | highbd_sadMxNx4D(4, 4) |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 290 | |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 291 | highbd_sadMxN(4, 16) |
| 292 | highbd_sadMxNx4D(4, 16) |
| 293 | highbd_sadMxN(16, 4) |
| 294 | highbd_sadMxNx4D(16, 4) |
| 295 | highbd_sadMxN(8, 32) |
| 296 | highbd_sadMxNx4D(8, 32) |
| 297 | highbd_sadMxN(32, 8) |
| 298 | highbd_sadMxNx4D(32, 8) |
Rupert Swarbrick | 7267857 | 2017-08-02 12:05:26 +0100 | [diff] [blame] | 299 | highbd_sadMxN(16, 64) |
| 300 | highbd_sadMxNx4D(16, 64) |
| 301 | highbd_sadMxN(64, 16) |
| 302 | highbd_sadMxNx4D(64, 16) |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 303 | /* clang-format on */ |