// Parts of this file derived from Chromium's base/cpu.cc.
namespace webrtc {
namespace {
uint32_t DetectNumberOfCoresHelper() {
int number_of_cores = 0;
#ifdefined(WEBRTC_WIN)
SYSTEM_INFO si;
GetNativeSystemInfo(&si);
number_of_cores = static_cast<int>(si.dwNumberOfProcessors); #elifdefined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) || defined(WEBRTC_BSD)
number_of_cores = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
if (number_of_cores <= 0) {
RTC_LOG(LS_ERROR) << "Failed to get number of cores";
number_of_cores = 1;
} #elifdefined(WEBRTC_MAC) || defined(WEBRTC_IOS)
int name[] = {CTL_HW, HW_AVAILCPU};
size_t size = sizeof(number_of_cores);
if (0 != sysctl(name, 2, &number_of_cores, &size, NULL, 0)) {
RTC_LOG(LS_ERROR) << "Failed to get number of cores";
number_of_cores = 1;
} #elifdefined(WEBRTC_FUCHSIA)
number_of_cores = zx_system_get_num_cpus(); #else
RTC_LOG(LS_ERROR) << "No function to get number of cores";
number_of_cores = 1; #endif
RTC_LOG(LS_INFO) << "Available number of cores: " << number_of_cores;
#ifdefined(WEBRTC_ENABLE_AVX2) // xgetbv returns the value of an Intel Extended Control Register (XCR). // Currently only XCR0 is defined by Intel so `xcr` should always be zero.
uint64_t xgetbv(uint32_t xcr) { #ifdefined(_MSC_VER) return _xgetbv(xcr); #else
uint32_t eax, edx;
uint32_t DetectNumberOfCores() { // Statically cache the number of system cores available since if the process // is running in a sandbox, we may only be able to read the value once (before // the sandbox is initialized) and not thereafter. // For more information see crbug.com/176522. staticconst uint32_t logical_cpus = DetectNumberOfCoresHelper(); return logical_cpus;
}
bool Supports(ISA instruction_set_architecture) { #ifdefined(WEBRTC_ARCH_X86_FAMILY)
int cpu_info[4];
__cpuid(cpu_info, 1);
if (instruction_set_architecture == ISA::kSSE2) { return0 != (cpu_info[3] & 0x04000000);
}
if (instruction_set_architecture == ISA::kSSE3) { return0 != (cpu_info[2] & 0x00000001);
} #ifdefined(WEBRTC_ENABLE_AVX2)
if (instruction_set_architecture == ISA::kAVX2) {
int cpu_info7[4];
__cpuid(cpu_info7, 0);
int num_ids = cpu_info7[0];
if (num_ids < 7) { return false;
} // Interpret CPU feature information.
__cpuid(cpu_info7, 7);
// AVX instructions can be used when // a) AVX are supported by the CPU, // b) XSAVE is supported by the CPU, // c) XSAVE is enabled by the kernel. // Compiling with MSVC and /arch:AVX2 surprisingly generates BMI2 // instructions (see crbug.com/1315519). return (cpu_info[2] & 0x10000000) != 0/* AVX */ &&
(cpu_info[2] & 0x04000000) != 0/* XSAVE */ &&
(cpu_info[2] & 0x08000000) != 0/* OSXSAVE */ &&
(xgetbv(0) & 0x00000006) == 6/* XSAVE enabled by kernel */ &&
(cpu_info7[1] & 0x00000020) != 0/* AVX2 */ &&
(cpu_info7[1] & 0x00000100) != 0/* BMI2 */;
} #endif// WEBRTC_ENABLE_AVX2
if (instruction_set_architecture == ISA::kFMA3) { return0 != (cpu_info[2] & 0x00001000);
} #elifdefined(WEBRTC_ARCH_ARM_FAMILY)
if (instruction_set_architecture == ISA::kNeon) { #ifdefined(WEBRTC_ANDROID) #ifdefined(WEBRTC_MOZILLA_BUILD) // We should revisit this if Supports(...) is ever more widely used. // Currently, it is used in unittests and when WEBRTC_ARCH_X86_FAMILY // is defined in non-unittest code. return false; #else return0 != (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON); #endif #elifdefined(WEBRTC_BSD) // OpenBSD does not have getauxval() and does not have /proc reading return false; #elifdefined(WEBRTC_LINUX)
uint64_t hwcap = 0;
hwcap = getauxval(AT_HWCAP); #ifdefined(__aarch64__)
if ((hwcap & HWCAP_ASIMD) != 0) { returntrue;
} #else
if ((hwcap & HWCAP_NEON) != 0) { returntrue;
} #endif #endif// WEBRTC_LINUX
} #else
RTC_UNUSED(instruction_set_architecture); #endif// WEBRTC_ARCH_ARM_FAMILY return false;
}
} // namespace cpu_info
} // namespace webrtc
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-08-27)
¤
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.