builtin-expect.m4 1.5 KB

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