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.

86 lines
2.4KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; 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. #ifdef __thumb__
  30. __asm__ ("ldrh %0, %1" : "=r"(v) : "m"(q[0]), "m"(q[1]));
  31. #else
  32. __asm__ ("ldrh %0, %1" : "=r"(v) : "Uq"(q[0]), "m"(q[1]));
  33. #endif
  34. return v;
  35. }
  36. #define AV_WN16 AV_WN16
  37. static av_always_inline void AV_WN16(void *p, uint16_t v)
  38. {
  39. __asm__ ("strh %1, %0" : "=m"(*(uint16_t *)p) : "r"(v));
  40. }
  41. #define AV_RN32 AV_RN32
  42. static av_always_inline uint32_t AV_RN32(const void *p)
  43. {
  44. const struct __attribute__((packed)) { uint32_t v; } *q = p;
  45. uint32_t v;
  46. __asm__ ("ldr %0, %1" : "=r"(v) : "m"(*q));
  47. return v;
  48. }
  49. #define AV_WN32 AV_WN32
  50. static av_always_inline void AV_WN32(void *p, uint32_t v)
  51. {
  52. __asm__ ("str %1, %0" : "=m"(*(uint32_t *)p) : "r"(v));
  53. }
  54. #define AV_RN64 AV_RN64
  55. static av_always_inline uint64_t AV_RN64(const void *p)
  56. {
  57. const struct __attribute__((packed)) { uint32_t v; } *q = p;
  58. uint64_t v;
  59. __asm__ ("ldr %Q0, %1 \n\t"
  60. "ldr %R0, %2 \n\t"
  61. : "=&r"(v)
  62. : "m"(q[0]), "m"(q[1]));
  63. return v;
  64. }
  65. #define AV_WN64 AV_WN64
  66. static av_always_inline void AV_WN64(void *p, uint64_t v)
  67. {
  68. __asm__ ("str %Q2, %0 \n\t"
  69. "str %R2, %1 \n\t"
  70. : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1))
  71. : "r"(v));
  72. }
  73. #endif /* HAVE_INLINE_ASM */
  74. #endif /* AVUTIL_ARM_INTREADWRITE_H */