intrinsics.h 5.2 KB

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