2
Copyright 2010-2011, D. E. Shaw Research.
5
Redistribution and use in source and binary forms, with or without
6
modification, are permitted provided that the following conditions are
9
* Redistributions of source code must retain the above copyright
10
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 the
14
documentation and/or other materials provided with the distribution.
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.
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
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
#ifndef __gccfeatures_dot_hpp
33
#define __gccfeatures_dot_hpp
35
#define R123_GNUC_VERSION (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__)
37
#if !defined(__x86_64__) && !defined(__i386__) && !defined(__powerpc__)
38
# error "This code has only been tested on x86 and powerpc platforms."
39
#include <including_a_nonexistent_file_will_stop_some_compilers_from_continuing_with_a_hopeless_task>
40
{ /* maybe an unbalanced brace will terminate the compilation */
41
/* Feel free to try the Random123 library on other architectures by changing
42
the conditions that reach this error, but you should consider it a
43
porting exercise and expect to encounter bugs and deficiencies.
44
Please let the authors know of any successes (or failures). */
48
#include <ppu_intrinsics.h>
51
#ifndef R123_STATIC_INLINE
52
#define R123_STATIC_INLINE static __inline__
55
#ifndef R123_FORCE_INLINE
56
#if R123_GNUC_VERSION >= 40000
57
#define R123_FORCE_INLINE(decl) decl __attribute__((always_inline))
59
#define R123_FORCE_INLINE(decl) decl
63
#ifndef R123_CUDA_DEVICE
64
#define R123_CUDA_DEVICE
69
#define R123_ASSERT(x) assert(x)
72
#ifndef R123_BUILTIN_EXPECT
73
#define R123_BUILTIN_EXPECT(expr,likely) __builtin_expect(expr,likely)
76
/* According to the C++0x standard, we should be able to test the numeric
77
value of __cplusplus == 199701L for C++98, __cplusplus == 201103L for C++0x
78
But gcc has had an open bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773
79
since early 2001, which was finally fixed in 4.7 (early 2012). For
80
earlier versions, the only way to detect whether --std=c++0x was requested
81
on the command line is to look at the __GCC_EXPERIMENTAL_CXX0X__ pp-symbol.
83
#define GNU_CXX11 (__cplusplus>=201103L || (R123_GNUC_VERSION<40700 && defined(__GCC_EXPERIMENTAL_CXX0X__) ))
85
#ifndef R123_USE_CXX11_UNRESTRICTED_UNIONS
86
#define R123_USE_CXX11_UNRESTRICTED_UNIONS ((R123_GNUC_VERSION >= 40600) && GNU_CXX11)
89
#ifndef R123_USE_CXX11_STATIC_ASSERT
90
#define R123_USE_CXX11_STATIC_ASSERT ((R123_GNUC_VERSION >= 40300) && GNU_CXX11)
93
#ifndef R123_USE_CXX11_CONSTEXPR
94
#define R123_USE_CXX11_CONSTEXPR ((R123_GNUC_VERSION >= 40600) && GNU_CXX11)
97
#ifndef R123_USE_CXX11_EXPLICIT_CONVERSIONS
98
#define R123_USE_CXX11_EXPLICIT_CONVERSIONS ((R123_GNUC_VERSION >= 40500) && GNU_CXX11)
101
#ifndef R123_USE_CXX11_RANDOM
102
#define R123_USE_CXX11_RANDOM ((R123_GNUC_VERSION>=40500) && GNU_CXX11)
105
#ifndef R123_USE_CXX11_TYPE_TRAITS
106
#define R123_USE_CXX11_TYPE_TRAITS ((R123_GNUC_VERSION>=40400) && GNU_CXX11)
109
#ifndef R123_USE_AES_NI
111
#define R123_USE_AES_NI 1
113
#define R123_USE_AES_NI 0
117
#ifndef R123_USE_SSE4_2
119
#define R123_USE_SSE4_2 1
121
#define R123_USE_SSE4_2 0
125
#ifndef R123_USE_SSE4_1
127
#define R123_USE_SSE4_1 1
129
#define R123_USE_SSE4_1 0
134
/* There's no point in trying to compile SSE code in Random123
135
unless SSE2 is available. */
137
#define R123_USE_SSE 1
139
#define R123_USE_SSE 0
143
#ifndef R123_USE_AES_OPENSSL
144
/* There isn't really a good way to tell at compile time whether
145
openssl is available. Without a pre-compilation configure-like
146
tool, it's less error-prone to guess that it isn't available. Add
147
-DR123_USE_AES_OPENSSL=1 and any necessary LDFLAGS or LDLIBS to
149
#define R123_USE_AES_OPENSSL 0
152
#ifndef R123_USE_GNU_UINT128
154
#define R123_USE_GNU_UINT128 1
156
#define R123_USE_GNU_UINT128 0
160
#ifndef R123_USE_ASM_GNU
161
#define R123_USE_ASM_GNU (defined(__x86_64__)||defined(__i386__))
164
#ifndef R123_USE_CPUID_MSVC
165
#define R123_USE_CPUID_MSVC 0
168
#ifndef R123_USE_X86INTRIN_H
169
#define R123_USE_X86INTRIN_H ((defined(__x86_64__)||defined(__i386__)) && R123_GNUC_VERSION >= 40402)
172
#ifndef R123_USE_IA32INTRIN_H
173
#define R123_USE_IA32INTRIN_H 0
176
#ifndef R123_USE_XMMINTRIN_H
177
#define R123_USE_XMMINTRIN_H 0
180
#ifndef R123_USE_EMMINTRIN_H
181
/* gcc -m64 on Solaris 10 defines __SSE2__ but doesn't have
182
emmintrin.h in the include search path. This is
183
so broken that I refuse to try to work around it. If this
184
affects you, figure out where your emmintrin.h lives and
185
add an appropriate -I to your CPPFLAGS. Or add -DR123_USE_SSE=0. */
186
#define R123_USE_EMMINTRIN_H (R123_USE_SSE && (R123_GNUC_VERSION < 40402))
189
#ifndef R123_USE_SMMINTRIN_H
190
#define R123_USE_SMMINTRIN_H ((R123_USE_SSE4_1 || R123_USE_SSE4_2) && (R123_GNUC_VERSION < 40402))
193
#ifndef R123_USE_WMMINTRIN_H
194
#define R123_USE_WMMINTRIN_H 0
197
#ifndef R123_USE_INTRIN_H
198
#define R123_USE_INTRIN_H 0
201
#ifndef R123_USE_MULHILO32_ASM
202
#define R123_USE_MULHILO32_ASM 0
205
#ifndef R123_USE_MULHILO64_ASM
206
#define R123_USE_MULHILO64_ASM 0
209
#ifndef R123_USE_MULHILO64_MSVC_INTRIN
210
#define R123_USE_MULHILO64_MSVC_INTRIN 0
213
#ifndef R123_USE_MULHILO64_CUDA_INTRIN
214
#define R123_USE_MULHILO64_CUDA_INTRIN 0
217
#ifndef R123_USE_MULHILO64_OPENCL_INTRIN
218
#define R123_USE_MULHILO64_OPENCL_INTRIN 0
221
#ifndef R123_USE_MULHILO64_MULHI_INTRIN
222
#define R123_USE_MULHILO64_MULHI_INTRIN (defined(__powerpc64__))
225
#ifndef R123_MULHILO64_MULHI_INTRIN
226
#define R123_MULHILO64_MULHI_INTRIN __mulhdu
229
#ifndef R123_USE_MULHILO32_MULHI_INTRIN
230
#define R123_USE_MULHILO32_MULHI_INTRIN 0
233
#ifndef R123_MULHILO32_MULHI_INTRIN
234
#define R123_MULHILO32_MULHI_INTRIN __mulhwu
237
#ifndef __STDC_CONSTANT_MACROS
238
#define __STDC_CONSTANT_MACROS
242
#error UINT64_C not defined. You must define __STDC_CONSTANT_MACROS before you #include <stdint.h>
245
/* If you add something, it must go in all the other XXfeatures.hpp
246
and in ../ut_features.cpp */