Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 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 | |
| 16 | #ifndef _ASM_TILE_BITOPS_H |
| 17 | #define _ASM_TILE_BITOPS_H |
| 18 | |
| 19 | #include <linux/types.h> |
Peter Zijlstra | ce3609f | 2014-03-13 19:00:35 +0100 | [diff] [blame] | 20 | #include <asm/barrier.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 21 | |
| 22 | #ifndef _LINUX_BITOPS_H |
| 23 | #error only <linux/bitops.h> can be included directly |
| 24 | #endif |
| 25 | |
| 26 | #ifdef __tilegx__ |
| 27 | #include <asm/bitops_64.h> |
| 28 | #else |
| 29 | #include <asm/bitops_32.h> |
| 30 | #endif |
| 31 | |
| 32 | /** |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 33 | * ffz - find first zero bit in word |
| 34 | * @word: The word to search |
| 35 | * |
| 36 | * Undefined if no zero exists, so code should check against ~0UL first. |
| 37 | */ |
| 38 | static inline unsigned long ffz(unsigned long word) |
| 39 | { |
| 40 | return __builtin_ctzl(~word); |
| 41 | } |
| 42 | |
Chris Metcalf | 9f1d62b | 2012-05-25 12:32:09 -0400 | [diff] [blame] | 43 | static inline int fls64(__u64 w) |
| 44 | { |
| 45 | return (sizeof(__u64) * 8) - __builtin_clzll(w); |
| 46 | } |
| 47 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 48 | /** |
| 49 | * fls - find last set bit in word |
| 50 | * @x: the word to search |
| 51 | * |
| 52 | * This is defined in a similar way as the libc and compiler builtin |
| 53 | * ffs, but returns the position of the most significant set bit. |
| 54 | * |
| 55 | * fls(value) returns 0 if value is 0 or the position of the last |
| 56 | * set bit if value is nonzero. The last (most significant) bit is |
| 57 | * at position 32. |
| 58 | */ |
| 59 | static inline int fls(int x) |
| 60 | { |
Chris Metcalf | 9f1d62b | 2012-05-25 12:32:09 -0400 | [diff] [blame] | 61 | return fls64((unsigned int) x); |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 62 | } |
| 63 | |
Chris Metcalf | 947e7dc | 2010-08-13 20:32:41 -0400 | [diff] [blame] | 64 | static inline unsigned int __arch_hweight32(unsigned int w) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 65 | { |
| 66 | return __builtin_popcount(w); |
| 67 | } |
| 68 | |
Chris Metcalf | 947e7dc | 2010-08-13 20:32:41 -0400 | [diff] [blame] | 69 | static inline unsigned int __arch_hweight16(unsigned int w) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 70 | { |
| 71 | return __builtin_popcount(w & 0xffff); |
| 72 | } |
| 73 | |
Chris Metcalf | 947e7dc | 2010-08-13 20:32:41 -0400 | [diff] [blame] | 74 | static inline unsigned int __arch_hweight8(unsigned int w) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 75 | { |
| 76 | return __builtin_popcount(w & 0xff); |
| 77 | } |
| 78 | |
Chris Metcalf | 947e7dc | 2010-08-13 20:32:41 -0400 | [diff] [blame] | 79 | static inline unsigned long __arch_hweight64(__u64 w) |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 80 | { |
| 81 | return __builtin_popcountll(w); |
| 82 | } |
| 83 | |
Akinobu Mita | d6a0aa3 | 2013-08-14 22:07:30 +0900 | [diff] [blame] | 84 | #include <asm-generic/bitops/builtin-__ffs.h> |
| 85 | #include <asm-generic/bitops/builtin-__fls.h> |
| 86 | #include <asm-generic/bitops/builtin-ffs.h> |
Chris Metcalf | 947e7dc | 2010-08-13 20:32:41 -0400 | [diff] [blame] | 87 | #include <asm-generic/bitops/const_hweight.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 88 | #include <asm-generic/bitops/lock.h> |
Akinobu Mita | 708ff2a | 2010-09-29 18:08:50 +0900 | [diff] [blame] | 89 | #include <asm-generic/bitops/find.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 90 | #include <asm-generic/bitops/sched.h> |
Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 91 | #include <asm-generic/bitops/non-atomic.h> |
Akinobu Mita | 861b5ae | 2011-03-23 16:42:02 -0700 | [diff] [blame] | 92 | #include <asm-generic/bitops/le.h> |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 93 | |
| 94 | #endif /* _ASM_TILE_BITOPS_H */ |