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.

158 lines
4.8KB

  1. /*
  2. * Alpha optimized DSP utils
  3. * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavutil/attributes.h"
  22. #include "libavcodec/dsputil.h"
  23. #include "dsputil_alpha.h"
  24. #include "asm.h"
  25. void (*put_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels,
  26. int line_size);
  27. void (*add_pixels_clamped_axp_p)(const int16_t *block, uint8_t *pixels,
  28. int line_size);
  29. #if 0
  30. /* These functions were the base for the optimized assembler routines,
  31. and remain here for documentation purposes. */
  32. static void put_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
  33. ptrdiff_t line_size)
  34. {
  35. int i = 8;
  36. uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
  37. do {
  38. uint64_t shorts0, shorts1;
  39. shorts0 = ldq(block);
  40. shorts0 = maxsw4(shorts0, 0);
  41. shorts0 = minsw4(shorts0, clampmask);
  42. stl(pkwb(shorts0), pixels);
  43. shorts1 = ldq(block + 4);
  44. shorts1 = maxsw4(shorts1, 0);
  45. shorts1 = minsw4(shorts1, clampmask);
  46. stl(pkwb(shorts1), pixels + 4);
  47. pixels += line_size;
  48. block += 8;
  49. } while (--i);
  50. }
  51. void add_pixels_clamped_mvi(const int16_t *block, uint8_t *pixels,
  52. ptrdiff_t line_size)
  53. {
  54. int h = 8;
  55. /* Keep this function a leaf function by generating the constants
  56. manually (mainly for the hack value ;-). */
  57. uint64_t clampmask = zap(-1, 0xaa); /* 0x00ff00ff00ff00ff */
  58. uint64_t signmask = zap(-1, 0x33);
  59. signmask ^= signmask >> 1; /* 0x8000800080008000 */
  60. do {
  61. uint64_t shorts0, pix0, signs0;
  62. uint64_t shorts1, pix1, signs1;
  63. shorts0 = ldq(block);
  64. shorts1 = ldq(block + 4);
  65. pix0 = unpkbw(ldl(pixels));
  66. /* Signed subword add (MMX paddw). */
  67. signs0 = shorts0 & signmask;
  68. shorts0 &= ~signmask;
  69. shorts0 += pix0;
  70. shorts0 ^= signs0;
  71. /* Clamp. */
  72. shorts0 = maxsw4(shorts0, 0);
  73. shorts0 = minsw4(shorts0, clampmask);
  74. /* Next 4. */
  75. pix1 = unpkbw(ldl(pixels + 4));
  76. signs1 = shorts1 & signmask;
  77. shorts1 &= ~signmask;
  78. shorts1 += pix1;
  79. shorts1 ^= signs1;
  80. shorts1 = maxsw4(shorts1, 0);
  81. shorts1 = minsw4(shorts1, clampmask);
  82. stl(pkwb(shorts0), pixels);
  83. stl(pkwb(shorts1), pixels + 4);
  84. pixels += line_size;
  85. block += 8;
  86. } while (--h);
  87. }
  88. #endif
  89. static void clear_blocks_axp(int16_t *blocks) {
  90. uint64_t *p = (uint64_t *) blocks;
  91. int n = sizeof(int16_t) * 6 * 64;
  92. do {
  93. p[0] = 0;
  94. p[1] = 0;
  95. p[2] = 0;
  96. p[3] = 0;
  97. p[4] = 0;
  98. p[5] = 0;
  99. p[6] = 0;
  100. p[7] = 0;
  101. p += 8;
  102. n -= 8 * 8;
  103. } while (n);
  104. }
  105. av_cold void ff_dsputil_init_alpha(DSPContext *c, AVCodecContext *avctx)
  106. {
  107. const int high_bit_depth = avctx->bits_per_raw_sample > 8;
  108. if (!high_bit_depth) {
  109. c->clear_blocks = clear_blocks_axp;
  110. }
  111. /* amask clears all bits that correspond to present features. */
  112. if (amask(AMASK_MVI) == 0) {
  113. c->put_pixels_clamped = put_pixels_clamped_mvi_asm;
  114. c->add_pixels_clamped = add_pixels_clamped_mvi_asm;
  115. if (!high_bit_depth)
  116. c->get_pixels = get_pixels_mvi;
  117. c->diff_pixels = diff_pixels_mvi;
  118. c->sad[0] = pix_abs16x16_mvi_asm;
  119. c->sad[1] = pix_abs8x8_mvi;
  120. c->pix_abs[0][0] = pix_abs16x16_mvi_asm;
  121. c->pix_abs[1][0] = pix_abs8x8_mvi;
  122. c->pix_abs[0][1] = pix_abs16x16_x2_mvi;
  123. c->pix_abs[0][2] = pix_abs16x16_y2_mvi;
  124. c->pix_abs[0][3] = pix_abs16x16_xy2_mvi;
  125. }
  126. put_pixels_clamped_axp_p = c->put_pixels_clamped;
  127. add_pixels_clamped_axp_p = c->add_pixels_clamped;
  128. if (avctx->bits_per_raw_sample <= 8 &&
  129. (avctx->idct_algo == FF_IDCT_AUTO ||
  130. avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) {
  131. c->idct_put = ff_simple_idct_put_axp;
  132. c->idct_add = ff_simple_idct_add_axp;
  133. c->idct = ff_simple_idct_axp;
  134. }
  135. }