2
dnl M4 macro to add support for extra optimizations
4
dnl It understand --enable/--disable-optimizations .
5
dnl when optimizations are disabled, it does not touch cflags
7
dnl Note: always disable while crosscompiling
10
AC_DEFUN([AC_OPTIMIZATIONS], [
11
AC_ARG_ENABLE([optimizations],
12
AC_HELP_STRING([--disable-optimizations], [Don't try to guess what optimization to enable]))
14
if test "x$enable_optimizations" != "xno"; then
15
INLINE_FUNCTIONS=-finline-functions
17
if test "$GCC" = yes; then
19
dnl check cflags not supported by all gcc versions
20
dnl eg: -mpreferred-stack-boundary=2 and 2.91.66,
21
dnl and gcc-2.7.2.3 support a bit less options
23
AC_TRY_CFLAGS("-mpreferred-stack-boundary=2",
24
m_psb="-mpreferred-stack-boundary=2", m_psb="")
25
AC_TRY_CFLAGS("-fno-strict-aliasing", f_nsa="-fno-strict-aliasing", f_nsa="")
26
AC_TRY_CFLAGS("-fschedule-insns2", f_si="-fschedule-insns2", f_si="")
27
AC_TRY_CFLAGS("-mwide-multiply", m_wm="-mwide-multiply", m_wm="")
29
dnl gcc 3.1 uses the -f version
31
AC_TRY_CFLAGS("-falign-functions=4", f_af="-falign-functions=4",
32
f_af="-malign-functions=4")
33
AC_TRY_CFLAGS("-falign-loops=4", f_al="-falign-loops=4",
34
f_al="-malign-loops=4")
35
AC_TRY_CFLAGS("-falign-jumps=4", f_aj="-falign-jumps=4",
36
f_aj="-malign-jumps=4")
38
dnl Check for some optimization disabling
39
dnl needed for win32 code
41
AC_TRY_CFLAGS("-fno-omit-frame-pointer", W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-omit-frame-pointer",)
42
AC_TRY_CFLAGS("-fno-inline-functions", W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-inline-functions",)
43
AC_TRY_CFLAGS("-fno-rename-registers", W32_NO_OPTIMIZE="$W32_NO_OPTIMIZE -fno-rename-registers",)
44
AC_SUBST(W32_NO_OPTIMIZE)
46
dnl Multipass compilation
48
AC_TRY_CFLAGS("-fprofile-arcs", PASS1_CFLAGS="-fprofile_arcs $PASS1_CFLAGS",)
49
AC_TRY_CFLAGS("-fbranch-probabilities", PASS2_CFLAGS="-fbranch-probabilities $PASS2_CFLAGS",)
50
AC_SUBST(PASS1_CFLAGS)
51
AC_SUBST(PASS2_CFLAGS)
55
CFLAGS="-Wchar-subscripts -Wmissing-declarations -Wmissing-prototypes $CFLAGS"
56
CFLAGS="-Wnested-externs -Wcast-align $CFLAGS"
57
dnl some combinations of gcc+glibc produce useless warnings on memset
58
dnl when compiling with -Wpointer-arith, so we check for this first
59
AC_MSG_CHECKING(for sane -Wpointer-arith)
61
CFLAGS="-O2 -Wpointer-arith -Werror $CFLAGS"
62
AC_TRY_COMPILE([#include <string.h>],[int a; memset(&a, 0, sizeof(int));],
63
[AC_MSG_RESULT(yes); CFLAGS="-Wpointer-arith $SAVE_CFLAGS"],
64
[AC_MSG_RESULT(no); CFLAGS="$SAVE_CFLAGS"]);
66
dnl gcc 3.3.5 (at least) is known to be buggy wrt optimisation and
67
dnl -finline-functions. Use -fno-inline-functions for gcc < 3.4.0.
69
AC_MSG_CHECKING(for gcc 3.4.0 or later)
73
newGCC="`"$CC" -dumpversion |
74
awk 'BEGIN { FS = "." };
75
1 { if (($ARG1 * 10000 + $ARG2 * 100 + $ARG3) >= 30400) { print "yes" } }'
77
AC_MSG_RESULT(${newGCC:-no - assuming bugginess in -finline-functions})
78
test "$newGCC" = yes || INLINE_FUNCTIONS=-fno-inline-functions
81
dnl Flags not supported by all *cc* variants
82
AC_TRY_CFLAGS("-Wall", wall="-Wall", wall="")
84
CFLAGS="$wall ${CFLAGS}"
85
DEBUG_CFLAGS="$wall ${DEBUG_CFLAGS}"
87
case "$host_or_hostalias" in
88
i?86-* | k?-* | athlon-* | pentium*)
89
if test "$GCC" = yes -o "${CC##*/}x" = "iccx" ; then
91
if test "$GCC" = yes; then
92
dnl Check for gcc cpu optimization support
93
AC_TRY_CFLAGS("-mtune=i386",
95
AC_TRY_CFLAGS("-mcpu=i386",
97
AC_TRY_CFLAGS("-march=i386",
99
[ AC_MSG_RESULT(** no cpu optimization supports **)
106
dnl special check for k7 cpu CC support
107
AC_TRY_CFLAGS("$sarchopt=athlon", k7cpu="athlon", k7cpu="i686")
109
dnl add x86 specific gcc CFLAGS
110
CFLAGS="-O3 -pipe -fomit-frame-pointer $f_af $f_al $f_aj $m_wm $m_psb -fexpensive-optimizations $f_si $f_nsa -ffast-math $INLINE_FUNCTIONS $CFLAGS"
112
DEBUG_CFLAGS="-O $DEBUG_CFLAGS"
114
if test x"$sarchopt" != "xno"; then
117
case "$host_or_hostalias" in
119
archopt_val="i386" ;;
121
archopt_val="i486" ;;
123
archopt_val="pentium"
126
archopt_val="pentium-mmx"
128
pentiumpro-* | pentium2-* | i686-*)
129
archopt_val="pentiumpro"
130
if test x"$check_athlon" = "xyes"; then
131
if test -f /proc/cpuinfo; then
132
modelname=`cat /proc/cpuinfo | grep "model\ name\ :" | sed -e 's/ //g' | cut -d':' -f2`
134
*Athlon* | *Duron* | *K7*)
151
archopt_val="pentium3"
154
archopt_val="pentium4"
156
athlon-4-* | athlon-xp-* | athlon-mp-*)
157
archopt_val="athlon-4"
159
k7-* | athlon-tbird-* | athlon-*)
164
if test x"$archopt_val" != x; then
165
CFLAGS="$sarchopt=$archopt_val $CFLAGS"
166
DEBUG_CFLAGS="$sarchopt=$archopt_val $DEBUG_CFLAGS"
170
dnl we have the Intel compiler
171
CFLAGS="-unroll -ipo -ipo_obj -O3 $CFLAGS"
172
PASS1_CFLAGS="-prof_genx -prof_dir \$(PWD)/\$(top_builddir)/ $PASS1_CFLAGS"
173
PASS2_CFLAGS="-prof_use -prof_dir \$(PWD)/\$(top_builddir)/ $PASS2_CFLAGS"
174
AC_SUBST(PASS1_CFLAGS)
175
AC_SUBST(PASS2_CFLAGS)
179
dnl add x86 specific cc CFLAGS
181
DEBUG_CFLAGS="-O $DEBUG_CFLAGS"
182
AC_DEFINE_UNQUOTED(FPM_64BIT,,[Define to select libmad fixed point arithmetic implementation])
186
CFLAGS="-O3 -mcpu=ev56 -mieee $CFLAGS"
187
DEBUG_CFLAGS="-O3 -mcpu=ev56 -mieee $DEBUG_CFLAGS"
190
CFLAGS="-O3 -mieee $CFLAGS"
191
DEBUG_CFLAGS="-O3 -mieee $DEBUG_CFLAGS"
194
CFLAGS="-O3 -pipe -fomit-frame-pointer $m_wm $m_psb -fexpensive-optimizations $f_si $f_nsa -ffast-math $INLINE_FUNCTIONS -no-cpp-precomp -D_INTL_REDIRECT_MACROS $CFLAGS"
195
DEBUG_CFLAGS="-O3 $DEBUG_CFLAGS"
197
ppc-*-linux* | powerpc-*)
198
CFLAGS="-O3 -pipe -fomit-frame-pointer $m_wm $m_psb -fexpensive-optimizations $f_si $f_nsa -ffast-math $INLINE_FUNCTIONS $CFLAGS"
199
DEBUG_CFLAGS="-O3 $DEBUG_CFLAGS"
202
CFLAGS="-O3 $cpu_cflags $INLINE_FUNCTIONS $CFLAGS"
203
DEBUG_CFLAGS="-O $cpu_cflags $INLINE_FUNCTIONS $DEBUG_CFLAGS"
207
cpu_cflags="-mcpu=supersparc -mtune=supersparc" ;;
209
cpu_cflags="-mcpu=ultrasparc -mtune=ultrasparc" ;;
213
if test "$GCC" = yes; then
215
sun4c) cpu_cflags="-mcpu=v7 -mtune=supersparc" ;;
216
sun4m) cpu_cflags="-mcpu=v8 -mtune=supersparc" ;;
218
case `$CC --version 2>/dev/null` in
220
# -mcpu=ultrasparc triggers a GCC 2.95.x compiler bug when
221
# compiling video_out.c:
222
# gcc: Internal compiler error: program cc1 got fatal signal 11
223
# avoid -mcpu=ultrasparc with gcc 2.*
224
cpu_cflags="-mcpu=v8 -mtune=ultrasparc"
227
# GCC 3 or newer should have no problem with -mcpu=ultrasparc
228
cpu_cflags="-mcpu=ultrasparc -mtune=ultrasparc"
233
cc_optimize_cflags="-O3 $cpu_cflags $INLINE_FUNCTIONS"
234
cc_debug_cflags="-O $cpu_cflags $INLINE_FUNCTIONS"
237
sun4c) cpu_cflags="-xarch=v7" ;;
238
sun4m) cpu_cflags="-xarch=v8" ;;
239
sun4u) cpu_cflags="-xarch=v8plusa" ;;
241
cc_optimize_cflags="-fast $cpu_cflags -xCC"
245
CFLAGS="$cc_optimize_cflags $CFLAGS"
246
DEBUG_CFLAGS="$cc_debug_cflags $DEBUG_CFLAGS"
249
CFLAGS="-O3 -fomit-frame-pointer $m_wm $m_psb -fexpensive-optimizations $f_si $f_nsa -ffast-math $INLINE_FUNCTIONS $CFLAGS"
250
DEBUG_CFLAGS="-g $DEBUG_CFLAGS"
253
CFLAGS="-O2 -fsigned-char -ffast-math -mcpu=strongarm1100 -fomit-frame-pointer -fthread-jumps -fregmove $CFLAGS"
254
dnl CFLAGS="-O1 -fforce-mem -fforce-addr -fthread-jumps -fcse-follow-jumps -fcse-skip-blocks -fexpensive-optimizations -fregmove -fschedule-insns2 $INLINE_FUNCTIONS -fsigned-char -fomit-frame-pointer -march=armv4 -mtune=strongarm $CFLAGS"
255
DEBUG_CFLAGS="-O2 $DEBUG_CFLAGS"
261
dnl Kate modeline: leave at the end
262
dnl kate: indent-width 2; replace-trailing-space-save 1; space-indent 1; backspace-indents 1;