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.9KB

  1. /*
  2. * Copyright (c) 2009 David Conrad <lessen42@gmail.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <stdint.h>
  21. #include "libavutil/attributes.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/x86/cpu.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavcodec/avcodec.h"
  26. #include "libavcodec/dsputil.h"
  27. #include "libavcodec/vp3dsp.h"
  28. #include "config.h"
  29. void ff_vp3_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block);
  30. void ff_vp3_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block);
  31. void ff_vp3_idct_put_sse2(uint8_t *dest, int line_size, int16_t *block);
  32. void ff_vp3_idct_add_sse2(uint8_t *dest, int line_size, int16_t *block);
  33. void ff_vp3_idct_dc_add_mmxext(uint8_t *dest, int line_size,
  34. int16_t *block);
  35. void ff_vp3_v_loop_filter_mmxext(uint8_t *src, int stride,
  36. int *bounding_values);
  37. void ff_vp3_h_loop_filter_mmxext(uint8_t *src, int stride,
  38. int *bounding_values);
  39. #if HAVE_INLINE_ASM
  40. #define MOVQ_BFE(regd) \
  41. __asm__ volatile ( \
  42. "pcmpeqd %%"#regd", %%"#regd" \n\t" \
  43. "paddb %%"#regd", %%"#regd" \n\t" ::)
  44. #define PAVGBP_MMX_NO_RND(rega, regb, regr, regc, regd, regp) \
  45. "movq "#rega", "#regr" \n\t" \
  46. "movq "#regc", "#regp" \n\t" \
  47. "pand "#regb", "#regr" \n\t" \
  48. "pand "#regd", "#regp" \n\t" \
  49. "pxor "#rega", "#regb" \n\t" \
  50. "pxor "#regc", "#regd" \n\t" \
  51. "pand %%mm6, "#regb" \n\t" \
  52. "pand %%mm6, "#regd" \n\t" \
  53. "psrlq $1, "#regb" \n\t" \
  54. "psrlq $1, "#regd" \n\t" \
  55. "paddb "#regb", "#regr" \n\t" \
  56. "paddb "#regd", "#regp" \n\t"
  57. static void put_vp_no_rnd_pixels8_l2_mmx(uint8_t *dst, const uint8_t *a, const uint8_t *b, ptrdiff_t stride, int h)
  58. {
  59. // START_TIMER
  60. MOVQ_BFE(mm6);
  61. __asm__ volatile(
  62. "1: \n\t"
  63. "movq (%1), %%mm0 \n\t"
  64. "movq (%2), %%mm1 \n\t"
  65. "movq (%1,%4), %%mm2 \n\t"
  66. "movq (%2,%4), %%mm3 \n\t"
  67. PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
  68. "movq %%mm4, (%3) \n\t"
  69. "movq %%mm5, (%3,%4) \n\t"
  70. "movq (%1,%4,2), %%mm0 \n\t"
  71. "movq (%2,%4,2), %%mm1 \n\t"
  72. "movq (%1,%5), %%mm2 \n\t"
  73. "movq (%2,%5), %%mm3 \n\t"
  74. "lea (%1,%4,4), %1 \n\t"
  75. "lea (%2,%4,4), %2 \n\t"
  76. PAVGBP_MMX_NO_RND(%%mm0, %%mm1, %%mm4, %%mm2, %%mm3, %%mm5)
  77. "movq %%mm4, (%3,%4,2) \n\t"
  78. "movq %%mm5, (%3,%5) \n\t"
  79. "lea (%3,%4,4), %3 \n\t"
  80. "subl $4, %0 \n\t"
  81. "jnz 1b \n\t"
  82. :"+r"(h), "+r"(a), "+r"(b), "+r"(dst)
  83. :"r"((x86_reg)stride), "r"((x86_reg)3L*stride)
  84. :"memory");
  85. // STOP_TIMER("put_vp_no_rnd_pixels8_l2_mmx")
  86. }
  87. #endif /* HAVE_INLINE_ASM */
  88. av_cold void ff_vp3dsp_init_x86(VP3DSPContext *c, int flags)
  89. {
  90. int cpuflags = av_get_cpu_flags();
  91. #if HAVE_INLINE_ASM
  92. c->put_no_rnd_pixels_l2 = put_vp_no_rnd_pixels8_l2_mmx;
  93. #endif /* HAVE_INLINE_ASM */
  94. #if ARCH_X86_32
  95. if (EXTERNAL_MMX(cpuflags)) {
  96. c->idct_put = ff_vp3_idct_put_mmx;
  97. c->idct_add = ff_vp3_idct_add_mmx;
  98. c->idct_perm = FF_PARTTRANS_IDCT_PERM;
  99. }
  100. #endif
  101. if (EXTERNAL_MMXEXT(cpuflags)) {
  102. c->idct_dc_add = ff_vp3_idct_dc_add_mmxext;
  103. if (!(flags & CODEC_FLAG_BITEXACT)) {
  104. c->v_loop_filter = ff_vp3_v_loop_filter_mmxext;
  105. c->h_loop_filter = ff_vp3_h_loop_filter_mmxext;
  106. }
  107. }
  108. if (EXTERNAL_SSE2(cpuflags)) {
  109. c->idct_put = ff_vp3_idct_put_sse2;
  110. c->idct_add = ff_vp3_idct_add_sse2;
  111. c->idct_perm = FF_TRANSPOSE_IDCT_PERM;
  112. }
  113. }