chromium/third_party/libyuv/include/libyuv/cpu_id.h

/*
 *  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 =;

// These flags are only valid on Arm processors.
static const int kCpuHasARM =;
static const int kCpuHasNEON =;
// Leave a gap to avoid setting kCpuHasX86.
static const int kCpuHasNeonDotProd =;
static const int kCpuHasNeonI8MM =;
static const int kCpuHasSVE =;
static const int kCpuHasSVE2 =;
static const int kCpuHasSME =;

// These flags are only valid on x86 processors.
static const int kCpuHasX86 =;
static const int kCpuHasSSE2 =;
static const int kCpuHasSSSE3 =;
static const int kCpuHasSSE41 =;
static const int kCpuHasSSE42 =;
static const int kCpuHasAVX =;
static const int kCpuHasAVX2 =;
static const int kCpuHasERMS =;
static const int kCpuHasFMA3 =;
static const int kCpuHasF16C =;
static const int kCpuHasAVX512BW =;
static const int kCpuHasAVX512VL =;
static const int kCpuHasAVX512VNNI =;
static const int kCpuHasAVX512VBMI =;
static const int kCpuHasAVX512VBMI2 =;
static const int kCpuHasAVX512VBITALG =;
static const int kCpuHasAVX10 =;
static const int kCpuHasAVXVNNI =;
static const int kCpuHasAVXVNNIINT8 =;
static const int kCpuHasAMXINT8 =;

// These flags are only valid on MIPS processors.
static const int kCpuHasMIPS =;
static const int kCpuHasMSA =;

// These flags are only valid on LOONGARCH processors.
static const int kCpuHasLOONGARCH =;
static const int kCpuHasLSX =;
static const int kCpuHasLASX =;

// These flags are only valid on RISCV processors.
static const int kCpuHasRISCV =;
static const int kCpuHasRVV =;
static const int kCpuHasRVVZVFH =;

// 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) {}

// Internal function for parsing /proc/cpuinfo.
LIBYUV_API
int ArmCpuCaps(const char* cpuinfo_name);
LIBYUV_API
int MipsCpuCaps(const char* cpuinfo_name);
LIBYUV_API
int RiscvCpuCaps(const char* cpuinfo_name);

#ifdef __linux__
// On Linux, parse AArch64 features from getauxval(AT_HWCAP{,2}).
LIBYUV_API
int AArch64CpuCaps(unsigned long hwcap, unsigned long hwcap2);
#else
LIBYUV_API
int AArch64CpuCaps();
#endif

// 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);

// Sets the CPU flags to |cpu_flags|, bypassing the detection code. |cpu_flags|
// should be a valid combination of the kCpuHas constants above and include
// kCpuInitialized. Use this method when running in a sandboxed process where
// the detection code might fail (as it might access /proc/cpuinfo). In such
// cases the cpu_info can be obtained from a non sandboxed process by calling
// InitCpuFlags() and passed to the sandboxed process (via command line
// parameters, IPC...) which can then call this method to initialize the CPU
// flags.
// Notes:
// - when specifying 0 for |cpu_flags|, the auto initialization is enabled
//   again.
// - enabling CPU features that are not supported by the CPU will result in
//   undefined behavior.
// TODO(fbarchard): consider writing a helper function that translates from
// other library CPU info to libyuv CPU info and add a .md doc that explains
// CPU detection.
static __inline void SetCpuFlags(int cpu_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 info_eax, int info_ecx, int* cpu_info);

#ifdef __cplusplus
}  // extern "C"
}  // namespace libyuv
#endif

#endif  // INCLUDE_LIBYUV_CPU_ID_H_