Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/wabt/config.h
1 /* 2 * Copyright 2016 WebAssembly Community Group participants 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef WABT_CONFIG_H_ 18 #define WABT_CONFIG_H_ 19 20 #include <stdint.h> 21 #include <stdlib.h> 22 23 #define WABT_VERSION_STRING "1.0.36" 24 25 /* #undef WABT_DEBUG */ 26 27 /* TODO(binji): nice way to define these with WABT_ prefix? */ 28 29 /* Whether <alloca.h> is available */ 30 #define HAVE_ALLOCA_H 1 31 32 /* Whether <unistd.h> is available */ 33 #define HAVE_UNISTD_H 1 34 35 /* Whether snprintf is defined by stdio.h */ 36 #define HAVE_SNPRINTF 1 37 38 /* Whether ssize_t is defined by stddef.h */ 39 #define HAVE_SSIZE_T 1 40 41 /* Whether strcasecmp is defined by strings.h */ 42 #define HAVE_STRCASECMP 1 43 44 /* Whether ENABLE_VIRTUAL_TERMINAL_PROCESSING is defined by windows.h */ 45 #define HAVE_WIN32_VT100 0 46 47 /* Whether the target architecture is big endian */ 48 #define WABT_BIG_ENDIAN 0 49 50 /* Whether <openssl/sha.h> is available */ 51 #define HAVE_OPENSSL_SHA_H 1 52 53 #define COMPILER_IS_CLANG 0 54 #define COMPILER_IS_GNU 1 55 #define COMPILER_IS_MSVC 0 56 57 #define WITH_EXCEPTIONS 0 58 59 #define SIZEOF_SIZE_T 8 60 61 #if HAVE_ALLOCA_H 62 #include <alloca.h> 63 #elif COMPILER_IS_MSVC 64 #include <malloc.h> 65 #define alloca _alloca 66 #elif defined(__MINGW32__) 67 #include <malloc.h> 68 #endif 69 70 #if COMPILER_IS_CLANG || COMPILER_IS_GNU 71 72 #define WABT_UNLIKELY(x) __builtin_expect(!!(x), 0) 73 #define WABT_LIKELY(x) __builtin_expect(!!(x), 1) 74 75 #define WABT_VECTORCALL 76 77 #if __MINGW32__ 78 // mingw defaults to printf format specifier being ms_printf (which doesn't 79 // understand 'llu', etc.) We always want gnu_printf, and force mingw to always 80 // use mingw_printf, mingw_vprintf, etc. 81 #define WABT_PRINTF_FORMAT(format_arg, first_arg) \ 82 __attribute__((format(gnu_printf, (format_arg), (first_arg)))) 83 #else 84 #define WABT_PRINTF_FORMAT(format_arg, first_arg) \ 85 __attribute__((format(printf, (format_arg), (first_arg)))) 86 #endif 87 88 #ifdef __cplusplus 89 #define WABT_STATIC_ASSERT(x) static_assert((x), #x) 90 #else 91 #define WABT_STATIC_ASSERT(x) _Static_assert((x), #x) 92 #endif 93 94 #elif COMPILER_IS_MSVC 95 96 #include <intrin.h> 97 #include <string.h> 98 99 #define WABT_STATIC_ASSERT(x) _STATIC_ASSERT(x) 100 #define WABT_UNLIKELY(x) (x) 101 #define WABT_LIKELY(x) (x) 102 #define WABT_PRINTF_FORMAT(format_arg, first_arg) 103 104 #define WABT_VECTORCALL __vectorcall 105 106 #else 107 108 #error unknown compiler 109 110 #endif 111 112 #define WABT_UNREACHABLE abort() 113 114 #ifdef __cplusplus 115 116 namespace wabt { 117 118 #if COMPILER_IS_CLANG || COMPILER_IS_GNU 119 120 inline int Clz(unsigned x) { return x ? __builtin_clz(x) : sizeof(x) * 8; } 121 inline int Clz(unsigned long x) { return x ? __builtin_clzl(x) : sizeof(x) * 8; } 122 inline int Clz(unsigned long long x) { return x ? __builtin_clzll(x) : sizeof(x) * 8; } 123 124 inline int Ctz(unsigned x) { return x ? __builtin_ctz(x) : sizeof(x) * 8; } 125 inline int Ctz(unsigned long x) { return x ? __builtin_ctzl(x) : sizeof(x) * 8; } 126 inline int Ctz(unsigned long long x) { return x ? __builtin_ctzll(x) : sizeof(x) * 8; } 127 128 inline int Popcount(uint8_t x) { return __builtin_popcount(x); } 129 inline int Popcount(unsigned x) { return __builtin_popcount(x); } 130 inline int Popcount(unsigned long x) { return __builtin_popcountl(x); } 131 inline int Popcount(unsigned long long x) { return __builtin_popcountll(x); } 132 133 #elif COMPILER_IS_MSVC 134 135 #if _M_IX86 136 inline unsigned long LowDword(unsigned __int64 value) { 137 return (unsigned long)value; 138 } 139 140 inline unsigned long HighDword(unsigned __int64 value) { 141 unsigned long high; 142 memcpy(&high, (unsigned char*)&value + sizeof(high), sizeof(high)); 143 return high; 144 } 145 #endif 146 147 inline int Clz(unsigned long mask) { 148 if (mask == 0) 149 return 32; 150 151 unsigned long index; 152 _BitScanReverse(&index, mask); 153 return sizeof(unsigned long) * 8 - (index + 1); 154 } 155 156 inline int Clz(unsigned int mask) { 157 return Clz((unsigned long)mask); 158 } 159 160 inline int Clz(unsigned __int64 mask) { 161 #if _M_X64 || _M_ARM64 162 if (mask == 0) 163 return 64; 164 165 unsigned long index; 166 _BitScanReverse64(&index, mask); 167 return sizeof(unsigned __int64) * 8 - (index + 1); 168 #elif _M_IX86 169 int result = Clz(HighDword(mask)); 170 if (result == 32) 171 result += Clz(LowDword(mask)); 172 173 return result; 174 #else 175 #error unexpected architecture 176 #endif 177 } 178 179 inline int Ctz(unsigned long mask) { 180 if (mask == 0) 181 return 32; 182 183 unsigned long index; 184 _BitScanForward(&index, mask); 185 return index; 186 } 187 188 inline int Ctz(unsigned int mask) { 189 return Ctz((unsigned long)mask); 190 } 191 192 inline int Ctz(unsigned __int64 mask) { 193 #if _M_X64 || _M_ARM64 194 if (mask == 0) 195 return 64; 196 197 unsigned long index; 198 _BitScanForward64(&index, mask); 199 return index; 200 #elif _M_IX86 201 int result = Ctz(LowDword(mask)); 202 if (result == 32) 203 result += Ctz(HighDword(mask)); 204 205 return result; 206 #else 207 #error unexpected architecture 208 #endif 209 } 210 211 #if _M_ARM64 212 //https://stackoverflow.com/a/70012905 213 template <typename T> 214 int BrianKernighanPopcount(T value) { 215 int count; 216 for(count = 0; value; count++) 217 { 218 value &= value - 1; 219 } 220 return count; 221 } 222 #endif 223 224 inline int Popcount(unsigned long value) { 225 #if _M_X64 || _M_IX86 226 return __popcnt(value); 227 #elif _M_ARM64 228 return BrianKernighanPopcount(value); 229 #else 230 #error unexpected architecture 231 #endif 232 } 233 234 inline int Popcount(uint8_t value) { 235 return Popcount((unsigned long)value); 236 } 237 238 inline int Popcount(unsigned int value) { 239 return Popcount((unsigned long)value); 240 } 241 242 inline int Popcount(unsigned __int64 value) { 243 #if _M_X64 244 return __popcnt64(value); 245 #elif _M_IX86 246 return Popcount(HighDword(value)) + Popcount(LowDword(value)); 247 #elif _M_ARM64 248 return BrianKernighanPopcount(value); 249 #else 250 #error unexpected architecture 251 #endif 252 } 253 254 #else 255 256 #error unknown compiler 257 258 #endif 259 260 } // namespace wabt 261 262 #if COMPILER_IS_MSVC 263 264 /* print format specifier for size_t */ 265 #if SIZEOF_SIZE_T == 4 266 #define PRIzd "d" 267 #define PRIzx "x" 268 #elif SIZEOF_SIZE_T == 8 269 #define PRIzd "I64d" 270 #define PRIzx "I64x" 271 #else 272 #error "weird sizeof size_t" 273 #endif 274 275 #elif COMPILER_IS_CLANG || COMPILER_IS_GNU 276 277 /* print format specifier for size_t */ 278 #define PRIzd "zd" 279 #define PRIzx "zx" 280 281 #else 282 283 #error unknown compiler 284 285 #endif 286 287 #if HAVE_SNPRINTF 288 #define wabt_snprintf snprintf 289 #elif COMPILER_IS_MSVC 290 /* can't just use _snprintf because it doesn't always null terminate */ 291 #include <cstdarg> 292 int wabt_snprintf(char* str, size_t size, const char* format, ...); 293 #else 294 #error no snprintf 295 #endif 296 297 #if COMPILER_IS_MSVC 298 /* can't just use vsnprintf because it doesn't always null terminate */ 299 int wabt_vsnprintf(char* str, size_t size, const char* format, va_list ap); 300 #else 301 #define wabt_vsnprintf vsnprintf 302 #endif 303 304 #if !HAVE_SSIZE_T 305 #if COMPILER_IS_MSVC 306 /* define ssize_t identically to how LLVM does, to avoid conflicts if including both */ 307 #if defined(_WIN64) 308 typedef signed __int64 ssize_t; 309 #else 310 typedef signed int ssize_t; 311 #endif /* _WIN64 */ 312 #else 313 typedef long ssize_t; 314 #endif 315 #endif 316 317 #if !HAVE_STRCASECMP 318 #if COMPILER_IS_MSVC 319 #define strcasecmp _stricmp 320 #else 321 #error no strcasecmp 322 #endif 323 #endif 324 325 double wabt_convert_uint64_to_double(uint64_t x); 326 float wabt_convert_uint64_to_float(uint64_t x); 327 double wabt_convert_int64_to_double(int64_t x); 328 float wabt_convert_int64_to_float(int64_t x); 329 330 #endif // __cplusplus 331 332 #endif /* WABT_CONFIG_H_ */