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 file is part of FFmpeg.
  6. *
  7. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "asm.h"
  22. #include "../dsputil.h"
  23. #include "../mpegvideo.h"
  24. static void dct_unquantize_h263_intra_axp(MpegEncContext *s, DCTELEM *block,
  25. int n, int qscale)
  26. {
  27. int i, n_coeffs;
  28. uint64_t qmul, qadd;
  29. uint64_t correction;
  30. DCTELEM *orig_block = block;
  31. DCTELEM block0; /* might not be used uninitialized */
  32. qadd = WORD_VEC((qscale - 1) | 1);
  33. qmul = qscale << 1;
  34. /* This mask kills spill from negative subwords to the next subword. */
  35. correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */
  36. if (!s->h263_aic) {
  37. if (n < 4)
  38. block0 = block[0] * s->y_dc_scale;
  39. else
  40. block0 = block[0] * s->c_dc_scale;
  41. } else {
  42. qadd = 0;
  43. }
  44. n_coeffs = 63; // does not always use zigzag table
  45. for(i = 0; i <= n_coeffs; block += 4, i += 4) {
  46. uint64_t levels, negmask, zeros, add;
  47. levels = ldq(block);
  48. if (levels == 0)
  49. continue;
  50. #ifdef __alpha_max__
  51. /* I don't think the speed difference justifies runtime
  52. detection. */
  53. negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
  54. negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
  55. #else
  56. negmask = cmpbge(WORD_VEC(0x7fff), levels);
  57. negmask &= (negmask >> 1) | (1 << 7);
  58. negmask = zap(-1, negmask);
  59. #endif
  60. zeros = cmpbge(0, levels);
  61. zeros &= zeros >> 1;
  62. /* zeros |= zeros << 1 is not needed since qadd <= 255, so
  63. zapping the lower byte suffices. */
  64. levels *= qmul;
  65. levels -= correction & (negmask << 16);
  66. /* Negate qadd for negative levels. */
  67. add = qadd ^ negmask;
  68. add += WORD_VEC(0x0001) & negmask;
  69. /* Set qadd to 0 for levels == 0. */
  70. add = zap(add, zeros);
  71. levels += add;
  72. stq(levels, block);
  73. }
  74. if (s->mb_intra && !s->h263_aic)
  75. orig_block[0] = block0;
  76. }
  77. static void dct_unquantize_h263_inter_axp(MpegEncContext *s, DCTELEM *block,
  78. int n, int qscale)
  79. {
  80. int i, n_coeffs;
  81. uint64_t qmul, qadd;
  82. uint64_t correction;
  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. }