armv7(float): Optimize encode usecase using NE10 library
[opus.git] / configure.ac
1 dnl Process this file with autoconf to produce a configure script. -*-m4-*-
2
3 dnl The package_version file will be automatically synced to the git revision
4 dnl by the update_version script when configured in the repository, but will
5 dnl remain constant in tarball releases unless it is manually edited.
6 m4_define([CURRENT_VERSION],
7           m4_esyscmd([ ./update_version 2>/dev/null || true
8                        if test -e package_version; then
9                            . ./package_version
10                            printf "$PACKAGE_VERSION"
11                        else
12                            printf "unknown"
13                        fi ]))
14
15 AC_INIT([opus],[CURRENT_VERSION],[opus@xiph.org])
16
17 AC_CONFIG_SRCDIR(src/opus_encoder.c)
18 AC_CONFIG_MACRO_DIR([m4])
19
20 dnl enable silent rules on automake 1.11 and later
21 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
22
23 # For libtool.
24 dnl Please update these for releases.
25 OPUS_LT_CURRENT=5
26 OPUS_LT_REVISION=0
27 OPUS_LT_AGE=5
28
29 AC_SUBST(OPUS_LT_CURRENT)
30 AC_SUBST(OPUS_LT_REVISION)
31 AC_SUBST(OPUS_LT_AGE)
32
33 AM_INIT_AUTOMAKE([no-define])
34 AM_MAINTAINER_MODE([enable])
35
36 AC_CANONICAL_HOST
37 AC_MINGW32
38 AM_PROG_LIBTOOL
39 AM_PROG_CC_C_O
40
41 AC_PROG_CC_C99
42 AC_C_CONST
43 AC_C_INLINE
44
45 AM_PROG_AS
46
47 AC_DEFINE([OPUS_BUILD], [], [This is a build of OPUS])
48
49 #Use a hacked up version of autoconf's AC_C_RESTRICT because it's not
50 #strong enough a test to detect old buggy versions of GCC (e.g. 2.95.3)
51 #Note: Both this and the test for variable-size arrays below are also
52 #      done by AC_PROG_CC_C99, but not thoroughly enough apparently.
53 AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
54   [ac_cv_c_restrict=no
55    # The order here caters to the fact that C++ does not require restrict.
56    for ac_kw in __restrict __restrict__ _Restrict restrict; do
57      AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
58       [[typedef int * int_ptr;
59         int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
60         return ip[0];
61        }]],
62       [[int s[1];
63         int * $ac_kw t = s;
64         t[0] = 0;
65         return foo(t, (void *)0)]])],
66       [ac_cv_c_restrict=$ac_kw])
67      test "$ac_cv_c_restrict" != no && break
68    done
69   ])
70
71 AH_VERBATIM([restrict],
72 [/* Define to the equivalent of the C99 'restrict' keyword, or to
73    nothing if this is not supported.  Do not define if restrict is
74    supported directly.  */
75 #undef restrict
76 /* Work around a bug in Sun C++: it does not support _Restrict or
77    __restrict__, even though the corresponding Sun C compiler ends up with
78    "#define restrict _Restrict" or "#define restrict __restrict__" in the
79    previous line.  Perhaps some future version of Sun C++ will work with
80    restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
81 #if defined __SUNPRO_CC && !defined __RESTRICT
82 # define _Restrict
83 # define __restrict__
84 #endif])
85
86 case $ac_cv_c_restrict in
87    restrict) ;;
88    no) AC_DEFINE([restrict], []) ;;
89    *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
90 esac
91
92 AC_MSG_CHECKING(for C99 variable-size arrays)
93 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
94                    [[static int x; char a[++x]; a[sizeof a - 1] = 0; int N; return a[0];]])],
95     [ has_var_arrays=yes
96       use_alloca="no (using var arrays)"
97       AC_DEFINE([VAR_ARRAYS], [1], [Use C99 variable-size arrays])
98     ],[
99       has_var_arrays=no
100     ])
101 AC_MSG_RESULT([$has_var_arrays])
102
103 AS_IF([test "$has_var_arrays" = "no"],
104   [
105    AC_CHECK_HEADERS([alloca.h])
106    AC_MSG_CHECKING(for alloca)
107    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <alloca.h>]],
108                                       [[int foo=10; int *array = alloca(foo);]])],
109      [ use_alloca=yes;
110        AC_DEFINE([USE_ALLOCA], [], [Make use of alloca])
111      ],[
112        use_alloca=no
113      ])
114    AC_MSG_RESULT([$use_alloca])
115   ])
116
117 LT_LIB_M
118
119 AC_ARG_ENABLE([fixed-point],
120     [AS_HELP_STRING([--enable-fixed-point],
121                     [compile without floating point (for machines without a fast enough FPU)])],,
122     [enable_fixed_point=no])
123
124 AS_IF([test "$enable_fixed_point" = "yes"],[
125   enable_float="no"
126   AC_DEFINE([FIXED_POINT], [1], [Compile as fixed-point (for machines without a fast enough FPU)])
127   PC_BUILD="fixed-point"
128 ],[
129   enable_float="yes";
130   PC_BUILD="floating-point"
131 ])
132
133 AM_CONDITIONAL([FIXED_POINT], [test "$enable_fixed_point" = "yes"])
134
135 AC_ARG_ENABLE([fixed-point-debug],
136     [AS_HELP_STRING([--enable-fixed-point-debug], [debug fixed-point implementation])],,
137     [enable_fixed_point_debug=no])
138
139 AS_IF([test "$enable_fixed_point_debug" = "yes"],[
140   AC_DEFINE([FIXED_DEBUG], [1], [Debug fixed-point implementation])
141 ])
142
143 AC_ARG_ENABLE([float_api],
144     [AS_HELP_STRING([--disable-float-api],
145                     [compile without the floating point API (for machines with no float library)])],,
146     [enable_float_api=yes])
147
148 AM_CONDITIONAL([DISABLE_FLOAT_API], [test "$enable_float_api" = "no"])
149
150 AS_IF([test "$enable_float_api" = "no"],[
151   AC_DEFINE([DISABLE_FLOAT_API], [1], [Do not build the float API])
152 ])
153
154 AC_ARG_ENABLE([custom-modes],
155     [AS_HELP_STRING([--enable-custom-modes], [enable non-Opus modes, e.g. 44.1 kHz & 2^n frames])],,
156     [enable_custom_modes=no])
157
158 AS_IF([test "$enable_custom_modes" = "yes"],[
159   AC_DEFINE([CUSTOM_MODES], [1], [Custom modes])
160   PC_BUILD="$PC_BUILD, custom modes"
161 ])
162
163 AM_CONDITIONAL([CUSTOM_MODES], [test "$enable_custom_modes" = "yes"])
164
165 has_float_approx=no
166 #case "$host_cpu" in
167 #i[[3456]]86 | x86_64 | powerpc64 | powerpc32 | ia64)
168 #  has_float_approx=yes
169 #  ;;
170 #esac
171
172 AC_ARG_ENABLE([float-approx],
173     [AS_HELP_STRING([--enable-float-approx], [enable fast approximations for floating point])],
174     [if test "$enable_float_approx" = "yes"; then
175        AC_WARN([Floating point approximations are not supported on all platforms.])
176      fi
177     ],
178     [enable_float_approx=$has_float_approx])
179
180 AS_IF([test "$enable_float_approx" = "yes"],[
181   AC_DEFINE([FLOAT_APPROX], [1], [Float approximations])
182 ])
183
184 AC_ARG_ENABLE([asm],
185     [AS_HELP_STRING([--disable-asm], [Disable assembly optimizations])],,
186     [enable_asm=yes])
187
188 AC_ARG_ENABLE([rtcd],
189     [AS_HELP_STRING([--disable-rtcd], [Disable run-time CPU capabilities detection])],,
190     [enable_rtcd=yes])
191
192 AC_ARG_ENABLE([intrinsics],
193     [AS_HELP_STRING([--enable-intrinsics], [Enable intrinsics optimizations for ARM(float) X86(fixed)])],,
194     [enable_intrinsics=no])
195
196 rtcd_support=no
197 cpu_arm=no
198
199 AS_IF([test x"${enable_asm}" = x"yes"],[
200     inline_optimization="No inline ASM for your platform, please send patches"
201     case $host_cpu in
202       arm*)
203         dnl Currently we only have asm for fixed-point
204         AS_IF([test "$enable_float" != "yes"],[
205             cpu_arm=yes
206             AC_DEFINE([OPUS_ARM_ASM], [],  [Make use of ARM asm optimization])
207             AS_GCC_INLINE_ASSEMBLY(
208                 [inline_optimization="ARM"],
209                 [inline_optimization="disabled"]
210             )
211             AS_ASM_ARM_EDSP([OPUS_ARM_INLINE_EDSP=1],[OPUS_ARM_INLINE_EDSP=0])
212             AS_ASM_ARM_MEDIA([OPUS_ARM_INLINE_MEDIA=1],
213                 [OPUS_ARM_INLINE_MEDIA=0])
214             AS_ASM_ARM_NEON([OPUS_ARM_INLINE_NEON=1],[OPUS_ARM_INLINE_NEON=0])
215             AS_IF([test x"$inline_optimization" = x"ARM"],[
216                 AM_CONDITIONAL([OPUS_ARM_INLINE_ASM],[true])
217                 AC_DEFINE([OPUS_ARM_INLINE_ASM], 1,
218                     [Use generic ARMv4 inline asm optimizations])
219                 AS_IF([test x"$OPUS_ARM_INLINE_EDSP" = x"1"],[
220                     AC_DEFINE([OPUS_ARM_INLINE_EDSP], [1],
221                         [Use ARMv5E inline asm optimizations])
222                     inline_optimization="$inline_optimization (EDSP)"
223                 ])
224                 AS_IF([test x"$OPUS_ARM_INLINE_MEDIA" = x"1"],[
225                     AC_DEFINE([OPUS_ARM_INLINE_MEDIA], [1],
226                         [Use ARMv6 inline asm optimizations])
227                     inline_optimization="$inline_optimization (Media)"
228                 ])
229                 AS_IF([test x"$OPUS_ARM_INLINE_NEON" = x"1"],[
230                     AC_DEFINE([OPUS_ARM_INLINE_NEON], 1,
231                         [Use ARM NEON inline asm optimizations])
232                     inline_optimization="$inline_optimization (NEON)"
233                 ])
234             ])
235             dnl We need Perl to translate RVCT-syntax asm to gas syntax.
236             AC_CHECK_PROG([HAVE_PERL], perl, yes, no)
237             AS_IF([test x"$HAVE_PERL" = x"yes"],[
238                 AM_CONDITIONAL([OPUS_ARM_EXTERNAL_ASM],[true])
239                 asm_optimization="ARM"
240                 AS_IF([test x"$OPUS_ARM_INLINE_EDSP" = x"1"], [
241                     OPUS_ARM_PRESUME_EDSP=1
242                     OPUS_ARM_MAY_HAVE_EDSP=1
243                 ],
244                 [
245                     OPUS_ARM_PRESUME_EDSP=0
246                     OPUS_ARM_MAY_HAVE_EDSP=0
247                 ])
248                 AS_IF([test x"$OPUS_ARM_INLINE_MEDIA" = x"1"], [
249                     OPUS_ARM_PRESUME_MEDIA=1
250                     OPUS_ARM_MAY_HAVE_MEDIA=1
251                 ],
252                 [
253                     OPUS_ARM_PRESUME_MEDIA=0
254                     OPUS_ARM_MAY_HAVE_MEDIA=0
255                 ])
256                 AS_IF([test x"$OPUS_ARM_INLINE_NEON" = x"1"], [
257                     OPUS_ARM_PRESUME_NEON=1
258                     OPUS_ARM_MAY_HAVE_NEON=1
259                 ],
260                 [
261                     OPUS_ARM_PRESUME_NEON=0
262                     OPUS_ARM_MAY_HAVE_NEON=0
263                 ])
264                 AS_IF([test x"$enable_rtcd" = x"yes"],[
265                     AS_IF([test x"$OPUS_ARM_MAY_HAVE_EDSP" != x"1"],[
266                         AC_MSG_NOTICE(
267                           [Trying to force-enable armv5e EDSP instructions...])
268                         AS_ASM_ARM_EDSP_FORCE([OPUS_ARM_MAY_HAVE_EDSP=1])
269                     ])
270                     AS_IF([test x"$OPUS_ARM_MAY_HAVE_MEDIA" != x"1"],[
271                         AC_MSG_NOTICE(
272                           [Trying to force-enable ARMv6 media instructions...])
273                         AS_ASM_ARM_MEDIA_FORCE([OPUS_ARM_MAY_HAVE_MEDIA=1])
274                     ])
275                     AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON" != x"1"],[
276                         AC_MSG_NOTICE(
277                           [Trying to force-enable NEON instructions...])
278                         AS_ASM_ARM_NEON_FORCE([OPUS_ARM_MAY_HAVE_NEON=1])
279                     ])
280                 ])
281                 rtcd_support=
282                 AS_IF([test x"$OPUS_ARM_MAY_HAVE_EDSP" = x"1"],[
283                     AC_DEFINE(OPUS_ARM_MAY_HAVE_EDSP, 1,
284                         [Define if assembler supports EDSP instructions])
285                     AS_IF([test x"$OPUS_ARM_PRESUME_EDSP" = x"1"],[
286                         AC_DEFINE(OPUS_ARM_PRESUME_EDSP, 1,
287                           [Define if binary requires EDSP instruction support])
288                         asm_optimization="$asm_optimization (EDSP)"
289                     ],
290                         [rtcd_support="$rtcd_support (EDSP)"]
291                     )
292                 ])
293                 AC_SUBST(OPUS_ARM_MAY_HAVE_EDSP)
294                 AS_IF([test x"$OPUS_ARM_MAY_HAVE_MEDIA" = x"1"],[
295                     AC_DEFINE(OPUS_ARM_MAY_HAVE_MEDIA, 1,
296                       [Define if assembler supports ARMv6 media instructions])
297                     AS_IF([test x"$OPUS_ARM_PRESUME_MEDIA" = x"1"],[
298                         AC_DEFINE(OPUS_ARM_PRESUME_MEDIA, 1,
299                           [Define if binary requires ARMv6 media instruction support])
300                         asm_optimization="$asm_optimization (Media)"
301                     ],
302                         [rtcd_support="$rtcd_support (Media)"]
303                     )
304                 ])
305                 AC_SUBST(OPUS_ARM_MAY_HAVE_MEDIA)
306                 AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON" = x"1"],[
307                     AC_DEFINE(OPUS_ARM_MAY_HAVE_NEON, 1,
308                       [Define if compiler supports NEON instructions])
309                     AS_IF([test x"$OPUS_ARM_PRESUME_NEON" = x"1"], [
310                         AC_DEFINE(OPUS_ARM_PRESUME_NEON, 1,
311                           [Define if binary requires NEON instruction support])
312                         asm_optimization="$asm_optimization (NEON)"
313                     ],
314                         [rtcd_support="$rtcd_support (NEON)"]
315                     )
316                 ])
317                 AC_SUBST(OPUS_ARM_MAY_HAVE_NEON)
318                 dnl Make sure turning on RTCD gets us at least one
319                 dnl instruction set.
320                 AS_IF([test x"$rtcd_support" != x""],
321                     [rtcd_support=ARM"$rtcd_support"],
322                     [rtcd_support="no"]
323                 )
324                 AC_MSG_CHECKING([for apple style tools])
325                 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([
326 #ifndef __APPLE__
327 #error 1
328 #endif],[])],
329                     [AC_MSG_RESULT([yes]); ARM2GNU_PARAMS="--apple"],
330                     [AC_MSG_RESULT([no]); ARM2GNU_PARAMS=""])
331                 AC_SUBST(ARM2GNU_PARAMS)
332             ],
333             [
334                 AC_MSG_WARN(
335                   [*** ARM assembly requires perl -- disabling optimizations])
336                 asm_optimization="(missing perl dependency for ARM)"
337             ])
338         ])
339         ;;
340     esac
341 ],[
342    inline_optimization="disabled"
343    asm_optimization="disabled"
344 ])
345
346 AM_CONDITIONAL([OPUS_ARM_INLINE_ASM],
347     [test x"${inline_optimization%% *}" = x"ARM"])
348 AM_CONDITIONAL([OPUS_ARM_EXTERNAL_ASM],
349     [test x"${asm_optimization%% *}" = x"ARM"])
350
351 AM_CONDITIONAL([HAVE_SSE], [false])
352 AM_CONDITIONAL([HAVE_SSE2], [false])
353 AM_CONDITIONAL([HAVE_SSE4_1], [false])
354
355 m4_define([DEFAULT_X86_SSE_CFLAGS], [-msse])
356 m4_define([DEFAULT_X86_SSE2_CFLAGS], [-msse2])
357 m4_define([DEFAULT_X86_SSE4_1_CFLAGS], [-msse4.1])
358 m4_define([DEFAULT_ARM_NEON_INTR_CFLAGS], [-mfpu=neon])
359 # With GCC on ARM32 softfp architectures (e.g. Android, or older Ubuntu) you need to specify
360 # -mfloat-abi=softfp for -mfpu=neon to work.  However, on ARM32 hardfp architectures (e.g. newer Ubuntu),
361 # this option will break things.
362
363 # As a heuristic, if host matches arm*eabi* but not arm*hf*, it's probably soft-float.
364 m4_define([DEFAULT_ARM_NEON_SOFTFP_INTR_CFLAGS], [-mfpu=neon -mfloat-abi=softfp])
365
366 AS_CASE([$host],
367         [arm*hf*], [AS_VAR_SET([RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS], "DEFAULT_ARM_NEON_INTR_CFLAGS")],
368         [arm*eabi*], [AS_VAR_SET([RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS], "DEFAULT_ARM_NEON_SOFTFP_INTR_CFLAGS")],
369         [AS_VAR_SET([RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS], "DEFAULT_ARM_NEON_INTR_CFLAGS")])
370
371 AC_ARG_VAR([X86_SSE_CFLAGS], [C compiler flags to compile SSE intrinsics @<:@default=]DEFAULT_X86_SSE_CFLAGS[@:>@])
372 AC_ARG_VAR([X86_SSE2_CFLAGS], [C compiler flags to compile SSE2 intrinsics @<:@default=]DEFAULT_X86_SSE2_CFLAGS[@:>@])
373 AC_ARG_VAR([X86_SSE4_1_CFLAGS], [C compiler flags to compile SSE4.1 intrinsics @<:@default=]DEFAULT_X86_SSE4_1_CFLAGS[@:>@])
374 AC_ARG_VAR([ARM_NEON_INTR_CFLAGS], [C compiler flags to compile ARM NEON intrinsics @<:@default=]DEFAULT_ARM_NEON_INTR_CFLAGS / DEFAULT_ARM_NEON_SOFTFP_INTR_CFLAGS[@:>@])
375
376 AS_VAR_SET_IF([X86_SSE_CFLAGS], [], [AS_VAR_SET([X86_SSE_CFLAGS], "DEFAULT_X86_SSE_CFLAGS")])
377 AS_VAR_SET_IF([X86_SSE2_CFLAGS], [], [AS_VAR_SET([X86_SSE2_CFLAGS], "DEFAULT_X86_SSE2_CFLAGS")])
378 AS_VAR_SET_IF([X86_SSE4_1_CFLAGS], [], [AS_VAR_SET([X86_SSE4_1_CFLAGS], "DEFAULT_X86_SSE4_1_CFLAGS")])
379 AS_VAR_SET_IF([ARM_NEON_INTR_CFLAGS], [], [AS_VAR_SET([ARM_NEON_INTR_CFLAGS], ["$RESOLVED_DEFAULT_ARM_NEON_INTR_CFLAGS"])])
380
381 AC_DEFUN([OPUS_PATH_NE10],
382    [
383       AC_ARG_WITH(NE10,
384                   AC_HELP_STRING([--with-NE10=PFX],[Prefix where libNE10 is installed (optional)]),
385                   NE10_prefix="$withval", NE10_prefix="")
386       AC_ARG_WITH(NE10-libraries,
387                   AC_HELP_STRING([--with-NE10-libraries=DIR],
388                         [Directory where libNE10 library is installed (optional)]),
389                   NE10_libraries="$withval", NE10_libraries="")
390       AC_ARG_WITH(NE10-includes,
391                   AC_HELP_STRING([--with-NE10-includes=DIR],
392                                  [Directory where libNE10 header files are installed (optional)]),
393                   NE10_includes="$withval", NE10_includes="")
394
395       if test "x$NE10_libraries" != "x" ; then
396          NE10_LIBS="-L$NE10_libraries"
397       elif test "x$NE10_prefix" = "xno" || test "x$NE10_prefix" = "xyes" ; then
398          NE10_LIBS=""
399       elif test "x$NE10_prefix" != "x" ; then
400          NE10_LIBS="-L$NE10_prefix/lib"
401       elif test "x$prefix" != "xNONE" ; then
402          NE10_LIBS="-L$prefix/lib"
403       fi
404
405       if test "x$NE10_prefix" != "xno" ; then
406          NE10_LIBS="$NE10_LIBS -lNE10"
407       fi
408
409       if test "x$NE10_includes" != "x" ; then
410          NE10_CFLAGS="-I$NE10_includes"
411       elif test "x$NE10_prefix" = "xno" || test "x$NE10_prefix" = "xyes" ; then
412          NE10_CFLAGS=""
413       elif test "x$ogg_prefix" != "x" ; then
414          NE10_CFLAGS="-I$NE10_prefix/include"
415       elif test "x$prefix" != "xNONE"; then
416          NE10_CFLAGS="-I$prefix/include"
417       fi
418
419       AC_MSG_CHECKING(for NE10)
420       save_CFLAGS="$CFLAGS"; CFLAGS="$NE10_CFLAGS"
421       save_LIBS="$LIBS"; LIBS="$NE10_LIBS $LIBM"
422       AC_LINK_IFELSE(
423          [
424             AC_LANG_PROGRAM(
425                [[#include <NE10_init.h>
426                ]],
427                [[
428                   ne10_fft_cfg_float32_t cfg;
429                   cfg = ne10_fft_alloc_c2c_float32_neon(480);
430                ]]
431             )
432          ],[
433             HAVE_ARM_NE10=1
434             AC_MSG_RESULT([yes])
435          ],[
436             HAVE_ARM_NE10=0
437             AC_MSG_RESULT([no])
438             NE10_CFLAGS=""
439             NE10_LIBS=""
440          ]
441       )
442       CFLAGS="$save_CFLAGS"; LIBS="$save_LIBS"
443       #Now we know if libNE10 is installed or not
444       AS_IF([test x"$HAVE_ARM_NE10" = x"1"],
445          [
446             AC_DEFINE([HAVE_ARM_NE10], 1, [NE10 library is installed on host. Make sure it is on target!])
447             AC_SUBST(HAVE_ARM_NE10)
448             AC_SUBST(NE10_CFLAGS)
449             AC_SUBST(NE10_LIBS)
450          ],[]
451       )
452    ]
453 )
454
455 AS_IF([test x"$enable_intrinsics" = x"yes"],[
456    intrinsics_support=""
457    AS_CASE([$host_cpu],
458    [arm*],
459    [
460       cpu_arm=yes
461       OPUS_CHECK_INTRINSICS(
462          [ARM Neon],
463          [$ARM_NEON_INTR_CFLAGS],
464          [OPUS_ARM_MAY_HAVE_NEON_INTR],
465          [OPUS_ARM_PRESUME_NEON_INTR],
466          [[#include <arm_neon.h>
467          ]],
468          [[
469             static float32x4_t A0, A1, SUMM;
470             SUMM = vmlaq_f32(SUMM, A0, A1);
471          ]]
472       )
473       AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON_INTR" = x"1" && test x"$OPUS_ARM_PRESUME_NEON_INTR" != x"1"],
474           [
475              OPUS_ARM_NEON_INTR_CFLAGS="$ARM_NEON_INTR_CFLAGS"
476              AC_SUBST([OPUS_ARM_NEON_INTR_CFLAGS])
477           ]
478       )
479
480       #Currently we only have intrinsic optimizations for floating point
481       AS_IF([test x"$enable_float" = x"yes"],
482       [
483          AS_IF([test x"$OPUS_ARM_MAY_HAVE_NEON_INTR" = x"1"],
484          [
485             AC_DEFINE([OPUS_ARM_MAY_HAVE_NEON_INTR], 1, [Compiler supports ARMv7 Neon Intrinsics])
486             intrinsics_support="$intrinsics_support (Neon_Intrinsics)"
487
488             AS_IF([test x"enable_rtcd" != x"" && test x"$OPUS_ARM_PRESUME_NEON_INTR" != x"1"],
489                [rtcd_support="$rtcd_support (ARMv7_Neon_Intrinsics)"],[])
490
491             AS_IF([test x"$OPUS_ARM_PRESUME_NEON_INTR" = x"1"],
492                [AC_DEFINE([OPUS_ARM_PRESUME_NEON_INTR], 1, [Define if binary requires NEON intrinsics support])])
493
494             OPUS_PATH_NE10()
495             AS_IF([test x"$NE10_LIBS" != x""],
496             [
497                  intrinsics_support="$intrinsics_support (NE10)"
498                  AS_IF([test x"enable_rtcd" != x"" \
499                   && test x"$OPUS_ARM_PRESUME_NEON_INTR" != x"1"],
500                     [rtcd_support="$rtcd_support (NE10)"],[])
501             ])
502
503             AS_IF([test x"$rtcd_support" = x""],
504                [rtcd_support=no])
505
506             AS_IF([test x"$intrinsics_support" = x""],
507                [intrinsics_support=no],
508                            [intrinsics_support="arm$intrinsics_support"])
509          ],
510          [
511             AC_MSG_WARN([Compiler does not support ARM intrinsics])
512             intrinsics_support=no
513          ])
514       ], [
515             AC_MSG_WARN([Currently only have ARM intrinsics for float])
516             intrinsics_support=no
517       ])
518    ],
519    [i?86|x86_64],
520    [
521       OPUS_CHECK_INTRINSICS(
522          [SSE],
523          [$X86_SSE_CFLAGS],
524          [OPUS_X86_MAY_HAVE_SSE],
525          [OPUS_X86_PRESUME_SSE],
526          [[#include <xmmintrin.h>
527          ]],
528          [[
529              static __m128 mtest;
530              mtest = _mm_setzero_ps();
531          ]]
532       )
533       AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE" = x"1" && test x"$OPUS_X86_PRESUME_SSE" != x"1"],
534           [
535              OPUS_X86_SSE_CFLAGS="$X86_SSE_CFLAGS"
536              AC_SUBST([OPUS_X86_SSE_CFLAGS])
537           ]
538       )
539       OPUS_CHECK_INTRINSICS(
540          [SSE2],
541          [$X86_SSE2_CFLAGS],
542          [OPUS_X86_MAY_HAVE_SSE2],
543          [OPUS_X86_PRESUME_SSE2],
544          [[#include <emmintrin.h>
545          ]],
546          [[
547              static __m128i mtest;
548              mtest = _mm_setzero_si128();
549          ]]
550       )
551       AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE2" = x"1" && test x"$OPUS_X86_PRESUME_SSE2" != x"1"],
552           [
553              OPUS_X86_SSE2_CFLAGS="$X86_SSE2_CFLAGS"
554              AC_SUBST([OPUS_X86_SSE2_CFLAGS])
555           ]
556       )
557       OPUS_CHECK_INTRINSICS(
558          [SSE4.1],
559          [$X86_SSE4_1_CFLAGS],
560          [OPUS_X86_MAY_HAVE_SSE4_1],
561          [OPUS_X86_PRESUME_SSE4_1],
562          [[#include <smmintrin.h>
563          ]],
564          [[
565             static __m128i mtest;
566             mtest = _mm_setzero_si128();
567             mtest = _mm_cmpeq_epi64(mtest, mtest);
568          ]]
569       )
570       AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE4_1" = x"1" && test x"$OPUS_X86_PRESUME_SSE4_1" != x"1"],
571           [
572              OPUS_X86_SSE4_1_CFLAGS="$X86_SSE4_1_CFLAGS"
573              AC_SUBST([OPUS_X86_SSE4_1_CFLAGS])
574           ]
575       )
576
577          AS_IF([test x"$rtcd_support" = x"no"], [rtcd_support=""])
578          AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE" = x"1"],
579          [
580             AC_DEFINE([OPUS_X86_MAY_HAVE_SSE], 1, [Compiler supports X86 SSE Intrinsics])
581             intrinsics_support="$intrinsics_support SSE"
582
583             AS_IF([test x"$OPUS_X86_PRESUME_SSE" = x"1"],
584                [AC_DEFINE([OPUS_X86_PRESUME_SSE], 1, [Define if binary requires SSE intrinsics support])],
585                [rtcd_support="$rtcd_support SSE"])
586          ],
587          [
588             AC_MSG_WARN([Compiler does not support SSE intrinsics])
589          ])
590
591          AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE2" = x"1"],
592          [
593             AC_DEFINE([OPUS_X86_MAY_HAVE_SSE2], 1, [Compiler supports X86 SSE2 Intrinsics])
594             intrinsics_support="$intrinsics_support SSE2"
595
596             AS_IF([test x"$OPUS_X86_PRESUME_SSE2" = x"1"],
597                [AC_DEFINE([OPUS_X86_PRESUME_SSE2], 1, [Define if binary requires SSE2 intrinsics support])],
598                [rtcd_support="$rtcd_support SSE2"])
599          ],
600          [
601             AC_MSG_WARN([Compiler does not support SSE2 intrinsics])
602          ])
603
604          AS_IF([test x"$OPUS_X86_MAY_HAVE_SSE4_1" = x"1"],
605          [
606             AC_DEFINE([OPUS_X86_MAY_HAVE_SSE4_1], 1, [Compiler supports X86 SSE4.1 Intrinsics])
607             intrinsics_support="$intrinsics_support SSE4.1"
608
609             AS_IF([test x"$OPUS_X86_PRESUME_SSE4_1" = x"1"],
610                [AC_DEFINE([OPUS_X86_PRESUME_SSE4_1], 1, [Define if binary requires SSE4.1 intrinsics support])],
611                [rtcd_support="$rtcd_support SSE4.1"])
612          ],
613          [
614             AC_MSG_WARN([Compiler does not support SSE4.1 intrinsics])
615          ])
616          AS_IF([test x"$intrinsics_support" = x""],
617             [intrinsics_support=no],
618             [intrinsics_support="x86$intrinsics_support"]
619          )
620          AS_IF([test x"$rtcd_support" = x""],
621             [rtcd_support=no],
622             [rtcd_support="x86$rtcd_support"],
623         )
624
625     AS_IF([test x"$enable_rtcd" = x"yes" && test x"$rtcd_support" != x""],[
626             get_cpuid_by_asm="no"
627             AC_MSG_CHECKING([How to get X86 CPU Info])
628             AC_LINK_IFELSE([AC_LANG_PROGRAM([[
629                  #include <stdio.h>
630             ]],[[
631                  unsigned int CPUInfo0;
632                  unsigned int CPUInfo1;
633                  unsigned int CPUInfo2;
634                  unsigned int CPUInfo3;
635                  unsigned int InfoType;
636                  __asm__ __volatile__ (
637                  "cpuid":
638                  "=a" (CPUInfo0),
639                  "=b" (CPUInfo1),
640                  "=c" (CPUInfo2),
641                  "=d" (CPUInfo3) :
642                  "a" (InfoType), "c" (0)
643                 );
644             ]])],
645             [get_cpuid_by_asm="yes"
646              AC_MSG_RESULT([Inline Assembly])
647                          AC_DEFINE([CPU_INFO_BY_ASM], [1], [Get CPU Info by asm method])],
648              [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
649                  #include <cpuid.h>
650             ]],[[
651                  unsigned int CPUInfo0;
652                  unsigned int CPUInfo1;
653                  unsigned int CPUInfo2;
654                  unsigned int CPUInfo3;
655                  unsigned int InfoType;
656                  __get_cpuid(InfoType, &CPUInfo0, &CPUInfo1, &CPUInfo2, &CPUInfo3);
657             ]])],
658             [AC_MSG_RESULT([C method])
659                          AC_DEFINE([CPU_INFO_BY_C], [1], [Get CPU Info by c method])],
660             [AC_MSG_ERROR([no supported Get CPU Info method, please disable intrinsics])])])])
661    ],
662    [
663       AC_MSG_WARN([No intrinsics support for your architecture])
664       intrinsics_support="no"
665    ])
666 ],
667 [
668    intrinsics_support="no"
669 ])
670
671 AM_CONDITIONAL([CPU_ARM], [test "$cpu_arm" = "yes"])
672 AM_CONDITIONAL([OPUS_ARM_NEON_INTR],
673     [test x"$OPUS_ARM_MAY_HAVE_NEON_INTR" = x"1"])
674 AM_CONDITIONAL([HAVE_ARM_NE10],
675     [test x"$HAVE_ARM_NE10" = x"1"])
676 AM_CONDITIONAL([HAVE_SSE],
677     [test x"$OPUS_X86_MAY_HAVE_SSE" = x"1"])
678 AM_CONDITIONAL([HAVE_SSE2],
679     [test x"$OPUS_X86_MAY_HAVE_SSE2" = x"1"])
680 AM_CONDITIONAL([HAVE_SSE4_1],
681     [test x"$OPUS_X86_MAY_HAVE_SSE4_1" = x"1"])
682
683 AS_IF([test x"$enable_rtcd" = x"yes"],[
684     AS_IF([test x"$rtcd_support" != x"no"],[
685         AC_DEFINE([OPUS_HAVE_RTCD], [1],
686             [Use run-time CPU capabilities detection])
687         OPUS_HAVE_RTCD=1
688         AC_SUBST(OPUS_HAVE_RTCD)
689     ])
690 ],[
691     rtcd_support="disabled"
692 ])
693
694 AC_ARG_ENABLE([assertions],
695     [AS_HELP_STRING([--enable-assertions],[enable additional software error checking])],,
696     [enable_assertions=no])
697
698 AS_IF([test "$enable_assertions" = "yes"], [
699   AC_DEFINE([ENABLE_ASSERTIONS], [1], [Assertions])
700 ])
701
702 AC_ARG_ENABLE([fuzzing],
703     [AS_HELP_STRING([--enable-fuzzing],[causes the encoder to make random decisions])],,
704     [enable_fuzzing=no])
705
706 AS_IF([test "$enable_fuzzing" = "yes"], [
707   AC_DEFINE([FUZZING], [1], [Fuzzing])
708 ])
709
710 AC_ARG_ENABLE([doc],
711     [AS_HELP_STRING([--disable-doc], [Do not build API documentation])],,
712     [enable_doc=yes])
713
714 AS_IF([test "$enable_doc" = "yes"], [
715   AC_CHECK_PROG(HAVE_DOXYGEN, [doxygen], [yes], [no])
716 ],[
717   HAVE_DOXYGEN=no
718 ])
719
720 AM_CONDITIONAL([HAVE_DOXYGEN], [test "$HAVE_DOXYGEN" = "yes"])
721
722 AC_ARG_ENABLE([extra-programs],
723     [AS_HELP_STRING([--disable-extra-programs], [Do not build extra programs (demo and tests)])],,
724     [enable_extra_programs=yes])
725
726 AM_CONDITIONAL([EXTRA_PROGRAMS], [test "$enable_extra_programs" = "yes"])
727
728
729 saved_CFLAGS="$CFLAGS"
730 CFLAGS="$CFLAGS -fvisibility=hidden"
731 AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden])
732 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
733     [ AC_MSG_RESULT([yes]) ],
734     [ AC_MSG_RESULT([no])
735       CFLAGS="$saved_CFLAGS"
736     ])
737
738 CFLAGS="$CFLAGS -W"
739
740 warn_CFLAGS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes"
741 saved_CFLAGS="$CFLAGS"
742 CFLAGS="$CFLAGS $warn_CFLAGS"
743 AC_MSG_CHECKING([if ${CC} supports ${warn_CFLAGS}])
744 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
745     [ AC_MSG_RESULT([yes]) ],
746     [ AC_MSG_RESULT([no])
747       CFLAGS="$saved_CFLAGS"
748     ])
749
750 saved_LIBS="$LIBS"
751 LIBS="$LIBS $LIBM"
752 AC_CHECK_FUNCS([lrintf])
753 AC_CHECK_FUNCS([lrint])
754 LIBS="$saved_LIBS"
755
756 AC_CHECK_FUNCS([__malloc_hook])
757
758 AC_SUBST([PC_BUILD])
759
760 AC_CONFIG_FILES([
761     Makefile
762     opus.pc
763     opus-uninstalled.pc
764     celt/arm/armopts.s
765     doc/Makefile
766     doc/Doxyfile
767 ])
768 AC_CONFIG_HEADERS([config.h])
769
770 AC_OUTPUT
771
772 AC_MSG_NOTICE([
773 ------------------------------------------------------------------------
774   $PACKAGE_NAME $PACKAGE_VERSION:  Automatic configuration OK.
775
776     Compiler support:
777
778       C99 var arrays: ................ ${has_var_arrays}
779       C99 lrintf: .................... ${ac_cv_func_lrintf}
780       Use alloca: .................... ${use_alloca}
781
782     General configuration:
783
784       Floating point support: ........ ${enable_float}
785       Fast float approximations: ..... ${enable_float_approx}
786       Fixed point debugging: ......... ${enable_fixed_point_debug}
787       Inline Assembly Optimizations: . ${inline_optimization}
788       External Assembly Optimizations: ${asm_optimization}
789       Intrinsics Optimizations.......: ${intrinsics_support}
790       Run-time CPU detection: ........ ${rtcd_support}
791       Custom modes: .................. ${enable_custom_modes}
792       Assertion checking: ............ ${enable_assertions}
793       Fuzzing: ....................... ${enable_fuzzing}
794
795       API documentation: ............. ${enable_doc}
796       Extra programs: ................ ${enable_extra_programs}
797 ------------------------------------------------------------------------
798
799  Type "make; make install" to compile and install
800  Type "make check" to run the test suite
801 ])
802