Commit d05ec087 authored by fbarchard@google.com's avatar fbarchard@google.com

expose __cpuid for gcc/visual c compatibility

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

git-svn-id: http://libyuv.googlecode.com/svn/trunk@258 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent 0e081561
Name: libyuv
URL: http://code.google.com/p/libyuv/
Version: 256
Version: 258
License: BSD
License File: LICENSE
......
......@@ -11,6 +11,29 @@
#ifndef INCLUDE_LIBYUV_CPU_ID_H_
#define INCLUDE_LIBYUV_CPU_ID_H_
#ifdef _MSC_VER
#include <intrin.h> // For __cpuid()
#endif
// TODO(fbarchard): Use cpuid.h when gcc 4.4 is used on OSX and Linux.
#if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__)
static __inline void __cpuid(int cpu_info[4], int info_type) {
asm volatile (
"mov %%ebx, %%edi \n"
"cpuid \n"
"xchg %%edi, %%ebx \n"
: "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type));
}
#elif defined(__i386__) || defined(__x86_64__)
static __inline void __cpuid(int cpu_info[4], int info_type) {
asm volatile (
"cpuid \n"
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type));
}
#endif
#ifdef __cplusplus
namespace libyuv {
extern "C" {
......@@ -51,3 +74,4 @@ void MaskCpuFlags(int enable_flags);
#endif
#endif // INCLUDE_LIBYUV_CPU_ID_H_
......@@ -11,7 +11,7 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_
#define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 256
#define LIBYUV_VERSION 258
#endif // INCLUDE_LIBYUV_VERSION_H_
......@@ -11,9 +11,6 @@
#include "libyuv/cpu_id.h"
#include <stdlib.h> // For getenv()
#ifdef _MSC_VER
#include <intrin.h> // For __cpuid()
#endif
// For ArmCpuCaps() but unittested on all platforms
#include <stdio.h>
......@@ -21,25 +18,6 @@
#include "libyuv/basic_types.h" // For CPU_X86
// TODO(fbarchard): Use cpuid.h when gcc 4.4 is used on OSX and Linux.
#if (defined(__pic__) || defined(__APPLE__)) && defined(__i386__)
static __inline void __cpuid(int cpu_info[4], int info_type) {
asm volatile (
"mov %%ebx, %%edi \n"
"cpuid \n"
"xchg %%edi, %%ebx \n"
: "=a"(cpu_info[0]), "=D"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type));
}
#elif defined(__i386__) || defined(__x86_64__)
static __inline void __cpuid(int cpu_info[4], int info_type) {
asm volatile (
"cpuid \n"
: "=a"(cpu_info[0]), "=b"(cpu_info[1]), "=c"(cpu_info[2]), "=d"(cpu_info[3])
: "a"(info_type));
}
#endif
#ifdef __cplusplus
namespace libyuv {
extern "C" {
......
......@@ -23,26 +23,48 @@ TEST_F(libyuvTest, TestVersion) {
}
TEST_F(libyuvTest, TestCpuHas) {
#if LIBYUV_VERSION >= 236
int has_x86 = TestCpuFlag(kCpuHasX86);
printf("Has X86 %d\n", has_x86);
#endif
int has_sse2 = TestCpuFlag(kCpuHasSSE2);
printf("Has SSE2 %d\n", has_sse2);
int has_ssse3 = TestCpuFlag(kCpuHasSSSE3);
printf("Has SSSE3 %d\n", has_ssse3);
#if LIBYUV_VERSION >= 236
int has_sse41 = TestCpuFlag(kCpuHasSSE41);
printf("Has SSE4.1 %d\n", has_sse41);
#endif
#if LIBYUV_VERSION >= 238
int has_arm = TestCpuFlag(kCpuHasARM);
printf("Has ARM %d\n", has_arm);
#endif
int has_neon = TestCpuFlag(kCpuHasNEON);
printf("Has NEON %d\n", has_neon);
}
// Known Vendor IDs are:
// AuthenticAMD AMD processor
// CentaurHauls Centaur processor
// CyrixInstead Cyrix processor
// GenuineIntel Intel processor
// GenuineTMx86 Transmeta processor
// Geode by NSC National Semiconductor processor
// NexGenDriven NexGen processor
// RiseRiseRise Rise Technology processor
// SiS SiS SiS SiS processor
// UMC UMC UMC UMC processor
#if defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64)
TEST_F(libyuvTest, TestCpuId) {
int has_x86 = TestCpuFlag(kCpuHasX86);
if (has_x86) {
int cpu_info[4];
__cpuid(cpu_info, 0);
cpu_info[0] = cpu_info[1]; // Reorder output
cpu_info[1] = cpu_info[3];
cpu_info[2] = cpu_info[2];
cpu_info[3] = 0;
printf("Cpu Vendor: %s\n", reinterpret_cast<char*>(&cpu_info[0]));
EXPECT_EQ(12, strlen(reinterpret_cast<char*>(&cpu_info[0])));
}
}
#endif
// For testing purposes call the proc/cpuinfo parser directly
extern "C" int ArmCpuCaps(const char* cpuinfoname);
......
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