findbit.S 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 2b
  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. * One or more bits in the LSB of r3 are assumed to be set.
  53. */
  54. .found: tst r3, #0x0f
  55. addeq r2, r2, #4
  56. movne r3, r3, lsl #4
  57. tst r3, #0x30
  58. addeq r2, r2, #2
  59. movne r3, r3, lsl #2
  60. tst r3, #0x40
  61. addeq r2, r2, #1
  62. mov r0, r2
  63. RETINSTR(mov,pc,lr)