bitops.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* $Id: bitops.h,v 1.39 2002/01/30 01:40:00 davem Exp $
  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. #include <linux/compiler.h>
  9. #include <asm/byteorder.h>
  10. extern int test_and_set_bit(unsigned long nr, volatile unsigned long *addr);
  11. extern int test_and_clear_bit(unsigned long nr, volatile unsigned long *addr);
  12. extern int test_and_change_bit(unsigned long nr, volatile unsigned long *addr);
  13. extern void set_bit(unsigned long nr, volatile unsigned long *addr);
  14. extern void clear_bit(unsigned long nr, volatile unsigned long *addr);
  15. extern void change_bit(unsigned long nr, volatile unsigned long *addr);
  16. #include <asm-generic/bitops/non-atomic.h>
  17. #ifdef CONFIG_SMP
  18. #define smp_mb__before_clear_bit() membar_storeload_loadload()
  19. #define smp_mb__after_clear_bit() membar_storeload_storestore()
  20. #else
  21. #define smp_mb__before_clear_bit() barrier()
  22. #define smp_mb__after_clear_bit() barrier()
  23. #endif
  24. #include <asm-generic/bitops/ffz.h>
  25. #include <asm-generic/bitops/__ffs.h>
  26. #include <asm-generic/bitops/fls.h>
  27. #include <asm-generic/bitops/fls64.h>
  28. #ifdef __KERNEL__
  29. #include <asm-generic/bitops/sched.h>
  30. #include <asm-generic/bitops/ffs.h>
  31. /*
  32. * hweightN: returns the hamming weight (i.e. the number
  33. * of bits set) of a N-bit word
  34. */
  35. #ifdef ULTRA_HAS_POPULATION_COUNT
  36. static inline unsigned int hweight64(unsigned long w)
  37. {
  38. unsigned int res;
  39. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w));
  40. return res;
  41. }
  42. static inline unsigned int hweight32(unsigned int w)
  43. {
  44. unsigned int res;
  45. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffffffff));
  46. return res;
  47. }
  48. static inline unsigned int hweight16(unsigned int w)
  49. {
  50. unsigned int res;
  51. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xffff));
  52. return res;
  53. }
  54. static inline unsigned int hweight8(unsigned int w)
  55. {
  56. unsigned int res;
  57. __asm__ ("popc %1,%0" : "=r" (res) : "r" (w & 0xff));
  58. return res;
  59. }
  60. #else
  61. #include <asm-generic/bitops/hweight.h>
  62. #endif
  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) */