bitops.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * linux/arch/unicore32/include/asm/bitops.h
  3. *
  4. * Code specific to PKUnity SoC and UniCore ISA
  5. *
  6. * Copyright (C) 2001-2010 GUAN Xue-tao
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __UNICORE_BITOPS_H__
  13. #define __UNICORE_BITOPS_H__
  14. #define _ASM_GENERIC_BITOPS_FLS_H_
  15. #define _ASM_GENERIC_BITOPS___FLS_H_
  16. #define _ASM_GENERIC_BITOPS_FFS_H_
  17. #define _ASM_GENERIC_BITOPS___FFS_H_
  18. /*
  19. * On UNICORE, those functions can be implemented around
  20. * the cntlz instruction for much better code efficiency.
  21. */
  22. static inline int fls(int x)
  23. {
  24. int ret;
  25. asm("cntlz\t%0, %1" : "=r" (ret) : "r" (x) : "cc");
  26. ret = 32 - ret;
  27. return ret;
  28. }
  29. #define __fls(x) (fls(x) - 1)
  30. #define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
  31. #define __ffs(x) (ffs(x) - 1)
  32. #include <asm-generic/bitops.h>
  33. /* following definitions: to avoid using codes in lib/find_*.c */
  34. #define find_next_bit find_next_bit
  35. #define find_next_zero_bit find_next_zero_bit
  36. #define find_first_bit find_first_bit
  37. #define find_first_zero_bit find_first_zero_bit
  38. #endif /* __UNICORE_BITOPS_H__ */