bitops.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <linux/config.h>
  7. #include <asm/asi.h>
  8. .text
  9. /* On SMP we need to use memory barriers to ensure
  10. * correct memory operation ordering, nop these out
  11. * for uniprocessor.
  12. */
  13. #ifdef CONFIG_SMP
  14. #define BITOP_PRE_BARRIER membar #StoreLoad | #LoadLoad
  15. #define BITOP_POST_BARRIER \
  16. ba,pt %xcc, 80b; \
  17. membar #StoreLoad | #StoreStore
  18. 80: retl
  19. nop
  20. #else
  21. #define BITOP_PRE_BARRIER
  22. #define BITOP_POST_BARRIER
  23. #endif
  24. .globl test_and_set_bit
  25. .type test_and_set_bit,#function
  26. test_and_set_bit: /* %o0=nr, %o1=addr */
  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, 1b
  39. and %g7, %o2, %g2
  40. clr %o0
  41. movrne %g2, 1, %o0
  42. BITOP_POST_BARRIER
  43. retl
  44. nop
  45. .size test_and_set_bit, .-test_and_set_bit
  46. .globl test_and_clear_bit
  47. .type test_and_clear_bit,#function
  48. test_and_clear_bit: /* %o0=nr, %o1=addr */
  49. BITOP_PRE_BARRIER
  50. srlx %o0, 6, %g1
  51. mov 1, %o2
  52. sllx %g1, 3, %g3
  53. and %o0, 63, %g2
  54. sllx %o2, %g2, %o2
  55. add %o1, %g3, %o1
  56. 1: ldx [%o1], %g7
  57. andn %g7, %o2, %g1
  58. casx [%o1], %g7, %g1
  59. cmp %g7, %g1
  60. bne,pn %xcc, 1b
  61. and %g7, %o2, %g2
  62. clr %o0
  63. movrne %g2, 1, %o0
  64. BITOP_POST_BARRIER
  65. retl
  66. nop
  67. .size test_and_clear_bit, .-test_and_clear_bit
  68. .globl test_and_change_bit
  69. .type test_and_change_bit,#function
  70. test_and_change_bit: /* %o0=nr, %o1=addr */
  71. BITOP_PRE_BARRIER
  72. srlx %o0, 6, %g1
  73. mov 1, %o2
  74. sllx %g1, 3, %g3
  75. and %o0, 63, %g2
  76. sllx %o2, %g2, %o2
  77. add %o1, %g3, %o1
  78. 1: ldx [%o1], %g7
  79. xor %g7, %o2, %g1
  80. casx [%o1], %g7, %g1
  81. cmp %g7, %g1
  82. bne,pn %xcc, 1b
  83. and %g7, %o2, %g2
  84. clr %o0
  85. movrne %g2, 1, %o0
  86. BITOP_POST_BARRIER
  87. retl
  88. nop
  89. .size test_and_change_bit, .-test_and_change_bit
  90. .globl set_bit
  91. .type set_bit,#function
  92. set_bit: /* %o0=nr, %o1=addr */
  93. srlx %o0, 6, %g1
  94. mov 1, %o2
  95. sllx %g1, 3, %g3
  96. and %o0, 63, %g2
  97. sllx %o2, %g2, %o2
  98. add %o1, %g3, %o1
  99. 1: ldx [%o1], %g7
  100. or %g7, %o2, %g1
  101. casx [%o1], %g7, %g1
  102. cmp %g7, %g1
  103. bne,pn %xcc, 1b
  104. nop
  105. retl
  106. nop
  107. .size set_bit, .-set_bit
  108. .globl clear_bit
  109. .type clear_bit,#function
  110. clear_bit: /* %o0=nr, %o1=addr */
  111. srlx %o0, 6, %g1
  112. mov 1, %o2
  113. sllx %g1, 3, %g3
  114. and %o0, 63, %g2
  115. sllx %o2, %g2, %o2
  116. add %o1, %g3, %o1
  117. 1: ldx [%o1], %g7
  118. andn %g7, %o2, %g1
  119. casx [%o1], %g7, %g1
  120. cmp %g7, %g1
  121. bne,pn %xcc, 1b
  122. nop
  123. retl
  124. nop
  125. .size clear_bit, .-clear_bit
  126. .globl change_bit
  127. .type change_bit,#function
  128. change_bit: /* %o0=nr, %o1=addr */
  129. srlx %o0, 6, %g1
  130. mov 1, %o2
  131. sllx %g1, 3, %g3
  132. and %o0, 63, %g2
  133. sllx %o2, %g2, %o2
  134. add %o1, %g3, %o1
  135. 1: ldx [%o1], %g7
  136. xor %g7, %o2, %g1
  137. casx [%o1], %g7, %g1
  138. cmp %g7, %g1
  139. bne,pn %xcc, 1b
  140. nop
  141. retl
  142. nop
  143. .size change_bit, .-change_bit