__ffs.h 738 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef _ASM_GENERIC_BITOPS___FFS_H_
  2. #define _ASM_GENERIC_BITOPS___FFS_H_
  3. #include <asm/types.h>
  4. /**
  5. * __ffs - find first bit in word.
  6. * @word: The word to search
  7. *
  8. * Undefined if no bit exists, so code should check against 0 first.
  9. */
  10. static __always_inline unsigned long __ffs(unsigned long word)
  11. {
  12. int num = 0;
  13. #if BITS_PER_LONG == 64
  14. if ((word & 0xffffffff) == 0) {
  15. num += 32;
  16. word >>= 32;
  17. }
  18. #endif
  19. if ((word & 0xffff) == 0) {
  20. num += 16;
  21. word >>= 16;
  22. }
  23. if ((word & 0xff) == 0) {
  24. num += 8;
  25. word >>= 8;
  26. }
  27. if ((word & 0xf) == 0) {
  28. num += 4;
  29. word >>= 4;
  30. }
  31. if ((word & 0x3) == 0) {
  32. num += 2;
  33. word >>= 2;
  34. }
  35. if ((word & 0x1) == 0)
  36. num += 1;
  37. return num;
  38. }
  39. #endif /* _ASM_GENERIC_BITOPS___FFS_H_ */