bitops.h 1.4 KB

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