3 * Copyright (C) 2010-2016, Intel Corporation
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 * *********************************************************************
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
44 * We welcome your contributions to this open source project. Thank you
45 * for your assistance in helping us improve Cilk Plus.
50 * @brief Defines common macros and structures used by the Intel(R) Cilk(TM) Plus runtime.
55 /** @defgroup common Common Definitions
56 * Definitions for runtime macros, structures, and classes.
60 #ifndef INCLUDED_CILK_COMMON
61 #define INCLUDED_CILK_COMMON
64 /** Namespace for all Intel Cilk Plus definitions that can be included in user code.
68 /** Namespace for definitions re-used in other Intel Cilk Plus definitions.
74 /** Intel Cilk Plus library version = 1.02
76 #define CILK_LIBRARY_VERSION 102
85 * Prefix standard library function and type names with __STDNS to
86 * get correct lookup in both C and C++.
89 # define __STDNS std::
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.
102 # ifdef IN_CILK_RUNTIME
103 # define CILK_EXPORT __declspec(dllexport)
104 # define CILK_EXPORT_DATA __declspec(dllexport)
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 */
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")))
117 # define CILK_EXPORT /* nothing */
118 # define CILK_EXPORT_DATA /* nothing */
119 # endif /* IN_CILK_RUNTIME */
120 #endif /* Unix/gcc */
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
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
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
142 # define __CILKRTS_BEGIN_EXTERN_C extern "C" {
143 # define __CILKRTS_END_EXTERN_C }
144 # define __CILKRTS_EXTERN_C extern "C"
146 # define __CILKRTS_BEGIN_EXTERN_C
147 # define __CILKRTS_END_EXTERN_C
148 # define __CILKRTS_EXTERN_C
152 * OS-independent macro to specify a function which is known to not throw
157 # define __CILKRTS_NOTHROW __declspec(nothrow)
158 # else /* Unix/gcc */
159 # define __CILKRTS_NOTHROW __attribute__((nothrow))
160 # endif /* Unix/gcc */
162 # define __CILKRTS_NOTHROW /* nothing */
163 #endif /* __cplusplus */
165 /** Cache alignment. (Good enough for most architectures.)
167 #define __CILKRTS_CACHE_LINE__ 64
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.
175 # define CILK_ALIGNAS(n) __declspec(align(n))
177 # define CILK_ALIGNAS(n) __attribute__((__aligned__(n)))
181 * Macro to specify cache-line alignment of a data member in a structure.
183 #define __CILKRTS_CACHE_ALIGN CILK_ALIGNAS(__CILKRTS_CACHE_LINE__)
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:
191 * class CILK_ALIGNAS_TYPE(foo) bar { ... };
194 # define CILK_ALIGNAS_TYPE(t) __declspec(align(__alignof(t)))
196 # define CILK_ALIGNAS_TYPE(t) __attribute__((__aligned__))
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
207 * Even when these are the same definitions, they should be separate macros so
208 * that they can be easily found in the code.
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
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
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.
226 #if defined(_WIN32) && defined(_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
234 # define __CILKRTS_ASSERT(e) static_cast<void>(0)
237 # define __CILKRTS_ASSERT(e) ((void) 0)
241 * OS-independent macro to specify a function that should be inlined
245 # define __CILKRTS_INLINE inline
246 #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
248 # define __CILKRTS_INLINE static inline
249 #elif defined(_MSC_VER)
251 # define __CILKRTS_INLINE __inline
253 // C89 on GCC-compatible systems
254 # define __CILKRTS_INLINE extern __inline__
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).
264 #ifdef COMPILING_CILK_API_FUNCTIONS
265 # define CILK_EXPORT_AND_INLINE CILK_EXPORT
267 # define CILK_EXPORT_AND_INLINE __CILKRTS_INLINE
271 * Try to determine if compiler supports rvalue references.
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
294 * Include stdint.h to define the standard integer types.
296 * Unfortunately Microsoft doesn't provide stdint.h until Visual Studio 2010,
297 * so use our own definitions until those are available
300 #if ! defined(_MSC_VER) || (_MSC_VER >= 1600)
303 # ifndef __MS_STDINT_TYPES_DEFINED__
304 # define __MS_STDINT_TYPES_DEFINED__
305 typedef signed char int8_t;
306 typedef short int16_t;
308 typedef __int64
int64_t;
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) */
318 * @brief Application Binary Interface (ABI) version of the Intel Cilk Plus runtime
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.)
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
334 // Non-Intel compiler or Intel compiler after version 12.0.
335 # define __CILKRTS_ABI_VERSION 1
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
345 struct __cilkrts_worker
;
347 /// Worker struct, exported for inlined API methods
349 typedef struct __cilkrts_worker __cilkrts_worker
;
351 /// Worker struct pointer, exported for inlined API methods
353 typedef struct __cilkrts_worker
*__cilkrts_worker_ptr
;
356 /// Fetch the worker out of TLS.
357 CILK_ABI(__cilkrts_worker_ptr
) __cilkrts_get_tls_worker(void);
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
;
363 __CILKRTS_END_EXTERN_C
366 #if __CILKRTS_ABI_VERSION >= 1
367 // Pedigree API is available only for compilers that use ABI version >= 1.
369 /** Pedigree information kept in the worker and stack frame.
372 typedef struct __cilkrts_pedigree
374 /** Rank at start of spawn helper. Saved rank for spawning functions */
377 /** Link to next in chain */
378 const struct __cilkrts_pedigree
*parent
;
379 } __cilkrts_pedigree
;
381 #endif // __CILKRTS_ABI_VERSION >= 1
385 #endif /* INCLUDED_CILK_COMMON */