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.

112 lines
3.3KB

  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 "libavcodec/mpegvideo.h"
  24. #include "asm.h"
  25. static void dct_unquantize_h263_axp(int16_t *block, int n_coeffs,
  26. uint64_t qscale, uint64_t qadd)
  27. {
  28. uint64_t qmul = qscale << 1;
  29. uint64_t correction = WORD_VEC(qmul * 255 >> 8);
  30. int i;
  31. qadd = WORD_VEC(qadd);
  32. for(i = 0; i <= n_coeffs; block += 4, i += 4) {
  33. uint64_t levels, negmask, zeros, add, sub;
  34. levels = ldq(block);
  35. if (levels == 0)
  36. continue;
  37. #ifdef __alpha_max__
  38. /* I don't think the speed difference justifies runtime
  39. detection. */
  40. negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */
  41. negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */
  42. #else
  43. negmask = cmpbge(WORD_VEC(0x7fff), levels);
  44. negmask &= (negmask >> 1) | (1 << 7);
  45. negmask = zap(-1, negmask);
  46. #endif
  47. zeros = cmpbge(0, levels);
  48. zeros &= zeros >> 1;
  49. /* zeros |= zeros << 1 is not needed since qadd <= 255, so
  50. zapping the lower byte suffices. */
  51. levels *= qmul;
  52. levels -= correction & (negmask << 16);
  53. add = qadd & ~negmask;
  54. sub = qadd & negmask;
  55. /* Set qadd to 0 for levels == 0. */
  56. add = zap(add, zeros);
  57. levels += add;
  58. levels -= sub;
  59. stq(levels, block);
  60. }
  61. }
  62. static void dct_unquantize_h263_intra_axp(MpegEncContext *s, int16_t *block,
  63. int n, int qscale)
  64. {
  65. int n_coeffs;
  66. uint64_t qadd;
  67. int16_t block0 = block[0];
  68. if (!s->h263_aic) {
  69. if (n < 4)
  70. block0 *= s->y_dc_scale;
  71. else
  72. block0 *= s->c_dc_scale;
  73. qadd = (qscale - 1) | 1;
  74. } else {
  75. qadd = 0;
  76. }
  77. if(s->ac_pred)
  78. n_coeffs = 63;
  79. else
  80. n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
  81. dct_unquantize_h263_axp(block, n_coeffs, qscale, qadd);
  82. block[0] = block0;
  83. }
  84. static void dct_unquantize_h263_inter_axp(MpegEncContext *s, int16_t *block,
  85. int n, int qscale)
  86. {
  87. int n_coeffs = s->inter_scantable.raster_end[s->block_last_index[n]];
  88. dct_unquantize_h263_axp(block, n_coeffs, qscale, (qscale - 1) | 1);
  89. }
  90. av_cold void ff_MPV_common_init_axp(MpegEncContext *s)
  91. {
  92. s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_axp;
  93. s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_axp;
  94. }