diff options
-rw-r--r-- | sys/conf/files | 4 | ||||
-rw-r--r-- | sys/lib/libkern/fls.c | 46 | ||||
-rw-r--r-- | sys/lib/libkern/flsl.c | 46 | ||||
-rw-r--r-- | sys/lib/libkern/libkern.h | 4 |
4 files changed, 98 insertions, 2 deletions
diff --git a/sys/conf/files b/sys/conf/files index a38320e87e2..96eca7bc44e 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.548 2013/06/11 18:17:25 deraadt Exp $ +# $OpenBSD: files,v 1.549 2013/07/11 01:20:31 jsg Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -1026,6 +1026,8 @@ file lib/libkern/arch/${MACHINE_ARCH}/bcopy.S | lib/libkern/bcopy.c file lib/libkern/arch/${MACHINE_ARCH}/memcpy.S | lib/libkern/memcpy.c file lib/libkern/arch/${MACHINE_ARCH}/memmove.S | lib/libkern/memmove.c file lib/libkern/arch/${MACHINE_ARCH}/ffs.S | lib/libkern/ffs.c +file lib/libkern/arch/${MACHINE_ARCH}/fls.S | lib/libkern/fls.c +file lib/libkern/arch/${MACHINE_ARCH}/flsl.S | lib/libkern/flsl.c file lib/libkern/arch/${MACHINE_ARCH}/memset.S | lib/libkern/memset.c file lib/libkern/arch/${MACHINE_ARCH}/strcmp.S | lib/libkern/strcmp.c file lib/libkern/arch/${MACHINE_ARCH}/strlcat.S | lib/libkern/strlcat.c diff --git a/sys/lib/libkern/fls.c b/sys/lib/libkern/fls.c new file mode 100644 index 00000000000..8de9d6eaed9 --- /dev/null +++ b/sys/lib/libkern/fls.c @@ -0,0 +1,46 @@ +/* $OpenBSD: fls.c,v 1.1 2013/07/11 01:20:32 jsg Exp $ */ +/*- + * 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. 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 <lib/libkern/libkern.h> + +/* + * Find Last Set bit + */ +int +fls(int mask) +{ + int bit; + + if (mask == 0) + return (0); + for (bit = 1; mask != 1; bit++) + mask = (unsigned int)mask >> 1; + return (bit); +} diff --git a/sys/lib/libkern/flsl.c b/sys/lib/libkern/flsl.c new file mode 100644 index 00000000000..7f4063eef48 --- /dev/null +++ b/sys/lib/libkern/flsl.c @@ -0,0 +1,46 @@ +/* $OpenBSD: flsl.c,v 1.1 2013/07/11 01:20:32 jsg Exp $ */ +/*- + * 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. 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 <lib/libkern/libkern.h> + +/* + * Find Last Set bit + */ +int +flsl(long mask) +{ + int bit; + + if (mask == 0) + return (0); + for (bit = 1; mask != 1; bit++) + mask = (unsigned long)mask >> 1; + return (bit); +} diff --git a/sys/lib/libkern/libkern.h b/sys/lib/libkern/libkern.h index cb9817bce7f..9de6fbf84b4 100644 --- a/sys/lib/libkern/libkern.h +++ b/sys/lib/libkern/libkern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libkern.h,v 1.30 2013/06/08 19:06:50 sf Exp $ */ +/* $OpenBSD: libkern.h,v 1.31 2013/07/11 01:20:32 jsg Exp $ */ /* $NetBSD: libkern.h,v 1.7 1996/03/14 18:52:08 christos Exp $ */ /*- @@ -148,6 +148,8 @@ int bcmp(const void *, const void *, size_t); void bzero(void *, size_t); void explicit_bzero(void *, size_t); int ffs(int); +int fls(int); +int flsl(long); void *memchr(const void *, int, size_t); int memcmp(const void *, const void *, size_t); u_int32_t random(void); |