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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 740 - (show annotations)
Mon Oct 31 06:10:14 2011 UTC (7 years, 9 months ago) by zherczeg
File MIME type: text/plain
File size: 12196 byte(s)
Updating the JIT compiler
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_X86_32 && SLJIT_CONFIG_X86_32) && !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
182 /* Just call __ARM_NR_cacheflush on Linux. */
183 #define SLJIT_CACHE_FLUSH(from, to) \
184 __clear_cache((char*)(from), (char*)(to))
185 #else
186 /* Not required to implement on archs with unified caches. */
187 #define SLJIT_CACHE_FLUSH(from, to)
188 #endif
189
190 #endif /* !SLJIT_CACHE_FLUSH */
191
192 /* 8 bit byte type. */
193 typedef unsigned char sljit_ub;
194 typedef signed char sljit_b;
195
196 /* 16 bit half-word type. */
197 typedef unsigned short int sljit_uh;
198 typedef signed short int sljit_h;
199
200 /* 32 bit integer type. */
201 typedef unsigned int sljit_ui;
202 typedef signed int sljit_i;
203
204 /* Machine word type. Can encapsulate a pointer.
205 32 bit for 32 bit machines.
206 64 bit for 64 bit machines. */
207 #if !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
208 #define SLJIT_32BIT_ARCHITECTURE 1
209 #define SLJIT_WORD_SHIFT 2
210 typedef unsigned int sljit_uw;
211 typedef int sljit_w;
212 #else
213 #define SLJIT_64BIT_ARCHITECTURE 1
214 #define SLJIT_WORD_SHIFT 3
215 #ifdef _WIN32
216 typedef unsigned __int64 sljit_uw;
217 typedef __int64 sljit_w;
218 #else
219 typedef unsigned long int sljit_uw;
220 typedef long int sljit_w;
221 #endif
222 #endif
223
224 /* Double precision. */
225 #define SLJIT_FLOAT_SHIFT 3
226
227 #ifndef SLJIT_W
228
229 /* Defining long constants. */
230 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
231 #define SLJIT_W(w) (w##ll)
232 #else
233 #define SLJIT_W(w) (w)
234 #endif
235
236 #endif /* !SLJIT_W */
237
238 #ifndef SLJIT_CALL
239
240 /* ABI (Application Binary Interface) types. */
241 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
242
243 #if defined(__GNUC__)
244
245 #define SLJIT_CALL __attribute__ ((fastcall))
246 #define SLJIT_X86_32_FASTCALL 1
247
248 #elif defined(_WIN32)
249
250 #ifdef __BORLANDC__
251 #define SLJIT_CALL __msfastcall
252 #else /* __BORLANDC__ */
253 #define SLJIT_CALL __fastcall
254 #endif /* __BORLANDC__ */
255 #define SLJIT_X86_32_FASTCALL 1
256
257 #else /* defined(_WIN32) */
258 #define SLJIT_CALL __stdcall
259 #endif
260
261 #else /* Other architectures. */
262
263 #define SLJIT_CALL
264
265 #endif /* SLJIT_CONFIG_X86_32 */
266
267 #endif /* !SLJIT_CALL */
268
269 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
270
271 /* These macros are useful for the application. */
272 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
273 #define SLJIT_BIG_ENDIAN 1
274
275 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
276
277 #ifdef __MIPSEL__
278 #define SLJIT_LITTLE_ENDIAN 1
279 #else
280 #define SLJIT_BIG_ENDIAN 1
281 #endif
282
283 #else
284 #define SLJIT_LITTLE_ENDIAN 1
285 #endif
286
287 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
288
289 /* Sanity check. */
290 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
291 #error "Exactly one endianness must be selected"
292 #endif
293
294 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
295 #error "Exactly one endianness must be selected"
296 #endif
297
298 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
299 /* It seems ppc64 compilers use an indirect addressing for functions.
300 It makes things really complicated. */
301 #define SLJIT_INDIRECT_CALL 1
302 #endif
303
304 #ifndef SLJIT_SSE2
305
306 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
307 /* Turn on SSE2 support on x86 (operating on doubles).
308 (Better performance than legacy fpu instructions). */
309 #define SLJIT_SSE2 1
310
311 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
312 /* Auto detect SSE2 support using CPUID.
313 On 64 bit x86 cpus, sse2 must be present. */
314 #define SLJIT_SSE2_AUTO 1
315 #endif
316
317 #endif /* (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) */
318
319 #endif /* !SLJIT_SSE2 */
320
321 #ifndef SLJIT_UNALIGNED
322
323 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
324 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
325 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
326 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
327 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
328 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
329 #define SLJIT_UNALIGNED 1
330 #endif
331
332 #endif /* !SLJIT_UNALIGNED */
333
334 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
335 void* sljit_malloc_exec(sljit_uw size);
336 void sljit_free_exec(void* ptr);
337 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
338 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
339 #endif
340
341 #if (defined SLJIT_DEBUG && SLJIT_DEBUG) || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
342 #include <stdio.h>
343 #endif
344
345 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
346
347 /* Feel free to redefine these two macros. */
348 #ifndef SLJIT_ASSERT
349
350 #define SLJIT_HALT_PROCESS() \
351 *((int*)0) = 0
352
353 #define SLJIT_ASSERT(x) \
354 do { \
355 if (SLJIT_UNLIKELY(!(x))) { \
356 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
357 SLJIT_HALT_PROCESS(); \
358 } \
359 } while (0)
360
361 #endif /* !SLJIT_ASSERT */
362
363 #ifndef SLJIT_ASSERT_STOP
364
365 #define SLJIT_ASSERT_STOP() \
366 do { \
367 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
368 SLJIT_HALT_PROCESS(); \
369 } while (0)
370
371 #endif /* !SLJIT_ASSERT_STOP */
372
373 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
374
375 #undef SLJIT_ASSERT
376 #undef SLJIT_ASSERT_STOP
377
378 #define SLJIT_ASSERT(x) \
379 do { } while (0)
380 #define SLJIT_ASSERT_STOP() \
381 do { } while (0)
382
383 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
384
385 #ifndef SLJIT_COMPILE_ASSERT
386
387 /* Should be improved eventually. */
388 #define SLJIT_COMPILE_ASSERT(x, description) \
389 SLJIT_ASSERT(x)
390
391 #endif /* !SLJIT_COMPILE_ASSERT */
392
393 #endif

  ViewVC Help
Powered by ViewVC 1.1.5