findbit.S 4.8 KB

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