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