1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2020 The Qt Company Ltd. |
4 | ** Copyright (C) 2018 Intel Corporation. |
5 | ** Contact: https://www.qt.io/licensing/ |
6 | ** |
7 | ** This file is part of the QtCore module of the Qt Toolkit. |
8 | ** |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
10 | ** Commercial License Usage |
11 | ** Licensees holding valid commercial Qt licenses may use this file in |
12 | ** accordance with the commercial license agreement provided with the |
13 | ** Software or, alternatively, in accordance with the terms contained in |
14 | ** a written agreement between you and The Qt Company. For licensing terms |
15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
16 | ** information use the contact form at https://www.qt.io/contact-us. |
17 | ** |
18 | ** GNU Lesser General Public License Usage |
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
20 | ** General Public License version 3 as published by the Free Software |
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
22 | ** packaging of this file. Please review the following information to |
23 | ** ensure the GNU Lesser General Public License version 3 requirements |
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
25 | ** |
26 | ** GNU General Public License Usage |
27 | ** Alternatively, this file may be used under the terms of the GNU |
28 | ** General Public License version 2.0 or (at your option) the GNU General |
29 | ** Public license version 3 or any later version approved by the KDE Free |
30 | ** Qt Foundation. The licenses are as published by the Free Software |
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
32 | ** included in the packaging of this file. Please review the following |
33 | ** information to ensure the GNU General Public License requirements will |
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
36 | ** |
37 | ** $QT_END_LICENSE$ |
38 | ** |
39 | ****************************************************************************/ |
40 | |
41 | #ifndef QSIMD_H |
42 | #define QSIMD_H |
43 | |
44 | #include <QtCore/qglobal.h> |
45 | |
46 | /* |
47 | * qconfig.h defines the QT_COMPILER_SUPPORTS_XXX macros. |
48 | * They mean the compiler supports the necessary flags and the headers |
49 | * for the x86 and ARM intrinsics. |
50 | * |
51 | * Supported instruction set extensions are: |
52 | * Flag | Arch |
53 | * neon | ARM |
54 | * mips_dsp | mips |
55 | * mips_dspr2 | mips |
56 | * sse2 | x86 |
57 | * sse4_1 | x86 |
58 | * sse4_2 | x86 |
59 | * avx | x86 |
60 | * |
61 | * Code can use the following constructs to determine compiler support & status: |
62 | * - #if QT_COMPILER_USES(XXX) (e.g: #if QT_COMPILER_USES(neon) or QT_COMPILER_USES(sse4_1) |
63 | * If this test passes, then the compiler is already generating code using the |
64 | * given instruction set. The intrinsics for those instructions are |
65 | * #included and can be used without restriction or runtime check. |
66 | * |
67 | * Code that requires runtime detection and different code paths at runtime is |
68 | * currently not supported here, have a look at qsimd_p.h for support. |
69 | */ |
70 | |
71 | #define QT_COMPILER_USES(feature) (1/QT_COMPILER_USES_##feature == 1) |
72 | |
73 | #if defined(Q_PROCESSOR_ARM) && defined(__ARM_NEON) || defined(__ARM_NEON__) |
74 | # include <arm_neon.h> |
75 | # define QT_COMPILER_USES_neon 1 |
76 | #else |
77 | # define QT_COMPILER_USES_neon -1 |
78 | #endif |
79 | |
80 | #if defined(Q_PROCESSOR_MIPS) && (defined(__MIPS_DSP__) || (defined(__mips_dsp) && defined(Q_PROCESSOR_MIPS_32))) |
81 | # define QT_COMPILER_USES_mips_dsp 1 |
82 | #else |
83 | # define QT_COMPILER_USES_mips_dsp -1 |
84 | #endif |
85 | |
86 | #if defined(Q_PROCESSOR_MIPS) && (defined(__MIPS_DSPR2__) || (defined(__mips_dspr2) && defined(Q_PROCESSOR_MIPS_32))) |
87 | # define QT_COMPILER_USES_mips_dspr2 1 |
88 | #else |
89 | # define QT_COMPILER_USES_mips_dspr2 -1 |
90 | #endif |
91 | |
92 | #if defined(Q_PROCESSOR_X86) |
93 | #if defined(Q_CC_MSVC) |
94 | // MSVC doesn't define __SSE2__, so do it ourselves |
95 | # if (defined(_M_X64) || _M_IX86_FP >= 2) |
96 | # define __SSE__ 1 |
97 | # define __SSE2__ 1 |
98 | # endif |
99 | #if (defined(_M_AVX) || defined(__AVX__)) |
100 | // Visual Studio defines __AVX__ when /arch:AVX is passed, but not the earlier macros |
101 | // See: https://msdn.microsoft.com/en-us/library/b0084kay.aspx |
102 | # define __SSE3__ 1 |
103 | # define __SSSE3__ 1 |
104 | # define __SSE4_1__ 1 |
105 | # define __SSE4_2__ 1 |
106 | # ifndef __AVX__ |
107 | # define __AVX__ 1 |
108 | # endif |
109 | # endif |
110 | # ifdef __SSE2__ |
111 | # define QT_VECTORCALL __vectorcall |
112 | # endif |
113 | #endif |
114 | #endif |
115 | |
116 | #if defined(Q_PROCESSOR_X86) && defined(__SSE2__) |
117 | # include <immintrin.h> |
118 | # define QT_COMPILER_USES_sse2 1 |
119 | #else |
120 | # define QT_COMPILER_USES_sse2 -1 |
121 | #endif |
122 | |
123 | #if defined(Q_PROCESSOR_X86) && defined(__SSE3__) |
124 | # define QT_COMPILER_USES_sse3 1 |
125 | #else |
126 | # define QT_COMPILER_USES_sse3 -1 |
127 | #endif |
128 | |
129 | #if defined(Q_PROCESSOR_X86) && defined(__SSSE3__) |
130 | # define QT_COMPILER_USES_ssse3 1 |
131 | #else |
132 | # define QT_COMPILER_USES_ssse3 -1 |
133 | #endif |
134 | |
135 | #if defined(Q_PROCESSOR_X86) && defined(__SSE4_1__) |
136 | # define QT_COMPILER_USES_sse4_1 1 |
137 | #else |
138 | # define QT_COMPILER_USES_sse4_1 -1 |
139 | #endif |
140 | |
141 | #if defined(Q_PROCESSOR_X86) && defined(__SSE4_2__) |
142 | # define QT_COMPILER_USES_sse4_2 1 |
143 | #else |
144 | # define QT_COMPILER_USES_sse4_2 -1 |
145 | #endif |
146 | |
147 | #if defined(Q_PROCESSOR_X86) && defined(__AVX__) |
148 | # define QT_COMPILER_USES_avx 1 |
149 | #else |
150 | # define QT_COMPILER_USES_avx -1 |
151 | #endif |
152 | |
153 | #ifndef QT_VECTORCALL |
154 | #define QT_VECTORCALL |
155 | #endif |
156 | |
157 | QT_BEGIN_NAMESPACE |
158 | QT_END_NAMESPACE |
159 | |
160 | #endif // QSIMD_H |
161 | |