diff options
author | Frank Barchard <fbarchard@google.com> | 2017-05-24 15:00:24 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2017-05-24 22:27:03 +0000 |
commit | 8edd2286fdf9df2b9da806bda7ed262492f95921 (patch) | |
tree | 882a8c6572b1479af681d8c215659deb65461399 /source/cpu_id.cc | |
parent | 651ccc0c3a3f507b8ab0895e4ba018b9a6dedbfa (diff) | |
download | libyuv-8edd2286fdf9df2b9da806bda7ed262492f95921.tar.gz |
MaskCpuFlags return cpuinfo so InitCpuFlags can call it
Reduce number of atomic references to cpu_info by making
InitCpuFlags call MaskCpuFlags and return the same value.
BUG=libyuv:641
TEST=libyuv_unittests pass
Change-Id: I5dfff8f7a10671bc8ef3ec0ed6f302791e752faa
Reviewed-on: https://chromium-review.googlesource.com/514145
Commit-Queue: Frank Barchard <fbarchard@google.com>
Reviewed-by: Cheng Wang <wangcheng@google.com>
Diffstat (limited to 'source/cpu_id.cc')
-rw-r--r-- | source/cpu_id.cc | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/source/cpu_id.cc b/source/cpu_id.cc index 04403967..b3eef701 100644 --- a/source/cpu_id.cc +++ b/source/cpu_id.cc @@ -46,6 +46,7 @@ extern "C" { // cpu_info_ variable for SIMD instruction sets detected. LIBYUV_API int cpu_info_ = 0; +// TODO(fbarchard): Consider using int for cpuid so casting is not needed. // Low level cpuid for X86. #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \ defined(__x86_64__)) && \ @@ -55,7 +56,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { #if defined(_MSC_VER) // Visual C version uses intrinsic or inline x86 assembly. #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) - __cpuidex((int*)(cpu_info), info_eax, info_ecx); + __cpuidex((int*)(cpu_info), info_eax, info_ecx); // NOLINT #elif defined(_M_IX86) __asm { mov eax, info_eax @@ -69,7 +70,7 @@ void CpuId(uint32 info_eax, uint32 info_ecx, uint32* cpu_info) { } #else // Visual C but not x86 if (info_ecx == 0) { - __cpuid((int*)(cpu_info), info_eax); + __cpuid((int*)(cpu_info), info_eax); // NOLINT } else { cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0u; } @@ -122,8 +123,9 @@ void CpuId(uint32 eax, uint32 ecx, uint32* cpu_info) { // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. int GetXCR0() { uint32 xcr0 = 0u; +// VS2010 SP1 required #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) - xcr0 = (uint32)(_xgetbv(0)); // VS2010 SP1 required. + xcr0 = (uint32)(_xgetbv(0)); // NOLINT #elif defined(__i386__) || defined(__x86_64__) asm(".byte 0x0f, 0x01, 0xd0" : "=a"(xcr0) : "c"(0) : "%edx"); #endif // defined(__i386__) || defined(__x86_64__) @@ -170,7 +172,7 @@ LIBYUV_API SAFEBUFFERS int ArmCpuCaps(const char* cpuinfo_name) { LIBYUV_API SAFEBUFFERS int MipsCpuCaps(const char* cpuinfo_name, const char ase[]) { char cpuinfo_line[512]; - int len = (int)strlen(ase); + int len = (int)strlen(ase); // NOLINT FILE* f = fopen(cpuinfo_name, "r"); if (!f) { // ase enabled if /proc/cpuinfo is unavailable. @@ -325,22 +327,19 @@ static SAFEBUFFERS int GetCpuFlags(void) { // Note that use of this function is not thread safe. LIBYUV_API -void MaskCpuFlags(int enable_flags) { +int MaskCpuFlags(int enable_flags) { + int cpu_info = GetCpuFlags() & enable_flags; #ifdef __ATOMIC_RELAXED - __atomic_store_n(&cpu_info_, GetCpuFlags() & enable_flags, __ATOMIC_RELAXED); + __atomic_store_n(&cpu_info_, cpu_info, __ATOMIC_RELAXED); #else - cpu_info_ = GetCpuFlags() & enable_flags; + cpu_info_ = cpu_info; #endif + return cpu_info; } LIBYUV_API int InitCpuFlags(void) { - MaskCpuFlags(-1); -#ifdef __ATOMIC_RELAXED - return __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED); -#else - return cpu_info_; -#endif + return MaskCpuFlags(-1); } #ifdef __cplusplus |