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.

122 lines
4.3KB

  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/attributes.h"
  22. #include "libavutil/common.h"
  23. #include "libavutil/cpu.h"
  24. #include "libavutil/mem.h"
  25. #include "libavutil/x86/asm.h"
  26. #include "libavutil/x86/cpu.h"
  27. #include "libavcodec/videodsp.h"
  28. #if HAVE_YASM
  29. typedef void emu_edge_core_func(uint8_t *buf, const uint8_t *src,
  30. x86_reg linesize, x86_reg start_y,
  31. x86_reg end_y, x86_reg block_h,
  32. x86_reg start_x, x86_reg end_x,
  33. x86_reg block_w);
  34. extern emu_edge_core_func ff_emu_edge_core_mmx;
  35. extern emu_edge_core_func ff_emu_edge_core_sse;
  36. static av_always_inline void emulated_edge_mc(uint8_t *buf, const uint8_t *src,
  37. ptrdiff_t linesize,
  38. int block_w, int block_h,
  39. int src_x, int src_y,
  40. int w, int h,
  41. emu_edge_core_func *core_fn)
  42. {
  43. int start_y, start_x, end_y, end_x, src_y_add = 0;
  44. if (src_y >= h) {
  45. src_y_add = h - 1 - src_y;
  46. src_y = h - 1;
  47. } else if (src_y <= -block_h) {
  48. src_y_add = 1 - block_h - src_y;
  49. src_y = 1 - block_h;
  50. }
  51. if (src_x >= w) {
  52. src += w - 1 - src_x;
  53. src_x = w - 1;
  54. } else if (src_x <= -block_w) {
  55. src += 1 - block_w - src_x;
  56. src_x = 1 - block_w;
  57. }
  58. start_y = FFMAX(0, -src_y);
  59. start_x = FFMAX(0, -src_x);
  60. end_y = FFMIN(block_h, h-src_y);
  61. end_x = FFMIN(block_w, w-src_x);
  62. assert(start_x < end_x && block_w > 0);
  63. assert(start_y < end_y && block_h > 0);
  64. // fill in the to-be-copied part plus all above/below
  65. src += (src_y_add + start_y) * linesize + start_x;
  66. buf += start_x;
  67. core_fn(buf, src, linesize, start_y, end_y,
  68. block_h, start_x, end_x, block_w);
  69. }
  70. #if ARCH_X86_32
  71. static av_noinline void emulated_edge_mc_mmx(uint8_t *buf, const uint8_t *src,
  72. ptrdiff_t linesize,
  73. int block_w, int block_h,
  74. int src_x, int src_y, int w, int h)
  75. {
  76. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  77. w, h, &ff_emu_edge_core_mmx);
  78. }
  79. #endif
  80. static av_noinline void emulated_edge_mc_sse(uint8_t *buf, const uint8_t *src,
  81. ptrdiff_t linesize,
  82. int block_w, int block_h,
  83. int src_x, int src_y, int w, int h)
  84. {
  85. emulated_edge_mc(buf, src, linesize, block_w, block_h, src_x, src_y,
  86. w, h, &ff_emu_edge_core_sse);
  87. }
  88. #endif /* HAVE_YASM */
  89. void ff_prefetch_mmxext(uint8_t *buf, ptrdiff_t stride, int h);
  90. void ff_prefetch_3dnow(uint8_t *buf, ptrdiff_t stride, int h);
  91. av_cold void ff_videodsp_init_x86(VideoDSPContext *ctx, int bpc)
  92. {
  93. #if HAVE_YASM
  94. int cpu_flags = av_get_cpu_flags();
  95. #if ARCH_X86_32
  96. if (EXTERNAL_MMX(cpu_flags) && bpc <= 8) {
  97. ctx->emulated_edge_mc = emulated_edge_mc_mmx;
  98. }
  99. if (EXTERNAL_AMD3DNOW(cpu_flags)) {
  100. ctx->prefetch = ff_prefetch_3dnow;
  101. }
  102. #endif /* ARCH_X86_32 */
  103. if (EXTERNAL_MMXEXT(cpu_flags)) {
  104. ctx->prefetch = ff_prefetch_mmxext;
  105. }
  106. if (EXTERNAL_SSE(cpu_flags) && bpc <= 8) {
  107. ctx->emulated_edge_mc = emulated_edge_mc_sse;
  108. }
  109. #endif /* HAVE_YASM */
  110. }