bitops.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_BITOPS_H
  3. #define __ASM_SH_BITOPS_H
  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. #include <asm/barrier.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. #elif defined(CONFIG_CPU_J2) && defined(CONFIG_SMP)
  18. #include <asm/bitops-cas.h>
  19. #else
  20. #include <asm-generic/bitops/atomic.h>
  21. #include <asm-generic/bitops/non-atomic.h>
  22. #endif
  23. static inline unsigned long ffz(unsigned long word)
  24. {
  25. unsigned long result;
  26. __asm__("1:\n\t"
  27. "shlr %1\n\t"
  28. "bt/s 1b\n\t"
  29. " add #1, %0"
  30. : "=r" (result), "=r" (word)
  31. : "0" (~0L), "1" (word)
  32. : "t");
  33. return result;
  34. }
  35. /**
  36. * __ffs - find first bit in word.
  37. * @word: The word to search
  38. *
  39. * Undefined if no bit exists, so code should check against 0 first.
  40. */
  41. static inline unsigned long __ffs(unsigned long word)
  42. {
  43. unsigned long result;
  44. __asm__("1:\n\t"
  45. "shlr %1\n\t"
  46. "bf/s 1b\n\t"
  47. " add #1, %0"
  48. : "=r" (result), "=r" (word)
  49. : "0" (~0L), "1" (word)
  50. : "t");
  51. return result;
  52. }
  53. #include <asm-generic/bitops/ffs.h>
  54. #include <asm-generic/bitops/hweight.h>
  55. #include <asm-generic/bitops/lock.h>
  56. #include <asm-generic/bitops/sched.h>
  57. #include <asm-generic/bitops/ext2-atomic.h>
  58. #include <asm-generic/bitops/fls.h>
  59. #include <asm-generic/bitops/__fls.h>
  60. #include <asm-generic/bitops/fls64.h>
  61. #include <asm-generic/bitops/le.h>
  62. #endif /* __ASM_SH_BITOPS_H */