bitops.h 2.4 KB

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