diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/ia64/lib/bitop.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/ia64/lib/bitop.c')
-rw-r--r-- | arch/ia64/lib/bitop.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/arch/ia64/lib/bitop.c b/arch/ia64/lib/bitop.c new file mode 100644 index 000000000000..82e299c8464e --- /dev/null +++ b/arch/ia64/lib/bitop.c | |||
@@ -0,0 +1,88 @@ | |||
1 | #include <linux/compiler.h> | ||
2 | #include <linux/types.h> | ||
3 | #include <asm/intrinsics.h> | ||
4 | #include <linux/module.h> | ||
5 | #include <linux/bitops.h> | ||
6 | |||
7 | /* | ||
8 | * Find next zero bit in a bitmap reasonably efficiently.. | ||
9 | */ | ||
10 | |||
11 | int __find_next_zero_bit (const void *addr, unsigned long size, unsigned long offset) | ||
12 | { | ||
13 | unsigned long *p = ((unsigned long *) addr) + (offset >> 6); | ||
14 | unsigned long result = offset & ~63UL; | ||
15 | unsigned long tmp; | ||
16 | |||
17 | if (offset >= size) | ||
18 | return size; | ||
19 | size -= result; | ||
20 | offset &= 63UL; | ||
21 | if (offset) { | ||
22 | tmp = *(p++); | ||
23 | tmp |= ~0UL >> (64-offset); | ||
24 | if (size < 64) | ||
25 | goto found_first; | ||
26 | if (~tmp) | ||
27 | goto found_middle; | ||
28 | size -= 64; | ||
29 | result += 64; | ||
30 | } | ||
31 | while (size & ~63UL) { | ||
32 | if (~(tmp = *(p++))) | ||
33 | goto found_middle; | ||
34 | result += 64; | ||
35 | size -= 64; | ||
36 | } | ||
37 | if (!size) | ||
38 | return result; | ||
39 | tmp = *p; | ||
40 | found_first: | ||
41 | tmp |= ~0UL << size; | ||
42 | if (tmp == ~0UL) /* any bits zero? */ | ||
43 | return result + size; /* nope */ | ||
44 | found_middle: | ||
45 | return result + ffz(tmp); | ||
46 | } | ||
47 | EXPORT_SYMBOL(__find_next_zero_bit); | ||
48 | |||
49 | /* | ||
50 | * Find next bit in a bitmap reasonably efficiently.. | ||
51 | */ | ||
52 | int __find_next_bit(const void *addr, unsigned long size, unsigned long offset) | ||
53 | { | ||
54 | unsigned long *p = ((unsigned long *) addr) + (offset >> 6); | ||
55 | unsigned long result = offset & ~63UL; | ||
56 | unsigned long tmp; | ||
57 | |||
58 | if (offset >= size) | ||
59 | return size; | ||
60 | size -= result; | ||
61 | offset &= 63UL; | ||
62 | if (offset) { | ||
63 | tmp = *(p++); | ||
64 | tmp &= ~0UL << offset; | ||
65 | if (size < 64) | ||
66 | goto found_first; | ||
67 | if (tmp) | ||
68 | goto found_middle; | ||
69 | size -= 64; | ||
70 | result += 64; | ||
71 | } | ||
72 | while (size & ~63UL) { | ||
73 | if ((tmp = *(p++))) | ||
74 | goto found_middle; | ||
75 | result += 64; | ||
76 | size -= 64; | ||
77 | } | ||
78 | if (!size) | ||
79 | return result; | ||
80 | tmp = *p; | ||
81 | found_first: | ||
82 | tmp &= ~0UL >> (64-size); | ||
83 | if (tmp == 0UL) /* Are any bits set? */ | ||
84 | return result + size; /* Nope. */ | ||
85 | found_middle: | ||
86 | return result + __ffs(tmp); | ||
87 | } | ||
88 | EXPORT_SYMBOL(__find_next_bit); | ||