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.

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