/arch/sparc64/lib/bitops.S

https://bitbucket.org/evzijst/gittest · Assembly · 145 lines · 127 code · 9 blank · 9 comment · 0 complexity · a6419ed0e68bc9489d5c8965e3dbba86 MD5 · raw file

  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. /* 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 membar #StoreLoad | #StoreStore
  15. #else
  16. #define BITOP_PRE_BARRIER nop
  17. #define BITOP_POST_BARRIER nop
  18. #endif
  19. .text
  20. .globl test_and_set_bit
  21. .type test_and_set_bit,#function
  22. test_and_set_bit: /* %o0=nr, %o1=addr */
  23. BITOP_PRE_BARRIER
  24. srlx %o0, 6, %g1
  25. mov 1, %o2
  26. sllx %g1, 3, %g3
  27. and %o0, 63, %g2
  28. sllx %o2, %g2, %o2
  29. add %o1, %g3, %o1
  30. 1: ldx [%o1], %g7
  31. or %g7, %o2, %g1
  32. casx [%o1], %g7, %g1
  33. cmp %g7, %g1
  34. bne,pn %xcc, 1b
  35. and %g7, %o2, %g2
  36. BITOP_POST_BARRIER
  37. clr %o0
  38. retl
  39. movrne %g2, 1, %o0
  40. .size test_and_set_bit, .-test_and_set_bit
  41. .globl test_and_clear_bit
  42. .type test_and_clear_bit,#function
  43. test_and_clear_bit: /* %o0=nr, %o1=addr */
  44. BITOP_PRE_BARRIER
  45. srlx %o0, 6, %g1
  46. mov 1, %o2
  47. sllx %g1, 3, %g3
  48. and %o0, 63, %g2
  49. sllx %o2, %g2, %o2
  50. add %o1, %g3, %o1
  51. 1: ldx [%o1], %g7
  52. andn %g7, %o2, %g1
  53. casx [%o1], %g7, %g1
  54. cmp %g7, %g1
  55. bne,pn %xcc, 1b
  56. and %g7, %o2, %g2
  57. BITOP_POST_BARRIER
  58. clr %o0
  59. retl
  60. movrne %g2, 1, %o0
  61. .size test_and_clear_bit, .-test_and_clear_bit
  62. .globl test_and_change_bit
  63. .type test_and_change_bit,#function
  64. test_and_change_bit: /* %o0=nr, %o1=addr */
  65. BITOP_PRE_BARRIER
  66. srlx %o0, 6, %g1
  67. mov 1, %o2
  68. sllx %g1, 3, %g3
  69. and %o0, 63, %g2
  70. sllx %o2, %g2, %o2
  71. add %o1, %g3, %o1
  72. 1: ldx [%o1], %g7
  73. xor %g7, %o2, %g1
  74. casx [%o1], %g7, %g1
  75. cmp %g7, %g1
  76. bne,pn %xcc, 1b
  77. and %g7, %o2, %g2
  78. BITOP_POST_BARRIER
  79. clr %o0
  80. retl
  81. movrne %g2, 1, %o0
  82. .size test_and_change_bit, .-test_and_change_bit
  83. .globl set_bit
  84. .type set_bit,#function
  85. set_bit: /* %o0=nr, %o1=addr */
  86. srlx %o0, 6, %g1
  87. mov 1, %o2
  88. sllx %g1, 3, %g3
  89. and %o0, 63, %g2
  90. sllx %o2, %g2, %o2
  91. add %o1, %g3, %o1
  92. 1: ldx [%o1], %g7
  93. or %g7, %o2, %g1
  94. casx [%o1], %g7, %g1
  95. cmp %g7, %g1
  96. bne,pn %xcc, 1b
  97. nop
  98. retl
  99. nop
  100. .size set_bit, .-set_bit
  101. .globl clear_bit
  102. .type clear_bit,#function
  103. clear_bit: /* %o0=nr, %o1=addr */
  104. srlx %o0, 6, %g1
  105. mov 1, %o2
  106. sllx %g1, 3, %g3
  107. and %o0, 63, %g2
  108. sllx %o2, %g2, %o2
  109. add %o1, %g3, %o1
  110. 1: ldx [%o1], %g7
  111. andn %g7, %o2, %g1
  112. casx [%o1], %g7, %g1
  113. cmp %g7, %g1
  114. bne,pn %xcc, 1b
  115. nop
  116. retl
  117. nop
  118. .size clear_bit, .-clear_bit
  119. .globl change_bit
  120. .type change_bit,#function
  121. change_bit: /* %o0=nr, %o1=addr */
  122. srlx %o0, 6, %g1
  123. mov 1, %o2
  124. sllx %g1, 3, %g3
  125. and %o0, 63, %g2
  126. sllx %o2, %g2, %o2
  127. add %o1, %g3, %o1
  128. 1: ldx [%o1], %g7
  129. xor %g7, %o2, %g1
  130. casx [%o1], %g7, %g1
  131. cmp %g7, %g1
  132. bne,pn %xcc, 1b
  133. nop
  134. retl
  135. nop
  136. .size change_bit, .-change_bit