Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: third_party/zlib/x86.c

Issue 552123005: Integrate SIMD optimisations for zlib (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Singleton on Windows, add reference frame data from optimised version Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * x86 feature check
3 *
4 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 * Author:
6 * Jim Kukunas
7 *
8 * For conditions of distribution and use, see copyright notice in zlib.h
9 */
10
11 #include "x86.h"
12
13 int x86_cpu_enable_simd;
14
15 #ifndef _MSC_VER
16 #include <pthread.h>
17
18 pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT;
19 static void _x86_check_features(void);
20
21 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.
22 pthread_once(&cpu_check_inited_once, _x86_check_features);
23 }
24
25 static void _x86_check_features(void)
26 {
27 int x86_cpu_has_sse2;
28 int x86_cpu_has_sse42;
29 int x86_cpu_has_pclmulqdq;
30 unsigned eax, ebx, ecx, edx;
31
32 eax = 1;
33 __asm__ __volatile__ (
34 #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.
35 "xchg %%ebx, %1\n\t"
36 #endif
37 "cpuid\n\t"
38 #ifdef __i386__
39 "xchg %1, %%ebx\n\t"
40 : "+a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx)
41 #else
42 : "+a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
43 #endif
44 );
45
46 x86_cpu_has_sse2 = edx & 0x4000000;
47 x86_cpu_has_sse42 = ecx & 0x100000;
48 x86_cpu_has_pclmulqdq = ecx & 0x2;
49
50 x86_cpu_enable_simd = x86_cpu_has_sse2 &&
51 x86_cpu_has_sse42 &&
52 x86_cpu_has_pclmulqdq;
53 }
54 #else
55 #include <intrin.h>
56 #include <windows.h>
57
58 static BOOL CALLBACK _x86_check_features(PINIT_ONCE once, PVOID param, PVOID *co ntext);
59 static INIT_ONCE cpu_check_inited_once = INIT_ONCE_STATIC_INIT;
60
61 void x86_check_features(void)
62 {
63 #if (_WIN32_WINNT >= 0x0600)
64 InitOnceExecuteOnce(&cpu_check_inited_once, _x86_check_features, NULL, NULL);
65 #endif // (_WIN32_WINNT >= 0x0600)
agl 2014/10/17 00:45:35 ditto about two spaces.
robert.bradford 2014/10/20 16:45:54 Done.
66 }
67
68 #if (_WIN32_WINNT >= 0x0600)
69 static BOOL CALLBACK _x86_check_features(PINIT_ONCE once, PVOID param, PVOID *co ntext)
70 {
71 int x86_cpu_has_sse2;
72 int x86_cpu_has_sse42;
73 int x86_cpu_has_pclmulqdq;
74 int regs[4];
75
76 __cpuid(regs, 1);
77
78 x86_cpu_has_sse2 = regs[3] & 0x4000000;
79 x86_cpu_has_sse42= regs[2] & 0x100000;
80 x86_cpu_has_pclmulqdq = regs[2] & 0x2;
81
82 x86_cpu_enable_simd = x86_cpu_has_sse2 &&
83 x86_cpu_has_sse42 &&
84 x86_cpu_has_pclmulqdq;
85 return TRUE;
86 }
87 #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
88 #endif
agl 2014/10/17 00:45:35 #endif // _MSC_VER
robert.bradford 2014/10/20 16:45:54 Done.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698