intrinsics.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #ifndef _ASM_IA64_INTRINSICS_H
  2. #define _ASM_IA64_INTRINSICS_H
  3. /*
  4. * Compiler-dependent intrinsics.
  5. *
  6. * Copyright (C) 2002-2003 Hewlett-Packard Co
  7. * David Mosberger-Tang <davidm@hpl.hp.com>
  8. */
  9. #ifndef __ASSEMBLY__
  10. /* include compiler specific intrinsics */
  11. #include <asm/ia64regs.h>
  12. #ifdef __INTEL_COMPILER
  13. # include <asm/intel_intrin.h>
  14. #else
  15. # include <asm/gcc_intrin.h>
  16. #endif
  17. #define ia64_set_rr0_to_rr4(val0, val1, val2, val3, val4) \
  18. do { \
  19. ia64_set_rr(0x0000000000000000UL, (val0)); \
  20. ia64_set_rr(0x2000000000000000UL, (val1)); \
  21. ia64_set_rr(0x4000000000000000UL, (val2)); \
  22. ia64_set_rr(0x6000000000000000UL, (val3)); \
  23. ia64_set_rr(0x8000000000000000UL, (val4)); \
  24. } while (0)
  25. /*
  26. * Force an unresolved reference if someone tries to use
  27. * ia64_fetch_and_add() with a bad value.
  28. */
  29. extern unsigned long __bad_size_for_ia64_fetch_and_add (void);
  30. extern unsigned long __bad_increment_for_ia64_fetch_and_add (void);
  31. #define IA64_FETCHADD(tmp,v,n,sz,sem) \
  32. ({ \
  33. switch (sz) { \
  34. case 4: \
  35. tmp = ia64_fetchadd4_##sem((unsigned int *) v, n); \
  36. break; \
  37. \
  38. case 8: \
  39. tmp = ia64_fetchadd8_##sem((unsigned long *) v, n); \
  40. break; \
  41. \
  42. default: \
  43. __bad_size_for_ia64_fetch_and_add(); \
  44. } \
  45. })
  46. #define ia64_fetchadd(i,v,sem) \
  47. ({ \
  48. __u64 _tmp; \
  49. volatile __typeof__(*(v)) *_v = (v); \
  50. /* Can't use a switch () here: gcc isn't always smart enough for that... */ \
  51. if ((i) == -16) \
  52. IA64_FETCHADD(_tmp, _v, -16, sizeof(*(v)), sem); \
  53. else if ((i) == -8) \
  54. IA64_FETCHADD(_tmp, _v, -8, sizeof(*(v)), sem); \
  55. else if ((i) == -4) \
  56. IA64_FETCHADD(_tmp, _v, -4, sizeof(*(v)), sem); \
  57. else if ((i) == -1) \
  58. IA64_FETCHADD(_tmp, _v, -1, sizeof(*(v)), sem); \
  59. else if ((i) == 1) \
  60. IA64_FETCHADD(_tmp, _v, 1, sizeof(*(v)), sem); \
  61. else if ((i) == 4) \
  62. IA64_FETCHADD(_tmp, _v, 4, sizeof(*(v)), sem); \
  63. else if ((i) == 8) \
  64. IA64_FETCHADD(_tmp, _v, 8, sizeof(*(v)), sem); \
  65. else if ((i) == 16) \
  66. IA64_FETCHADD(_tmp, _v, 16, sizeof(*(v)), sem); \
  67. else \
  68. _tmp = __bad_increment_for_ia64_fetch_and_add(); \
  69. (__typeof__(*(v))) (_tmp); /* return old value */ \
  70. })
  71. #define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
  72. /*
  73. * This function doesn't exist, so you'll get a linker error if
  74. * something tries to do an invalid xchg().
  75. */
  76. extern void ia64_xchg_called_with_bad_pointer (void);
  77. #define __xchg(x,ptr,size) \
  78. ({ \
  79. unsigned long __xchg_result; \
  80. \
  81. switch (size) { \
  82. case 1: \
  83. __xchg_result = ia64_xchg1((__u8 *)ptr, x); \
  84. break; \
  85. \
  86. case 2: \
  87. __xchg_result = ia64_xchg2((__u16 *)ptr, x); \
  88. break; \
  89. \
  90. case 4: \
  91. __xchg_result = ia64_xchg4((__u32 *)ptr, x); \
  92. break; \
  93. \
  94. case 8: \
  95. __xchg_result = ia64_xchg8((__u64 *)ptr, x); \
  96. break; \
  97. default: \
  98. ia64_xchg_called_with_bad_pointer(); \
  99. } \
  100. __xchg_result; \
  101. })
  102. #define xchg(ptr,x) \
  103. ((__typeof__(*(ptr))) __xchg ((unsigned long) (x), (ptr), sizeof(*(ptr))))
  104. /*
  105. * Atomic compare and exchange. Compare OLD with MEM, if identical,
  106. * store NEW in MEM. Return the initial value in MEM. Success is
  107. * indicated by comparing RETURN with OLD.
  108. */
  109. #define __HAVE_ARCH_CMPXCHG 1
  110. /*
  111. * This function doesn't exist, so you'll get a linker error
  112. * if something tries to do an invalid cmpxchg().
  113. */
  114. extern long ia64_cmpxchg_called_with_bad_pointer (void);
  115. #define ia64_cmpxchg(sem,ptr,old,new,size) \
  116. ({ \
  117. __u64 _o_, _r_; \
  118. \
  119. switch (size) { \
  120. case 1: _o_ = (__u8 ) (long) (old); break; \
  121. case 2: _o_ = (__u16) (long) (old); break; \
  122. case 4: _o_ = (__u32) (long) (old); break; \
  123. case 8: _o_ = (__u64) (long) (old); break; \
  124. default: break; \
  125. } \
  126. switch (size) { \
  127. case 1: \
  128. _r_ = ia64_cmpxchg1_##sem((__u8 *) ptr, new, _o_); \
  129. break; \
  130. \
  131. case 2: \
  132. _r_ = ia64_cmpxchg2_##sem((__u16 *) ptr, new, _o_); \
  133. break; \
  134. \
  135. case 4: \
  136. _r_ = ia64_cmpxchg4_##sem((__u32 *) ptr, new, _o_); \
  137. break; \
  138. \
  139. case 8: \
  140. _r_ = ia64_cmpxchg8_##sem((__u64 *) ptr, new, _o_); \
  141. break; \
  142. \
  143. default: \
  144. _r_ = ia64_cmpxchg_called_with_bad_pointer(); \
  145. break; \
  146. } \
  147. (__typeof__(old)) _r_; \
  148. })
  149. #define cmpxchg_acq(ptr, o, n) \
  150. ia64_cmpxchg(acq, (ptr), (o), (n), sizeof(*(ptr)))
  151. #define cmpxchg_rel(ptr, o, n) \
  152. ia64_cmpxchg(rel, (ptr), (o), (n), sizeof(*(ptr)))
  153. /* for compatibility with other platforms: */
  154. #define cmpxchg(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
  155. #define cmpxchg64(ptr, o, n) cmpxchg_acq((ptr), (o), (n))
  156. #define cmpxchg_local cmpxchg
  157. #define cmpxchg64_local cmpxchg64
  158. #ifdef CONFIG_IA64_DEBUG_CMPXCHG
  159. # define CMPXCHG_BUGCHECK_DECL int _cmpxchg_bugcheck_count = 128;
  160. # define CMPXCHG_BUGCHECK(v) \
  161. do { \
  162. if (_cmpxchg_bugcheck_count-- <= 0) { \
  163. void *ip; \
  164. extern int printk(const char *fmt, ...); \
  165. ip = (void *) ia64_getreg(_IA64_REG_IP); \
  166. printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v)); \
  167. break; \
  168. } \
  169. } while (0)
  170. #else /* !CONFIG_IA64_DEBUG_CMPXCHG */
  171. # define CMPXCHG_BUGCHECK_DECL
  172. # define CMPXCHG_BUGCHECK(v)
  173. #endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
  174. #endif
  175. #endif /* _ASM_IA64_INTRINSICS_H */