comparison src/fftw-3.3.8/simd-support/avx512.c @ 167:bd3cc4d1df30

Add FFTW 3.3.8 source, and a Linux build
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 19 Nov 2019 14:52:55 +0000
parents
children
comparison
equal deleted inserted replaced
166:cbd6d7e562c7 167:bd3cc4d1df30
1 /*
2 * Copyright (c) 2003, 2007-11 Matteo Frigo
3 * Copyright (c) 2003, 2007-11 Massachusetts Institute of Technology
4 * Copyright (c) 2012-2013 Romain Dolbeau
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 */
25
26 #include "kernel/ifftw.h"
27
28 #if HAVE_AVX512
29
30 #if defined(__x86_64__) || defined(_M_X64) || defined(_M_AMD64)
31
32 #include "amd64-cpuid.h"
33
34 int X(have_simd_avx512)(void)
35 {
36 static int init = 0, res;
37 int max_stdfn, eax, ebx, ecx, edx;
38
39 /* NOTE: this code is a total guess. I don't have an avx512
40 machine available. The code contributed by Erik Lindahl would
41 crash on a machine without XGETBV, so I had to guess a fix. */
42 if (!init) {
43 cpuid_all(0,0,&eax,&ebx,&ecx,&edx);
44 max_stdfn = eax;
45 if (max_stdfn >= 0x1) {
46 /* have OSXSAVE? (implies XGETBV exists) */
47 cpuid_all(0x1, 0, &eax, &ebx, &ecx, &edx);
48 if ((ecx & 0x08000000) == 0x08000000) {
49 /* have AVX512? */
50 cpuid_all(7,0,&eax,&ebx,&ecx,&edx);
51 if (ebx & (1 << 16)) {
52 /* have OS support for XMM, YMM, ZMM */
53 int zmm_ymm_xmm = (7 << 5) | (1 << 2) | (1 << 1);
54 res = ((xgetbv_eax(0) & zmm_ymm_xmm) == zmm_ymm_xmm);
55 }
56 }
57 }
58 init = 1;
59 }
60
61 return res;
62 }
63
64 #else /* 32-bit code */
65
66 #error "Avx512 is 64 bits only"
67
68 #endif
69
70 #endif