annotate src/fftw-3.3.8/simd-support/avx512.c @ 82:d0c2a83c1364

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