]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/xfs_bit.h
xfs: remove double-underscore integer types
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_bit.h
CommitLineData
2bd0ea18 1/*
f302e9e4
NS
2 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
5000d01d 4 *
f302e9e4
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
2bd0ea18 7 * published by the Free Software Foundation.
5000d01d 8 *
f302e9e4
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.
5000d01d 13 *
f302e9e4
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
2bd0ea18
NS
17 */
18#ifndef __XFS_BIT_H__
dfc130f3 19#define __XFS_BIT_H__
2bd0ea18
NS
20
21/*
22 * XFS bit manipulation routines.
23 */
24
25/*
56b2de80 26 * masks with n high/low bits set, 64-bit values
2bd0ea18 27 */
4a492e72 28static inline uint64_t xfs_mask64hi(int n)
f302e9e4 29{
4a492e72 30 return (uint64_t)-1 << (64 - (n));
f302e9e4 31}
4a492e72 32static inline uint32_t xfs_mask32lo(int n)
f302e9e4 33{
4a492e72 34 return ((uint32_t)1 << (n)) - 1;
f302e9e4 35}
4a492e72 36static inline uint64_t xfs_mask64lo(int n)
f302e9e4 37{
4a492e72 38 return ((uint64_t)1 << (n)) - 1;
f302e9e4 39}
2bd0ea18 40
d4ae0811 41/* Get high bit set out of 32-bit argument, -1 if none set */
4a492e72 42static inline int xfs_highbit32(uint32_t v)
5e656dbb
BN
43{
44 return fls(v) - 1;
45}
46
47/* Get high bit set out of 64-bit argument, -1 if none set */
4a492e72 48static inline int xfs_highbit64(uint64_t v)
5e656dbb
BN
49{
50 return fls64(v) - 1;
51}
52
53/* Get low bit set out of 32-bit argument, -1 if none set */
4a492e72 54static inline int xfs_lowbit32(uint32_t v)
5e656dbb
BN
55{
56 return ffs(v) - 1;
57}
2bd0ea18 58
d4ae0811 59/* Get low bit set out of 64-bit argument, -1 if none set */
4a492e72 60static inline int xfs_lowbit64(uint64_t v)
5e656dbb 61{
4a492e72 62 uint32_t w = (uint32_t)v;
5e656dbb 63 int n = 0;
2bd0ea18 64
5e656dbb
BN
65 if (w) { /* lower bits */
66 n = ffs(w);
67 } else { /* upper bits */
4a492e72 68 w = (uint32_t)(v >> 32);
ff105f75
DC
69 if (w) {
70 n = ffs(w);
71 if (n)
72 n += 32;
73 }
5e656dbb
BN
74 }
75 return n - 1;
76}
2bd0ea18 77
5e656dbb
BN
78/* Return whether bitmap is empty (1 == empty) */
79extern int xfs_bitmap_empty(uint *map, uint size);
d4ae0811
NS
80
81/* Count continuous one bits in map starting with start_bit */
82extern int xfs_contig_bits(uint *map, uint size, uint start_bit);
83
84/* Find next set bit in map */
85extern int xfs_next_bit(uint *map, uint size, uint start_bit);
86
2bd0ea18 87#endif /* __XFS_BIT_H__ */