bitops.h 2.4 KB

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