![]() |
|
|||
File indexing completed on 2025-02-22 10:57:13
0001 /* This file is part of the Vc library. {{{ 0002 Copyright © 2010-2015 Matthias Kretz <kretz@kde.org> 0003 0004 Redistribution and use in source and binary forms, with or without 0005 modification, are permitted provided that the following conditions are met: 0006 * Redistributions of source code must retain the above copyright 0007 notice, this list of conditions and the following disclaimer. 0008 * Redistributions in binary form must reproduce the above copyright 0009 notice, this list of conditions and the following disclaimer in the 0010 documentation and/or other materials provided with the distribution. 0011 * Neither the names of contributing organizations nor the 0012 names of its contributors may be used to endorse or promote products 0013 derived from this software without specific prior written permission. 0014 0015 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 0016 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 0017 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 0018 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 0019 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 0020 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 0021 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 0022 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0023 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 0024 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 0025 0026 }}}*/ 0027 0028 #ifndef VC_COMMON_SUPPORT_H_ 0029 #define VC_COMMON_SUPPORT_H_ 0030 0031 #ifndef VC_GLOBAL_H_ 0032 #error "Vc/global.h must be included first!" 0033 #endif 0034 0035 #if defined __x86_64__ || defined __amd64__ || defined __amd64 || defined __x86_64 || \ 0036 defined _M_AMD64 || defined __i386__ 0037 #include <Vc/cpuid.h> 0038 #endif 0039 0040 #if defined(Vc_GCC) && Vc_GCC >= 0x40400 && defined __SSE__ 0041 #define Vc_TARGET_NO_SIMD __attribute__((target("no-sse2,no-avx"))) 0042 #else 0043 #define Vc_TARGET_NO_SIMD 0044 #endif 0045 0046 #include "common/macros.h" 0047 namespace Vc_VERSIONED_NAMESPACE 0048 { 0049 0050 /** 0051 * \name Micro-Architecture Feature Tests 0052 */ 0053 //@{ 0054 /** 0055 * \ingroup Utilities 0056 * \headerfile support.h <Vc/support.h> 0057 * Determines the extra instructions supported by the current CPU. 0058 * 0059 * \return A combination of flags from Vc::ExtraInstructions that the current CPU supports. 0060 */ 0061 Vc_TARGET_NO_SIMD 0062 unsigned int extraInstructionsSupported(); 0063 0064 /** 0065 * \ingroup Utilities 0066 * \headerfile support.h <Vc/support.h> 0067 * 0068 * Tests whether the given implementation is supported by the system the code is executing on. 0069 * 0070 * \return \c true if the OS and hardware support execution of instructions defined by \p impl. 0071 * \return \c false otherwise 0072 * 0073 * \param impl The SIMD target to test for. 0074 */ 0075 Vc_TARGET_NO_SIMD bool Vc_VDECL isImplementationSupported(Vc::Implementation impl); 0076 0077 /** 0078 * \internal 0079 * \ingroup Utilities 0080 * \headerfile support.h <Vc/support.h> 0081 * 0082 * Tests whether the given implementation is supported by the system the code is executing on. 0083 * 0084 * \code 0085 * if (!isImplementationSupported<Vc::CurrentImplementation>()) { 0086 * std::cerr << "This code was compiled with features that this system does not support.\n"; 0087 * return EXIT_FAILURE; 0088 * } 0089 * \endcode 0090 * 0091 * \return \c true if the OS and hardware support execution of instructions defined by \p impl. 0092 * \return \c false otherwise 0093 * 0094 * \tparam Impl The SIMD target to test for. 0095 */ 0096 template<typename Impl> 0097 Vc_TARGET_NO_SIMD 0098 static inline bool isImplementationSupported() 0099 { 0100 return isImplementationSupported(Impl::current()) && 0101 Impl::runs_on(extraInstructionsSupported()); 0102 } 0103 0104 /** 0105 * \ingroup Utilities 0106 * \headerfile support.h <Vc/support.h> 0107 * 0108 * Determines the best supported implementation for the current system. 0109 * 0110 * \return The enum value for the best implementation. 0111 */ 0112 Vc_TARGET_NO_SIMD 0113 Vc::Implementation bestImplementationSupported(); 0114 0115 #ifndef Vc_COMPILE_LIB 0116 /** 0117 * \ingroup Utilities 0118 * \headerfile support.h <Vc/support.h> 0119 * 0120 * Tests that the CPU and Operating System support the vector unit which was compiled for. This 0121 * function should be called before any other Vc functionality is used. It checks whether the program 0122 * will work. If this function returns \c false then the program should exit with a useful error 0123 * message before the OS has to kill it because of an invalid instruction exception. 0124 * 0125 * If the program continues and makes use of any vector features not supported by 0126 * hard- or software then the program will crash. 0127 * 0128 * Example: 0129 * \code 0130 * int main() 0131 * { 0132 * if (!Vc::currentImplementationSupported()) { 0133 * std::cerr << "CPU or OS requirements not met for the compiled in vector unit!\n"; 0134 * exit -1; 0135 * } 0136 * ... 0137 * } 0138 * \endcode 0139 * 0140 * \return \c true if the OS and hardware support execution of the currently selected SIMD 0141 * instructions. 0142 * \return \c false otherwise 0143 */ 0144 Vc_TARGET_NO_SIMD 0145 #ifndef DOXYGEN 0146 static 0147 #endif 0148 inline bool currentImplementationSupported() 0149 { 0150 return isImplementationSupported<Vc::CurrentImplementation>(); 0151 } 0152 #endif // Vc_COMPILE_LIB 0153 //@} 0154 0155 } 0156 0157 #undef Vc_TARGET_NO_SIMD 0158 0159 #endif // VC_COMMON_SUPPORT_H_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |