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.

125 lines
4.1KB

  1. /*
  2. * Copyright (c) 2002 Dieter Shirley
  3. *
  4. * dct_unquantize_h263_altivec:
  5. * Copyright (c) 2003 Romain Dolbeau <romain@dolbeau.org>
  6. *
  7. * This file is part of Libav.
  8. *
  9. * Libav is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * Libav is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with Libav; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/ppc/types_altivec.h"
  27. #include "libavutil/ppc/util_altivec.h"
  28. #include "libavcodec/dsputil.h"
  29. #include "libavcodec/mpegvideo.h"
  30. #include "dsputil_altivec.h"
  31. /* AltiVec version of dct_unquantize_h263
  32. this code assumes `block' is 16 bytes-aligned */
  33. static void dct_unquantize_h263_altivec(MpegEncContext *s,
  34. DCTELEM *block, int n, int qscale)
  35. {
  36. int i, level, qmul, qadd;
  37. int nCoeffs;
  38. assert(s->block_last_index[n]>=0);
  39. qadd = (qscale - 1) | 1;
  40. qmul = qscale << 1;
  41. if (s->mb_intra) {
  42. if (!s->h263_aic) {
  43. if (n < 4)
  44. block[0] = block[0] * s->y_dc_scale;
  45. else
  46. block[0] = block[0] * s->c_dc_scale;
  47. }else
  48. qadd = 0;
  49. i = 1;
  50. nCoeffs= 63; //does not always use zigzag table
  51. } else {
  52. i = 0;
  53. nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
  54. }
  55. {
  56. register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
  57. DECLARE_ALIGNED(16, short, qmul8) = qmul;
  58. DECLARE_ALIGNED(16, short, qadd8) = qadd;
  59. register vector signed short blockv, qmulv, qaddv, nqaddv, temp1;
  60. register vector bool short blockv_null, blockv_neg;
  61. register short backup_0 = block[0];
  62. register int j = 0;
  63. qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0);
  64. qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
  65. nqaddv = vec_sub(vczero, qaddv);
  66. // vectorize all the 16 bytes-aligned blocks
  67. // of 8 elements
  68. for(; (j + 7) <= nCoeffs ; j+=8) {
  69. blockv = vec_ld(j << 1, block);
  70. blockv_neg = vec_cmplt(blockv, vczero);
  71. blockv_null = vec_cmpeq(blockv, vczero);
  72. // choose between +qadd or -qadd as the third operand
  73. temp1 = vec_sel(qaddv, nqaddv, blockv_neg);
  74. // multiply & add (block{i,i+7} * qmul [+-] qadd)
  75. temp1 = vec_mladd(blockv, qmulv, temp1);
  76. // put 0 where block[{i,i+7} used to have 0
  77. blockv = vec_sel(temp1, blockv, blockv_null);
  78. vec_st(blockv, j << 1, block);
  79. }
  80. // if nCoeffs isn't a multiple of 8, finish the job
  81. // using good old scalar units.
  82. // (we could do it using a truncated vector,
  83. // but I'm not sure it's worth the hassle)
  84. for(; j <= nCoeffs ; j++) {
  85. level = block[j];
  86. if (level) {
  87. if (level < 0) {
  88. level = level * qmul - qadd;
  89. } else {
  90. level = level * qmul + qadd;
  91. }
  92. block[j] = level;
  93. }
  94. }
  95. if (i == 1) {
  96. // cheat. this avoid special-casing the first iteration
  97. block[0] = backup_0;
  98. }
  99. }
  100. }
  101. void ff_MPV_common_init_altivec(MpegEncContext *s)
  102. {
  103. if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return;
  104. if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
  105. (s->avctx->dct_algo == FF_DCT_ALTIVEC)) {
  106. s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec;
  107. s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec;
  108. }
  109. }