diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-15 17:50:12 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-12-17 09:14:48 -0500 |
| commit | 23e1a358e81017759714cb413a0e930d4f892563 (patch) | |
| tree | 6ad2a1c06e8b968c869e3f16a82cbbe8ce3ec502 /tools/perf/util/include/linux | |
| parent | 93c49b3e535659102aa1ca28b775b48e3594036c (diff) | |
tools lib: Move asm-generic/bitops/find.h code to tools/include and tools/lib
To match the Linux kernel source code structure from where this code came from.
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-fkbma1h04ki0zzdmp0dpgfyy@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/include/linux')
| -rw-r--r-- | tools/perf/util/include/linux/bitops.h | 73 |
1 files changed, 1 insertions, 72 deletions
diff --git a/tools/perf/util/include/linux/bitops.h b/tools/perf/util/include/linux/bitops.h index 58c4a2520ac2..292aadeb66c5 100644 --- a/tools/perf/util/include/linux/bitops.h +++ b/tools/perf/util/include/linux/bitops.h | |||
| @@ -37,78 +37,7 @@ static inline unsigned long hweight_long(unsigned long w) | |||
| 37 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); | 37 | return sizeof(w) == 4 ? hweight32(w) : hweight64(w); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | #define BITOP_WORD(nr) ((nr) / BITS_PER_LONG) | ||
| 41 | |||
| 42 | #include <asm-generic/bitops/__ffs.h> | 40 | #include <asm-generic/bitops/__ffs.h> |
| 43 | 41 | #include <asm-generic/bitops/find.h> | |
| 44 | typedef const unsigned long __attribute__((__may_alias__)) long_alias_t; | ||
| 45 | |||
| 46 | /* | ||
| 47 | * Find the first set bit in a memory region. | ||
| 48 | */ | ||
| 49 | static inline unsigned long | ||
| 50 | find_first_bit(const unsigned long *addr, unsigned long size) | ||
| 51 | { | ||
| 52 | long_alias_t *p = (long_alias_t *) addr; | ||
| 53 | unsigned long result = 0; | ||
| 54 | unsigned long tmp; | ||
| 55 | |||
| 56 | while (size & ~(BITS_PER_LONG-1)) { | ||
| 57 | if ((tmp = *(p++))) | ||
| 58 | goto found; | ||
| 59 | result += BITS_PER_LONG; | ||
| 60 | size -= BITS_PER_LONG; | ||
| 61 | } | ||
| 62 | if (!size) | ||
| 63 | return result; | ||
| 64 | |||
| 65 | tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); | ||
| 66 | if (tmp == 0UL) /* Are any bits set? */ | ||
| 67 | return result + size; /* Nope. */ | ||
| 68 | found: | ||
| 69 | return result + __ffs(tmp); | ||
| 70 | } | ||
| 71 | |||
| 72 | /* | ||
| 73 | * Find the next set bit in a memory region. | ||
| 74 | */ | ||
| 75 | static inline unsigned long | ||
| 76 | find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) | ||
| 77 | { | ||
| 78 | const unsigned long *p = addr + BITOP_WORD(offset); | ||
| 79 | unsigned long result = offset & ~(BITS_PER_LONG-1); | ||
| 80 | unsigned long tmp; | ||
| 81 | |||
| 82 | if (offset >= size) | ||
| 83 | return size; | ||
| 84 | size -= result; | ||
| 85 | offset %= BITS_PER_LONG; | ||
| 86 | if (offset) { | ||
| 87 | tmp = *(p++); | ||
| 88 | tmp &= (~0UL << offset); | ||
| 89 | if (size < BITS_PER_LONG) | ||
| 90 | goto found_first; | ||
| 91 | if (tmp) | ||
| 92 | goto found_middle; | ||
| 93 | size -= BITS_PER_LONG; | ||
| 94 | result += BITS_PER_LONG; | ||
| 95 | } | ||
| 96 | while (size & ~(BITS_PER_LONG-1)) { | ||
| 97 | if ((tmp = *(p++))) | ||
| 98 | goto found_middle; | ||
| 99 | result += BITS_PER_LONG; | ||
| 100 | size -= BITS_PER_LONG; | ||
| 101 | } | ||
| 102 | if (!size) | ||
| 103 | return result; | ||
| 104 | tmp = *p; | ||
| 105 | |||
| 106 | found_first: | ||
| 107 | tmp &= (~0UL >> (BITS_PER_LONG - size)); | ||
| 108 | if (tmp == 0UL) /* Are any bits set? */ | ||
| 109 | return result + size; /* Nope. */ | ||
| 110 | found_middle: | ||
| 111 | return result + __ffs(tmp); | ||
| 112 | } | ||
| 113 | 42 | ||
| 114 | #endif | 43 | #endif |
