bitops.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef _ASM_CRIS_ARCH_BITOPS_H
  2. #define _ASM_CRIS_ARCH_BITOPS_H
  3. /*
  4. * Helper functions for the core of the ff[sz] functions. They compute the
  5. * number of leading zeroes of a bits-in-byte, byte-in-word and
  6. * word-in-dword-swapped number. They differ in that the first function also
  7. * inverts all bits in the input.
  8. */
  9. extern inline unsigned long
  10. cris_swapnwbrlz(unsigned long w)
  11. {
  12. unsigned long res;
  13. __asm__ __volatile__ ("swapnwbr %0\n\t"
  14. "lz %0,%0"
  15. : "=r" (res) : "0" (w));
  16. return res;
  17. }
  18. extern inline unsigned long
  19. cris_swapwbrlz(unsigned long w)
  20. {
  21. unsigned long res;
  22. __asm__ __volatile__ ("swapwbr %0\n\t"
  23. "lz %0,%0"
  24. : "=r" (res) : "0" (w));
  25. return res;
  26. }
  27. /*
  28. * Find First Zero in word. Undefined if no zero exist, so the caller should
  29. * check against ~0 first.
  30. */
  31. extern inline unsigned long
  32. ffz(unsigned long w)
  33. {
  34. return cris_swapnwbrlz(w);
  35. }
  36. /*
  37. * Find First Set bit in word. Undefined if no 1 exist, so the caller
  38. * should check against 0 first.
  39. */
  40. extern inline unsigned long
  41. __ffs(unsigned long w)
  42. {
  43. return cris_swapnwbrlz(~w);
  44. }
  45. /*
  46. * Find First Bit that is set.
  47. */
  48. extern inline unsigned long
  49. kernel_ffs(unsigned long w)
  50. {
  51. return w ? cris_swapwbrlz (w) + 1 : 0;
  52. }
  53. #endif /* _ASM_CRIS_ARCH_BITOPS_H */