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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1215 - (show annotations)
Fri Nov 9 08:13:13 2012 UTC (7 years ago) by zherczeg
File MIME type: text/plain
File size: 14942 byte(s)
Large JIT compiler update again.
1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2012 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 macros depending on the target architecture:
32
33 Feature detection (boolean) macros:
34 SLJIT_32BIT_ARCHITECTURE : 32 bit architecture
35 SLJIT_64BIT_ARCHITECTURE : 64 bit architecture
36 SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index
37 SLJIT_DOUBLE_SHIFT : the shift required to apply when accessing a double array by index
38 SLJIT_LITTLE_ENDIAN : little endian architecture
39 SLJIT_BIG_ENDIAN : big endian architecture
40 SLJIT_UNALIGNED : allows unaligned memory accesses for non-fpu operations (only!)
41 SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() for more information
42 SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address
43
44 Types and useful macros:
45 sljit_sb, sljit_ub : signed and unsigned 8 bit byte
46 sljit_sh, sljit_uh : signed and unsigned 16 bit half-word (short) type
47 sljit_si, sljit_ui : signed and unsigned 32 bit integer type
48 sljit_sw, sljit_uw : signed and unsigned machine word, enough to store a pointer
49 sljit_p : unsgined pointer value (usually the same as sljit_uw, but
50 some 64 bit ABIs may use 32 bit pointers)
51 sljit_s : single precision floating point value
52 sljit_d : double precision floating point value
53 SLJIT_CALL : C calling convention define for both calling JIT form C and C callbacks for JIT
54 SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper)
55 */
56
57 #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
58 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
59 || (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
60 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
61 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
62 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
63 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
64 || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
65 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
66 || (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
67 || (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED))
68 #error "An architecture must be selected"
69 #endif
70
71 /* Sanity check. */
72 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
73 + (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
74 + (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
75 + (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
76 + (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
77 + (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
78 + (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
79 + (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
80 + (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
81 + (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
82 + (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) >= 2
83 #error "Multiple architectures are selected"
84 #endif
85
86 /* Auto select option (requires compiler support) */
87 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
88
89 #ifndef _WIN32
90
91 #if defined(__i386__) || defined(__i386)
92 #define SLJIT_CONFIG_X86_32 1
93 #elif defined(__x86_64__)
94 #define SLJIT_CONFIG_X86_64 1
95 #elif defined(__arm__) || defined(__ARM__)
96 #ifdef __thumb2__
97 #define SLJIT_CONFIG_ARM_THUMB2 1
98 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
99 #define SLJIT_CONFIG_ARM_V7 1
100 #else
101 #define SLJIT_CONFIG_ARM_V5 1
102 #endif
103 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) || (defined(_POWER) && defined(__64BIT__))
104 #define SLJIT_CONFIG_PPC_64 1
105 #elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_POWER)
106 #define SLJIT_CONFIG_PPC_32 1
107 #elif defined(__mips__)
108 #define SLJIT_CONFIG_MIPS_32 1
109 #elif defined(__sparc__) || defined(__sparc)
110 #define SLJIT_CONFIG_SPARC_32 1
111 #else
112 /* Unsupported architecture */
113 #define SLJIT_CONFIG_UNSUPPORTED 1
114 #endif
115
116 #else /* !_WIN32 */
117
118 #if defined(_M_X64) || defined(__x86_64__)
119 #define SLJIT_CONFIG_X86_64 1
120 #elif defined(_ARM_)
121 #define SLJIT_CONFIG_ARM_V5 1
122 #else
123 #define SLJIT_CONFIG_X86_32 1
124 #endif
125
126 #endif /* !WIN32 */
127 #endif /* SLJIT_CONFIG_AUTO */
128
129 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
130 #undef SLJIT_EXECUTABLE_ALLOCATOR
131 #endif
132
133 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
134
135 /* These libraries are needed for the macros below. */
136 #include <stdlib.h>
137 #include <string.h>
138
139 #endif /* STD_MACROS_DEFINED */
140
141 /* General macros:
142 Note: SLJIT is designed to be independent from them as possible.
143
144 In release mode (SLJIT_DEBUG is not defined) only the following macros are needed:
145 */
146
147 #ifndef SLJIT_MALLOC
148 #define SLJIT_MALLOC(size) malloc(size)
149 #endif
150
151 #ifndef SLJIT_FREE
152 #define SLJIT_FREE(ptr) free(ptr)
153 #endif
154
155 #ifndef SLJIT_MEMMOVE
156 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
157 #endif
158
159 #ifndef SLJIT_ZEROMEM
160 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
161 #endif
162
163 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
164
165 #if defined(__GNUC__) && (__GNUC__ >= 3)
166 #define SLJIT_LIKELY(x) __builtin_expect((x), 1)
167 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0)
168 #else
169 #define SLJIT_LIKELY(x) (x)
170 #define SLJIT_UNLIKELY(x) (x)
171 #endif
172
173 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
174
175 #ifndef SLJIT_INLINE
176 /* Inline functions. */
177 #define SLJIT_INLINE __inline
178 #endif
179
180 #ifndef SLJIT_CONST
181 /* Const variables. */
182 #define SLJIT_CONST const
183 #endif
184
185 #ifndef SLJIT_UNUSED_ARG
186 /* Unused arguments. */
187 #define SLJIT_UNUSED_ARG(arg) (void)arg
188 #endif
189
190 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
191 /* Static ABI functions. For all-in-one programs. */
192
193 #if defined(__GNUC__)
194 /* Disable unused warnings in gcc. */
195 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
196 #else
197 #define SLJIT_API_FUNC_ATTRIBUTE static
198 #endif
199
200 #else
201 #define SLJIT_API_FUNC_ATTRIBUTE
202 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
203
204 #ifndef SLJIT_CACHE_FLUSH
205
206 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
207
208 /* Not required to implement on archs with unified caches. */
209 #define SLJIT_CACHE_FLUSH(from, to)
210
211 #elif defined __APPLE__
212
213 /* Supported by all macs since Mac OS 10.5.
214 However, it does not work on non-jailbroken iOS devices,
215 although the compilation is successful. */
216
217 #define SLJIT_CACHE_FLUSH(from, to) \
218 sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
219
220 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
221
222 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
223 #define SLJIT_CACHE_FLUSH(from, to) \
224 ppc_cache_flush((from), (to))
225
226 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
227
228 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
229 #define SLJIT_CACHE_FLUSH(from, to) \
230 sparc_cache_flush((from), (to))
231
232 #else
233
234 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
235 #define SLJIT_CACHE_FLUSH(from, to) \
236 __clear_cache((char*)(from), (char*)(to))
237
238 #endif
239
240 #endif /* !SLJIT_CACHE_FLUSH */
241
242 /* 8 bit byte type. */
243 typedef unsigned char sljit_ub;
244 typedef signed char sljit_sb;
245
246 /* 16 bit half-word type. */
247 typedef unsigned short int sljit_uh;
248 typedef signed short int sljit_sh;
249
250 /* 32 bit integer type. */
251 typedef unsigned int sljit_ui;
252 typedef signed int sljit_si;
253
254 /* Machine word type. Can encapsulate a pointer.
255 32 bit for 32 bit machines.
256 64 bit for 64 bit machines. */
257 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
258 /* Just to have something. */
259 #define SLJIT_WORD_SHIFT 0
260 typedef unsigned long int sljit_uw;
261 typedef long int sljit_sw;
262 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
263 #define SLJIT_32BIT_ARCHITECTURE 1
264 #define SLJIT_WORD_SHIFT 2
265 typedef unsigned int sljit_uw;
266 typedef int sljit_sw;
267 #else
268 #define SLJIT_64BIT_ARCHITECTURE 1
269 #define SLJIT_WORD_SHIFT 3
270 #ifdef _WIN32
271 typedef unsigned __int64 sljit_uw;
272 typedef __int64 sljit_sw;
273 #else
274 typedef unsigned long int sljit_uw;
275 typedef long int sljit_sw;
276 #endif
277 #endif
278
279 typedef sljit_uw sljit_p;
280
281 /* Floating point types. */
282 typedef float sljit_s;
283 typedef double sljit_d;
284
285 /* Shift for pointer sized data. */
286 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
287
288 /* Shift for double precision sized data. */
289 #define SLJIT_DOUBLE_SHIFT 3
290
291 #ifndef SLJIT_W
292
293 /* Defining long constants. */
294 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
295 #define SLJIT_W(w) (w##ll)
296 #else
297 #define SLJIT_W(w) (w)
298 #endif
299
300 #endif /* !SLJIT_W */
301
302 #ifndef SLJIT_CALL
303
304 /* ABI (Application Binary Interface) types. */
305 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
306
307 #if defined(__GNUC__)
308
309 #define SLJIT_CALL __attribute__ ((fastcall))
310 #define SLJIT_X86_32_FASTCALL 1
311
312 #elif defined(_WIN32)
313
314 #ifdef __BORLANDC__
315 #define SLJIT_CALL __msfastcall
316 #else /* __BORLANDC__ */
317 #define SLJIT_CALL __fastcall
318 #endif /* __BORLANDC__ */
319 #define SLJIT_X86_32_FASTCALL 1
320
321 #else /* defined(_WIN32) */
322 #define SLJIT_CALL __stdcall
323 #endif
324
325 #else /* Other architectures. */
326
327 #define SLJIT_CALL
328
329 #endif /* SLJIT_CONFIG_X86_32 */
330
331 #endif /* !SLJIT_CALL */
332
333 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
334
335 /* These macros are useful for the application. */
336 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
337 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
338 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
339 #define SLJIT_BIG_ENDIAN 1
340
341 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
342
343 #ifdef __MIPSEL__
344 #define SLJIT_LITTLE_ENDIAN 1
345 #else
346 #define SLJIT_BIG_ENDIAN 1
347 #endif
348
349 #else
350 #define SLJIT_LITTLE_ENDIAN 1
351 #endif
352
353 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
354
355 /* Sanity check. */
356 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
357 #error "Exactly one endianness must be selected"
358 #endif
359
360 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
361 #error "Exactly one endianness must be selected"
362 #endif
363
364 #ifndef SLJIT_INDIRECT_CALL
365 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32 && defined _AIX)
366 /* It seems certain ppc compilers use an indirect addressing for functions
367 which makes things complicated. */
368 #define SLJIT_INDIRECT_CALL 1
369 #endif
370 #endif /* SLJIT_INDIRECT_CALL */
371
372 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
373 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
374 #define SLJIT_RETURN_ADDRESS_OFFSET 8
375 #else
376 #define SLJIT_RETURN_ADDRESS_OFFSET 0
377 #endif
378 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
379
380 #ifndef SLJIT_SSE2
381
382 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
383 /* Turn on SSE2 support on x86. */
384 #define SLJIT_SSE2 1
385
386 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
387 /* Auto detect SSE2 support using CPUID.
388 On 64 bit x86 cpus, sse2 must be present. */
389 #define SLJIT_DETECT_SSE2 1
390 #endif
391
392 #endif /* (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) */
393
394 #endif /* !SLJIT_SSE2 */
395
396 #ifndef SLJIT_UNALIGNED
397
398 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
399 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
400 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
401 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
402 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
403 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
404 #define SLJIT_UNALIGNED 1
405 #endif
406
407 #endif /* !SLJIT_UNALIGNED */
408
409 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
410 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
411 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
412 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
413 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
414 #endif
415
416 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
417 #include <stdio.h>
418 #endif
419
420 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
421
422 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
423
424 /* SLJIT_HALT_PROCESS must halt the process. */
425 #ifndef SLJIT_HALT_PROCESS
426 #include <stdlib.h>
427
428 #define SLJIT_HALT_PROCESS() \
429 abort();
430 #endif /* !SLJIT_HALT_PROCESS */
431
432 #include <stdio.h>
433
434 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
435
436 /* Feel free to redefine these two macros. */
437 #ifndef SLJIT_ASSERT
438
439 #define SLJIT_ASSERT(x) \
440 do { \
441 if (SLJIT_UNLIKELY(!(x))) { \
442 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
443 SLJIT_HALT_PROCESS(); \
444 } \
445 } while (0)
446
447 #endif /* !SLJIT_ASSERT */
448
449 #ifndef SLJIT_ASSERT_STOP
450
451 #define SLJIT_ASSERT_STOP() \
452 do { \
453 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
454 SLJIT_HALT_PROCESS(); \
455 } while (0)
456
457 #endif /* !SLJIT_ASSERT_STOP */
458
459 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
460
461 /* Forcing empty, but valid statements. */
462 #undef SLJIT_ASSERT
463 #undef SLJIT_ASSERT_STOP
464
465 #define SLJIT_ASSERT(x) \
466 do { } while (0)
467 #define SLJIT_ASSERT_STOP() \
468 do { } while (0)
469
470 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
471
472 #ifndef SLJIT_COMPILE_ASSERT
473
474 /* Should be improved eventually. */
475 #define SLJIT_COMPILE_ASSERT(x, description) \
476 SLJIT_ASSERT(x)
477
478 #endif /* !SLJIT_COMPILE_ASSERT */
479
480 #endif

  ViewVC Help
Powered by ViewVC 1.1.5