1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/************************************************************************** 2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas. 4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved. 5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the 8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including 9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish, 10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to 11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to 12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions: 13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the 15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions 16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software. 17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/ 27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef P_COMPILER_H 29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define P_COMPILER_H 30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "p_config.h" 33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdlib.h> 35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <string.h> 36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stddef.h> 37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdarg.h> 38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <limits.h> 39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(_WIN32) && !defined(__WIN32__) 42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __WIN32__ 43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(_MSC_VER) 46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Avoid 'expression is always true' warning */ 48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#pragma warning(disable: 4296) 49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* _MSC_VER */ 51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Alternative stdint.h and stdbool.h headers are supplied in include/c99 for 55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * systems that lack it. 56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef __STDC_LIMIT_MACROS 58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define __STDC_LIMIT_MACROS 1 59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdint.h> 61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <stdbool.h> 62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __cplusplus 65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern "C" { 66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(__HAIKU__) && !defined(__USE_MISC) 70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if !defined(PIPE_OS_ANDROID) 71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef unsigned int uint; 72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef unsigned short ushort; 74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef unsigned char ubyte; 76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef unsigned char boolean; 78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef TRUE 79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define TRUE true 80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef FALSE 82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define FALSE false 83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef va_copy 86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef __va_copy 87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define va_copy(dest, src) __va_copy((dest), (src)) 88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else 89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define va_copy(dest, src) (dest) = (src) 90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Function inlining */ 94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef inline 95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# ifdef __cplusplus 96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* C++ supports inline keyword */ 97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__GNUC__) 98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define inline __inline__ 99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(_MSC_VER) 100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define inline __inline 101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__ICL) 102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define inline __inline 103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__INTEL_COMPILER) 104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* Intel compiler supports inline keyword */ 105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100) 106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define inline __inline 107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__SUNPRO_C) && defined(__C99FEATURES__) 108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* C99 supports inline keyword */ 109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif (__STDC_VERSION__ >= 199901L) 110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* C99 supports inline keyword */ 111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define inline 113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef INLINE 116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define INLINE inline 117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Forced function inlining */ 120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef ALWAYS_INLINE 121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# ifdef __GNUC__ 122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ALWAYS_INLINE inline __attribute__((always_inline)) 123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(_MSC_VER) 124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ALWAYS_INLINE __forceinline 125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define ALWAYS_INLINE INLINE 127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* 131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Define the C99 restrict keyword. 132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * See also: 134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * - http://cellperformance.beyond3d.com/articles/2006/05/demystifying-the-restrict-keyword.html 135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef restrict 137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if (__STDC_VERSION__ >= 199901L) 138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* C99 */ 139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__SUNPRO_C) && defined(__C99FEATURES__) 140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* C99 */ 141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(__GNUC__) 142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define restrict __restrict__ 143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(_MSC_VER) 144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define restrict __restrict 145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define restrict /* */ 147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Function visibility */ 152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef PUBLIC 153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) 154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define PUBLIC __attribute__((visibility("default"))) 155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(_MSC_VER) 156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define PUBLIC __declspec(dllexport) 157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define PUBLIC 159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* The __FUNCTION__ gcc variable is generally only used for debugging. 164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If we're not using gcc, define __FUNCTION__ as a cpp symbol here. 165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef __FUNCTION__ 167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if !defined(__GNUC__) 168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if (__STDC_VERSION__ >= 199901L) /* C99 */ || \ 169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (defined(__SUNPRO_C) && defined(__C99FEATURES__)) 170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define __FUNCTION__ __func__ 171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define __FUNCTION__ "<unknown>" 173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if defined(_MSC_VER) && _MSC_VER < 1300 176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define __FUNCTION__ "<unknown>" 177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef __func__ 180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if (__STDC_VERSION__ >= 199901L) || \ 181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org (defined(__SUNPRO_C) && defined(__C99FEATURES__)) 182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org /* __func__ is part of C99 */ 183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# elif defined(_MSC_VER) 184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if _MSC_VER >= 1300 185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define __func__ __FUNCTION__ 186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define __func__ "<unknown>" 188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* This should match linux gcc cdecl semantics everywhere, so that we 195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * just codegen one calling convention on all platforms. 196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifdef _MSC_VER 198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_CDECL __cdecl 199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else 200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_CDECL 201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__GNUC__) 206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_DEPRECATED __attribute__((__deprecated__)) 207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else 208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_DEPRECATED 209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Macros for data alignment. */ 214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) || defined(__SUNPRO_CC) 215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Type-Attributes.html */ 217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_TYPE(_alignment, _type) _type __attribute__((aligned(_alignment))) 218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* See http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gcc/Variable-Attributes.html */ 220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_VAR(_alignment) __attribute__((aligned(_alignment))) 221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if (__GNUC__ > 4 || (__GNUC__ == 4 &&__GNUC_MINOR__>1)) && !defined(PIPE_ARCH_X86_64) 223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_STACK __attribute__((force_align_arg_pointer)) 224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else 225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_STACK 226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(_MSC_VER) 229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* See http://msdn.microsoft.com/en-us/library/83ythb65.aspx */ 231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_TYPE(_alignment, _type) __declspec(align(_alignment)) _type 232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_VAR(_alignment) __declspec(align(_alignment)) 233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_STACK 235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(SWIG) 237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_TYPE(_alignment, _type) _type 239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_VAR(_alignment) 240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_ALIGN_STACK 242f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 243f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else 244f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 245f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#error "Unsupported compiler" 246f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 247f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 248f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 249f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 250f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__GNUC__) 251f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 252f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_READ_WRITE_BARRIER() __asm__("":::"memory") 253f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 254f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(_MSC_VER) 255f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 256f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid _ReadWriteBarrier(void); 257f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#pragma intrinsic(_ReadWriteBarrier) 258f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_READ_WRITE_BARRIER() _ReadWriteBarrier() 259f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 260f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) 261f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 262f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_READ_WRITE_BARRIER() __machine_rw_barrier() 263f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 264f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#else 265f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 266f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#warning "Unsupported compiler" 267f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define PIPE_READ_WRITE_BARRIER() /* */ 268f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 269f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 270f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 271f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 272f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* You should use these macros to mark if blocks where the if condition 273f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * is either likely to be true, or unlikely to be true. 274f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 275f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * This will inform human readers of this fact, and will also inform 276f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the compiler, who will in turn inform the CPU. 277f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 278f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * CPUs often start executing code inside the if or the else blocks 279f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without knowing whether the condition is true or not, and will have 280f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * to throw the work away if they find out later they executed the 281f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * wrong part of the if. 282f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 283f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * If these macros are used, the CPU is more likely to correctly predict 284f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the right path, and will avoid speculatively executing the wrong branch, 285f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * thus not throwing away work, resulting in better performance. 286f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 287f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * In light of this, it is also a good idea to mark as "likely" a path 288f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * which is not necessarily always more likely, but that will benefit much 289f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * more from performance improvements since it is already much faster than 290f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the other path, or viceversa with "unlikely". 291f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 292f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Example usage: 293f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * if(unlikely(do_we_need_a_software_fallback())) 294f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * do_software_fallback(); 295f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * else 296f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * render_with_gpu(); 297f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 298f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The macros follow the Linux kernel convention, and more examples can 299f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * be found there. 300f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * 301f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Note that profile guided optimization can offer better results, but 302f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * needs an appropriate coverage suite and does not inform human readers. 303f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 304f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef likely 305f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# if defined(__GNUC__) 306f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define likely(x) __builtin_expect(!!(x), 1) 307f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define unlikely(x) __builtin_expect(!!(x), 0) 308f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# else 309f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define likely(x) (x) 310f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# define unlikely(x) (x) 311f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org# endif 312f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 313f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 314f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 315f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/** 316f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Static (compile-time) assertion. 317f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Basically, use COND to dimension an array. If COND is false/zero the 318f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * array size will be -1 and we'll get a compilation error. 319f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */ 320f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define STATIC_ASSERT(COND) \ 321f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org do { \ 322f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org typedef int static_assertion_failed[(!!(COND))*2-1]; \ 323f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org } while (0) 324f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 325f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 326f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#if defined(__cplusplus) 327f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org} 328f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif 329f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 330f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org 331f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* P_COMPILER_H */ 332