mpegvideo_alpha.c 3.2 KB

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