intreadwrite.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef AVUTIL_PPC_INTREADWRITE_H
  21. #define AVUTIL_PPC_INTREADWRITE_H
  22. #include <stdint.h>
  23. #include "config.h"
  24. #if HAVE_XFORM_ASM
  25. #if HAVE_BIGENDIAN
  26. #define AV_RL16 AV_RX16
  27. #define AV_WL16 AV_WX16
  28. #define AV_RL32 AV_RX32
  29. #define AV_WL32 AV_WX32
  30. #else
  31. #define AV_RB16 AV_RX16
  32. #define AV_WB16 AV_WX16
  33. #define AV_RB32 AV_RX32
  34. #define AV_WB32 AV_WX32
  35. #endif
  36. static av_always_inline uint16_t AV_RX16(const void *p)
  37. {
  38. uint16_t v;
  39. __asm__ ("lhbrx %0, %y1" : "=r"(v) : "Z"(*(const uint16_t*)p));
  40. return v;
  41. }
  42. static av_always_inline void AV_WX16(void *p, uint16_t v)
  43. {
  44. __asm__ ("sthbrx %1, %y0" : "=Z"(*(uint16_t*)p) : "r"(v));
  45. }
  46. static av_always_inline uint32_t AV_RX32(const void *p)
  47. {
  48. uint32_t v;
  49. __asm__ ("lwbrx %0, %y1" : "=r"(v) : "Z"(*(const uint32_t*)p));
  50. return v;
  51. }
  52. static av_always_inline void AV_WX32(void *p, uint32_t v)
  53. {
  54. __asm__ ("stwbrx %1, %y0" : "=Z"(*(uint32_t*)p) : "r"(v));
  55. }
  56. #if HAVE_LDBRX
  57. #if HAVE_BIGENDIAN
  58. #define AV_RL64 AV_RX64
  59. #define AV_WL64 AV_WX64
  60. #else
  61. #define AV_RB64 AV_RX64
  62. #define AV_WB64 AV_WX64
  63. #endif
  64. static av_always_inline uint64_t AV_RX64(const void *p)
  65. {
  66. uint64_t v;
  67. __asm__ ("ldbrx %0, %y1" : "=r"(v) : "Z"(*(const uint64_t*)p));
  68. return v;
  69. }
  70. static av_always_inline void AV_WX64(void *p, uint64_t v)
  71. {
  72. __asm__ ("stdbrx %1, %y0" : "=Z"(*(uint64_t*)p) : "r"(v));
  73. }
  74. #else
  75. #define AV_RL64 AV_RL64
  76. static av_always_inline uint64_t AV_RL64(const void *p)
  77. {
  78. union { uint64_t v; uint32_t hl[2]; } v;
  79. __asm__ ("lwbrx %0, %y2 \n\t"
  80. "lwbrx %1, %y3 \n\t"
  81. : "=&r"(v.hl[1]), "=r"(v.hl[0])
  82. : "Z"(*(const uint32_t*)p), "Z"(*((const uint32_t*)p+1)));
  83. return v.v;
  84. }
  85. #define AV_WL64 AV_WL64
  86. static av_always_inline void AV_WL64(void *p, uint64_t v)
  87. {
  88. union { uint64_t v; uint32_t hl[2]; } vv = { v };
  89. __asm__ ("stwbrx %2, %y0 \n\t"
  90. "stwbrx %3, %y1 \n\t"
  91. : "=Z"(*(uint32_t*)p), "=Z"(*((uint32_t*)p+1))
  92. : "r"(vv.hl[1]), "r"(vv.hl[0]));
  93. }
  94. #endif /* HAVE_LDBRX */
  95. #endif /* HAVE_XFORM_ASM */
  96. /*
  97. * GCC fails miserably on the packed struct version which is used by
  98. * default, so we override it here.
  99. */
  100. #if HAVE_BIGENDIAN
  101. #define AV_RB64(p) (*(const uint64_t *)(p))
  102. #define AV_WB64(p, v) (*(uint64_t *)(p) = (v))
  103. #endif
  104. #endif /* AVUTIL_PPC_INTREADWRITE_H */