mpegvideoenc_qns_template.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * QNS functions are compiled 3 times for MMX/3DNOW/SSSE3
  3. * Copyright (c) 2004 Michael Niedermayer
  4. *
  5. * MMX optimization by Michael Niedermayer <michaelni@gmx.at>
  6. * 3DNow! and SSSE3 optimization by Zuxy Meng <zuxy.meng@gmail.com>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include <stdint.h>
  25. #include "libavutil/avassert.h"
  26. #include "libavutil/common.h"
  27. #include "libavutil/x86/asm.h"
  28. #include "inline_asm.h"
  29. #define MAX_ABS (512 >> (SCALE_OFFSET>0 ? SCALE_OFFSET : 0))
  30. static int DEF(try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale)
  31. {
  32. x86_reg i=0;
  33. av_assert2(FFABS(scale) < MAX_ABS);
  34. scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT;
  35. SET_RND(mm6);
  36. __asm__ volatile(
  37. "pxor %%mm7, %%mm7 \n\t"
  38. "movd %4, %%mm5 \n\t"
  39. "punpcklwd %%mm5, %%mm5 \n\t"
  40. "punpcklwd %%mm5, %%mm5 \n\t"
  41. ".p2align 4 \n\t"
  42. "1: \n\t"
  43. "movq (%1, %0), %%mm0 \n\t"
  44. "movq 8(%1, %0), %%mm1 \n\t"
  45. PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6)
  46. "paddw (%2, %0), %%mm0 \n\t"
  47. "paddw 8(%2, %0), %%mm1 \n\t"
  48. "psraw $6, %%mm0 \n\t"
  49. "psraw $6, %%mm1 \n\t"
  50. "pmullw (%3, %0), %%mm0 \n\t"
  51. "pmullw 8(%3, %0), %%mm1 \n\t"
  52. "pmaddwd %%mm0, %%mm0 \n\t"
  53. "pmaddwd %%mm1, %%mm1 \n\t"
  54. "paddd %%mm1, %%mm0 \n\t"
  55. "psrld $4, %%mm0 \n\t"
  56. "paddd %%mm0, %%mm7 \n\t"
  57. "add $16, %0 \n\t"
  58. "cmp $128, %0 \n\t" //FIXME optimize & bench
  59. " jb 1b \n\t"
  60. PHADDD(%%mm7, %%mm6)
  61. "psrld $2, %%mm7 \n\t"
  62. "movd %%mm7, %0 \n\t"
  63. : "+r" (i)
  64. : "r"(basis), "r"(rem), "r"(weight), "g"(scale)
  65. );
  66. return i;
  67. }
  68. static void DEF(add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale)
  69. {
  70. x86_reg i=0;
  71. if(FFABS(scale) < MAX_ABS){
  72. scale<<= 16 + SCALE_OFFSET - BASIS_SHIFT + RECON_SHIFT;
  73. SET_RND(mm6);
  74. __asm__ volatile(
  75. "movd %3, %%mm5 \n\t"
  76. "punpcklwd %%mm5, %%mm5 \n\t"
  77. "punpcklwd %%mm5, %%mm5 \n\t"
  78. ".p2align 4 \n\t"
  79. "1: \n\t"
  80. "movq (%1, %0), %%mm0 \n\t"
  81. "movq 8(%1, %0), %%mm1 \n\t"
  82. PMULHRW(%%mm0, %%mm1, %%mm5, %%mm6)
  83. "paddw (%2, %0), %%mm0 \n\t"
  84. "paddw 8(%2, %0), %%mm1 \n\t"
  85. "movq %%mm0, (%2, %0) \n\t"
  86. "movq %%mm1, 8(%2, %0) \n\t"
  87. "add $16, %0 \n\t"
  88. "cmp $128, %0 \n\t" // FIXME optimize & bench
  89. " jb 1b \n\t"
  90. : "+r" (i)
  91. : "r"(basis), "r"(rem), "g"(scale)
  92. );
  93. }else{
  94. for(i=0; i<8*8; i++){
  95. rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT);
  96. }
  97. }
  98. }