30 #ifndef _QORE_MACHINE_MACROS_H
32 #define _QORE_MACHINE_MACROS_H
35 #if !defined(__sparcv9)
37 #define STACK_DIRECTION_DOWN 1
41 #define HAVE_ATOMIC_MACROS
44 inline int compare_and_swap(
int *dest_,
int compare_,
int swap_) {
45 __asm__ __volatile__(
"cas %0, %2, %1"
46 :
"+m" (*dest_),
"+r" (swap_)
53 inline int atomic_fetch_and_add(
int * pw,
int dv) {
57 if (__builtin_expect((compare_and_swap(pw, r, r + dv) == r), 1)) {
63 static inline int atomic_dec(
int *pw) {
64 return !atomic_fetch_and_add(pw, -1);
67 static inline void atomic_inc(
int *pw) {
68 atomic_fetch_and_add(pw, 1);
71 #define HAVE_CHECK_STACK_POS
73 static inline size_t get_stack_pos() {
75 __asm__(
"mov %%sp,%0" :
"=r" (addr) );
82 #define HAVE_ATOMIC_MACROS
85 extern "C" int atomic_dec(
int *pw);
86 extern "C" void atomic_inc(
int *pw);
88 #define HAVE_CHECK_STACK_POS
90 extern "C" size_t get_stack_pos();