Random123
compilerfeatures.h
Go to the documentation of this file.
1/*
2Copyright 2010-2011, D. E. Shaw Research.
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are
7met:
8
9* Redistributions of source code must retain the above copyright
10 notice, this list of conditions, and the following disclaimer.
11
12* Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions, and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16* Neither the name of D. E. Shaw Research nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*/
195/*
196N.B. When something is added to the list of features, it should be
197added to each of the *features.h files, AND to examples/ut_features.cpp.
198*/
199
200/* N.B. most other compilers (icc, nvcc, open64, llvm) will also define __GNUC__, so order matters. */
201#if defined(__METAL_MACOS__)
202#include "metalfeatures.h"
203#elif defined(__OPENCL_VERSION__) && __OPENCL_VERSION__ > 0
204#include "openclfeatures.h"
205#elif defined(__CUDACC__)
206#include "nvccfeatures.h"
207#elif defined(__ICC)
208#include "iccfeatures.h"
209#elif defined(__xlC__) || defined(__ibmxl__)
210#include "xlcfeatures.h"
211#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
212#include "sunprofeatures.h"
213#elif defined(__OPEN64__)
214#include "open64features.h"
215#elif defined(__clang__)
216#include "clangfeatures.h"
217#elif defined(__GNUC__)
218#include "gccfeatures.h"
219#elif defined(__PGI)
220#include "pgccfeatures.h"
221#elif defined(_MSC_FULL_VER)
222#include "msvcfeatures.h"
223#else
224#error "Can't identify compiler. You'll need to add a new xxfeatures.hpp"
225{ /* maybe an unbalanced brace will terminate the compilation */
226#endif
227
228#ifndef R123_USE_CXX11
229#define R123_USE_CXX11 (__cplusplus >= 201103L)
230#endif
231
232#ifndef R123_USE_CXX11_UNRESTRICTED_UNIONS
233#define R123_USE_CXX11_UNRESTRICTED_UNIONS R123_USE_CXX11
234#endif
235
236#ifndef R123_USE_CXX11_STATIC_ASSERT
237#define R123_USE_CXX11_STATIC_ASSERT R123_USE_CXX11
238#endif
239
240#ifndef R123_USE_CXX11_CONSTEXPR
241#define R123_USE_CXX11_CONSTEXPR R123_USE_CXX11
242#endif
243
244#ifndef R123_USE_CXX11_EXPLICIT_CONVERSIONS
245#define R123_USE_CXX11_EXPLICIT_CONVERSIONS R123_USE_CXX11
246#endif
247
248#ifndef R123_USE_CXX11_RANDOM
249#define R123_USE_CXX11_RANDOM R123_USE_CXX11
250#endif
251
252#ifndef R123_USE_CXX11_TYPE_TRAITS
253#define R123_USE_CXX11_TYPE_TRAITS R123_USE_CXX11
254#endif
255
256#ifndef R123_USE_CXX11_LONG_LONG
257#define R123_USE_CXX11_LONG_LONG R123_USE_CXX11
258#endif
259
260#ifndef R123_USE_CXX11_STD_ARRAY
261#define R123_USE_CXX11_STD_ARRAY R123_USE_CXX11
262#endif
263
264#ifndef R123_USE_MULHILO64_C99
265#define R123_USE_MULHILO64_C99 0
266#endif
267
268#ifndef R123_USE_MULHILO64_MULHI_INTRIN
269#define R123_USE_MULHILO64_MULHI_INTRIN 0
270#endif
271
272#ifndef R123_USE_MULHILO32_MULHI_INTRIN
273#define R123_USE_MULHILO32_MULHI_INTRIN 0
274#endif
275
276#ifndef R123_STATIC_ASSERT
277#if R123_USE_CXX11_STATIC_ASSERT
278#define R123_STATIC_ASSERT(expr, msg) static_assert(expr, msg)
279#else
280 /* if msg always_looked_like_this, we could paste it into the name. Worth it? */
281#define R123_STATIC_ASSERT(expr, msg) typedef char static_assertion[(!!(expr))*2-1]
282#endif
283#endif
284
285#ifndef R123_CONSTEXPR
286#if R123_USE_CXX11_CONSTEXPR
287#define R123_CONSTEXPR constexpr
288#else
289#define R123_CONSTEXPR
290#endif
291#endif
292
293#ifndef R123_USE_64BIT
294#define R123_USE_64BIT 1
295#endif
296
297#ifndef R123_USE_PHILOX_64BIT
298#define R123_USE_PHILOX_64BIT (R123_USE_64BIT && (R123_USE_MULHILO64_ASM || R123_USE_MULHILO64_MSVC_INTRIN || R123_USE_MULHILO64_CUDA_INTRIN || R123_USE_GNU_UINT128 || R123_USE_MULHILO64_C99 || R123_USE_MULHILO64_OPENCL_INTRIN || R123_USE_MULHILO64_MULHI_INTRIN))
299#endif
300
301#ifndef R123_ULONG_LONG
302#if defined(__cplusplus) && !R123_USE_CXX11_LONG_LONG
303/* C++98 doesn't have long long. It doesn't have uint64_t either, but
304 we will have typedef'ed uint64_t to something in the xxxfeatures.h.
305 With luck, it won't elicit complaints from -pedantic. Cross your
306 fingers... */
307#define R123_ULONG_LONG uint64_t
308#else
309#define R123_ULONG_LONG unsigned long long
310#endif
311#endif
312
313/* UINT64_C should have been #defined by XXXfeatures.h, either by
314 #include <stdint.h> or through compiler-dependent hacks */
315#ifndef R123_64BIT
316#define R123_64BIT(x) UINT64_C(x)
317#endif
318
319#ifndef R123_THROW
320#define R123_THROW(x) throw (x)
321#endif
322
323#ifndef R123_METAL_THREAD_ADDRESS_SPACE
324#define R123_METAL_THREAD_ADDRESS_SPACE
325#endif
326
327#ifndef R123_METAL_CONSTANT_ADDRESS_SPACE
328#define R123_METAL_CONSTANT_ADDRESS_SPACE
329#endif
330
331/*
332 * Windows.h (and perhaps other "well-meaning" code define min and
333 * max, so there's a high chance that our definition of min, max
334 * methods or use of std::numeric_limits min and max will cause
335 * complaints in any program that happened to include Windows.h or
336 * suchlike first. We use the null macro below in our own header
337 * files definition or use of min, max to defensively preclude
338 * this problem. It may not be enough; one might need to #define
339 * NOMINMAX before including Windows.h or compile with -DNOMINMAX.
340 */
341#define R123_NO_MACRO_SUBST
342