intreadwrite.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_ARM_INTREADWRITE_H
  19. #define AVUTIL_ARM_INTREADWRITE_H
  20. #include <stdint.h>
  21. #include "config.h"
  22. #if HAVE_FAST_UNALIGNED && HAVE_INLINE_ASM
  23. #define AV_RN16 AV_RN16
  24. static av_always_inline unsigned AV_RN16(const void *p)
  25. {
  26. unsigned v;
  27. __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(*(const uint16_t *)p));
  28. return v;
  29. }
  30. #define AV_WN16 AV_WN16
  31. static av_always_inline void AV_WN16(void *p, uint16_t v)
  32. {
  33. __asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v));
  34. }
  35. #define AV_RN32 AV_RN32
  36. static av_always_inline uint32_t AV_RN32(const void *p)
  37. {
  38. uint32_t v;
  39. __asm__ ("ldr %0, %1" : "=r"(v) : "m"(*(const uint32_t *)p));
  40. return v;
  41. }
  42. #define AV_WN32 AV_WN32
  43. static av_always_inline void AV_WN32(void *p, uint32_t v)
  44. {
  45. __asm__ ("str %1, %0" : "=m"(*(uint32_t *)p) : "r"(v));
  46. }
  47. #define AV_RN64 AV_RN64
  48. static av_always_inline uint64_t AV_RN64(const void *p)
  49. {
  50. uint64_t v;
  51. __asm__ ("ldr %Q0, %1 \n\t"
  52. "ldr %R0, %2 \n\t"
  53. : "=&r"(v)
  54. : "m"(*(const uint32_t*)p), "m"(*((const uint32_t*)p+1)));
  55. return v;
  56. }
  57. #define AV_WN64 AV_WN64
  58. static av_always_inline void AV_WN64(void *p, uint64_t v)
  59. {
  60. __asm__ ("str %Q2, %0 \n\t"
  61. "str %R2, %1 \n\t"
  62. : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
  63. : "r"(v));
  64. }
  65. #endif /* HAVE_INLINE_ASM */
  66. #endif /* AVUTIL_ARM_INTREADWRITE_H */