1#ifndef SIMDJSON_IMPLEMENTATIONS_H
2#define SIMDJSON_IMPLEMENTATIONS_H
3
4#include "simdjson/implementation-base.h"
5
6//
7// First, figure out which implementations can be run. Doing it here makes it so we don't have to worry about the order
8// in which we include them.
9//
10
11#ifndef SIMDJSON_IMPLEMENTATION_ARM64
12#define SIMDJSON_IMPLEMENTATION_ARM64 (SIMDJSON_IS_ARM64)
13#endif
14#define SIMDJSON_CAN_ALWAYS_RUN_ARM64 SIMDJSON_IMPLEMENTATION_ARM64 && SIMDJSON_IS_ARM64
15
16#ifdef __has_include
17// How do we detect that a compiler supports vbmi2?
18// For sure if the following header is found, we are ok?
19#if __has_include(<avx512vbmi2intrin.h>)
20#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
21#endif
22#endif
23
24#ifdef _MSC_VER
25#if _MSC_VER >= 1920
26// Visual Studio 2019 and up support VBMI2 under x64 even if the header
27// avx512vbmi2intrin.h is not found.
28#define SIMDJSON_COMPILER_SUPPORTS_VBMI2 1
29#endif
30#endif
31
32// By default, we allow AVX512.
33#ifndef SIMDJSON_AVX512_ALLOWED
34#define SIMDJSON_AVX512_ALLOWED 1
35#endif
36
37// Default Icelake to on if this is x86-64. Even if we're not compiled for it, it could be selected
38// at runtime.
39#ifndef SIMDJSON_IMPLEMENTATION_ICELAKE
40#define SIMDJSON_IMPLEMENTATION_ICELAKE ((SIMDJSON_IS_X86_64) && (SIMDJSON_AVX512_ALLOWED) && (SIMDJSON_COMPILER_SUPPORTS_VBMI2))
41#endif
42
43#ifdef _MSC_VER
44// To see why (__BMI__) && (__PCLMUL__) && (__LZCNT__) are not part of this next line, see
45// https://github.com/simdjson/simdjson/issues/1247
46#define SIMDJSON_CAN_ALWAYS_RUN_ICELAKE ((SIMDJSON_IMPLEMENTATION_ICELAKE) && (__AVX2__) && (__AVX512F__) && (__AVX512DQ__) && (__AVX512CD__) && (__AVX512BW__) && (__AVX512VL__) && (__AVX512VBMI2__))
47#else
48#define SIMDJSON_CAN_ALWAYS_RUN_ICELAKE ((SIMDJSON_IMPLEMENTATION_ICELAKE) && (__AVX2__) && (__BMI__) && (__PCLMUL__) && (__LZCNT__) && (__AVX512F__) && (__AVX512DQ__) && (__AVX512CD__) && (__AVX512BW__) && (__AVX512VL__) && (__AVX512VBMI2__))
49#endif
50
51// Default Haswell to on if this is x86-64. Even if we're not compiled for it, it could be selected
52// at runtime.
53#ifndef SIMDJSON_IMPLEMENTATION_HASWELL
54#if SIMDJSON_CAN_ALWAYS_RUN_ICELAKE
55// if icelake is always available, never enable haswell.
56#define SIMDJSON_IMPLEMENTATION_HASWELL 0
57#else
58#define SIMDJSON_IMPLEMENTATION_HASWELL SIMDJSON_IS_X86_64
59#endif
60#endif
61#ifdef _MSC_VER
62// To see why (__BMI__) && (__PCLMUL__) && (__LZCNT__) are not part of this next line, see
63// https://github.com/simdjson/simdjson/issues/1247
64#define SIMDJSON_CAN_ALWAYS_RUN_HASWELL ((SIMDJSON_IMPLEMENTATION_HASWELL) && (SIMDJSON_IS_X86_64) && (__AVX2__))
65#else
66#define SIMDJSON_CAN_ALWAYS_RUN_HASWELL ((SIMDJSON_IMPLEMENTATION_HASWELL) && (SIMDJSON_IS_X86_64) && (__AVX2__) && (__BMI__) && (__PCLMUL__) && (__LZCNT__))
67#endif
68
69// Default Westmere to on if this is x86-64.
70#ifndef SIMDJSON_IMPLEMENTATION_WESTMERE
71#if SIMDJSON_CAN_ALWAYS_RUN_ICELAKE || SIMDJSON_CAN_ALWAYS_RUN_HASWELL
72// if icelake or haswell are always available, never enable westmere.
73#define SIMDJSON_IMPLEMENTATION_WESTMERE 0
74#else
75#define SIMDJSON_IMPLEMENTATION_WESTMERE SIMDJSON_IS_X86_64
76#endif
77#endif
78#define SIMDJSON_CAN_ALWAYS_RUN_WESTMERE (SIMDJSON_IMPLEMENTATION_WESTMERE && SIMDJSON_IS_X86_64 && __SSE4_2__ && __PCLMUL__)
79
80#ifndef SIMDJSON_IMPLEMENTATION_PPC64
81#define SIMDJSON_IMPLEMENTATION_PPC64 (SIMDJSON_IS_PPC64)
82#endif
83#define SIMDJSON_CAN_ALWAYS_RUN_PPC64 SIMDJSON_IMPLEMENTATION_PPC64 && SIMDJSON_IS_PPC64
84
85// Default Fallback to on unless a builtin implementation has already been selected.
86#ifndef SIMDJSON_IMPLEMENTATION_FALLBACK
87#if SIMDJSON_CAN_ALWAYS_RUN_ARM64 || SIMDJSON_CAN_ALWAYS_RUN_ICELAKE || SIMDJSON_CAN_ALWAYS_RUN_HASWELL || SIMDJSON_CAN_ALWAYS_RUN_WESTMERE || SIMDJSON_CAN_ALWAYS_RUN_PPC64
88// if anything at all except fallback can always run, then disable fallback.
89#define SIMDJSON_IMPLEMENTATION_FALLBACK 0
90#else
91#define SIMDJSON_IMPLEMENTATION_FALLBACK 1
92#endif
93#endif
94#define SIMDJSON_CAN_ALWAYS_RUN_FALLBACK SIMDJSON_IMPLEMENTATION_FALLBACK
95
96SIMDJSON_PUSH_DISABLE_WARNINGS
97SIMDJSON_DISABLE_UNDESIRED_WARNINGS
98
99// Implementations
100#include "simdjson/arm64.h"
101#include "simdjson/fallback.h"
102#include "simdjson/icelake.h"
103#include "simdjson/haswell.h"
104#include "simdjson/ppc64.h"
105#include "simdjson/westmere.h"
106
107// Builtin implementation
108#include "simdjson/builtin.h"
109
110SIMDJSON_POP_DISABLE_WARNINGS
111
112#endif // SIMDJSON_IMPLEMENTATIONS_H