xref: /netbsd-src/share/man/man3/ffs32.3 (revision b0f3c6983eb8e43de4f360f36d96b16afa407782)
1.\"	$NetBSD: ffs32.3,v 1.6 2011/04/08 08:47:50 wiz Exp $
2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jukka Ruohonen.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd April 8, 2011
31.Dt FFS32 3
32.Os
33.Sh NAME
34.Nm ffs32 ,
35.Nm ffs64 ,
36.Nm fls32 ,
37.Nm fls64
38.Nd find first or last bit set
39.Sh SYNOPSIS
40.In sys/bitops.h
41.Ft int
42.Fn ffs32 "uint32_t n"
43.Ft int
44.Fn ffs64 "uint64_t n"
45.Ft int
46.Fn fls32 "uint32_t n"
47.Ft int
48.Fn fls64 "uint64_t n"
49.Sh DESCRIPTION
50The
51.Fn ffs32
52and
53.Fn ffs64
54functions find the first bit set in
55.Fa n
56and return the index of that bit.
57Conversely,
58the
59.Fn fls32
60and
61.Fn fls64
62functions find the last bit set in
63.Fa n ,
64returning the index of the bit.
65.Pp
66The search always starts from the bit 1 (the least significant bit).
67If the argument
68.Fa n
69is zero, each function returns zero.
70.Sh IMPLEMENTATION NOTES
71The described functions are implemented as
72.Em static inline
73functions in the
74.In sys/bitops.h
75header.
76The standard C library includes a more portable
77.Xr ffs 3
78for user applications.
79.\"
80.\" XXX: It is noted in the CVS history of <sys/bitops.h> that MD-optimized
81.\"	 <machine/bitops.h> is a TODO. If those start to appear, note it here.
82.\"
83.Sh EXAMPLES
84In the following example
85.Va f = 3
86and
87.Va l = 7 :
88.Bd -literal -offset indent
89uint32_t n = 0x44;	/* 01000100 */
90int f, l;
91
92f = ffs32(n);
93l = fls32(n);
94.Ed
95.Sh SEE ALSO
96.Xr bitops 3 ,
97.Xr bits 3 ,
98.Xr bitstring 3 ,
99.Xr ffs 3 ,
100.Xr setbit 9
101.Sh HISTORY
102These functions first appeared in
103.Nx 5.0 .
104