2 * Copyright (C) 2014 by the Massachusetts Institute of Technology.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 * This contains portable implementations of the BSD ffs() suite of functions,
33 * which locate the first or last bit set in a bit string.
36 #ifndef OPENAFS_OPR_FFS_H
37 #define OPENAFS_OPR_FFS_H
43 afs_uint32 tmp
= value
;
47 /* This loop must terminate because tmp is nonzero and thus has at least
59 opr_ffsll(long long value
)
62 afs_uint64 tmp
= value
;
66 /* This loop must terminate because tmp is nonzero and thus has at least
81 /* tmp must be unsigned to avoid undefined behavior. */
82 afs_uint32 tmp
= value
;
86 /* This loop must terminate because tmp is nonzero and thus has at least
89 if (tmp
& 0x80000000u
)
98 opr_flsll(long long value
)
101 /* tmp must be unsigned to avoid undefined behavior. */
102 afs_uint64 tmp
= value
;
106 /* This loop must terminate because tmp is nonzero and thus has at least
109 if (tmp
& 0x8000000000000000ull
)
117 #endif /* OPENAFS_OPR_FFS_H */