convolve.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * Copyright (c) 2015 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. #ifndef VPX_DSP_X86_CONVOLVE_H_
  11. #define VPX_DSP_X86_CONVOLVE_H_
  12. #include <assert.h>
  13. #include "./vpx_config.h"
  14. #include "vpx/vpx_integer.h"
  15. #include "vpx_ports/mem.h"
  16. typedef void filter8_1dfunction (
  17. const uint8_t *src_ptr,
  18. ptrdiff_t src_pitch,
  19. uint8_t *output_ptr,
  20. ptrdiff_t out_pitch,
  21. uint32_t output_height,
  22. const int16_t *filter
  23. );
  24. #define FUN_CONV_1D(name, step_q4, filter, dir, src_start, avg, opt) \
  25. void vpx_convolve8_##name##_##opt(const uint8_t *src, ptrdiff_t src_stride, \
  26. uint8_t *dst, ptrdiff_t dst_stride, \
  27. const int16_t *filter_x, int x_step_q4, \
  28. const int16_t *filter_y, int y_step_q4, \
  29. int w, int h) { \
  30. assert(filter[3] != 128); \
  31. assert(step_q4 == 16); \
  32. if (filter[0] | filter[1] | filter[2]) { \
  33. while (w >= 16) { \
  34. vpx_filter_block1d16_##dir##8_##avg##opt(src_start, \
  35. src_stride, \
  36. dst, \
  37. dst_stride, \
  38. h, \
  39. filter); \
  40. src += 16; \
  41. dst += 16; \
  42. w -= 16; \
  43. } \
  44. if (w == 8) { \
  45. vpx_filter_block1d8_##dir##8_##avg##opt(src_start, \
  46. src_stride, \
  47. dst, \
  48. dst_stride, \
  49. h, \
  50. filter); \
  51. } else if (w == 4) { \
  52. vpx_filter_block1d4_##dir##8_##avg##opt(src_start, \
  53. src_stride, \
  54. dst, \
  55. dst_stride, \
  56. h, \
  57. filter); \
  58. } \
  59. } else { \
  60. while (w >= 16) { \
  61. vpx_filter_block1d16_##dir##2_##avg##opt(src, \
  62. src_stride, \
  63. dst, \
  64. dst_stride, \
  65. h, \
  66. filter); \
  67. src += 16; \
  68. dst += 16; \
  69. w -= 16; \
  70. } \
  71. if (w == 8) { \
  72. vpx_filter_block1d8_##dir##2_##avg##opt(src, \
  73. src_stride, \
  74. dst, \
  75. dst_stride, \
  76. h, \
  77. filter); \
  78. } else if (w == 4) { \
  79. vpx_filter_block1d4_##dir##2_##avg##opt(src, \
  80. src_stride, \
  81. dst, \
  82. dst_stride, \
  83. h, \
  84. filter); \
  85. } \
  86. } \
  87. }
  88. #define FUN_CONV_2D(avg, opt) \
  89. void vpx_convolve8_##avg##opt(const uint8_t *src, ptrdiff_t src_stride, \
  90. uint8_t *dst, ptrdiff_t dst_stride, \
  91. const int16_t *filter_x, int x_step_q4, \
  92. const int16_t *filter_y, int y_step_q4, \
  93. int w, int h) { \
  94. assert(filter_x[3] != 128); \
  95. assert(filter_y[3] != 128); \
  96. assert(w <= 64); \
  97. assert(h <= 64); \
  98. assert(x_step_q4 == 16); \
  99. assert(y_step_q4 == 16); \
  100. if (filter_x[0] | filter_x[1] | filter_x[2]) { \
  101. DECLARE_ALIGNED(16, uint8_t, fdata2[64 * 71]); \
  102. vpx_convolve8_horiz_##opt(src - 3 * src_stride, src_stride, fdata2, 64, \
  103. filter_x, x_step_q4, filter_y, y_step_q4, \
  104. w, h + 7); \
  105. vpx_convolve8_##avg##vert_##opt(fdata2 + 3 * 64, 64, dst, dst_stride, \
  106. filter_x, x_step_q4, filter_y, \
  107. y_step_q4, w, h); \
  108. } else { \
  109. DECLARE_ALIGNED(16, uint8_t, fdata2[64 * 65]); \
  110. vpx_convolve8_horiz_##opt(src, src_stride, fdata2, 64, \
  111. filter_x, x_step_q4, filter_y, y_step_q4, \
  112. w, h + 1); \
  113. vpx_convolve8_##avg##vert_##opt(fdata2, 64, dst, dst_stride, \
  114. filter_x, x_step_q4, filter_y, \
  115. y_step_q4, w, h); \
  116. } \
  117. }
  118. #if CONFIG_VP9_HIGHBITDEPTH
  119. typedef void highbd_filter8_1dfunction (
  120. const uint16_t *src_ptr,
  121. const ptrdiff_t src_pitch,
  122. uint16_t *output_ptr,
  123. ptrdiff_t out_pitch,
  124. unsigned int output_height,
  125. const int16_t *filter,
  126. int bd
  127. );
  128. #define HIGH_FUN_CONV_1D(name, step_q4, filter, dir, src_start, avg, opt) \
  129. void vpx_highbd_convolve8_##name##_##opt(const uint8_t *src8, \
  130. ptrdiff_t src_stride, \
  131. uint8_t *dst8, \
  132. ptrdiff_t dst_stride, \
  133. const int16_t *filter_x, \
  134. int x_step_q4, \
  135. const int16_t *filter_y, \
  136. int y_step_q4, \
  137. int w, int h, int bd) { \
  138. if (step_q4 == 16 && filter[3] != 128) { \
  139. uint16_t *src = CONVERT_TO_SHORTPTR(src8); \
  140. uint16_t *dst = CONVERT_TO_SHORTPTR(dst8); \
  141. if (filter[0] | filter[1] | filter[2]) { \
  142. while (w >= 16) { \
  143. vpx_highbd_filter_block1d16_##dir##8_##avg##opt(src_start, \
  144. src_stride, \
  145. dst, \
  146. dst_stride, \
  147. h, \
  148. filter, \
  149. bd); \
  150. src += 16; \
  151. dst += 16; \
  152. w -= 16; \
  153. } \
  154. while (w >= 8) { \
  155. vpx_highbd_filter_block1d8_##dir##8_##avg##opt(src_start, \
  156. src_stride, \
  157. dst, \
  158. dst_stride, \
  159. h, \
  160. filter, \
  161. bd); \
  162. src += 8; \
  163. dst += 8; \
  164. w -= 8; \
  165. } \
  166. while (w >= 4) { \
  167. vpx_highbd_filter_block1d4_##dir##8_##avg##opt(src_start, \
  168. src_stride, \
  169. dst, \
  170. dst_stride, \
  171. h, \
  172. filter, \
  173. bd); \
  174. src += 4; \
  175. dst += 4; \
  176. w -= 4; \
  177. } \
  178. } else { \
  179. while (w >= 16) { \
  180. vpx_highbd_filter_block1d16_##dir##2_##avg##opt(src, \
  181. src_stride, \
  182. dst, \
  183. dst_stride, \
  184. h, \
  185. filter, \
  186. bd); \
  187. src += 16; \
  188. dst += 16; \
  189. w -= 16; \
  190. } \
  191. while (w >= 8) { \
  192. vpx_highbd_filter_block1d8_##dir##2_##avg##opt(src, \
  193. src_stride, \
  194. dst, \
  195. dst_stride, \
  196. h, \
  197. filter, \
  198. bd); \
  199. src += 8; \
  200. dst += 8; \
  201. w -= 8; \
  202. } \
  203. while (w >= 4) { \
  204. vpx_highbd_filter_block1d4_##dir##2_##avg##opt(src, \
  205. src_stride, \
  206. dst, \
  207. dst_stride, \
  208. h, \
  209. filter, \
  210. bd); \
  211. src += 4; \
  212. dst += 4; \
  213. w -= 4; \
  214. } \
  215. } \
  216. } \
  217. if (w) { \
  218. vpx_highbd_convolve8_##name##_c(src8, src_stride, dst8, dst_stride, \
  219. filter_x, x_step_q4, filter_y, y_step_q4, \
  220. w, h, bd); \
  221. } \
  222. }
  223. #define HIGH_FUN_CONV_2D(avg, opt) \
  224. void vpx_highbd_convolve8_##avg##opt(const uint8_t *src, ptrdiff_t src_stride, \
  225. uint8_t *dst, ptrdiff_t dst_stride, \
  226. const int16_t *filter_x, int x_step_q4, \
  227. const int16_t *filter_y, int y_step_q4, \
  228. int w, int h, int bd) { \
  229. assert(w <= 64); \
  230. assert(h <= 64); \
  231. if (x_step_q4 == 16 && y_step_q4 == 16) { \
  232. if ((filter_x[0] | filter_x[1] | filter_x[2]) || filter_x[3] == 128) { \
  233. DECLARE_ALIGNED(16, uint16_t, fdata2[64 * 71]); \
  234. vpx_highbd_convolve8_horiz_##opt(src - 3 * src_stride, src_stride, \
  235. CONVERT_TO_BYTEPTR(fdata2), 64, \
  236. filter_x, x_step_q4, \
  237. filter_y, y_step_q4, \
  238. w, h + 7, bd); \
  239. vpx_highbd_convolve8_##avg##vert_##opt(CONVERT_TO_BYTEPTR(fdata2) + 192, \
  240. 64, dst, dst_stride, \
  241. filter_x, x_step_q4, \
  242. filter_y, y_step_q4, \
  243. w, h, bd); \
  244. } else { \
  245. DECLARE_ALIGNED(16, uint16_t, fdata2[64 * 65]); \
  246. vpx_highbd_convolve8_horiz_##opt(src, src_stride, \
  247. CONVERT_TO_BYTEPTR(fdata2), 64, \
  248. filter_x, x_step_q4, \
  249. filter_y, y_step_q4, \
  250. w, h + 1, bd); \
  251. vpx_highbd_convolve8_##avg##vert_##opt(CONVERT_TO_BYTEPTR(fdata2), 64, \
  252. dst, dst_stride, \
  253. filter_x, x_step_q4, \
  254. filter_y, y_step_q4, \
  255. w, h, bd); \
  256. } \
  257. } else { \
  258. vpx_highbd_convolve8_##avg##c(src, src_stride, dst, dst_stride, \
  259. filter_x, x_step_q4, filter_y, y_step_q4, w, \
  260. h, bd); \
  261. } \
  262. }
  263. #endif // CONFIG_VP9_HIGHBITDEPTH
  264. #endif // VPX_DSP_X86_CONVOLVE_H_