Neon instructions detect without using NDK so it will work within Android, and on other linux arm based platforms and builds

BUG=none
TEST=none
Review URL: https://webrtc-codereview.appspot.com/358008

git-svn-id: http://libyuv.googlecode.com/svn/trunk@153 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
fbarchard@google.com 2012-01-26 02:14:52 +00:00
parent 0abb8dda2d
commit e3ebe7a5cd
8 changed files with 94 additions and 9 deletions

View File

@ -1,6 +1,6 @@
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 152
Version: 154
License: BSD
License File: LICENSE

View File

@ -16,7 +16,7 @@ namespace libyuv {
extern "C" {
#endif
#define LIBYUV_VERSION 152
#define LIBYUV_VERSION 153
#ifdef __cplusplus
} // extern "C"

View File

@ -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',

View File

@ -14,9 +14,10 @@
#ifdef _MSC_VER
#include <intrin.h> // For __cpuid()
#endif
#if defined(__ANDROID__) && defined(NDK_ROOT)
#include <cpu-features.h> // For android_getCpuFeatures()
#endif
// For ArmCpuCaps() but unittested on all platforms
#include <stdio.h>
#include <string.h>
#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

28
unit_test/cpu_test.cc Normal file
View File

@ -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 <stdlib.h>
#include <string.h>
#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

12
unit_test/testdata/arm_v7.txt vendored Normal file
View File

@ -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

23
unit_test/testdata/tegra3.txt vendored Normal file
View File

@ -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

View File

@ -35,6 +35,8 @@ static double get_time()
return double(t.QuadPart)/double(f.QuadPart);
}
#define random rand
#define srandom srand
#else
#include <sys/time.h>