intrinsics.h 4.1 KB

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