Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/czankel/xtens...
[deliverable/linux.git] / fs / xfs / xfs_bit.h
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
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
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
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.
1da177e4 13 *
7b718769
NS
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
1da177e4
LT
17 */
18#ifndef __XFS_BIT_H__
19#define __XFS_BIT_H__
20
21/*
22 * XFS bit manipulation routines.
23 */
24
25/*
26 * masks with n high/low bits set, 32-bit values & 64-bit values
27 */
1da177e4 28#define XFS_MASK32HI(n) xfs_mask32hi(n)
a844f451
NS
29static inline __uint32_t xfs_mask32hi(int n)
30{
31 return (__uint32_t)-1 << (32 - (n));
32}
1da177e4 33#define XFS_MASK64HI(n) xfs_mask64hi(n)
a844f451
NS
34static inline __uint64_t xfs_mask64hi(int n)
35{
36 return (__uint64_t)-1 << (64 - (n));
37}
1da177e4 38#define XFS_MASK32LO(n) xfs_mask32lo(n)
a844f451
NS
39static inline __uint32_t xfs_mask32lo(int n)
40{
41 return ((__uint32_t)1 << (n)) - 1;
42}
1da177e4 43#define XFS_MASK64LO(n) xfs_mask64lo(n)
a844f451
NS
44static inline __uint64_t xfs_mask64lo(int n)
45{
46 return ((__uint64_t)1 << (n)) - 1;
47}
1da177e4
LT
48
49/* Get high bit set out of 32-bit argument, -1 if none set */
a69b176d
DC
50static inline int xfs_highbit32(__uint32_t v)
51{
52 return fls(v) - 1;
53}
1da177e4
LT
54
55/* Get high bit set out of 64-bit argument, -1 if none set */
a69b176d
DC
56static 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 */
62static inline int xfs_lowbit32(__uint32_t v)
63{
edd319dc
DC
64 __uint32_t t = v;
65 return (t) ? find_first_bit((unsigned long *)&t, 32) : -1;
a69b176d
DC
66}
67
68/* Get low bit set out of 64-bit argument, -1 if none set */
69static inline int xfs_lowbit64(__uint64_t v)
70{
edd319dc
DC
71 __uint64_t t = v;
72 return (t) ? find_first_bit((unsigned long *)&t, 64) : -1;
a69b176d 73}
1da177e4 74
24ad33ff
ES
75/* Return whether bitmap is empty (1 == empty) */
76extern int xfs_bitmap_empty(uint *map, uint size);
1da177e4
LT
77
78/* Count continuous one bits in map starting with start_bit */
79extern int xfs_contig_bits(uint *map, uint size, uint start_bit);
80
81/* Find next set bit in map */
82extern int xfs_next_bit(uint *map, uint size, uint start_bit);
83
84#endif /* __XFS_BIT_H__ */
This page took 0.478815 seconds and 5 git commands to generate.