blob: 0bbe568175428f4759a6a7ef1d89b0f6bd60baef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#define XFS_MASK32HI(n) xfs_mask32hi(n)
Nathan Scotta844f452005-11-02 14:38:42 +110029static inline __uint32_t xfs_mask32hi(int n)
30{
31 return (__uint32_t)-1 << (32 - (n));
32}
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define XFS_MASK64HI(n) xfs_mask64hi(n)
Nathan Scotta844f452005-11-02 14:38:42 +110034static inline __uint64_t xfs_mask64hi(int n)
35{
36 return (__uint64_t)-1 << (64 - (n));
37}
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#define XFS_MASK32LO(n) xfs_mask32lo(n)
Nathan Scotta844f452005-11-02 14:38:42 +110039static inline __uint32_t xfs_mask32lo(int n)
40{
41 return ((__uint32_t)1 << (n)) - 1;
42}
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define XFS_MASK64LO(n) xfs_mask64lo(n)
Nathan Scotta844f452005-11-02 14:38:42 +110044static inline __uint64_t xfs_mask64lo(int n)
45{
46 return ((__uint64_t)1 << (n)) - 1;
47}
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49/* Get high bit set out of 32-bit argument, -1 if none set */
50extern int xfs_highbit32(__uint32_t v);
51
52/* Get low bit set out of 64-bit argument, -1 if none set */
53extern int xfs_lowbit64(__uint64_t v);
54
55/* Get high bit set out of 64-bit argument, -1 if none set */
56extern int xfs_highbit64(__uint64_t);
57
58/* Count set bits in map starting with start_bit */
59extern int xfs_count_bits(uint *map, uint size, uint start_bit);
60
61/* Count continuous one bits in map starting with start_bit */
62extern int xfs_contig_bits(uint *map, uint size, uint start_bit);
63
64/* Find next set bit in map */
65extern int xfs_next_bit(uint *map, uint size, uint start_bit);
66
67#endif /* __XFS_BIT_H__ */