sparc_atomic.s 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. .section ".text",#alloc,#execinstr
  2. .align 8
  3. .skip 16
  4. /*
  5. ** int _STLP_atomic_exchange (void *pvalue, int value)
  6. */
  7. .type _STLP_atomic_exchange,#function
  8. .global _STLP_atomic_exchange
  9. .align 8
  10. _STLP_atomic_exchange:
  11. 0:
  12. ld [%o0], %o2 ! Set the current value
  13. mov %o1, %o3 ! Set the new value
  14. ! swap [%o0], %o3 ! Do the compare and swap
  15. cas [%o0], %o2, %o3
  16. cmp %o2, %o3 ! Check whether successful
  17. bne 0b ! Retry upon failure
  18. stbar
  19. mov %o2, %o0 ! Set the new value
  20. retl ! return
  21. nop
  22. .size _STLP_atomic_exchange,(.-_STLP_atomic_exchange)
  23. /* int _STLP_atomic_increment (void *pvalue) */
  24. .type _STLP_atomic_increment,#function
  25. .global _STLP_atomic_increment
  26. .align 8
  27. _STLP_atomic_increment:
  28. 1:
  29. ld [%o0], %o2 ! set the current
  30. add %o2, 0x1, %o3 ! Increment and store current
  31. ! swap [%o0], %o3 ! Do the compare and swap
  32. cas [%o0], %o2, %o3
  33. cmp %o3, %o2 ! Check whether successful
  34. bne 1b ! Retry if we failed.
  35. membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
  36. ! returning
  37. nop
  38. retl ! return
  39. nop
  40. .size _STLP_atomic_increment,(.-_STLP_atomic_increment)
  41. /* int _STLP_atomic_decrement (void *pvalue) */
  42. .type _STLP_atomic_decrement,#function
  43. .global _STLP_atomic_decrement
  44. .align 8
  45. _STLP_atomic_decrement:
  46. 2:
  47. ld [%o0], %o2 ! set the current
  48. sub %o2, 0x1, %o3 ! decrement and store current
  49. ! swap [%o0], %o3 ! Do the compare and swap
  50. cas [%o0], %o2, %o3
  51. cmp %o3, %o2 ! Check whether successful
  52. bne 2b ! Retry if we failed.
  53. membar #LoadLoad | #LoadStore ! Ensure the cas finishes before
  54. nop
  55. ! returning
  56. retl ! return
  57. nop
  58. .size _STLP_atomic_decrement,(.-_STLP_atomic_decrement)