1bf215546Sopenharmony_ci/************************************************************************** 2bf215546Sopenharmony_ci * 3bf215546Sopenharmony_ci * Copyright 2007-2008 VMware, Inc. 4bf215546Sopenharmony_ci * All Rights Reserved. 5bf215546Sopenharmony_ci * 6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the 8bf215546Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 9bf215546Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 10bf215546Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 11bf215546Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 12bf215546Sopenharmony_ci * the following conditions: 13bf215546Sopenharmony_ci * 14bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the 15bf215546Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 16bf215546Sopenharmony_ci * of the Software. 17bf215546Sopenharmony_ci * 18bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21bf215546Sopenharmony_ci * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22bf215546Sopenharmony_ci * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23bf215546Sopenharmony_ci * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24bf215546Sopenharmony_ci * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25bf215546Sopenharmony_ci * 26bf215546Sopenharmony_ci **************************************************************************/ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#ifndef P_COMPILER_H 29bf215546Sopenharmony_ci#define P_COMPILER_H 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ci#include "p_config.h" 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_ci#include "util/macros.h" 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci#include <limits.h> 37bf215546Sopenharmony_ci#include <stdarg.h> 38bf215546Sopenharmony_ci#include <stdbool.h> 39bf215546Sopenharmony_ci#include <stddef.h> 40bf215546Sopenharmony_ci#include <stdint.h> 41bf215546Sopenharmony_ci#include <stdlib.h> 42bf215546Sopenharmony_ci#include <string.h> 43bf215546Sopenharmony_ci 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci#if defined(_WIN32) && !defined(__WIN32__) 46bf215546Sopenharmony_ci#define __WIN32__ 47bf215546Sopenharmony_ci#endif 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_ci#if defined(_MSC_VER) 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci#include <intrin.h> 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci/* Avoid 'expression is always true' warning */ 54bf215546Sopenharmony_ci#pragma warning(disable: 4296) 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci#endif /* _MSC_VER */ 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_ci#ifdef __cplusplus 60bf215546Sopenharmony_ciextern "C" { 61bf215546Sopenharmony_ci#endif 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci 64bf215546Sopenharmony_ci#if !defined(__HAIKU__) && !defined(__USE_MISC) 65bf215546Sopenharmony_ci#if !defined(PIPE_OS_ANDROID) 66bf215546Sopenharmony_citypedef unsigned int uint; 67bf215546Sopenharmony_ci#endif 68bf215546Sopenharmony_citypedef unsigned short ushort; 69bf215546Sopenharmony_ci#endif 70bf215546Sopenharmony_citypedef unsigned char ubyte; 71bf215546Sopenharmony_ci 72bf215546Sopenharmony_citypedef unsigned char boolean; 73bf215546Sopenharmony_ci#ifndef TRUE 74bf215546Sopenharmony_ci#define TRUE true 75bf215546Sopenharmony_ci#endif 76bf215546Sopenharmony_ci#ifndef FALSE 77bf215546Sopenharmony_ci#define FALSE false 78bf215546Sopenharmony_ci#endif 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_ci#ifndef va_copy 81bf215546Sopenharmony_ci#ifdef __va_copy 82bf215546Sopenharmony_ci#define va_copy(dest, src) __va_copy((dest), (src)) 83bf215546Sopenharmony_ci#else 84bf215546Sopenharmony_ci#define va_copy(dest, src) (dest) = (src) 85bf215546Sopenharmony_ci#endif 86bf215546Sopenharmony_ci#endif 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_ci/* XXX: Use standard `__func__` instead */ 90bf215546Sopenharmony_ci#ifndef __FUNCTION__ 91bf215546Sopenharmony_ci# define __FUNCTION__ __func__ 92bf215546Sopenharmony_ci#endif 93bf215546Sopenharmony_ci 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci/* This should match linux gcc cdecl semantics everywhere, so that we 96bf215546Sopenharmony_ci * just codegen one calling convention on all platforms. 97bf215546Sopenharmony_ci */ 98bf215546Sopenharmony_ci#ifdef _MSC_VER 99bf215546Sopenharmony_ci#define PIPE_CDECL __cdecl 100bf215546Sopenharmony_ci#else 101bf215546Sopenharmony_ci#define PIPE_CDECL 102bf215546Sopenharmony_ci#endif 103bf215546Sopenharmony_ci 104bf215546Sopenharmony_ci 105bf215546Sopenharmony_ci 106bf215546Sopenharmony_ci/* Macro for stack alignment. */ 107bf215546Sopenharmony_ci#if defined(__GNUC__) && defined(PIPE_ARCH_X86) 108bf215546Sopenharmony_ci#define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer)) 109bf215546Sopenharmony_ci#else 110bf215546Sopenharmony_ci#define PIPE_ALIGN_STACK 111bf215546Sopenharmony_ci#endif 112bf215546Sopenharmony_ci 113bf215546Sopenharmony_ci/** 114bf215546Sopenharmony_ci * Declare a variable on its own cache line. 115bf215546Sopenharmony_ci * 116bf215546Sopenharmony_ci * This helps eliminate "False sharing" to make atomic operations 117bf215546Sopenharmony_ci * on pipe_reference::count faster and/or access to adjacent fields faster. 118bf215546Sopenharmony_ci * 119bf215546Sopenharmony_ci * https://en.wikipedia.org/wiki/False_sharing 120bf215546Sopenharmony_ci * 121bf215546Sopenharmony_ci * CALLOC_STRUCT_CL or MALLOC_STRUCT_CL and FREE_CL should be used to allocate 122bf215546Sopenharmony_ci * structures that contain this. 123bf215546Sopenharmony_ci * 124bf215546Sopenharmony_ci * NOTE: Don't use PIPE_ALIGN_VAR because it causes the whole structure to be 125bf215546Sopenharmony_ci * aligned, but we only want to align the field. 126bf215546Sopenharmony_ci */ 127bf215546Sopenharmony_ci#define EXCLUSIVE_CACHELINE(decl) \ 128bf215546Sopenharmony_ci union { char __cl_space[CACHE_LINE_SIZE]; \ 129bf215546Sopenharmony_ci decl; } 130bf215546Sopenharmony_ci 131bf215546Sopenharmony_ci#if defined(__cplusplus) 132bf215546Sopenharmony_ci} 133bf215546Sopenharmony_ci#endif 134bf215546Sopenharmony_ci 135bf215546Sopenharmony_ci 136bf215546Sopenharmony_ci#endif /* P_COMPILER_H */ 137