]> Savannah Git Hosting - gnulib.git/commitdiff
builtin-expect: new module
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Dec 2016 22:52:59 +0000 (14:52 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 16 Dec 2016 22:57:13 +0000 (14:57 -0800)
Fix fnmatch to use it.
Problem reported for z/OS by Daniel Richard G.
* lib/fnmatch.c (__builtin_expect):
* lib/glob.c (__builtin_expect):
* lib/grantpt.c (__builtin_expect) [!_LIBC]:
* lib/memmem.c (__builtin_expect) [!_LIBC]:
* lib/scandir.c (__builtin_expect):
* lib/strstr.c (__builtin_expect) [!_LIBC]:
Remove macro; config.h now does this.
* lib/gl_anytreehash_list1.h (add_to_bucket):
* lib/regex_internal.h (BE):
Assume __builtin_expect.
* m4/builtin-expect.m4, modules/builtin-expect: New files.
* modules/avltreehash-list, modules/fnmatch, modules/glob:
* modules/grantpt, modules/memmem-simple, modules/rbtreehash-list:
* modules/scandir, modules/strstr-simple:
Depend on builtin-expect.

19 files changed:
ChangeLog
lib/fnmatch.c
lib/gl_anytreehash_list1.h
lib/glob.c
lib/grantpt.c
lib/memmem.c
lib/regex_internal.h
lib/scandir.c
lib/strstr.c
m4/builtin-expect.m4 [new file with mode: 0644]
modules/avltreehash-list
modules/builtin-expect [new file with mode: 0644]
modules/fnmatch
modules/glob
modules/grantpt
modules/memmem-simple
modules/rbtreehash-list
modules/scandir
modules/strstr-simple

index f3522e71245b434395aa0d5cc3869cd56970d3ce..451e1d5bb8ac0a85c960cf0ed22fcec0780729b4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2016-12-16  Paul Eggert  <eggert@cs.ucla.edu>
+
+       builtin-expect: new module
+       Fix fnmatch to use it.
+       Problem reported for z/OS by Daniel Richard G.
+       * lib/fnmatch.c (__builtin_expect):
+       * lib/glob.c (__builtin_expect):
+       * lib/grantpt.c (__builtin_expect) [!_LIBC]:
+       * lib/memmem.c (__builtin_expect) [!_LIBC]:
+       * lib/scandir.c (__builtin_expect):
+       * lib/strstr.c (__builtin_expect) [!_LIBC]:
+       Remove macro; config.h now does this.
+       * lib/gl_anytreehash_list1.h (add_to_bucket):
+       * lib/regex_internal.h (BE):
+       Assume __builtin_expect.
+       * m4/builtin-expect.m4, modules/builtin-expect: New files.
+       * modules/avltreehash-list, modules/fnmatch, modules/glob:
+       * modules/grantpt, modules/memmem-simple, modules/rbtreehash-list:
+       * modules/scandir, modules/strstr-simple:
+       Depend on builtin-expect.
+
 2016-12-15  Bruno Haible  <bruno@clisp.org>
 
        init.sh: Add possibility to not delete temporary files.
index 75b85c05db766ffcc6f340a493db967f65baa25a..cc690bba2d1f837e59d7337885e13e3cb28fd3ae 100644 (file)
 # define _GNU_SOURCE    1
 #endif
 
-#if ! defined __builtin_expect && (!defined __GNUC__ || __GNUC__ < 3)
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
 #include <fnmatch.h>
 
 #include <alloca.h>
index 11578ed6b1d1772d700a809559d2587055d6ac76..cf44b596882e6613594379a85896ac897a26515d 100644 (file)
@@ -185,10 +185,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
   return 0;
 }
 /* Tell GCC that the likely return value is 0.  */
-#if __GNUC__ >= 3
-# define add_to_bucket(list,node) \
+#define add_to_bucket(list,node) \
     __builtin_expect ((add_to_bucket) (list, node), 0)
-#endif
 
 /* Remove a node from the hash table structure.
    If duplicates are allowed, this function performs in average time
index 5b2ff9d623eb31dc5f7f34a13cc85f0b77971254..4a7dab2b426d016f71c80943e6c6e4948e1cc9ac 100644 (file)
@@ -222,10 +222,6 @@ convert_dirent64 (const struct dirent64 *source)
 # endif
 #endif
 
-#if ! defined __builtin_expect && __GNUC__ < 3
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
 #ifndef __glibc_unlikely
 # define __glibc_unlikely(expr) __builtin_expect (expr, 0)
 #endif
index e4c1b9181e5f5cb580152d514bf63c6e2e84399d..2af879ab715ae60e5876372a14d8614b1ad928bb 100644 (file)
@@ -35,7 +35,6 @@
 #include "pty-private.h"
 
 #ifndef _LIBC
-# define __builtin_expect(expr,val) (expr)
 # define __set_errno(e) errno = (e)
 # define __dup2 dup2
 # define __fork fork
index 255490e675f0b971fbef98820812f70c4059bd9f..a77c107583f77aff9a1bab4b3287e1a0ec567f7f 100644 (file)
 /* Specification of memmem.  */
 #include <string.h>
 
-#ifndef _LIBC
-# define __builtin_expect(expr, val)   (expr)
-#endif
-
 #define RETURN_TYPE void *
 #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
 #include "str-two-way.h"
index 7ac5f9267139edcf49b44edafd5ae35217e546e5..411410740fd2e9af98ddaa88f0c73f27a3f691f5 100644 (file)
 # define RE_ENABLE_I18N
 #endif
 
-#if __GNUC__ >= 3
-# define BE(expr, val) __builtin_expect (expr, val)
-#else
-# define BE(expr, val) (expr)
-#endif
+#define BE(expr, val) __builtin_expect (expr, val)
 
 /* Number of ASCII characters.  */
 #define ASCII_CHARS 0x80
index a41ef1ad3e1ec1db0161220521ac067dbf6cf098..747bd8798b83069797e2bf278715e1e18d31e853 100644 (file)
 # include <bits/libc-lock.h>
 #endif
 
-#if ! defined __builtin_expect && __GNUC__ < 3
-# define __builtin_expect(expr, expected) (expr)
-#endif
-
 #undef select
 
 #ifndef _D_EXACT_NAMLEN
index 7e1865f615f3dfda2821ba16318f1cbca5ed84e9..29da790c55b6efe869ad1e2476a329c6ce6c0aa5 100644 (file)
 
 #include <stdbool.h>
 
-#ifndef _LIBC
-# define __builtin_expect(expr, val)   (expr)
-#endif
-
 #define RETURN_TYPE char *
 #define AVAILABLE(h, h_l, j, n_l)                       \
   (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l))     \
diff --git a/m4/builtin-expect.m4 b/m4/builtin-expect.m4
new file mode 100644 (file)
index 0000000..5f7a323
--- /dev/null
@@ -0,0 +1,34 @@
+dnl Check for __builtin_expect.
+
+dnl Copyright 2016 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl___BUILTIN_EXPECT],
+[
+  AC_CACHE_CHECK([for __builtin_expect],
+    [gl_cv___builtin_expect],
+    [AC_LINK_IFELSE(
+       [AC_LANG_SOURCE([[
+         int
+         main (int argc, char **argv)
+         {
+           argc = __builtin_expect (argc, 100);
+           return argv[argc != 100][0];
+         }]])],
+       [gl_cv___builtin_expect=yes],
+       [gl_cv___builtin_expect=no])])
+  if test "$gl_cv___builtin_expect" = yes; then
+    AC_DEFINE([HAVE___BUILTIN_EXPECT], [1])
+  fi
+  AH_VERBATIM([HAVE___BUILTIN_EXPECT],
+    [/* Define to 1 if the compiler understands __builtin_expect.  */
+#undef HAVE___BUILTIN_EXPECT
+#ifndef HAVE___BUILTIN_EXPECT
+# define __builtin_expect(e, c) (e)
+#endif
+    ])
+])
index f4d569917af8080ef2274027c26e1f4aa3454d31..a7aa75ec456ea716566ea1a7eb1253c16babf3f8 100644 (file)
@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
 lib/gl_anytreehash_list2.h
 
 Depends-on:
+builtin-expect
 list
 avltree-oset
 stdint
diff --git a/modules/builtin-expect b/modules/builtin-expect
new file mode 100644 (file)
index 0000000..c11d5d9
--- /dev/null
@@ -0,0 +1,20 @@
+Description:
+Check for __builtin_expect.
+
+Files:
+m4/builtin-expect.m4
+
+Depends-on:
+
+configure.ac:
+gl___BUILTIN_EXPECT
+
+Makefile.am:
+
+Include:
+
+License:
+LGPLv2+
+
+Maintainer:
+all
index ab302361ba2130f4a4c788f45392fd2bc095e349..70563f9bda0dbbf8d7761786efd0557085a37ca9 100644 (file)
@@ -12,6 +12,7 @@ Depends-on:
 extensions
 snippet/arg-nonnull
 alloca          [test -n "$FNMATCH_H"]
+builtin-expect  [test -n "$FNMATCH_H"]
 flexmember      [test -n "$FNMATCH_H"]
 stdbool         [test -n "$FNMATCH_H"]
 wchar           [test -n "$FNMATCH_H"]
index f32fe5f36fef75d3d721f41bb2dbd9e50e42e774..29df7ab89b827c9f106d5b7459bd57b66aac95c4 100644 (file)
@@ -15,6 +15,7 @@ snippet/arg-nonnull
 snippet/c++defs
 snippet/warn-on-use
 alloca          [test -n "$GLOB_H"]
+builtin-expect  [test -n "$GLOB_H"]
 closedir        [test -n "$GLOB_H"]
 d-type          [test -n "$GLOB_H"]
 dirfd           [test -n "$GLOB_H"]
index 38675b6fb5c786da56b149fcb4442ffe69e3bf00..486bb8550ea6ba0fc8a9de8c9f95b9499d321698 100644 (file)
@@ -9,6 +9,7 @@ m4/grantpt.m4
 Depends-on:
 stdlib
 extensions
+builtin-expect  [test $HAVE_GRANTPT = 0]
 pt_chown        [test $HAVE_GRANTPT = 0]
 waitpid         [test $HAVE_GRANTPT = 0]
 configmake      [test $HAVE_GRANTPT = 0]
index d4ae332a264a5c7aa2764f2d1e919ed8308a4fa5..71de887c39da6bb7c412f138648678f0c9af13f8 100644 (file)
@@ -7,6 +7,7 @@ lib/memmem.c
 m4/memmem.m4
 
 Depends-on:
+builtin-expect
 extensions
 string
 stdint
index e7369cbfc044b55de5d06c75625ab0c09c70db76..2b4add5546d9f0de70094b4bf2d6f5fc78db3b93 100644 (file)
@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
 lib/gl_anytreehash_list2.h
 
 Depends-on:
+builtin-expect
 list
 rbtree-oset
 stdint
index 71ef4654c2b739bb6df02bf1a7b9cda3add5d060..8d5e1058d89de33051bc84b5111b3b7bd32297dd 100644 (file)
@@ -6,6 +6,7 @@ lib/scandir.c
 m4/scandir.m4
 
 Depends-on:
+builtin-expect
 closedir
 dirent
 extensions
@@ -31,4 +32,3 @@ LGPL
 
 Maintainer:
 all, glibc
-
index c61afc45adff69a15b4e6916bfb2c26b2e2e52c6..bd52b17310c099b913deff27ef59949659e16b77 100644 (file)
@@ -8,6 +8,7 @@ m4/strstr.m4
 
 Depends-on:
 string
+builtin-expect  [test $REPLACE_STRSTR = 1]
 stdbool         [test $REPLACE_STRSTR = 1]
 memchr          [test $REPLACE_STRSTR = 1]
 memcmp          [test $REPLACE_STRSTR = 1]