1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 27 /** 28 * \file compiler.h 29 * Compiler-related stuff. 30 */ 31 32 33 #ifndef COMPILER_H 34 #define COMPILER_H 35 36 37 #include <assert.h> 38 #include <limits.h> 39 #include <stdarg.h> 40 #include <stdbool.h> 41 #include <stddef.h> 42 #include <stdint.h> 43 #include <stdlib.h> 44 #include <string.h> 45 46 #include "util/detect.h" 47 #include "util/macros.h" 48 49 /** 50 * Define CPU_TO_LE32 51 * Do not use these unless absolutely necessary! 52 * Try to use a runtime test instead. 53 * For now, only used by some DRI hardware drivers for color/texel packing. 54 */ 55 #if UTIL_ARCH_BIG_ENDIAN 56 #if defined(__linux__) 57 #include <byteswap.h> 58 #define CPU_TO_LE32( x ) bswap_32( x ) 59 #elif defined(__APPLE__) 60 #include <CoreFoundation/CFByteOrder.h> 61 #define CPU_TO_LE32( x ) CFSwapInt32HostToLittle( x ) 62 #elif defined(__OpenBSD__) 63 #include <sys/types.h> 64 #define CPU_TO_LE32( x ) htole32( x ) 65 #else /*__linux__ */ 66 #include <sys/endian.h> 67 #define CPU_TO_LE32( x ) bswap32( x ) 68 #endif /*__linux__*/ 69 #else 70 #define CPU_TO_LE32( x ) ( x ) 71 #endif 72 #define LE32_TO_CPU( x ) CPU_TO_LE32( x ) 73 74 75 /* Macro for stack alignment. */ 76 #if defined(__GNUC__) && DETECT_ARCH_X86 77 #define UTIL_ALIGN_STACK __attribute__((force_align_arg_pointer)) 78 #else 79 #define UTIL_ALIGN_STACK 80 #endif 81 82 #define IEEE_ONE 0x3f800000 83 84 #ifndef __has_attribute 85 # define __has_attribute(x) 0 86 #endif 87 88 #if defined(__has_cpp_attribute) && defined(__clang__) 89 /* We do not do the same trick as __has_attribute because parsing 90 * clang::fallthrough in the preprocessor fails in GCC. */ 91 # define HAS_CLANG_FALLTHROUGH __has_cpp_attribute(clang::fallthrough) 92 #else 93 # define HAS_CLANG_FALLTHROUGH 0 94 #endif 95 96 #if (defined(__cplusplus) && (__cplusplus >= 201703L)) || \ 97 (defined(__STDC_VERSION__) && (__STDC_VERSION__ > 201710L)) 98 /* Standard C++17/C23 attribute */ 99 #define FALLTHROUGH [[fallthrough]] 100 #elif HAS_CLANG_FALLTHROUGH 101 /* Clang++ specific */ 102 #define FALLTHROUGH [[clang::fallthrough]] 103 #elif __has_attribute(fallthrough) 104 /* Non-standard but supported by at least gcc and clang */ 105 #define FALLTHROUGH __attribute__((fallthrough)) 106 #else 107 #define FALLTHROUGH do { } while(0) 108 #endif 109 110 #ifdef __cplusplus 111 extern "C" { 112 #endif 113 114 #if !defined(__HAIKU__) && !defined(__USE_MISC) 115 #if !DETECT_OS_ANDROID 116 typedef unsigned int uint; 117 #endif 118 #endif 119 120 #if defined(__cplusplus) 121 } 122 #endif 123 124 #endif /* COMPILER_H */ 125