asm.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Alpha optimized DSP utils
  3. * Copyright (c) 2002 Falk Hueffner <falk@debian.org>
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVCODEC_ALPHA_ASM_H
  22. #define AVCODEC_ALPHA_ASM_H
  23. #include <inttypes.h>
  24. #if defined __GNUC__
  25. # define GNUC_PREREQ(maj, min) \
  26. ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
  27. #else
  28. # define GNUC_PREREQ(maj, min) 0
  29. #endif
  30. #if GNUC_PREREQ(2,96)
  31. # define likely(x) __builtin_expect((x) != 0, 1)
  32. # define unlikely(x) __builtin_expect((x) != 0, 0)
  33. #else
  34. # define likely(x) (x)
  35. # define unlikely(x) (x)
  36. #endif
  37. #define AMASK_BWX (1 << 0)
  38. #define AMASK_FIX (1 << 1)
  39. #define AMASK_CIX (1 << 2)
  40. #define AMASK_MVI (1 << 8)
  41. static inline uint64_t BYTE_VEC(uint64_t x)
  42. {
  43. x |= x << 8;
  44. x |= x << 16;
  45. x |= x << 32;
  46. return x;
  47. }
  48. static inline uint64_t WORD_VEC(uint64_t x)
  49. {
  50. x |= x << 16;
  51. x |= x << 32;
  52. return x;
  53. }
  54. #define sextw(x) ((int16_t) (x))
  55. #ifdef __GNUC__
  56. #define ldq(p) \
  57. (((const union { \
  58. uint64_t __l; \
  59. __typeof__(*(p)) __s[sizeof (uint64_t) / sizeof *(p)]; \
  60. } *) (p))->__l)
  61. #define ldl(p) \
  62. (((const union { \
  63. int32_t __l; \
  64. __typeof__(*(p)) __s[sizeof (int32_t) / sizeof *(p)]; \
  65. } *) (p))->__l)
  66. #define stq(l, p) \
  67. do { \
  68. (((union { \
  69. uint64_t __l; \
  70. __typeof__(*(p)) __s[sizeof (uint64_t) / sizeof *(p)]; \
  71. } *) (p))->__l) = l; \
  72. } while (0)
  73. #define stl(l, p) \
  74. do { \
  75. (((union { \
  76. int32_t __l; \
  77. __typeof__(*(p)) __s[sizeof (int32_t) / sizeof *(p)]; \
  78. } *) (p))->__l) = l; \
  79. } while (0)
  80. struct unaligned_long { uint64_t l; } __attribute__((packed));
  81. #define ldq_u(p) (*(const uint64_t *) (((uint64_t) (p)) & ~7ul))
  82. #define uldq(a) (((const struct unaligned_long *) (a))->l)
  83. #if GNUC_PREREQ(3,3)
  84. #define prefetch(p) __builtin_prefetch((p), 0, 1)
  85. #define prefetch_en(p) __builtin_prefetch((p), 0, 0)
  86. #define prefetch_m(p) __builtin_prefetch((p), 1, 1)
  87. #define prefetch_men(p) __builtin_prefetch((p), 1, 0)
  88. #define cmpbge __builtin_alpha_cmpbge
  89. /* Avoid warnings. */
  90. #define extql(a, b) __builtin_alpha_extql(a, (uint64_t) (b))
  91. #define extwl(a, b) __builtin_alpha_extwl(a, (uint64_t) (b))
  92. #define extqh(a, b) __builtin_alpha_extqh(a, (uint64_t) (b))
  93. #define zap __builtin_alpha_zap
  94. #define zapnot __builtin_alpha_zapnot
  95. #define amask __builtin_alpha_amask
  96. #define implver __builtin_alpha_implver
  97. #define rpcc __builtin_alpha_rpcc
  98. #else
  99. #define prefetch(p) __asm__ volatile("ldl $31,%0" : : "m"(*(const char *) (p)) : "memory")
  100. #define prefetch_en(p) __asm__ volatile("ldq $31,%0" : : "m"(*(const char *) (p)) : "memory")
  101. #define prefetch_m(p) __asm__ volatile("lds $f31,%0" : : "m"(*(const char *) (p)) : "memory")
  102. #define prefetch_men(p) __asm__ volatile("ldt $f31,%0" : : "m"(*(const char *) (p)) : "memory")
  103. #define cmpbge(a, b) ({ uint64_t __r; __asm__ ("cmpbge %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; })
  104. #define extql(a, b) ({ uint64_t __r; __asm__ ("extql %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; })
  105. #define extwl(a, b) ({ uint64_t __r; __asm__ ("extwl %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; })
  106. #define extqh(a, b) ({ uint64_t __r; __asm__ ("extqh %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; })
  107. #define zap(a, b) ({ uint64_t __r; __asm__ ("zap %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; })
  108. #define zapnot(a, b) ({ uint64_t __r; __asm__ ("zapnot %r1,%2,%0" : "=r" (__r) : "rJ" (a), "rI" (b)); __r; })
  109. #define amask(a) ({ uint64_t __r; __asm__ ("amask %1,%0" : "=r" (__r) : "rI" (a)); __r; })
  110. #define implver() ({ uint64_t __r; __asm__ ("implver %0" : "=r" (__r)); __r; })
  111. #define rpcc() ({ uint64_t __r; __asm__ volatile ("rpcc %0" : "=r" (__r)); __r; })
  112. #endif
  113. #define wh64(p) __asm__ volatile("wh64 (%0)" : : "r"(p) : "memory")
  114. #if GNUC_PREREQ(3,3) && defined(__alpha_max__)
  115. #define minub8 __builtin_alpha_minub8
  116. #define minsb8 __builtin_alpha_minsb8
  117. #define minuw4 __builtin_alpha_minuw4
  118. #define minsw4 __builtin_alpha_minsw4
  119. #define maxub8 __builtin_alpha_maxub8
  120. #define maxsb8 __builtin_alpha_maxsb8
  121. #define maxuw4 __builtin_alpha_maxuw4
  122. #define maxsw4 __builtin_alpha_maxsw4
  123. #define perr __builtin_alpha_perr
  124. #define pklb __builtin_alpha_pklb
  125. #define pkwb __builtin_alpha_pkwb
  126. #define unpkbl __builtin_alpha_unpkbl
  127. #define unpkbw __builtin_alpha_unpkbw
  128. #else
  129. #define minub8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minub8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  130. #define minsb8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minsb8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  131. #define minuw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minuw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  132. #define minsw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; minsw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  133. #define maxub8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxub8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  134. #define maxsb8(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxsb8 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  135. #define maxuw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxuw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  136. #define maxsw4(a, b) ({ uint64_t __r; __asm__ (".arch ev6; maxsw4 %r1,%2,%0" : "=r" (__r) : "%rJ" (a), "rI" (b)); __r; })
  137. #define perr(a, b) ({ uint64_t __r; __asm__ (".arch ev6; perr %r1,%r2,%0" : "=r" (__r) : "%rJ" (a), "rJ" (b)); __r; })
  138. #define pklb(a) ({ uint64_t __r; __asm__ (".arch ev6; pklb %r1,%0" : "=r" (__r) : "rJ" (a)); __r; })
  139. #define pkwb(a) ({ uint64_t __r; __asm__ (".arch ev6; pkwb %r1,%0" : "=r" (__r) : "rJ" (a)); __r; })
  140. #define unpkbl(a) ({ uint64_t __r; __asm__ (".arch ev6; unpkbl %r1,%0" : "=r" (__r) : "rJ" (a)); __r; })
  141. #define unpkbw(a) ({ uint64_t __r; __asm__ (".arch ev6; unpkbw %r1,%0" : "=r" (__r) : "rJ" (a)); __r; })
  142. #endif
  143. #elif defined(__DECC) /* Digital/Compaq/hp "ccc" compiler */
  144. #include <c_asm.h>
  145. #define ldq(p) (*(const uint64_t *) (p))
  146. #define ldl(p) (*(const int32_t *) (p))
  147. #define stq(l, p) do { *(uint64_t *) (p) = (l); } while (0)
  148. #define stl(l, p) do { *(int32_t *) (p) = (l); } while (0)
  149. #define ldq_u(a) asm ("ldq_u %v0,0(%a0)", a)
  150. #define uldq(a) (*(const __unaligned uint64_t *) (a))
  151. #define cmpbge(a, b) asm ("cmpbge %a0,%a1,%v0", a, b)
  152. #define extql(a, b) asm ("extql %a0,%a1,%v0", a, b)
  153. #define extwl(a, b) asm ("extwl %a0,%a1,%v0", a, b)
  154. #define extqh(a, b) asm ("extqh %a0,%a1,%v0", a, b)
  155. #define zap(a, b) asm ("zap %a0,%a1,%v0", a, b)
  156. #define zapnot(a, b) asm ("zapnot %a0,%a1,%v0", a, b)
  157. #define amask(a) asm ("amask %a0,%v0", a)
  158. #define implver() asm ("implver %v0")
  159. #define rpcc() asm ("rpcc %v0")
  160. #define minub8(a, b) asm ("minub8 %a0,%a1,%v0", a, b)
  161. #define minsb8(a, b) asm ("minsb8 %a0,%a1,%v0", a, b)
  162. #define minuw4(a, b) asm ("minuw4 %a0,%a1,%v0", a, b)
  163. #define minsw4(a, b) asm ("minsw4 %a0,%a1,%v0", a, b)
  164. #define maxub8(a, b) asm ("maxub8 %a0,%a1,%v0", a, b)
  165. #define maxsb8(a, b) asm ("maxsb8 %a0,%a1,%v0", a, b)
  166. #define maxuw4(a, b) asm ("maxuw4 %a0,%a1,%v0", a, b)
  167. #define maxsw4(a, b) asm ("maxsw4 %a0,%a1,%v0", a, b)
  168. #define perr(a, b) asm ("perr %a0,%a1,%v0", a, b)
  169. #define pklb(a) asm ("pklb %a0,%v0", a)
  170. #define pkwb(a) asm ("pkwb %a0,%v0", a)
  171. #define unpkbl(a) asm ("unpkbl %a0,%v0", a)
  172. #define unpkbw(a) asm ("unpkbw %a0,%v0", a)
  173. #define wh64(a) asm ("wh64 %a0", a)
  174. #else
  175. #error "Unknown compiler!"
  176. #endif
  177. #endif /* AVCODEC_ALPHA_ASM_H */