1 /*************************************************************************/ /*!
3 @Title Common header containing type definitions for portability
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @Description Contains variable and structure definitions. Any platform
6 specific types should be defined in this file.
7 @License Dual MIT/GPLv2
9 The contents of this file are subject to the MIT license as set out below.
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
18 The above copyright notice and this permission notice shall be included in
19 all copies or substantial portions of the Software.
21 Alternatively, the contents of this file may be used under the terms of
22 the GNU General Public License Version 2 ("GPL") in which case the provisions
23 of GPL are applicable instead of those above.
25 If you wish to allow use of your version of this file only under the terms of
26 GPL, and not to allow others to use your version of this file under the terms
27 of the MIT license, indicate your decision by deleting the provisions above
28 and replace them with the notice and other provisions required by GPL as set
29 out in the file called "GPL-COPYING" included in this distribution. If you do
30 not delete the provisions above, a recipient may use your version of this file
31 under the terms of either the MIT license or GPL.
33 This License is also included in this distribution in the file called
36 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
37 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
39 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
40 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
41 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
42 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
43 */ /**************************************************************************/
45 #if !defined (__IMG_DEFS_H__)
46 #define __IMG_DEFS_H__
50 #include "img_types.h"
52 #if defined (NO_INLINE_FUNCS)
56 #if defined (__cplusplus)
58 #define FORCE_INLINE inline
61 #define INLINE __inline
63 #if defined(UNDER_WDDM) && defined(_X86_)
64 #define FORCE_INLINE __forceinline
66 #define FORCE_INLINE static __inline
72 /* Use this in any file, or use attributes under GCC - see below */
73 #ifndef PVR_UNREFERENCED_PARAMETER
74 #define PVR_UNREFERENCED_PARAMETER(param) ((void)(param))
77 /*! Macro used to check structure size and alignment at compile time. */
78 #define BLD_ASSERT(expr, file) _impl_ASSERT_LINE(expr,__LINE__,file)
79 #define _impl_JOIN(a,b) a##b
80 #define _impl_ASSERT_LINE(expr, line, file) \
81 typedef char _impl_JOIN(build_assertion_failed_##file##_,line)[2*!!(expr)-1];
83 /*! Macro to calculate the n-byte aligned value from that supplied rounding up.
84 * n must be a power of two.
86 * Both arguments should be of a type with the same size otherwise the macro may
87 * cut off digits, e.g. imagine a 64 bit address in _x and a 32 bit value in _n.
89 #define PVR_ALIGN(_x, _n) (((_x)+((_n)-1)) & ~((_n)-1))
92 /* The best way to supress unused parameter warnings using GCC is to use a
93 * variable attribute. Place the unref__ between the type and name of an
94 * unused parameter in a function parameter list, eg `int unref__ var'. This
95 * should only be used in GCC build environments, for example, in files that
96 * compile only on Linux. Other files should use UNREFERENCED_PARAMETER */
98 #define unref__ __attribute__ ((unused))
104 #define IMG_CALLCONV __stdcall
106 #define IMG_EXPORT __declspec(dllexport)
107 #define IMG_RESTRICT __restrict
108 #define C_CALLCONV __cdecl
110 /* IMG_IMPORT is defined as IMG_EXPORT so that headers and implementations match.
111 * Some compilers require the header to be declared IMPORT, while the implementation is declared EXPORT
113 #define IMG_IMPORT IMG_EXPORT
115 #if defined(UNDER_WDDM)
117 #if defined (UNDER_MSBUILD)
118 _CRTIMP __declspec(noreturn) void __cdecl abort(void);
120 _CRTIMP void __cdecl abort(void);
123 #if defined(EXIT_ON_ABORT)
124 #define IMG_ABORT() exit(1);
126 #define IMG_ABORT() abort();
128 // #define IMG_ABORT() img_abort()
129 #endif /* UNDER_WDDM */
131 #if defined(LINUX) || defined(__METAG) || defined(__QNXNTO__)
135 #if defined(__linux__) || defined(__QNXNTO__)
136 #define IMG_INTERNAL __attribute__((visibility("hidden")))
140 #define IMG_EXPORT __attribute__((visibility("default")))
142 #define IMG_RESTRICT __restrict__
145 #error("define an OS")
149 // Use default definition if not overridden
151 #if defined(EXIT_ON_ABORT)
152 #define IMG_ABORT() exit(1)
154 #define IMG_ABORT() abort()
158 #if defined(__GNUC__)
159 #define IMG_FORMAT_PRINTF(x,y) __attribute__((format(printf,x,y)))
161 #define IMG_FORMAT_PRINTF(x,y)
164 #if defined(__GNUC__)
165 #define IMG_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
167 #define IMG_WARN_UNUSED_RESULT
170 #if defined(_MSC_VER) || defined(CC_ARM)
171 #define IMG_NORETURN __declspec(noreturn)
173 #if defined(__GNUC__)
174 #define IMG_NORETURN __attribute__((noreturn))
180 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
181 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
183 /* Get a structures address from the address of a member */
184 #define IMG_CONTAINER_OF(ptr, type, member) \
185 (type *) ((IMG_UINT8 *) (ptr) - offsetof(type, member))
187 /* The number of elements in a fixed-sized array, IMGs ARRAY_SIZE macro */
188 #define IMG_ARR_NUM_ELEMS(ARR) \
189 (sizeof(ARR) / sizeof((ARR)[0]))
191 /* To guarantee that __func__ can be used, define it as a macro here if it
192 isn't already provided by the compiler. */
193 #if defined(_MSC_VER)
194 #define __func__ __FUNCTION__
197 #if defined(__cplusplus)
199 * Disallow use of copy and assignment operator within a class.
200 * Should be placed under private. */
201 #define IMG_DISALLOW_COPY_AND_ASSIGN(C) \
203 void operator=(const C&)
206 #if defined(SUPPORT_PVR_VALGRIND)
207 #if !defined(__METAG)
208 #include "/usr/include/valgrind/memcheck.h"
210 #define VALGRIND_HEADER_PRESENT
212 #define VG_MARK_INITIALIZED(pvData,ui32Size) VALGRIND_MAKE_MEM_DEFINED(pvData,ui32Size)
214 #define VG_MARK_INITIALIZED(pvData,ui32Size) do { } while(0)
218 #define VG_MARK_INITIALIZED(pvData,ui32Size) do { } while(0)
222 #endif /* #if !defined (__IMG_DEFS_H__) */
223 /*****************************************************************************
224 End of file (IMG_DEFS.H)
225 *****************************************************************************/