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.

107 lines
3.7KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * Libav is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdint.h>
  19. #include "config.h"
  20. #include "libavutil/attributes.h"
  21. #include "libavutil/internal.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/x86/asm.h"
  24. #include "libavutil/x86/cpu.h"
  25. #include "libavcodec/blockdsp.h"
  26. #if HAVE_INLINE_ASM
  27. #define CLEAR_BLOCKS(name, n) \
  28. static void name(int16_t *blocks) \
  29. { \
  30. __asm__ volatile ( \
  31. "pxor %%mm7, %%mm7 \n\t" \
  32. "mov %1, %%"FF_REG_a" \n\t" \
  33. "1: \n\t" \
  34. "movq %%mm7, (%0, %%"FF_REG_a") \n\t" \
  35. "movq %%mm7, 8(%0, %%"FF_REG_a") \n\t" \
  36. "movq %%mm7, 16(%0, %%"FF_REG_a") \n\t" \
  37. "movq %%mm7, 24(%0, %%"FF_REG_a") \n\t" \
  38. "add $32, %%"FF_REG_a" \n\t" \
  39. "js 1b \n\t" \
  40. :: "r"(((uint8_t *) blocks) + 128 * n), \
  41. "i"(-128 * n) \
  42. : "%"FF_REG_a); \
  43. }
  44. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  45. CLEAR_BLOCKS(clear_block_mmx, 1)
  46. static void clear_block_sse(int16_t *block)
  47. {
  48. __asm__ volatile (
  49. "xorps %%xmm0, %%xmm0 \n"
  50. "movaps %%xmm0, (%0) \n"
  51. "movaps %%xmm0, 16(%0) \n"
  52. "movaps %%xmm0, 32(%0) \n"
  53. "movaps %%xmm0, 48(%0) \n"
  54. "movaps %%xmm0, 64(%0) \n"
  55. "movaps %%xmm0, 80(%0) \n"
  56. "movaps %%xmm0, 96(%0) \n"
  57. "movaps %%xmm0, 112(%0) \n"
  58. :: "r" (block)
  59. : "memory");
  60. }
  61. static void clear_blocks_sse(int16_t *blocks)
  62. {
  63. __asm__ volatile (
  64. "xorps %%xmm0, %%xmm0 \n"
  65. "mov %1, %%"FF_REG_a" \n"
  66. "1: \n"
  67. "movaps %%xmm0, (%0, %%"FF_REG_a") \n"
  68. "movaps %%xmm0, 16(%0, %%"FF_REG_a") \n"
  69. "movaps %%xmm0, 32(%0, %%"FF_REG_a") \n"
  70. "movaps %%xmm0, 48(%0, %%"FF_REG_a") \n"
  71. "movaps %%xmm0, 64(%0, %%"FF_REG_a") \n"
  72. "movaps %%xmm0, 80(%0, %%"FF_REG_a") \n"
  73. "movaps %%xmm0, 96(%0, %%"FF_REG_a") \n"
  74. "movaps %%xmm0, 112(%0, %%"FF_REG_a") \n"
  75. "add $128, %%"FF_REG_a" \n"
  76. "js 1b \n"
  77. :: "r"(((uint8_t *) blocks) + 128 * 6), "i"(-128 * 6)
  78. : "%"FF_REG_a);
  79. }
  80. #endif /* HAVE_INLINE_ASM */
  81. av_cold void ff_blockdsp_init_x86(BlockDSPContext *c)
  82. {
  83. #if HAVE_INLINE_ASM
  84. int cpu_flags = av_get_cpu_flags();
  85. if (INLINE_MMX(cpu_flags)) {
  86. c->clear_block = clear_block_mmx;
  87. c->clear_blocks = clear_blocks_mmx;
  88. }
  89. if (INLINE_SSE(cpu_flags)) {
  90. c->clear_block = clear_block_sse;
  91. c->clear_blocks = clear_blocks_sse;
  92. }
  93. #endif /* HAVE_INLINE_ASM */
  94. }