Add and document ffsl(), fls() and flsl().
This commit is contained in:
parent
dfa5456537
commit
ec1fd605cb
@ -42,6 +42,9 @@ int bcmp(const void *, const void *, size_t); /* LEGACY */
|
|||||||
void bcopy(const void *, void *, size_t); /* LEGACY */
|
void bcopy(const void *, void *, size_t); /* LEGACY */
|
||||||
void bzero(void *, size_t); /* LEGACY */
|
void bzero(void *, size_t); /* LEGACY */
|
||||||
int ffs(int);
|
int ffs(int);
|
||||||
|
int ffsl(long);
|
||||||
|
int fls(int);
|
||||||
|
int flsl(long);
|
||||||
char *index(const char *, int); /* LEGACY */
|
char *index(const char *, int); /* LEGACY */
|
||||||
char *rindex(const char *, int); /* LEGACY */
|
char *rindex(const char *, int); /* LEGACY */
|
||||||
int strcasecmp(const char *, const char *);
|
int strcasecmp(const char *, const char *);
|
||||||
|
@ -83,8 +83,8 @@ SRCS+= ${_src}
|
|||||||
KQSRCS= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
|
KQSRCS= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
|
||||||
lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
|
lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
|
||||||
subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
|
subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
|
||||||
KSRCS= bcmp.c ffs.c index.c mcount.c rindex.c strcat.c strcmp.c strcpy.c \
|
KSRCS= bcmp.c ffs.c ffsl.c fls.c flsl.c index.c mcount.c rindex.c \
|
||||||
strlen.c strncpy.c
|
strcat.c strcmp.c strcpy.c strlen.c strncpy.c
|
||||||
|
|
||||||
libkern: libkern.gen libkern.${MACHINE_ARCH}
|
libkern: libkern.gen libkern.${MACHINE_ARCH}
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
CFLAGS+= -I${.CURDIR}/locale
|
CFLAGS+= -I${.CURDIR}/locale
|
||||||
|
|
||||||
# machine-independent string sources
|
# machine-independent string sources
|
||||||
MISRCS+=bcmp.c bcopy.c bzero.c ffs.c index.c memccpy.c memchr.c memcmp.c \
|
MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c fls.c flsl.c index.c memccpy.c \
|
||||||
|
memchr.c memcmp.c \
|
||||||
memcpy.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c strcat.c \
|
memcpy.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c strcat.c \
|
||||||
strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strdup.c strerror.c \
|
strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strdup.c strerror.c \
|
||||||
strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c strncpy.c \
|
strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c strncpy.c \
|
||||||
@ -32,6 +33,9 @@ MAN+= bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \
|
|||||||
strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 wcscoll.3 wcstok.3 \
|
strspn.3 strstr.3 strtok.3 strxfrm.3 swab.3 wcscoll.3 wcstok.3 \
|
||||||
wcswidth.3 wcsxfrm.3 wmemchr.3
|
wcswidth.3 wcsxfrm.3 wmemchr.3
|
||||||
|
|
||||||
|
MLINKS+=ffs.3 ffsl.3
|
||||||
|
MLINKS+=ffs.3 fls.3
|
||||||
|
MLINKS+=ffs.3 flsl.3
|
||||||
MLINKS+=index.3 rindex.3
|
MLINKS+=index.3 rindex.3
|
||||||
MLINKS+=strcasecmp.3 strncasecmp.3
|
MLINKS+=strcasecmp.3 strncasecmp.3
|
||||||
MLINKS+=strcat.3 strncat.3
|
MLINKS+=strcat.3 strncat.3
|
||||||
|
@ -38,23 +38,44 @@
|
|||||||
.Dt FFS 3
|
.Dt FFS 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm ffs
|
.Nm ffs ,
|
||||||
.Nd find first bit set in a bit string
|
.Nm ffsl ,
|
||||||
|
.Nm fls ,
|
||||||
|
.Nm flsl
|
||||||
|
.Nd find first or last bit set in a bit string
|
||||||
.Sh LIBRARY
|
.Sh LIBRARY
|
||||||
.Lb libc
|
.Lb libc
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.In strings.h
|
.In strings.h
|
||||||
.Ft int
|
.Ft int
|
||||||
.Fn ffs "int value"
|
.Fn ffs "int value"
|
||||||
|
.Ft int
|
||||||
|
.Fn ffsl "long value"
|
||||||
|
.Ft int
|
||||||
|
.Fn fls "int value"
|
||||||
|
.Ft int
|
||||||
|
.Fn flsl "long value"
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Fn ffs
|
.Fn ffs
|
||||||
function finds the first bit set in
|
and
|
||||||
|
.Fn ffsl
|
||||||
|
functions find the first bit set in
|
||||||
.Fa value
|
.Fa value
|
||||||
and returns the index of that bit.
|
and return the index of that bit.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn fls
|
||||||
|
and
|
||||||
|
.Fn flsl
|
||||||
|
functions find the last bit set in
|
||||||
|
.Fa value
|
||||||
|
and return the index of that bit.
|
||||||
|
.Pp
|
||||||
Bits are numbered starting from 1, starting at the right-most
|
Bits are numbered starting from 1, starting at the right-most
|
||||||
bit.
|
(least significant) bit.
|
||||||
A return value of 0 means that the argument was zero.
|
A return value of zero from any of these functions means that the
|
||||||
|
argument was zero.
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr bitstring 3
|
.Xr bitstring 3
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
@ -69,3 +90,11 @@ before it was moved to
|
|||||||
for
|
for
|
||||||
.St -p1003.1-2001
|
.St -p1003.1-2001
|
||||||
compliance.
|
compliance.
|
||||||
|
.Pp
|
||||||
|
The
|
||||||
|
.Fn ffsl ,
|
||||||
|
.Fn fls
|
||||||
|
and
|
||||||
|
.Fn flsl
|
||||||
|
functions appeared in
|
||||||
|
.Fx 5.3 .
|
||||||
|
@ -40,7 +40,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ffs -- vax ffs instruction
|
* Find First Set bit
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ffs(int mask)
|
ffs(int mask)
|
||||||
@ -50,6 +50,6 @@ ffs(int mask)
|
|||||||
if (mask == 0)
|
if (mask == 0)
|
||||||
return(0);
|
return(0);
|
||||||
for (bit = 1; !(mask & 1); bit++)
|
for (bit = 1; !(mask & 1); bit++)
|
||||||
mask >>= 1;
|
(unsigned int)mask >>= 1;
|
||||||
return(bit);
|
return (bit);
|
||||||
}
|
}
|
||||||
|
52
lib/libc/string/ffsl.c
Normal file
52
lib/libc/string/ffsl.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find First Set bit
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ffsl(long mask)
|
||||||
|
{
|
||||||
|
int bit;
|
||||||
|
|
||||||
|
if (mask == 0)
|
||||||
|
return(0);
|
||||||
|
for (bit = 1; !(mask & 1); bit++)
|
||||||
|
(unsigned long)mask >>= 1;
|
||||||
|
return (bit);
|
||||||
|
}
|
52
lib/libc/string/fls.c
Normal file
52
lib/libc/string/fls.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find Last Set bit
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
fls(int mask)
|
||||||
|
{
|
||||||
|
int bit;
|
||||||
|
|
||||||
|
if (mask == 0)
|
||||||
|
return (0);
|
||||||
|
for (bit = 1; mask != 1; bit++)
|
||||||
|
(unsigned int)mask >>= 1;
|
||||||
|
return (bit);
|
||||||
|
}
|
52
lib/libc/string/flsl.c
Normal file
52
lib/libc/string/flsl.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <strings.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find Last Set bit
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
flsl(long mask)
|
||||||
|
{
|
||||||
|
int bit;
|
||||||
|
|
||||||
|
if (mask == 0)
|
||||||
|
return (0);
|
||||||
|
for (bit = 1; mask != 1; bit++)
|
||||||
|
(unsigned long)mask >>= 1;
|
||||||
|
return (bit);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user