bitops.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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-atomic.h>
  23. #include <asm/barrier.h>
  24. #ifndef CONFIG_SMP
  25. #include <linux/irqflags.h>
  26. /*
  27. * clear_bit may not imply a memory barrier
  28. */
  29. #include <asm-generic/bitops/atomic.h>
  30. #include <asm-generic/bitops/non-atomic.h>
  31. #else
  32. #include <asm/byteorder.h> /* swab32 */
  33. #include <linux/linkage.h>
  34. asmlinkage int __raw_bit_set_asm(volatile unsigned long *addr, int nr);
  35. asmlinkage int __raw_bit_clear_asm(volatile unsigned long *addr, int nr);
  36. asmlinkage int __raw_bit_toggle_asm(volatile unsigned long *addr, int nr);
  37. asmlinkage int __raw_bit_test_set_asm(volatile unsigned long *addr, int nr);
  38. asmlinkage int __raw_bit_test_clear_asm(volatile unsigned long *addr, int nr);
  39. asmlinkage int __raw_bit_test_toggle_asm(volatile unsigned long *addr, int nr);
  40. asmlinkage int __raw_bit_test_asm(const volatile unsigned long *addr, int nr);
  41. static inline void set_bit(int nr, volatile unsigned long *addr)
  42. {
  43. volatile unsigned long *a = addr + (nr >> 5);
  44. __raw_bit_set_asm(a, nr & 0x1f);
  45. }
  46. static inline void clear_bit(int nr, volatile unsigned long *addr)
  47. {
  48. volatile unsigned long *a = addr + (nr >> 5);
  49. __raw_bit_clear_asm(a, nr & 0x1f);
  50. }
  51. static inline void change_bit(int nr, volatile unsigned long *addr)
  52. {
  53. volatile unsigned long *a = addr + (nr >> 5);
  54. __raw_bit_toggle_asm(a, nr & 0x1f);
  55. }
  56. static inline int test_bit(int nr, const volatile unsigned long *addr)
  57. {
  58. volatile const unsigned long *a = addr + (nr >> 5);
  59. return __raw_bit_test_asm(a, nr & 0x1f) != 0;
  60. }
  61. static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
  62. {
  63. volatile unsigned long *a = addr + (nr >> 5);
  64. return __raw_bit_test_set_asm(a, nr & 0x1f);
  65. }
  66. static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
  67. {
  68. volatile unsigned long *a = addr + (nr >> 5);
  69. return __raw_bit_test_clear_asm(a, nr & 0x1f);
  70. }
  71. static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
  72. {
  73. volatile unsigned long *a = addr + (nr >> 5);
  74. return __raw_bit_test_toggle_asm(a, nr & 0x1f);
  75. }
  76. #define test_bit __skip_test_bit
  77. #include <asm-generic/bitops/non-atomic.h>
  78. #undef test_bit
  79. #endif /* CONFIG_SMP */
  80. /* Needs to be after test_bit and friends */
  81. #include <asm-generic/bitops/le.h>
  82. /*
  83. * hweightN: returns the hamming weight (i.e. the number
  84. * of bits set) of a N-bit word
  85. */
  86. static inline unsigned int __arch_hweight32(unsigned int w)
  87. {
  88. unsigned int res;
  89. __asm__ ("%0.l = ONES %1;"
  90. "%0 = %0.l (Z);"
  91. : "=d" (res) : "d" (w));
  92. return res;
  93. }
  94. static inline unsigned int __arch_hweight64(__u64 w)
  95. {
  96. return __arch_hweight32((unsigned int)(w >> 32)) +
  97. __arch_hweight32((unsigned int)w);
  98. }
  99. static inline unsigned int __arch_hweight16(unsigned int w)
  100. {
  101. return __arch_hweight32(w & 0xffff);
  102. }
  103. static inline unsigned int __arch_hweight8(unsigned int w)
  104. {
  105. return __arch_hweight32(w & 0xff);
  106. }
  107. #endif /* _BLACKFIN_BITOPS_H */