From 230a055501c52c9c78d7ed8b29ab553a10f234a4 Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 3 Jun 2014 23:29:23 -0700 Subject: [PATCH] configure: set WEBP_HAVE_AVX2 when available this is used to set WEBP_USE_AVX2 in files where the build flag won't be used, i.e., dsp/enc.c, which enables VP8EncDspInitAVX2() to be called Change-Id: I362f4ba39ca40d3e07a081292d5f743c649d9d7f --- configure.ac | 5 +++++ src/dsp/dsp.h | 6 +++++- src/dsp/enc.c | 11 ++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 0d6d0b85..1c5395ff 100644 --- a/configure.ac +++ b/configure.ac @@ -60,6 +60,11 @@ TEST_AND_ADD_CFLAGS([AM_CFLAGS], [-Wvla]) AC_SUBST([AM_CFLAGS]) TEST_AND_ADD_CFLAGS([AVX2_FLAGS], [-mavx2]) +# Assume the presence of any flag is enough. This could be made more robust +# with a header and/or compile check if needed. +AS_IF([test -n "$AVX2_FLAGS"], [ + AC_DEFINE(WEBP_HAVE_AVX2, [1], + [Set to 1 if AVX2 is supported])]) AC_SUBST([AVX2_FLAGS]) dnl === CLEAR_LIBVARS([var_pfx]) diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h index 51c3bb8e..107bc5cc 100644 --- a/src/dsp/dsp.h +++ b/src/dsp/dsp.h @@ -14,6 +14,10 @@ #ifndef WEBP_DSP_DSP_H_ #define WEBP_DSP_DSP_H_ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "../webp/types.h" #ifdef __cplusplus @@ -40,7 +44,7 @@ extern "C" { #define WEBP_USE_SSE2 #endif -#if defined(__AVX2__) +#if defined(__AVX2__) || defined(WEBP_HAVE_AVX2) #define WEBP_USE_AVX2 #endif diff --git a/src/dsp/enc.c b/src/dsp/enc.c index d9b25904..e4ea8cb8 100644 --- a/src/dsp/enc.c +++ b/src/dsp/enc.c @@ -720,17 +720,18 @@ void VP8EncDspInit(void) { if (VP8GetCPUInfo(kSSE2)) { VP8EncDspInitSSE2(); } - // TODO(jzern): this should be conditionally included based on a configure - // (HAVE_AVX2) define. We can't use WEBP_USE_AVX2/__AVX2__ here as -mavx2 - // won't be defined for this file. +#endif +#if defined(WEBP_USE_AVX2) if (VP8GetCPUInfo(kAVX2)) { VP8EncDspInitAVX2(); } -#elif defined(WEBP_USE_NEON) +#endif +#if defined(WEBP_USE_NEON) if (VP8GetCPUInfo(kNEON)) { VP8EncDspInitNEON(); } -#elif defined(WEBP_USE_MIPS32) +#endif +#if defined(WEBP_USE_MIPS32) if (VP8GetCPUInfo(kMIPS32)) { VP8EncDspInitMIPS32(); }