| 1 |
/* |
| 2 |
Copyright(c) 2002-2017 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com) |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
|
| 16 |
For more information please visit: http://bitmagic.io |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "libbmcpuid.h" |
| 20 |
#ifdef _MSC_VER |
| 21 |
#include <intrin.h> |
| 22 |
#endif |
| 23 |
|
| 24 |
// ------------------------------------------------------------------- |
| 25 |
// |
| 26 |
// code credit for CPU caps identification: |
| 27 |
// https://attractivechaos.wordpress.com/2017/09/04/on-cpu-dispatch/ |
| 28 |
// |
| 29 |
// ------------------------------------------------------------------- |
| 30 |
|
| 31 |
unsigned BM_x86_simd(void) |
| 32 |
{ |
| 33 |
unsigned eax, ebx, ecx, edx, flag = 0; |
| 34 |
#ifdef _MSC_VER |
| 35 |
int cpuid[4]; |
| 36 |
__cpuid(cpuid, 1); |
| 37 |
eax = cpuid[0], ebx = cpuid[1], ecx = cpuid[2], edx = cpuid[3]; |
| 38 |
#else |
| 39 |
asm volatile("cpuid" : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) : "a" (1)); |
| 40 |
#endif |
| 41 |
if (edx>>25&1) flag |= SIMD_SSE; |
| 42 |
if (edx>>26&1) flag |= SIMD_SSE2; |
| 43 |
if (ecx>>0 &1) flag |= SIMD_SSE3; |
| 44 |
if (ecx>>19&1) flag |= SIMD_SSE4_1; |
| 45 |
if (ecx>>20&1) flag |= SIMD_SSE4_2; |
| 46 |
if (ecx>>28&1) flag |= SIMD_AVX; |
| 47 |
if (ebx>>5 &1) flag |= SIMD_AVX2; |
| 48 |
if (ebx>>16&1) flag |= SIMD_AVX512F; |
| 49 |
return flag; |
| 50 |
} |
| 51 |
|
| 52 |
|