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.

146 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; /* might not be used uninitialized */
  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. qadd = WORD_VEC((qscale - 1) | 1);
  82. qmul = qscale << 1;
  83. /* This mask kills spill from negative subwords to the next subword. */
  84. correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
  85. n_coeffs = s->intra_scantable.raster_end[s->block_last_index[n]];
  86. for(i = 0; i <= n_coeffs; block += 4, i += 4) {
  87. uint64_t levels, negmask, zeros, add;
  88. levels = ldq(block);
  89. if (levels == 0)
  90. continue;
  91. #ifdef __alpha_max__
  92. /* I don't think the speed difference justifies runtime
  93. detection. */
  94. negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
  95. negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
  96. #else
  97. negmask = cmpbge(WORD_VEC(0x7fff), levels);
  98. negmask &= (negmask >> 1) | (1 << 7);
  99. negmask = zap(-1, negmask);
  100. #endif
  101. zeros = cmpbge(0, levels);
  102. zeros &= zeros >> 1;
  103. /* zeros |= zeros << 1 is not needed since qadd <= 255, so
  104. zapping the lower byte suffices. */
  105. levels *= qmul;
  106. levels -= correction & (negmask << 16);
  107. /* Negate qadd for negative levels. */
  108. add = qadd ^ negmask;
  109. add += WORD_VEC(0x0001) & negmask;
  110. /* Set qadd to 0 for levels == 0. */
  111. add = zap(add, zeros);
  112. levels += add;
  113. stq(levels, block);
  114. }
  115. }
  116. void MPV_common_init_axp(MpegEncContext *s)
  117. {
  118. s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_axp;
  119. s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_axp;
  120. }