Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
0004  * All Rights Reserved.
0005  */
0006 #ifndef __XFS_BIT_H__
0007 #define __XFS_BIT_H__
0008 
0009 /*
0010  * XFS bit manipulation routines.
0011  */
0012 
0013 /*
0014  * masks with n high/low bits set, 64-bit values
0015  */
0016 static inline uint64_t xfs_mask64hi(int n)
0017 {
0018     return (uint64_t)-1 << (64 - (n));
0019 }
0020 static inline uint32_t xfs_mask32lo(int n)
0021 {
0022     return ((uint32_t)1 << (n)) - 1;
0023 }
0024 static inline uint64_t xfs_mask64lo(int n)
0025 {
0026     return ((uint64_t)1 << (n)) - 1;
0027 }
0028 
0029 /* Get high bit set out of 32-bit argument, -1 if none set */
0030 static inline int xfs_highbit32(uint32_t v)
0031 {
0032     return fls(v) - 1;
0033 }
0034 
0035 /* Get high bit set out of 64-bit argument, -1 if none set */
0036 static inline int xfs_highbit64(uint64_t v)
0037 {
0038     return fls64(v) - 1;
0039 }
0040 
0041 /* Get low bit set out of 32-bit argument, -1 if none set */
0042 static inline int xfs_lowbit32(uint32_t v)
0043 {
0044     return ffs(v) - 1;
0045 }
0046 
0047 /* Get low bit set out of 64-bit argument, -1 if none set */
0048 static inline int xfs_lowbit64(uint64_t v)
0049 {
0050     uint32_t    w = (uint32_t)v;
0051     int     n = 0;
0052 
0053     if (w) {    /* lower bits */
0054         n = ffs(w);
0055     } else {    /* upper bits */
0056         w = (uint32_t)(v >> 32);
0057         if (w) {
0058             n = ffs(w);
0059             if (n)
0060                 n += 32;
0061         }
0062     }
0063     return n - 1;
0064 }
0065 
0066 /* Return whether bitmap is empty (1 == empty) */
0067 extern int xfs_bitmap_empty(uint *map, uint size);
0068 
0069 /* Count continuous one bits in map starting with start_bit */
0070 extern int xfs_contig_bits(uint *map, uint size, uint start_bit);
0071 
0072 /* Find next set bit in map */
0073 extern int xfs_next_bit(uint *map, uint size, uint start_bit);
0074 
0075 #endif  /* __XFS_BIT_H__ */