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.

309 lines
11KB

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