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.

120 lines
4.2KB

  1. /*
  2. * Copyright (C) 2012 Ronald S. Bultje
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "config.h"
  21. #include "libavutil/common.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/mem.h"
  24. #include "libavutil/x86/asm.h"
  25. #include "libavcodec/videodsp.h"
  26. #if HAVE_YASM
  27. typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src,
  28. x86_reg linesize, x86_reg start_y,
  29. x86_reg end_y, x86_reg block_h,
  30. x86_reg start_x, x86_reg end_x,
  31. x86_reg block_w);
  32. extern emu_edge_core_func ff_emu_edge_core_mmx;
  33. extern emu_edge_core_func ff_emu_edge_core_sse;
  34. static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src,
  35. ptrdiff_t linesize,
  36. int block_w, int block_h,
  37. int src_x, int src_y,
  38. int w, int h,
  39. emu_edge_core_func *core_fn)
  40. {
  41. int start_y, start_x, end_y, end_x, src_y_add = 0;
  42. if (src_y >= h) {
  43. src_y_add = h - 1 - src_y;
  44. src_y = h - 1;
  45. } else if (src_y <= -block_h) {
  46. src_y_add = 1 - block_h - src_y;
  47. src_y = 1 - block_h;
  48. }
  49. if (src_x >= w) {
  50. src += w - 1 - src_x;
  51. src_x = w - 1;
  52. } else if (src_x <= -block_w) {
  53. src += 1 - block_w - src_x;
  54. src_x = 1 - block_w;
  55. }
  56. start_y = FFMAX(0, -src_y);
  57. start_x = FFMAX(0, -src_x);
  58. end_y = FFMIN(block_h, h-src_y);
  59. end_x = FFMIN(block_w, w-src_x);
  60. assert(start_x < end_x && block_w > 0);
  61. assert(start_y < end_y && block_h > 0);
  62. // fill in the to-be-copied part plus all above/below
  63. src += (src_y_add + start_y) * linesize + start_x;
  64. buf += start_x;
  65. core_fn(buf, src, linesize, start_y, end_y,
  66. block_h, start_x, end_x, block_w);
  67. }
  68. #if ARCH_X86_32
  69. static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src,
  70. ptrdiff_t linesize,
  71. int block_w, int block_h,
  72. int src_x, int src_y, int w, int h)
  73. {
  74. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  75. w, h, &ff_emu_edge_core_mmx);
  76. }
  77. #endif
  78. static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src,
  79. ptrdiff_t linesize,
  80. int block_w, int block_h,
  81. int src_x, int src_y, int w, int h)
  82. {
  83. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  84. w, h, &ff_emu_edge_core_sse);
  85. }
  86. #endif /* HAVE_YASM */
  87. void ff_prefetch_mmxext(uint8_t *buf, ptrdiff_t stride, int h);
  88. void ff_prefetch_3dnow(uint8_t *buf, ptrdiff_t stride, int h);
  89. void ff_videodsp_init_x86(VideoDSPContext *ctx, int bpc)
  90. {
  91. #if HAVE_YASM
  92. int mm_flags = av_get_cpu_flags();
  93. #if ARCH_X86_32
  94. if (bpc <= 8 && mm_flags & AV_CPU_FLAG_MMX) {
  95. ctx->emulated_edge_mc = emulated_edge_mc_mmx;
  96. }
  97. if (mm_flags & AV_CPU_FLAG_3DNOW) {
  98. ctx->prefetch = ff_prefetch_3dnow;
  99. }
  100. #endif /* ARCH_X86_32 */
  101. if (mm_flags & AV_CPU_FLAG_MMXEXT) {
  102. ctx->prefetch = ff_prefetch_mmxext;
  103. }
  104. if (bpc <= 8 && mm_flags & AV_CPU_FLAG_SSE) {
  105. ctx->emulated_edge_mc = emulated_edge_mc_sse;
  106. }
  107. #endif /* HAVE_YASM */
  108. }