Qore Programming Language  0.8.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
macros-sparc.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 #ifndef _QORE_MACHINE_MACROS_H
3 
4 #define _QORE_MACHINE_MACROS_H
5 
6 // no atomic support or stack guard for 64-bit sparc yet
7 #if !defined(__sparcv9)
8 
9 #define STACK_DIRECTION_DOWN 1
10 
11 #ifdef __GNUC__
12 
13 #define HAVE_ATOMIC_MACROS
14 
15 // borrowed from boost
16 inline int compare_and_swap(int *dest_, int compare_, int swap_) {
17  __asm__ __volatile__( "cas %0, %2, %1"
18  : "+m" (*dest_), "+r" (swap_)
19  : "r" (compare_)
20  : "memory" );
21 
22  return swap_;
23 }
24 
25 inline int atomic_fetch_and_add(int * pw, int dv) {
26  for( ;; ) {
27  int r = *pw;
28 
29  if (__builtin_expect((compare_and_swap(pw, r, r + dv) == r), 1)) {
30  return r;
31  }
32  }
33 }
34 
35 static inline int atomic_dec(int *pw) {
36  return !atomic_fetch_and_add(pw, -1);
37 }
38 
39 static inline void atomic_inc(int *pw) {
40  atomic_fetch_and_add(pw, 1);
41 }
42 
43 #define HAVE_CHECK_STACK_POS
44 
45 static inline size_t get_stack_pos() {
46  size_t addr;
47  __asm__("mov %%sp,%0" : "=r" (addr) );
48  return addr;
49 }
50 
51 #endif
52 
53 #ifdef __SUNPRO_CC
54 #define HAVE_ATOMIC_MACROS
55 
56 // routines are implemented in assembler
57 extern "C" int atomic_dec(int *pw);
58 extern "C" void atomic_inc(int *pw);
59 
60 #define HAVE_CHECK_STACK_POS
61 
62 extern "C" size_t get_stack_pos();
63 
64 #endif
65 
66 #endif
67 
68 #endif