intrinsics.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Compiler-dependent intrinsics.
  3. *
  4. * Copyright (C) 2002-2003 Hewlett-Packard Co
  5. * David Mosberger-Tang <davidm@hpl.hp.com>
  6. */
  7. #ifndef _UAPI_ASM_IA64_INTRINSICS_H
  8. #define _UAPI_ASM_IA64_INTRINSICS_H
  9. #ifndef __ASSEMBLY__
  10. #include <linux/types.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. #include <asm/cmpxchg.h>
  19. #define ia64_native_get_psr_i() (ia64_native_getreg(_IA64_REG_PSR) & IA64_PSR_I)
  20. #define ia64_native_set_rr0_to_rr4(val0, val1, val2, val3, val4) \
  21. do { \
  22. ia64_native_set_rr(0x0000000000000000UL, (val0)); \
  23. ia64_native_set_rr(0x2000000000000000UL, (val1)); \
  24. ia64_native_set_rr(0x4000000000000000UL, (val2)); \
  25. ia64_native_set_rr(0x6000000000000000UL, (val3)); \
  26. ia64_native_set_rr(0x8000000000000000UL, (val4)); \
  27. } while (0)
  28. /*
  29. * Force an unresolved reference if someone tries to use
  30. * ia64_fetch_and_add() with a bad value.
  31. */
  32. extern unsigned long __bad_size_for_ia64_fetch_and_add (void);
  33. extern unsigned long __bad_increment_for_ia64_fetch_and_add (void);
  34. #define IA64_FETCHADD(tmp,v,n,sz,sem) \
  35. ({ \
  36. switch (sz) { \
  37. case 4: \
  38. tmp = ia64_fetchadd4_##sem((unsigned int *) v, n); \
  39. break; \
  40. \
  41. case 8: \
  42. tmp = ia64_fetchadd8_##sem((unsigned long *) v, n); \
  43. break; \
  44. \
  45. default: \
  46. __bad_size_for_ia64_fetch_and_add(); \
  47. } \
  48. })
  49. #define ia64_fetchadd(i,v,sem) \
  50. ({ \
  51. __u64 _tmp; \
  52. volatile __typeof__(*(v)) *_v = (v); \
  53. /* Can't use a switch () here: gcc isn't always smart enough for that... */ \
  54. if ((i) == -16) \
  55. IA64_FETCHADD(_tmp, _v, -16, sizeof(*(v)), sem); \
  56. else if ((i) == -8) \
  57. IA64_FETCHADD(_tmp, _v, -8, sizeof(*(v)), sem); \
  58. else if ((i) == -4) \
  59. IA64_FETCHADD(_tmp, _v, -4, sizeof(*(v)), sem); \
  60. else if ((i) == -1) \
  61. IA64_FETCHADD(_tmp, _v, -1, sizeof(*(v)), sem); \
  62. else if ((i) == 1) \
  63. IA64_FETCHADD(_tmp, _v, 1, sizeof(*(v)), sem); \
  64. else if ((i) == 4) \
  65. IA64_FETCHADD(_tmp, _v, 4, sizeof(*(v)), sem); \
  66. else if ((i) == 8) \
  67. IA64_FETCHADD(_tmp, _v, 8, sizeof(*(v)), sem); \
  68. else if ((i) == 16) \
  69. IA64_FETCHADD(_tmp, _v, 16, sizeof(*(v)), sem); \
  70. else \
  71. _tmp = __bad_increment_for_ia64_fetch_and_add(); \
  72. (__typeof__(*(v))) (_tmp); /* return old value */ \
  73. })
  74. #define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
  75. #endif
  76. #ifndef __ASSEMBLY__
  77. #define IA64_INTRINSIC_API(name) ia64_native_ ## name
  78. #define IA64_INTRINSIC_MACRO(name) ia64_native_ ## name
  79. /************************************************/
  80. /* Instructions paravirtualized for correctness */
  81. /************************************************/
  82. /* fc, thash, get_cpuid, get_pmd, get_eflags, set_eflags */
  83. /* Note that "ttag" and "cover" are also privilege-sensitive; "ttag"
  84. * is not currently used (though it may be in a long-format VHPT system!)
  85. */
  86. #define ia64_fc IA64_INTRINSIC_API(fc)
  87. #define ia64_thash IA64_INTRINSIC_API(thash)
  88. #define ia64_get_cpuid IA64_INTRINSIC_API(get_cpuid)
  89. #define ia64_get_pmd IA64_INTRINSIC_API(get_pmd)
  90. /************************************************/
  91. /* Instructions paravirtualized for performance */
  92. /************************************************/
  93. #define ia64_ssm IA64_INTRINSIC_MACRO(ssm)
  94. #define ia64_rsm IA64_INTRINSIC_MACRO(rsm)
  95. #define ia64_getreg IA64_INTRINSIC_MACRO(getreg)
  96. #define ia64_setreg IA64_INTRINSIC_API(setreg)
  97. #define ia64_set_rr IA64_INTRINSIC_API(set_rr)
  98. #define ia64_get_rr IA64_INTRINSIC_API(get_rr)
  99. #define ia64_ptcga IA64_INTRINSIC_API(ptcga)
  100. #define ia64_get_psr_i IA64_INTRINSIC_API(get_psr_i)
  101. #define ia64_intrin_local_irq_restore \
  102. IA64_INTRINSIC_API(intrin_local_irq_restore)
  103. #define ia64_set_rr0_to_rr4 IA64_INTRINSIC_API(set_rr0_to_rr4)
  104. #endif /* !__ASSEMBLY__ */
  105. #endif /* _UAPI_ASM_IA64_INTRINSICS_H */