svn commit: r185025 - in stable/7: include lib/libc lib/libc/string

Konstantin Belousov kib at FreeBSD.org
Mon Nov 17 10:45:08 PST 2008


Author: kib
Date: Mon Nov 17 18:45:07 2008
New Revision: 185025
URL: http://svn.freebsd.org/changeset/base/185025

Log:
  MFC r184587:
  
  Add the ffsll and flsll functions. These are ffs and fls operating
  on long long arguments.
  
  Approved by:	re (kensmith)

Added:
  stable/7/lib/libc/string/ffsll.c
     - copied unchanged from r184587, head/lib/libc/string/ffsll.c
  stable/7/lib/libc/string/flsll.c
     - copied unchanged from r184587, head/lib/libc/string/flsll.c
Modified:
  stable/7/include/   (props changed)
  stable/7/include/strings.h
  stable/7/lib/libc/   (props changed)
  stable/7/lib/libc/string/Makefile.inc
  stable/7/lib/libc/string/Symbol.map
  stable/7/lib/libc/string/ffs.3

Modified: stable/7/include/strings.h
==============================================================================
--- stable/7/include/strings.h	Mon Nov 17 16:37:04 2008	(r185024)
+++ stable/7/include/strings.h	Mon Nov 17 18:45:07 2008	(r185025)
@@ -44,8 +44,10 @@ void	 bzero(void *, size_t);					/* LEGA
 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 */

Modified: stable/7/lib/libc/string/Makefile.inc
==============================================================================
--- stable/7/lib/libc/string/Makefile.inc	Mon Nov 17 16:37:04 2008	(r185024)
+++ stable/7/lib/libc/string/Makefile.inc	Mon Nov 17 18:45:07 2008	(r185025)
@@ -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 f
 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

Modified: stable/7/lib/libc/string/Symbol.map
==============================================================================
--- stable/7/lib/libc/string/Symbol.map	Mon Nov 17 16:37:04 2008	(r185024)
+++ stable/7/lib/libc/string/Symbol.map	Mon Nov 17 18:45:07 2008	(r185025)
@@ -78,6 +78,8 @@ FBSD_1.0 {
 };
 
 FBSD_1.1 {
+	ffsll;
+	flsll;
 	memrchr;
 };
 

Modified: stable/7/lib/libc/string/ffs.3
==============================================================================
--- stable/7/lib/libc/string/ffs.3	Mon Nov 17 16:37:04 2008	(r185024)
+++ stable/7/lib/libc/string/ffs.3	Mon Nov 17 18:45:07 2008	(r185025)
@@ -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 .

Copied: stable/7/lib/libc/string/ffsll.c (from r184587, head/lib/libc/string/ffsll.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/7/lib/libc/string/ffsll.c	Mon Nov 17 18:45:07 2008	(r185025, copy of r184587, head/lib/libc/string/ffsll.c)
@@ -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);
+}

Copied: stable/7/lib/libc/string/flsll.c (from r184587, head/lib/libc/string/flsll.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/7/lib/libc/string/flsll.c	Mon Nov 17 18:45:07 2008	(r185025, copy of r184587, head/lib/libc/string/flsll.c)
@@ -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);
+}


More information about the svn-src-stable-7 mailing list