Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1892 serge 1
/* cairo - a vector graphics library with display and print output
2
 *
3
 * Copyright © 2002 University of Southern California
4
 * Copyright © 2005 Red Hat, Inc.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it either under the terms of the GNU Lesser General Public
8
 * License version 2.1 as published by the Free Software Foundation
9
 * (the "LGPL") or, at your option, under the terms of the Mozilla
10
 * Public License Version 1.1 (the "MPL"). If you do not alter this
11
 * notice, a recipient may use your version of this file under either
12
 * the MPL or the LGPL.
13
 *
14
 * You should have received a copy of the LGPL along with this library
15
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
17
 * You should have received a copy of the MPL along with this library
18
 * in the file COPYING-MPL-1.1
19
 *
20
 * The contents of this file are subject to the Mozilla Public License
21
 * Version 1.1 (the "License"); you may not use this file except in
22
 * compliance with the License. You may obtain a copy of the License at
23
 * http://www.mozilla.org/MPL/
24
 *
25
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
26
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
27
 * the specific language governing rights and limitations.
28
 *
29
 * The Original Code is the cairo graphics library.
30
 *
31
 * The Initial Developer of the Original Code is University of Southern
32
 * California.
33
 *
34
 * Contributor(s):
35
 *	Carl D. Worth 
36
 */
37
 
38
#ifndef CAIRO_COMPILER_PRIVATE_H
39
#define CAIRO_COMPILER_PRIVATE_H
40
 
41
#include "cairo.h"
42
 
43
#if HAVE_CONFIG_H
44
#include "config.h"
45
#endif
46
 
47
/* Size in bytes of buffer to use off the stack per functions.
48
 * Mostly used by text functions.  For larger allocations, they'll
49
 * malloc(). */
50
#ifndef CAIRO_STACK_BUFFER_SIZE
51
#define CAIRO_STACK_BUFFER_SIZE (512 * sizeof (int))
52
#endif
53
 
54
#define CAIRO_STACK_ARRAY_LENGTH(T) (CAIRO_STACK_BUFFER_SIZE / sizeof(T))
55
 
56
/*
57
 * The goal of this block is to define the following macros for
58
 * providing faster linkage to functions in the public API for calls
59
 * from within cairo.
60
 *
61
 * slim_hidden_proto(f)
62
 * slim_hidden_proto_no_warn(f)
63
 *
64
 *   Declares `f' as a library internal function and hides the
65
 *   function from the global symbol table.  This macro must be
66
 *   expanded after `f' has been declared with a prototype but before
67
 *   any calls to the function are seen by the compiler.  The no_warn
68
 *   variant inhibits warnings about the return value being unused at
69
 *   call sites.  The macro works by renaming `f' to an internal name
70
 *   in the symbol table and hiding that.  As far as cairo internal
71
 *   calls are concerned they're calling a library internal function
72
 *   and thus don't need to bounce via the PLT.
73
 *
74
 * slim_hidden_def(f)
75
 *
76
 *   Exports `f' back to the global symbol table.  This macro must be
77
 *   expanded right after the function definition and only for symbols
78
 *   hidden previously with slim_hidden_proto().  The macro works by
79
 *   adding a global entry to the symbol table which points at the
80
 *   internal name of `f' created by slim_hidden_proto().
81
 *
82
 * Functions in the public API which aren't called by the library
83
 * don't need to be hidden and re-exported using the slim hidden
84
 * macros.
85
 */
86
#if __GNUC__ >= 3 && defined(__ELF__) && !defined(__sun)
87
# define slim_hidden_proto(name)		slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private
88
# define slim_hidden_proto_no_warn(name)	slim_hidden_proto1(name, slim_hidden_int_name(name)) cairo_private_no_warn
89
# define slim_hidden_def(name)			slim_hidden_def1(name, slim_hidden_int_name(name))
90
# define slim_hidden_int_name(name) INT_##name
91
# define slim_hidden_proto1(name, internal)				\
92
  extern __typeof (name) name						\
93
	__asm__ (slim_hidden_asmname (internal))
94
# define slim_hidden_def1(name, internal)				\
95
  extern __typeof (name) EXT_##name __asm__(slim_hidden_asmname(name))	\
96
	__attribute__((__alias__(slim_hidden_asmname(internal))))
97
# define slim_hidden_ulp		slim_hidden_ulp1(__USER_LABEL_PREFIX__)
98
# define slim_hidden_ulp1(x)		slim_hidden_ulp2(x)
99
# define slim_hidden_ulp2(x)		#x
100
# define slim_hidden_asmname(name)	slim_hidden_asmname1(name)
101
# define slim_hidden_asmname1(name)	slim_hidden_ulp #name
102
#else
103
# define slim_hidden_proto(name)		int _cairo_dummy_prototype(void)
104
# define slim_hidden_proto_no_warn(name)	int _cairo_dummy_prototype(void)
105
# define slim_hidden_def(name)			int _cairo_dummy_prototype(void)
106
#endif
107
 
108
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
109
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
110
	__attribute__((__format__(__printf__, fmt_index, va_index)))
111
#else
112
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index)
113
#endif
114
 
115
/* slim_internal.h */
116
#define CAIRO_HAS_HIDDEN_SYMBOLS 1
117
#if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) && defined(__ELF__) && !defined(__sun)
118
#define cairo_private_no_warn	__attribute__((__visibility__("hidden")))
119
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
120
#define cairo_private_no_warn	__hidden
121
#else /* not gcc >= 3.3 and not Sun Studio >= 8 */
122
#define cairo_private_no_warn
123
#undef CAIRO_HAS_HIDDEN_SYMBOLS
124
#endif
125
 
126
#ifndef WARN_UNUSED_RESULT
127
#define WARN_UNUSED_RESULT
128
#endif
129
/* Add attribute(warn_unused_result) if supported */
130
#define cairo_warn	    WARN_UNUSED_RESULT
131
#define cairo_private	    cairo_private_no_warn cairo_warn
132
 
133
/* This macro allow us to deprecate a function by providing an alias
134
   for the old function name to the new function name. With this
135
   macro, binary compatibility is preserved. The macro only works on
136
   some platforms --- tough.
137
 
138
   Meanwhile, new definitions in the public header file break the
139
   source code so that it will no longer link against the old
140
   symbols. Instead it will give a descriptive error message
141
   indicating that the old function has been deprecated by the new
142
   function.
143
*/
144
#if __GNUC__ >= 2 && defined(__ELF__)
145
# define CAIRO_FUNCTION_ALIAS(old, new)		\
146
	extern __typeof (new) old		\
147
	__asm__ ("" #old)			\
148
	__attribute__((__alias__("" #new)))
149
#else
150
# define CAIRO_FUNCTION_ALIAS(old, new)
151
#endif
152
 
153
/*
154
 * Cairo uses the following function attributes in order to improve the
155
 * generated code (effectively by manual inter-procedural analysis).
156
 *
157
 *   'cairo_pure': The function is only allowed to read from its arguments
158
 *                 and global memory (i.e. following a pointer argument or
159
 *                 accessing a shared variable). The return value should
160
 *                 only depend on its arguments, and for an identical set of
161
 *                 arguments should return the same value.
162
 *
163
 *   'cairo_const': The function is only allowed to read from its arguments.
164
 *                  It is not allowed to access global memory. The return
165
 *                  value should only depend its arguments, and for an
166
 *                  identical set of arguments should return the same value.
167
 *                  This is currently the most strict function attribute.
168
 *
169
 * Both these function attributes allow gcc to perform CSE and
170
 * constant-folding, with 'cairo_const 'also guaranteeing that pointer contents
171
 * do not change across the function call.
172
 */
173
#if __GNUC__ >= 3
174
#define cairo_pure __attribute__((pure))
175
#define cairo_const __attribute__((const))
176
#define cairo_always_inline inline __attribute__((always_inline))
177
#else
178
#define cairo_pure
179
#define cairo_const
180
#define cairo_always_inline inline
181
#endif
182
 
183
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
184
#define _CAIRO_BOOLEAN_EXPR(expr)                   \
185
 __extension__ ({                               \
186
   int _cairo_boolean_var_;                         \
187
   if (expr)                                    \
188
      _cairo_boolean_var_ = 1;                      \
189
   else                                         \
190
      _cairo_boolean_var_ = 0;                      \
191
   _cairo_boolean_var_;                             \
192
})
193
#define likely(expr) (__builtin_expect (_CAIRO_BOOLEAN_EXPR(expr), 1))
194
#define unlikely(expr) (__builtin_expect (_CAIRO_BOOLEAN_EXPR(expr), 0))
195
#else
196
#define likely(expr) (expr)
197
#define unlikely(expr) (expr)
198
#endif
199
 
200
#ifndef __GNUC__
201
#undef __attribute__
202
#define __attribute__(x)
203
#endif
204
 
205
#if (defined(__WIN32__) && !defined(__WINE__)) || defined(_MSC_VER)
206
#define snprintf _snprintf
207
#define popen _popen
208
#define pclose _pclose
209
#define hypot _hypot
210
#endif
211
 
212
#ifdef _MSC_VER
213
#undef inline
214
#define inline __inline
215
 
216
/* Add a definition of ffs */
217
#include 
218
#pragma intrinsic(_BitScanForward)
219
static __forceinline int
220
ffs (int x)
221
{
222
    unsigned long i;
223
 
224
    if (_BitScanForward(&i, x) != 0)
225
	return i + 1;
226
 
227
    return 0;
228
}
229
 
230
#endif
231
 
232
#if defined(_MSC_VER) && defined(_M_IX86)
233
/* When compiling with /Gy and /OPT:ICF identical functions will be folded in together.
234
   The CAIRO_ENSURE_UNIQUE macro ensures that a function is always unique and
235
   will never be folded into another one. Something like this might eventually
236
   be needed for GCC but it seems fine for now. */
237
#define CAIRO_ENSURE_UNIQUE                       \
238
    do {                                          \
239
	char func[] = __FUNCTION__;               \
240
	char file[] = __FILE__;                   \
241
	__asm {                                   \
242
	    __asm jmp __internal_skip_line_no     \
243
	    __asm _emit (__LINE__ & 0xff)         \
244
	    __asm _emit ((__LINE__>>8) & 0xff)    \
245
	    __asm _emit ((__LINE__>>16) & 0xff)   \
246
	    __asm _emit ((__LINE__>>24) & 0xff)   \
247
	    __asm lea eax, func                   \
248
	    __asm lea eax, file                   \
249
	    __asm __internal_skip_line_no:        \
250
	};                                        \
251
    } while (0)
252
#else
253
#define CAIRO_ENSURE_UNIQUE    do { } while (0)
254
#endif
255
 
256
#ifdef __STRICT_ANSI__
257
#undef inline
258
#define inline __inline__
259
#endif
260
 
261
#endif