findbit.S 4.1 KB

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