Commit 005973d6 authored by Paul Eggert's avatar Paul Eggert

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.
parent 3044ae7f
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> 2016-12-15 Bruno Haible <bruno@clisp.org>
init.sh: Add possibility to not delete temporary files. init.sh: Add possibility to not delete temporary files.
...@@ -22,10 +22,6 @@ ...@@ -22,10 +22,6 @@
# define _GNU_SOURCE 1 # define _GNU_SOURCE 1
#endif #endif
#if ! defined __builtin_expect && (!defined __GNUC__ || __GNUC__ < 3)
# define __builtin_expect(expr, expected) (expr)
#endif
#include <fnmatch.h> #include <fnmatch.h>
#include <alloca.h> #include <alloca.h>
......
...@@ -185,10 +185,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node) ...@@ -185,10 +185,8 @@ add_to_bucket (gl_list_t list, gl_list_node_t new_node)
return 0; return 0;
} }
/* Tell GCC that the likely return value is 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) __builtin_expect ((add_to_bucket) (list, node), 0)
#endif
/* Remove a node from the hash table structure. /* Remove a node from the hash table structure.
If duplicates are allowed, this function performs in average time If duplicates are allowed, this function performs in average time
......
...@@ -222,10 +222,6 @@ convert_dirent64 (const struct dirent64 *source) ...@@ -222,10 +222,6 @@ convert_dirent64 (const struct dirent64 *source)
# endif # endif
#endif #endif
#if ! defined __builtin_expect && __GNUC__ < 3
# define __builtin_expect(expr, expected) (expr)
#endif
#ifndef __glibc_unlikely #ifndef __glibc_unlikely
# define __glibc_unlikely(expr) __builtin_expect (expr, 0) # define __glibc_unlikely(expr) __builtin_expect (expr, 0)
#endif #endif
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "pty-private.h" #include "pty-private.h"
#ifndef _LIBC #ifndef _LIBC
# define __builtin_expect(expr,val) (expr)
# define __set_errno(e) errno = (e) # define __set_errno(e) errno = (e)
# define __dup2 dup2 # define __dup2 dup2
# define __fork fork # define __fork fork
......
...@@ -24,10 +24,6 @@ ...@@ -24,10 +24,6 @@
/* Specification of memmem. */ /* Specification of memmem. */
#include <string.h> #include <string.h>
#ifndef _LIBC
# define __builtin_expect(expr, val) (expr)
#endif
#define RETURN_TYPE void * #define RETURN_TYPE void *
#define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l)) #define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
#include "str-two-way.h" #include "str-two-way.h"
......
...@@ -115,11 +115,7 @@ ...@@ -115,11 +115,7 @@
# define RE_ENABLE_I18N # define RE_ENABLE_I18N
#endif #endif
#if __GNUC__ >= 3 #define BE(expr, val) __builtin_expect (expr, val)
# define BE(expr, val) __builtin_expect (expr, val)
#else
# define BE(expr, val) (expr)
#endif
/* Number of ASCII characters. */ /* Number of ASCII characters. */
#define ASCII_CHARS 0x80 #define ASCII_CHARS 0x80
......
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
# include <bits/libc-lock.h> # include <bits/libc-lock.h>
#endif #endif
#if ! defined __builtin_expect && __GNUC__ < 3
# define __builtin_expect(expr, expected) (expr)
#endif
#undef select #undef select
#ifndef _D_EXACT_NAMLEN #ifndef _D_EXACT_NAMLEN
......
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
#include <stdbool.h> #include <stdbool.h>
#ifndef _LIBC
# define __builtin_expect(expr, val) (expr)
#endif
#define RETURN_TYPE char * #define RETURN_TYPE char *
#define AVAILABLE(h, h_l, j, n_l) \ #define AVAILABLE(h, h_l, j, n_l) \
(!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \ (!memchr ((h) + (h_l), '\0', (j) + (n_l) - (h_l)) \
......
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
])
])
...@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h ...@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
lib/gl_anytreehash_list2.h lib/gl_anytreehash_list2.h
Depends-on: Depends-on:
builtin-expect
list list
avltree-oset avltree-oset
stdint stdint
......
Description:
Check for __builtin_expect.
Files:
m4/builtin-expect.m4
Depends-on:
configure.ac:
gl___BUILTIN_EXPECT
Makefile.am:
Include:
License:
LGPLv2+
Maintainer:
all
...@@ -12,6 +12,7 @@ Depends-on: ...@@ -12,6 +12,7 @@ Depends-on:
extensions extensions
snippet/arg-nonnull snippet/arg-nonnull
alloca [test -n "$FNMATCH_H"] alloca [test -n "$FNMATCH_H"]
builtin-expect [test -n "$FNMATCH_H"]
flexmember [test -n "$FNMATCH_H"] flexmember [test -n "$FNMATCH_H"]
stdbool [test -n "$FNMATCH_H"] stdbool [test -n "$FNMATCH_H"]
wchar [test -n "$FNMATCH_H"] wchar [test -n "$FNMATCH_H"]
......
...@@ -15,6 +15,7 @@ snippet/arg-nonnull ...@@ -15,6 +15,7 @@ snippet/arg-nonnull
snippet/c++defs snippet/c++defs
snippet/warn-on-use snippet/warn-on-use
alloca [test -n "$GLOB_H"] alloca [test -n "$GLOB_H"]
builtin-expect [test -n "$GLOB_H"]
closedir [test -n "$GLOB_H"] closedir [test -n "$GLOB_H"]
d-type [test -n "$GLOB_H"] d-type [test -n "$GLOB_H"]
dirfd [test -n "$GLOB_H"] dirfd [test -n "$GLOB_H"]
......
...@@ -9,6 +9,7 @@ m4/grantpt.m4 ...@@ -9,6 +9,7 @@ m4/grantpt.m4
Depends-on: Depends-on:
stdlib stdlib
extensions extensions
builtin-expect [test $HAVE_GRANTPT = 0]
pt_chown [test $HAVE_GRANTPT = 0] pt_chown [test $HAVE_GRANTPT = 0]
waitpid [test $HAVE_GRANTPT = 0] waitpid [test $HAVE_GRANTPT = 0]
configmake [test $HAVE_GRANTPT = 0] configmake [test $HAVE_GRANTPT = 0]
......
...@@ -7,6 +7,7 @@ lib/memmem.c ...@@ -7,6 +7,7 @@ lib/memmem.c
m4/memmem.m4 m4/memmem.m4
Depends-on: Depends-on:
builtin-expect
extensions extensions
string string
stdint stdint
......
...@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h ...@@ -14,6 +14,7 @@ lib/gl_anytreehash_list1.h
lib/gl_anytreehash_list2.h lib/gl_anytreehash_list2.h
Depends-on: Depends-on:
builtin-expect
list list
rbtree-oset rbtree-oset
stdint stdint
......
...@@ -6,6 +6,7 @@ lib/scandir.c ...@@ -6,6 +6,7 @@ lib/scandir.c
m4/scandir.m4 m4/scandir.m4
Depends-on: Depends-on:
builtin-expect
closedir closedir
dirent dirent
extensions extensions
...@@ -31,4 +32,3 @@ LGPL ...@@ -31,4 +32,3 @@ LGPL
Maintainer: Maintainer:
all, glibc all, glibc
...@@ -8,6 +8,7 @@ m4/strstr.m4 ...@@ -8,6 +8,7 @@ m4/strstr.m4
Depends-on: Depends-on:
string string
builtin-expect [test $REPLACE_STRSTR = 1]
stdbool [test $REPLACE_STRSTR = 1] stdbool [test $REPLACE_STRSTR = 1]
memchr [test $REPLACE_STRSTR = 1] memchr [test $REPLACE_STRSTR = 1]
memcmp [test $REPLACE_STRSTR = 1] memcmp [test $REPLACE_STRSTR = 1]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment