intreadwrite.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #include "libavutil/attributes.h"
  23. #if HAVE_FAST_UNALIGNED && HAVE_INLINE_ASM && !AV_GCC_VERSION_AT_LEAST(4,7)
  24. #define AV_RN16 AV_RN16
  25. static av_always_inline unsigned AV_RN16(const void *p)
  26. {
  27. const uint8_t *q = p;
  28. unsigned v;
  29. #if !AV_GCC_VERSION_AT_LEAST(4,6)
  30. __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(*(const uint16_t *)q));
  31. #elif defined __thumb__
  32. __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(q[0]), "m"(q[1]));
  33. #else
  34. __asm__ ("ldrh %0, %1" : "=r"(v) : "Uq"(q[0]), "m"(q[1]));
  35. #endif
  36. return v;
  37. }
  38. #define AV_WN16 AV_WN16
  39. static av_always_inline void AV_WN16(void *p, uint16_t v)
  40. {
  41. __asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v));
  42. }
  43. #define AV_RN32 AV_RN32
  44. static av_always_inline uint32_t AV_RN32(const void *p)
  45. {
  46. const struct __attribute__((packed)) { uint32_t v; } *q = p;
  47. uint32_t v;
  48. __asm__ ("ldr %0, %1" : "=r"(v) : "m"(*q));
  49. return v;
  50. }
  51. #define AV_WN32 AV_WN32
  52. static av_always_inline void AV_WN32(void *p, uint32_t v)
  53. {
  54. __asm__ ("str %1, %0" : "=m"(*(uint32_t *)p) : "r"(v));
  55. }
  56. #if HAVE_ASM_MOD_Q
  57. #define AV_RN64 AV_RN64
  58. static av_always_inline uint64_t AV_RN64(const void *p)
  59. {
  60. const struct __attribute__((packed)) { uint32_t v; } *q = p;
  61. uint64_t v;
  62. __asm__ ("ldr %Q0, %1 \n\t"
  63. "ldr %R0, %2 \n\t"
  64. : "=&r"(v)
  65. : "m"(q[0]), "m"(q[1]));
  66. return v;
  67. }
  68. #define AV_WN64 AV_WN64
  69. static av_always_inline void AV_WN64(void *p, uint64_t v)
  70. {
  71. __asm__ ("str %Q2, %0 \n\t"
  72. "str %R2, %1 \n\t"
  73. : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
  74. : "r"(v));
  75. }
  76. #endif /* HAVE_ASM_MOD_Q */
  77. #endif /* HAVE_INLINE_ASM */
  78. #endif /* AVUTIL_ARM_INTREADWRITE_H */