]> git.ipfire.org Git - thirdparty/gcc.git/blob - libcilkrts/include/cilk/common.h
91b2928e7e62a61013b8f1a843004c9445c4646b
[thirdparty/gcc.git] / libcilkrts / include / cilk / common.h
1 /** common.h
2 *
3 * Copyright (C) 2010-2016, Intel Corporation
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
30 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 *
33 * *********************************************************************
34 *
35 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
36 * a repository at cilkplus.org. Changes made to this file that are not
37 * submitted through the contribution process detailed at
38 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
39 * time that a new version is released. Changes only submitted to the
40 * GNU compiler collection or posted to the git repository at
41 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
42 * not tracked.
43 *
44 * We welcome your contributions to this open source project. Thank you
45 * for your assistance in helping us improve Cilk Plus.
46 */
47
48 /** @file common.h
49 *
50 * @brief Defines common macros and structures used by the Intel(R) Cilk(TM) Plus runtime.
51 *
52 * @ingroup common
53 */
54
55 /** @defgroup common Common Definitions
56 * Definitions for runtime macros, structures, and classes.
57 * @{
58 */
59
60 #ifndef INCLUDED_CILK_COMMON
61 #define INCLUDED_CILK_COMMON
62
63 #ifdef __cplusplus
64 /** Namespace for all Intel Cilk Plus definitions that can be included in user code.
65 */
66 namespace cilk {
67
68 /** Namespace for definitions re-used in other Intel Cilk Plus definitions.
69 */
70 namespace internal {}
71 }
72 #endif
73
74 /** Intel Cilk Plus library version = 1.02
75 */
76 #define CILK_LIBRARY_VERSION 102
77
78 #ifdef __cplusplus
79 # include <cassert>
80 #else
81 # include <assert.h>
82 #endif
83
84 /**
85 * Prefix standard library function and type names with __STDNS to
86 * get correct lookup in both C and C++.
87 */
88 #ifdef __cplusplus
89 # define __STDNS std::
90 #else
91 # define __STDNS
92 #endif
93
94 /**
95 * @def CILK_EXPORT
96 * Define export of runtime functions from shared library.
97 * Should be exported only from cilkrts*.dll/cilkrts*.so
98 * @def CILK_EXPORT_DATA
99 * Define export of runtime data from shared library.
100 */
101 #ifdef _WIN32
102 # ifdef IN_CILK_RUNTIME
103 # define CILK_EXPORT __declspec(dllexport)
104 # define CILK_EXPORT_DATA __declspec(dllexport)
105 # else
106 # define CILK_EXPORT __declspec(dllimport)
107 # define CILK_EXPORT_DATA __declspec(dllimport)
108 # endif /* IN_CILK_RUNTIME */
109 #elif defined(__CYGWIN__) || defined(__APPLE__) || defined(_DARWIN_C_SOURCE)
110 # define CILK_EXPORT /* nothing */
111 # define CILK_EXPORT_DATA /* nothing */
112 #else /* Unix/gcc */
113 # if defined(IN_CILK_RUNTIME) && defined(HAVE_ATTRIBUTE_VISIBILITY)
114 # define CILK_EXPORT __attribute__((visibility("protected")))
115 # define CILK_EXPORT_DATA __attribute__((visibility("protected")))
116 # else
117 # define CILK_EXPORT /* nothing */
118 # define CILK_EXPORT_DATA /* nothing */
119 # endif /* IN_CILK_RUNTIME */
120 #endif /* Unix/gcc */
121
122 /**
123 * @def __CILKRTS_BEGIN_EXTERN_C
124 * Macro to denote the start of a section in which all names have "C" linkage.
125 * That is, none of the names are to be mangled.
126 * @see __CILKRTS_END_EXTERN_C
127 * @see __CILKRTS_EXTERN_C
128 *
129 * @def __CILKRTS_END_EXTERN_C
130 * Macro to denote the end of a section in which all names have "C" linkage.
131 * That is, none of the names are to be mangled.
132 * @see __CILKRTS_BEGIN_EXTERN_C
133 * @see __CILKRTS_EXTERN_C
134 *
135 * @def __CILKRTS_EXTERN_C
136 * Macro to prefix a single definition which has "C" linkage.
137 * That is, the defined name is not to be mangled.
138 * @see __CILKRTS_BEGIN_EXTERN_C
139 * @see __CILKRTS_END_EXTERN_C
140 */
141 #ifdef __cplusplus
142 # define __CILKRTS_BEGIN_EXTERN_C extern "C" {
143 # define __CILKRTS_END_EXTERN_C }
144 # define __CILKRTS_EXTERN_C extern "C"
145 #else
146 # define __CILKRTS_BEGIN_EXTERN_C
147 # define __CILKRTS_END_EXTERN_C
148 # define __CILKRTS_EXTERN_C
149 #endif
150
151 /**
152 * OS-independent macro to specify a function which is known to not throw
153 * an exception.
154 */
155 #ifdef __cplusplus
156 # ifdef _WIN32
157 # define __CILKRTS_NOTHROW __declspec(nothrow)
158 # else /* Unix/gcc */
159 # define __CILKRTS_NOTHROW __attribute__((nothrow))
160 # endif /* Unix/gcc */
161 #else
162 # define __CILKRTS_NOTHROW /* nothing */
163 #endif /* __cplusplus */
164
165 /** Cache alignment. (Good enough for most architectures.)
166 */
167 #define __CILKRTS_CACHE_LINE__ 64
168
169 /**
170 * Macro to specify alignment of a data member in a structure.
171 * Because of the way that gcc's alignment attribute is defined, @a n must
172 * be a numeric literal, not just a compile-time constant expression.
173 */
174 #ifdef _WIN32
175 # define CILK_ALIGNAS(n) __declspec(align(n))
176 #else /* Unix/gcc */
177 # define CILK_ALIGNAS(n) __attribute__((__aligned__(n)))
178 #endif
179
180 /**
181 * Macro to specify cache-line alignment of a data member in a structure.
182 */
183 #define __CILKRTS_CACHE_ALIGN CILK_ALIGNAS(__CILKRTS_CACHE_LINE__)
184
185 /**
186 * Macro to specify a class as being at least as strictly aligned as some
187 * type on Windows. gcc does not provide a way of doing this, so on Unix,
188 * this just specifies the largest natural type alignment. Put the macro
189 * between the `class` keyword and the class name:
190 *
191 * class CILK_ALIGNAS_TYPE(foo) bar { ... };
192 */
193 #ifdef _WIN32
194 # define CILK_ALIGNAS_TYPE(t) __declspec(align(__alignof(t)))
195 #else /* Unix/gcc */
196 # define CILK_ALIGNAS_TYPE(t) __attribute__((__aligned__))
197 #endif
198
199 /**
200 * @def CILK_API(RET_TYPE)
201 * A function called explicitly by the programmer.
202 * @def CILK_ABI(RET_TYPE)
203 * A function called by compiler-generated code.
204 * @def CILK_ABI_THROWS(RET_TYPE)
205 * An ABI function that may throw an exception
206 *
207 * Even when these are the same definitions, they should be separate macros so
208 * that they can be easily found in the code.
209 */
210
211 #ifdef _WIN32
212 # define CILK_API(RET_TYPE) CILK_EXPORT RET_TYPE __CILKRTS_NOTHROW __cdecl
213 # define CILK_ABI(RET_TYPE) CILK_EXPORT RET_TYPE __CILKRTS_NOTHROW __cdecl
214 # define CILK_ABI_THROWS(RET_TYPE) CILK_EXPORT RET_TYPE __cdecl
215 #else
216 # define CILK_API(RET_TYPE) CILK_EXPORT RET_TYPE __CILKRTS_NOTHROW
217 # define CILK_ABI(RET_TYPE) CILK_EXPORT RET_TYPE __CILKRTS_NOTHROW
218 # define CILK_ABI_THROWS(RET_TYPE) CILK_EXPORT RET_TYPE
219 #endif
220
221 /**
222 * __CILKRTS_ASSERT should be defined for debugging only, otherwise it
223 * interferes with vectorization. Since NDEBUG is not reliable (it must be
224 * set by the user), we must use a platform-specific detection of debug mode.
225 */
226 #if defined(_WIN32) && defined(_DEBUG)
227 /* Windows debug */
228 # define __CILKRTS_ASSERT(e) assert(e)
229 #elif (! defined(_WIN32)) && ! defined(__OPTIMIZE__)
230 /* Unix non-optimized */
231 # define __CILKRTS_ASSERT(e) assert(e)
232 #elif defined __cplusplus
233 /* C++ non-debug */
234 # define __CILKRTS_ASSERT(e) static_cast<void>(0)
235 #else
236 /* C non-debug */
237 # define __CILKRTS_ASSERT(e) ((void) 0)
238 #endif
239
240 /**
241 * OS-independent macro to specify a function that should be inlined
242 */
243 #ifdef __cplusplus
244 // C++
245 # define __CILKRTS_INLINE inline
246 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
247 // C99
248 # define __CILKRTS_INLINE static inline
249 #elif defined(_MSC_VER)
250 // C89 on Windows
251 # define __CILKRTS_INLINE __inline
252 #else
253 // C89 on GCC-compatible systems
254 # define __CILKRTS_INLINE extern __inline__
255 #endif
256
257 /**
258 * Functions marked as CILK_EXPORT_AND_INLINE have both
259 * inline versions defined in the Intel Cilk Plus API, as well as
260 * non-inlined versions that are exported (for
261 * compatibility with previous versions that did not
262 * inline the functions).
263 */
264 #ifdef COMPILING_CILK_API_FUNCTIONS
265 # define CILK_EXPORT_AND_INLINE CILK_EXPORT
266 #else
267 # define CILK_EXPORT_AND_INLINE __CILKRTS_INLINE
268 #endif
269
270 /**
271 * Try to determine if compiler supports rvalue references.
272 */
273 #if defined(__cplusplus) && !defined(__CILKRTS_RVALUE_REFERENCES)
274 # if __cplusplus >= 201103L // C++11
275 # define __CILKRTS_RVALUE_REFERENCES 1
276 # elif defined(__GXX_EXPERIMENTAL_CXX0X__)
277 # define __CILKRTS_RVALUE_REFERENCES 1
278 # elif __cplusplus >= 199711L && __cplusplus < 201103L
279 // Compiler recognizes a language version prior to C++11
280 # elif __INTEL_COMPILER == 1200 && defined(__STDC_HOSTED__)
281 // Intel compiler version 12.0
282 // __cplusplus has a non-standard definition. In the absence of a
283 // proper definition, look for the C++0x macro, __STDC_HOSTED__.
284 # define __CILKRTS_RVALUE_REFERENCES 1
285 # elif __INTEL_COMPILER > 1200 && defined(CHAR16T)
286 // Intel compiler version >= 12.1
287 // __cplusplus has a non-standard definition. In the absence of a
288 // proper definition, look for the Intel macro, CHAR16T
289 # define __CILKRTS_RVALUE_REFERENCES 1
290 # endif
291 #endif
292
293 /*
294 * Include stdint.h to define the standard integer types.
295 *
296 * Unfortunately Microsoft doesn't provide stdint.h until Visual Studio 2010,
297 * so use our own definitions until those are available
298 */
299
300 #if ! defined(_MSC_VER) || (_MSC_VER >= 1600)
301 # include <stdint.h>
302 #else
303 # ifndef __MS_STDINT_TYPES_DEFINED__
304 # define __MS_STDINT_TYPES_DEFINED__
305 typedef signed char int8_t;
306 typedef short int16_t;
307 typedef int int32_t;
308 typedef __int64 int64_t;
309
310 typedef unsigned char uint8_t;
311 typedef unsigned short uint16_t;
312 typedef unsigned int uint32_t;
313 typedef unsigned __int64 uint64_t;
314 # endif /* __MS_STDINT_TYPES_DEFINED__ */
315 #endif /* ! defined(_MSC_VER) || (_MSC_VER >= 1600) */
316
317 /**
318 * @brief Application Binary Interface (ABI) version of the Intel Cilk Plus runtime
319 * library.
320 *
321 * The compiler determines the ABI version used for compilation. Object files
322 * compiled with higher ABI versions are not compatible with libraries compiled
323 * with lower ABI versions. However, an object file compiled with a lower ABI
324 * version can be used with a library compiled with a higher ABI version
325 * (unless otherwise stated.)
326 */
327 #ifndef __CILKRTS_ABI_VERSION
328 # ifdef IN_CILK_RUNTIME
329 # define __CILKRTS_ABI_VERSION 1
330 # elif defined(__INTEL_COMPILER) && (__INTEL_COMPILER <= 1200)
331 // Intel compilers prior to version 12.1 support only ABI 0
332 # define __CILKRTS_ABI_VERSION 0
333 # else
334 // Non-Intel compiler or Intel compiler after version 12.0.
335 # define __CILKRTS_ABI_VERSION 1
336 # endif
337 #endif
338
339 // These structs are exported because the inlining of
340 // the internal version of API methods require a worker
341 // structure as parameter.
342 __CILKRTS_BEGIN_EXTERN_C
343 /// Worker struct, exported for inlined API methods
344 /// @ingroup api
345 struct __cilkrts_worker;
346
347 /// Worker struct, exported for inlined API methods
348 /// @ingroup api
349 typedef struct __cilkrts_worker __cilkrts_worker;
350
351 /// Worker struct pointer, exported for inlined API methods
352 /// @ingroup api
353 typedef struct __cilkrts_worker *__cilkrts_worker_ptr;
354
355
356 /// Fetch the worker out of TLS.
357 CILK_ABI(__cilkrts_worker_ptr) __cilkrts_get_tls_worker(void);
358
359 /// void *, defined to work around complaints from the compiler
360 /// about using __declspec(nothrow) after the "void *" return type
361 typedef void * __cilkrts_void_ptr;
362
363 __CILKRTS_END_EXTERN_C
364
365
366 #if __CILKRTS_ABI_VERSION >= 1
367 // Pedigree API is available only for compilers that use ABI version >= 1.
368
369 /** Pedigree information kept in the worker and stack frame.
370 * @ingroup api
371 */
372 typedef struct __cilkrts_pedigree
373 {
374 /** Rank at start of spawn helper. Saved rank for spawning functions */
375 uint64_t rank;
376
377 /** Link to next in chain */
378 const struct __cilkrts_pedigree *parent;
379 } __cilkrts_pedigree;
380
381 #endif // __CILKRTS_ABI_VERSION >= 1
382
383 /// @}
384
385 #endif /* INCLUDED_CILK_COMMON */