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.

131 lines
4.2KB

  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 "config.h"
  26. #include "libavutil/attributes.h"
  27. #include "libavutil/cpu.h"
  28. #include "libavutil/ppc/types_altivec.h"
  29. #include "libavutil/ppc/util_altivec.h"
  30. #include "libavcodec/mpegvideo.h"
  31. #include "dsputil_altivec.h"
  32. #if HAVE_ALTIVEC
  33. /* AltiVec version of dct_unquantize_h263
  34. this code assumes `block' is 16 bytes-aligned */
  35. static void dct_unquantize_h263_altivec(MpegEncContext *s,
  36. int16_t *block, int n, int qscale)
  37. {
  38. int i, level, qmul, qadd;
  39. int nCoeffs;
  40. assert(s->block_last_index[n]>=0);
  41. qadd = (qscale - 1) | 1;
  42. qmul = qscale << 1;
  43. if (s->mb_intra) {
  44. if (!s->h263_aic) {
  45. if (n < 4)
  46. block[0] = block[0] * s->y_dc_scale;
  47. else
  48. block[0] = block[0] * s->c_dc_scale;
  49. }else
  50. qadd = 0;
  51. i = 1;
  52. nCoeffs= 63; //does not always use zigzag table
  53. } else {
  54. i = 0;
  55. nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
  56. }
  57. {
  58. register const vector signed short vczero = (const vector signed short)vec_splat_s16(0);
  59. DECLARE_ALIGNED(16, short, qmul8) = qmul;
  60. DECLARE_ALIGNED(16, short, qadd8) = qadd;
  61. register vector signed short blockv, qmulv, qaddv, nqaddv, temp1;
  62. register vector bool short blockv_null, blockv_neg;
  63. register short backup_0 = block[0];
  64. register int j = 0;
  65. qmulv = vec_splat((vec_s16)vec_lde(0, &qmul8), 0);
  66. qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0);
  67. nqaddv = vec_sub(vczero, qaddv);
  68. // vectorize all the 16 bytes-aligned blocks
  69. // of 8 elements
  70. for(; (j + 7) <= nCoeffs ; j+=8) {
  71. blockv = vec_ld(j << 1, block);
  72. blockv_neg = vec_cmplt(blockv, vczero);
  73. blockv_null = vec_cmpeq(blockv, vczero);
  74. // choose between +qadd or -qadd as the third operand
  75. temp1 = vec_sel(qaddv, nqaddv, blockv_neg);
  76. // multiply & add (block{i,i+7} * qmul [+-] qadd)
  77. temp1 = vec_mladd(blockv, qmulv, temp1);
  78. // put 0 where block[{i,i+7} used to have 0
  79. blockv = vec_sel(temp1, blockv, blockv_null);
  80. vec_st(blockv, j << 1, block);
  81. }
  82. // if nCoeffs isn't a multiple of 8, finish the job
  83. // using good old scalar units.
  84. // (we could do it using a truncated vector,
  85. // but I'm not sure it's worth the hassle)
  86. for(; j <= nCoeffs ; j++) {
  87. level = block[j];
  88. if (level) {
  89. if (level < 0) {
  90. level = level * qmul - qadd;
  91. } else {
  92. level = level * qmul + qadd;
  93. }
  94. block[j] = level;
  95. }
  96. }
  97. if (i == 1) {
  98. // cheat. this avoid special-casing the first iteration
  99. block[0] = backup_0;
  100. }
  101. }
  102. }
  103. #endif /* HAVE_ALTIVEC */
  104. av_cold void ff_MPV_common_init_ppc(MpegEncContext *s)
  105. {
  106. #if HAVE_ALTIVEC
  107. if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
  108. return;
  109. if ((s->avctx->dct_algo == FF_DCT_AUTO) ||
  110. (s->avctx->dct_algo == FF_DCT_ALTIVEC)) {
  111. s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec;
  112. s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec;
  113. }
  114. #endif /* HAVE_ALTIVEC */
  115. }