~siretart/xine-lib/ubuntu

« back to all changes in this revision

Viewing changes to m4/optimizations.m4

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-15 13:13:45 UTC
  • mto: (40.2.1 squeeze) (0.1.19 upstream)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20051215131345-x3rwu3clsnn3v4dv
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl
 
2
dnl M4 macro to add support for extra optimizations
 
3
dnl
 
4
dnl It understand --enable/--disable-optimizations .
 
5
dnl when optimizations are disabled, it does not touch cflags
 
6
dnl
 
7
dnl Note: always disable while crosscompiling
 
8
dnl
 
9
 
 
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]))
 
13
 
 
14
  if test "x$enable_optimizations" != "xno"; then
 
15
    INLINE_FUNCTIONS=-finline-functions
 
16
 
 
17
    if test "$GCC" = yes; then
 
18
        dnl
 
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
 
22
        dnl
 
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="")
 
28
        dnl
 
29
        dnl gcc 3.1 uses the -f version
 
30
        dnl
 
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")
 
37
        dnl
 
38
        dnl Check for some optimization disabling
 
39
        dnl needed for win32 code
 
40
        dnl
 
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)
 
45
        dnl
 
46
        dnl Multipass compilation
 
47
        dnl
 
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)
 
52
        dnl
 
53
        dnl Warnings
 
54
        dnl
 
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)
 
60
        SAVE_CFLAGS="$CFLAGS"
 
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"]);
 
65
 
 
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.
 
68
 
 
69
        AC_MSG_CHECKING(for gcc 3.4.0 or later)
 
70
        ARG1="$1"
 
71
        ARG2="$2"
 
72
        ARG3="$3"
 
73
        newGCC="`"$CC" -dumpversion |
 
74
                awk 'BEGIN { FS = "." };
 
75
                      1 { if (($ARG1 * 10000 + $ARG2 * 100 + $ARG3) >= 30400) { print "yes" } }'
 
76
                `"
 
77
        AC_MSG_RESULT(${newGCC:-no - assuming bugginess in -finline-functions})
 
78
        test "$newGCC" = yes || INLINE_FUNCTIONS=-fno-inline-functions
 
79
    fi
 
80
 
 
81
    dnl Flags not supported by all *cc* variants
 
82
    AC_TRY_CFLAGS("-Wall", wall="-Wall", wall="")
 
83
 
 
84
    CFLAGS="$wall ${CFLAGS}"
 
85
    DEBUG_CFLAGS="$wall ${DEBUG_CFLAGS}"
 
86
 
 
87
    case "$host_or_hostalias" in
 
88
      i?86-* | k?-* | athlon-* | pentium*)
 
89
        if test "$GCC" = yes -o "${CC##*/}x" = "iccx" ; then
 
90
 
 
91
          if test "$GCC" = yes; then
 
92
            dnl Check for gcc cpu optimization support
 
93
            AC_TRY_CFLAGS("-mtune=i386",
 
94
              sarchopt="-mtune",
 
95
              AC_TRY_CFLAGS("-mcpu=i386",
 
96
                sarchopt="-mcpu",
 
97
                AC_TRY_CFLAGS("-march=i386",
 
98
                  sarchopt="-march",
 
99
                  [ AC_MSG_RESULT(** no cpu optimization supports **)
 
100
                    sarchopt=no
 
101
                  ]
 
102
                )
 
103
              )
 
104
            )
 
105
 
 
106
            dnl special check for k7 cpu CC support
 
107
            AC_TRY_CFLAGS("$sarchopt=athlon", k7cpu="athlon", k7cpu="i686")
 
108
 
 
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"
 
111
 
 
112
            DEBUG_CFLAGS="-O $DEBUG_CFLAGS"
 
113
 
 
114
            if test x"$sarchopt" != "xno"; then
 
115
              archopt_val=
 
116
 
 
117
              case "$host_or_hostalias" in
 
118
              i386-*)
 
119
                  archopt_val="i386" ;;
 
120
              i486-*)
 
121
                  archopt_val="i486" ;;
 
122
              i586-*)
 
123
                  archopt_val="pentium"
 
124
                  ;;
 
125
              pentium-mmx-*)
 
126
                  archopt_val="pentium-mmx"
 
127
                  ;;
 
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`
 
133
                          case "$modelname" in
 
134
                          *Athlon* | *Duron* | *K7*)
 
135
                              archopt_val="$k7cpu"
 
136
                              ;;
 
137
                          VIAEzra)
 
138
                              archopt_val="c3"
 
139
                              ;;
 
140
                          esac
 
141
                      fi
 
142
                  fi
 
143
                  ;;
 
144
              k6-2-* | k6-3-*)
 
145
                  archopt_val="k6-2"
 
146
                  ;;
 
147
              k6-*)
 
148
                  archopt_val="k6"
 
149
                  ;;
 
150
              pentium3-*)
 
151
                  archopt_val="pentium3"
 
152
                  ;;
 
153
              pentium4-*)
 
154
                  archopt_val="pentium4"
 
155
                  ;;
 
156
              athlon-4-* | athlon-xp-* | athlon-mp-*)
 
157
                  archopt_val="athlon-4"
 
158
                  ;;
 
159
              k7-* | athlon-tbird-* | athlon-*)
 
160
                  archopt_val="athlon"
 
161
                  ;;
 
162
 
 
163
              esac
 
164
              if test x"$archopt_val" != x; then
 
165
                  CFLAGS="$sarchopt=$archopt_val $CFLAGS"
 
166
                  DEBUG_CFLAGS="$sarchopt=$archopt_val $DEBUG_CFLAGS"
 
167
              fi
 
168
            fi
 
169
          else
 
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)
 
176
          fi
 
177
 
 
178
        else
 
179
            dnl add x86 specific cc CFLAGS
 
180
            CFLAGS="-O $CFLAGS"
 
181
            DEBUG_CFLAGS="-O $DEBUG_CFLAGS"
 
182
            AC_DEFINE_UNQUOTED(FPM_64BIT,,[Define to select libmad fixed point arithmetic implementation])
 
183
        fi
 
184
        ;;
 
185
      alphaev56-*)
 
186
        CFLAGS="-O3 -mcpu=ev56 -mieee $CFLAGS"
 
187
        DEBUG_CFLAGS="-O3 -mcpu=ev56 -mieee $DEBUG_CFLAGS"
 
188
        ;;
 
189
      alpha*)
 
190
        CFLAGS="-O3 -mieee $CFLAGS"
 
191
        DEBUG_CFLAGS="-O3 -mieee $DEBUG_CFLAGS"
 
192
        ;;
 
193
      *darwin*)
 
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"
 
196
        ;;
 
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"
 
200
        ;;
 
201
      sparc*-*-linux*)
 
202
        CFLAGS="-O3 $cpu_cflags $INLINE_FUNCTIONS $CFLAGS"
 
203
        DEBUG_CFLAGS="-O $cpu_cflags $INLINE_FUNCTIONS $DEBUG_CFLAGS"
 
204
 
 
205
        case `uname -m` in
 
206
          sparc)
 
207
            cpu_cflags="-mcpu=supersparc -mtune=supersparc" ;;
 
208
          sparc64)
 
209
            cpu_cflags="-mcpu=ultrasparc -mtune=ultrasparc" ;;
 
210
        esac
 
211
        ;;
 
212
      sparc-*-solaris*)
 
213
        if test "$GCC" = yes; then
 
214
          case `uname -m` in
 
215
            sun4c) cpu_cflags="-mcpu=v7 -mtune=supersparc" ;;
 
216
            sun4m) cpu_cflags="-mcpu=v8 -mtune=supersparc" ;;
 
217
            sun4u)
 
218
              case `$CC --version 2>/dev/null` in
 
219
                1.*|2.*)
 
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"
 
225
                  ;;
 
226
                *)
 
227
                  # GCC 3 or newer should have no problem with -mcpu=ultrasparc
 
228
                  cpu_cflags="-mcpu=ultrasparc -mtune=ultrasparc"
 
229
                  ;;
 
230
              esac
 
231
            ;;
 
232
          esac
 
233
          cc_optimize_cflags="-O3 $cpu_cflags $INLINE_FUNCTIONS"
 
234
          cc_debug_cflags="-O $cpu_cflags $INLINE_FUNCTIONS"
 
235
        else
 
236
          case `uname -m` in
 
237
            sun4c) cpu_cflags="-xarch=v7" ;;
 
238
            sun4m) cpu_cflags="-xarch=v8" ;;
 
239
            sun4u) cpu_cflags="-xarch=v8plusa" ;;
 
240
          esac
 
241
          cc_optimize_cflags="-fast $cpu_cflags -xCC"
 
242
          cc_debug_cflags="-O"
 
243
        fi
 
244
 
 
245
        CFLAGS="$cc_optimize_cflags $CFLAGS"
 
246
        DEBUG_CFLAGS="$cc_debug_cflags $DEBUG_CFLAGS"
 
247
        ;;
 
248
      x86_64-*)
 
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"
 
251
        ;;
 
252
      armv4l-*-linux*)
 
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"
 
256
        ;;
 
257
    esac
 
258
  fi
 
259
])
 
260
 
 
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;