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.

148 lines
4.5KB

  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. #include "../mpegvideo.h"
  22. static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block,
  23. int n, int qscale)
  24. {
  25. int i, n_coeffs;
  26. uint64_t qmul, qadd;
  27. uint64_t correction;
  28. DCTELEM *orig_block = block;
  29. DCTELEM block0;
  30. qadd = WORD_VEC((qscale - 1) | 1);
  31. qmul = qscale << 1;
  32. /* This mask kills spill from negative subwords to the next subword. */
  33. correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
  34. if (!s->h263_aic) {
  35. if (n < 4)
  36. block0 = block[0] * s->y_dc_scale;
  37. else
  38. block0 = block[0] * s->c_dc_scale;
  39. } else {
  40. qadd = 0;
  41. }
  42. n_coeffs = 63; // does not always use zigzag table
  43. for(i = 0; i <= n_coeffs; block += 4, i += 4) {
  44. uint64_t levels, negmask, zeros, add;
  45. levels = ldq(block);
  46. if (levels == 0)
  47. continue;
  48. #ifdef __alpha_max__
  49. /* I don't think the speed difference justifies runtime
  50. detection. */
  51. negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
  52. negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
  53. #else
  54. negmask = cmpbge(WORD_VEC(0x7fff), levels);
  55. negmask &= (negmask >> 1) | (1 << 7);
  56. negmask = zap(-1, negmask);
  57. #endif
  58. zeros = cmpbge(0, levels);
  59. zeros &= zeros >> 1;
  60. /* zeros |= zeros << 1 is not needed since qadd <= 255, so
  61. zapping the lower byte suffices. */
  62. levels *= qmul;
  63. levels -= correction & (negmask << 16);
  64. /* Negate qadd for negative levels. */
  65. add = qadd ^ negmask;
  66. add += WORD_VEC(0x0001) & negmask;
  67. /* Set qadd to 0 for levels == 0. */
  68. add = zap(add, zeros);
  69. levels += add;
  70. stq(levels, block);
  71. }
  72. if (s->mb_intra && !s->h263_aic)
  73. orig_block[0] = block0;
  74. }
  75. static void dct_unquantize_h263_inter_axp(MpegEncContext *s, DCTELEM *block,
  76. int n, int qscale)
  77. {
  78. int i, n_coeffs;
  79. uint64_t qmul, qadd;
  80. uint64_t correction;
  81. DCTELEM *orig_block = block;
  82. DCTELEM block0;
  83. qadd = WORD_VEC((qscale - 1) | 1);
  84. qmul = qscale << 1;
  85. /* This mask kills spill from negative subwords to the next subword. */
  86. correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
  87. n_coeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
  88. for(i = 0; i <= n_coeffs; block += 4, i += 4) {
  89. uint64_t levels, negmask, zeros, add;
  90. levels = ldq(block);
  91. if (levels == 0)
  92. continue;
  93. #ifdef __alpha_max__
  94. /* I don't think the speed difference justifies runtime
  95. detection. */
  96. negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
  97. negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
  98. #else
  99. negmask = cmpbge(WORD_VEC(0x7fff), levels);
  100. negmask &= (negmask >> 1) | (1 << 7);
  101. negmask = zap(-1, negmask);
  102. #endif
  103. zeros = cmpbge(0, levels);
  104. zeros &= zeros >> 1;
  105. /* zeros |= zeros << 1 is not needed since qadd <= 255, so
  106. zapping the lower byte suffices. */
  107. levels *= qmul;
  108. levels -= correction & (negmask << 16);
  109. /* Negate qadd for negative levels. */
  110. add = qadd ^ negmask;
  111. add += WORD_VEC(0x0001) & negmask;
  112. /* Set qadd to 0 for levels == 0. */
  113. add = zap(add, zeros);
  114. levels += add;
  115. stq(levels, block);
  116. }
  117. }
  118. void MPV_common_init_axp(MpegEncContext *s)
  119. {
  120. s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_axp;
  121. s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_axp;
  122. }