bitops_64.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #ifdef CONFIG_SMP
  21. #define smp_mb__before_clear_bit() membar_storeload_loadload()
  22. #define smp_mb__after_clear_bit() membar_storeload_storestore()
  23. #else
  24. #define smp_mb__before_clear_bit() barrier()
  25. #define smp_mb__after_clear_bit() barrier()
  26. #endif
  27. #include <asm-generic/bitops/ffz.h>
  28. #include <asm-generic/bitops/__ffs.h>
  29. #include <asm-generic/bitops/fls.h>
  30. #include <asm-generic/bitops/__fls.h>
  31. #include <asm-generic/bitops/fls64.h>
  32. #ifdef __KERNEL__
  33. #include <asm-generic/bitops/sched.h>
  34. #include <asm-generic/bitops/ffs.h>
  35. /*
  36. * hweightN: returns the hamming weight (i.e. the number
  37. * of bits set) of a N-bit word
  38. */
  39. #ifdef ULTRA_HAS_POPULATION_COUNT
  40. static inline unsigned int hweight64(unsigned long w)
  41. {
  42. unsigned int res;
  43. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
  44. return res;
  45. }
  46. static inline unsigned int hweight32(unsigned int w)
  47. {
  48. unsigned int res;
  49. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
  50. return res;
  51. }
  52. static inline unsigned int hweight16(unsigned int w)
  53. {
  54. unsigned int res;
  55. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
  56. return res;
  57. }
  58. static inline unsigned int hweight8(unsigned int w)
  59. {
  60. unsigned int res;
  61. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
  62. return res;
  63. }
  64. #else
  65. #include <asm-generic/bitops/hweight.h>
  66. #endif
  67. #include <asm-generic/bitops/lock.h>
  68. #endif /* __KERNEL__ */
  69. #include <asm-generic/bitops/find.h>
  70. #ifdef __KERNEL__
  71. #include <asm-generic/bitops/ext2-non-atomic.h>
  72. #define ext2_set_bit_atomic(lock,nr,addr) \
  73. test_and_set_bit((nr) ^ 0x38,(unsigned long *)(addr))
  74. #define ext2_clear_bit_atomic(lock,nr,addr) \
  75. test_and_clear_bit((nr) ^ 0x38,(unsigned long *)(addr))
  76. #include <asm-generic/bitops/minix.h>
  77. #endif /* __KERNEL__ */
  78. #endif /* defined(_SPARC64_BITOPS_H) */