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.

129 lines
4.5KB

  1. /*
  2. * Copyright (C) 2002-2012 Michael Niedermayer
  3. * Copyright (C) 2012 Ronald S. Bultje
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "config.h"
  22. #include "libavutil/attributes.h"
  23. #include "libavutil/avassert.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/mem.h"
  27. #include "libavutil/x86/asm.h"
  28. #include "libavcodec/videodsp.h"
  29. #if HAVE_YASM
  30. typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src,
  31. x86_reg linesize, x86_reg start_y,
  32. x86_reg end_y, x86_reg block_h,
  33. x86_reg start_x, x86_reg end_x,
  34. x86_reg block_w);
  35. extern emu_edge_core_func ff_emu_edge_core_mmx;
  36. extern emu_edge_core_func ff_emu_edge_core_sse;
  37. static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src,
  38. ptrdiff_t linesize_arg,
  39. int block_w, int block_h,
  40. int src_x, int src_y,
  41. int w, int h,
  42. emu_edge_core_func *core_fn)
  43. {
  44. int start_y, start_x, end_y, end_x, src_y_add = 0;
  45. int linesize = linesize_arg;
  46. if(!w || !h)
  47. return;
  48. if (src_y >= h) {
  49. src -= src_y*linesize;
  50. src_y_add = h - 1;
  51. src_y = h - 1;
  52. } else if (src_y <= -block_h) {
  53. src -= src_y*linesize;
  54. src_y_add = 1 - block_h;
  55. src_y = 1 - block_h;
  56. }
  57. if (src_x >= w) {
  58. src += w - 1 - src_x;
  59. src_x = w - 1;
  60. } else if (src_x <= -block_w) {
  61. src += 1 - block_w - src_x;
  62. src_x = 1 - block_w;
  63. }
  64. start_y = FFMAX(0, -src_y);
  65. start_x = FFMAX(0, -src_x);
  66. end_y = FFMIN(block_h, h-src_y);
  67. end_x = FFMIN(block_w, w-src_x);
  68. av_assert2(start_x < end_x && block_w > 0);
  69. av_assert2(start_y < end_y && block_h > 0);
  70. // fill in the to-be-copied part plus all above/below
  71. src += (src_y_add + start_y) * linesize + start_x;
  72. buf += start_x;
  73. core_fn(buf, src, linesize, start_y, end_y,
  74. block_h, start_x, end_x, block_w);
  75. }
  76. #if ARCH_X86_32
  77. static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src,
  78. ptrdiff_t linesize,
  79. int block_w, int block_h,
  80. int src_x, int src_y, int w, int h)
  81. {
  82. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  83. w, h, &ff_emu_edge_core_mmx);
  84. }
  85. #endif
  86. static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src,
  87. ptrdiff_t linesize,
  88. int block_w, int block_h,
  89. int src_x, int src_y, int w, int h)
  90. {
  91. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  92. w, h, &ff_emu_edge_core_sse);
  93. }
  94. #endif /* HAVE_YASM */
  95. void ff_prefetch_mmxext(uint8_t *buf, ptrdiff_t stride, int h);
  96. void ff_prefetch_3dnow(uint8_t *buf, ptrdiff_t stride, int h);
  97. av_cold void ff_videodsp_init_x86(VideoDSPContext *ctx, int bpc)
  98. {
  99. #if HAVE_YASM
  100. int mm_flags = av_get_cpu_flags();
  101. #if ARCH_X86_32
  102. if (bpc <= 8 && mm_flags & AV_CPU_FLAG_MMX) {
  103. ctx->emulated_edge_mc = emulated_edge_mc_mmx;
  104. }
  105. if (mm_flags & AV_CPU_FLAG_3DNOW) {
  106. ctx->prefetch = ff_prefetch_3dnow;
  107. }
  108. #endif /* ARCH_X86_32 */
  109. if (mm_flags & AV_CPU_FLAG_MMXEXT) {
  110. ctx->prefetch = ff_prefetch_mmxext;
  111. }
  112. if (bpc <= 8 && mm_flags & AV_CPU_FLAG_SSE) {
  113. ctx->emulated_edge_mc = emulated_edge_mc_sse;
  114. }
  115. #endif /* HAVE_YASM */
  116. }