Project Euler Solutions
macros.h
Go to the documentation of this file.
1 #ifndef MACROS_H
2 #define MACROS_H
3 
4 // compiler info section
5 
10 #if (defined(_MSC_VER) && !defined(__clang__))
11  #define CL_COMPILER 1
12 #else
13  #define CL_COMPILER 0
14 #endif
15 
20 #if (defined(__clang__) && (!defined(AMD_COMPILER) || !AMD_COMPILER))
21  #define CLANG_COMPILER 1
22 #else
23  #define CLANG_COMPILER 0
24 #endif
25 
30 #if (defined(__GNUC__) && !defined(__clang__)) && !defined(__INTEL_COMPILER) && !defined(__PCC__)
31  #define GCC_COMPILER 1
32 #else
33  #define GCC_COMPILER 0
34 #endif
35 
40 #ifdef __INTEL_COMPILER
41  #define INTEL_COMPILER 1
42 #else
43  #define INTEL_COMPILER 0
44 #endif
45 
53 #ifndef AMD_COMPILER
54  #if CLANG_COMPILER
55  #warning "This suite can't detect the difference between clang and aocc. You need to specify -DAMD_COMPILER={0 or 1}"
56  #endif
57  #define AMD_COMPILER 0
58 #endif
59 
64 #if (defined(_M_X64) || defined(_M_AMD64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64))
65  #define X64_COMPILER 1
66 #else
67  #define X64_COMPILER 0
68 #endif
69 
77 #if (!X64_COMPILER && (defined(_M_X86) || defined(_M_IX86) || defined(i386) || defined(__i386) || defined(__i386__) || defined(_X86_)))
78  #define X86_COMPILER 1
79 #else
80  #define X86_COMPILER 0
81 #endif
82 
87 #if (defined(__arm__) || defined(__aarch64__) || defined(__thumb__) || defined(_M_ARM) || defined(_M_ARMT) || defined(__ARM_ARCH))
88  #define ARM_COMPILER 1
89 #else
90  #define ARM_COMPILER 0
91 #endif
92 
97 #if (ARM_COMPILER && (defined(__thumb__) || defined(_M_ARMT)))
98  #define ARM_THUMB 1
99 #else
100  #define ARM_THUMB 0
101 #endif
102 
103 // helper macro function section
104 
111 #ifndef max
112  #define max(a, b) (((a) > (b)) ? (a) : (b))
113 #endif
114 
121 #ifndef min
122  #define min(a, b) (((a) < (b)) ? (a) : (b))
123 #endif
124 
131 #define swap(x, y, T) do { T SWAP = x; x = y; y = SWAP; } while (0)
132 
133 #if !CL_COMPILER
134 
142  #define likely(x) __builtin_expect(!!(x), 1)
143 
151  #define unlikely(x) __builtin_expect(!!(x), 0)
152 
159  #define PACK(decl) decl __attribute__((__packed__))
160 #else
161  #define likely(x) (x)
162  #define unlikely(x) (x)
163  #define PACK(decl) __pragma(pack(push, 1)) decl __pragma(pack(pop))
164 #endif
165 
166 // constants section
167 
171 #define EXTERN_PRINTF extern int printf(const char *const _Format, ...)
172 
176 #define PCC_SQRT_ACCURACY 8
177 
181 #define MAX_FACTORIAL_64 20
182 
186 #define MAX_FACTORIAL_128 34
187 
191 #define MAX_POW_10_16 10000U
192 
196 #define POW_OF_MAX_POW_10_16 4
197 
201 #define MAX_POW_10_32 1000000000UL
202 
206 #define POW_OF_MAX_POW_10_32 9
207 
211 #define MAX_POW_10_64 10000000000000000000ULL
212 
216 #define POW_OF_MAX_POW_10_64 19
217 
221 #define MAX_POW_10_128 ((uintmax_t) MAX_POW_10_64 * (uintmax_t) MAX_POW_10_64)
222 
226 #define POW_OF_MAX_POW_10_128 38
227 
228 #endif