bitops.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #ifndef _BLACKFIN_BITOPS_H
  7. #define _BLACKFIN_BITOPS_H
  8. #include <linux/compiler.h>
  9. #include <asm-generic/bitops/__ffs.h>
  10. #include <asm-generic/bitops/ffz.h>
  11. #include <asm-generic/bitops/fls.h>
  12. #include <asm-generic/bitops/__fls.h>
  13. #include <asm-generic/bitops/fls64.h>
  14. #include <asm-generic/bitops/find.h>
  15. #ifndef _LINUX_BITOPS_H
  16. #error only <linux/bitops.h> can be included directly
  17. #endif
  18. #include <asm-generic/bitops/sched.h>
  19. #include <asm-generic/bitops/ffs.h>
  20. #include <asm-generic/bitops/const_hweight.h>
  21. #include <asm-generic/bitops/lock.h>
  22. #include <asm-generic/bitops/ext2-non-atomic.h>
  23. #include <asm-generic/bitops/ext2-atomic.h>
  24. #include <asm-generic/bitops/minix.h>
  25. #ifndef CONFIG_SMP
  26. #include <linux/irqflags.h>
  27. /*
  28. * clear_bit may not imply a memory barrier
  29. */
  30. #ifndef smp_mb__before_clear_bit
  31. #define smp_mb__before_clear_bit() smp_mb()
  32. #define smp_mb__after_clear_bit() smp_mb()
  33. #endif
  34. #include <asm-generic/bitops/atomic.h>
  35. #include <asm-generic/bitops/non-atomic.h>
  36. #else
  37. #include <asm/byteorder.h> /* swab32 */
  38. #include <linux/linkage.h>
  39. asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
  40. asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
  41. asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
  42. asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
  43. asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
  44. asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
  45. asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
  46. static inline void set_bit(int nr, volatile unsigned long *addr)
  47. {
  48. volatile unsigned long *a = addr + (nr >> 5);
  49. __raw_bit_set_asm(a, nr & 0x1f);
  50. }
  51. static inline void clear_bit(int nr, volatile unsigned long *addr)
  52. {
  53. volatile unsigned long *a = addr + (nr >> 5);
  54. __raw_bit_clear_asm(a, nr & 0x1f);
  55. }
  56. static inline void change_bit(int nr, volatile unsigned long *addr)
  57. {
  58. volatile unsigned long *a = addr + (nr >> 5);
  59. __raw_bit_toggle_asm(a, nr & 0x1f);
  60. }
  61. static inline int test_bit(int nr, const volatile unsigned long *addr)
  62. {
  63. volatile const unsigned long *a = addr + (nr >> 5);
  64. return __raw_bit_test_asm(a, nr & 0x1f) != 0;
  65. }
  66. static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
  67. {
  68. volatile unsigned long *a = addr + (nr >> 5);
  69. return __raw_bit_test_set_asm(a, nr & 0x1f);
  70. }
  71. static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
  72. {
  73. volatile unsigned long *a = addr + (nr >> 5);
  74. return __raw_bit_test_clear_asm(a, nr & 0x1f);
  75. }
  76. static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
  77. {
  78. volatile unsigned long *a = addr + (nr >> 5);
  79. return __raw_bit_test_toggle_asm(a, nr & 0x1f);
  80. }
  81. /*
  82. * clear_bit() doesn't provide any barrier for the compiler.
  83. */
  84. #define smp_mb__before_clear_bit() barrier()
  85. #define smp_mb__after_clear_bit() barrier()
  86. #include <asm-generic/bitops/non-atomic.h>
  87. #endif /* CONFIG_SMP */
  88. /*
  89. * hweightN: returns the hamming weight (i.e. the number
  90. * of bits set) of a N-bit word
  91. */
  92. static inline unsigned int __arch_hweight32(unsigned int w)
  93. {
  94. unsigned int res;
  95. __asm__ ("%0.l = ONES %1;"
  96. "%0 = %0.l (Z);"
  97. : "=d" (res) : "d" (w));
  98. return res;
  99. }
  100. static inline unsigned int __arch_hweight64(__u64 w)
  101. {
  102. return __arch_hweight32((unsigned int)(w >> 32)) +
  103. __arch_hweight32((unsigned int)w);
  104. }
  105. static inline unsigned int __arch_hweight16(unsigned int w)
  106. {
  107. return __arch_hweight32(w & 0xffff);
  108. }
  109. static inline unsigned int __arch_hweight8(unsigned int w)
  110. {
  111. return __arch_hweight32(w & 0xff);
  112. }
  113. #endif /* _BLACKFIN_BITOPS_H */