mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-27 19:37:53 +01:00
Add the ffsll and flsll functions. These are ffs and fls operating
on long long arguments. Reviewed by: bde (previous version, that included asm implementation for all ffs and fls functions on i386 and amd64) MFC after: 2 weeks
This commit is contained in:
parent
6f41f432e1
commit
4a723bd20c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=184587
@ -44,8 +44,10 @@ void bzero(void *, size_t); /* LEGACY */
|
||||
int ffs(int) __pure2;
|
||||
#ifdef __BSD_VISIBLE
|
||||
int ffsl(long) __pure2;
|
||||
int ffsll(long long) __pure2;
|
||||
int fls(int) __pure2;
|
||||
int flsl(long) __pure2;
|
||||
int flsll(long long) __pure2;
|
||||
#endif
|
||||
char *index(const char *, int) __pure; /* LEGACY */
|
||||
char *rindex(const char *, int) __pure; /* LEGACY */
|
||||
|
@ -6,8 +6,8 @@
|
||||
CFLAGS+= -I${.CURDIR}/locale
|
||||
|
||||
# machine-independent string sources
|
||||
MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c fls.c flsl.c index.c memccpy.c \
|
||||
memchr.c memrchr.c memcmp.c \
|
||||
MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \
|
||||
index.c memccpy.c memchr.c memrchr.c memcmp.c \
|
||||
memcpy.c memmem.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 strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c \
|
||||
@ -38,6 +38,8 @@ MAN+= bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \
|
||||
MLINKS+=ffs.3 ffsl.3
|
||||
MLINKS+=ffs.3 fls.3
|
||||
MLINKS+=ffs.3 flsl.3
|
||||
MLINKS+=ffs.3 ffsll.3
|
||||
MLINKS+=ffs.3 flsll.3
|
||||
MLINKS+=index.3 rindex.3
|
||||
MLINKS+=memchr.3 memrchr.3
|
||||
MLINKS+=strcasecmp.3 strncasecmp.3
|
||||
|
@ -78,6 +78,8 @@ FBSD_1.0 {
|
||||
};
|
||||
|
||||
FBSD_1.1 {
|
||||
ffsll;
|
||||
flsll;
|
||||
memrchr;
|
||||
};
|
||||
|
||||
|
@ -30,14 +30,16 @@
|
||||
.\" @(#)ffs.3 8.2 (Berkeley) 4/19/94
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 12, 2006
|
||||
.Dd October 26, 2008
|
||||
.Dt FFS 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ffs ,
|
||||
.Nm ffsl ,
|
||||
.Nm ffsll ,
|
||||
.Nm fls ,
|
||||
.Nm flsl
|
||||
.Nm flsl ,
|
||||
.Nm flsll
|
||||
.Nd find first or last bit set in a bit string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
@ -48,14 +50,19 @@
|
||||
.Ft int
|
||||
.Fn ffsl "long value"
|
||||
.Ft int
|
||||
.Ft int
|
||||
.Fn ffsll "long long value"
|
||||
.Fn fls "int value"
|
||||
.Ft int
|
||||
.Fn flsl "long value"
|
||||
.Ft int
|
||||
.Fn flsll "long long value"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn ffs
|
||||
and
|
||||
.Fn ffs ,
|
||||
.Fn ffsl
|
||||
and
|
||||
.Fn ffsll
|
||||
functions find the first bit set
|
||||
(beginning with the least significant bit)
|
||||
in
|
||||
@ -63,9 +70,10 @@ in
|
||||
and return the index of that bit.
|
||||
.Pp
|
||||
The
|
||||
.Fn fls
|
||||
and
|
||||
.Fn fls ,
|
||||
.Fn flsl
|
||||
and
|
||||
.Fn flsll
|
||||
functions find the last bit set in
|
||||
.Fa value
|
||||
and return the index of that bit.
|
||||
@ -95,3 +103,9 @@ and
|
||||
.Fn flsl
|
||||
functions appeared in
|
||||
.Fx 5.3 .
|
||||
The
|
||||
.Fn ffsll
|
||||
and
|
||||
.Fn flsll
|
||||
functions appeared in
|
||||
.Fx 8.0 .
|
||||
|
48
lib/libc/string/ffsll.c
Normal file
48
lib/libc/string/ffsll.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* 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.
|
||||
* 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
|
||||
ffsll(long long mask)
|
||||
{
|
||||
int bit;
|
||||
|
||||
if (mask == 0)
|
||||
return (0);
|
||||
for (bit = 1; !(mask & 1); bit++)
|
||||
mask = (unsigned long long)mask >> 1;
|
||||
return (bit);
|
||||
}
|
48
lib/libc/string/flsll.c
Normal file
48
lib/libc/string/flsll.c
Normal file
@ -0,0 +1,48 @@
|
||||
/*-
|
||||
* 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.
|
||||
* 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
|
||||
flsll(long long mask)
|
||||
{
|
||||
int bit;
|
||||
|
||||
if (mask == 0)
|
||||
return (0);
|
||||
for (bit = 1; mask != 1; bit++)
|
||||
mask = (unsigned long long)mask >> 1;
|
||||
return (bit);
|
||||
}
|
Loading…
Reference in New Issue
Block a user