bitops.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef __ASM_SH_BITOPS_H
  2. #define __ASM_SH_BITOPS_H
  3. #ifdef __KERNEL__
  4. #ifndef _LINUX_BITOPS_H
  5. #error only <linux/bitops.h> can be included directly
  6. #endif
  7. #include <asm/system.h>
  8. /* For __swab32 */
  9. #include <asm/byteorder.h>
  10. #ifdef CONFIG_GUSA_RB
  11. #include <asm/bitops-grb.h>
  12. #elif defined(CONFIG_CPU_SH2A)
  13. #include <asm-generic/bitops/atomic.h>
  14. #include <asm/bitops-op32.h>
  15. #elif defined(CONFIG_CPU_SH4A)
  16. #include <asm/bitops-llsc.h>
  17. #else
  18. #include <asm-generic/bitops/atomic.h>
  19. #include <asm-generic/bitops/non-atomic.h>
  20. #endif
  21. /*
  22. * clear_bit() doesn't provide any barrier for the compiler.
  23. */
  24. #define smp_mb__before_clear_bit() smp_mb()
  25. #define smp_mb__after_clear_bit() smp_mb()
  26. #ifdef CONFIG_SUPERH32
  27. static inline unsigned long ffz(unsigned long word)
  28. {
  29. unsigned long result;
  30. __asm__("1:\n\t"
  31. "shlr %1\n\t"
  32. "bt/s 1b\n\t"
  33. " add #1, %0"
  34. : "=r" (result), "=r" (word)
  35. : "0" (~0L), "1" (word)
  36. : "t");
  37. return result;
  38. }
  39. /**
  40. * __ffs - find first bit in word.
  41. * @word: The word to search
  42. *
  43. * Undefined if no bit exists, so code should check against 0 first.
  44. */
  45. static inline unsigned long __ffs(unsigned long word)
  46. {
  47. unsigned long result;
  48. __asm__("1:\n\t"
  49. "shlr %1\n\t"
  50. "bf/s 1b\n\t"
  51. " add #1, %0"
  52. : "=r" (result), "=r" (word)
  53. : "0" (~0L), "1" (word)
  54. : "t");
  55. return result;
  56. }
  57. #else
  58. static inline unsigned long ffz(unsigned long word)
  59. {
  60. unsigned long result, __d2, __d3;
  61. __asm__("gettr tr0, %2\n\t"
  62. "pta $+32, tr0\n\t"
  63. "andi %1, 1, %3\n\t"
  64. "beq %3, r63, tr0\n\t"
  65. "pta $+4, tr0\n"
  66. "0:\n\t"
  67. "shlri.l %1, 1, %1\n\t"
  68. "addi %0, 1, %0\n\t"
  69. "andi %1, 1, %3\n\t"
  70. "beqi %3, 1, tr0\n"
  71. "1:\n\t"
  72. "ptabs %2, tr0\n\t"
  73. : "=r" (result), "=r" (word), "=r" (__d2), "=r" (__d3)
  74. : "0" (0L), "1" (word));
  75. return result;
  76. }
  77. #include <asm-generic/bitops/__ffs.h>
  78. #endif
  79. #include <asm-generic/bitops/find.h>
  80. #include <asm-generic/bitops/ffs.h>
  81. #include <asm-generic/bitops/hweight.h>
  82. #include <asm-generic/bitops/lock.h>
  83. #include <asm-generic/bitops/sched.h>
  84. #include <asm-generic/bitops/le.h>
  85. #include <asm-generic/bitops/ext2-atomic.h>
  86. #include <asm-generic/bitops/fls.h>
  87. #include <asm-generic/bitops/__fls.h>
  88. #include <asm-generic/bitops/fls64.h>
  89. #endif /* __KERNEL__ */
  90. #endif /* __ASM_SH_BITOPS_H */