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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 704 - (show annotations) (download)
Wed Sep 21 12:35:36 2011 UTC (3 years, 2 months ago) by zherczeg
File MIME type: text/plain
File size: 11521 byte(s)
Borland C++ JIT support by Dmitry Ukolov
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_FREE(ptr) free(ptr)
133 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
134
135 #endif /* STD_MACROS_DEFINED */
136
137 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
138
139 #if defined(__GNUC__) && (__GNUC__ >= 3)
140 #define SLJIT_LIKELY(x) __builtin_expect((x), 1)
141 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0)
142 #else
143 #define SLJIT_LIKELY(x) (x)
144 #define SLJIT_UNLIKELY(x) (x)
145 #endif
146
147 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
148
149 #ifndef SLJIT_INLINE
150 /* Inline functions. */
151 #define SLJIT_INLINE __inline
152 #endif
153
154 #ifndef SLJIT_CONST
155 /* Const variables. */
156 #define SLJIT_CONST const
157 #endif
158
159 #ifndef SLJIT_UNUSED_ARG
160 /* Unused arguments. */
161 #define SLJIT_UNUSED_ARG(arg) (void)arg
162 #endif
163
164 #ifndef SLJIT_CACHE_FLUSH
165
166 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) && !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
167 /* Just call __ARM_NR_cacheflush on Linux. */
168 #define SLJIT_CACHE_FLUSH(from, to) \
169 __clear_cache((char*)(from), (char*)(to))
170 #else
171 /* Not required to implement on archs with unified caches. */
172 #define SLJIT_CACHE_FLUSH(from, to)
173 #endif
174
175 #endif /* !SLJIT_CACHE_FLUSH */
176
177 /* 8 bit byte type. */
178 typedef unsigned char sljit_ub;
179 typedef signed char sljit_b;
180
181 /* 16 bit half-word type. */
182 typedef unsigned short int sljit_uh;
183 typedef signed short int sljit_h;
184
185 /* 32 bit integer type. */
186 typedef unsigned int sljit_ui;
187 typedef signed int sljit_i;
188
189 /* Machine word type. Can encapsulate a pointer.
190 32 bit for 32 bit machines.
191 64 bit for 64 bit machines. */
192 #if !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
193 #define SLJIT_32BIT_ARCHITECTURE 1
194 #define SLJIT_WORD_SHIFT 2
195 typedef unsigned int sljit_uw;
196 typedef int sljit_w;
197 #else
198 #define SLJIT_64BIT_ARCHITECTURE 1
199 #define SLJIT_WORD_SHIFT 3
200 #ifdef _WIN32
201 typedef unsigned __int64 sljit_uw;
202 typedef __int64 sljit_w;
203 #else
204 typedef unsigned long int sljit_uw;
205 typedef long int sljit_w;
206 #endif
207 #endif
208
209 /* Double precision. */
210 #define SLJIT_FLOAT_SHIFT 3
211
212 #ifndef SLJIT_W
213
214 /* Defining long constants. */
215 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
216 #define SLJIT_W(w) (w##ll)
217 #else
218 #define SLJIT_W(w) (w)
219 #endif
220
221 #endif /* !SLJIT_W */
222
223 #ifndef SLJIT_CALL
224
225 /* ABI (Application Binary Interface) types. */
226 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
227
228 #if defined(__GNUC__)
229
230 #define SLJIT_CALL __attribute__ ((fastcall))
231 #define SLJIT_X86_32_FASTCALL 1
232
233 #elif defined(_WIN32)
234
235 #ifdef __BORLANDC__
236 #define SLJIT_CALL __msfastcall
237 #else /* __BORLANDC__ */
238 #define SLJIT_CALL __fastcall
239 #endif /* __BORLANDC__ */
240 #define SLJIT_X86_32_FASTCALL 1
241
242 #else /* defined(_WIN32) */
243 #define SLJIT_CALL __stdcall
244 #endif
245
246 #else /* Other architectures. */
247
248 #define SLJIT_CALL
249
250 #endif /* SLJIT_CONFIG_X86_32 */
251
252 #endif /* !SLJIT_CALL */
253
254 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
255
256 /* These macros are useful for the application. */
257 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
258 #define SLJIT_BIG_ENDIAN 1
259
260 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
261
262 #ifdef __MIPSEL__
263 #define SLJIT_LITTLE_ENDIAN 1
264 #else
265 #define SLJIT_BIG_ENDIAN 1
266 #endif
267
268 #else
269 #define SLJIT_LITTLE_ENDIAN 1
270 #endif
271
272 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
273
274 /* Sanity check. */
275 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
276 #error "Exactly one endianness must be selected"
277 #endif
278
279 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
280 #error "Exactly one endianness must be selected"
281 #endif
282
283 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
284 /* It seems ppc64 compilers use an indirect addressing for functions.
285 It makes things really complicated. */
286 #define SLJIT_INDIRECT_CALL 1
287 #endif
288
289 #ifndef SLJIT_SSE2
290
291 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
292 /* Turn on SSE2 support on x86 (operating on doubles).
293 (Better performance than legacy fpu instructions). */
294 #define SLJIT_SSE2 1
295
296 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
297 /* Auto detect SSE2 support using CPUID.
298 On 64 bit x86 cpus, sse2 must be present. */
299 #define SLJIT_SSE2_AUTO 1
300 #endif
301
302 #endif /* (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) */
303
304 #endif /* !SLJIT_SSE2 */
305
306 #ifndef SLJIT_UNALIGNED
307
308 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
309 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
310 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
311 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
312 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
313 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
314 #define SLJIT_UNALIGNED 1
315 #endif
316
317 #endif /* !SLJIT_UNALIGNED */
318
319 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
320 void* sljit_malloc_exec(sljit_uw size);
321 void sljit_free_exec(void* ptr);
322 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
323 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
324 #endif
325
326 #if (defined SLJIT_DEBUG && SLJIT_DEBUG) || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
327 #include <stdio.h>
328 #endif
329
330 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
331
332 /* Feel free to redefine these two macros. */
333 #ifndef SLJIT_ASSERT
334
335 #define SLJIT_ASSERT(x) \
336 do { \
337 if (SLJIT_UNLIKELY(!(x))) { \
338 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
339 *((int*)0) = 0; \
340 } \
341 } while (0)
342
343 #endif /* !SLJIT_ASSERT */
344
345 #ifndef SLJIT_ASSERT_STOP
346
347 #define SLJIT_ASSERT_STOP() \
348 do { \
349 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
350 *((int*)0) = 0; \
351 } while (0)
352
353 #endif /* !SLJIT_ASSERT_STOP */
354
355 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
356
357 #undef SLJIT_ASSERT
358 #undef SLJIT_ASSERT_STOP
359
360 #define SLJIT_ASSERT(x) \
361 do { } while (0)
362 #define SLJIT_ASSERT_STOP() \
363 do { } while (0)
364
365 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
366
367 #endif

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12