1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
/*
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "xfs.h"
#include "xfs_bit.h"
#include "xfs_log.h"
#include "xfs_trans.h"
#include "xfs_buf_item.h"
/*
* XFS bit manipulation routines, used in non-realtime code.
*/
#ifndef HAVE_ARCH_HIGHBIT
/*
* Index of high bit number in byte, -1 for none set, 0..7 otherwise.
*/
static const char xfs_highbit[256] = {
-1, 0, 1, 1, 2, 2, 2, 2, /* 00 .. 07 */
3, 3, 3, 3, 3, 3, 3, 3, /* 08 .. 0f */
4, 4, 4, 4, 4, 4, 4, 4, /* 10 .. 17 */
4, 4, 4, 4, 4, 4, 4, 4, /* 18 .. 1f */
5, 5, 5, 5, 5, 5, 5, 5, /* 20 .. 27 */
5, 5, 5, 5, 5, 5, 5, 5, /* 28 .. 2f */
5, 5, 5, 5, 5, 5, 5, 5, /* 30 .. 37 */
5, 5, 5, 5, 5, 5, 5, 5, /* 38 .. 3f */
6, 6, 6, 6, 6, 6, 6, 6, /* 40 .. 47 */
6, 6, 6, 6, 6, 6, 6, 6, /* 48 .. 4f */
6, 6, 6, 6, 6, 6, 6, 6, /* 50 .. 57 */
6, 6, 6, 6, 6, 6, 6, 6, /* 58 .. 5f */
6, 6, 6, 6, 6, 6, 6, 6, /* 60 .. 67 */
6, 6, 6, 6, 6, 6, 6, 6, /* 68 .. 6f */
6, 6, 6, 6, 6, 6, 6, 6, /* 70 .. 77 */
6, 6, 6, 6, 6, 6, 6, 6, /* 78 .. 7f */
7, 7, 7, 7, 7, 7, 7, 7, /* 80 .. 87 */
7, 7, 7, 7, 7, 7, 7, 7, /* 88 .. 8f */
7, 7, 7, 7, 7, 7, 7, 7, /* 90 .. 97 */
7, 7, 7, 7, 7, 7, 7, 7, /* 98 .. 9f */
7, 7, 7, 7, 7, 7, 7, 7, /* a0 .. a7 */
7, 7, 7, 7, 7, 7, 7, 7, /* a8 .. af */
7, 7, 7, 7, 7, 7, 7, 7, /* b0 .. b7 */
7, 7, 7, 7, 7, 7, 7, 7, /* b8 .. bf */
7, 7, 7, 7, 7, 7, 7, 7, /* c0 .. c7 */
7, 7, 7, 7, 7, 7, 7, 7, /* c8 .. cf */
7, 7, 7, 7, 7, 7, 7, 7, /* d0 .. d7 */
7, 7, 7, 7, 7, 7, 7, 7, /* d8 .. df */
7, 7, 7, 7, 7, 7, 7, 7, /* e0 .. e7 */
7, 7, 7, 7, 7, 7, 7, 7, /* e8 .. ef */
7, 7, 7, 7, 7, 7, 7, 7, /* f0 .. f7 */
7, 7, 7, 7, 7, 7, 7, 7, /* f8 .. ff */
};
#endif
/*
* Count of bits set in byte, 0..8.
*/
static const char xfs_countbit[256] = {
0, 1, 1, 2, 1, 2, 2, 3, /* 00 .. 07 */
1, 2, 2, 3, 2, 3, 3, 4, /* 08 .. 0f */
1, 2, 2, 3, 2, 3, 3, 4, /* 10 .. 17 */
2, 3, 3, 4, 3, 4, 4, 5, /* 18 .. 1f */
1, 2, 2, 3, 2, 3, 3, 4, /* 20 .. 27 */
2, 3, 3, 4, 3, 4, 4, 5, /* 28 .. 2f */
2, 3, 3, 4, 3, 4, 4, 5, /* 30 .. 37 */
3, 4, 4, 5, 4, 5, 5, 6, /* 38 .. 3f */
1, 2, 2, 3, 2, 3, 3, 4, /* 40 .. 47 */
2, 3, 3, 4, 3, 4, 4, 5, /* 48 .. 4f */
2, 3, 3, 4, 3, 4, 4, 5, /* 50 .. 57 */
3, 4, 4, 5, 4, 5, 5, 6, /* 58 .. 5f */
2, 3, 3, 4, 3, 4, 4, 5, /* 60 .. 67 */
3, 4, 4, 5, 4, 5, 5, 6, /* 68 .. 6f */
3, 4, 4, 5, 4, 5, 5, 6, /* 70 .. 77 */
4, 5, 5, 6, 5, 6, 6, 7, /* 78 .. 7f */
1, 2, 2, 3, 2, 3, 3, 4, /* 80 .. 87 */
2, 3, 3, 4, 3, 4, 4, 5, /* 88 .. 8f */
2, 3, 3, 4, 3, 4, 4, 5, /* 90 .. 97 */
3, 4, 4, 5, 4, 5, 5, 6, /* 98 .. 9f */
2, 3, 3, 4, 3, 4, 4, 5, /* a0 .. a7 */
3, 4, 4, 5, 4, 5, 5, 6, /* a8 .. af */
3, 4, 4, 5, 4, 5, 5, 6, /* b0 .. b7 */
4, 5, 5, 6, 5, 6, 6, 7, /* b8 .. bf */
2, 3, 3, 4, 3, 4, 4, 5, /* c0 .. c7 */
3, 4, 4, 5, 4, 5, 5, 6, /* c8 .. cf */
3, 4, 4, 5, 4, 5, 5, 6, /* d0 .. d7 */
4, 5, 5, 6, 5, 6, 6, 7, /* d8 .. df */
3, 4, 4, 5, 4, 5, 5, 6, /* e0 .. e7 */
4, 5, 5, 6, 5, 6, 6, 7, /* e8 .. ef */
4, 5, 5, 6, 5, 6, 6, 7, /* f0 .. f7 */
5, 6, 6, 7, 6, 7, 7, 8, /* f8 .. ff */
};
/*
* xfs_highbit32: get high bit set out of 32-bit argument, -1 if none set.
*/
inline int
xfs_highbit32(
__uint32_t v)
{
#ifdef HAVE_ARCH_HIGHBIT
return highbit32(v);
#else
int i;
if (v & 0xffff0000)
if (v & 0xff000000)
i = 24;
else
i = 16;
else if (v & 0x0000ffff)
if (v & 0x0000ff00)
i = 8;
else
i =
|