bitops.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* bitops.S: Sparc64 atomic bit operations.
  2. *
  3. * Copyright (C) 2000, 2007 David S. Miller (davem@davemloft.net)
  4. */
  5. #include <asm/asi.h>
  6. #include <asm/backoff.h>
  7. .text
  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 BITOP_PRE_BARRIER membar #StoreLoad | #LoadLoad
  14. #define BITOP_POST_BARRIER \
  15. ba,pt %xcc, 80b; \
  16. membar #StoreLoad | #StoreStore
  17. 80: retl
  18. nop
  19. #else
  20. #define BITOP_PRE_BARRIER
  21. #define BITOP_POST_BARRIER
  22. #endif
  23. .globl test_and_set_bit
  24. .type test_and_set_bit,#function
  25. test_and_set_bit: /* %o0=nr, %o1=addr */
  26. BACKOFF_SETUP(%o3)
  27. BITOP_PRE_BARRIER
  28. srlx %o0, 6, %g1
  29. mov 1, %o2
  30. sllx %g1, 3, %g3
  31. and %o0, 63, %g2
  32. sllx %o2, %g2, %o2
  33. add %o1, %g3, %o1
  34. 1: ldx [%o1], %g7
  35. or %g7, %o2, %g1
  36. casx [%o1], %g7, %g1
  37. cmp %g7, %g1
  38. bne,pn %xcc, 2f
  39. and %g7, %o2, %g2
  40. clr %o0
  41. movrne %g2, 1, %o0
  42. BITOP_POST_BARRIER
  43. retl
  44. nop
  45. 2: BACKOFF_SPIN(%o3, %o4, 1b)
  46. .size test_and_set_bit, .-test_and_set_bit
  47. .globl test_and_clear_bit
  48. .type test_and_clear_bit,#function
  49. test_and_clear_bit: /* %o0=nr, %o1=addr */
  50. BACKOFF_SETUP(%o3)
  51. BITOP_PRE_BARRIER
  52. srlx %o0, 6, %g1
  53. mov 1, %o2
  54. sllx %g1, 3, %g3
  55. and %o0, 63, %g2
  56. sllx %o2, %g2, %o2
  57. add %o1, %g3, %o1
  58. 1: ldx [%o1], %g7
  59. andn %g7, %o2, %g1
  60. casx [%o1], %g7, %g1
  61. cmp %g7, %g1
  62. bne,pn %xcc, 2f
  63. and %g7, %o2, %g2
  64. clr %o0
  65. movrne %g2, 1, %o0
  66. BITOP_POST_BARRIER
  67. retl
  68. nop
  69. 2: BACKOFF_SPIN(%o3, %o4, 1b)
  70. .size test_and_clear_bit, .-test_and_clear_bit
  71. .globl test_and_change_bit
  72. .type test_and_change_bit,#function
  73. test_and_change_bit: /* %o0=nr, %o1=addr */
  74. BACKOFF_SETUP(%o3)
  75. BITOP_PRE_BARRIER
  76. srlx %o0, 6, %g1
  77. mov 1, %o2
  78. sllx %g1, 3, %g3
  79. and %o0, 63, %g2
  80. sllx %o2, %g2, %o2
  81. add %o1, %g3, %o1
  82. 1: ldx [%o1], %g7
  83. xor %g7, %o2, %g1
  84. casx [%o1], %g7, %g1
  85. cmp %g7, %g1
  86. bne,pn %xcc, 2f
  87. and %g7, %o2, %g2
  88. clr %o0
  89. movrne %g2, 1, %o0
  90. BITOP_POST_BARRIER
  91. retl
  92. nop
  93. 2: BACKOFF_SPIN(%o3, %o4, 1b)
  94. .size test_and_change_bit, .-test_and_change_bit
  95. .globl set_bit
  96. .type set_bit,#function
  97. set_bit: /* %o0=nr, %o1=addr */
  98. BACKOFF_SETUP(%o3)
  99. srlx %o0, 6, %g1
  100. mov 1, %o2
  101. sllx %g1, 3, %g3
  102. and %o0, 63, %g2
  103. sllx %o2, %g2, %o2
  104. add %o1, %g3, %o1
  105. 1: ldx [%o1], %g7
  106. or %g7, %o2, %g1
  107. casx [%o1], %g7, %g1
  108. cmp %g7, %g1
  109. bne,pn %xcc, 2f
  110. nop
  111. retl
  112. nop
  113. 2: BACKOFF_SPIN(%o3, %o4, 1b)
  114. .size set_bit, .-set_bit
  115. .globl clear_bit
  116. .type clear_bit,#function
  117. clear_bit: /* %o0=nr, %o1=addr */
  118. BACKOFF_SETUP(%o3)
  119. srlx %o0, 6, %g1
  120. mov 1, %o2
  121. sllx %g1, 3, %g3
  122. and %o0, 63, %g2
  123. sllx %o2, %g2, %o2
  124. add %o1, %g3, %o1
  125. 1: ldx [%o1], %g7
  126. andn %g7, %o2, %g1
  127. casx [%o1], %g7, %g1
  128. cmp %g7, %g1
  129. bne,pn %xcc, 2f
  130. nop
  131. retl
  132. nop
  133. 2: BACKOFF_SPIN(%o3, %o4, 1b)
  134. .size clear_bit, .-clear_bit
  135. .globl change_bit
  136. .type change_bit,#function
  137. change_bit: /* %o0=nr, %o1=addr */
  138. BACKOFF_SETUP(%o3)
  139. srlx %o0, 6, %g1
  140. mov 1, %o2
  141. sllx %g1, 3, %g3
  142. and %o0, 63, %g2
  143. sllx %o2, %g2, %o2
  144. add %o1, %g3, %o1
  145. 1: ldx [%o1], %g7
  146. xor %g7, %o2, %g1
  147. casx [%o1], %g7, %g1
  148. cmp %g7, %g1
  149. bne,pn %xcc, 2f
  150. nop
  151. retl
  152. nop
  153. 2: BACKOFF_SPIN(%o3, %o4, 1b)
  154. .size change_bit, .-change_bit