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