mirror of
https://chromium.googlesource.com/libyuv/libyuv
synced 2025-12-07 17:26:49 +08:00
The CpuId function is a wrapper for the intrinsic, or implemented with inline if unavailable. It had been using uint32, but the intrinsics use int, so it was causing casting and lint warnings. This change makes the internal implementation use int. Casting was also done for xgetbv, and the cast is simply removed, and is not causing a build error. MipCpuCaps was doing strlen to check for white space after the instruction set. Arm also does this but with a hard coded offset. This was causing a cast from size_t to int, which produced a lint warning. The change removes the white space detect. In theory the code could be used to detect SSE vs SSE2, and it would need to check SSE is followed by a space or end of line. But this code is only used on Arm and Mips, where there there is one form of SIMD detected. e.g. MSA for mips. If a new instruction set is added with a similar name, the write space check could be reintroduced. But its more likely the code can be rewritten to use a better form of detection by then. Or remove detection and require the instructions BUG=libyuv:641 TEST=try bots build on all platforms without error and lint is clean Change-Id: I9f55f8e57bba0f78571bdddbe63b945dea3e8809 Reviewed-on: https://chromium-review.googlesource.com/514524 Commit-Queue: Frank Barchard <fbarchard@google.com> Reviewed-by: Cheng Wang <wangcheng@google.com> Reviewed-by: Wan-Teh Chang <wtc@chromium.org>
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
/*
|
|
* Copyright 2011 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.
|
|
*/
|
|
|
|
#ifndef INCLUDE_LIBYUV_CPU_ID_H_
|
|
#define INCLUDE_LIBYUV_CPU_ID_H_
|
|
|
|
#include "libyuv/basic_types.h"
|
|
|
|
#ifdef __cplusplus
|
|
namespace libyuv {
|
|
extern "C" {
|
|
#endif
|
|
|
|
// Internal flag to indicate cpuid requires initialization.
|
|
static const int kCpuInitialized = 0x1;
|
|
|
|
// These flags are only valid on ARM processors.
|
|
static const int kCpuHasARM = 0x2;
|
|
static const int kCpuHasNEON = 0x4;
|
|
// 0x8 reserved for future ARM flag.
|
|
|
|
// These flags are only valid on x86 processors.
|
|
static const int kCpuHasX86 = 0x10;
|
|
static const int kCpuHasSSE2 = 0x20;
|
|
static const int kCpuHasSSSE3 = 0x40;
|
|
static const int kCpuHasSSE41 = 0x80;
|
|
static const int kCpuHasSSE42 = 0x100; // unused at this time.
|
|
static const int kCpuHasAVX = 0x200;
|
|
static const int kCpuHasAVX2 = 0x400;
|
|
static const int kCpuHasERMS = 0x800;
|
|
static const int kCpuHasFMA3 = 0x1000;
|
|
static const int kCpuHasAVX3 = 0x2000;
|
|
static const int kCpuHasF16C = 0x4000;
|
|
|
|
// 0x8000 reserved for future X86 flags.
|
|
|
|
// These flags are only valid on MIPS processors.
|
|
static const int kCpuHasMIPS = 0x10000;
|
|
static const int kCpuHasDSPR2 = 0x20000;
|
|
static const int kCpuHasMSA = 0x40000;
|
|
|
|
// Optional init function. TestCpuFlag does an auto-init.
|
|
// Returns cpu_info flags.
|
|
LIBYUV_API
|
|
int InitCpuFlags(void);
|
|
|
|
// Detect CPU has SSE2 etc.
|
|
// Test_flag parameter should be one of kCpuHas constants above.
|
|
// Returns non-zero if instruction set is detected
|
|
static __inline int TestCpuFlag(int test_flag) {
|
|
LIBYUV_API extern int cpu_info_;
|
|
#ifdef __ATOMIC_RELAXED
|
|
int cpu_info = __atomic_load_n(&cpu_info_, __ATOMIC_RELAXED);
|
|
#else
|
|
int cpu_info = cpu_info_;
|
|
#endif
|
|
return (!cpu_info ? InitCpuFlags() : cpu_info) & test_flag;
|
|
}
|
|
|
|
// Internal function for parsing /proc/cpuinfo.
|
|
LIBYUV_API
|
|
int ArmCpuCaps(const char* cpuinfo_name);
|
|
|
|
// For testing, allow CPU flags to be disabled.
|
|
// ie MaskCpuFlags(~kCpuHasSSSE3) to disable SSSE3.
|
|
// MaskCpuFlags(-1) to enable all cpu specific optimizations.
|
|
// MaskCpuFlags(1) to disable all cpu specific optimizations.
|
|
// MaskCpuFlags(0) to reset state so next call will auto init.
|
|
// Returns cpu_info flags.
|
|
LIBYUV_API
|
|
int MaskCpuFlags(int enable_flags);
|
|
|
|
// Low level cpuid for X86. Returns zeros on other CPUs.
|
|
// eax is the info type that you want.
|
|
// ecx is typically the cpu number, and should normally be zero.
|
|
LIBYUV_API
|
|
void CpuId(int eax, int ecx, int* cpu_info);
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
} // namespace libyuv
|
|
#endif
|
|
|
|
#endif // INCLUDE_LIBYUV_CPU_ID_H_
|