Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsimd.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// Copyright (C) 2022 Intel Corporation.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QSIMD_H
7#define QSIMD_H
8
9#include <QtCore/qglobal.h>
10
11/*
12 * qconfig.h defines the QT_COMPILER_SUPPORTS_XXX macros.
13 * They mean the compiler supports the necessary flags and the headers
14 * for the x86 and ARM intrinsics.
15 *
16 * Supported instruction set extensions are:
17 * Flag | Arch
18 * neon | ARM
19 * sve | ARM
20 * mips_dsp | mips
21 * mips_dspr2 | mips
22 * sse2 | x86
23 * sse4_1 | x86
24 * sse4_2 | x86
25 * avx | x86
26 * avx2 | x86
27 * lsx | loongarch
28 * lasx | loongarch
29 *
30 * Code can use the following constructs to determine compiler support & status:
31 * - #if QT_COMPILER_USES(XXX) (e.g: #if QT_COMPILER_USES(neon) or QT_COMPILER_USES(sse4_1)
32 * If this test passes, then the compiler is already generating code using the
33 * given instruction set. The intrinsics for those instructions are
34 * #included and can be used without restriction or runtime check.
35 *
36 * Code that requires runtime detection and different code paths at runtime is
37 * currently not supported here, have a look at qsimd_p.h for support.
38 */
39
40#define QT_COMPILER_USES(feature) (1/QT_COMPILER_USES_##feature == 1)
41
42#if defined(Q_PROCESSOR_ARM) && defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(_M_ARM64)
43# include <arm_neon.h>
44# define QT_COMPILER_USES_neon 1
45#else
46# define QT_COMPILER_USES_neon -1
47#endif
48
49// To avoid to many untestable fringe cases we so far only support 64bit LE in SVE code
50// The test for QT_COMPILER_SUPPORTS_SVE ensures the intrinsics exists
51#if defined(Q_PROCESSOR_ARM_64) && defined(__ARM_FEATURE_SVE) && defined(Q_LITTLE_ENDIAN) && defined(QT_COMPILER_SUPPORTS_SVE)
52# include <arm_sve.h>
53# define QT_COMPILER_USES_sve 1
54#else
55# define QT_COMPILER_USES_sve -1
56#endif
57
58#if defined(Q_PROCESSOR_MIPS) && (defined(__MIPS_DSP__) || (defined(__mips_dsp) && defined(Q_PROCESSOR_MIPS_32)))
59# define QT_COMPILER_USES_mips_dsp 1
60#else
61# define QT_COMPILER_USES_mips_dsp -1
62#endif
63
64#if defined(Q_PROCESSOR_MIPS) && (defined(__MIPS_DSPR2__) || (defined(__mips_dspr2) && defined(Q_PROCESSOR_MIPS_32)))
65# define QT_COMPILER_USES_mips_dspr2 1
66#else
67# define QT_COMPILER_USES_mips_dspr2 -1
68#endif
69
70#if defined(Q_PROCESSOR_LOONGARCH) && defined(__loongarch_sx)
71# include <lsxintrin.h>
72# define QT_COMPILER_USES_lsx 1
73#else
74# define QT_COMPILER_USES_lsx -1
75#endif
76
77#if defined(Q_PROCESSOR_LOONGARCH) && defined(__loongarch_asx)
78# include <lasxintrin.h>
79# define QT_COMPILER_USES_lasx 1
80#else
81# define QT_COMPILER_USES_lasx -1
82#endif
83
84#if defined(Q_PROCESSOR_X86) && defined(Q_CC_MSVC)
85// MSVC doesn't define __SSE2__, so do it ourselves
86# if (defined(_M_X64) || _M_IX86_FP >= 2) && defined(QT_COMPILER_SUPPORTS_SSE2)
87# define __SSE__ 1
88# define __SSE2__ 1
89# endif
90# if (defined(_M_AVX) || defined(__AVX__))
91// Visual Studio defines __AVX__ when /arch:AVX is passed, but not the earlier macros
92// See: https://msdn.microsoft.com/en-us/library/b0084kay.aspx
93# define __SSE3__ 1
94# define __SSSE3__ 1
95# define __SSE4_1__ 1
96# define __SSE4_2__ 1
97# define __POPCNT__ 1
98# ifndef __AVX__
99# define __AVX__ 1
100# endif
101# endif
102# ifdef __SSE2__
103# define QT_VECTORCALL __vectorcall
104# endif
105# ifdef __AVX2__
106// MSVC defines __AVX2__ with /arch:AVX2
107# define __F16C__ 1
108# define __RDRND__ 1
109# define __FMA__ 1
110# define __BMI__ 1
111# define __BMI2__ 1
112# define __MOVBE__ 1
113# define __LZCNT__ 1
114# endif
115// Starting with /arch:AVX512, MSVC defines all the macros
116#endif
117
118#if defined(Q_PROCESSOR_X86) && defined(__SSE2__)
119# include <immintrin.h>
120# define QT_COMPILER_USES_sse2 1
121#else
122# define QT_COMPILER_USES_sse2 -1
123#endif
124
125#if defined(Q_PROCESSOR_X86) && defined(__SSE3__)
126# define QT_COMPILER_USES_sse3 1
127#else
128# define QT_COMPILER_USES_sse3 -1
129#endif
130
131#if defined(Q_PROCESSOR_X86) && defined(__SSSE3__)
132# define QT_COMPILER_USES_ssse3 1
133#else
134# define QT_COMPILER_USES_ssse3 -1
135#endif
136
137#if defined(Q_PROCESSOR_X86) && defined(__SSE4_1__)
138# define QT_COMPILER_USES_sse4_1 1
139#else
140# define QT_COMPILER_USES_sse4_1 -1
141#endif
142
143#if defined(Q_PROCESSOR_X86) && defined(__SSE4_2__)
144# define QT_COMPILER_USES_sse4_2 1
145#else
146# define QT_COMPILER_USES_sse4_2 -1
147#endif
148
149#if defined(Q_PROCESSOR_X86) && defined(__AVX__)
150# define QT_COMPILER_USES_avx 1
151#else
152# define QT_COMPILER_USES_avx -1
153#endif
154
155#if defined(Q_PROCESSOR_X86) && defined(__AVX2__)
156# define QT_COMPILER_USES_avx2 1
157#else
158# define QT_COMPILER_USES_avx2 -1
159#endif
160
161#ifndef QT_VECTORCALL
162#define QT_VECTORCALL
163#endif
164
167
168#endif // QSIMD_H
\inmodule QtSql