1
2// Currently, SUN CC requires object file
3
4#if defined (__GNUC__)
5
6/*
7**  int _STLP_atomic_exchange (__stl_atomic_t *pvalue, __stl_atomic_t value)
8*/
9
10#  if defined(__sparc_v9__) || defined (__sparcv9)
11
12#    ifdef __arch64__
13
14#      define _STLP_EXCH_ASM  asm volatile ("casx [%3], %4, %0 ;  membar  #LoadLoad | #LoadStore " : \
15                   "=r" (_L_value2), "=m" (*_L_pvalue1) : \
16                   "m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) )
17
18#    else /* __arch64__ */
19
20#      define _STLP_EXCH_ASM  asm volatile ("cas [%3], %4, %0" : \
21                   "=r" (_L_value2), "=m" (*_L_pvalue1) : \
22                   "m" (*_L_pvalue1), "r" (_L_pvalue1), "r" (_L_value1), "0" (_L_value2) )
23#    endif
24
25#  else /* __sparc_v9__ */
26
27#    define _STLP_EXCH_ASM asm volatile ("swap [%3], %0 " : \
28                                       "=r" (_L_value2), "=m" (*_L_pvalue1) : \
29                                       "m" (*_L_pvalue1), "r" (_L_pvalue1),  "0" (_L_value2) )
30#  endif
31
32
33#  define _STLP_ATOMIC_EXCHANGE(__pvalue1, __value2) \
34 ({  register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
35     register __stl_atomic_t _L_value1, _L_value2 =  __value2 ; \
36     do { _L_value1 = *_L_pvalue1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
37     _L_value1; })
38
39#  define _STLP_ATOMIC_INCREMENT(__pvalue1) \
40 ({  register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
41    register __stl_atomic_t _L_value1, _L_value2; \
42    do { _L_value1 = *_L_pvalue1;  _L_value2 = _L_value1+1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
43    (_L_value2 + 1); })
44
45#  define _STLP_ATOMIC_DECREMENT(__pvalue1) \
46 ({  register volatile __stl_atomic_t *_L_pvalue1 = __pvalue1; \
47    register __stl_atomic_t _L_value1, _L_value2; \
48    do { _L_value1 = *_L_pvalue1;  _L_value2 = _L_value1-1; _STLP_EXCH_ASM; } while ( _L_value1 != _L_value2 ) ; \
49    (_L_value2 - 1); })
50
51#  elif ! defined (_STLP_NO_EXTERN_INLINE)
52
53extern "C" __stl_atomic_t _STLP_atomic_exchange(__stl_atomic_t * __x, __stl_atomic_t __v);
54extern "C" void _STLP_atomic_decrement(__stl_atomic_t* i);
55extern "C" void _STLP_atomic_increment(__stl_atomic_t* i);
56
57#    define _STLP_ATOMIC_INCREMENT(__x)           _STLP_atomic_increment((__stl_atomic_t*)__x)
58#    define _STLP_ATOMIC_DECREMENT(__x)           _STLP_atomic_decrement((__stl_atomic_t*)__x)
59#    define _STLP_ATOMIC_EXCHANGE(__x, __y)       _STLP_atomic_exchange((__stl_atomic_t*)__x, (__stl_atomic_t)__y)
60
61#endif
62