2
0

hpeldsp.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * Half-pel DSP functions.
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. /**
  25. * @file
  26. * Half-pel DSP functions.
  27. */
  28. #include "libavutil/attributes.h"
  29. #include "libavutil/intreadwrite.h"
  30. #include "hpeldsp.h"
  31. #define BIT_DEPTH 8
  32. #include "hpel_template.c"
  33. #include "pel_template.c"
  34. #define PIXOP2(OPNAME, OP) \
  35. static inline void OPNAME ## _no_rnd_pixels8_l2_8(uint8_t *dst, \
  36. const uint8_t *src1, \
  37. const uint8_t *src2, \
  38. int dst_stride, \
  39. int src_stride1, \
  40. int src_stride2, \
  41. int h) \
  42. { \
  43. int i; \
  44. \
  45. for (i = 0; i < h; i++) { \
  46. uint32_t a, b; \
  47. a = AV_RN32(&src1[i * src_stride1]); \
  48. b = AV_RN32(&src2[i * src_stride2]); \
  49. OP(*((uint32_t *) &dst[i * dst_stride]), \
  50. no_rnd_avg32(a, b)); \
  51. a = AV_RN32(&src1[i * src_stride1 + 4]); \
  52. b = AV_RN32(&src2[i * src_stride2 + 4]); \
  53. OP(*((uint32_t *) &dst[i * dst_stride + 4]), \
  54. no_rnd_avg32(a, b)); \
  55. } \
  56. } \
  57. \
  58. static inline void OPNAME ## _no_rnd_pixels8_x2_8_c(uint8_t *block, \
  59. const uint8_t *pixels, \
  60. ptrdiff_t line_size, \
  61. int h) \
  62. { \
  63. OPNAME ## _no_rnd_pixels8_l2_8(block, pixels, pixels + 1, \
  64. line_size, line_size, line_size, h); \
  65. } \
  66. \
  67. static inline void OPNAME ## _pixels8_x2_8_c(uint8_t *block, \
  68. const uint8_t *pixels, \
  69. ptrdiff_t line_size, \
  70. int h) \
  71. { \
  72. OPNAME ## _pixels8_l2_8(block, pixels, pixels + 1, \
  73. line_size, line_size, line_size, h); \
  74. } \
  75. \
  76. static inline void OPNAME ## _no_rnd_pixels8_y2_8_c(uint8_t *block, \
  77. const uint8_t *pixels, \
  78. ptrdiff_t line_size, \
  79. int h) \
  80. { \
  81. OPNAME ## _no_rnd_pixels8_l2_8(block, pixels, pixels + line_size, \
  82. line_size, line_size, line_size, h); \
  83. } \
  84. \
  85. static inline void OPNAME ## _pixels8_y2_8_c(uint8_t *block, \
  86. const uint8_t *pixels, \
  87. ptrdiff_t line_size, \
  88. int h) \
  89. { \
  90. OPNAME ## _pixels8_l2_8(block, pixels, pixels + line_size, \
  91. line_size, line_size, line_size, h); \
  92. } \
  93. \
  94. static inline void OPNAME ## _pixels4_x2_8_c(uint8_t *block, \
  95. const uint8_t *pixels, \
  96. ptrdiff_t line_size, \
  97. int h) \
  98. { \
  99. OPNAME ## _pixels4_l2_8(block, pixels, pixels + 1, \
  100. line_size, line_size, line_size, h); \
  101. } \
  102. \
  103. static inline void OPNAME ## _pixels4_y2_8_c(uint8_t *block, \
  104. const uint8_t *pixels, \
  105. ptrdiff_t line_size, \
  106. int h) \
  107. { \
  108. OPNAME ## _pixels4_l2_8(block, pixels, pixels + line_size, \
  109. line_size, line_size, line_size, h); \
  110. } \
  111. \
  112. static inline void OPNAME ## _pixels2_x2_8_c(uint8_t *block, \
  113. const uint8_t *pixels, \
  114. ptrdiff_t line_size, \
  115. int h) \
  116. { \
  117. OPNAME ## _pixels2_l2_8(block, pixels, pixels + 1, \
  118. line_size, line_size, line_size, h); \
  119. } \
  120. \
  121. static inline void OPNAME ## _pixels2_y2_8_c(uint8_t *block, \
  122. const uint8_t *pixels, \
  123. ptrdiff_t line_size, \
  124. int h) \
  125. { \
  126. OPNAME ## _pixels2_l2_8(block, pixels, pixels + line_size, \
  127. line_size, line_size, line_size, h); \
  128. } \
  129. \
  130. static inline void OPNAME ## _pixels2_xy2_8_c(uint8_t *block, \
  131. const uint8_t *pixels, \
  132. ptrdiff_t line_size, \
  133. int h) \
  134. { \
  135. int i, a1, b1; \
  136. int a0 = pixels[0]; \
  137. int b0 = pixels[1] + 2; \
  138. \
  139. a0 += b0; \
  140. b0 += pixels[2]; \
  141. pixels += line_size; \
  142. for (i = 0; i < h; i += 2) { \
  143. a1 = pixels[0]; \
  144. b1 = pixels[1]; \
  145. a1 += b1; \
  146. b1 += pixels[2]; \
  147. \
  148. block[0] = (a1 + a0) >> 2; /* FIXME non put */ \
  149. block[1] = (b1 + b0) >> 2; \
  150. \
  151. pixels += line_size; \
  152. block += line_size; \
  153. \
  154. a0 = pixels[0]; \
  155. b0 = pixels[1] + 2; \
  156. a0 += b0; \
  157. b0 += pixels[2]; \
  158. \
  159. block[0] = (a1 + a0) >> 2; \
  160. block[1] = (b1 + b0) >> 2; \
  161. pixels += line_size; \
  162. block += line_size; \
  163. } \
  164. } \
  165. \
  166. static inline void OPNAME ## _pixels4_xy2_8_c(uint8_t *block, \
  167. const uint8_t *pixels, \
  168. ptrdiff_t line_size, \
  169. int h) \
  170. { \
  171. /* FIXME HIGH BIT DEPTH */ \
  172. int i; \
  173. const uint32_t a = AV_RN32(pixels); \
  174. const uint32_t b = AV_RN32(pixels + 1); \
  175. uint32_t l0 = (a & 0x03030303UL) + \
  176. (b & 0x03030303UL) + \
  177. 0x02020202UL; \
  178. uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
  179. ((b & 0xFCFCFCFCUL) >> 2); \
  180. uint32_t l1, h1; \
  181. \
  182. pixels += line_size; \
  183. for (i = 0; i < h; i += 2) { \
  184. uint32_t a = AV_RN32(pixels); \
  185. uint32_t b = AV_RN32(pixels + 1); \
  186. l1 = (a & 0x03030303UL) + \
  187. (b & 0x03030303UL); \
  188. h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
  189. ((b & 0xFCFCFCFCUL) >> 2); \
  190. OP(*((uint32_t *) block), h0 + h1 + \
  191. (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
  192. pixels += line_size; \
  193. block += line_size; \
  194. a = AV_RN32(pixels); \
  195. b = AV_RN32(pixels + 1); \
  196. l0 = (a & 0x03030303UL) + \
  197. (b & 0x03030303UL) + \
  198. 0x02020202UL; \
  199. h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
  200. ((b & 0xFCFCFCFCUL) >> 2); \
  201. OP(*((uint32_t *) block), h0 + h1 + \
  202. (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
  203. pixels += line_size; \
  204. block += line_size; \
  205. } \
  206. } \
  207. \
  208. static inline void OPNAME ## _pixels8_xy2_8_c(uint8_t *block, \
  209. const uint8_t *pixels, \
  210. ptrdiff_t line_size, \
  211. int h) \
  212. { \
  213. /* FIXME HIGH BIT DEPTH */ \
  214. int j; \
  215. \
  216. for (j = 0; j < 2; j++) { \
  217. int i; \
  218. const uint32_t a = AV_RN32(pixels); \
  219. const uint32_t b = AV_RN32(pixels + 1); \
  220. uint32_t l0 = (a & 0x03030303UL) + \
  221. (b & 0x03030303UL) + \
  222. 0x02020202UL; \
  223. uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
  224. ((b & 0xFCFCFCFCUL) >> 2); \
  225. uint32_t l1, h1; \
  226. \
  227. pixels += line_size; \
  228. for (i = 0; i < h; i += 2) { \
  229. uint32_t a = AV_RN32(pixels); \
  230. uint32_t b = AV_RN32(pixels + 1); \
  231. l1 = (a & 0x03030303UL) + \
  232. (b & 0x03030303UL); \
  233. h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
  234. ((b & 0xFCFCFCFCUL) >> 2); \
  235. OP(*((uint32_t *) block), h0 + h1 + \
  236. (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
  237. pixels += line_size; \
  238. block += line_size; \
  239. a = AV_RN32(pixels); \
  240. b = AV_RN32(pixels + 1); \
  241. l0 = (a & 0x03030303UL) + \
  242. (b & 0x03030303UL) + \
  243. 0x02020202UL; \
  244. h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
  245. ((b & 0xFCFCFCFCUL) >> 2); \
  246. OP(*((uint32_t *) block), h0 + h1 + \
  247. (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
  248. pixels += line_size; \
  249. block += line_size; \
  250. } \
  251. pixels += 4 - line_size * (h + 1); \
  252. block += 4 - line_size * h; \
  253. } \
  254. } \
  255. \
  256. static inline void OPNAME ## _no_rnd_pixels8_xy2_8_c(uint8_t *block, \
  257. const uint8_t *pixels, \
  258. ptrdiff_t line_size, \
  259. int h) \
  260. { \
  261. /* FIXME HIGH BIT DEPTH */ \
  262. int j; \
  263. \
  264. for (j = 0; j < 2; j++) { \
  265. int i; \
  266. const uint32_t a = AV_RN32(pixels); \
  267. const uint32_t b = AV_RN32(pixels + 1); \
  268. uint32_t l0 = (a & 0x03030303UL) + \
  269. (b & 0x03030303UL) + \
  270. 0x01010101UL; \
  271. uint32_t h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
  272. ((b & 0xFCFCFCFCUL) >> 2); \
  273. uint32_t l1, h1; \
  274. \
  275. pixels += line_size; \
  276. for (i = 0; i < h; i += 2) { \
  277. uint32_t a = AV_RN32(pixels); \
  278. uint32_t b = AV_RN32(pixels + 1); \
  279. l1 = (a & 0x03030303UL) + \
  280. (b & 0x03030303UL); \
  281. h1 = ((a & 0xFCFCFCFCUL) >> 2) + \
  282. ((b & 0xFCFCFCFCUL) >> 2); \
  283. OP(*((uint32_t *) block), h0 + h1 + \
  284. (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
  285. pixels += line_size; \
  286. block += line_size; \
  287. a = AV_RN32(pixels); \
  288. b = AV_RN32(pixels + 1); \
  289. l0 = (a & 0x03030303UL) + \
  290. (b & 0x03030303UL) + \
  291. 0x01010101UL; \
  292. h0 = ((a & 0xFCFCFCFCUL) >> 2) + \
  293. ((b & 0xFCFCFCFCUL) >> 2); \
  294. OP(*((uint32_t *) block), h0 + h1 + \
  295. (((l0 + l1) >> 2) & 0x0F0F0F0FUL)); \
  296. pixels += line_size; \
  297. block += line_size; \
  298. } \
  299. pixels += 4 - line_size * (h + 1); \
  300. block += 4 - line_size * h; \
  301. } \
  302. } \
  303. \
  304. CALL_2X_PIXELS(OPNAME ## _pixels16_x2_8_c, \
  305. OPNAME ## _pixels8_x2_8_c, \
  306. 8) \
  307. CALL_2X_PIXELS(OPNAME ## _pixels16_y2_8_c, \
  308. OPNAME ## _pixels8_y2_8_c, \
  309. 8) \
  310. CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_8_c, \
  311. OPNAME ## _pixels8_xy2_8_c, \
  312. 8) \
  313. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_8_c, \
  314. OPNAME ## _pixels8_8_c, \
  315. 8) \
  316. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_8_c, \
  317. OPNAME ## _no_rnd_pixels8_x2_8_c, \
  318. 8) \
  319. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_8_c, \
  320. OPNAME ## _no_rnd_pixels8_y2_8_c, \
  321. 8) \
  322. CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_8_c, \
  323. OPNAME ## _no_rnd_pixels8_xy2_8_c, \
  324. 8) \
  325. #define op_avg(a, b) a = rnd_avg32(a, b)
  326. #define op_put(a, b) a = b
  327. #define put_no_rnd_pixels8_8_c put_pixels8_8_c
  328. PIXOP2(avg, op_avg)
  329. PIXOP2(put, op_put)
  330. #undef op_avg
  331. #undef op_put
  332. av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
  333. {
  334. #define hpel_funcs(prefix, idx, num) \
  335. c->prefix ## _pixels_tab idx [0] = prefix ## _pixels ## num ## _8_c; \
  336. c->prefix ## _pixels_tab idx [1] = prefix ## _pixels ## num ## _x2_8_c; \
  337. c->prefix ## _pixels_tab idx [2] = prefix ## _pixels ## num ## _y2_8_c; \
  338. c->prefix ## _pixels_tab idx [3] = prefix ## _pixels ## num ## _xy2_8_c
  339. hpel_funcs(put, [0], 16);
  340. hpel_funcs(put, [1], 8);
  341. hpel_funcs(put, [2], 4);
  342. hpel_funcs(put, [3], 2);
  343. hpel_funcs(put_no_rnd, [0], 16);
  344. hpel_funcs(put_no_rnd, [1], 8);
  345. hpel_funcs(avg, [0], 16);
  346. hpel_funcs(avg, [1], 8);
  347. hpel_funcs(avg, [2], 4);
  348. hpel_funcs(avg, [3], 2);
  349. hpel_funcs(avg_no_rnd,, 16);
  350. if (ARCH_AARCH64)
  351. ff_hpeldsp_init_aarch64(c, flags);
  352. if (ARCH_ALPHA)
  353. ff_hpeldsp_init_alpha(c, flags);
  354. if (ARCH_ARM)
  355. ff_hpeldsp_init_arm(c, flags);
  356. if (ARCH_PPC)
  357. ff_hpeldsp_init_ppc(c, flags);
  358. if (ARCH_X86)
  359. ff_hpeldsp_init_x86(c, flags);
  360. if (ARCH_MIPS)
  361. ff_hpeldsp_init_mips(c, flags);
  362. }