4 * These atomic operations copied from the linux kernel and altered
5 * only slightly. I need to get official permission to distribute
6 * under the Artistic License.
8 /* We really need to integrate the atomic typedef with the typedef
9 * used by sv_refcnt of an SV. It's possible that for CPUs like alpha
10 * where we'd need to up sv_refcnt from 32 to 64 bits, we may be better
11 * off sticking with EMULATE_ATOMIC_REFCOUNTS instead.
13 typedef U32 atomic_t; /* kludge */
20 # define LOCK "lock ; "
23 # define __atomic_fool_gcc(x) (*(struct { int a[100]; } *)x)
24 static __inline__ void atomic_inc(atomic_t *v)
28 :"=m" (__atomic_fool_gcc(v))
29 :"m" (__atomic_fool_gcc(v)));
32 static __inline__ int atomic_dec_and_test(atomic_t *v)
37 LOCK "decl %0; sete %1"
38 :"=m" (__atomic_fool_gcc(v)), "=qm" (c)
39 :"m" (__atomic_fool_gcc(v)));
43 /* XXX What symbol does gcc define for sparc64? */
45 # define __atomic_fool_gcc(x) ((struct { int a[100]; } *)x)
47 extern __inline__ void atomic_add(int i, atomic_t *v)
49 __asm__ __volatile__("
57 : "HIr" (i), "r" (__atomic_fool_gcc(v))
58 : "g5", "g7", "memory");
61 extern __inline__ int atomic_sub_return(int i, atomic_t *v)
64 __asm__ __volatile__("
72 : "HIr" (i), "r" (__atomic_fool_gcc(v))
73 : "g5", "g7", "memory");
77 #define atomic_inc(v) atomic_add(1,(v))
78 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
79 /* Add further gcc architectures here */
81 # define EMULATE_ATOMIC_REFCOUNTS
85 /* Add non-gcc native atomic operations here */
86 # define EMULATE_ATOMIC_REFCOUNTS