bitops.h 2.5 KB

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