findbit.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. __uc32_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. /*
  32. * Purpose : Find next 'zero' bit
  33. * Prototype: int find_next_zero_bit
  34. * (void *addr, unsigned int maxbit, int offset)
  35. */
  36. ENTRY(__uc32_find_next_zero_bit)
  37. cxor.a r1, #0
  38. beq 3b
  39. and.a ip, r2, #7
  40. beq 1b @ If new byte, goto old routine
  41. ldb r3, [r0+], r2 >> #3
  42. xor r3, r3, #0xff @ now looking for a 1 bit
  43. mov.a r3, r3 >> ip @ shift off unused bits
  44. bne .L_found
  45. or r2, r2, #7 @ if zero, then no bits here
  46. add r2, r2, #1 @ align bit pointer
  47. b 2b @ loop for next bit
  48. ENDPROC(__uc32_find_next_zero_bit)
  49. /*
  50. * Purpose : Find a 'one' bit
  51. * Prototype: int find_first_bit
  52. * (const unsigned long *addr, unsigned int maxbit);
  53. */
  54. __uc32_find_first_bit:
  55. cxor.a r1, #0
  56. beq 3f
  57. mov r2, #0
  58. 1: ldb r3, [r0+], r2 >> #3
  59. mov.a r3, r3
  60. bne .L_found @ any now set - found zero bit
  61. add r2, r2, #8 @ next bit pointer
  62. 2: csub.a r2, r1 @ any more?
  63. bub 1b
  64. 3: mov r0, r1 @ no free bits
  65. mov pc, lr
  66. /*
  67. * Purpose : Find next 'one' bit
  68. * Prototype: int find_next_zero_bit
  69. * (void *addr, unsigned int maxbit, int offset)
  70. */
  71. ENTRY(__uc32_find_next_bit)
  72. cxor.a r1, #0
  73. beq 3b
  74. and.a ip, r2, #7
  75. beq 1b @ If new byte, goto old routine
  76. ldb r3, [r0+], r2 >> #3
  77. mov.a r3, r3 >> ip @ shift off unused bits
  78. bne .L_found
  79. or 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. ENDPROC(__uc32_find_next_bit)
  83. /*
  84. * One or more bits in the LSB of r3 are assumed to be set.
  85. */
  86. .L_found:
  87. rsub r1, r3, #0
  88. and r3, r3, r1
  89. cntlz r3, r3
  90. rsub r3, r3, #31
  91. add r0, r2, r3
  92. mov pc, lr