intreadwrite.h 4.6 KB

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