diff --git a/README.chromium b/README.chromium index 8ce85d3e4..d2c2cf73f 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 152 +Version: 154 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index f4341ae4f..b72cd10ae 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -16,7 +16,7 @@ namespace libyuv { extern "C" { #endif -#define LIBYUV_VERSION 152 +#define LIBYUV_VERSION 153 #ifdef __cplusplus } // extern "C" diff --git a/libyuv_test.gyp b/libyuv_test.gyp index 10df57b10..52e11fdc1 100644 --- a/libyuv_test.gyp +++ b/libyuv_test.gyp @@ -23,6 +23,7 @@ # sources 'unit_test/compare_test.cc', + 'unit_test/cpu_test.cc', 'unit_test/planar_test.cc', 'unit_test/rotate_test.cc', 'unit_test/scale_test.cc', diff --git a/source/cpu_id.cc b/source/cpu_id.cc index 252b7acc7..85218330d 100644 --- a/source/cpu_id.cc +++ b/source/cpu_id.cc @@ -14,9 +14,10 @@ #ifdef _MSC_VER #include // For __cpuid() #endif -#if defined(__ANDROID__) && defined(NDK_ROOT) -#include // For android_getCpuFeatures() -#endif + +// For ArmCpuCaps() but unittested on all platforms +#include +#include #include "libyuv/basic_types.h" // For CPU_X86 @@ -46,6 +47,26 @@ namespace libyuv { extern "C" { #endif +// based on libvpx arm_cpudetect.c +int ArmCpuCaps(const char* cpuinfoname) { + int flags = 0; + FILE* fin = fopen(cpuinfoname, "r"); + if (fin) { + char buf[512]; + while (fgets(buf, 511, fin)) { + if (memcmp(buf, "Features", 8) == 0) { + char* p = strstr(buf, " neon"); + if (p && (p[5] == ' ' || p[5] == '\n')) { + flags |= kCpuHasNEON; + break; + } + } + } + fclose(fin); + } + return flags; +} + // CPU detect function for SIMD instruction sets. int cpu_info_ = 0; @@ -65,10 +86,8 @@ int InitCpuFlags() { if (getenv("LIBYUV_DISABLE_SSSE3")) { cpu_info_ &= ~kCpuHasSSSE3; } -#elif defined(__ANDROID__) && defined(__ARM_NEON__) && defined(NDK_ROOT) - uint64_t features = android_getCpuFeatures(); - cpu_info_ = ((features & ANDROID_CPU_ARM_FEATURE_NEON) ? kCpuHasNEON : 0) | - kCpuInitialized; +#elif if defined(__linux__) && defined(__ARM_NEON__) + cpu_info_ = ArmCpuCaps("/proc/cpuinfo") | kCpuInitialized; #elif defined(__ARM_NEON__) // gcc -mfpu=neon defines __ARM_NEON__ // Enable Neon if you want support for Neon and Arm, and use MaskCpuFlags diff --git a/unit_test/cpu_test.cc b/unit_test/cpu_test.cc new file mode 100644 index 000000000..66bae8aa8 --- /dev/null +++ b/unit_test/cpu_test.cc @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2012 The LibYuv project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "unit_test.h" + +#include +#include + +#include "libyuv/basic_types.h" +#include "libyuv/cpu_id.h" + +namespace libyuv { + +extern "C" int ArmCpuCaps(const char* cpuinfoname); + +TEST_F(libyuvTest, TestLinuxNeon) { + EXPECT_EQ(0,ArmCpuCaps("testdata/arm_v7.txt")); + EXPECT_NE(kCpuHasNEON,ArmCpuCaps("testdata/tegra3.txt")); +} + +} // namespace libyuv diff --git a/unit_test/testdata/arm_v7.txt b/unit_test/testdata/arm_v7.txt new file mode 100644 index 000000000..5d7dbd048 --- /dev/null +++ b/unit_test/testdata/arm_v7.txt @@ -0,0 +1,12 @@ +Processor : ARMv7 Processor rev 5 (v7l) +BogoMIPS : 795.44 +Features : swp half thumb fastmult vfp edsp iwmmxt thumbee vfpv3 vfpv3d16 +CPU implementer : 0x56 +CPU architecture: 7 +CPU variant : 0x0 +CPU part : 0x581 +CPU revision : 5 + +Hardware : OLPC XO-1.75 +Revision : 0000 +Serial : 0000000000000000 diff --git a/unit_test/testdata/tegra3.txt b/unit_test/testdata/tegra3.txt new file mode 100644 index 000000000..d1b09f6b7 --- /dev/null +++ b/unit_test/testdata/tegra3.txt @@ -0,0 +1,23 @@ +Processor : ARMv7 Processor rev 9 (v7l) +processor : 0 +BogoMIPS : 1992.29 + +processor : 1 +BogoMIPS : 1992.29 + +processor : 2 +BogoMIPS : 1992.29 + +processor : 3 +BogoMIPS : 1992.29 + +Features : swp half thumb fastmult vfp edsp neon vfpv3 +CPU implementer : 0×41 +CPU architecture: 7 +CPU variant : 0×2 +CPU part : 0xc09 +CPU revision : 9 + +Hardware : cardhu +Revision : 0000 + diff --git a/unit_test/unit_test.h b/unit_test/unit_test.h index 603499c2d..8b082a1fe 100644 --- a/unit_test/unit_test.h +++ b/unit_test/unit_test.h @@ -35,6 +35,8 @@ static double get_time() return double(t.QuadPart)/double(f.QuadPart); } +#define random rand +#define srandom srand #else #include