1 /* This file is part of the Vc library.
3 Copyright (C) 2010-2012 Matthias Kretz <kretz@kde.org>
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.
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.
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/>.
20 #ifndef VC_COMMON_SUPPORT_H
21 #define VC_COMMON_SUPPORT_H
24 #error "Vc/global.h must be included first!"
29 #if defined(VC_GCC) && VC_GCC >= 0x40400
30 #define VC_TARGET_NO_SIMD __attribute__((target("no-sse2,no-avx")))
32 #define VC_TARGET_NO_SIMD
40 * \name Micro-Architecture Feature Tests
45 * \headerfile support.h <Vc/support.h>
46 * Determines the extra instructions supported by the current CPU.
48 * \return A combination of flags from Vc::ExtraInstructions that the current CPU supports.
51 unsigned int extraInstructionsSupported();
55 * \headerfile support.h <Vc/support.h>
57 * Tests whether the given implementation is supported by the system the code is executing on.
59 * \return \c true if the OS and hardware support execution of instructions defined by \p impl.
60 * \return \c false otherwise
62 * \param impl The SIMD target to test for.
65 bool isImplementationSupported(Vc::Implementation impl);
70 * \headerfile support.h <Vc/support.h>
72 * Tests whether the given implementation is supported by the system the code is executing on.
75 * if (!isImplementationSupported<Vc::CurrentImplementation>()) {
76 * std::cerr << "This code was compiled with features that this system does not support.\n";
77 * return EXIT_FAILURE;
81 * \return \c true if the OS and hardware support execution of instructions defined by \p impl.
82 * \return \c false otherwise
84 * \tparam Impl The SIMD target to test for.
86 template<typename Impl>
88 static inline bool isImplementationSupported()
90 return isImplementationSupported(static_cast<Vc::Implementation>(Impl::Implementation)) &&
91 (extraInstructionsSupported() & Impl::ExtraInstructions) == Impl::ExtraInstructions;
96 * \headerfile support.h <Vc/support.h>
98 * Determines the best supported implementation for the current system.
100 * \return The enum value for the best implementation.
103 Vc::Implementation bestImplementationSupported();
105 #ifndef VC_COMPILE_LIB
108 * \headerfile support.h <Vc/support.h>
110 * Tests that the CPU and Operating System support the vector unit which was compiled for. This
111 * function should be called before any other Vc functionality is used. It checks whether the program
112 * will work. If this function returns \c false then the program should exit with a useful error
113 * message before the OS has to kill it because of an invalid instruction exception.
115 * If the program continues and makes use of any vector features not supported by
116 * hard- or software then the program will crash.
122 * if (!Vc::currentImplementationSupported()) {
123 * std::cerr << "CPU or OS requirements not met for the compiled in vector unit!\n";
130 * \return \c true if the OS and hardware support execution of the currently selected SIMD
132 * \return \c false otherwise
138 inline bool currentImplementationSupported()
140 return isImplementationSupported<Vc::CurrentImplementation>();
142 #endif // VC_COMPILE_LIB
146 } // namespace AliRoot
148 #undef VC_TARGET_NO_SIMD
150 #endif // VC_COMMON_SUPPORT_H