Krita Source Code Documentation
Loading...
Searching...
No Matches
xsimd_arch.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 L. E. Segovia <amy@amyspark.me>
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef KIS_XSIMD_ARCH_HPP
8#define KIS_XSIMD_ARCH_HPP
9
10#include "./xsimd_config.hpp"
11
12// Architecture initialization. Borrowed from Vc
13// Define the following strings to a unique integer, which is the only type the
14// preprocessor can compare. This allows to use -DXSIMD_IMPL=SSE3. The
15// preprocessor will then consider XSIMD_IMPL and SSE3 to be equal.
16// An additional define IMPL_MASK allows to detect the FMA extension.
17
18#define Scalar 0x00100000
19#define SSE2 0x00200000
20#define SSE3 0x00300000
21#define SSSE3 0x00400000
22#define SSE4_1 0x00500000
23#define SSE4_2 0x00600000
24#define FMA4 0x00700000
25#define AVX 0x00800000
26#define AVX2 0x00900000
27#define AVX512F 0x00A00000
28#define AVX512BW 0x00B00000
29#define AVX512CD 0x00C00000
30#define AVX512DQ 0x00D00000
31#define NEON 0x10100000
32#define NEON64 0x10200000
33
34#define FMA 0x00000001
35
36#define Intel_Architecture 0x00000000
37#define Arm_Architecture 0x10000000
38
39#define IMPL_MASK 0xFFF00000
40#define PLATFORM_MASK 0xF0000000
41
42namespace xsimd
43{
44#if XSIMD_VERSION_MAJOR >= 14
45using generic = common;
46#endif
47#if defined(XSIMD_IMPL) && (XSIMD_IMPL & IMPL_MASK) == Scalar
48using current_arch = generic;
49#elif !defined(XSIMD_IMPL)
50using current_arch = default_arch;
51#elif (XSIMD_IMPL & IMPL_MASK) == SSE2
52using current_arch = sse2;
53#elif (XSIMD_IMPL & IMPL_MASK) == SSE3
54using current_arch = sse3;
55#elif (XSIMD_IMPL & IMPL_MASK) == SSSE3
56using current_arch = ssse3;
57#elif (XSIMD_IMPL & IMPL_MASK) == SSE4_1
58using current_arch = sse4_1;
59#elif (XSIMD_IMPL & IMPL_MASK) == SSE4_2
60#if (XSIMD_IMPL & FMA)
61using current_arch = fma3<sse4_2>;
62#else
63using current_arch = sse4_2;
64#endif
65#elif (XSIMD_IMPL & IMPL_MASK) == FMA4
66using current_arch = fma4;
67#elif (XSIMD_IMPL & IMPL_MASK) == AVX
68#if (XSIMD_IMPL & FMA)
69using current_arch = fma3<avx>;
70#else
71using current_arch = avx;
72#endif
73#elif (XSIMD_IMPL & IMPL_MASK) == AVX2
74#if (XSIMD_IMPL & FMA)
75using current_arch = fma3<avx2>;
76#else
77using current_arch = avx2;
78#endif
79#elif (XSIMD_IMPL & IMPL_MASK) == AVX512F
80using current_arch = avx512f;
81#elif (XSIMD_IMPL & IMPL_MASK) == AVX512CD
82using current_arch = avx512cd;
83#elif (XSIMD_IMPL & IMPL_MASK) == AVX512DQ
84using current_arch = avx512dq;
85#elif (XSIMD_IMPL & IMPL_MASK) == AVX512BW
86using current_arch = avx512bw;
87#elif (XSIMD_IMPL & IMPL_MASK) == NEON
88using current_arch = neon;
89#elif (XSIMD_IMPL & IMPL_MASK) == NEON64
90using current_arch = neon64;
91#endif
92}; // namespace xsimd
93
94// xsimd extension to block AppleClang's auto-lipoization of
95// compiled objects.
96// If the defined instruction sets don't match what's expected
97// from the build flags, zonk out the included file.
98
99#if !defined(XSIMD_IMPL) || defined(XSIMD_IMPL) && (XSIMD_IMPL & IMPL_MASK) == Scalar
100#define XSIMD_UNIVERSAL_BUILD_PASS 3
101#elif XSIMD_WITH_SSE2 && (XSIMD_IMPL & PLATFORM_MASK) == Intel_Architecture
102#define XSIMD_UNIVERSAL_BUILD_PASS 2
103#elif (XSIMD_WITH_NEON || XSIMD_WITH_NEON64) && (XSIMD_IMPL & PLATFORM_MASK) == Arm_Architecture
104#define XSIMD_UNIVERSAL_BUILD_PASS 1
105#endif
106
107#ifndef XSIMD_UNIVERSAL_BUILD_PASS
108#define XSIMD_UNIVERSAL_BUILD_PASS 0
109#endif
110
111#undef Scalar
112#undef SSE2
113#undef SSE3
114#undef SSSE3
115#undef SSE4_1
116#undef SSE4_2
117#undef AVX
118#undef AVX2
119#undef AVX512F
120#undef AVX512BW
121#undef AVX512CD
122#undef AVX512DQ
123#undef NEON
124#undef NEON64
125
126#undef FMA3
127#undef FMA4
128#undef IMPL_MASK
129
130#endif // KIS_XSIMD_ARCH_HPP
default_arch current_arch