fastmemcpy.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This file is part of MPlayer.
  3. *
  4. * MPlayer 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. * MPlayer 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 MPlayer; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef MPLAYER_FASTMEMCPY_H
  19. #define MPLAYER_FASTMEMCPY_H
  20. #include <inttypes.h>
  21. #include <string.h>
  22. #include <stddef.h>
  23. void * fast_memcpy(void * to, const void * from, size_t len);
  24. void * mem2agpcpy(void * to, const void * from, size_t len);
  25. #if ! defined(CONFIG_FASTMEMCPY) || ! (HAVE_MMX || HAVE_MMX2 || HAVE_AMD3DNOW /* || HAVE_SSE || HAVE_SSE2 */)
  26. #define mem2agpcpy(a,b,c) memcpy(a,b,c)
  27. #define fast_memcpy(a,b,c) memcpy(a,b,c)
  28. #endif
  29. static inline void * mem2agpcpy_pic(void * dst, const void * src, int bytesPerLine, int height, int dstStride, int srcStride)
  30. {
  31. int i;
  32. void *retval=dst;
  33. if(dstStride == srcStride)
  34. {
  35. if (srcStride < 0) {
  36. src = (const uint8_t*)src + (height-1)*srcStride;
  37. dst = (uint8_t*)dst + (height-1)*dstStride;
  38. srcStride = -srcStride;
  39. }
  40. mem2agpcpy(dst, src, srcStride*height);
  41. }
  42. else
  43. {
  44. for(i=0; i<height; i++)
  45. {
  46. mem2agpcpy(dst, src, bytesPerLine);
  47. src = (const uint8_t*)src + srcStride;
  48. dst = (uint8_t*)dst + dstStride;
  49. }
  50. }
  51. return retval;
  52. }
  53. #define memcpy_pic(d, s, b, h, ds, ss) memcpy_pic2(d, s, b, h, ds, ss, 0)
  54. #define my_memcpy_pic(d, s, b, h, ds, ss) memcpy_pic2(d, s, b, h, ds, ss, 1)
  55. /**
  56. * \param limit2width always skip data between end of line and start of next
  57. * instead of copying the full block when strides are the same
  58. */
  59. static inline void * memcpy_pic2(void * dst, const void * src,
  60. int bytesPerLine, int height,
  61. int dstStride, int srcStride, int limit2width)
  62. {
  63. int i;
  64. void *retval=dst;
  65. if(!limit2width && dstStride == srcStride)
  66. {
  67. if (srcStride < 0) {
  68. src = (const uint8_t*)src + (height-1)*srcStride;
  69. dst = (uint8_t*)dst + (height-1)*dstStride;
  70. srcStride = -srcStride;
  71. }
  72. fast_memcpy(dst, src, srcStride*height);
  73. }
  74. else
  75. {
  76. for(i=0; i<height; i++)
  77. {
  78. fast_memcpy(dst, src, bytesPerLine);
  79. src = (const uint8_t*)src + srcStride;
  80. dst = (uint8_t*)dst + dstStride;
  81. }
  82. }
  83. return retval;
  84. }
  85. #endif /* MPLAYER_FASTMEMCPY_H */