findbit.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * linux/arch/unicore32/lib/findbit.S
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/linkage.h>
  13. #include <asm/assembler.h>
  14. .text
  15. /*
  16. * Purpose : Find a 'zero' bit
  17. * Prototype: int find_first_zero_bit(void *addr, unsigned int maxbit);
  18. */
  19. ENTRY(find_first_zero_bit)
  20. cxor.a r1, #0
  21. beq 3f
  22. mov r2, #0
  23. 1: ldb r3, [r0+], r2 >> #3
  24. xor.a r3, r3, #0xff @ invert bits
  25. bne .L_found @ any now set - found zero bit
  26. add r2, r2, #8 @ next bit pointer
  27. 2: csub.a r2, r1 @ any more?
  28. bub 1b
  29. 3: mov r0, r1 @ no free bits
  30. mov pc, lr
  31. ENDPROC(find_first_zero_bit)
  32. /*
  33. * Purpose : Find next 'zero' bit
  34. * Prototype: int find_next_zero_bit
  35. * (void *addr, unsigned int maxbit, int offset)
  36. */
  37. ENTRY(find_next_zero_bit)
  38. cxor.a r1, #0
  39. beq 3b
  40. and.a ip, r2, #7
  41. beq 1b @ If new byte, goto old routine
  42. ldb r3, [r0+], r2 >> #3
  43. xor r3, r3, #0xff @ now looking for a 1 bit
  44. mov.a r3, r3 >> ip @ shift off unused bits
  45. bne .L_found
  46. or r2, r2, #7 @ if zero, then no bits here
  47. add r2, r2, #1 @ align bit pointer
  48. b 2b @ loop for next bit
  49. ENDPROC(find_next_zero_bit)
  50. /*
  51. * Purpose : Find a 'one' bit
  52. * Prototype: int find_first_bit
  53. * (const unsigned long *addr, unsigned int maxbit);
  54. */
  55. ENTRY(find_first_bit)
  56. cxor.a r1, #0
  57. beq 3f
  58. mov r2, #0
  59. 1: ldb r3, [r0+], r2 >> #3
  60. mov.a r3, r3
  61. bne .L_found @ any now set - found zero bit
  62. add r2, r2, #8 @ next bit pointer
  63. 2: csub.a r2, r1 @ any more?
  64. bub 1b
  65. 3: mov r0, r1 @ no free bits
  66. mov pc, lr
  67. ENDPROC(find_first_bit)
  68. /*
  69. * Purpose : Find next 'one' bit
  70. * Prototype: int find_next_zero_bit
  71. * (void *addr, unsigned int maxbit, int offset)
  72. */
  73. ENTRY(find_next_bit)
  74. cxor.a r1, #0
  75. beq 3b
  76. and.a ip, r2, #7
  77. beq 1b @ If new byte, goto old routine
  78. ldb r3, [r0+], r2 >> #3
  79. mov.a r3, r3 >> ip @ shift off unused bits
  80. bne .L_found
  81. or r2, r2, #7 @ if zero, then no bits here
  82. add r2, r2, #1 @ align bit pointer
  83. b 2b @ loop for next bit
  84. ENDPROC(find_next_bit)
  85. /*
  86. * One or more bits in the LSB of r3 are assumed to be set.
  87. */
  88. .L_found:
  89. rsub r1, r3, #0
  90. and r3, r3, r1
  91. cntlz r3, r3
  92. rsub r3, r3, #31
  93. add r0, r2, r3
  94. mov pc, lr