1// -*- C++ -*-
2//===-- pstl_config.h -----------------------------------------------------===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef __PSTL_config_H
11#define __PSTL_config_H
12
13#define PSTL_VERSION 203
14#define PSTL_VERSION_MAJOR (PSTL_VERSION / 100)
15#define PSTL_VERSION_MINOR (PSTL_VERSION - PSTL_VERSION_MAJOR * 100)
16
17// Check the user-defined macro for parallel policies
18#if defined(PSTL_USE_PARALLEL_POLICIES)
19#undef __PSTL_USE_PAR_POLICIES
20#define __PSTL_USE_PAR_POLICIES PSTL_USE_PARALLEL_POLICIES
21// Check the internal macro for parallel policies
22#elif !defined(__PSTL_USE_PAR_POLICIES)
23#define __PSTL_USE_PAR_POLICIES 1
24#endif
25
26#if __PSTL_USE_PAR_POLICIES
27#if !defined(__PSTL_PAR_BACKEND_TBB)
28#define __PSTL_PAR_BACKEND_TBB 1
29#endif
30#else
31#undef __PSTL_PAR_BACKEND_TBB
32#endif
33
34// Check the user-defined macro for warnings
35#if defined(PSTL_USAGE_WARNINGS)
36#undef __PSTL_USAGE_WARNINGS
37#define __PSTL_USAGE_WARNINGS PSTL_USAGE_WARNINGS
38// Check the internal macro for warnings
39#elif !defined(__PSTL_USAGE_WARNINGS)
40#define __PSTL_USAGE_WARNINGS 0
41#endif
42
43// Portability "#pragma" definition
44#ifdef _MSC_VER
45#define __PSTL_PRAGMA(x) __pragma(x)
46#else
47#define __PSTL_PRAGMA(x) _Pragma(#x)
48#endif
49
50#define __PSTL_STRING_AUX(x) #x
51#define __PSTL_STRING(x) __PSTL_STRING_AUX(x)
52#define __PSTL_STRING_CONCAT(x, y) x #y
53
54// note that when ICC or Clang is in use, __PSTL_GCC_VERSION might not fully match
55// the actual GCC version on the system.
56#define __PSTL_GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
57
58#if __clang__
59// according to clang documentation, version can be vendor specific
60#define __PSTL_CLANG_VERSION (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__)
61#endif
62
63// Enable SIMD for compilers that support OpenMP 4.0
64#if (_OPENMP >= 201307) || (__INTEL_COMPILER >= 1600) || (!defined(__INTEL_COMPILER) && __PSTL_GCC_VERSION >= 40900)
65#define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(omp simd)
66#define __PSTL_PRAGMA_DECLARE_SIMD __PSTL_PRAGMA(omp declare simd)
67#define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(omp simd reduction(PRM))
68#elif !defined(_MSC_VER) //#pragma simd
69#define __PSTL_PRAGMA_SIMD __PSTL_PRAGMA(simd)
70#define __PSTL_PRAGMA_DECLARE_SIMD
71#define __PSTL_PRAGMA_SIMD_REDUCTION(PRM) __PSTL_PRAGMA(simd reduction(PRM))
72#else //no simd
73#define __PSTL_PRAGMA_SIMD
74#define __PSTL_PRAGMA_DECLARE_SIMD
75#define __PSTL_PRAGMA_SIMD_REDUCTION(PRM)
76#endif //Enable SIMD
77
78#if (__INTEL_COMPILER)
79#define __PSTL_PRAGMA_FORCEINLINE __PSTL_PRAGMA(forceinline)
80#else
81#define __PSTL_PRAGMA_FORCEINLINE
82#endif
83
84#if (__INTEL_COMPILER >= 1900)
85#define __PSTL_PRAGMA_SIMD_SCAN(PRM) __PSTL_PRAGMA(omp simd reduction(inscan, PRM))
86#define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) __PSTL_PRAGMA(omp scan inclusive(PRM))
87#define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) __PSTL_PRAGMA(omp scan exclusive(PRM))
88#else
89#define __PSTL_PRAGMA_SIMD_SCAN(PRM)
90#define __PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
91#define __PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
92#endif
93
94// Should be defined to 1 for environments with a vendor implementation of C++17 execution policies
95#define __PSTL_CPP17_EXECUTION_POLICIES_PRESENT (_MSC_VER >= 1912)
96
97#define __PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT \
98 (_MSC_VER >= 1900 || __cplusplus >= 201300L || __cpp_lib_robust_nonmodifying_seq_ops == 201304)
99#define __PSTL_CPP14_MAKE_REVERSE_ITERATOR_PRESENT \
100 (_MSC_VER >= 1900 || __cplusplus >= 201402L || __cpp_lib_make_reverse_iterator == 201402)
101#define __PSTL_CPP14_INTEGER_SEQUENCE_PRESENT (_MSC_VER >= 1900 || __cplusplus >= 201402L)
102#define __PSTL_CPP14_VARIABLE_TEMPLATES_PRESENT \
103 (!__INTEL_COMPILER || __INTEL_COMPILER >= 1700) && (_MSC_FULL_VER >= 190023918 || __cplusplus >= 201402L)
104
105#define __PSTL_EARLYEXIT_PRESENT (__INTEL_COMPILER >= 1800)
106#define __PSTL_MONOTONIC_PRESENT (__INTEL_COMPILER >= 1800)
107
108#if (__INTEL_COMPILER >= 1900 || !defined(__INTEL_COMPILER) && __PSTL_GCC_VERSION >= 40900 || _OPENMP >= 201307)
109#define __PSTL_UDR_PRESENT 1
110#else
111#define __PSTL_UDR_PRESENT 0
112#endif
113
114#define __PSTL_UDS_PRESENT (__INTEL_COMPILER >= 1900 && __INTEL_COMPILER_BUILD_DATE >= 20180626)
115
116#if __PSTL_EARLYEXIT_PRESENT
117#define __PSTL_PRAGMA_SIMD_EARLYEXIT __PSTL_PRAGMA(omp simd early_exit)
118#else
119#define __PSTL_PRAGMA_SIMD_EARLYEXIT
120#endif
121
122#if __PSTL_MONOTONIC_PRESENT
123#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM) __PSTL_PRAGMA(omp ordered simd monotonic(PRM))
124#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2) __PSTL_PRAGMA(omp ordered simd monotonic(PRM1, PRM2))
125#else
126#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC(PRM)
127#define __PSTL_PRAGMA_SIMD_ORDERED_MONOTONIC_2ARGS(PRM1, PRM2)
128#endif
129
130// Declaration of reduction functor, where
131// NAME - the name of the functor
132// OP - type of the callable object with the reduction operation
133// omp_in - refers to the local partial result
134// omp_out - refers to the final value of the combiner operator
135// omp_priv - refers to the private copy of the initial value
136// omp_orig - refers to the original variable to be reduced
137#define __PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
138 __PSTL_PRAGMA(omp declare reduction(NAME : OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
139
140#if (__INTEL_COMPILER >= 1600)
141#define __PSTL_PRAGMA_VECTOR_UNALIGNED __PSTL_PRAGMA(vector unaligned)
142#else
143#define __PSTL_PRAGMA_VECTOR_UNALIGNED
144#endif
145
146// Check the user-defined macro to use non-temporal stores
147#if defined(PSTL_USE_NONTEMPORAL_STORES) && (__INTEL_COMPILER >= 1600)
148#define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED __PSTL_PRAGMA(vector nontemporal)
149#else
150#define __PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
151#endif
152
153#if _MSC_VER || __INTEL_COMPILER //the preprocessors don't type a message location
154#define __PSTL_PRAGMA_LOCATION __FILE__ ":" __PSTL_STRING(__LINE__) ": [Parallel STL message]: "
155#else
156#define __PSTL_PRAGMA_LOCATION " [Parallel STL message]: "
157#endif
158
159#define __PSTL_PRAGMA_MESSAGE_IMPL(x) __PSTL_PRAGMA(message(__PSTL_STRING_CONCAT(__PSTL_PRAGMA_LOCATION, x)))
160
161#if __PSTL_USAGE_WARNINGS
162#define __PSTL_PRAGMA_MESSAGE(x) __PSTL_PRAGMA_MESSAGE_IMPL(x)
163#define __PSTL_PRAGMA_MESSAGE_POLICIES(x) __PSTL_PRAGMA_MESSAGE_IMPL(x)
164#else
165#define __PSTL_PRAGMA_MESSAGE(x)
166#define __PSTL_PRAGMA_MESSAGE_POLICIES(x)
167#endif
168
169// broken macros
170#define __PSTL_CPP11_STD_ROTATE_BROKEN ((__GLIBCXX__ && __GLIBCXX__ < 20150716) || (_MSC_VER && _MSC_VER < 1800))
171
172#define __PSTL_ICC_18_OMP_SIMD_BROKEN (__INTEL_COMPILER == 1800)
173
174#endif /* __PSTL_config_H */
175