2 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * XFS bit manipulation routines.
26 * masks with n high/low bits set, 64-bit values
28 static inline __uint64_t
xfs_mask64hi(int n
)
30 return (__uint64_t
)-1 << (64 - (n
));
32 static inline __uint32_t
xfs_mask32lo(int n
)
34 return ((__uint32_t
)1 << (n
)) - 1;
36 static inline __uint64_t
xfs_mask64lo(int n
)
38 return ((__uint64_t
)1 << (n
)) - 1;
41 /* Get high bit set out of 32-bit argument, -1 if none set */
42 static inline int xfs_highbit32(__uint32_t v
)
47 /* Get high bit set out of 64-bit argument, -1 if none set */
48 static inline int xfs_highbit64(__uint64_t v
)
53 /* Get low bit set out of 32-bit argument, -1 if none set */
54 static inline int xfs_lowbit32(__uint32_t v
)
59 /* Get low bit set out of 64-bit argument, -1 if none set */
60 static inline int xfs_lowbit64(__uint64_t v
)
62 __uint32_t w
= (__uint32_t
)v
;
65 if (w
) { /* lower bits */
67 } else { /* upper bits */
68 w
= (__uint32_t
)(v
>> 32);
69 if (w
&& (n
= ffs(w
)))
75 /* Return whether bitmap is empty (1 == empty) */
76 extern int xfs_bitmap_empty(uint
*map
, uint size
);
78 /* Count continuous one bits in map starting with start_bit */
79 extern int xfs_contig_bits(uint
*map
, uint size
, uint start_bit
);
81 /* Find next set bit in map */
82 extern int xfs_next_bit(uint
*map
, uint size
, uint start_bit
);
84 #endif /* __XFS_BIT_H__ */