]>
Commit | Line | Data |
---|---|---|
f22341db | 1 | /* This file is part of the Vc library. |
2 | ||
3 | Copyright (C) 2010-2012 Matthias Kretz <kretz@kde.org> | |
4 | ||
5 | Vc is free software: you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser General Public License as | |
7 | published by the Free Software Foundation, either version 3 of | |
8 | the License, or (at your option) any later version. | |
9 | ||
10 | Vc is distributed in the hope that it will be useful, but | |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
16 | License along with Vc. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | */ | |
19 | ||
20 | #include <Vc/global.h> | |
21 | #include <Vc/cpuid.h> | |
7c616f25 | 22 | #include "Vc/common/support.h" |
f22341db | 23 | |
24 | #ifdef VC_MSVC | |
25 | #include <intrin.h> | |
26 | #endif | |
27 | ||
28 | namespace Vc | |
29 | { | |
30 | ||
31 | #ifdef VC_GCC | |
32 | __attribute__((target("no-sse2,no-avx"))) | |
33 | #endif | |
34 | bool isImplementationSupported(Implementation impl) | |
35 | { | |
36 | CpuId::init(); | |
37 | // for AVX we need to check for OSXSAVE and AVX | |
38 | ||
39 | switch (impl) { | |
40 | case ScalarImpl: | |
41 | return true; | |
42 | case SSE2Impl: | |
43 | return CpuId::hasSse2(); | |
44 | case SSE3Impl: | |
45 | return CpuId::hasSse3(); | |
46 | case SSSE3Impl: | |
47 | return CpuId::hasSsse3(); | |
48 | case SSE41Impl: | |
49 | return CpuId::hasSse41(); | |
50 | case SSE42Impl: | |
51 | return CpuId::hasSse42(); | |
52 | case SSE4aImpl: | |
53 | return CpuId::hasSse4a(); | |
54 | case XopImpl: | |
55 | return CpuId::hasXop(); | |
56 | case Fma4Impl: | |
57 | return CpuId::hasFma4(); | |
58 | case AVXImpl: | |
59 | #if defined(VC_MSVC) && VC_MSVC >= 160040219 // MSVC 2010 SP1 introduced _xgetbv | |
60 | unsigned long long xcrFeatureMask = _xgetbv(_XCR_XFEATURE_ENABLED_MASK); | |
61 | return (xcrFeatureMask & 0x6) != 0; | |
62 | #elif !defined(VC_NO_XGETBV) | |
63 | if (CpuId::hasOsxsave() && CpuId::hasAvx()) { | |
64 | unsigned int eax; | |
65 | asm("xgetbv" : "=a"(eax) : "c"(0) : "edx"); | |
66 | return (eax & 0x06) == 0x06; | |
67 | } | |
68 | #endif | |
69 | return false; | |
70 | } | |
71 | return false; | |
72 | } | |
73 | ||
74 | } // namespace Vc | |
75 | ||
76 | // vim: sw=4 sts=4 et tw=100 |