diff options
author | Xinchen Hui <laruence@gmail.com> | 2018-02-10 17:37:38 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2018-02-10 17:38:30 +0800 |
commit | 08428cf6a77d360b52028d6ddfe1409218e391db (patch) | |
tree | 34c4db557c8353f08da3158320baaa75ed8bda0c /Zend/zend_cpuinfo.c | |
parent | 7ce72f0cf5c0b5bc458bee90698e19fb417d8b96 (diff) | |
download | php-git-08428cf6a77d360b52028d6ddfe1409218e391db.tar.gz |
Fixed cpuinfo in LLVM GCC & Added AVX2 detection
Seems it only defines __builtin_cpu_supports but no __builtin_cpu_init
(Apple LLVM version 9.0.0 (clang-900.0.38))
Diffstat (limited to 'Zend/zend_cpuinfo.c')
-rw-r--r-- | Zend/zend_cpuinfo.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/Zend/zend_cpuinfo.c b/Zend/zend_cpuinfo.c index 988ceb2521..43252a7cca 100644 --- a/Zend/zend_cpuinfo.c +++ b/Zend/zend_cpuinfo.c @@ -29,46 +29,53 @@ typedef struct _zend_cpu_info { static zend_cpu_info cpuinfo = {0}; #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -static void __zend_cpuid(uint32_t func, uint32_t subfunc) { +static void __zend_cpuid(uint32_t func, uint32_t subfunc, zend_cpu_info *cpuinfo) { __asm__ __volatile__ ( "cpuid" - : "=a"(cpuinfo.eax), "=b"(cpuinfo.ebx), "=c"(cpuinfo.ecx), "=d"(cpuinfo.edx) + : "=a"(cpuinfo->eax), "=b"(cpuinfo->ebx), "=c"(cpuinfo->ecx), "=d"(cpuinfo->edx) : "a"(func), "c"(subfunc) ); } #elif defined(ZEND_WIN32) # include <intrin.h> -static void __zend_cpuid(uint32_t func, uint32_t subfunc) { +static void __zend_cpuid(uint32_t func, uint32_t subfunc, zend_cpu_info *cpuinfo) { int regs[4]; __cpuidex(regs, func, subfunc); - cpuinfo.eax = regs[0]; - cpuinfo.ebx = regs[1]; - cpuinfo.ecx = regs[2]; - cpuinfo.edx = regs[3]; + cpuinfo->eax = regs[0]; + cpuinfo->ebx = regs[1]; + cpuinfo->ecx = regs[2]; + cpuinfo->edx = regs[3]; } #else -static void __zend_cpuid(uint32_t func, uint32_t subfunc) { - cpuinfo.eax = 0; +static void __zend_cpuid(uint32_t func, uint32_t subfunc, zend_cpu_info *cpuinfo) { + cpuinfo->eax = 0; } #endif void zend_cpu_startup(void) { if (!cpuinfo.initialized) { + zend_cpu_info ebx; + cpuinfo.initialized = 1; - __zend_cpuid(0, 0); + __zend_cpuid(0, 0, &cpuinfo); if (cpuinfo.eax == 0) { return; } - __zend_cpuid(1, 0); + __zend_cpuid(1, 0, &cpuinfo); + /* for avx2 */ + __zend_cpuid(7, 0, &ebx); + cpuinfo.ebx = ebx.ebx; } } ZEND_API int zend_cpu_supports(zend_cpu_feature feature) { if (feature & ZEND_CPU_EDX_MASK) { return (cpuinfo.edx & (feature & ~ZEND_CPU_EDX_MASK)); + } else if (feature & ZEND_CPU_EBX_MASK) { + return (cpuinfo.ebx & (feature & ~ZEND_CPU_EBX_MASK)); } else { return (cpuinfo.ecx & feature); } |