1 #ifndef _ASM_IA64_INTRINSICS_H
2 #define _ASM_IA64_INTRINSICS_H
5 * Compiler-dependent intrinsics.
7 * Copyright (C) 2002-2003 Hewlett-Packard Co
8 * David Mosberger-Tang <davidm@hpl.hp.com>
12 #include <linux/config.h>
14 /* include compiler specific intrinsics */
15 #include <asm/ia64regs.h>
16 #ifdef __INTEL_COMPILER
17 # include <asm/intel_intrin.h>
19 # include <asm/gcc_intrin.h>
23 * Force an unresolved reference if someone tries to use
24 * ia64_fetch_and_add() with a bad value.
26 extern unsigned long __bad_size_for_ia64_fetch_and_add (void);
27 extern unsigned long __bad_increment_for_ia64_fetch_and_add (void);
29 #define IA64_FETCHADD(tmp,v,n,sz,sem) \
33 tmp = ia64_fetchadd4_##sem((unsigned int *) v, n); \
37 tmp = ia64_fetchadd8_##sem((unsigned long *) v, n); \
41 __bad_size_for_ia64_fetch_and_add(); \
45 #define ia64_fetchadd(i,v,sem) \
48 volatile __typeof__(*(v)) *_v = (v); \
49 /* Can't use a switch () here: gcc isn't always smart enough for that... */ \
51 IA64_FETCHADD(_tmp, _v, -16, sizeof(*(v)), sem); \
53 IA64_FETCHADD(_tmp, _v, -8, sizeof(*(v)), sem); \
55 IA64_FETCHADD(_tmp, _v, -4, sizeof(*(v)), sem); \
57 IA64_FETCHADD(_tmp, _v, -1, sizeof(*(v)), sem); \
59 IA64_FETCHADD(_tmp, _v, 1, sizeof(*(v)), sem); \
61 IA64_FETCHADD(_tmp, _v, 4, sizeof(*(v)), sem); \
63 IA64_FETCHADD(_tmp, _v, 8, sizeof(*(v)), sem); \
65 IA64_FETCHADD(_tmp, _v, 16, sizeof(*(v)), sem); \
67 _tmp = __bad_increment_for_ia64_fetch_and_add(); \
68 (__typeof__(*(v))) (_tmp); /* return old value */ \
71 #define ia64_fetch_and_add(i,v) (ia64_fetchadd(i, v, rel) + (i)) /* return new value */
74 * This function doesn't exist, so you'll get a linker error if
75 * something tries to do an invalid xchg().
77 extern void ia64_xchg_called_with_bad_pointer (void);
79 #define __xchg(x,ptr,size) \
81 unsigned long __xchg_result; \
85 __xchg_result = ia64_xchg1((__u8 *)ptr, x); \
89 __xchg_result = ia64_xchg2((__u16 *)ptr, x); \
93 __xchg_result = ia64_xchg4((__u32 *)ptr, x); \
97 __xchg_result = ia64_xchg8((__u64 *)ptr, x); \
100 ia64_xchg_called_with_bad_pointer(); \
105 #define xchg(ptr,x) \
106 ((__typeof__(*(ptr))) __xchg ((unsigned long) (x), (ptr), sizeof(*(ptr))))
109 * Atomic compare and exchange. Compare OLD with MEM, if identical,
110 * store NEW in MEM. Return the initial value in MEM. Success is
111 * indicated by comparing RETURN with OLD.
114 #define __HAVE_ARCH_CMPXCHG 1
117 * This function doesn't exist, so you'll get a linker error
118 * if something tries to do an invalid cmpxchg().
120 extern long ia64_cmpxchg_called_with_bad_pointer (void);
122 #define ia64_cmpxchg(sem,ptr,old,new,size) \
127 case 1: _o_ = (__u8 ) (long) (old); break; \
128 case 2: _o_ = (__u16) (long) (old); break; \
129 case 4: _o_ = (__u32) (long) (old); break; \
130 case 8: _o_ = (__u64) (long) (old); break; \
135 _r_ = ia64_cmpxchg1_##sem((__u8 *) ptr, new, _o_); \
139 _r_ = ia64_cmpxchg2_##sem((__u16 *) ptr, new, _o_); \
143 _r_ = ia64_cmpxchg4_##sem((__u32 *) ptr, new, _o_); \
147 _r_ = ia64_cmpxchg8_##sem((__u64 *) ptr, new, _o_); \
151 _r_ = ia64_cmpxchg_called_with_bad_pointer(); \
154 (__typeof__(old)) _r_; \
157 #define cmpxchg_acq(ptr,o,n) ia64_cmpxchg(acq, (ptr), (o), (n), sizeof(*(ptr)))
158 #define cmpxchg_rel(ptr,o,n) ia64_cmpxchg(rel, (ptr), (o), (n), sizeof(*(ptr)))
160 /* for compatibility with other platforms: */
161 #define cmpxchg(ptr,o,n) cmpxchg_acq(ptr,o,n)
163 #ifdef CONFIG_IA64_DEBUG_CMPXCHG
164 # define CMPXCHG_BUGCHECK_DECL int _cmpxchg_bugcheck_count = 128;
165 # define CMPXCHG_BUGCHECK(v) \
167 if (_cmpxchg_bugcheck_count-- <= 0) { \
169 extern int printk(const char *fmt, ...); \
170 ip = (void *) ia64_getreg(_IA64_REG_IP); \
171 printk("CMPXCHG_BUGCHECK: stuck at %p on word %p\n", ip, (v)); \
175 #else /* !CONFIG_IA64_DEBUG_CMPXCHG */
176 # define CMPXCHG_BUGCHECK_DECL
177 # define CMPXCHG_BUGCHECK(v)
178 #endif /* !CONFIG_IA64_DEBUG_CMPXCHG */
181 #endif /* _ASM_IA64_INTRINSICS_H */