bitops.h 2.3 KB

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