compiler.h
1 /* 2 * Copyright (C) 2018-2020, Advanced Micro Devices, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without modification, 5 * are permitted provided that the following conditions are met: 6 * 1. Redistributions of source code must retain the above copyright notice, 7 * this list of conditions and the following disclaimer. 8 * 2. Redistributions in binary form must reproduce the above copyright notice, 9 * this list of conditions and the following disclaimer in the documentation 10 * and/or other materials provided with the distribution. 11 * 3. Neither the name of the copyright holder nor the names of its contributors 12 * may be used to endorse or promote products derived from this software without 13 * specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 21 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * 26 */ 27 28 #ifndef __AMD_LIBM_COMPILER_H__ 29 #define __AMD_LIBM_COMPILER_H__ 30 31 /* 32 To check for which OS the code is compiled: 33 Linux and Linux-derived __linux__ 34 Android __ANDROID__ (implies __linux__) 35 Linux (non-Android) __linux__ && !__ANDROID__ 36 Darwin (Mac OS X and iOS) __APPLE__ 37 Akaros (http://akaros.org) __ros__ 38 Windows _WIN32 39 Windows 64 bit _WIN64 (implies _WIN32) 40 NaCL __native_client__ 41 AsmJS __asmjs__ 42 Fuschia __Fuchsia__ 43 44 45 To check which compiler is used: 46 Visual Studio _MSC_VER 47 gcc __GNUC__ 48 clang __clang__ 49 emscripten __EMSCRIPTEN__ (for asm.js and webassembly) 50 MinGW 32 __MINGW32__ 51 MinGW-w64 32bit __MINGW32__ 52 MinGW-w64 64bit __MINGW64__ 53 54 55 To check that this is gcc compiler version 5.1 or greater: 56 #if defined(__GNUC__) && (__GNUC___ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1)) 57 // this is gcc 5.1 or greater 58 #endif 59 60 */ 61 62 #if defined(__GNUC__) 63 64 #define PACKED __attribute__((packed)) 65 66 #define PACK_ALIGNED(x) __attribute__((packed, aligned(x))) 67 #define ALIGN(x) __attribute__((aligned ((x)))) 68 69 #define RODATA __attribute__((section (".rodata"))) 70 71 #define HIDDEN __attribute__ ((__visibility__ ("hidden"))) 72 #define NOINLINE __attribute__ ((noinline)) 73 #define likely(x) __builtin_expect (!!(x), 1) 74 #define unlikely(x) __builtin_expect (x, 0) 75 76 77 #define strong_alias(aliasname, name) _strong_alias(aliasname, name) 78 79 #define _strong_alias(al_name, name) \ 80 extern __typeof (name) al_name __attribute__ ((alias (#name))); 81 82 #define hidden_alias(al_name, name) \ 83 extern __typeof (name) al_name \ 84 __attribute__ ((alias (#al_name), visibility ("hidden"))); 85 86 #define OPT_O1 __attribute__((optimize("O1"))) 87 #define OPT_O2 __attribute__((optimize("O2"))) 88 #define OPT_O3 __attribute__((optimize("O3"))) 89 #define OPT_Og __attribute__((optimize("Og"))) 90 91 #define OPTIMIZE(x) __attribute__((optimize(x))) 92 #define NO_OPTIMIZE __attribute__((optimize("0")) 93 94 #define CONSTRUCTOR __attribute__((constructor)) 95 #define INITIALIZER(f) static void f(void) CONSTRUCTOR; static void f(void) 96 97 98 #define WEAK_LIBM_ALIAS(x, y) \ 99 asm("\n\t"".weak " STRINGIFY(x) \ 100 "\n\t"".set " STRINGIFY(x) ", " STRINGIFY(y) \ 101 "\n\t"); 102 103 #if defined(__clang__) 104 #define FALLTHROUGH 105 #undef NO_OPTIMIZE 106 #define NO_OPTIMIZE __attribute__((optnone)) 107 #else 108 #define FALLTHROUGH __attribute__((fallthrough)) 109 #undef NO_OPTIMIZE 110 #define NO_OPTIMIZE __attribute__((optimize("O0"))) 111 #endif 112 113 #elif defined(__MSVC) && defined(_MSC_VER) 114 #include <intrin.h> 115 #define CPUID __cpuid 116 #define CCALL __cdecl 117 #pragma section(".CRT$XCU",read) 118 #define INITIALIZER(f) static void __cdecl f(void); __declspec(allocate(".CRT$XCU")) void (__cdecl*f##_)(void) = f; static void __cdecl f(void) 119 120 121 #define FALLTHROUGH 122 123 #endif /* GCC */ 124 125 #endif /* AMD_LIBM_COMPILER_H */