bitops.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef _LINUX_BITOPS_H
  19. #error only <linux/bitops.h> can be included directly
  20. #endif
  21. #ifdef __tilegx__
  22. #include <asm/bitops_64.h>
  23. #else
  24. #include <asm/bitops_32.h>
  25. #endif
  26. /**
  27. * ffz - find first zero bit in word
  28. * @word: The word to search
  29. *
  30. * Undefined if no zero exists, so code should check against ~0UL first.
  31. */
  32. static inline unsigned long ffz(unsigned long word)
  33. {
  34. return __builtin_ctzl(~word);
  35. }
  36. static inline int fls64(__u64 w)
  37. {
  38. return (sizeof(__u64) * 8) - __builtin_clzll(w);
  39. }
  40. /**
  41. * fls - find last set bit in word
  42. * @x: the word to search
  43. *
  44. * This is defined in a similar way as the libc and compiler builtin
  45. * ffs, but returns the position of the most significant set bit.
  46. *
  47. * fls(value) returns 0 if value is 0 or the position of the last
  48. * set bit if value is nonzero. The last (most significant) bit is
  49. * at position 32.
  50. */
  51. static inline int fls(int x)
  52. {
  53. return fls64((unsigned int) x);
  54. }
  55. static inline unsigned int __arch_hweight32(unsigned int w)
  56. {
  57. return __builtin_popcount(w);
  58. }
  59. static inline unsigned int __arch_hweight16(unsigned int w)
  60. {
  61. return __builtin_popcount(w & 0xffff);
  62. }
  63. static inline unsigned int __arch_hweight8(unsigned int w)
  64. {
  65. return __builtin_popcount(w & 0xff);
  66. }
  67. static inline unsigned long __arch_hweight64(__u64 w)
  68. {
  69. return __builtin_popcountll(w);
  70. }
  71. #include <asm-generic/bitops/builtin-__ffs.h>
  72. #include <asm-generic/bitops/builtin-__fls.h>
  73. #include <asm-generic/bitops/builtin-ffs.h>
  74. #include <asm-generic/bitops/const_hweight.h>
  75. #include <asm-generic/bitops/lock.h>
  76. #include <asm-generic/bitops/find.h>
  77. #include <asm-generic/bitops/sched.h>
  78. #include <asm-generic/bitops/non-atomic.h>
  79. #include <asm-generic/bitops/le.h>
  80. #endif /* _ASM_TILE_BITOPS_H */