Commit a69b176df246d59626e6a9c640b44c0921fa4566
Committed by
Lachlan McIlroy
1 parent
c319b58b13
Exists in
master
and in
39 other branches
[XFS] Use the generic bitops rather than implementing them ourselves.
Patch inspired by Andi Kleen. SGI-PV: 971186 SGI-Modid: xfs-linux-melb:xfs-kern:30000a Signed-off-by: David Chinner <dgc@sgi.com> Signed-off-by: Christoph Hellwig <hch@infradead.org> Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Showing 3 changed files with 29 additions and 120 deletions Side-by-side Diff
fs/xfs/xfs_bit.c
... | ... | @@ -25,109 +25,6 @@ |
25 | 25 | * XFS bit manipulation routines, used in non-realtime code. |
26 | 26 | */ |
27 | 27 | |
28 | -#ifndef HAVE_ARCH_HIGHBIT | |
29 | -/* | |
30 | - * Index of high bit number in byte, -1 for none set, 0..7 otherwise. | |
31 | - */ | |
32 | -static const char xfs_highbit[256] = { | |
33 | - -1, 0, 1, 1, 2, 2, 2, 2, /* 00 .. 07 */ | |
34 | - 3, 3, 3, 3, 3, 3, 3, 3, /* 08 .. 0f */ | |
35 | - 4, 4, 4, 4, 4, 4, 4, 4, /* 10 .. 17 */ | |
36 | - 4, 4, 4, 4, 4, 4, 4, 4, /* 18 .. 1f */ | |
37 | - 5, 5, 5, 5, 5, 5, 5, 5, /* 20 .. 27 */ | |
38 | - 5, 5, 5, 5, 5, 5, 5, 5, /* 28 .. 2f */ | |
39 | - 5, 5, 5, 5, 5, 5, 5, 5, /* 30 .. 37 */ | |
40 | - 5, 5, 5, 5, 5, 5, 5, 5, /* 38 .. 3f */ | |
41 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 40 .. 47 */ | |
42 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 48 .. 4f */ | |
43 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 50 .. 57 */ | |
44 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 58 .. 5f */ | |
45 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 60 .. 67 */ | |
46 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 68 .. 6f */ | |
47 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 70 .. 77 */ | |
48 | - 6, 6, 6, 6, 6, 6, 6, 6, /* 78 .. 7f */ | |
49 | - 7, 7, 7, 7, 7, 7, 7, 7, /* 80 .. 87 */ | |
50 | - 7, 7, 7, 7, 7, 7, 7, 7, /* 88 .. 8f */ | |
51 | - 7, 7, 7, 7, 7, 7, 7, 7, /* 90 .. 97 */ | |
52 | - 7, 7, 7, 7, 7, 7, 7, 7, /* 98 .. 9f */ | |
53 | - 7, 7, 7, 7, 7, 7, 7, 7, /* a0 .. a7 */ | |
54 | - 7, 7, 7, 7, 7, 7, 7, 7, /* a8 .. af */ | |
55 | - 7, 7, 7, 7, 7, 7, 7, 7, /* b0 .. b7 */ | |
56 | - 7, 7, 7, 7, 7, 7, 7, 7, /* b8 .. bf */ | |
57 | - 7, 7, 7, 7, 7, 7, 7, 7, /* c0 .. c7 */ | |
58 | - 7, 7, 7, 7, 7, 7, 7, 7, /* c8 .. cf */ | |
59 | - 7, 7, 7, 7, 7, 7, 7, 7, /* d0 .. d7 */ | |
60 | - 7, 7, 7, 7, 7, 7, 7, 7, /* d8 .. df */ | |
61 | - 7, 7, 7, 7, 7, 7, 7, 7, /* e0 .. e7 */ | |
62 | - 7, 7, 7, 7, 7, 7, 7, 7, /* e8 .. ef */ | |
63 | - 7, 7, 7, 7, 7, 7, 7, 7, /* f0 .. f7 */ | |
64 | - 7, 7, 7, 7, 7, 7, 7, 7, /* f8 .. ff */ | |
65 | -}; | |
66 | -#endif | |
67 | - | |
68 | -/* | |
69 | - * xfs_highbit32: get high bit set out of 32-bit argument, -1 if none set. | |
70 | - */ | |
71 | -inline int | |
72 | -xfs_highbit32( | |
73 | - __uint32_t v) | |
74 | -{ | |
75 | -#ifdef HAVE_ARCH_HIGHBIT | |
76 | - return highbit32(v); | |
77 | -#else | |
78 | - int i; | |
79 | - | |
80 | - if (v & 0xffff0000) | |
81 | - if (v & 0xff000000) | |
82 | - i = 24; | |
83 | - else | |
84 | - i = 16; | |
85 | - else if (v & 0x0000ffff) | |
86 | - if (v & 0x0000ff00) | |
87 | - i = 8; | |
88 | - else | |
89 | - i = 0; | |
90 | - else | |
91 | - return -1; | |
92 | - return i + xfs_highbit[(v >> i) & 0xff]; | |
93 | -#endif | |
94 | -} | |
95 | - | |
96 | -/* | |
97 | - * xfs_lowbit64: get low bit set out of 64-bit argument, -1 if none set. | |
98 | - */ | |
99 | -int | |
100 | -xfs_lowbit64( | |
101 | - __uint64_t v) | |
102 | -{ | |
103 | - __uint32_t w = (__uint32_t)v; | |
104 | - int n = 0; | |
105 | - | |
106 | - if (w) { /* lower bits */ | |
107 | - n = ffs(w); | |
108 | - } else { /* upper bits */ | |
109 | - w = (__uint32_t)(v >> 32); | |
110 | - if (w && (n = ffs(w))) | |
111 | - n += 32; | |
112 | - } | |
113 | - return n - 1; | |
114 | -} | |
115 | - | |
116 | -/* | |
117 | - * xfs_highbit64: get high bit set out of 64-bit argument, -1 if none set. | |
118 | - */ | |
119 | -int | |
120 | -xfs_highbit64( | |
121 | - __uint64_t v) | |
122 | -{ | |
123 | - __uint32_t h = (__uint32_t)(v >> 32); | |
124 | - | |
125 | - if (h) | |
126 | - return xfs_highbit32(h) + 32; | |
127 | - return xfs_highbit32((__uint32_t)v); | |
128 | -} | |
129 | - | |
130 | - | |
131 | 28 | /* |
132 | 29 | * Return whether bitmap is empty. |
133 | 30 | * Size is number of words in the bitmap, which is padded to word boundary |
fs/xfs/xfs_bit.h
... | ... | @@ -47,13 +47,30 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | /* Get high bit set out of 32-bit argument, -1 if none set */ |
50 | -extern int xfs_highbit32(__uint32_t v); | |
50 | +static inline int xfs_highbit32(__uint32_t v) | |
51 | +{ | |
52 | + return fls(v) - 1; | |
53 | +} | |
51 | 54 | |
52 | -/* Get low bit set out of 64-bit argument, -1 if none set */ | |
53 | -extern int xfs_lowbit64(__uint64_t v); | |
54 | - | |
55 | 55 | /* Get high bit set out of 64-bit argument, -1 if none set */ |
56 | -extern int xfs_highbit64(__uint64_t); | |
56 | +static inline int xfs_highbit64(__uint64_t v) | |
57 | +{ | |
58 | + return fls64(v) - 1; | |
59 | +} | |
60 | + | |
61 | +/* Get low bit set out of 32-bit argument, -1 if none set */ | |
62 | +static inline int xfs_lowbit32(__uint32_t v) | |
63 | +{ | |
64 | + unsigned long t = v; | |
65 | + return (v) ? find_first_bit(&t, 32) : -1; | |
66 | +} | |
67 | + | |
68 | +/* Get low bit set out of 64-bit argument, -1 if none set */ | |
69 | +static inline int xfs_lowbit64(__uint64_t v) | |
70 | +{ | |
71 | + unsigned long t = v; | |
72 | + return (v) ? find_first_bit(&t, 64) : -1; | |
73 | +} | |
57 | 74 | |
58 | 75 | /* Return whether bitmap is empty (1 == empty) */ |
59 | 76 | extern int xfs_bitmap_empty(uint *map, uint size); |
fs/xfs/xfs_rtalloc.c
... | ... | @@ -73,18 +73,6 @@ |
73 | 73 | */ |
74 | 74 | |
75 | 75 | /* |
76 | - * xfs_lowbit32: get low bit set out of 32-bit argument, -1 if none set. | |
77 | - */ | |
78 | -STATIC int | |
79 | -xfs_lowbit32( | |
80 | - __uint32_t v) | |
81 | -{ | |
82 | - if (v) | |
83 | - return ffs(v) - 1; | |
84 | - return -1; | |
85 | -} | |
86 | - | |
87 | -/* | |
88 | 76 | * Allocate space to the bitmap or summary file, and zero it, for growfs. |
89 | 77 | */ |
90 | 78 | STATIC int /* error */ |
... | ... | @@ -444,6 +432,7 @@ |
444 | 432 | } |
445 | 433 | bbno = XFS_BITTOBLOCK(mp, bno); |
446 | 434 | i = 0; |
435 | + ASSERT(minlen != 0); | |
447 | 436 | log2len = xfs_highbit32(minlen); |
448 | 437 | /* |
449 | 438 | * Loop over all bitmap blocks (bbno + i is current block). |
... | ... | @@ -612,6 +601,8 @@ |
612 | 601 | xfs_suminfo_t sum; /* summary information for extents */ |
613 | 602 | |
614 | 603 | ASSERT(minlen % prod == 0 && maxlen % prod == 0); |
604 | + ASSERT(maxlen != 0); | |
605 | + | |
615 | 606 | /* |
616 | 607 | * Loop over all the levels starting with maxlen. |
617 | 608 | * At each level, look at all the bitmap blocks, to see if there |
... | ... | @@ -669,6 +660,9 @@ |
669 | 660 | *rtblock = NULLRTBLOCK; |
670 | 661 | return 0; |
671 | 662 | } |
663 | + ASSERT(minlen != 0); | |
664 | + ASSERT(maxlen != 0); | |
665 | + | |
672 | 666 | /* |
673 | 667 | * Loop over sizes, from maxlen down to minlen. |
674 | 668 | * This time, when we do the allocations, allow smaller ones |
... | ... | @@ -1954,6 +1948,7 @@ |
1954 | 1948 | nsbp->sb_blocksize * nsbp->sb_rextsize); |
1955 | 1949 | nsbp->sb_rextents = nsbp->sb_rblocks; |
1956 | 1950 | do_div(nsbp->sb_rextents, nsbp->sb_rextsize); |
1951 | + ASSERT(nsbp->sb_rextents != 0); | |
1957 | 1952 | nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents); |
1958 | 1953 | nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1; |
1959 | 1954 | nrsumsize = |