1 /************************************************************************** 2 * 3 * Copyright 2007-2008 VMware, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 #ifndef P_COMPILER_H 29 #define P_COMPILER_H 30 31 32 #include "c99_compat.h" /* inline, __func__, etc. */ 33 34 #include "p_config.h" 35 36 #include "util/macros.h" 37 38 #include <stdlib.h> 39 #include <string.h> 40 #include <stddef.h> 41 #include <stdarg.h> 42 #include <limits.h> 43 /* (virglrenderer) To get uint typedef with musl */ 44 #include <sys/types.h> 45 46 47 #if defined(_WIN32) && !defined(__WIN32__) 48 #define __WIN32__ 49 #endif 50 51 #if defined(_MSC_VER) 52 53 #include <intrin.h> 54 55 /* Avoid 'expression is always true' warning */ 56 #pragma warning(disable: 4296) 57 58 #endif /* _MSC_VER */ 59 60 61 /* 62 * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for 63 * systems that lack it. 64 */ 65 #include <stdint.h> 66 #include <stdbool.h> 67 68 69 #ifdef __cplusplus 70 extern "C" { 71 #endif 72 73 74 #if !defined(__HAIKU__) && !defined(__USE_MISC) 75 #if !defined(PIPE_OS_ANDROID) 76 typedef unsigned int uint; 77 #endif 78 typedef unsigned short ushort; 79 #endif 80 typedef unsigned char ubyte; 81 82 typedef unsigned char boolean; 83 #ifndef TRUE 84 #define TRUE true 85 #endif 86 #ifndef FALSE 87 #define FALSE false 88 #endif 89 90 #ifndef va_copy 91 #ifdef __va_copy 92 #define va_copy(dest, src) __va_copy((dest), (src)) 93 #else 94 #define va_copy(dest, src) (dest) = (src) 95 #endif 96 #endif 97 98 99 /* XXX: Use standard `__func__` instead */ 100 #ifndef __FUNCTION__ 101 # define __FUNCTION__ __func__ 102 #endif 103 104 105 /* This should match linux gcc cdecl semantics everywhere, so that we 106 * just codegen one calling convention on all platforms. 107 */ 108 #ifdef _MSC_VER 109 #define PIPE_CDECL __cdecl 110 #else 111 #define PIPE_CDECL 112 #endif 113 114 115 116 #if defined(__GNUC__) 117 #define PIPE_DEPRECATED __attribute__((__deprecated__)) 118 #else 119 #define PIPE_DEPRECATED 120 #endif 121 122 123 124 /* Macros for data alignment. */ 125 #if defined(__GNUC__) 126 127 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */ 128 #define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment))) 129 130 /* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */ 131 #define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment))) 132 133 #if defined(__GNUC__) && defined(PIPE_ARCH_X86) 134 #define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer)) 135 #else 136 #define PIPE_ALIGN_STACK 137 #endif 138 139 #elif defined(_MSC_VER) 140 141 /* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */ 142 #define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type 143 #define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment)) 144 145 #define PIPE_ALIGN_STACK 146 147 #elif defined(SWIG) 148 149 #define PIPE_ALIGN_TYPE(_alignment, _type) _type 150 #define PIPE_ALIGN_VAR(_alignment) 151 152 #define PIPE_ALIGN_STACK 153 154 #else 155 156 #error "Unsupported compiler" 157 158 #endif 159 160 161 #if defined(__GNUC__) 162 163 #define PIPE_READ_WRITE_BARRIER() __asm__("":::"memory") 164 165 #elif defined(_MSC_VER) 166 167 #define PIPE_READ_WRITE_BARRIER() _ReadWriteBarrier() 168 169 #else 170 171 #warning "Unsupported compiler" 172 #define PIPE_READ_WRITE_BARRIER() /* */ 173 174 #endif 175 176 #if defined(__cplusplus) 177 } 178 #endif 179 180 181 #endif /* P_COMPILER_H */ 182