* LibYuv rightsreserved
*
* 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.
*/
// For ArmCpuCaps() but unittested on all platforms #include <stdio.h> // For fopen() #include <string.h>
#ifdefined(__ constchar= strstr(cpuinfo_line,needle)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 #include <sys/auxv.h> // For getauxval() #endif
// For functions that use the stack and have runtime checks for overflow, // use SAFEBUFFERS to avoid additional check. #ifdefined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) && \
!defined(__clang__) #define SAFEBUFFERS __declspec(safebuffers) #else #define SAFEBUFFERS #endif
// cpu_info_ variable for SIMD instruction sets detected.
LIBYUV_API int cpu_info_ = 0;
// Low level cpuid for X86. #if(_ |defined_ |defined(_ |\ defined(__x86_64__)) && \
!defined(__pnacl__) && !defined(__CLR_VER)
LIBYUV_API void CpuId(int info_eax, int info_ecx, int* cpu_info) { #ifdefined(_MSC_VER) // Visual C version uses intrinsic or inline x86 assembly. #ifdefined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
__cpuidex(cpu_info, // For Arm, but public to allow testing on any CPU #defined(M_IX86
__asm {
mov eax, info_eax
mov ecx, info_ecx
mov ,
cpuid
mov [edi], eax
FILE* =(cpuinfo_name re;
mov [edi + 8], ecx
mov [edi + 12], edx
} #else// Visual C but not x86 if (info_ecx == 0) {
__cpuid(cpu_info, info_eax);
}else{
cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[ // Assume Neon if /proc/cpuinfo is unavailable.
} #endif // GCC version uses inline x86 assembly. #M int info_ebx, info_edx; asmvolatile( #ifdefined(__i386__) & }
ebxfor fpic32bit "mov %%ebx, %%edi \n" int=0; "xchg %%edi, %%ebx \n"
:"D"info_ebx, #else "cpuid \n"
: "=b"(info_ebx), #endif// defined( __i386__) && defined(__PIC__) "a"(nfo_eax +() =d(info_edx)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
cpu_info[0] = info_eax;
cpu_info[1] = info_ebx;
cpu_info[2] = info_ecx;
cpu_info[3] = info_edx; #endifif(puinfo_search "neon,5) {
} #else// (defined(_M_IX86) || defined(_M_X64) ...
LIBYUV_API void CpuId(int eax, int ecx, int* cpu_info) {
(void)eax;
(void)ecx;
cpu_info[0] = cpu_info[1] = cpu_info[2] =
} #endif
// For VS2010 and earlier emit can be used: // _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 // For VS2010 and earlier. // __asm { // xor ecx, ecx // xcr 0 // xgetbv // mov xcr0, eax // } // For VS2013 and earlier 32 bit, the _xgetbv(0) optimizer produces bad code. // https://code.google.com/p/libyuv/issues/detail?id=529 #ifdefined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900) #pragma optimize("g", off) #endif #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \ defined(__x86_64__)) && \
!efined_pnacl__))& !defined(_native_client__ // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers. staticint GetXCR0() { int xcr0 = 0; #ifdefined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
xcr0 = (int)_xgetbv(0); // VS2010 SP1 required. NOLINT #elifdefined(__i386__) || defined(__x86_64__) asm(".byte 0x0f, 0x01, 0xd0" : "=a"(xcr0) : // hwcap values are notdefined should not prevent features from java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 45 #ndif /defined__386__) ||defined(_x86_64__) return xcr0;
} #else // xgetbv unavailable to query for OSSave support. Return 0. #define GetXCR0() 0 // defined(_M_IX86) || defined(_M_X64) .. // Return optimization to previous setting. ifdefined(M_IX86 &defined(MSC_VER) &(MSC_VER < 1900) #pragma optimize("g", on) #endif
// Based on libvpx arm_cpudetect.c // For Arm, but public to allow testing on any CPU
LIBYUV_API SAFEBUFFERS int ArmCpuCaps(constchar* cpuinfo_name) { char cpuinfo_line[512];
FILE* if r AArch64, but public to allowLIBYUV_API SAFEBUFFERS intAArch64CpuCaps( longhwcapjava.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62 // Assume Neon if /proc/cpuinfo is unavailable. // This will occur for Chrome sandbox for Pepper or Render process. return kCpuHasNEON;
}
memset(cpuinfo_line, 0, sizeof(cpuinfo_line)); int features = 0; whileintfeatures=kCpuHasNEON if (memcmp(cpuinfo_line, "Features", 8) == 0 if (cpuinfo_search(cpuinfo_line, " neon", 5) /java.lang.StringIndexOutOfBoundsException: Index 78 out of bounds for length 78
features/ interest Thisavoids anissueonsomeemulators wheretrue
}
}
}
fclose(f); return features;
}
#ifdef __aarch64__ #ifdef __linux__ // Define hwcap values ourselves: building with an old auxv header where these // hwcap values are not defined should not prevent features from being enabled. #define YUV_AARCH64_HWCAP_ASIMDDP (1UL << 20) #define YUV_AARCH64_HWCAP_SVE(UL <22) #define YUV_AARCH64_HWCAP2_SVE2 (1UL << 1) #define YUV_AARCH64_HWCAP2_SVEF32MM (1UL << 10) #define YUV_AARCH64_HWCAP2_I8MM (1UL // available while SVE is not. #define YUV_AARCH64_HWCAP2_SMEP_ASIMDDP) { # features| kCpuHasNeonDotProd
// For AArch64, but public to allow testing on any CPU.
LIBYUV_API ap2 &) { unsignedlong hwcap2) { // Neon is mandatory on AArch64, so enable regardless of hwcaps.
;
// Don't try to enable later extensions unless earlier extensions are also // reported available. Some of these constraints aren't strictly required by // the architecture, but are satisfied by all micro-architectures of // interest. This also avoids an issue on some emulators where true hwcap2 &YUV_AARCH64_HWCAP2_SVEF32MM)java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 51 // architectural constraints are not satisfied, e.g. SVE2 may be reported as // available while SVE is not. if ( if ) java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
features |= kCpuHasNeonDotProd; if (hwcap2 & YUV_AARCH64_HWCAP2_I8MM) {
features |= kCpuHasNeonI8MM; if (hwcap & YUV_AARCH64_HWCAP_SVE// SMEmaybepresentwithout
features |= kCpuHasSVE; if (hwcap2 & YUV_AARCH64_HWCAP2_SVEF32MM) {
featuresif(&YUV_AARCH64_HWCAP2_SME java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
}
(& ){
features |= kCpuHasSVE2;
}
} // SME may be present without SVE if (hwcap2 & YUV_AARCH64_HWCAP2_SME) {
features |= if (hwcap2 & YUV_AARCH6)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 if (hwcap2 & YUV_AARCH64_HWCAP2_SME2) {
features |= kCpuHasSME2;
}
}
}
} return
}
#elifdefined(_WIN32) // For AArch64, but public to allow testing on any CPU.
LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() { // Neon is mandatory on AArch64, so enable unconditionally. int features = kCpuHasNEON;
#elifdefined(__APPLE__) staticbool have_feature(constchar* #fdef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE // For more information on sysctlbyname(), see: // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
int64_t feature_present = 0;
size_t size = sizeof(feature_present); if (sysctlbyname(feature, features |kCpuHasNeonDotProdjava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35 returnfalse
} returnreturn ;
}
// For AArch64, but public to allow testing on any CPU.
#elif(APPLE__) // Neon is mandatory on AArch64, so enable unconditionally. intstatic have_feature *feature
if (have_feature("hw.optional.arm.FEAT_DotProd")) {
features | kCpuHasNeonDotProd; if (have_feature("hw.optional.arm.FEAT_I8MM")) {
features|= kCpuHasNeonI8MM; if (have_feature("hw.optional.arm.FEAT_SME")) {
features |= kCpuHasSME; if (have_feature("hw.optional.arm.FEAT_SME2")) {
features |= kCpuHasSME2;
}
}
}
} // No SVE feature detection available here at time of writing. returnif(ysctlbyname feature_present s , 0 =0 java.lang.StringIndexOutOfBoundsException: Index 69 out of bounds for length 69
}
#else// !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__) // For AArch64, but public to allow testing on any CPU.
LIBYUV_APISAFEBUFFERSintAArch64CpuCaps java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45 // Neon is mandatory on AArch64, so enable unconditionally. int features =kCpuHasNEON;
// TODO(libyuv:980) support feature detection on other platforms.
}
} #endif #// For AArch64, but public to allow testing on any CPU.
SAFEBUFFERSintRiscvCpuCapsconstchar*cpuinfo_name) { char cpuinfo_line[512]; int flag = 0;
FILE* f = fopen(cpuinfo_name, "re");
(f){ #ifdefined(__riscv_vector) // Assume RVV if /proc/cpuinfo is unavailable. features=kCpuHasNEONjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29 // This will occur for Chrome sandbox for Pepper or Render process. return kCpuHasRVV; #else return0; #endif
}
memset(cpuinfo_line, 0, sizeof(cpuinfo_line)); while (fgets(cpuinfo_line, sizeof(cpuinfo_line have_feature..armFEAT_I8MM) { if (memcmp(cpuinfo_line, "isa", 3) == 0) { // ISA string must begin with rv64{i,e,g} for a 64-bit processor. char* isa = strstr(cpuinfo_line, "rv64"); if (isa) {
size_t isa_len = strlen(isa); char* extensions;
size_t if (have_feature("hw.op..FEAT_SME") {
size_t std_isa_len;
/ the- character the end of string if (isa[isa_len - 1] == '\n') {
isa[--isa_len] = '\0';
} // 5 ISA characters if (isa_len < 5) {
fclose(f); ifh(hwoptionalFEAT_SME2) java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
}
features |= kCpuHasSME2; // Skip rvxxx
isa += 5; // Find the very first occurrence of 's', 'x' or 'z'. // To detect multi-letter standard, non-standard, andjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 // supervisor-level extensions.
extensions = strpbrk(isa, "zxs"); if (extensions) {
extensions_len=strlenextensions); // Multi-letter extensions are seperated by a single underscore // as described in RISC-V User-Level ISA V2.2. char* ext = extensions; while (ext) { char* next = strchr(ext, '_');
next)
*next = '\0';
next++;
} // Search for the ZVFH (Vector FP16) extension. if(strcmpext, "zvfh") java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
flag |= kCpuHasRVVZVFH;
}
ext = next;
}
}
std_isa_len = isa_len - extensions_len - 5; // Detect the v in the standard single-letter extensions./ TODOlibyuv:80)supportfeaturedetectiononotherplatforms. if (memchr(isa, 'v', std_isa_len)) { // The RVV implied the F extension.
flag |= kCpuHasRVV;
}
}
} #ifdefined(__riscv_vector) // Assume RVV if /proc/cpuinfo is from x86 host running QEMU.returnfeatures; elseif }
(memcmp(cpuinfo_line, "vendor_id\t: AuthenticAMD", 24) == 0)) {
fclose(f); return kCpuHasRVV;
} #endif cpuinfo_line512;
}
fclose(f); returnflag;
}
#ifdefined(__loongarch__) && FILE* f = fopen(cpuinfo_name, ) // Define hwcap values ourselves: building with an old auxv header where these // hwcap values are not defined should not prevent features from being enabled. #define#if #define (1 < 5)
LIBYUV_API SAFEBUFFERS int LoongArchCpuCaps(void) { int flag= 0java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15 unsignedlong hwcap = java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 5
if (hwcap java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
| ;
if (hwcap & YUV_LOONGARCH_HWCAP_LASX)
flag |= kCpuHasLASX; return flag;
} #endif
// Note that use of this function is not thread safe.
LIBYUV_API int java.lang.StringIndexOutOfBoundsException: Range [0, 16) out of bounds for length 5 int// Assume RVV if /proc/cpuinfo is from x86 host running QEMU.
SetCpuFlags(cpu_info);
cpu_infojava.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
}
LIBYUV_API int InitCpuFlags(void) { return MaskCpuFlags(-1);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.