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 defined(XSIMD_IMPL) && (XSIMD_IMPL & IMPL_MASK) == Scalar
45using current_arch = generic;
46#elif !defined(XSIMD_IMPL)
47using current_arch = default_arch;
48#elif (XSIMD_IMPL & IMPL_MASK) == SSE2
49using current_arch = sse2;
50#elif (XSIMD_IMPL & IMPL_MASK) == SSE3
51using current_arch = sse3;
52#elif (XSIMD_IMPL & IMPL_MASK) == SSSE3
53using current_arch = ssse3;
54#elif (XSIMD_IMPL & IMPL_MASK) == SSE4_1
55using current_arch = sse4_1;
56#elif (XSIMD_IMPL & IMPL_MASK) == SSE4_2
57#if (XSIMD_IMPL & FMA)
58using current_arch = fma3<sse4_2>;
59#else
60using current_arch = sse4_2;
61#endif
62#elif (XSIMD_IMPL & IMPL_MASK) == FMA4
63using current_arch = fma4;
64#elif (XSIMD_IMPL & IMPL_MASK) == AVX
65#if (XSIMD_IMPL & FMA)
66using current_arch = fma3<avx>;
67#else
68using current_arch = avx;
69#endif
70#elif (XSIMD_IMPL & IMPL_MASK) == AVX2
71#if (XSIMD_IMPL & FMA)
72using current_arch = fma3<avx2>;
73#else
74using current_arch = avx2;
75#endif
76#elif (XSIMD_IMPL & IMPL_MASK) == AVX512F
77using current_arch = avx512f;
78#elif (XSIMD_IMPL & IMPL_MASK) == AVX512CD
79using current_arch = avx512cd;
80#elif (XSIMD_IMPL & IMPL_MASK) == AVX512DQ
81using current_arch = avx512dq;
82#elif (XSIMD_IMPL & IMPL_MASK) == AVX512BW
83using current_arch = avx512bw;
84#elif (XSIMD_IMPL & IMPL_MASK) == NEON
85using current_arch = neon;
86#elif (XSIMD_IMPL & IMPL_MASK) == NEON64
87using current_arch = neon64;
88#endif
89}; // namespace xsimd
90
91// xsimd extension to block AppleClang's auto-lipoization of
92// compiled objects.
93// If the defined instruction sets don't match what's expected
94// from the build flags, zonk out the included file.
95
96#if !defined(XSIMD_IMPL) || defined(XSIMD_IMPL) && (XSIMD_IMPL & IMPL_MASK) == Scalar
97#define XSIMD_UNIVERSAL_BUILD_PASS 3
98#elif XSIMD_WITH_SSE2 && (XSIMD_IMPL & PLATFORM_MASK) == Intel_Architecture
99#define XSIMD_UNIVERSAL_BUILD_PASS 2
100#elif (XSIMD_WITH_NEON || XSIMD_WITH_NEON64) && (XSIMD_IMPL & PLATFORM_MASK) == Arm_Architecture
101#define XSIMD_UNIVERSAL_BUILD_PASS 1
102#endif
103
104#ifndef XSIMD_UNIVERSAL_BUILD_PASS
105#define XSIMD_UNIVERSAL_BUILD_PASS 0
106#endif
107
108#undef Scalar
109#undef SSE2
110#undef SSE3
111#undef SSSE3
112#undef SSE4_1
113#undef SSE4_2
114#undef AVX
115#undef AVX2
116#undef AVX512F
117#undef AVX512BW
118#undef AVX512CD
119#undef AVX512DQ
120#undef NEON
121#undef NEON64
122
123#undef FMA3
124#undef FMA4
125#undef IMPL_MASK
126
127#endif // KIS_XSIMD_ARCH_HPP
default_arch current_arch