You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

367 lines
14KB

  1. /*
  2. * Alpha optimized DSP utils
  3. * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include "asm.h"
  20. #include "../dsputil.h"
  21. extern void simple_idct_put_axp(uint8_t *dest, int line_size, DCTELEM *block);
  22. extern void simple_idct_add_axp(uint8_t *dest, int line_size, DCTELEM *block);
  23. void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels,
  24. int line_size, int h);
  25. void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
  26. int line_size);
  27. void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels,
  28. int line_size);
  29. void (*put_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
  30. int line_size);
  31. void (*add_pixels_clamped_axp_p)(const DCTELEM *block, uint8_t *pixels,
  32. int line_size);
  33. void get_pixels_mvi(DCTELEM *restrict block,
  34. const uint8_t *restrict pixels, int line_size);
  35. void diff_pixels_mvi(DCTELEM *block, const uint8_t *s1, const uint8_t *s2,
  36. int stride);
  37. int pix_abs8x8_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
  38. int pix_abs16x16_mvi_asm(uint8_t *pix1, uint8_t *pix2, int line_size);
  39. int pix_abs16x16_x2_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
  40. int pix_abs16x16_y2_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
  41. int pix_abs16x16_xy2_mvi(uint8_t *pix1, uint8_t *pix2, int line_size);
  42. #if 0
  43. /* These functions were the base for the optimized assembler routines,
  44. and remain here for documentation purposes. */
  45. static void put_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels,
  46. int line_size)
  47. {
  48. int i = 8;
  49. uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
  50. ASM_ACCEPT_MVI;
  51. do {
  52. uint64_t shorts0, shorts1;
  53. shorts0 = ldq(block);
  54. shorts0 = maxsw4(shorts0, 0);
  55. shorts0 = minsw4(shorts0, clampmask);
  56. stl(pkwb(shorts0), pixels);
  57. shorts1 = ldq(block + 4);
  58. shorts1 = maxsw4(shorts1, 0);
  59. shorts1 = minsw4(shorts1, clampmask);
  60. stl(pkwb(shorts1), pixels + 4);
  61. pixels += line_size;
  62. block += 8;
  63. } while (--i);
  64. }
  65. void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels,
  66. int line_size)
  67. {
  68. int h = 8;
  69. /* Keep this function a leaf function by generating the constants
  70. manually (mainly for the hack value ;-). */
  71. uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
  72. uint64_t signmask = zap(-1, 0x33);
  73. signmask ^= signmask >> 1; /* 0x8000800080008000 */
  74. ASM_ACCEPT_MVI;
  75. do {
  76. uint64_t shorts0, pix0, signs0;
  77. uint64_t shorts1, pix1, signs1;
  78. shorts0 = ldq(block);
  79. shorts1 = ldq(block + 4);
  80. pix0 = unpkbw(ldl(pixels));
  81. /* Signed subword add (MMX paddw). */
  82. signs0 = shorts0 & signmask;
  83. shorts0 &= ~signmask;
  84. shorts0 += pix0;
  85. shorts0 ^= signs0;
  86. /* Clamp. */
  87. shorts0 = maxsw4(shorts0, 0);
  88. shorts0 = minsw4(shorts0, clampmask);
  89. /* Next 4. */
  90. pix1 = unpkbw(ldl(pixels + 4));
  91. signs1 = shorts1 & signmask;
  92. shorts1 &= ~signmask;
  93. shorts1 += pix1;
  94. shorts1 ^= signs1;
  95. shorts1 = maxsw4(shorts1, 0);
  96. shorts1 = minsw4(shorts1, clampmask);
  97. stl(pkwb(shorts0), pixels);
  98. stl(pkwb(shorts1), pixels + 4);
  99. pixels += line_size;
  100. block += 8;
  101. } while (--h);
  102. }
  103. #endif
  104. static void clear_blocks_axp(DCTELEM *blocks) {
  105. uint64_t *p = (uint64_t *) blocks;
  106. int n = sizeof(DCTELEM) * 6 * 64;
  107. do {
  108. p[0] = 0;
  109. p[1] = 0;
  110. p[2] = 0;
  111. p[3] = 0;
  112. p[4] = 0;
  113. p[5] = 0;
  114. p[6] = 0;
  115. p[7] = 0;
  116. p += 8;
  117. n -= 8 * 8;
  118. } while (n);
  119. }
  120. static inline uint64_t avg2_no_rnd(uint64_t a, uint64_t b)
  121. {
  122. return (a & b) + (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
  123. }
  124. static inline uint64_t avg2(uint64_t a, uint64_t b)
  125. {
  126. return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1);
  127. }
  128. #if 0
  129. /* The XY2 routines basically utilize this scheme, but reuse parts in
  130. each iteration. */
  131. static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4)
  132. {
  133. uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2)
  134. + ((l2 & ~BYTE_VEC(0x03)) >> 2)
  135. + ((l3 & ~BYTE_VEC(0x03)) >> 2)
  136. + ((l4 & ~BYTE_VEC(0x03)) >> 2);
  137. uint64_t r2 = (( (l1 & BYTE_VEC(0x03))
  138. + (l2 & BYTE_VEC(0x03))
  139. + (l3 & BYTE_VEC(0x03))
  140. + (l4 & BYTE_VEC(0x03))
  141. + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03);
  142. return r1 + r2;
  143. }
  144. #endif
  145. #define OP(LOAD, STORE) \
  146. do { \
  147. STORE(LOAD(pixels), block); \
  148. pixels += line_size; \
  149. block += line_size; \
  150. } while (--h)
  151. #define OP_X2(LOAD, STORE) \
  152. do { \
  153. uint64_t pix1, pix2; \
  154. \
  155. pix1 = LOAD(pixels); \
  156. pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
  157. STORE(AVG2(pix1, pix2), block); \
  158. pixels += line_size; \
  159. block += line_size; \
  160. } while (--h)
  161. #define OP_Y2(LOAD, STORE) \
  162. do { \
  163. uint64_t pix = LOAD(pixels); \
  164. do { \
  165. uint64_t next_pix; \
  166. \
  167. pixels += line_size; \
  168. next_pix = LOAD(pixels); \
  169. STORE(AVG2(pix, next_pix), block); \
  170. block += line_size; \
  171. pix = next_pix; \
  172. } while (--h); \
  173. } while (0)
  174. #define OP_XY2(LOAD, STORE) \
  175. do { \
  176. uint64_t pix1 = LOAD(pixels); \
  177. uint64_t pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \
  178. uint64_t pix_l = (pix1 & BYTE_VEC(0x03)) \
  179. + (pix2 & BYTE_VEC(0x03)); \
  180. uint64_t pix_h = ((pix1 & ~BYTE_VEC(0x03)) >> 2) \
  181. + ((pix2 & ~BYTE_VEC(0x03)) >> 2); \
  182. \
  183. do { \
  184. uint64_t npix1, npix2; \
  185. uint64_t npix_l, npix_h; \
  186. uint64_t avg; \
  187. \
  188. pixels += line_size; \
  189. npix1 = LOAD(pixels); \
  190. npix2 = npix1 >> 8 | ((uint64_t) pixels[8] << 56); \
  191. npix_l = (npix1 & BYTE_VEC(0x03)) \
  192. + (npix2 & BYTE_VEC(0x03)); \
  193. npix_h = ((npix1 & ~BYTE_VEC(0x03)) >> 2) \
  194. + ((npix2 & ~BYTE_VEC(0x03)) >> 2); \
  195. avg = (((pix_l + npix_l + AVG4_ROUNDER) >> 2) & BYTE_VEC(0x03)) \
  196. + pix_h + npix_h; \
  197. STORE(avg, block); \
  198. \
  199. block += line_size; \
  200. pix_l = npix_l; \
  201. pix_h = npix_h; \
  202. } while (--h); \
  203. } while (0)
  204. #define MAKE_OP(OPNAME, SUFF, OPKIND, STORE) \
  205. static void OPNAME ## _pixels ## SUFF ## _axp \
  206. (uint8_t *restrict block, const uint8_t *restrict pixels, \
  207. int line_size, int h) \
  208. { \
  209. if ((size_t) pixels & 0x7) { \
  210. OPKIND(uldq, STORE); \
  211. } else { \
  212. OPKIND(ldq, STORE); \
  213. } \
  214. } \
  215. \
  216. static void OPNAME ## _pixels16 ## SUFF ## _axp \
  217. (uint8_t *restrict block, const uint8_t *restrict pixels, \
  218. int line_size, int h) \
  219. { \
  220. OPNAME ## _pixels ## SUFF ## _axp(block, pixels, line_size, h); \
  221. OPNAME ## _pixels ## SUFF ## _axp(block + 8, pixels + 8, line_size, h); \
  222. }
  223. #define PIXOP(OPNAME, STORE) \
  224. MAKE_OP(OPNAME, , OP, STORE) \
  225. MAKE_OP(OPNAME, _x2, OP_X2, STORE) \
  226. MAKE_OP(OPNAME, _y2, OP_Y2, STORE) \
  227. MAKE_OP(OPNAME, _xy2, OP_XY2, STORE)
  228. /* Rounding primitives. */
  229. #define AVG2 avg2
  230. #define AVG4 avg4
  231. #define AVG4_ROUNDER BYTE_VEC(0x02)
  232. #define STORE(l, b) stq(l, b)
  233. PIXOP(put, STORE);
  234. #undef STORE
  235. #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
  236. PIXOP(avg, STORE);
  237. /* Not rounding primitives. */
  238. #undef AVG2
  239. #undef AVG4
  240. #undef AVG4_ROUNDER
  241. #undef STORE
  242. #define AVG2 avg2_no_rnd
  243. #define AVG4 avg4_no_rnd
  244. #define AVG4_ROUNDER BYTE_VEC(0x01)
  245. #define STORE(l, b) stq(l, b)
  246. PIXOP(put_no_rnd, STORE);
  247. #undef STORE
  248. #define STORE(l, b) stq(AVG2(l, ldq(b)), b);
  249. PIXOP(avg_no_rnd, STORE);
  250. void put_pixels16_axp_asm(uint8_t *block, const uint8_t *pixels,
  251. int line_size, int h)
  252. {
  253. put_pixels_axp_asm(block, pixels, line_size, h);
  254. put_pixels_axp_asm(block + 8, pixels + 8, line_size, h);
  255. }
  256. static int sad16x16_mvi(void *s, uint8_t *a, uint8_t *b, int stride)
  257. {
  258. return pix_abs16x16_mvi_asm(a, b, stride);
  259. }
  260. static int sad8x8_mvi(void *s, uint8_t *a, uint8_t *b, int stride)
  261. {
  262. return pix_abs8x8_mvi(a, b, stride);
  263. }
  264. void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx)
  265. {
  266. c->put_pixels_tab[0][0] = put_pixels16_axp_asm;
  267. c->put_pixels_tab[0][1] = put_pixels16_x2_axp;
  268. c->put_pixels_tab[0][2] = put_pixels16_y2_axp;
  269. c->put_pixels_tab[0][3] = put_pixels16_xy2_axp;
  270. c->put_no_rnd_pixels_tab[0][0] = put_pixels16_axp_asm;
  271. c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_axp;
  272. c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_axp;
  273. c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_axp;
  274. c->avg_pixels_tab[0][0] = avg_pixels16_axp;
  275. c->avg_pixels_tab[0][1] = avg_pixels16_x2_axp;
  276. c->avg_pixels_tab[0][2] = avg_pixels16_y2_axp;
  277. c->avg_pixels_tab[0][3] = avg_pixels16_xy2_axp;
  278. c->avg_no_rnd_pixels_tab[0][0] = avg_no_rnd_pixels16_axp;
  279. c->avg_no_rnd_pixels_tab[0][1] = avg_no_rnd_pixels16_x2_axp;
  280. c->avg_no_rnd_pixels_tab[0][2] = avg_no_rnd_pixels16_y2_axp;
  281. c->avg_no_rnd_pixels_tab[0][3] = avg_no_rnd_pixels16_xy2_axp;
  282. c->put_pixels_tab[1][0] = put_pixels_axp_asm;
  283. c->put_pixels_tab[1][1] = put_pixels_x2_axp;
  284. c->put_pixels_tab[1][2] = put_pixels_y2_axp;
  285. c->put_pixels_tab[1][3] = put_pixels_xy2_axp;
  286. c->put_no_rnd_pixels_tab[1][0] = put_pixels_axp_asm;
  287. c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels_x2_axp;
  288. c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels_y2_axp;
  289. c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels_xy2_axp;
  290. c->avg_pixels_tab[1][0] = avg_pixels_axp;
  291. c->avg_pixels_tab[1][1] = avg_pixels_x2_axp;
  292. c->avg_pixels_tab[1][2] = avg_pixels_y2_axp;
  293. c->avg_pixels_tab[1][3] = avg_pixels_xy2_axp;
  294. c->avg_no_rnd_pixels_tab[1][0] = avg_no_rnd_pixels_axp;
  295. c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels_x2_axp;
  296. c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels_y2_axp;
  297. c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels_xy2_axp;
  298. c->clear_blocks = clear_blocks_axp;
  299. /* amask clears all bits that correspond to present features. */
  300. if (amask(AMASK_MVI) == 0) {
  301. c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
  302. c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
  303. c->get_pixels = get_pixels_mvi;
  304. c->diff_pixels = diff_pixels_mvi;
  305. c->sad[0] = sad16x16_mvi;
  306. c->sad[1] = sad8x8_mvi;
  307. c->pix_abs8x8 = pix_abs8x8_mvi;
  308. c->pix_abs16x16 = pix_abs16x16_mvi_asm;
  309. c->pix_abs16x16_x2 = pix_abs16x16_x2_mvi;
  310. c->pix_abs16x16_y2 = pix_abs16x16_y2_mvi;
  311. c->pix_abs16x16_xy2 = pix_abs16x16_xy2_mvi;
  312. }
  313. put_pixels_clamped_axp_p = c->put_pixels_clamped;
  314. add_pixels_clamped_axp_p = c->add_pixels_clamped;
  315. c->idct_put = simple_idct_put_axp;
  316. c->idct_add = simple_idct_add_axp;
  317. }