intrinsics.h 5.2 KB

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