From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26214 invoked by alias); 4 Jul 2017 13:34:50 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 26104 invoked by uid 89); 4 Jul 2017 13:34:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=incidental, H*r:sk:zimbra., HOWEVER, ffs X-HELO: dedi548.your-server.de Received: from dedi548.your-server.de (HELO dedi548.your-server.de) (85.10.215.148) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 04 Jul 2017 13:34:46 +0000 Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dSNyW-0002AM-72 for newlib@sourceware.org; Tue, 04 Jul 2017 15:34:44 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dSNyV-0004N3-CX for newlib@sourceware.org; Tue, 04 Jul 2017 15:34:44 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 0E18D2A1679 for ; Tue, 4 Jul 2017 15:34:50 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 29CqjaK5jwGo for ; Tue, 4 Jul 2017 15:34:47 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id C85042A004F for ; Tue, 4 Jul 2017 15:34:47 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id Rcg6hOI_1ali for ; Tue, 4 Jul 2017 15:34:47 +0200 (CEST) Received: from linux-diu0.suse (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id 8FC042A167A for ; Tue, 4 Jul 2017 15:34:47 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll() Date: Tue, 04 Jul 2017 13:34:00 -0000 Message-Id: <20170704133435.9840-3-sebastian.huber@embedded-brains.de> In-Reply-To: <20170704133435.9840-1-sebastian.huber@embedded-brains.de> References: <20170704133435.9840-1-sebastian.huber@embedded-brains.de> X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00550.txt.bz2 Use compiler builtin for ffs(). Remove duplicate implementation from Cygwin. Signed-off-by: Sebastian Huber --- newlib/libc/misc/ffs.c | 14 ++------- newlib/libc/string/Makefile.am | 5 ++++ newlib/libc/string/Makefile.in | 64 +++++++++++++++++++++++++++++++++--------- newlib/libc/string/ffsl.c | 34 ++++++++++++++++++++++ newlib/libc/string/ffsll.c | 34 ++++++++++++++++++++++ newlib/libc/string/fls.c | 35 +++++++++++++++++++++++ newlib/libc/string/flsl.c | 35 +++++++++++++++++++++++ newlib/libc/string/flsll.c | 35 +++++++++++++++++++++++ winsup/cygwin/syscalls.cc | 22 --------------- 9 files changed, 231 insertions(+), 47 deletions(-) create mode 100644 newlib/libc/string/ffsl.c create mode 100644 newlib/libc/string/ffsll.c create mode 100644 newlib/libc/string/fls.c create mode 100644 newlib/libc/string/flsl.c create mode 100644 newlib/libc/string/flsll.c diff --git a/newlib/libc/misc/ffs.c b/newlib/libc/misc/ffs.c index 7fc38c8d8..ba5700920 100644 --- a/newlib/libc/misc/ffs.c +++ b/newlib/libc/misc/ffs.c @@ -29,18 +29,8 @@ No supporting OS subroutines are required. */ #include int -_DEFUN(ffs, (word), - int word) +ffs(int i) { - int i; - if (!word) - return 0; - - i = 0; - for (;;) - { - if (((1 << i++) & word) != 0) - return i; - } + return (__builtin_ffs(i)); } diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index bb5a78fe6..e62f28627 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -8,6 +8,11 @@ GENERAL_SOURCES = \ bcopy.c \ bzero.c \ explicit_bzero.c \ + ffsl.c \ + ffsll.c \ + fls.c \ + flsl.c \ + flsll.c \ index.c \ memchr.c \ memcmp.c \ diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index bd330e481..63681d070 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -73,7 +73,9 @@ ARFLAGS = cru lib_a_AR = $(AR) $(ARFLAGS) lib_a_LIBADD = am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \ - lib_a-explicit_bzero.$(OBJEXT) lib_a-index.$(OBJEXT) \ + lib_a-explicit_bzero.$(OBJEXT) lib_a-ffsl.$(OBJEXT) \ + lib_a-ffsll.$(OBJEXT) lib_a-fls.$(OBJEXT) lib_a-flsl.$(OBJEXT) \ + lib_a-flsll.$(OBJEXT) lib_a-index.$(OBJEXT) \ lib_a-memchr.$(OBJEXT) lib_a-memcmp.$(OBJEXT) \ lib_a-memcpy.$(OBJEXT) lib_a-memmove.$(OBJEXT) \ lib_a-memset.$(OBJEXT) lib_a-rindex.$(OBJEXT) \ @@ -140,18 +142,19 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \ lib_a_OBJECTS = $(am_lib_a_OBJECTS) LTLIBRARIES = $(noinst_LTLIBRARIES) libstring_la_LIBADD = -am__objects_4 = bcopy.lo bzero.lo explicit_bzero.lo index.lo memchr.lo \ - memcmp.lo memcpy.lo memmove.lo memset.lo rindex.lo \ - strcasecmp.lo strcat.lo strchr.lo strcmp.lo strcoll.lo \ - strcpy.lo strcspn.lo strdup.lo strdup_r.lo strerror.lo \ - strerror_r.lo strlcat.lo strlcpy.lo strlen.lo strlwr.lo \ - strncasecmp.lo strncat.lo strncmp.lo strncpy.lo strnlen.lo \ - strpbrk.lo strrchr.lo strsep.lo strsignal.lo strspn.lo \ - strtok.lo strtok_r.lo strupr.lo strxfrm.lo strstr.lo swab.lo \ - timingsafe_bcmp.lo timingsafe_memcmp.lo u_strerr.lo wcscat.lo \ - wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo \ - wcslcpy.lo wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo \ - wcsnlen.lo wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcstok.lo \ +am__objects_4 = bcopy.lo bzero.lo explicit_bzero.lo ffsl.lo ffsll.lo \ + fls.lo flsl.lo flsll.lo index.lo memchr.lo memcmp.lo memcpy.lo \ + memmove.lo memset.lo rindex.lo strcasecmp.lo strcat.lo \ + strchr.lo strcmp.lo strcoll.lo strcpy.lo strcspn.lo strdup.lo \ + strdup_r.lo strerror.lo strerror_r.lo strlcat.lo strlcpy.lo \ + strlen.lo strlwr.lo strncasecmp.lo strncat.lo strncmp.lo \ + strncpy.lo strnlen.lo strpbrk.lo strrchr.lo strsep.lo \ + strsignal.lo strspn.lo strtok.lo strtok_r.lo strupr.lo \ + strxfrm.lo strstr.lo swab.lo timingsafe_bcmp.lo \ + timingsafe_memcmp.lo u_strerr.lo wcscat.lo wcschr.lo wcscmp.lo \ + wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo wcslcpy.lo \ + wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo wcsnlen.lo \ + wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcstok.lo \ wcswidth.lo wcsxfrm.lo wcwidth.lo wmemchr.lo wmemcmp.lo \ wmemcpy.lo wmemmove.lo wmemset.lo xpg_strerror_r.lo @ELIX_LEVEL_1_FALSE@am__objects_5 = bcmp.lo memccpy.lo mempcpy.lo \ @@ -351,6 +354,11 @@ GENERAL_SOURCES = \ bcopy.c \ bzero.c \ explicit_bzero.c \ + ffsl.c \ + ffsll.c \ + fls.c \ + flsl.c \ + flsll.c \ index.c \ memchr.c \ memcmp.c \ @@ -582,6 +590,36 @@ lib_a-explicit_bzero.o: explicit_bzero.c lib_a-explicit_bzero.obj: explicit_bzero.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-explicit_bzero.obj `if test -f 'explicit_bzero.c'; then $(CYGPATH_W) 'explicit_bzero.c'; else $(CYGPATH_W) '$(srcdir)/explicit_bzero.c'; fi` +lib_a-ffsl.o: ffsl.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ffsl.o `test -f 'ffsl.c' || echo '$(srcdir)/'`ffsl.c + +lib_a-ffsl.obj: ffsl.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ffsl.obj `if test -f 'ffsl.c'; then $(CYGPATH_W) 'ffsl.c'; else $(CYGPATH_W) '$(srcdir)/ffsl.c'; fi` + +lib_a-ffsll.o: ffsll.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ffsll.o `test -f 'ffsll.c' || echo '$(srcdir)/'`ffsll.c + +lib_a-ffsll.obj: ffsll.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-ffsll.obj `if test -f 'ffsll.c'; then $(CYGPATH_W) 'ffsll.c'; else $(CYGPATH_W) '$(srcdir)/ffsll.c'; fi` + +lib_a-fls.o: fls.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fls.o `test -f 'fls.c' || echo '$(srcdir)/'`fls.c + +lib_a-fls.obj: fls.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-fls.obj `if test -f 'fls.c'; then $(CYGPATH_W) 'fls.c'; else $(CYGPATH_W) '$(srcdir)/fls.c'; fi` + +lib_a-flsl.o: flsl.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-flsl.o `test -f 'flsl.c' || echo '$(srcdir)/'`flsl.c + +lib_a-flsl.obj: flsl.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-flsl.obj `if test -f 'flsl.c'; then $(CYGPATH_W) 'flsl.c'; else $(CYGPATH_W) '$(srcdir)/flsl.c'; fi` + +lib_a-flsll.o: flsll.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-flsll.o `test -f 'flsll.c' || echo '$(srcdir)/'`flsll.c + +lib_a-flsll.obj: flsll.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-flsll.obj `if test -f 'flsll.c'; then $(CYGPATH_W) 'flsll.c'; else $(CYGPATH_W) '$(srcdir)/flsll.c'; fi` + lib_a-index.o: index.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-index.o `test -f 'index.c' || echo '$(srcdir)/'`index.c diff --git a/newlib/libc/string/ffsl.c b/newlib/libc/string/ffsl.c new file mode 100644 index 000000000..4b1d52d27 --- /dev/null +++ b/newlib/libc/string/ffsl.c @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2017 embedded brains GmbH + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 + +int +ffsl(long i) +{ + + return (__builtin_ffsl(i)); +} diff --git a/newlib/libc/string/ffsll.c b/newlib/libc/string/ffsll.c new file mode 100644 index 000000000..71725069f --- /dev/null +++ b/newlib/libc/string/ffsll.c @@ -0,0 +1,34 @@ +/*- + * Copyright (c) 2017 embedded brains GmbH + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 + +int +ffsll(long long i) +{ + + return (__builtin_ffsll(i)); +} diff --git a/newlib/libc/string/fls.c b/newlib/libc/string/fls.c new file mode 100644 index 000000000..fa5a73322 --- /dev/null +++ b/newlib/libc/string/fls.c @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2017 embedded brains GmbH + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 +#include + +int +fls(int i) +{ + + return (sizeof(i) * CHAR_BIT - __builtin_clz(i)); +} diff --git a/newlib/libc/string/flsl.c b/newlib/libc/string/flsl.c new file mode 100644 index 000000000..22661d2d2 --- /dev/null +++ b/newlib/libc/string/flsl.c @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2017 embedded brains GmbH + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 +#include + +int +flsl(long i) +{ + + return (sizeof(i) * CHAR_BIT - __builtin_clzl(i)); +} diff --git a/newlib/libc/string/flsll.c b/newlib/libc/string/flsll.c new file mode 100644 index 000000000..bdb63adb9 --- /dev/null +++ b/newlib/libc/string/flsll.c @@ -0,0 +1,35 @@ +/*- + * Copyright (c) 2017 embedded brains GmbH + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 +#include + +int +flsll(long long i) +{ + + return (sizeof(i) * CHAR_BIT - __builtin_clzll(i)); +} diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc index faee928bf..c78772586 100644 --- a/winsup/cygwin/syscalls.cc +++ b/winsup/cygwin/syscalls.cc @@ -3784,28 +3784,6 @@ nice (int incr) return setpriority (PRIO_PROCESS, myself->pid, myself->nice + incr); } -/* - * Find the first bit set in I. - */ - -extern "C" int -ffs (int i) -{ - return __builtin_ffs (i); -} - -extern "C" int -ffsl (long i) -{ - return __builtin_ffsl (i); -} - -extern "C" int -ffsll (long long i) -{ - return __builtin_ffsll (i); -} - static void locked_append (int fd, const void * buf, size_t size) { -- 2.12.3