bitops_32.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _I386_BITOPS_H
  2. #define _I386_BITOPS_H
  3. /*
  4. * Copyright 1992, Linus Torvalds.
  5. */
  6. /**
  7. * find_first_zero_bit - find the first zero bit in a memory region
  8. * @addr: The address to start the search at
  9. * @size: The maximum size to search
  10. *
  11. * Returns the bit number of the first zero bit, not the number of the byte
  12. * containing a bit.
  13. */
  14. static inline int find_first_zero_bit(const unsigned long *addr, unsigned size)
  15. {
  16. int d0, d1, d2;
  17. int res;
  18. if (!size)
  19. return 0;
  20. /* This looks at memory.
  21. * Mark it volatile to tell gcc not to move it around
  22. */
  23. asm volatile("movl $-1,%%eax\n\t"
  24. "xorl %%edx,%%edx\n\t"
  25. "repe; scasl\n\t"
  26. "je 1f\n\t"
  27. "xorl -4(%%edi),%%eax\n\t"
  28. "subl $4,%%edi\n\t"
  29. "bsfl %%eax,%%edx\n"
  30. "1:\tsubl %%ebx,%%edi\n\t"
  31. "shll $3,%%edi\n\t"
  32. "addl %%edi,%%edx"
  33. : "=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2)
  34. : "1" ((size + 31) >> 5), "2" (addr),
  35. "b" (addr) : "memory");
  36. return res;
  37. }
  38. /**
  39. * find_first_bit - find the first set bit in a memory region
  40. * @addr: The address to start the search at
  41. * @size: The maximum size to search
  42. *
  43. * Returns the bit number of the first set bit, not the number of the byte
  44. * containing a bit.
  45. */
  46. static inline unsigned find_first_bit(const unsigned long *addr, unsigned size)
  47. {
  48. unsigned x = 0;
  49. while (x < size) {
  50. unsigned long val = *addr++;
  51. if (val)
  52. return __ffs(val) + x;
  53. x += sizeof(*addr) << 3;
  54. }
  55. return x;
  56. }
  57. #ifdef __KERNEL__
  58. #include <asm-generic/bitops/sched.h>
  59. #include <asm-generic/bitops/hweight.h>
  60. #endif /* __KERNEL__ */
  61. #include <asm-generic/bitops/fls64.h>
  62. #ifdef __KERNEL__
  63. #include <asm-generic/bitops/ext2-non-atomic.h>
  64. #define ext2_set_bit_atomic(lock, nr, addr) \
  65. test_and_set_bit((nr), (unsigned long *)(addr))
  66. #define ext2_clear_bit_atomic(lock, nr, addr) \
  67. test_and_clear_bit((nr), (unsigned long *)(addr))
  68. #include <asm-generic/bitops/minix.h>
  69. #endif /* __KERNEL__ */
  70. #endif /* _I386_BITOPS_H */