bitops.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 1992, Linus Torvalds.
  3. * Copyright 2010 Tilera Corporation. All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation, version 2.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  12. * NON INFRINGEMENT. See the GNU General Public License for
  13. * more details.
  14. */
  15. #ifndef _ASM_TILE_BITOPS_H
  16. #define _ASM_TILE_BITOPS_H
  17. #include <linux/types.h>
  18. #include <asm/barrier.h>
  19. #ifndef _LINUX_BITOPS_H
  20. #error only <linux/bitops.h> can be included directly
  21. #endif
  22. #ifdef __tilegx__
  23. #include <asm/bitops_64.h>
  24. #else
  25. #include <asm/bitops_32.h>
  26. #endif
  27. /**
  28. * ffz - find first zero bit in word
  29. * @word: The word to search
  30. *
  31. * Undefined if no zero exists, so code should check against ~0UL first.
  32. */
  33. static inline unsigned long ffz(unsigned long word)
  34. {
  35. return __builtin_ctzl(~word);
  36. }
  37. static inline int fls64(__u64 w)
  38. {
  39. return (sizeof(__u64) * 8) - __builtin_clzll(w);
  40. }
  41. /**
  42. * fls - find last set bit in word
  43. * @x: the word to search
  44. *
  45. * This is defined in a similar way as the libc and compiler builtin
  46. * ffs, but returns the position of the most significant set bit.
  47. *
  48. * fls(value) returns 0 if value is 0 or the position of the last
  49. * set bit if value is nonzero. The last (most significant) bit is
  50. * at position 32.
  51. */
  52. static inline int fls(int x)
  53. {
  54. return fls64((unsigned int) x);
  55. }
  56. static inline unsigned int __arch_hweight32(unsigned int w)
  57. {
  58. return __builtin_popcount(w);
  59. }
  60. static inline unsigned int __arch_hweight16(unsigned int w)
  61. {
  62. return __builtin_popcount(w & 0xffff);
  63. }
  64. static inline unsigned int __arch_hweight8(unsigned int w)
  65. {
  66. return __builtin_popcount(w & 0xff);
  67. }
  68. static inline unsigned long __arch_hweight64(__u64 w)
  69. {
  70. return __builtin_popcountll(w);
  71. }
  72. #include <asm-generic/bitops/builtin-__ffs.h>
  73. #include <asm-generic/bitops/builtin-__fls.h>
  74. #include <asm-generic/bitops/builtin-ffs.h>
  75. #include <asm-generic/bitops/const_hweight.h>
  76. #include <asm-generic/bitops/lock.h>
  77. #include <asm-generic/bitops/find.h>
  78. #include <asm-generic/bitops/sched.h>
  79. #include <asm-generic/bitops/non-atomic.h>
  80. #include <asm-generic/bitops/le.h>
  81. #endif /* _ASM_TILE_BITOPS_H */