os/ossrv/genericopenlibs/cppstdlib/stl/src/sparc_atomic.s
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
        .section        ".text",#alloc,#execinstr
sl@0
     2
          .align 8
sl@0
     3
          .skip 16
sl@0
     4
sl@0
     5
sl@0
     6
  /*
sl@0
     7
  **  int _STLP_atomic_exchange (void *pvalue, int value)
sl@0
     8
  */
sl@0
     9
sl@0
    10
          .type   _STLP_atomic_exchange,#function
sl@0
    11
          .global _STLP_atomic_exchange
sl@0
    12
          .align  8
sl@0
    13
sl@0
    14
_STLP_atomic_exchange:
sl@0
    15
0:
sl@0
    16
          ld      [%o0], %o2              ! Set the current value
sl@0
    17
          mov     %o1, %o3                ! Set the new value
sl@0
    18
!          swap     [%o0], %o3             ! Do the compare and swap
sl@0
    19
          cas     [%o0], %o2, %o3
sl@0
    20
          cmp     %o2, %o3                ! Check whether successful
sl@0
    21
          bne     0b                      ! Retry upon failure
sl@0
    22
          stbar
sl@0
    23
          mov     %o2, %o0                ! Set the new value
sl@0
    24
          retl                            ! return
sl@0
    25
          nop
sl@0
    26
          .size   _STLP_atomic_exchange,(.-_STLP_atomic_exchange)
sl@0
    27
sl@0
    28
  /* int _STLP_atomic_increment (void *pvalue) */
sl@0
    29
sl@0
    30
          .type   _STLP_atomic_increment,#function
sl@0
    31
          .global _STLP_atomic_increment
sl@0
    32
          .align  8
sl@0
    33
_STLP_atomic_increment:
sl@0
    34
1:
sl@0
    35
          ld      [%o0], %o2              ! set the current
sl@0
    36
          add             %o2, 0x1, %o3                   ! Increment and store current
sl@0
    37
!          swap     [%o0], %o3         ! Do the compare and swap
sl@0
    38
          cas     [%o0], %o2, %o3
sl@0
    39
          cmp     %o3, %o2                ! Check whether successful
sl@0
    40
          bne     1b                                         ! Retry if we failed.
sl@0
    41
          membar  #LoadLoad | #LoadStore  ! Ensure the cas finishes before
sl@0
    42
                                          ! returning
sl@0
    43
          nop
sl@0
    44
          retl                            ! return
sl@0
    45
          nop
sl@0
    46
sl@0
    47
          .size   _STLP_atomic_increment,(.-_STLP_atomic_increment)
sl@0
    48
sl@0
    49
sl@0
    50
  /* int _STLP_atomic_decrement (void *pvalue) */
sl@0
    51
          .type   _STLP_atomic_decrement,#function
sl@0
    52
          .global _STLP_atomic_decrement
sl@0
    53
          .align  8
sl@0
    54
sl@0
    55
_STLP_atomic_decrement:
sl@0
    56
2:
sl@0
    57
          ld      [%o0], %o2              ! set the current
sl@0
    58
          sub     %o2, 0x1, %o3                   ! decrement and store current
sl@0
    59
!          swap    [%o0], %o3         ! Do the compare and swap
sl@0
    60
          cas     [%o0], %o2, %o3
sl@0
    61
          cmp     %o3, %o2                ! Check whether successful
sl@0
    62
          bne     2b                                         ! Retry if we failed.
sl@0
    63
          membar  #LoadLoad | #LoadStore  ! Ensure the cas finishes before
sl@0
    64
          nop
sl@0
    65
                                          ! returning
sl@0
    66
          retl                            ! return
sl@0
    67
          nop
sl@0
    68
          .size   _STLP_atomic_decrement,(.-_STLP_atomic_decrement)