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.

342 lines
13KB

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