findbit.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. #include <asm/export.h>
  19. .text
  20. /*
  21. * Purpose : Find a 'zero' bit
  22. * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
  23. */
  24. ENTRY(_find_first_zero_bit_le)
  25. teq r1, #0
  26. beq 3f
  27. mov r2, #0
  28. 1:
  29. ARM( ldrb r3, [r0, r2, lsr #3] )
  30. THUMB( lsr r3, r2, #3 )
  31. THUMB( ldrb r3, [r0, r3] )
  32. eors r3, r3, #0xff @ invert bits
  33. bne .L_found @ any now set - found zero bit
  34. add r2, r2, #8 @ next bit pointer
  35. 2: cmp r2, r1 @ any more?
  36. blo 1b
  37. 3: mov r0, r1 @ no free bits
  38. ret lr
  39. ENDPROC(_find_first_zero_bit_le)
  40. EXPORT_SYMBOL(_find_first_zero_bit_le)
  41. /*
  42. * Purpose : Find next 'zero' bit
  43. * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
  44. */
  45. ENTRY(_find_next_zero_bit_le)
  46. teq r1, #0
  47. beq 3b
  48. ands ip, r2, #7
  49. beq 1b @ If new byte, goto old routine
  50. ARM( ldrb r3, [r0, r2, lsr #3] )
  51. THUMB( lsr r3, r2, #3 )
  52. THUMB( ldrb r3, [r0, r3] )
  53. eor r3, r3, #0xff @ now looking for a 1 bit
  54. movs r3, r3, lsr ip @ shift off unused bits
  55. bne .L_found
  56. orr r2, r2, #7 @ if zero, then no bits here
  57. add r2, r2, #1 @ align bit pointer
  58. b 2b @ loop for next bit
  59. ENDPROC(_find_next_zero_bit_le)
  60. EXPORT_SYMBOL(_find_next_zero_bit_le)
  61. /*
  62. * Purpose : Find a 'one' bit
  63. * Prototype: int find_first_bit(const unsigned long *addr, unsigned int maxbit);
  64. */
  65. ENTRY(_find_first_bit_le)
  66. teq r1, #0
  67. beq 3f
  68. mov r2, #0
  69. 1:
  70. ARM( ldrb r3, [r0, r2, lsr #3] )
  71. THUMB( lsr r3, r2, #3 )
  72. THUMB( ldrb r3, [r0, r3] )
  73. movs r3, r3
  74. bne .L_found @ any now set - found zero bit
  75. add r2, r2, #8 @ next bit pointer
  76. 2: cmp r2, r1 @ any more?
  77. blo 1b
  78. 3: mov r0, r1 @ no free bits
  79. ret lr
  80. ENDPROC(_find_first_bit_le)
  81. EXPORT_SYMBOL(_find_first_bit_le)
  82. /*
  83. * Purpose : Find next 'one' bit
  84. * Prototype: int find_next_zero_bit(void *addr, unsigned int maxbit, int offset)
  85. */
  86. ENTRY(_find_next_bit_le)
  87. teq r1, #0
  88. beq 3b
  89. ands ip, r2, #7
  90. beq 1b @ If new byte, goto old routine
  91. ARM( ldrb r3, [r0, r2, lsr #3] )
  92. THUMB( lsr r3, r2, #3 )
  93. THUMB( ldrb r3, [r0, r3] )
  94. movs r3, r3, lsr ip @ shift off unused bits
  95. bne .L_found
  96. orr r2, r2, #7 @ if zero, then no bits here
  97. add r2, r2, #1 @ align bit pointer
  98. b 2b @ loop for next bit
  99. ENDPROC(_find_next_bit_le)
  100. EXPORT_SYMBOL(_find_next_bit_le)
  101. #ifdef __ARMEB__
  102. ENTRY(_find_first_zero_bit_be)
  103. teq r1, #0
  104. beq 3f
  105. mov r2, #0
  106. 1: eor r3, r2, #0x18 @ big endian byte ordering
  107. ARM( ldrb r3, [r0, r3, lsr #3] )
  108. THUMB( lsr r3, #3 )
  109. THUMB( ldrb r3, [r0, r3] )
  110. eors r3, r3, #0xff @ invert bits
  111. bne .L_found @ any now set - found zero bit
  112. add r2, r2, #8 @ next bit pointer
  113. 2: cmp r2, r1 @ any more?
  114. blo 1b
  115. 3: mov r0, r1 @ no free bits
  116. ret lr
  117. ENDPROC(_find_first_zero_bit_be)
  118. EXPORT_SYMBOL(_find_first_zero_bit_be)
  119. ENTRY(_find_next_zero_bit_be)
  120. teq r1, #0
  121. beq 3b
  122. ands ip, r2, #7
  123. beq 1b @ If new byte, goto old routine
  124. eor r3, r2, #0x18 @ big endian byte ordering
  125. ARM( ldrb r3, [r0, r3, lsr #3] )
  126. THUMB( lsr r3, #3 )
  127. THUMB( ldrb r3, [r0, r3] )
  128. eor r3, r3, #0xff @ now looking for a 1 bit
  129. movs r3, r3, lsr ip @ shift off unused bits
  130. bne .L_found
  131. orr r2, r2, #7 @ if zero, then no bits here
  132. add r2, r2, #1 @ align bit pointer
  133. b 2b @ loop for next bit
  134. ENDPROC(_find_next_zero_bit_be)
  135. EXPORT_SYMBOL(_find_next_zero_bit_be)
  136. ENTRY(_find_first_bit_be)
  137. teq r1, #0
  138. beq 3f
  139. mov r2, #0
  140. 1: eor r3, r2, #0x18 @ big endian byte ordering
  141. ARM( ldrb r3, [r0, r3, lsr #3] )
  142. THUMB( lsr r3, #3 )
  143. THUMB( ldrb r3, [r0, r3] )
  144. movs r3, r3
  145. bne .L_found @ any now set - found zero bit
  146. add r2, r2, #8 @ next bit pointer
  147. 2: cmp r2, r1 @ any more?
  148. blo 1b
  149. 3: mov r0, r1 @ no free bits
  150. ret lr
  151. ENDPROC(_find_first_bit_be)
  152. EXPORT_SYMBOL(_find_first_bit_be)
  153. ENTRY(_find_next_bit_be)
  154. teq r1, #0
  155. beq 3b
  156. ands ip, r2, #7
  157. beq 1b @ If new byte, goto old routine
  158. eor r3, r2, #0x18 @ big endian byte ordering
  159. ARM( ldrb r3, [r0, r3, lsr #3] )
  160. THUMB( lsr r3, #3 )
  161. THUMB( ldrb r3, [r0, r3] )
  162. movs r3, r3, lsr ip @ shift off unused bits
  163. bne .L_found
  164. orr r2, r2, #7 @ if zero, then no bits here
  165. add r2, r2, #1 @ align bit pointer
  166. b 2b @ loop for next bit
  167. ENDPROC(_find_next_bit_be)
  168. EXPORT_SYMBOL(_find_next_bit_be)
  169. #endif
  170. /*
  171. * One or more bits in the LSB of r3 are assumed to be set.
  172. */
  173. .L_found:
  174. #if __LINUX_ARM_ARCH__ >= 5
  175. rsb r0, r3, #0
  176. and r3, r3, r0
  177. clz r3, r3
  178. rsb r3, r3, #31
  179. add r0, r2, r3
  180. #else
  181. tst r3, #0x0f
  182. addeq r2, r2, #4
  183. movne r3, r3, lsl #4
  184. tst r3, #0x30
  185. addeq r2, r2, #2
  186. movne r3, r3, lsl #2
  187. tst r3, #0x40
  188. addeq r2, r2, #1
  189. mov r0, r2
  190. #endif
  191. cmp r1, r0 @ Clamp to maxbit
  192. movlo r0, r1
  193. ret lr