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.

121 lines
4.2KB

  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. #include "libavcodec/version.h"
  27. #if HAVE_INLINE_ASM
  28. #define CLEAR_BLOCKS(name, n) \
  29. static void name(int16_t *blocks) \
  30. { \
  31. __asm__ volatile ( \
  32. "pxor %%mm7, %%mm7 \n\t" \
  33. "mov %1, %%"REG_a" \n\t" \
  34. "1: \n\t" \
  35. "movq %%mm7, (%0, %%"REG_a") \n\t" \
  36. "movq %%mm7, 8(%0, %%"REG_a") \n\t" \
  37. "movq %%mm7, 16(%0, %%"REG_a") \n\t" \
  38. "movq %%mm7, 24(%0, %%"REG_a") \n\t" \
  39. "add $32, %%"REG_a" \n\t" \
  40. "js 1b \n\t" \
  41. :: "r"(((uint8_t *) blocks) + 128 * n), \
  42. "i"(-128 * n) \
  43. : "%"REG_a); \
  44. }
  45. CLEAR_BLOCKS(clear_blocks_mmx, 6)
  46. CLEAR_BLOCKS(clear_block_mmx, 1)
  47. static void clear_block_sse(int16_t *block)
  48. {
  49. __asm__ volatile (
  50. "xorps %%xmm0, %%xmm0 \n"
  51. "movaps %%xmm0, (%0) \n"
  52. "movaps %%xmm0, 16(%0) \n"
  53. "movaps %%xmm0, 32(%0) \n"
  54. "movaps %%xmm0, 48(%0) \n"
  55. "movaps %%xmm0, 64(%0) \n"
  56. "movaps %%xmm0, 80(%0) \n"
  57. "movaps %%xmm0, 96(%0) \n"
  58. "movaps %%xmm0, 112(%0) \n"
  59. :: "r" (block)
  60. : "memory");
  61. }
  62. static void clear_blocks_sse(int16_t *blocks)
  63. {
  64. __asm__ volatile (
  65. "xorps %%xmm0, %%xmm0 \n"
  66. "mov %1, %%"REG_a" \n"
  67. "1: \n"
  68. "movaps %%xmm0, (%0, %%"REG_a") \n"
  69. "movaps %%xmm0, 16(%0, %%"REG_a") \n"
  70. "movaps %%xmm0, 32(%0, %%"REG_a") \n"
  71. "movaps %%xmm0, 48(%0, %%"REG_a") \n"
  72. "movaps %%xmm0, 64(%0, %%"REG_a") \n"
  73. "movaps %%xmm0, 80(%0, %%"REG_a") \n"
  74. "movaps %%xmm0, 96(%0, %%"REG_a") \n"
  75. "movaps %%xmm0, 112(%0, %%"REG_a") \n"
  76. "add $128, %%"REG_a" \n"
  77. "js 1b \n"
  78. :: "r"(((uint8_t *) blocks) + 128 * 6), "i"(-128 * 6)
  79. : "%"REG_a);
  80. }
  81. #endif /* HAVE_INLINE_ASM */
  82. #if FF_API_XVMC
  83. av_cold void ff_blockdsp_init_x86(BlockDSPContext *c, unsigned high_bit_depth,
  84. AVCodecContext *avctx)
  85. #else
  86. av_cold void ff_blockdsp_init_x86(BlockDSPContext *c, unsigned high_bit_depth)
  87. #endif /* FF_API_XVMC */
  88. {
  89. #if HAVE_INLINE_ASM
  90. int cpu_flags = av_get_cpu_flags();
  91. if (!high_bit_depth) {
  92. if (INLINE_MMX(cpu_flags)) {
  93. c->clear_block = clear_block_mmx;
  94. c->clear_blocks = clear_blocks_mmx;
  95. }
  96. #if FF_API_XVMC
  97. FF_DISABLE_DEPRECATION_WARNINGS
  98. /* XvMCCreateBlocks() may not allocate 16-byte aligned blocks */
  99. if (CONFIG_MPEG_XVMC_DECODER && avctx->xvmc_acceleration > 1)
  100. return;
  101. FF_ENABLE_DEPRECATION_WARNINGS
  102. #endif /* FF_API_XVMC */
  103. if (INLINE_SSE(cpu_flags)) {
  104. c->clear_block = clear_block_sse;
  105. c->clear_blocks = clear_blocks_sse;
  106. }
  107. }
  108. #endif /* HAVE_INLINE_ASM */
  109. }