Chromium Code Reviews| Index: third_party/zlib/x86.c |
| diff --git a/third_party/zlib/x86.c b/third_party/zlib/x86.c |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3593d5d6929b575d00719a71a003880a24b27106 |
| --- /dev/null |
| +++ b/third_party/zlib/x86.c |
| @@ -0,0 +1,88 @@ |
| +/* |
| + * x86 feature check |
| + * |
| + * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| + * Author: |
| + * Jim Kukunas |
| + * |
| + * For conditions of distribution and use, see copyright notice in zlib.h |
| + */ |
| + |
| +#include "x86.h" |
| + |
| +int x86_cpu_enable_simd; |
| + |
| +#ifndef _MSC_VER |
| +#include <pthread.h> |
| + |
| +pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT; |
| +static void _x86_check_features(void); |
| + |
| +void x86_check_features(void) { |
|
agl
2014/10/17 00:45:35
you've switched brace style and indentation here.
robert.bradford
2014/10/20 16:45:54
Done.
|
| + pthread_once(&cpu_check_inited_once, _x86_check_features); |
| +} |
| + |
| +static void _x86_check_features(void) |
| +{ |
| + int x86_cpu_has_sse2; |
| + int x86_cpu_has_sse42; |
| + int x86_cpu_has_pclmulqdq; |
| + unsigned eax, ebx, ecx, edx; |
| + |
| + eax = 1; |
| + __asm__ __volatile__ ( |
| +#ifdef __i386__ |
|
agl
2014/10/17 00:45:34
I think it would be better to suffer a little dupl
robert.bradford
2014/10/20 16:45:54
Done.
|
| + "xchg %%ebx, %1\n\t" |
| +#endif |
| + "cpuid\n\t" |
| +#ifdef __i386__ |
| + "xchg %1, %%ebx\n\t" |
| + : "+a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx) |
| +#else |
| + : "+a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) |
| +#endif |
| + ); |
| + |
| + x86_cpu_has_sse2 = edx & 0x4000000; |
| + x86_cpu_has_sse42 = ecx & 0x100000; |
| + x86_cpu_has_pclmulqdq = ecx & 0x2; |
| + |
| + x86_cpu_enable_simd = x86_cpu_has_sse2 && |
| + x86_cpu_has_sse42 && |
| + x86_cpu_has_pclmulqdq; |
| +} |
| +#else |
| +#include <intrin.h> |
| +#include <windows.h> |
| + |
| +static BOOL CALLBACK _x86_check_features(PINIT_ONCE once, PVOID param, PVOID *context); |
| +static INIT_ONCE cpu_check_inited_once = INIT_ONCE_STATIC_INIT; |
| + |
| +void x86_check_features(void) |
| +{ |
| +#if (_WIN32_WINNT >= 0x0600) |
| + InitOnceExecuteOnce(&cpu_check_inited_once, _x86_check_features, NULL, NULL); |
| +#endif // (_WIN32_WINNT >= 0x0600) |
|
agl
2014/10/17 00:45:35
ditto about two spaces.
robert.bradford
2014/10/20 16:45:54
Done.
|
| +} |
| + |
| +#if (_WIN32_WINNT >= 0x0600) |
| +static BOOL CALLBACK _x86_check_features(PINIT_ONCE once, PVOID param, PVOID *context) |
| +{ |
| + int x86_cpu_has_sse2; |
| + int x86_cpu_has_sse42; |
| + int x86_cpu_has_pclmulqdq; |
| + int regs[4]; |
| + |
| + __cpuid(regs, 1); |
| + |
| + x86_cpu_has_sse2 = regs[3] & 0x4000000; |
| + x86_cpu_has_sse42= regs[2] & 0x100000; |
| + x86_cpu_has_pclmulqdq = regs[2] & 0x2; |
| + |
| + x86_cpu_enable_simd = x86_cpu_has_sse2 && |
| + x86_cpu_has_sse42 && |
| + x86_cpu_has_pclmulqdq; |
| + return TRUE; |
| +} |
| +#endif // (_WIN32_WINNT >= 0x0600) |
|
agl
2014/10/17 00:45:35
nit: two spaces before "//"
Also, does VC++ accep
robert.bradford
2014/10/20 16:45:54
Well I did build it with the windows toolchain. Bu
|
| +#endif |
|
agl
2014/10/17 00:45:35
#endif // _MSC_VER
robert.bradford
2014/10/20 16:45:54
Done.
|