bitops.h 2.4 KB

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