findbit.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * linux/arch/arm/lib/findbit.S
  3. *
  4. * Copyright (C) 1995-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * 16th March 2001 - John Ripley <jripley@sonicblue.com>
  11. * Fixed so that "size" is an exclusive not an inclusive quantity.
  12. * All users of these functions expect exclusive sizes, and may
  13. * also call with zero size.
  14. * Reworked by rmk.
  15. */
  16. #include <linux/linkage.h>
  17. #include <asm/assembler.h>
  18. .text
  19. /*
  20. * Purpose : Find a 'zero' bit
  21. * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
  22. */
  23. ENTRY(_find_first_zero_bit_le)
  24. teq r1, #0
  25. beq 3f
  26. mov r2, #0
  27. 1: ldrb r3, [r0, r2, lsr #3]
  28. eors r3, r3, #0xff @ invert bits
  29. bne .L_found @ any now set - found zero bit
  30. add r2, r2, #8 @ next bit pointer
  31. 2: cmp r2, r1 @ any more?
  32. blo 1b
  33. 3: mov r0, r1 @ no free bits
  34. mov pc, lr
  35. ENDPROC(_find_first_zero_bit_le)
  36. /*
  37. * Purpose : Find next 'zero' bit
  38. * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
  39. */
  40. ENTRY(_find_next_zero_bit_le)
  41. teq r1, #0
  42. beq 3b
  43. ands ip, r2, #7
  44. beq 1b @ If new byte, goto old routine
  45. ldrb r3, [r0, r2, lsr #3]
  46. eor r3, r3, #0xff @ now looking for a 1 bit
  47. movs r3, r3, lsr ip @ shift off unused bits
  48. bne .L_found
  49. orr r2, r2, #7 @ if zero, then no bits here
  50. add r2, r2, #1 @ align bit pointer
  51. b 2b @ loop for next bit
  52. ENDPROC(_find_next_zero_bit_le)
  53. /*
  54. * Purpose : Find a 'one' bit
  55. * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
  56. */
  57. ENTRY(_find_first_bit_le)
  58. teq r1, #0
  59. beq 3f
  60. mov r2, #0
  61. 1: ldrb r3, [r0, r2, lsr #3]
  62. movs r3, r3
  63. bne .L_found @ any now set - found zero bit
  64. add r2, r2, #8 @ next bit pointer
  65. 2: cmp r2, r1 @ any more?
  66. blo 1b
  67. 3: mov r0, r1 @ no free bits
  68. mov pc, lr
  69. ENDPROC(_find_first_bit_le)
  70. /*
  71. * Purpose : Find next 'one' bit
  72. * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
  73. */
  74. ENTRY(_find_next_bit_le)
  75. teq r1, #0
  76. beq 3b
  77. ands ip, r2, #7
  78. beq 1b @ If new byte, goto old routine
  79. ldrb r3, [r0, r2, lsr #3]
  80. movs r3, r3, lsr ip @ shift off unused bits
  81. bne .L_found
  82. orr r2, r2, #7 @ if zero, then no bits here
  83. add r2, r2, #1 @ align bit pointer
  84. b 2b @ loop for next bit
  85. ENDPROC(_find_next_bit_le)
  86. #ifdef __ARMEB__
  87. ENTRY(_find_first_zero_bit_be)
  88. teq r1, #0
  89. beq 3f
  90. mov r2, #0
  91. 1: eor r3, r2, #0x18 @ big endian byte ordering
  92. ldrb r3, [r0, r3, lsr #3]
  93. eors r3, r3, #0xff @ invert bits
  94. bne .L_found @ any now set - found zero bit
  95. add r2, r2, #8 @ next bit pointer
  96. 2: cmp r2, r1 @ any more?
  97. blo 1b
  98. 3: mov r0, r1 @ no free bits
  99. mov pc, lr
  100. ENDPROC(_find_first_zero_bit_be)
  101. ENTRY(_find_next_zero_bit_be)
  102. teq r1, #0
  103. beq 3b
  104. ands ip, r2, #7
  105. beq 1b @ If new byte, goto old routine
  106. eor r3, r2, #0x18 @ big endian byte ordering
  107. ldrb r3, [r0, r3, lsr #3]
  108. eor r3, r3, #0xff @ now looking for a 1 bit
  109. movs r3, r3, lsr ip @ shift off unused bits
  110. bne .L_found
  111. orr r2, r2, #7 @ if zero, then no bits here
  112. add r2, r2, #1 @ align bit pointer
  113. b 2b @ loop for next bit
  114. ENDPROC(_find_next_zero_bit_be)
  115. ENTRY(_find_first_bit_be)
  116. teq r1, #0
  117. beq 3f
  118. mov r2, #0
  119. 1: eor r3, r2, #0x18 @ big endian byte ordering
  120. ldrb r3, [r0, r3, lsr #3]
  121. movs r3, r3
  122. bne .L_found @ any now set - found zero bit
  123. add r2, r2, #8 @ next bit pointer
  124. 2: cmp r2, r1 @ any more?
  125. blo 1b
  126. 3: mov r0, r1 @ no free bits
  127. mov pc, lr
  128. ENDPROC(_find_first_bit_be)
  129. ENTRY(_find_next_bit_be)
  130. teq r1, #0
  131. beq 3b
  132. ands ip, r2, #7
  133. beq 1b @ If new byte, goto old routine
  134. eor r3, r2, #0x18 @ big endian byte ordering
  135. ldrb r3, [r0, r3, lsr #3]
  136. movs r3, r3, lsr ip @ shift off unused bits
  137. bne .L_found
  138. orr r2, r2, #7 @ if zero, then no bits here
  139. add r2, r2, #1 @ align bit pointer
  140. b 2b @ loop for next bit
  141. ENDPROC(_find_next_bit_be)
  142. #endif
  143. /*
  144. * One or more bits in the LSB of r3 are assumed to be set.
  145. */
  146. .L_found:
  147. #if __LINUX_ARM_ARCH__ >= 5
  148. rsb r1, r3, #0
  149. and r3, r3, r1
  150. clz r3, r3
  151. rsb r3, r3, #31
  152. add r0, r2, r3
  153. #else
  154. tst r3, #0x0f
  155. addeq r2, r2, #4
  156. movne r3, r3, lsl #4
  157. tst r3, #0x30
  158. addeq r2, r2, #2
  159. movne r3, r3, lsl #2
  160. tst r3, #0x40
  161. addeq r2, r2, #1
  162. mov r0, r2
  163. #endif
  164. mov pc, lr