1// -*- C++ -*-
2//===----------------------------------------------------------------------===//
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 _LIBCPP___CONFIGURATION_PSTL_H
11#define _LIBCPP___CONFIGURATION_PSTL_H
12
13#include <__config_site>
14
15#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
16# pragma GCC system_header
17#endif
18
19#define _PSTL_PRAGMA(x) _Pragma(#x)
20
21// Enable SIMD for compilers that support OpenMP 4.0
22#if (defined(_OPENMP) && _OPENMP >= 201307)
23
24# define _PSTL_UDR_PRESENT
25# define _PSTL_PRAGMA_SIMD _PSTL_PRAGMA(omp simd)
26# define _PSTL_PRAGMA_DECLARE_SIMD _PSTL_PRAGMA(omp declare simd)
27# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _PSTL_PRAGMA(omp simd reduction(PRM))
28# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _PSTL_PRAGMA(omp simd reduction(inscan, PRM))
29# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan inclusive(PRM))
30# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM) _PSTL_PRAGMA(omp scan exclusive(PRM))
31
32// Declaration of reduction functor, where
33// NAME - the name of the functor
34// OP - type of the callable object with the reduction operation
35// omp_in - refers to the local partial result
36// omp_out - refers to the final value of the combiner operator
37// omp_priv - refers to the private copy of the initial value
38// omp_orig - refers to the original variable to be reduced
39# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP) \
40 _PSTL_PRAGMA(omp declare reduction(NAME:OP : omp_out(omp_in)) initializer(omp_priv = omp_orig))
41
42#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
43
44# define _PSTL_PRAGMA_SIMD _Pragma("clang loop vectorize(enable) interleave(enable)")
45# define _PSTL_PRAGMA_DECLARE_SIMD
46# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
47# define _PSTL_PRAGMA_SIMD_SCAN(PRM) _Pragma("clang loop vectorize(enable) interleave(enable)")
48# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
49# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
50# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
51
52#else // (defined(_OPENMP) && _OPENMP >= 201307)
53
54# define _PSTL_PRAGMA_SIMD
55# define _PSTL_PRAGMA_DECLARE_SIMD
56# define _PSTL_PRAGMA_SIMD_REDUCTION(PRM)
57# define _PSTL_PRAGMA_SIMD_SCAN(PRM)
58# define _PSTL_PRAGMA_SIMD_INCLUSIVE_SCAN(PRM)
59# define _PSTL_PRAGMA_SIMD_EXCLUSIVE_SCAN(PRM)
60# define _PSTL_PRAGMA_DECLARE_REDUCTION(NAME, OP)
61
62#endif // (defined(_OPENMP) && _OPENMP >= 201307)
63
64#define _PSTL_USE_NONTEMPORAL_STORES_IF_ALLOWED
65
66#endif // _LIBCPP___CONFIGURATION_PSTL_H
67