bitops.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * bitops.h: Bit string operations on the m68k
  3. */
  4. #ifndef _M68K_BITOPS_H
  5. #define _M68K_BITOPS_H
  6. #include <asm/byteorder.h>
  7. #include <asm-generic/bitops/fls.h>
  8. #include <asm-generic/bitops/__fls.h>
  9. #include <asm-generic/bitops/fls64.h>
  10. #include <asm-generic/bitops/__ffs.h>
  11. extern void set_bit(int nr, volatile void *addr);
  12. extern void clear_bit(int nr, volatile void *addr);
  13. extern void change_bit(int nr, volatile void *addr);
  14. extern int test_and_clear_bit(int nr, volatile void *addr);
  15. extern int test_and_change_bit(int nr, volatile void *addr);
  16. #ifdef __KERNEL__
  17. static inline int test_bit(int nr, __const__ volatile void *addr)
  18. {
  19. __const__ unsigned int *p = (__const__ unsigned int *) addr;
  20. return (p[nr >> 5] & (1UL << (nr & 31))) != 0;
  21. }
  22. static inline int test_and_set_bit(int nr, volatile void *vaddr)
  23. {
  24. char retval;
  25. volatile char *p = &((volatile char *)vaddr)[(nr^31) >> 3];
  26. __asm__ __volatile__ ("bset %2,(%4); sne %0"
  27. : "=d" (retval), "=m" (*p)
  28. : "di" (nr & 7), "m" (*p), "a" (p));
  29. return retval;
  30. }
  31. #define __ffs(x) (ffs(x) - 1)
  32. /*
  33. * * hweightN: returns the hamming weight (i.e. the number
  34. * * of bits set) of a N-bit word
  35. * */
  36. #define hweight32(x) generic_hweight32(x)
  37. #define hweight16(x) generic_hweight16(x)
  38. #define hweight8(x) generic_hweight8(x)
  39. #endif /* __KERNEL__ */
  40. #endif /* _M68K_BITOPS_H */