bitops_64.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * bitops.h: Bit string operations on the V9.
  3. *
  4. * Copyright 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
  5. */
  6. #ifndef _SPARC64_BITOPS_H
  7. #define _SPARC64_BITOPS_H
  8. #ifndef _LINUX_BITOPS_H
  9. #error only <linux/bitops.h> can be included directly
  10. #endif
  11. #include <linux/compiler.h>
  12. #include <asm/byteorder.h>
  13. extern int test_and_set_bit(unsigned long nr, volatile unsigned long *addr);
  14. extern int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr);
  15. extern int test_and_change_bit(unsigned long nr, volatile unsigned long *addr);
  16. extern void set_bit(unsigned long nr, volatile unsigned long *addr);
  17. extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
  18. extern void change_bit(unsigned long nr, volatile unsigned long *addr);
  19. #include <asm-generic/bitops/non-atomic.h>
  20. #define smp_mb__before_clear_bit() barrier()
  21. #define smp_mb__after_clear_bit() barrier()
  22. #include <asm-generic/bitops/ffz.h>
  23. #include <asm-generic/bitops/__ffs.h>
  24. #include <asm-generic/bitops/fls.h>
  25. #include <asm-generic/bitops/__fls.h>
  26. #include <asm-generic/bitops/fls64.h>
  27. #ifdef __KERNEL__
  28. #include <asm-generic/bitops/sched.h>
  29. #include <asm-generic/bitops/ffs.h>
  30. /*
  31. * hweightN: returns the hamming weight (i.e. the number
  32. * of bits set) of a N-bit word
  33. */
  34. #ifdef ULTRA_HAS_POPULATION_COUNT
  35. static inline unsigned int hweight64(unsigned long w)
  36. {
  37. unsigned int res;
  38. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
  39. return res;
  40. }
  41. static inline unsigned int hweight32(unsigned int w)
  42. {
  43. unsigned int res;
  44. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
  45. return res;
  46. }
  47. static inline unsigned int hweight16(unsigned int w)
  48. {
  49. unsigned int res;
  50. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
  51. return res;
  52. }
  53. static inline unsigned int hweight8(unsigned int w)
  54. {
  55. unsigned int res;
  56. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
  57. return res;
  58. }
  59. #else
  60. #include <asm-generic/bitops/hweight.h>
  61. #endif
  62. #include <asm-generic/bitops/lock.h>
  63. #endif /* __KERNEL__ */
  64. #include <asm-generic/bitops/find.h>
  65. #ifdef __KERNEL__
  66. #include <asm-generic/bitops/ext2-non-atomic.h>
  67. #define ext2_set_bit_atomic(lock,nr,addr) \
  68. test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
  69. #define ext2_clear_bit_atomic(lock,nr,addr) \
  70. test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
  71. #include <asm-generic/bitops/minix.h>
  72. #endif /* __KERNEL__ */
  73. #endif /* defined(_SPARC64_BITOPS_H) */