p_compiler.h revision 938d9d596324e411fde5312f2bb65b444c502c37
1/**************************************************************************
2 *
3 * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <stdlib.h>
35#include <string.h>
36
37
38#if defined(_WIN32) && !defined(__WIN32__)
39#define __WIN32__
40#endif
41
42#if defined(_MSC_VER) && !defined(__MSC__)
43#define __MSC__
44#endif
45
46
47#if defined(__MSC__)
48
49/* Avoid 'expression is always true' warning */
50#pragma warning(disable: 4296)
51
52#endif /* __MSC__ */
53
54
55#if defined(__MSC__)
56
57typedef __int8             int8_t;
58typedef unsigned __int8    uint8_t;
59typedef __int16            int16_t;
60typedef unsigned __int16   uint16_t;
61typedef __int32            int32_t;
62typedef unsigned __int32   uint32_t;
63typedef __int64            int64_t;
64typedef unsigned __int64   uint64_t;
65
66#if defined(_WIN64)
67typedef __int64            intptr_t;
68typedef unsigned __int64   uintptr_t;
69#else
70typedef __int32            intptr_t;
71typedef unsigned __int32   uintptr_t;
72#endif
73
74#ifndef __cplusplus
75#define false   0
76#define true    1
77#define bool    _Bool
78typedef int     _Bool;
79#define __bool_true_false_are_defined   1
80#endif /* !__cplusplus */
81
82#else
83#include <stdint.h>
84#include <stdbool.h>
85#endif
86
87
88typedef unsigned int       uint;
89typedef unsigned char      ubyte;
90typedef unsigned short     ushort;
91typedef uint64_t           uint64;
92
93#if 0
94#define boolean bool
95#else
96typedef unsigned char boolean;
97#endif
98#ifndef TRUE
99#define TRUE  true
100#endif
101#ifndef FALSE
102#define FALSE false
103#endif
104
105
106/* Function inlining */
107#if defined(__GNUC__)
108#  define INLINE __inline__
109#elif defined(__MSC__)
110#  define INLINE __inline
111#elif defined(__ICL)
112#  define INLINE __inline
113#elif defined(__INTEL_COMPILER)
114#  define INLINE inline
115#elif defined(__WATCOMC__) && (__WATCOMC__ >= 1100)
116#  define INLINE __inline
117#else
118#  define INLINE
119#endif
120
121
122/* This should match linux gcc cdecl semantics everywhere, so that we
123 * just codegen one calling convention on all platforms.
124 */
125#ifdef WIN32
126#define PIPE_CDECL __cdecl
127#else
128#define PIPE_CDECL
129#endif
130
131
132
133#if defined __GNUC__
134#define ALIGN16_DECL(TYPE, NAME, SIZE)  TYPE NAME##___aligned[SIZE] __attribute__(( aligned( 16 ) ))
135#define ALIGN16_ASSIGN(NAME) NAME##___aligned
136#define ALIGN16_ATTRIB  __attribute__(( aligned( 16 ) ))
137#else
138#define ALIGN16_DECL(TYPE, NAME, SIZE)  TYPE NAME##___unaligned[SIZE + 1]
139#define ALIGN16_ASSIGN(NAME) align16(NAME##___unaligned)
140#define ALIGN16_ATTRIB
141#endif
142
143
144
145/**
146 * For calling code-gen'd functions, phase out in favor of
147 * PIPE_CDECL, above, which really means cdecl on all platforms, not
148 * like the below...
149 */
150#if !defined(XSTDCALL)
151#if defined(WIN32)
152#define XSTDCALL __stdcall      /* phase this out */
153#else
154#define XSTDCALL                /* XXX: NOTE! not STDCALL! */
155#endif
156#endif
157
158
159#endif /* P_COMPILER_H */
160