1dnl AC_C_RESTRICT
2dnl Do nothing if the compiler accepts the restrict keyword.
3dnl Otherwise define restrict to __restrict__ or __restrict if one of
4dnl those work, otherwise define restrict to be empty.
5AC_DEFUN([AC_C_RESTRICT],
6    [AC_MSG_CHECKING([for restrict])
7    ac_cv_c_restrict=no
8    for ac_kw in restrict __restrict__ __restrict; do
9        AC_TRY_COMPILE([],[char * $ac_kw p;],[ac_cv_c_restrict=$ac_kw; break])
10    done
11    AC_MSG_RESULT([$ac_cv_c_restrict])
12    case $ac_cv_c_restrict in
13        restrict) ;;
14        no)     AC_DEFINE([restrict],,
15                    [Define as `__restrict' if that's what the C compiler calls
16                    it, or to nothing if it is not supported.]) ;;
17        *)      AC_DEFINE_UNQUOTED([restrict],$ac_cv_c_restrict) ;;
18    esac])
19
20dnl AC_C_BUILTIN_EXPECT
21dnl Check whether compiler understands __builtin_expect.
22AC_DEFUN([AC_C_BUILTIN_EXPECT],
23    [AC_CACHE_CHECK([for __builtin_expect],[ac_cv_builtin_expect],
24        [cat > conftest.c <<EOF
25#line __oline__ "configure"
26int foo (int a)
27{
28    a = __builtin_expect (a, 10);
29    return a == 10 ? 0 : 1;
30}
31EOF
32        if AC_TRY_COMMAND([${CC-cc} $CFLAGS -nostdlib -nostartfiles
33            -o conftest conftest.c -lgcc >&AC_FD_CC]); then
34            ac_cv_builtin_expect=yes
35        else
36            ac_cv_builtin_expect=no
37        fi
38        rm -f conftest*])
39    if test x"$ac_cv_builtin_expect" = x"yes"; then
40        AC_DEFINE(HAVE_BUILTIN_EXPECT,,
41            [Define if you have the `__builtin_expect' function.])
42    fi])
43
44dnl AC_C_ALWAYS_INLINE
45dnl Define inline to something appropriate, including the new always_inline
46dnl attribute from gcc 3.1
47AC_DEFUN([AC_C_ALWAYS_INLINE],
48    [AC_C_INLINE
49    if test x"$GCC" = x"yes" -a x"$ac_cv_c_inline" = x"inline"; then
50        AC_MSG_CHECKING([for always_inline])
51        SAVE_CFLAGS="$CFLAGS"
52        CFLAGS="$CFLAGS -Wall -Werror"
53        AC_TRY_COMPILE([],
54            [__attribute__ ((__always_inline__)) void f (void);
55            #ifdef __cplusplus
56            42 = 42;    // obviously illegal - we want c++ to fail here
57            #endif],
58            [ac_cv_always_inline=yes],[ac_cv_always_inline=no])
59        CFLAGS="$SAVE_CFLAGS"
60        AC_MSG_RESULT([$ac_cv_always_inline])
61        if test x"$ac_cv_always_inline" = x"yes"; then
62            AC_DEFINE_UNQUOTED([inline],[__attribute__ ((__always_inline__))])
63        fi
64    fi])
65
66dnl AC_C_ATTRIBUTE_ALIGNED
67dnl define ATTRIBUTE_ALIGNED_MAX to the maximum alignment if this is supported
68AC_DEFUN([AC_C_ATTRIBUTE_ALIGNED],
69    [SAV_CFLAGS=$CFLAGS;
70    if test x"$GCC" = xyes; then CFLAGS="$CFLAGS -Werror"; fi
71    AC_CACHE_CHECK([__attribute__ ((aligned ())) support],
72        [ac_cv_c_attribute_aligned],
73        [ac_cv_c_attribute_aligned=0
74        for ac_cv_c_attr_align_try in 2 4 8 16 32 64; do
75            AC_TRY_COMPILE([],
76                [static struct s {
77                    char a;
78                    char b __attribute__ ((aligned($ac_cv_c_attr_align_try)));
79                } S = {0, 0};
80                switch (1) {
81                    case 0:
82                    case (long)(&((struct s *)0)->b) == $ac_cv_c_attr_align_try:
83                        return 0;
84                }
85                return (long)&S;],
86                [ac_cv_c_attribute_aligned=$ac_cv_c_attr_align_try])
87        done])
88    if test x"$ac_cv_c_attribute_aligned" != x"0"; then
89        AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX],
90            [$ac_cv_c_attribute_aligned],[maximum supported data alignment])
91    fi
92    CFLAGS=$SAV_CFLAGS])
93
94