intreadwrite.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2010 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_TOMI_INTREADWRITE_H
  21. #define AVUTIL_TOMI_INTREADWRITE_H
  22. #include <stdint.h>
  23. #include "config.h"
  24. #include "libavutil/attributes.h"
  25. #define AV_RB16 AV_RB16
  26. static av_always_inline uint16_t AV_RB16(const void *p)
  27. {
  28. uint16_t v;
  29. __asm__ ("loadacc, (%1+) \n\t"
  30. "rol8 \n\t"
  31. "storeacc, %0 \n\t"
  32. "loadacc, (%1+) \n\t"
  33. "add, %0 \n\t"
  34. : "=r"(v), "+a"(p));
  35. return v;
  36. }
  37. #define AV_WB16 AV_WB16
  38. static av_always_inline void AV_WB16(void *p, uint16_t v)
  39. {
  40. __asm__ volatile ("loadacc, %1 \n\t"
  41. "lsr8 \n\t"
  42. "storeacc, (%0+) \n\t"
  43. "loadacc, %1 \n\t"
  44. "storeacc, (%0+) \n\t"
  45. : "+&a"(p) : "r"(v));
  46. }
  47. #define AV_RL16 AV_RL16
  48. static av_always_inline uint16_t AV_RL16(const void *p)
  49. {
  50. uint16_t v;
  51. __asm__ ("loadacc, (%1+) \n\t"
  52. "storeacc, %0 \n\t"
  53. "loadacc, (%1+) \n\t"
  54. "rol8 \n\t"
  55. "add, %0 \n\t"
  56. : "=r"(v), "+a"(p));
  57. return v;
  58. }
  59. #define AV_WL16 AV_WL16
  60. static av_always_inline void AV_WL16(void *p, uint16_t v)
  61. {
  62. __asm__ volatile ("loadacc, %1 \n\t"
  63. "storeacc, (%0+) \n\t"
  64. "lsr8 \n\t"
  65. "storeacc, (%0+) \n\t"
  66. : "+&a"(p) : "r"(v));
  67. }
  68. #define AV_RB32 AV_RB32
  69. static av_always_inline uint32_t AV_RB32(const void *p)
  70. {
  71. uint32_t v;
  72. __asm__ ("loadacc, (%1+) \n\t"
  73. "rol8 \n\t"
  74. "rol8 \n\t"
  75. "rol8 \n\t"
  76. "storeacc, %0 \n\t"
  77. "loadacc, (%1+) \n\t"
  78. "rol8 \n\t"
  79. "rol8 \n\t"
  80. "add, %0 \n\t"
  81. "loadacc, (%1+) \n\t"
  82. "rol8 \n\t"
  83. "add, %0 \n\t"
  84. "loadacc, (%1+) \n\t"
  85. "add, %0 \n\t"
  86. : "=r"(v), "+a"(p));
  87. return v;
  88. }
  89. #define AV_WB32 AV_WB32
  90. static av_always_inline void AV_WB32(void *p, uint32_t v)
  91. {
  92. __asm__ volatile ("loadacc, #4 \n\t"
  93. "add, %0 \n\t"
  94. "loadacc, %1 \n\t"
  95. "storeacc, (-%0) \n\t"
  96. "lsr8 \n\t"
  97. "storeacc, (-%0) \n\t"
  98. "lsr8 \n\t"
  99. "storeacc, (-%0) \n\t"
  100. "lsr8 \n\t"
  101. "storeacc, (-%0) \n\t"
  102. : "+&a"(p) : "r"(v));
  103. }
  104. #define AV_RL32 AV_RL32
  105. static av_always_inline uint32_t AV_RL32(const void *p)
  106. {
  107. uint32_t v;
  108. __asm__ ("loadacc, (%1+) \n\t"
  109. "storeacc, %0 \n\t"
  110. "loadacc, (%1+) \n\t"
  111. "rol8 \n\t"
  112. "add, %0 \n\t"
  113. "loadacc, (%1+) \n\t"
  114. "rol8 \n\t"
  115. "rol8 \n\t"
  116. "add, %0 \n\t"
  117. "loadacc, (%1+) \n\t"
  118. "rol8 \n\t"
  119. "rol8 \n\t"
  120. "rol8 \n\t"
  121. "add, %0 \n\t"
  122. : "=r"(v), "+a"(p));
  123. return v;
  124. }
  125. #define AV_WL32 AV_WL32
  126. static av_always_inline void AV_WL32(void *p, uint32_t v)
  127. {
  128. __asm__ volatile ("loadacc, %1 \n\t"
  129. "storeacc, (%0+) \n\t"
  130. "lsr8 \n\t"
  131. "storeacc, (%0+) \n\t"
  132. "lsr8 \n\t"
  133. "storeacc, (%0+) \n\t"
  134. "lsr8 \n\t"
  135. "storeacc, (%0+) \n\t"
  136. : "+&a"(p) : "r"(v));
  137. }
  138. #endif /* AVUTIL_TOMI_INTREADWRITE_H */