highbd_variance_sse2.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. /*
  2. * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include "./vpx_config.h"
  11. #include "./vpx_dsp_rtcd.h"
  12. #include "vpx_ports/mem.h"
  13. typedef uint32_t (*high_variance_fn_t)(const uint16_t *src, int src_stride,
  14. const uint16_t *ref, int ref_stride,
  15. uint32_t *sse, int *sum);
  16. uint32_t vpx_highbd_calc8x8var_sse2(const uint16_t *src, int src_stride,
  17. const uint16_t *ref, int ref_stride,
  18. uint32_t *sse, int *sum);
  19. uint32_t vpx_highbd_calc16x16var_sse2(const uint16_t *src, int src_stride,
  20. const uint16_t *ref, int ref_stride,
  21. uint32_t *sse, int *sum);
  22. static void highbd_8_variance_sse2(const uint16_t *src, int src_stride,
  23. const uint16_t *ref, int ref_stride, int w,
  24. int h, uint32_t *sse, int *sum,
  25. high_variance_fn_t var_fn, int block_size) {
  26. int i, j;
  27. *sse = 0;
  28. *sum = 0;
  29. for (i = 0; i < h; i += block_size) {
  30. for (j = 0; j < w; j += block_size) {
  31. unsigned int sse0;
  32. int sum0;
  33. var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j,
  34. ref_stride, &sse0, &sum0);
  35. *sse += sse0;
  36. *sum += sum0;
  37. }
  38. }
  39. }
  40. static void highbd_10_variance_sse2(const uint16_t *src, int src_stride,
  41. const uint16_t *ref, int ref_stride, int w,
  42. int h, uint32_t *sse, int *sum,
  43. high_variance_fn_t var_fn, int block_size) {
  44. int i, j;
  45. uint64_t sse_long = 0;
  46. int32_t sum_long = 0;
  47. for (i = 0; i < h; i += block_size) {
  48. for (j = 0; j < w; j += block_size) {
  49. unsigned int sse0;
  50. int sum0;
  51. var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j,
  52. ref_stride, &sse0, &sum0);
  53. sse_long += sse0;
  54. sum_long += sum0;
  55. }
  56. }
  57. *sum = ROUND_POWER_OF_TWO(sum_long, 2);
  58. *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 4);
  59. }
  60. static void highbd_12_variance_sse2(const uint16_t *src, int src_stride,
  61. const uint16_t *ref, int ref_stride, int w,
  62. int h, uint32_t *sse, int *sum,
  63. high_variance_fn_t var_fn, int block_size) {
  64. int i, j;
  65. uint64_t sse_long = 0;
  66. int32_t sum_long = 0;
  67. for (i = 0; i < h; i += block_size) {
  68. for (j = 0; j < w; j += block_size) {
  69. unsigned int sse0;
  70. int sum0;
  71. var_fn(src + src_stride * i + j, src_stride, ref + ref_stride * i + j,
  72. ref_stride, &sse0, &sum0);
  73. sse_long += sse0;
  74. sum_long += sum0;
  75. }
  76. }
  77. *sum = ROUND_POWER_OF_TWO(sum_long, 4);
  78. *sse = (uint32_t)ROUND_POWER_OF_TWO(sse_long, 8);
  79. }
  80. #define HIGH_GET_VAR(S) \
  81. void vpx_highbd_8_get##S##x##S##var_sse2( \
  82. const uint8_t *src8, int src_stride, const uint8_t *ref8, \
  83. int ref_stride, uint32_t *sse, int *sum) { \
  84. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  85. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  86. vpx_highbd_calc##S##x##S##var_sse2(src, src_stride, ref, ref_stride, sse, \
  87. sum); \
  88. } \
  89. \
  90. void vpx_highbd_10_get##S##x##S##var_sse2( \
  91. const uint8_t *src8, int src_stride, const uint8_t *ref8, \
  92. int ref_stride, uint32_t *sse, int *sum) { \
  93. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  94. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  95. vpx_highbd_calc##S##x##S##var_sse2(src, src_stride, ref, ref_stride, sse, \
  96. sum); \
  97. *sum = ROUND_POWER_OF_TWO(*sum, 2); \
  98. *sse = ROUND_POWER_OF_TWO(*sse, 4); \
  99. } \
  100. \
  101. void vpx_highbd_12_get##S##x##S##var_sse2( \
  102. const uint8_t *src8, int src_stride, const uint8_t *ref8, \
  103. int ref_stride, uint32_t *sse, int *sum) { \
  104. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  105. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  106. vpx_highbd_calc##S##x##S##var_sse2(src, src_stride, ref, ref_stride, sse, \
  107. sum); \
  108. *sum = ROUND_POWER_OF_TWO(*sum, 4); \
  109. *sse = ROUND_POWER_OF_TWO(*sse, 8); \
  110. }
  111. HIGH_GET_VAR(16);
  112. HIGH_GET_VAR(8);
  113. #undef HIGH_GET_VAR
  114. #define VAR_FN(w, h, block_size, shift) \
  115. uint32_t vpx_highbd_8_variance##w##x##h##_sse2( \
  116. const uint8_t *src8, int src_stride, const uint8_t *ref8, \
  117. int ref_stride, uint32_t *sse) { \
  118. int sum; \
  119. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  120. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  121. highbd_8_variance_sse2( \
  122. src, src_stride, ref, ref_stride, w, h, sse, &sum, \
  123. vpx_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
  124. return *sse - (uint32_t)(((int64_t)sum * sum) >> (shift)); \
  125. } \
  126. \
  127. uint32_t vpx_highbd_10_variance##w##x##h##_sse2( \
  128. const uint8_t *src8, int src_stride, const uint8_t *ref8, \
  129. int ref_stride, uint32_t *sse) { \
  130. int sum; \
  131. int64_t var; \
  132. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  133. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  134. highbd_10_variance_sse2( \
  135. src, src_stride, ref, ref_stride, w, h, sse, &sum, \
  136. vpx_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
  137. var = (int64_t)(*sse) - (((int64_t)sum * sum) >> (shift)); \
  138. return (var >= 0) ? (uint32_t)var : 0; \
  139. } \
  140. \
  141. uint32_t vpx_highbd_12_variance##w##x##h##_sse2( \
  142. const uint8_t *src8, int src_stride, const uint8_t *ref8, \
  143. int ref_stride, uint32_t *sse) { \
  144. int sum; \
  145. int64_t var; \
  146. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  147. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  148. highbd_12_variance_sse2( \
  149. src, src_stride, ref, ref_stride, w, h, sse, &sum, \
  150. vpx_highbd_calc##block_size##x##block_size##var_sse2, block_size); \
  151. var = (int64_t)(*sse) - (((int64_t)sum * sum) >> (shift)); \
  152. return (var >= 0) ? (uint32_t)var : 0; \
  153. }
  154. VAR_FN(64, 64, 16, 12);
  155. VAR_FN(64, 32, 16, 11);
  156. VAR_FN(32, 64, 16, 11);
  157. VAR_FN(32, 32, 16, 10);
  158. VAR_FN(32, 16, 16, 9);
  159. VAR_FN(16, 32, 16, 9);
  160. VAR_FN(16, 16, 16, 8);
  161. VAR_FN(16, 8, 8, 7);
  162. VAR_FN(8, 16, 8, 7);
  163. VAR_FN(8, 8, 8, 6);
  164. #undef VAR_FN
  165. unsigned int vpx_highbd_8_mse16x16_sse2(const uint8_t *src8, int src_stride,
  166. const uint8_t *ref8, int ref_stride,
  167. unsigned int *sse) {
  168. int sum;
  169. uint16_t *src = CONVERT_TO_SHORTPTR(src8);
  170. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
  171. highbd_8_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum,
  172. vpx_highbd_calc16x16var_sse2, 16);
  173. return *sse;
  174. }
  175. unsigned int vpx_highbd_10_mse16x16_sse2(const uint8_t *src8, int src_stride,
  176. const uint8_t *ref8, int ref_stride,
  177. unsigned int *sse) {
  178. int sum;
  179. uint16_t *src = CONVERT_TO_SHORTPTR(src8);
  180. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
  181. highbd_10_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum,
  182. vpx_highbd_calc16x16var_sse2, 16);
  183. return *sse;
  184. }
  185. unsigned int vpx_highbd_12_mse16x16_sse2(const uint8_t *src8, int src_stride,
  186. const uint8_t *ref8, int ref_stride,
  187. unsigned int *sse) {
  188. int sum;
  189. uint16_t *src = CONVERT_TO_SHORTPTR(src8);
  190. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
  191. highbd_12_variance_sse2(src, src_stride, ref, ref_stride, 16, 16, sse, &sum,
  192. vpx_highbd_calc16x16var_sse2, 16);
  193. return *sse;
  194. }
  195. unsigned int vpx_highbd_8_mse8x8_sse2(const uint8_t *src8, int src_stride,
  196. const uint8_t *ref8, int ref_stride,
  197. unsigned int *sse) {
  198. int sum;
  199. uint16_t *src = CONVERT_TO_SHORTPTR(src8);
  200. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
  201. highbd_8_variance_sse2(src, src_stride, ref, ref_stride, 8, 8, sse, &sum,
  202. vpx_highbd_calc8x8var_sse2, 8);
  203. return *sse;
  204. }
  205. unsigned int vpx_highbd_10_mse8x8_sse2(const uint8_t *src8, int src_stride,
  206. const uint8_t *ref8, int ref_stride,
  207. unsigned int *sse) {
  208. int sum;
  209. uint16_t *src = CONVERT_TO_SHORTPTR(src8);
  210. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
  211. highbd_10_variance_sse2(src, src_stride, ref, ref_stride, 8, 8, sse, &sum,
  212. vpx_highbd_calc8x8var_sse2, 8);
  213. return *sse;
  214. }
  215. unsigned int vpx_highbd_12_mse8x8_sse2(const uint8_t *src8, int src_stride,
  216. const uint8_t *ref8, int ref_stride,
  217. unsigned int *sse) {
  218. int sum;
  219. uint16_t *src = CONVERT_TO_SHORTPTR(src8);
  220. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
  221. highbd_12_variance_sse2(src, src_stride, ref, ref_stride, 8, 8, sse, &sum,
  222. vpx_highbd_calc8x8var_sse2, 8);
  223. return *sse;
  224. }
  225. // The 2 unused parameters are place holders for PIC enabled build.
  226. // These definitions are for functions defined in
  227. // highbd_subpel_variance_impl_sse2.asm
  228. #define DECL(w, opt) \
  229. int vpx_highbd_sub_pixel_variance##w##xh_##opt( \
  230. const uint16_t *src, ptrdiff_t src_stride, int x_offset, int y_offset, \
  231. const uint16_t *ref, ptrdiff_t ref_stride, int height, \
  232. unsigned int *sse, void *unused0, void *unused);
  233. #define DECLS(opt) \
  234. DECL(8, opt); \
  235. DECL(16, opt)
  236. DECLS(sse2);
  237. #undef DECLS
  238. #undef DECL
  239. #define FN(w, h, wf, wlog2, hlog2, opt, cast) \
  240. uint32_t vpx_highbd_8_sub_pixel_variance##w##x##h##_##opt( \
  241. const uint8_t *src8, int src_stride, int x_offset, int y_offset, \
  242. const uint8_t *ref8, int ref_stride, uint32_t *sse_ptr) { \
  243. uint32_t sse; \
  244. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  245. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  246. int se = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  247. src, src_stride, x_offset, y_offset, ref, ref_stride, h, &sse, NULL, \
  248. NULL); \
  249. if (w > wf) { \
  250. unsigned int sse2; \
  251. int se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  252. src + 16, src_stride, x_offset, y_offset, ref + 16, ref_stride, h, \
  253. &sse2, NULL, NULL); \
  254. se += se2; \
  255. sse += sse2; \
  256. if (w > wf * 2) { \
  257. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  258. src + 32, src_stride, x_offset, y_offset, ref + 32, ref_stride, h, \
  259. &sse2, NULL, NULL); \
  260. se += se2; \
  261. sse += sse2; \
  262. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  263. src + 48, src_stride, x_offset, y_offset, ref + 48, ref_stride, h, \
  264. &sse2, NULL, NULL); \
  265. se += se2; \
  266. sse += sse2; \
  267. } \
  268. } \
  269. *sse_ptr = sse; \
  270. return sse - (uint32_t)((cast se * se) >> (wlog2 + hlog2)); \
  271. } \
  272. \
  273. uint32_t vpx_highbd_10_sub_pixel_variance##w##x##h##_##opt( \
  274. const uint8_t *src8, int src_stride, int x_offset, int y_offset, \
  275. const uint8_t *ref8, int ref_stride, uint32_t *sse_ptr) { \
  276. int64_t var; \
  277. uint32_t sse; \
  278. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  279. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  280. int se = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  281. src, src_stride, x_offset, y_offset, ref, ref_stride, h, &sse, NULL, \
  282. NULL); \
  283. if (w > wf) { \
  284. uint32_t sse2; \
  285. int se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  286. src + 16, src_stride, x_offset, y_offset, ref + 16, ref_stride, h, \
  287. &sse2, NULL, NULL); \
  288. se += se2; \
  289. sse += sse2; \
  290. if (w > wf * 2) { \
  291. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  292. src + 32, src_stride, x_offset, y_offset, ref + 32, ref_stride, h, \
  293. &sse2, NULL, NULL); \
  294. se += se2; \
  295. sse += sse2; \
  296. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  297. src + 48, src_stride, x_offset, y_offset, ref + 48, ref_stride, h, \
  298. &sse2, NULL, NULL); \
  299. se += se2; \
  300. sse += sse2; \
  301. } \
  302. } \
  303. se = ROUND_POWER_OF_TWO(se, 2); \
  304. sse = ROUND_POWER_OF_TWO(sse, 4); \
  305. *sse_ptr = sse; \
  306. var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \
  307. return (var >= 0) ? (uint32_t)var : 0; \
  308. } \
  309. \
  310. uint32_t vpx_highbd_12_sub_pixel_variance##w##x##h##_##opt( \
  311. const uint8_t *src8, int src_stride, int x_offset, int y_offset, \
  312. const uint8_t *ref8, int ref_stride, uint32_t *sse_ptr) { \
  313. int start_row; \
  314. uint32_t sse; \
  315. int se = 0; \
  316. int64_t var; \
  317. uint64_t long_sse = 0; \
  318. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  319. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  320. for (start_row = 0; start_row < h; start_row += 16) { \
  321. uint32_t sse2; \
  322. int height = h - start_row < 16 ? h - start_row : 16; \
  323. int se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  324. src + (start_row * src_stride), src_stride, x_offset, y_offset, \
  325. ref + (start_row * ref_stride), ref_stride, height, &sse2, NULL, \
  326. NULL); \
  327. se += se2; \
  328. long_sse += sse2; \
  329. if (w > wf) { \
  330. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  331. src + 16 + (start_row * src_stride), src_stride, x_offset, \
  332. y_offset, ref + 16 + (start_row * ref_stride), ref_stride, height, \
  333. &sse2, NULL, NULL); \
  334. se += se2; \
  335. long_sse += sse2; \
  336. if (w > wf * 2) { \
  337. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  338. src + 32 + (start_row * src_stride), src_stride, x_offset, \
  339. y_offset, ref + 32 + (start_row * ref_stride), ref_stride, \
  340. height, &sse2, NULL, NULL); \
  341. se += se2; \
  342. long_sse += sse2; \
  343. se2 = vpx_highbd_sub_pixel_variance##wf##xh_##opt( \
  344. src + 48 + (start_row * src_stride), src_stride, x_offset, \
  345. y_offset, ref + 48 + (start_row * ref_stride), ref_stride, \
  346. height, &sse2, NULL, NULL); \
  347. se += se2; \
  348. long_sse += sse2; \
  349. } \
  350. } \
  351. } \
  352. se = ROUND_POWER_OF_TWO(se, 4); \
  353. sse = (uint32_t)ROUND_POWER_OF_TWO(long_sse, 8); \
  354. *sse_ptr = sse; \
  355. var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \
  356. return (var >= 0) ? (uint32_t)var : 0; \
  357. }
  358. #define FNS(opt) \
  359. FN(64, 64, 16, 6, 6, opt, (int64_t)); \
  360. FN(64, 32, 16, 6, 5, opt, (int64_t)); \
  361. FN(32, 64, 16, 5, 6, opt, (int64_t)); \
  362. FN(32, 32, 16, 5, 5, opt, (int64_t)); \
  363. FN(32, 16, 16, 5, 4, opt, (int64_t)); \
  364. FN(16, 32, 16, 4, 5, opt, (int64_t)); \
  365. FN(16, 16, 16, 4, 4, opt, (int64_t)); \
  366. FN(16, 8, 16, 4, 3, opt, (int64_t)); \
  367. FN(8, 16, 8, 3, 4, opt, (int64_t)); \
  368. FN(8, 8, 8, 3, 3, opt, (int64_t)); \
  369. FN(8, 4, 8, 3, 2, opt, (int64_t));
  370. FNS(sse2);
  371. #undef FNS
  372. #undef FN
  373. // The 2 unused parameters are place holders for PIC enabled build.
  374. #define DECL(w, opt) \
  375. int vpx_highbd_sub_pixel_avg_variance##w##xh_##opt( \
  376. const uint16_t *src, ptrdiff_t src_stride, int x_offset, int y_offset, \
  377. const uint16_t *ref, ptrdiff_t ref_stride, const uint16_t *second, \
  378. ptrdiff_t second_stride, int height, unsigned int *sse, void *unused0, \
  379. void *unused);
  380. #define DECLS(opt1) \
  381. DECL(16, opt1) \
  382. DECL(8, opt1)
  383. DECLS(sse2);
  384. #undef DECL
  385. #undef DECLS
  386. #define FN(w, h, wf, wlog2, hlog2, opt, cast) \
  387. uint32_t vpx_highbd_8_sub_pixel_avg_variance##w##x##h##_##opt( \
  388. const uint8_t *src8, int src_stride, int x_offset, int y_offset, \
  389. const uint8_t *ref8, int ref_stride, uint32_t *sse_ptr, \
  390. const uint8_t *sec8) { \
  391. uint32_t sse; \
  392. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  393. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  394. uint16_t *sec = CONVERT_TO_SHORTPTR(sec8); \
  395. int se = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  396. src, src_stride, x_offset, y_offset, ref, ref_stride, sec, w, h, &sse, \
  397. NULL, NULL); \
  398. if (w > wf) { \
  399. uint32_t sse2; \
  400. int se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  401. src + 16, src_stride, x_offset, y_offset, ref + 16, ref_stride, \
  402. sec + 16, w, h, &sse2, NULL, NULL); \
  403. se += se2; \
  404. sse += sse2; \
  405. if (w > wf * 2) { \
  406. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  407. src + 32, src_stride, x_offset, y_offset, ref + 32, ref_stride, \
  408. sec + 32, w, h, &sse2, NULL, NULL); \
  409. se += se2; \
  410. sse += sse2; \
  411. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  412. src + 48, src_stride, x_offset, y_offset, ref + 48, ref_stride, \
  413. sec + 48, w, h, &sse2, NULL, NULL); \
  414. se += se2; \
  415. sse += sse2; \
  416. } \
  417. } \
  418. *sse_ptr = sse; \
  419. return sse - (uint32_t)((cast se * se) >> (wlog2 + hlog2)); \
  420. } \
  421. \
  422. uint32_t vpx_highbd_10_sub_pixel_avg_variance##w##x##h##_##opt( \
  423. const uint8_t *src8, int src_stride, int x_offset, int y_offset, \
  424. const uint8_t *ref8, int ref_stride, uint32_t *sse_ptr, \
  425. const uint8_t *sec8) { \
  426. int64_t var; \
  427. uint32_t sse; \
  428. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  429. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  430. uint16_t *sec = CONVERT_TO_SHORTPTR(sec8); \
  431. int se = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  432. src, src_stride, x_offset, y_offset, ref, ref_stride, sec, w, h, &sse, \
  433. NULL, NULL); \
  434. if (w > wf) { \
  435. uint32_t sse2; \
  436. int se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  437. src + 16, src_stride, x_offset, y_offset, ref + 16, ref_stride, \
  438. sec + 16, w, h, &sse2, NULL, NULL); \
  439. se += se2; \
  440. sse += sse2; \
  441. if (w > wf * 2) { \
  442. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  443. src + 32, src_stride, x_offset, y_offset, ref + 32, ref_stride, \
  444. sec + 32, w, h, &sse2, NULL, NULL); \
  445. se += se2; \
  446. sse += sse2; \
  447. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  448. src + 48, src_stride, x_offset, y_offset, ref + 48, ref_stride, \
  449. sec + 48, w, h, &sse2, NULL, NULL); \
  450. se += se2; \
  451. sse += sse2; \
  452. } \
  453. } \
  454. se = ROUND_POWER_OF_TWO(se, 2); \
  455. sse = ROUND_POWER_OF_TWO(sse, 4); \
  456. *sse_ptr = sse; \
  457. var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \
  458. return (var >= 0) ? (uint32_t)var : 0; \
  459. } \
  460. \
  461. uint32_t vpx_highbd_12_sub_pixel_avg_variance##w##x##h##_##opt( \
  462. const uint8_t *src8, int src_stride, int x_offset, int y_offset, \
  463. const uint8_t *ref8, int ref_stride, uint32_t *sse_ptr, \
  464. const uint8_t *sec8) { \
  465. int start_row; \
  466. int64_t var; \
  467. uint32_t sse; \
  468. int se = 0; \
  469. uint64_t long_sse = 0; \
  470. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  471. uint16_t *ref = CONVERT_TO_SHORTPTR(ref8); \
  472. uint16_t *sec = CONVERT_TO_SHORTPTR(sec8); \
  473. for (start_row = 0; start_row < h; start_row += 16) { \
  474. uint32_t sse2; \
  475. int height = h - start_row < 16 ? h - start_row : 16; \
  476. int se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  477. src + (start_row * src_stride), src_stride, x_offset, y_offset, \
  478. ref + (start_row * ref_stride), ref_stride, sec + (start_row * w), \
  479. w, height, &sse2, NULL, NULL); \
  480. se += se2; \
  481. long_sse += sse2; \
  482. if (w > wf) { \
  483. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  484. src + 16 + (start_row * src_stride), src_stride, x_offset, \
  485. y_offset, ref + 16 + (start_row * ref_stride), ref_stride, \
  486. sec + 16 + (start_row * w), w, height, &sse2, NULL, NULL); \
  487. se += se2; \
  488. long_sse += sse2; \
  489. if (w > wf * 2) { \
  490. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  491. src + 32 + (start_row * src_stride), src_stride, x_offset, \
  492. y_offset, ref + 32 + (start_row * ref_stride), ref_stride, \
  493. sec + 32 + (start_row * w), w, height, &sse2, NULL, NULL); \
  494. se += se2; \
  495. long_sse += sse2; \
  496. se2 = vpx_highbd_sub_pixel_avg_variance##wf##xh_##opt( \
  497. src + 48 + (start_row * src_stride), src_stride, x_offset, \
  498. y_offset, ref + 48 + (start_row * ref_stride), ref_stride, \
  499. sec + 48 + (start_row * w), w, height, &sse2, NULL, NULL); \
  500. se += se2; \
  501. long_sse += sse2; \
  502. } \
  503. } \
  504. } \
  505. se = ROUND_POWER_OF_TWO(se, 4); \
  506. sse = (uint32_t)ROUND_POWER_OF_TWO(long_sse, 8); \
  507. *sse_ptr = sse; \
  508. var = (int64_t)(sse) - ((cast se * se) >> (wlog2 + hlog2)); \
  509. return (var >= 0) ? (uint32_t)var : 0; \
  510. }
  511. #define FNS(opt1) \
  512. FN(64, 64, 16, 6, 6, opt1, (int64_t)); \
  513. FN(64, 32, 16, 6, 5, opt1, (int64_t)); \
  514. FN(32, 64, 16, 5, 6, opt1, (int64_t)); \
  515. FN(32, 32, 16, 5, 5, opt1, (int64_t)); \
  516. FN(32, 16, 16, 5, 4, opt1, (int64_t)); \
  517. FN(16, 32, 16, 4, 5, opt1, (int64_t)); \
  518. FN(16, 16, 16, 4, 4, opt1, (int64_t)); \
  519. FN(16, 8, 16, 4, 3, opt1, (int64_t)); \
  520. FN(8, 16, 8, 4, 3, opt1, (int64_t)); \
  521. FN(8, 8, 8, 3, 3, opt1, (int64_t)); \
  522. FN(8, 4, 8, 3, 2, opt1, (int64_t));
  523. FNS(sse2);
  524. #undef FNS
  525. #undef FN