Commit 5daaa838 authored by Attila Nagy's avatar Attila Nagy

Enables building examples with Android NDK

Soft enable runtime cpu detect for armv7-android target, so that it
can be disabled and remove dependency on 'cpufeatures' lib.
Change the arm_cpu_caps implementation selection such that 'no rtcd' takes
precedence over system type.

Switch to use -mtune instead of -mcpu. NDK was complaining about
-mcpu=cortex-a8 conflicting with -march=armv7-a, not sure why.

Add a linker flag to fix some cortex-a8 bug, as suggested by NDK Dev
Guide.

Examples:
Configure for armv7+neon:

./configure --target=armv7-android-gcc \
            --sdk-path=/path/to/android/ndk \
            --disable-runtime-cpu-detect \
            --enable-realtime-only \
            --disable-unit-tests

...armv7 w/o neon:

./configure --target=armv7-android-gcc \
            --sdk-path=/path/to/android/ndk \
            --disable-runtime-cpu-detect \
            --enable-realtime-only \
            --disable-neon \
            --cpu=cortex-a9 \
            --disable-unit-tests

Change-Id: I37e2c0592745208979deec38f7658378d4bd6cfa
parent b178fe7b
......@@ -34,8 +34,15 @@
# Application.mk in the jni directory that contains:
# APP_ABI := armeabi-v7a
#
# By default libvpx will detect at runtime the existance of NEON extension.
# For this we import the 'cpufeatures' module from the NDK sources.
# libvpx can also be configured without this runtime detection method.
# Configuring with --disable-runtime-cpu-detect will assume presence of NEON.
# Configuring with --disable-runtime-cpu-detect --disable-neon will remove any
# NEON dependency.
# To change to building armeabi, run ./libvpx/configure again, but with
# --target=arm5te-android-gcc and and modify the Application.mk file to
# --target=arm5te-android-gcc and modify the Application.mk file to
# set APP_ABI := armeabi
#
# Running ndk-build will build libvpx and include it in your project.
......@@ -166,7 +173,9 @@ LOCAL_MODULE := libvpx
LOCAL_LDLIBS := -llog
LOCAL_STATIC_LIBRARIES := cpufeatures
ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
LOCAL_STATIC_LIBRARIES := cpufeatures
endif
$(foreach file, $(LOCAL_SRC_FILES), $(LOCAL_PATH)/$(file)): vpx_rtcd.h
......@@ -196,4 +205,7 @@ ifeq ($(CONFIG_VP8_ENCODER), yes)
$(LIBVPX_PATH)/vp8/encoder/asm_enc_offsets.c))
endif
ifeq ($(CONFIG_RUNTIME_CPU_DETECT),yes)
$(call import-module,cpufeatures)
endif
......@@ -773,17 +773,23 @@ process_common_toolchain() {
check_add_asflags --defsym ARCHITECTURE=${arch_int}
tune_cflags="-mtune="
if [ ${tgt_isa} == "armv7" ]; then
check_add_cflags -march=armv7-a -mfloat-abi=softfp
check_add_asflags -march=armv7-a -mfloat-abi=softfp
if enabled neon
then
check_add_cflags -mfpu=neon #-ftree-vectorize
check_add_asflags -mfpu=neon
fi
check_add_cflags -march=armv7-a -mcpu=cortex-a8 -mfloat-abi=softfp
check_add_asflags -mcpu=cortex-a8 -mfloat-abi=softfp #-march=armv7-a
if [ -z "${tune_cpu}" ]; then
tune_cpu=cortex-a8
fi
else
check_add_cflags -march=${tgt_isa}
check_add_asflags -march=${tgt_isa}
fi
enabled debug && add_asflags -g
asm_conversion_cmd="${source_path}/build/make/ads2gas.pl"
;;
......@@ -851,12 +857,17 @@ process_common_toolchain() {
add_cflags "--sysroot=${alt_libc}"
add_ldflags "--sysroot=${alt_libc}"
add_cflags "-I${SDK_PATH}/sources/android/cpufeatures/"
# linker flag that routes around a CPU bug in some
# Cortex-A8 implementations (NDK Dev Guide)
add_ldflags "-Wl,--fix-cortex-a8"
enable pic
soft_enable realtime_only
if [ ${tgt_isa} == "armv7" ]; then
enable runtime_cpu_detect
soft_enable runtime_cpu_detect
fi
if enabled runtime_cpu_detect; then
add_cflags "-I${SDK_PATH}/sources/android/cpufeatures"
fi
;;
......
......@@ -32,8 +32,30 @@ static int arm_cpu_env_mask(void)
return env && *env ? (int)strtol(env, NULL, 0) : ~0;
}
#if !CONFIG_RUNTIME_CPU_DETECT
#if defined(_MSC_VER)
int arm_cpu_caps(void)
{
int flags;
int mask;
if (!arm_cpu_env_flags(&flags))
{
return flags;
}
mask = arm_cpu_env_mask();
#if defined(HAVE_EDSP)
flags |= HAS_EDSP;
#endif
#if defined(HAVE_MEDIA)
flags |= HAS_MEDIA;
#endif
#if defined(HAVE_NEON)
flags |= HAS_NEON;
#endif
return flags & mask;
}
#elif defined(_MSC_VER)
/*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
......@@ -189,30 +211,7 @@ int arm_cpu_caps(void)
return flags & mask;
}
#endif // defined(__linux__)
#elif !CONFIG_RUNTIME_CPU_DETECT
int arm_cpu_caps(void)
{
int flags;
int mask;
if (!arm_cpu_env_flags(&flags))
{
return flags;
}
mask = arm_cpu_env_mask();
#if defined(HAVE_EDSP)
flags |= HAS_EDSP;
#endif
#if defined(HAVE_MEDIA)
flags |= HAS_MEDIA;
#endif
#if defined(HAVE_NEON)
flags |= HAS_NEON;
#endif
return flags & mask;
}
#else
#error "--enable-runtime-cpu-detect selected, but no CPU detection method " \
"available for your platform. Reconfigure without --enable-runtime-cpu-detect."
"available for your platform. Reconfigure with --disable-runtime-cpu-detect."
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment