bitops.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* $Id: bitops.S,v 1.3 2001/11/18 00:12:56 davem Exp $
  2. * bitops.S: Sparc64 atomic bit operations.
  3. *
  4. * Copyright (C) 2000 David S. Miller (davem@redhat.com)
  5. */
  6. #include <asm/asi.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. BITOP_PRE_BARRIER
  27. srlx %o0, 6, %g1
  28. mov 1, %o2
  29. sllx %g1, 3, %g3
  30. and %o0, 63, %g2
  31. sllx %o2, %g2, %o2
  32. add %o1, %g3, %o1
  33. 1: ldx [%o1], %g7
  34. or %g7, %o2, %g1
  35. casx [%o1], %g7, %g1
  36. cmp %g7, %g1
  37. bne,pn %xcc, 1b
  38. and %g7, %o2, %g2
  39. clr %o0
  40. movrne %g2, 1, %o0
  41. BITOP_POST_BARRIER
  42. retl
  43. nop
  44. .size test_and_set_bit, .-test_and_set_bit
  45. .globl test_and_clear_bit
  46. .type test_and_clear_bit,#function
  47. test_and_clear_bit: /* %o0=nr, %o1=addr */
  48. BITOP_PRE_BARRIER
  49. srlx %o0, 6, %g1
  50. mov 1, %o2
  51. sllx %g1, 3, %g3
  52. and %o0, 63, %g2
  53. sllx %o2, %g2, %o2
  54. add %o1, %g3, %o1
  55. 1: ldx [%o1], %g7
  56. andn %g7, %o2, %g1
  57. casx [%o1], %g7, %g1
  58. cmp %g7, %g1
  59. bne,pn %xcc, 1b
  60. and %g7, %o2, %g2
  61. clr %o0
  62. movrne %g2, 1, %o0
  63. BITOP_POST_BARRIER
  64. retl
  65. nop
  66. .size test_and_clear_bit, .-test_and_clear_bit
  67. .globl test_and_change_bit
  68. .type test_and_change_bit,#function
  69. test_and_change_bit: /* %o0=nr, %o1=addr */
  70. BITOP_PRE_BARRIER
  71. srlx %o0, 6, %g1
  72. mov 1, %o2
  73. sllx %g1, 3, %g3
  74. and %o0, 63, %g2
  75. sllx %o2, %g2, %o2
  76. add %o1, %g3, %o1
  77. 1: ldx [%o1], %g7
  78. xor %g7, %o2, %g1
  79. casx [%o1], %g7, %g1
  80. cmp %g7, %g1
  81. bne,pn %xcc, 1b
  82. and %g7, %o2, %g2
  83. clr %o0
  84. movrne %g2, 1, %o0
  85. BITOP_POST_BARRIER
  86. retl
  87. nop
  88. .size test_and_change_bit, .-test_and_change_bit
  89. .globl set_bit
  90. .type set_bit,#function
  91. set_bit: /* %o0=nr, %o1=addr */
  92. srlx %o0, 6, %g1
  93. mov 1, %o2
  94. sllx %g1, 3, %g3
  95. and %o0, 63, %g2
  96. sllx %o2, %g2, %o2
  97. add %o1, %g3, %o1
  98. 1: ldx [%o1], %g7
  99. or %g7, %o2, %g1
  100. casx [%o1], %g7, %g1
  101. cmp %g7, %g1
  102. bne,pn %xcc, 1b
  103. nop
  104. retl
  105. nop
  106. .size set_bit, .-set_bit
  107. .globl clear_bit
  108. .type clear_bit,#function
  109. clear_bit: /* %o0=nr, %o1=addr */
  110. srlx %o0, 6, %g1
  111. mov 1, %o2
  112. sllx %g1, 3, %g3
  113. and %o0, 63, %g2
  114. sllx %o2, %g2, %o2
  115. add %o1, %g3, %o1
  116. 1: ldx [%o1], %g7
  117. andn %g7, %o2, %g1
  118. casx [%o1], %g7, %g1
  119. cmp %g7, %g1
  120. bne,pn %xcc, 1b
  121. nop
  122. retl
  123. nop
  124. .size clear_bit, .-clear_bit
  125. .globl change_bit
  126. .type change_bit,#function
  127. change_bit: /* %o0=nr, %o1=addr */
  128. srlx %o0, 6, %g1
  129. mov 1, %o2
  130. sllx %g1, 3, %g3
  131. and %o0, 63, %g2
  132. sllx %o2, %g2, %o2
  133. add %o1, %g3, %o1
  134. 1: ldx [%o1], %g7
  135. xor %g7, %o2, %g1
  136. casx [%o1], %g7, %g1
  137. cmp %g7, %g1
  138. bne,pn %xcc, 1b
  139. nop
  140. retl
  141. nop
  142. .size change_bit, .-change_bit