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 "p_config.h" 33 34 #include "util/macros.h" 35 36 #include <limits.h> 37 #include <stdarg.h> 38 #include <stdbool.h> 39 #include <stddef.h> 40 #include <stdint.h> 41 #include <stdlib.h> 42 #include <string.h> 43 44 45 #if defined(_WIN32) && !defined(__WIN32__) 46 #define __WIN32__ 47 #endif 48 49 #if defined(_MSC_VER) 50 51 #include <intrin.h> 52 53 /* Avoid 'expression is always true' warning */ 54 #pragma warning(disable: 4296) 55 56 #endif /* _MSC_VER */ 57 58 59 #ifdef __cplusplus 60 extern "C" { 61 #endif 62 63 64 #if !defined(__HAIKU__) && !defined(__USE_MISC) 65 #if !defined(PIPE_OS_ANDROID) 66 typedef unsigned int uint; 67 #endif 68 typedef unsigned short ushort; 69 #endif 70 typedef unsigned char ubyte; 71 72 typedef unsigned char boolean; 73 #ifndef TRUE 74 #define TRUE true 75 #endif 76 #ifndef FALSE 77 #define FALSE false 78 #endif 79 80 #ifndef va_copy 81 #ifdef __va_copy 82 #define va_copy(dest, src) __va_copy((dest), (src)) 83 #else 84 #define va_copy(dest, src) (dest) = (src) 85 #endif 86 #endif 87 88 89 /* XXX: Use standard `__func__` instead */ 90 #ifndef __FUNCTION__ 91 # define __FUNCTION__ __func__ 92 #endif 93 94 95 /* This should match linux gcc cdecl semantics everywhere, so that we 96 * just codegen one calling convention on all platforms. 97 */ 98 #ifdef _MSC_VER 99 #define PIPE_CDECL __cdecl 100 #else 101 #define PIPE_CDECL 102 #endif 103 104 105 106 /* Macro for stack alignment. */ 107 #if defined(__GNUC__) && defined(PIPE_ARCH_X86) 108 #define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer)) 109 #else 110 #define PIPE_ALIGN_STACK 111 #endif 112 113 /** 114 * Declare a variable on its own cache line. 115 * 116 * This helps eliminate "False sharing" to make atomic operations 117 * on pipe_reference::count faster and/or access to adjacent fields faster. 118 * 119 * https://en.wikipedia.org/wiki/False_sharing 120 * 121 * CALLOC_STRUCT_CL or MALLOC_STRUCT_CL and FREE_CL should be used to allocate 122 * structures that contain this. 123 * 124 * NOTE: Don't use PIPE_ALIGN_VAR because it causes the whole structure to be 125 * aligned, but we only want to align the field. 126 */ 127 #define EXCLUSIVE_CACHELINE(decl) \ 128 union { char __cl_space[CACHE_LINE_SIZE]; \ 129 decl; } 130 131 #if defined(__cplusplus) 132 } 133 #endif 134 135 136 #endif /* P_COMPILER_H */ 137