Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 | |
|
agl
2014/09/26 18:32:27
delete line.
robert.bradford
2014/10/15 16:14:40
Done.
| |
| 11 | |
| 12 #include "x86.h" | |
| 13 | |
| 14 #include <pthread.h> | |
|
agl
2014/09/26 18:32:27
This file is always built, but includes pthread.h.
robert.bradford
2014/10/15 16:14:40
Works on Mac OS X, for Windows we now have a Win32
| |
| 15 | |
| 16 int x86_cpu_enable_simd; | |
| 17 | |
| 18 #ifdef HAVE_ARCH_INTEL | |
| 19 pthread_once_t cpu_check_inited_once = PTHREAD_ONCE_INIT; | |
| 20 static void _x86_check_features(void); | |
| 21 | |
| 22 void x86_check_features(void) { | |
| 23 pthread_once(&cpu_check_inited_once, _x86_check_features); | |
| 24 } | |
| 25 | |
| 26 static void _x86_check_features(void) | |
| 27 { | |
| 28 int x86_cpu_has_sse2; | |
| 29 int x86_cpu_has_sse42; | |
| 30 int x86_cpu_has_pclmulqdq; | |
| 31 unsigned eax, ebx, ecx, edx; | |
| 32 | |
| 33 eax = 1; | |
| 34 __asm__ __volatile__ ( | |
| 35 #ifdef __i386__ | |
| 36 "xchg %%ebx, %1\n\t" | |
| 37 #endif | |
| 38 "cpuid\n\t" | |
| 39 #ifdef __i386__ | |
| 40 "xchg %1, %%ebx\n\t" | |
| 41 : "+a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx) | |
| 42 #else | |
| 43 : "+a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) | |
| 44 #endif | |
| 45 ); | |
| 46 | |
| 47 x86_cpu_has_sse2 = edx & 0x4000000; | |
| 48 x86_cpu_has_sse42 = ecx & 0x100000; | |
| 49 x86_cpu_has_pclmulqdq = ecx & 0x2; | |
| 50 | |
| 51 x86_cpu_enable_simd = x86_cpu_has_sse2 && | |
| 52 x86_cpu_has_sse42 && | |
| 53 x86_cpu_has_pclmulqdq; | |
| 54 } | |
| 55 #else | |
| 56 void x86_check_features(void) {} | |
| 57 #endif /* HAVE_ARCH_INTEL */ | |
| OLD | NEW |