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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5