bitops.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_CSKY_BITOPS_H
  3. #define __ASM_CSKY_BITOPS_H
  4. #include <linux/compiler.h>
  5. #include <asm/barrier.h>
  6. /*
  7. * asm-generic/bitops/ffs.h
  8. */
  9. static inline int ffs(int x)
  10. {
  11. if (!x)
  12. return 0;
  13. asm volatile (
  14. "brev %0\n"
  15. "ff1 %0\n"
  16. "addi %0, 1\n"
  17. : "=&r"(x)
  18. : "0"(x));
  19. return x;
  20. }
  21. /*
  22. * asm-generic/bitops/__ffs.h
  23. */
  24. static __always_inline unsigned long __ffs(unsigned long x)
  25. {
  26. asm volatile (
  27. "brev %0\n"
  28. "ff1 %0\n"
  29. : "=&r"(x)
  30. : "0"(x));
  31. return x;
  32. }
  33. /*
  34. * asm-generic/bitops/fls.h
  35. */
  36. static __always_inline int fls(unsigned int x)
  37. {
  38. asm volatile(
  39. "ff1 %0\n"
  40. : "=&r"(x)
  41. : "0"(x));
  42. return (32 - x);
  43. }
  44. /*
  45. * asm-generic/bitops/__fls.h
  46. */
  47. static __always_inline unsigned long __fls(unsigned long x)
  48. {
  49. return fls(x) - 1;
  50. }
  51. #include <asm-generic/bitops/ffz.h>
  52. #include <asm-generic/bitops/fls64.h>
  53. #ifndef _LINUX_BITOPS_H
  54. #error only <linux/bitops.h> can be included directly
  55. #endif
  56. #include <asm-generic/bitops/sched.h>
  57. #include <asm-generic/bitops/hweight.h>
  58. #include <asm-generic/bitops/lock.h>
  59. #include <asm-generic/bitops/atomic.h>
  60. /*
  61. * bug fix, why only could use atomic!!!!
  62. */
  63. #include <asm-generic/bitops/non-atomic.h>
  64. #include <asm-generic/bitops/le.h>
  65. #include <asm-generic/bitops/ext2-atomic.h>
  66. #endif /* __ASM_CSKY_BITOPS_H */