bitops.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * bitops.h: Bit string operations on the m68k
  3. */
  4. #ifndef _M68K_BITOPS_H
  5. #define _M68K_BITOPS_H
  6. #include <linux/config.h>
  7. #include <asm/byteorder.h>
  8. extern void set_bit(int nr, volatile void *addr);
  9. extern void clear_bit(int nr, volatile void *addr);
  10. extern void change_bit(int nr, volatile void *addr);
  11. extern int test_and_set_bit(int nr, volatile void *addr);
  12. extern int test_and_clear_bit(int nr, volatile void *addr);
  13. extern int test_and_change_bit(int nr, volatile void *addr);
  14. #ifdef __KERNEL__
  15. /*
  16. * ffs: find first bit set. This is defined the same way as
  17. * the libc and compiler builtin ffs routines, therefore
  18. * differs in spirit from the above ffz (man ffs).
  19. */
  20. extern __inline__ int ffs(int x)
  21. {
  22. int r = 1;
  23. if (!x)
  24. return 0;
  25. if (!(x & 0xffff)) {
  26. x >>= 16;
  27. r += 16;
  28. }
  29. if (!(x & 0xff)) {
  30. x >>= 8;
  31. r += 8;
  32. }
  33. if (!(x & 0xf)) {
  34. x >>= 4;
  35. r += 4;
  36. }
  37. if (!(x & 3)) {
  38. x >>= 2;
  39. r += 2;
  40. }
  41. if (!(x & 1)) {
  42. x >>= 1;
  43. r += 1;
  44. }
  45. return r;
  46. }
  47. #define __ffs(x) (ffs(x) - 1)
  48. #endif /* __KERNEL__ */
  49. #endif /* _M68K_BITOPS_H */