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.

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