* [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-04 13:34 [PATCH 1/3] Implement bzero() via memset() Sebastian Huber
2017-07-04 13:34 ` [PATCH 2/3] Synchronize <strings.h> with latest FreeBSD Sebastian Huber
@ 2017-07-04 13:34 ` Sebastian Huber
2017-07-05 6:06 ` Sebastian Huber
2017-07-05 8:54 ` [PATCH v2 " Sebastian Huber
1 sibling, 2 replies; 16+ messages in thread
From: Sebastian Huber @ 2017-07-04 13:34 UTC (permalink / raw)
To: newlib
Use compiler builtin for ffs(). Remove duplicate implementation from
Cygwin.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
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 <strings.h>
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 <strings.h>
+
+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 <strings.h>
+
+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 <strings.h>
+#include <limits.h>
+
+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 <strings.h>
+#include <limits.h>
+
+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 <strings.h>
+#include <limits.h>
+
+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
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/3] Implement bzero() via memset()
@ 2017-07-04 13:34 Sebastian Huber
2017-07-04 13:34 ` [PATCH 2/3] Synchronize <strings.h> with latest FreeBSD Sebastian Huber
2017-07-04 13:34 ` [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll() Sebastian Huber
0 siblings, 2 replies; 16+ messages in thread
From: Sebastian Huber @ 2017-07-04 13:34 UTC (permalink / raw)
To: newlib
Use memset() to implement bzero() to profit from machine-specific
memset() optimizations.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
newlib/libc/string/bzero.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/newlib/libc/string/bzero.c b/newlib/libc/string/bzero.c
index dbcae02d6..e99529af6 100644
--- a/newlib/libc/string/bzero.c
+++ b/newlib/libc/string/bzero.c
@@ -30,14 +30,11 @@ Neither ANSI C nor the System V Interface Definition (Issue 2) require
<<bzero>> requires no supporting OS subroutines.
*/
-#include <strings.h>
+#include <string.h>
-_VOID
-_DEFUN (bzero, (b, length),
- void *b _AND
- size_t length)
+void
+bzero(void *b, size_t length)
{
- char *ptr = (char *)b;
- while (length--)
- *ptr++ = 0;
+
+ memset(b, 0, length);
}
--
2.12.3
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/3] Synchronize <strings.h> with latest FreeBSD
2017-07-04 13:34 [PATCH 1/3] Implement bzero() via memset() Sebastian Huber
@ 2017-07-04 13:34 ` Sebastian Huber
2017-07-04 13:34 ` [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll() Sebastian Huber
1 sibling, 0 replies; 16+ messages in thread
From: Sebastian Huber @ 2017-07-04 13:34 UTC (permalink / raw)
To: newlib
Include <strings.h> in <string.h> if __BSD_VISIBLE like on FreeBSD.
Remove redundant declarations from <string.h>. Make ffsl(), ffsll(),
strncasecmp(), strcasecmp_l(), and strncasecmp_l() visible via
__BSD_VISIBLE instead of __GNU_VISIBLE. Add fls(), flsl(), and flsll()
to <strings.h> if __BSD_VISIBLE.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
newlib/libc/include/string.h | 32 ++--------------
newlib/libc/include/strings.h | 89 ++++++++++++++++++++++++++++---------------
2 files changed, 62 insertions(+), 59 deletions(-)
diff --git a/newlib/libc/include/string.h b/newlib/libc/include/string.h
index 75de50351..29e0d4476 100644
--- a/newlib/libc/include/string.h
+++ b/newlib/libc/include/string.h
@@ -20,6 +20,10 @@
#include <xlocale.h>
#endif
+#if __BSD_VISIBLE
+#include <strings.h>
+#endif
+
_BEGIN_STD_C
_PTR _EXFUN(memchr,(const _PTR, int, size_t));
@@ -52,27 +56,13 @@ int strcoll_l (const char *, const char *, locale_t);
char *strerror_l (int, locale_t);
size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
#endif
-#if __GNU_VISIBLE
-int strcasecmp_l (const char *, const char *, locale_t);
-int strncasecmp_l (const char *, const char *, size_t, locale_t);
-#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE
char *_EXFUN(strtok_r,(char *__restrict, const char *__restrict, char **__restrict));
#endif
-#if __BSD_VISIBLE /* POSIX declaration is in <strings.h> */
-int _EXFUN(bcmp,(const void *, const void *, size_t));
-void _EXFUN(bcopy,(const void *, void *, size_t));
-void _EXFUN(bzero,(void *, size_t));
-#endif
#if __BSD_VISIBLE
-void _EXFUN(explicit_bzero,(void *, size_t));
int _EXFUN(timingsafe_bcmp,(const void *, const void *, size_t));
int _EXFUN(timingsafe_memcmp,(const void *, const void *, size_t));
#endif
-#if __BSD_VISIBLE /* POSIX declaration is in <strings.h> */
-int _EXFUN(ffs,(int));
-char *_EXFUN(index,(const char *, int));
-#endif
#if __MISC_VISIBLE || __POSIX_VISIBLE
_PTR _EXFUN(memccpy,(_PTR __restrict, const _PTR __restrict, int, size_t));
#endif
@@ -82,16 +72,10 @@ _PTR _EXFUN(memmem, (const _PTR, size_t, const _PTR, size_t));
_PTR _EXFUN(memrchr,(const _PTR, int, size_t));
_PTR _EXFUN(rawmemchr,(const _PTR, int));
#endif
-#if __BSD_VISIBLE /* POSIX declaration is in <strings.h> */
-char *_EXFUN(rindex,(const char *, int));
-#endif
#if __POSIX_VISIBLE >= 200809
char *_EXFUN(stpcpy,(char *__restrict, const char *__restrict));
char *_EXFUN(stpncpy,(char *__restrict, const char *__restrict, size_t));
#endif
-#if __BSD_VISIBLE /* POSIX declaration is in <strings.h> */
-int _EXFUN(strcasecmp,(const char *, const char *));
-#endif
#if __GNU_VISIBLE
char *_EXFUN(strcasestr,(const char *, const char *));
char *_EXFUN(strchrnul,(const char *, int));
@@ -105,11 +89,6 @@ char *_EXFUN(strndup,(const char *, size_t));
#endif
char *_EXFUN(_strndup_r,(struct _reent *, const char *, size_t));
-#if __GNU_VISIBLE
-int _EXFUN(ffsl,(long));
-int _EXFUN(ffsll, (long long));
-#endif
-
/* There are two common strerror_r variants. If you request
_GNU_SOURCE, you get the GNU version; otherwise you get the POSIX
version. POSIX requires that #undef strerror_r will still let you
@@ -136,9 +115,6 @@ char * _EXFUN(_strerror_r, (struct _reent *, int, int, int *));
size_t _EXFUN(strlcat,(char *, const char *, size_t));
size_t _EXFUN(strlcpy,(char *, const char *, size_t));
#endif
-#if __BSD_VISIBLE /* POSIX declaration is in <strings.h> */
-int _EXFUN(strncasecmp,(const char *, const char *, size_t));
-#endif
#if __POSIX_VISIBLE >= 200809
size_t _EXFUN(strnlen,(const char *, size_t));
#endif
diff --git a/newlib/libc/include/strings.h b/newlib/libc/include/strings.h
index 3331611ab..35fcdc092 100644
--- a/newlib/libc/include/strings.h
+++ b/newlib/libc/include/strings.h
@@ -1,49 +1,76 @@
-/*
- * strings.h
+/*-
+ * Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
+ * All rights reserved.
*
- * Definitions for string operations.
+ * 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.
+ *
+ * $FreeBSD: head/include/strings.h 272673 2014-10-07 04:54:11Z delphij $
*/
#ifndef _STRINGS_H_
-#define _STRINGS_H_
+#define _STRINGS_H_
-/* These functions are already declared in <string.h> with __BSD_VISIBLE */
-#if !(defined(_STRING_H_) && __BSD_VISIBLE)
-
-#include "_ansi.h"
-#include <sys/reent.h>
#include <sys/cdefs.h>
-#include <sys/types.h> /* for size_t */
+#include <sys/_types.h>
#if __POSIX_VISIBLE >= 200809
#include <xlocale.h>
#endif
-_BEGIN_STD_C
-
-#if __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809)
-/*
- * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004
- * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008
- */
-int _EXFUN(bcmp,(const void *, const void *, size_t));
-void _EXFUN(bcopy,(const void *, void *, size_t));
-void _EXFUN(bzero,(void *, size_t));
-char *_EXFUN(index,(const char *, int));
-char *_EXFUN(rindex,(const char *, int));
-#endif /* __BSD_VISIBLE || (__POSIX_VISIBLE && __POSIX_VISIBLE < 200809) */
+#ifndef _SIZE_T_DECLARED
+typedef __size_t size_t;
+#define _SIZE_T_DECLARED
+#endif
-int _EXFUN(ffs,(int));
-int _EXFUN(strcasecmp,(const char *, const char *));
-int _EXFUN(strncasecmp,(const char *, const char *, size_t));
+__BEGIN_DECLS
+#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112
+int bcmp(const void *, const void *, size_t) __pure; /* LEGACY */
+void bcopy(const void *, void *, size_t); /* LEGACY */
+void bzero(void *, size_t); /* LEGACY */
+#endif
+#if __BSD_VISIBLE
+void explicit_bzero(void *, size_t);
+#endif
+#if __XSI_VISIBLE
+int ffs(int) __pure2;
+#endif
+#if __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
+#if __BSD_VISIBLE || __POSIX_VISIBLE <= 200112
+char *index(const char *, int) __pure; /* LEGACY */
+char *rindex(const char *, int) __pure; /* LEGACY */
+#endif
+int strcasecmp(const char *, const char *) __pure;
+int strncasecmp(const char *, const char *, size_t) __pure;
#if __POSIX_VISIBLE >= 200809
int strcasecmp_l (const char *, const char *, locale_t);
int strncasecmp_l (const char *, const char *, size_t, locale_t);
-#endif /* __POSIX_VISIBLE >= 200809 */
-
-_END_STD_C
-
-#endif /* !(_STRING_H_ && __BSD_VISIBLE) */
+#endif
+__END_DECLS
#endif /* _STRINGS_H_ */
--
2.12.3
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-04 13:34 ` [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll() Sebastian Huber
@ 2017-07-05 6:06 ` Sebastian Huber
2017-07-05 8:42 ` Corinna Vinschen
2017-07-05 8:54 ` [PATCH v2 " Sebastian Huber
1 sibling, 1 reply; 16+ messages in thread
From: Sebastian Huber @ 2017-07-05 6:06 UTC (permalink / raw)
To: newlib
On 04/07/17 15:34, Sebastian Huber wrote:
> +int
> +fls(int i)
> +{
> +
> + return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
> +}
I just realized that the result of __builtin_clz(i) is undefined if i ==
0. However, fls(0) should return 0. So this must be changed to:
int
fls(int i)
{
if (i == 0)
return (0);
return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
}
Similar for flsl() and flsll().
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-05 6:06 ` Sebastian Huber
@ 2017-07-05 8:42 ` Corinna Vinschen
0 siblings, 0 replies; 16+ messages in thread
From: Corinna Vinschen @ 2017-07-05 8:42 UTC (permalink / raw)
To: newlib
[-- Attachment #1: Type: text/plain, Size: 660 bytes --]
On Jul 5 08:06, Sebastian Huber wrote:
> On 04/07/17 15:34, Sebastian Huber wrote:
>
> > +int
> > +fls(int i)
> > +{
> > +
> > + return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
> > +}
>
> I just realized that the result of __builtin_clz(i) is undefined if i == 0.
> However, fls(0) should return 0. So this must be changed to:
>
> int
> fls(int i)
> {
>
> if (i == 0)
> return (0);
>
> return (sizeof(i) * CHAR_BIT - __builtin_clz(i));
> }
>
> Similar for flsl() and flsll().
Are you going to send a new patch series ir just a v2 for path 3?
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-04 13:34 ` [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll() Sebastian Huber
2017-07-05 6:06 ` Sebastian Huber
@ 2017-07-05 8:54 ` Sebastian Huber
2017-07-05 11:26 ` Corinna Vinschen
1 sibling, 1 reply; 16+ messages in thread
From: Sebastian Huber @ 2017-07-05 8:54 UTC (permalink / raw)
To: newlib
Use compiler builtin for ffs(). Remove duplicate implementation from
Cygwin.
Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
---
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 | 38 +++++++++++++++++++++++++
newlib/libc/string/flsl.c | 38 +++++++++++++++++++++++++
newlib/libc/string/flsll.c | 38 +++++++++++++++++++++++++
winsup/cygwin/syscalls.cc | 22 ---------------
9 files changed, 240 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 <strings.h>
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 <strings.h>
+
+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 <strings.h>
+
+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..a3e88d291
--- /dev/null
+++ b/newlib/libc/string/fls.c
@@ -0,0 +1,38 @@
+/*-
+ * 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 <strings.h>
+#include <limits.h>
+
+int
+fls(int i)
+{
+
+ if (i == 0)
+ return 0;
+
+ 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..af6277d1a
--- /dev/null
+++ b/newlib/libc/string/flsl.c
@@ -0,0 +1,38 @@
+/*-
+ * 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 <strings.h>
+#include <limits.h>
+
+int
+flsl(long i)
+{
+
+ if (i == 0)
+ return 0;
+
+ 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..393618484
--- /dev/null
+++ b/newlib/libc/string/flsll.c
@@ -0,0 +1,38 @@
+/*-
+ * 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 <strings.h>
+#include <limits.h>
+
+int
+flsll(long long i)
+{
+
+ if (i == 0)
+ return 0;
+
+ 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
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-05 8:54 ` [PATCH v2 " Sebastian Huber
@ 2017-07-05 11:26 ` Corinna Vinschen
2017-07-27 1:40 ` Kito Cheng
0 siblings, 1 reply; 16+ messages in thread
From: Corinna Vinschen @ 2017-07-05 11:26 UTC (permalink / raw)
To: Sebastian Huber; +Cc: newlib
[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]
On Jul 5 10:54, Sebastian Huber wrote:
> Use compiler builtin for ffs(). Remove duplicate implementation from
> Cygwin.
>
> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
> ---
> 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 | 38 +++++++++++++++++++++++++
> newlib/libc/string/flsl.c | 38 +++++++++++++++++++++++++
> newlib/libc/string/flsll.c | 38 +++++++++++++++++++++++++
> winsup/cygwin/syscalls.cc | 22 ---------------
> 9 files changed, 240 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
Patchset looks good, please push.
For Cygwin we also need to add the new fls* entry points to
common.din and to the docs. I'll do that later, when you
pushed your patch.
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
Red Hat
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-05 11:26 ` Corinna Vinschen
@ 2017-07-27 1:40 ` Kito Cheng
2017-07-27 5:47 ` Sebastian Huber
2017-07-27 6:50 ` Sebastian Huber
0 siblings, 2 replies; 16+ messages in thread
From: Kito Cheng @ 2017-07-27 1:40 UTC (permalink / raw)
To: newlib, Sebastian Huber
Hi
I am testing with RISC-V with newlib/trunk and just hang on ffs,
after investigate, I saw gcc just generate a ffs call in ffs for riscv64
and I guess riscv64 is not the only target will hit this bug,
so maybe we can revert the part of this patch, at least for ffs.c?
Code gen by riscv64-elf-gcc:
.file "ffs.c"
.option nopic
.globl ffs
.text
.align 1
.globl ffs
.type ffs, @function
ffs:
add sp,sp,-16
sd ra,8(sp)
call ffs
ld ra,8(sp)
sext.w a0,a0
add sp,sp,16
jr ra
.size ffs, .-ffs
.ident "GCC: (GNU) 8.0.0 20170509 (experimental)"
On Wed, Jul 5, 2017 at 7:26 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 5 10:54, Sebastian Huber wrote:
>> Use compiler builtin for ffs(). Remove duplicate implementation from
>> Cygwin.
>>
>> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
>> ---
>> 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 | 38 +++++++++++++++++++++++++
>> newlib/libc/string/flsl.c | 38 +++++++++++++++++++++++++
>> newlib/libc/string/flsll.c | 38 +++++++++++++++++++++++++
>> winsup/cygwin/syscalls.cc | 22 ---------------
>> 9 files changed, 240 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
>
> Patchset looks good, please push.
>
> For Cygwin we also need to add the new fls* entry points to
> common.din and to the docs. I'll do that later, when you
> pushed your patch.
>
>
> Thanks,
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 1:40 ` Kito Cheng
@ 2017-07-27 5:47 ` Sebastian Huber
2017-07-27 6:21 ` Sebastian Huber
2017-07-27 6:50 ` Sebastian Huber
1 sibling, 1 reply; 16+ messages in thread
From: Sebastian Huber @ 2017-07-27 5:47 UTC (permalink / raw)
To: Kito Cheng, newlib
On 27/07/17 03:40, Kito Cheng wrote:
> I am testing with RISC-V with newlib/trunk and just hang on ffs,
> after investigate, I saw gcc just generate a ffs call in ffs for riscv64
> and I guess riscv64 is not the only target will hit this bug,
> so maybe we can revert the part of this patch, at least for ffs.c?
We should first investigate why GCC performs this optimization. The file
is compiled with -fno-builtin, so it some other optimization. Maybe we
need something like __attribute__ ((__optimize__
("-fno-tree-loop-distribute-patterns"))) as in string/local.h.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 5:47 ` Sebastian Huber
@ 2017-07-27 6:21 ` Sebastian Huber
2017-07-27 6:38 ` Kito Cheng
0 siblings, 1 reply; 16+ messages in thread
From: Sebastian Huber @ 2017-07-27 6:21 UTC (permalink / raw)
To: Kito Cheng, newlib
On 27/07/17 07:47, Sebastian Huber wrote:
> On 27/07/17 03:40, Kito Cheng wrote:
>
>> I am testing with RISC-V with newlib/trunk and just hang on ffs,
>> after investigate, I saw gcc just generate a ffs call in ffs for riscv64
>> and I guess riscv64 is not the only target will hit this bug,
>> so maybe we can revert the part of this patch, at least for ffs.c?
>
> We should first investigate why GCC performs this optimization. The
> file is compiled with -fno-builtin, so it some other optimization.
> Maybe we need something like __attribute__ ((__optimize__
> ("-fno-tree-loop-distribute-patterns"))) as in string/local.h.
>
I tried to build a riscv32 GCC, but apparently there is no RISC-V
support in upstream Newlib:
n file included from
/home/EB/sebastian_h/archive/gcc-git/newlib/libc/include/sys/config.h:4:0,
from
/home/EB/sebastian_h/archive/gcc-git/newlib/libc/include/_ansi.h:16,
from
/home/EB/sebastian_h/archive/gcc-git/newlib/libc/include/sys/unistd.h:8,
from
/home/EB/sebastian_h/archive/gcc-git/newlib/libc/include/unistd.h:4,
from
/home/EB/sebastian_h/archive/gcc-git/newlib/libc/include/pthread.h:25,
from ./gthr-default.h:31,
from
/home/EB/sebastian_h/archive/gcc-git/libgcc/gthr.h:148,
from
/home/EB/sebastian_h/archive/gcc-git/libgcc/unwind-dw2.c:37:
/home/EB/sebastian_h/archive/gcc-git/newlib/libc/include/machine/ieeefp.h:428:2:
error: #error Endianess not declared!!
#error Endianess not declared!!
^~~~~
Do you have plans to add RISC-V support to upstream Newlib?
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 6:21 ` Sebastian Huber
@ 2017-07-27 6:38 ` Kito Cheng
2017-07-27 6:40 ` Kito Cheng
0 siblings, 1 reply; 16+ messages in thread
From: Kito Cheng @ 2017-07-27 6:38 UTC (permalink / raw)
To: Sebastian Huber; +Cc: newlib
> Do you have plans to add RISC-V support to upstream Newlib?
Yes, I plan submit patches in next few weeks and I am doing testing
now, we have already porting to newlib 2.5[1].
> We should first investigate why GCC performs this optimization. The file is compiled with -fno-builtin, so it some other optimization. Maybe we need something like __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) as in string/local.h.
-fno-builtin just mean do not emit any builtin function in front-end,
but we've explicit call builtin function here, so -fno-builtin doesn't
any help for this case.
However I think I could add a local ffs.c in libc/machine/riscv to
avoid this issue since I've saw it's really improve the code gen for
some target which have ffs or ctz instructions,
but the potential problem is maybe some target will hit this issue too.
[1] https://github.com/riscv/riscv-newlib
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 6:38 ` Kito Cheng
@ 2017-07-27 6:40 ` Kito Cheng
0 siblings, 0 replies; 16+ messages in thread
From: Kito Cheng @ 2017-07-27 6:40 UTC (permalink / raw)
To: Sebastian Huber; +Cc: newlib
Btw, it's my working tree if you are interested
https://github.com/kito-cheng/riscv-newlib/tree/riscv-newlib-submission-v1
On Thu, Jul 27, 2017 at 2:37 PM, Kito Cheng <kito.cheng@gmail.com> wrote:
>> Do you have plans to add RISC-V support to upstream Newlib?
> Yes, I plan submit patches in next few weeks and I am doing testing
> now, we have already porting to newlib 2.5[1].
>
>> We should first investigate why GCC performs this optimization. The file is compiled with -fno-builtin, so it some other optimization. Maybe we need something like __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) as in string/local.h.
>
> -fno-builtin just mean do not emit any builtin function in front-end,
> but we've explicit call builtin function here, so -fno-builtin doesn't
> any help for this case.
>
> However I think I could add a local ffs.c in libc/machine/riscv to
> avoid this issue since I've saw it's really improve the code gen for
> some target which have ffs or ctz instructions,
> but the potential problem is maybe some target will hit this issue too.
>
> [1] https://github.com/riscv/riscv-newlib
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 1:40 ` Kito Cheng
2017-07-27 5:47 ` Sebastian Huber
@ 2017-07-27 6:50 ` Sebastian Huber
2017-07-27 6:53 ` Kito Cheng
1 sibling, 1 reply; 16+ messages in thread
From: Sebastian Huber @ 2017-07-27 6:50 UTC (permalink / raw)
To: Kito Cheng, newlib
On 27/07/17 03:40, Kito Cheng wrote:
> Hi
>
> I am testing with RISC-V with newlib/trunk and just hang on ffs,
> after investigate, I saw gcc just generate a ffs call in ffs for riscv64
> and I guess riscv64 is not the only target will hit this bug,
> so maybe we can revert the part of this patch, at least for ffs.c?
>
> Code gen by riscv64-elf-gcc:
> .file "ffs.c"
> .option nopic
> .globl ffs
> .text
> .align 1
> .globl ffs
> .type ffs, @function
> ffs:
> add sp,sp,-16
> sd ra,8(sp)
> call ffs
> ld ra,8(sp)
> sext.w a0,a0
> add sp,sp,16
> jr ra
> .size ffs, .-ffs
> .ident "GCC: (GNU) 8.0.0 20170509 (experimental)"
I get:
/build/git-build/b-gcc-git-riscv32-rtems4.12/./gcc/xgcc
-B/build/git-build/b-gcc-git-riscv32-rtems4.12/./gcc/ -S -o - -O2 ffs.c
-fno-builtin
.file "ffs.c"
.option nopic
.globl __ffssi2
.text
.align 1
.globl ffs
.type ffs, @function
ffs:
add sp,sp,-16
sw ra,12(sp)
call __ffssi2
lw ra,12(sp)
add sp,sp,16
jr ra
.size ffs, .-ffs
.ident "GCC: (GNU) 8.0.0 20170727 (experimental)
Why does your GCC emit the call to ffs()?
>
> On Wed, Jul 5, 2017 at 7:26 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> On Jul 5 10:54, Sebastian Huber wrote:
>>> Use compiler builtin for ffs(). Remove duplicate implementation from
>>> Cygwin.
>>>
>>> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
>>> ---
>>> 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 | 38 +++++++++++++++++++++++++
>>> newlib/libc/string/flsl.c | 38 +++++++++++++++++++++++++
>>> newlib/libc/string/flsll.c | 38 +++++++++++++++++++++++++
>>> winsup/cygwin/syscalls.cc | 22 ---------------
>>> 9 files changed, 240 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
>> Patchset looks good, please push.
>>
>> For Cygwin we also need to add the new fls* entry points to
>> common.din and to the docs. I'll do that later, when you
>> pushed your patch.
>>
>>
>> Thanks,
>> Corinna
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 6:50 ` Sebastian Huber
@ 2017-07-27 6:53 ` Kito Cheng
2017-07-27 7:09 ` Sebastian Huber
0 siblings, 1 reply; 16+ messages in thread
From: Kito Cheng @ 2017-07-27 6:53 UTC (permalink / raw)
To: Sebastian Huber; +Cc: newlib
Hi Sebastian:
I only hit this bug on RV64, you can try -march=rv64ima -mabi=lp64
with riscv32-elf-gcc if you don't want to rebuild.
On Thu, Jul 27, 2017 at 2:48 PM, Sebastian Huber
<sebastian.huber@embedded-brains.de> wrote:
> On 27/07/17 03:40, Kito Cheng wrote:
>
>> Hi
>>
>> I am testing with RISC-V with newlib/trunk and just hang on ffs,
>> after investigate, I saw gcc just generate a ffs call in ffs for riscv64
>> and I guess riscv64 is not the only target will hit this bug,
>> so maybe we can revert the part of this patch, at least for ffs.c?
>>
>> Code gen by riscv64-elf-gcc:
>> .file "ffs.c"
>> .option nopic
>> .globl ffs
>> .text
>> .align 1
>> .globl ffs
>> .type ffs, @function
>> ffs:
>> add sp,sp,-16
>> sd ra,8(sp)
>> call ffs
>> ld ra,8(sp)
>> sext.w a0,a0
>> add sp,sp,16
>> jr ra
>> .size ffs, .-ffs
>> .ident "GCC: (GNU) 8.0.0 20170509 (experimental)"
>
>
> I get:
>
> /build/git-build/b-gcc-git-riscv32-rtems4.12/./gcc/xgcc
> -B/build/git-build/b-gcc-git-riscv32-rtems4.12/./gcc/ -S -o - -O2 ffs.c
> -fno-builtin
> .file "ffs.c"
> .option nopic
> .globl __ffssi2
> .text
> .align 1
> .globl ffs
> .type ffs, @function
> ffs:
> add sp,sp,-16
> sw ra,12(sp)
> call __ffssi2
> lw ra,12(sp)
> add sp,sp,16
> jr ra
> .size ffs, .-ffs
> .ident "GCC: (GNU) 8.0.0 20170727 (experimental)
>
> Why does your GCC emit the call to ffs()?
>
>
>>
>> On Wed, Jul 5, 2017 at 7:26 PM, Corinna Vinschen <vinschen@redhat.com>
>> wrote:
>>>
>>> On Jul 5 10:54, Sebastian Huber wrote:
>>>>
>>>> Use compiler builtin for ffs(). Remove duplicate implementation from
>>>> Cygwin.
>>>>
>>>> Signed-off-by: Sebastian Huber <sebastian.huber@embedded-brains.de>
>>>> ---
>>>> 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 | 38 +++++++++++++++++++++++++
>>>> newlib/libc/string/flsl.c | 38 +++++++++++++++++++++++++
>>>> newlib/libc/string/flsll.c | 38 +++++++++++++++++++++++++
>>>> winsup/cygwin/syscalls.cc | 22 ---------------
>>>> 9 files changed, 240 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
>>>
>>> Patchset looks good, please push.
>>>
>>> For Cygwin we also need to add the new fls* entry points to
>>> common.din and to the docs. I'll do that later, when you
>>> pushed your patch.
>>>
>>>
>>> Thanks,
>>> Corinna
>>>
>>> --
>>> Corinna Vinschen
>>> Cygwin Maintainer
>>> Red Hat
>
>
> --
> Sebastian Huber, embedded brains GmbH
>
> Address : Dornierstr. 4, D-82178 Puchheim, Germany
> Phone : +49 89 189 47 41-16
> Fax : +49 89 189 47 41-09
> E-Mail : sebastian.huber@embedded-brains.de
> PGP : Public key available on request.
>
> Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
>
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 6:53 ` Kito Cheng
@ 2017-07-27 7:09 ` Sebastian Huber
2017-07-27 7:21 ` Sebastian Huber
0 siblings, 1 reply; 16+ messages in thread
From: Sebastian Huber @ 2017-07-27 7:09 UTC (permalink / raw)
To: Kito Cheng; +Cc: newlib
On 27/07/17 08:52, Kito Cheng wrote:
> I only hit this bug on RV64, you can try -march=rv64ima -mabi=lp64
> with riscv32-elf-gcc if you don't want to rebuild.
Yes, I get the same. Is this a GCC bug?
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH v2 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll()
2017-07-27 7:09 ` Sebastian Huber
@ 2017-07-27 7:21 ` Sebastian Huber
0 siblings, 0 replies; 16+ messages in thread
From: Sebastian Huber @ 2017-07-27 7:21 UTC (permalink / raw)
To: Kito Cheng; +Cc: newlib
On 27/07/17 09:06, Sebastian Huber wrote:
> On 27/07/17 08:52, Kito Cheng wrote:
>
>> I only hit this bug on RV64, you can try -march=rv64ima -mabi=lp64
>> with riscv32-elf-gcc if you don't want to rebuild.
>
> Yes, I get the same. Is this a GCC bug?
>
No, its a feature:
/* Call this to initialize the contents of the optabs
appropriately for the current target machine. */
void
init_optabs (void)
{
[...]
/* The ffs function operates on `int'. Fall back on it if we do not
have a libgcc2 function for that width. */
if (INT_TYPE_SIZE < BITS_PER_WORD)
set_optab_libfunc (ffs_optab, mode_for_size (INT_TYPE_SIZE,
MODE_INT, 0),
"ffs");
I guess we have to use some conditional compilation in ffs() to work
around this GCC feature.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2017-07-27 7:21 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-04 13:34 [PATCH 1/3] Implement bzero() via memset() Sebastian Huber
2017-07-04 13:34 ` [PATCH 2/3] Synchronize <strings.h> with latest FreeBSD Sebastian Huber
2017-07-04 13:34 ` [PATCH 3/3] Add ffsl(), ffsll(), fls(), flsl(), flsll() Sebastian Huber
2017-07-05 6:06 ` Sebastian Huber
2017-07-05 8:42 ` Corinna Vinschen
2017-07-05 8:54 ` [PATCH v2 " Sebastian Huber
2017-07-05 11:26 ` Corinna Vinschen
2017-07-27 1:40 ` Kito Cheng
2017-07-27 5:47 ` Sebastian Huber
2017-07-27 6:21 ` Sebastian Huber
2017-07-27 6:38 ` Kito Cheng
2017-07-27 6:40 ` Kito Cheng
2017-07-27 6:50 ` Sebastian Huber
2017-07-27 6:53 ` Kito Cheng
2017-07-27 7:09 ` Sebastian Huber
2017-07-27 7:21 ` Sebastian Huber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).