atomic.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* $Id: atomic.S,v 1.4 2001/11/18 00:12:56 davem Exp $
  2. * atomic.S: These things are too big to do inline.
  3. *
  4. * Copyright (C) 1999 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/config.h>
  7. #include <asm/asi.h>
  8. /* On SMP we need to use memory barriers to ensure
  9. * correct memory operation ordering, nop these out
  10. * for uniprocessor.
  11. */
  12. #ifdef CONFIG_SMP
  13. #define ATOMIC_PRE_BARRIER membar #StoreLoad | #LoadLoad
  14. #define ATOMIC_POST_BARRIER membar #StoreLoad | #StoreStore
  15. #else
  16. #define ATOMIC_PRE_BARRIER nop
  17. #define ATOMIC_POST_BARRIER nop
  18. #endif
  19. .text
  20. /* Two versions of the atomic routines, one that
  21. * does not return a value and does not perform
  22. * memory barriers, and a second which returns
  23. * a value and does the barriers.
  24. */
  25. .globl atomic_add
  26. .type atomic_add,#function
  27. atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
  28. 1: lduw [%o1], %g1
  29. add %g1, %o0, %g7
  30. cas [%o1], %g1, %g7
  31. cmp %g1, %g7
  32. bne,pn %icc, 1b
  33. nop
  34. retl
  35. nop
  36. .size atomic_add, .-atomic_add
  37. .globl atomic_sub
  38. .type atomic_sub,#function
  39. atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
  40. 1: lduw [%o1], %g1
  41. sub %g1, %o0, %g7
  42. cas [%o1], %g1, %g7
  43. cmp %g1, %g7
  44. bne,pn %icc, 1b
  45. nop
  46. retl
  47. nop
  48. .size atomic_sub, .-atomic_sub
  49. .globl atomic_add_ret
  50. .type atomic_add_ret,#function
  51. atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
  52. ATOMIC_PRE_BARRIER
  53. 1: lduw [%o1], %g1
  54. add %g1, %o0, %g7
  55. cas [%o1], %g1, %g7
  56. cmp %g1, %g7
  57. bne,pn %icc, 1b
  58. add %g7, %o0, %g7
  59. ATOMIC_POST_BARRIER
  60. retl
  61. sra %g7, 0, %o0
  62. .size atomic_add_ret, .-atomic_add_ret
  63. .globl atomic_sub_ret
  64. .type atomic_sub_ret,#function
  65. atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
  66. ATOMIC_PRE_BARRIER
  67. 1: lduw [%o1], %g1
  68. sub %g1, %o0, %g7
  69. cas [%o1], %g1, %g7
  70. cmp %g1, %g7
  71. bne,pn %icc, 1b
  72. sub %g7, %o0, %g7
  73. ATOMIC_POST_BARRIER
  74. retl
  75. sra %g7, 0, %o0
  76. .size atomic_sub_ret, .-atomic_sub_ret
  77. .globl atomic64_add
  78. .type atomic64_add,#function
  79. atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
  80. 1: ldx [%o1], %g1
  81. add %g1, %o0, %g7
  82. casx [%o1], %g1, %g7
  83. cmp %g1, %g7
  84. bne,pn %xcc, 1b
  85. nop
  86. retl
  87. nop
  88. .size atomic64_add, .-atomic64_add
  89. .globl atomic64_sub
  90. .type atomic64_sub,#function
  91. atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
  92. 1: ldx [%o1], %g1
  93. sub %g1, %o0, %g7
  94. casx [%o1], %g1, %g7
  95. cmp %g1, %g7
  96. bne,pn %xcc, 1b
  97. nop
  98. retl
  99. nop
  100. .size atomic64_sub, .-atomic64_sub
  101. .globl atomic64_add_ret
  102. .type atomic64_add_ret,#function
  103. atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
  104. ATOMIC_PRE_BARRIER
  105. 1: ldx [%o1], %g1
  106. add %g1, %o0, %g7
  107. casx [%o1], %g1, %g7
  108. cmp %g1, %g7
  109. bne,pn %xcc, 1b
  110. add %g7, %o0, %g7
  111. ATOMIC_POST_BARRIER
  112. retl
  113. mov %g7, %o0
  114. .size atomic64_add_ret, .-atomic64_add_ret
  115. .globl atomic64_sub_ret
  116. .type atomic64_sub_ret,#function
  117. atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
  118. ATOMIC_PRE_BARRIER
  119. 1: ldx [%o1], %g1
  120. sub %g1, %o0, %g7
  121. casx [%o1], %g1, %g7
  122. cmp %g1, %g7
  123. bne,pn %xcc, 1b
  124. sub %g7, %o0, %g7
  125. ATOMIC_POST_BARRIER
  126. retl
  127. mov %g7, %o0
  128. .size atomic64_sub_ret, .-atomic64_sub_ret