| 1 |
# builtin-expect.m4 |
| 2 |
# serial 2 |
| 3 |
dnl Copyright 2016-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
dnl Provide a GCC-compatible __builtin_expect macro in <config.h>. |
| 10 |
|
| 11 |
dnl Written by Paul Eggert. |
| 12 |
|
| 13 |
AC_DEFUN([gl___BUILTIN_EXPECT], |
| 14 |
[ |
| 15 |
AC_CACHE_CHECK([for __builtin_expect], |
| 16 |
[gl_cv___builtin_expect], |
| 17 |
[AC_LINK_IFELSE( |
| 18 |
[AC_LANG_SOURCE([[ |
| 19 |
int |
| 20 |
main (int argc, char **argv) |
| 21 |
{ |
| 22 |
argc = __builtin_expect (argc, 100); |
| 23 |
return argv[argc != 100][0]; |
| 24 |
}]])], |
| 25 |
[gl_cv___builtin_expect=yes], |
| 26 |
[AC_LINK_IFELSE( |
| 27 |
[AC_LANG_SOURCE([[ |
| 28 |
#include <builtins.h> |
| 29 |
int |
| 30 |
main (int argc, char **argv) |
| 31 |
{ |
| 32 |
argc = __builtin_expect (argc, 100); |
| 33 |
return argv[argc != 100][0]; |
| 34 |
}]])], |
| 35 |
[gl_cv___builtin_expect="in <builtins.h>"], |
| 36 |
[gl_cv___builtin_expect=no])])]) |
| 37 |
if test "$gl_cv___builtin_expect" = yes; then |
| 38 |
AC_DEFINE([HAVE___BUILTIN_EXPECT], [1]) |
| 39 |
elif test "$gl_cv___builtin_expect" = "in <builtins.h>"; then |
| 40 |
AC_DEFINE([HAVE___BUILTIN_EXPECT], [2]) |
| 41 |
fi |
| 42 |
AH_VERBATIM([HAVE___BUILTIN_EXPECT], |
| 43 |
[/* Define to 1 if the compiler supports __builtin_expect, |
| 44 |
and to 2 if <builtins.h> does. */ |
| 45 |
#undef HAVE___BUILTIN_EXPECT |
| 46 |
#ifndef HAVE___BUILTIN_EXPECT |
| 47 |
# define __builtin_expect(e, c) (e) |
| 48 |
#elif HAVE___BUILTIN_EXPECT == 2 |
| 49 |
# include <builtins.h> |
| 50 |
#endif |
| 51 |
]) |
| 52 |
]) |