/[pcre]/code/trunk/sljit/sljitConfigInternal.h
ViewVC logotype

Contents of /code/trunk/sljit/sljitConfigInternal.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 742 - (show annotations)
Sun Nov 6 08:05:33 2011 UTC (7 years, 10 months ago) by zherczeg
File MIME type: text/plain
File size: 12462 byte(s)
Fix cache-flush issue on PowerPC, adding some comments and a check for disabled PCRE_EXTRA_TABLES.

1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2010 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef _SLJIT_CONFIG_INTERNAL_H_
28 #define _SLJIT_CONFIG_INTERNAL_H_
29
30 /*
31 SLJIT defines the following variables itself depending on the configuration:
32 sljit_b, sljit_ub : signed and unsigned 8 bit byte
33 sljit_h, sljit_uh : signed and unsigned 16 bit half-word (short) type
34 sljit_i, sljit_ui : signed and unsigned 32 bit integer type
35 sljit_w, sljit_uw : signed and unsigned machine word, enough to store a pointer (same as intptr_t)
36 SLJIT_CALL : C calling convention for both calling JIT and C callbacks from JIT
37 SLJIT_32BIT_ARCHITECTURE : 32 bit architecture
38 SLJIT_64BIT_ARCHITECTURE : 64 bit architecture
39 SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_w/sljit_uw array by index
40 SLJIT_FLOAT_SHIFT : the shift required to apply when accessing a double array by index
41 SLJIT_BIG_ENDIAN : big endian architecture
42 SLJIT_LITTLE_ENDIAN : little endian architecture
43 SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET()
44 SLJIT_W : for defining 64 bit constants on 64 bit architectures (compiler workaround)
45 SLJIT_UNALIGNED : allows unaligned memory accesses for integer arithmetic (only!)
46 */
47
48 #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
49 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
50 || (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
51 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
52 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
53 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
54 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
55 || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
56 || (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
57 || (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED))
58 #error "An architecture must be selected"
59 #endif
60
61 /* Sanity check. */
62 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
63 + (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
64 + (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
65 + (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
66 + (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
67 + (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
68 + (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
69 + (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
70 + (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
71 + (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) >= 2
72 #error "Multiple architectures are selected"
73 #endif
74
75 /* Auto select option (requires compiler support) */
76 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
77
78 #ifndef _WIN32
79
80 #if defined(__i386__) || defined(__i386)
81 #define SLJIT_CONFIG_X86_32 1
82 #elif defined(__x86_64__)
83 #define SLJIT_CONFIG_X86_64 1
84 #elif defined(__arm__) || defined(__ARM__)
85 #ifdef __thumb2__
86 #define SLJIT_CONFIG_ARM_THUMB2 1
87 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
88 #define SLJIT_CONFIG_ARM_V7 1
89 #else
90 #define SLJIT_CONFIG_ARM_V5 1
91 #endif
92 #elif defined(__ppc64__) || defined(__powerpc64__)
93 #define SLJIT_CONFIG_PPC_64 1
94 #elif defined(__ppc__) || defined(__powerpc__)
95 #define SLJIT_CONFIG_PPC_32 1
96 #elif defined(__mips__)
97 #define SLJIT_CONFIG_MIPS_32 1
98 #else
99 /* Unsupported architecture */
100 #define SLJIT_CONFIG_UNSUPPORTED 1
101 #endif
102
103 #else /* !_WIN32 */
104
105 #if defined(_M_X64) || defined(__x86_64__)
106 #define SLJIT_CONFIG_X86_64 1
107 #elif defined(_ARM_)
108 #define SLJIT_CONFIG_ARM_V5 1
109 #else
110 #define SLJIT_CONFIG_X86_32 1
111 #endif
112
113 #endif /* !WIN32 */
114 #endif /* SLJIT_CONFIG_AUTO */
115
116 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
117 #undef SLJIT_EXECUTABLE_ALLOCATOR
118 #endif
119
120 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
121
122 #include <stdlib.h>
123 #include <string.h>
124
125 /* General libraries:
126 Note: SLJIT is designed to be independent from them as possible.
127
128 In release mode (SLJIT_DEBUG is not defined) only the following macros are needed: */
129
130 /* General allocation. */
131 #define SLJIT_MALLOC(size) malloc(size)
132 #define SLJIT_MALLOC_ZEROED(size) calloc((size), 1)
133 #define SLJIT_FREE(ptr) free(ptr)
134 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
135
136 #endif /* STD_MACROS_DEFINED */
137
138 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
139
140 #if defined(__GNUC__) && (__GNUC__ >= 3)
141 #define SLJIT_LIKELY(x) __builtin_expect((x), 1)
142 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0)
143 #else
144 #define SLJIT_LIKELY(x) (x)
145 #define SLJIT_UNLIKELY(x) (x)
146 #endif
147
148 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
149
150 #ifndef SLJIT_INLINE
151 /* Inline functions. */
152 #define SLJIT_INLINE __inline
153 #endif
154
155 #ifndef SLJIT_CONST
156 /* Const variables. */
157 #define SLJIT_CONST const
158 #endif
159
160 #ifndef SLJIT_UNUSED_ARG
161 /* Unused arguments. */
162 #define SLJIT_UNUSED_ARG(arg) (void)arg
163 #endif
164
165 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
166 /* Static ABI functions. For all-in-one programs. */
167
168 #if defined(__GNUC__)
169 /* Disable unused warnings in gcc. */
170 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
171 #else
172 #define SLJIT_API_FUNC_ATTRIBUTE static
173 #endif
174
175 #else
176 #define SLJIT_API_FUNC_ATTRIBUTE
177 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
178
179 #ifndef SLJIT_CACHE_FLUSH
180
181 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
182
183 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
184 #define SLJIT_CACHE_FLUSH(from, to) \
185 ppc_cache_flush((from), (to))
186
187 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
188
189 /* Not required to implement on archs with unified caches. */
190 #define SLJIT_CACHE_FLUSH(from, to)
191
192 #else
193
194 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
195 #define SLJIT_CACHE_FLUSH(from, to) \
196 __clear_cache((char*)(from), (char*)(to))
197
198 #endif
199
200 #endif /* !SLJIT_CACHE_FLUSH */
201
202 /* 8 bit byte type. */
203 typedef unsigned char sljit_ub;
204 typedef signed char sljit_b;
205
206 /* 16 bit half-word type. */
207 typedef unsigned short int sljit_uh;
208 typedef signed short int sljit_h;
209
210 /* 32 bit integer type. */
211 typedef unsigned int sljit_ui;
212 typedef signed int sljit_i;
213
214 /* Machine word type. Can encapsulate a pointer.
215 32 bit for 32 bit machines.
216 64 bit for 64 bit machines. */
217 #if !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
218 #define SLJIT_32BIT_ARCHITECTURE 1
219 #define SLJIT_WORD_SHIFT 2
220 typedef unsigned int sljit_uw;
221 typedef int sljit_w;
222 #else
223 #define SLJIT_64BIT_ARCHITECTURE 1
224 #define SLJIT_WORD_SHIFT 3
225 #ifdef _WIN32
226 typedef unsigned __int64 sljit_uw;
227 typedef __int64 sljit_w;
228 #else
229 typedef unsigned long int sljit_uw;
230 typedef long int sljit_w;
231 #endif
232 #endif
233
234 /* Double precision. */
235 #define SLJIT_FLOAT_SHIFT 3
236
237 #ifndef SLJIT_W
238
239 /* Defining long constants. */
240 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
241 #define SLJIT_W(w) (w##ll)
242 #else
243 #define SLJIT_W(w) (w)
244 #endif
245
246 #endif /* !SLJIT_W */
247
248 #ifndef SLJIT_CALL
249
250 /* ABI (Application Binary Interface) types. */
251 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
252
253 #if defined(__GNUC__)
254
255 #define SLJIT_CALL __attribute__ ((fastcall))
256 #define SLJIT_X86_32_FASTCALL 1
257
258 #elif defined(_WIN32)
259
260 #ifdef __BORLANDC__
261 #define SLJIT_CALL __msfastcall
262 #else /* __BORLANDC__ */
263 #define SLJIT_CALL __fastcall
264 #endif /* __BORLANDC__ */
265 #define SLJIT_X86_32_FASTCALL 1
266
267 #else /* defined(_WIN32) */
268 #define SLJIT_CALL __stdcall
269 #endif
270
271 #else /* Other architectures. */
272
273 #define SLJIT_CALL
274
275 #endif /* SLJIT_CONFIG_X86_32 */
276
277 #endif /* !SLJIT_CALL */
278
279 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
280
281 /* These macros are useful for the application. */
282 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
283 #define SLJIT_BIG_ENDIAN 1
284
285 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
286
287 #ifdef __MIPSEL__
288 #define SLJIT_LITTLE_ENDIAN 1
289 #else
290 #define SLJIT_BIG_ENDIAN 1
291 #endif
292
293 #else
294 #define SLJIT_LITTLE_ENDIAN 1
295 #endif
296
297 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
298
299 /* Sanity check. */
300 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
301 #error "Exactly one endianness must be selected"
302 #endif
303
304 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
305 #error "Exactly one endianness must be selected"
306 #endif
307
308 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
309 /* It seems ppc64 compilers use an indirect addressing for functions.
310 It makes things really complicated. */
311 #define SLJIT_INDIRECT_CALL 1
312 #endif
313
314 #ifndef SLJIT_SSE2
315
316 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
317 /* Turn on SSE2 support on x86 (operating on doubles).
318 (Better performance than legacy fpu instructions). */
319 #define SLJIT_SSE2 1
320
321 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
322 /* Auto detect SSE2 support using CPUID.
323 On 64 bit x86 cpus, sse2 must be present. */
324 #define SLJIT_SSE2_AUTO 1
325 #endif
326
327 #endif /* (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) */
328
329 #endif /* !SLJIT_SSE2 */
330
331 #ifndef SLJIT_UNALIGNED
332
333 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
334 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
335 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
336 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
337 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
338 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
339 #define SLJIT_UNALIGNED 1
340 #endif
341
342 #endif /* !SLJIT_UNALIGNED */
343
344 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
345 void* sljit_malloc_exec(sljit_uw size);
346 void sljit_free_exec(void* ptr);
347 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
348 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
349 #endif
350
351 #if (defined SLJIT_DEBUG && SLJIT_DEBUG) || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
352 #include <stdio.h>
353 #endif
354
355 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
356
357 /* Feel free to redefine these two macros. */
358 #ifndef SLJIT_ASSERT
359
360 #define SLJIT_HALT_PROCESS() \
361 *((int*)0) = 0
362
363 #define SLJIT_ASSERT(x) \
364 do { \
365 if (SLJIT_UNLIKELY(!(x))) { \
366 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
367 SLJIT_HALT_PROCESS(); \
368 } \
369 } while (0)
370
371 #endif /* !SLJIT_ASSERT */
372
373 #ifndef SLJIT_ASSERT_STOP
374
375 #define SLJIT_ASSERT_STOP() \
376 do { \
377 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
378 SLJIT_HALT_PROCESS(); \
379 } while (0)
380
381 #endif /* !SLJIT_ASSERT_STOP */
382
383 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
384
385 #undef SLJIT_ASSERT
386 #undef SLJIT_ASSERT_STOP
387
388 #define SLJIT_ASSERT(x) \
389 do { } while (0)
390 #define SLJIT_ASSERT_STOP() \
391 do { } while (0)
392
393 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
394
395 #ifndef SLJIT_COMPILE_ASSERT
396
397 /* Should be improved eventually. */
398 #define SLJIT_COMPILE_ASSERT(x, description) \
399 SLJIT_ASSERT(x)
400
401 #endif /* !SLJIT_COMPILE_ASSERT */
402
403 #endif

  ViewVC Help
Powered by ViewVC 1.1.5