/[pcre2]/code/trunk/src/sljit/sljitConfigInternal.h
ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 652 - (show annotations)
Thu Jan 12 09:32:15 2017 UTC (4 days, 5 hours ago) by zherczeg
File MIME type: text/plain
File size: 23873 byte(s)
JIT compiler update. Patch insipred by Christian Persch.
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 architecture dependent types and macros:
32
33 Types:
34 sljit_s8, sljit_u8 : signed and unsigned 8 bit integer type
35 sljit_s16, sljit_u16 : signed and unsigned 16 bit integer type
36 sljit_s32, sljit_u32 : signed and unsigned 32 bit integer type
37 sljit_sw, sljit_uw : signed and unsigned machine word, enough to store a pointer
38 sljit_p : unsgined pointer value (usually the same as sljit_uw, but
39 some 64 bit ABIs may use 32 bit pointers)
40 sljit_f32 : 32 bit single precision floating point value
41 sljit_f64 : 64 bit double precision floating point value
42
43 Macros for feature detection (boolean):
44 SLJIT_32BIT_ARCHITECTURE : 32 bit architecture
45 SLJIT_64BIT_ARCHITECTURE : 64 bit architecture
46 SLJIT_LITTLE_ENDIAN : little endian architecture
47 SLJIT_BIG_ENDIAN : big endian architecture
48 SLJIT_UNALIGNED : allows unaligned memory accesses for non-fpu operations (only!)
49 SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() for more information
50
51 Constants:
52 SLJIT_NUMBER_OF_REGISTERS : number of available registers
53 SLJIT_NUMBER_OF_SCRATCH_REGISTERS : number of available scratch registers
54 SLJIT_NUMBER_OF_SAVED_REGISTERS : number of available saved registers
55 SLJIT_NUMBER_OF_FLOAT_REGISTERS : number of available floating point registers
56 SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS : number of available floating point scratch registers
57 SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS : number of available floating point saved registers
58 SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index
59 SLJIT_F32_SHIFT : the shift required to apply when accessing
60 a single precision floating point array by index
61 SLJIT_F64_SHIFT : the shift required to apply when accessing
62 a double precision floating point array by index
63 SLJIT_LOCALS_OFFSET : local space starting offset (SLJIT_SP + SLJIT_LOCALS_OFFSET)
64 SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address
65
66 Other macros:
67 SLJIT_CALL : C calling convention define for both calling JIT form C and C callbacks for JIT
68 SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper)
69 */
70
71 /*****************/
72 /* Sanity check. */
73 /*****************/
74
75 #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
76 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
77 || (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
78 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
79 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
80 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
81 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
82 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
83 || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
84 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
85 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
86 || (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
87 || (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
88 || (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED))
89 #error "An architecture must be selected"
90 #endif
91
92 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
93 + (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
94 + (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
95 + (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
96 + (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
97 + (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
98 + (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
99 + (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
100 + (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
101 + (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
102 + (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
103 + (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
104 + (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
105 + (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) >= 2
106 #error "Multiple architectures are selected"
107 #endif
108
109 /********************************************************/
110 /* Automatic CPU detection (requires compiler support). */
111 /********************************************************/
112
113 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
114
115 #ifndef _WIN32
116
117 #if defined(__i386__) || defined(__i386)
118 #define SLJIT_CONFIG_X86_32 1
119 #elif defined(__x86_64__)
120 #define SLJIT_CONFIG_X86_64 1
121 #elif defined(__arm__) || defined(__ARM__)
122 #ifdef __thumb2__
123 #define SLJIT_CONFIG_ARM_THUMB2 1
124 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
125 #define SLJIT_CONFIG_ARM_V7 1
126 #else
127 #define SLJIT_CONFIG_ARM_V5 1
128 #endif
129 #elif defined (__aarch64__)
130 #define SLJIT_CONFIG_ARM_64 1
131 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) || (defined(_POWER) && defined(__64BIT__))
132 #define SLJIT_CONFIG_PPC_64 1
133 #elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_POWER)
134 #define SLJIT_CONFIG_PPC_32 1
135 #elif defined(__mips__) && !defined(_LP64)
136 #define SLJIT_CONFIG_MIPS_32 1
137 #elif defined(__mips64)
138 #define SLJIT_CONFIG_MIPS_64 1
139 #elif defined(__sparc__) || defined(__sparc)
140 #define SLJIT_CONFIG_SPARC_32 1
141 #elif defined(__tilegx__)
142 #define SLJIT_CONFIG_TILEGX 1
143 #else
144 /* Unsupported architecture */
145 #define SLJIT_CONFIG_UNSUPPORTED 1
146 #endif
147
148 #else /* !_WIN32 */
149
150 #if defined(_M_X64) || defined(__x86_64__)
151 #define SLJIT_CONFIG_X86_64 1
152 #elif defined(_ARM_)
153 #define SLJIT_CONFIG_ARM_V5 1
154 #else
155 #define SLJIT_CONFIG_X86_32 1
156 #endif
157
158 #endif /* !WIN32 */
159 #endif /* SLJIT_CONFIG_AUTO */
160
161 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
162 #undef SLJIT_EXECUTABLE_ALLOCATOR
163 #endif
164
165 /******************************/
166 /* CPU family type detection. */
167 /******************************/
168
169 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
170 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
171 #define SLJIT_CONFIG_ARM_32 1
172 #endif
173
174 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
175 #define SLJIT_CONFIG_X86 1
176 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
177 #define SLJIT_CONFIG_ARM 1
178 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
179 #define SLJIT_CONFIG_PPC 1
180 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
181 #define SLJIT_CONFIG_MIPS 1
182 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) || (defined SLJIT_CONFIG_SPARC_64 && SLJIT_CONFIG_SPARC_64)
183 #define SLJIT_CONFIG_SPARC 1
184 #endif
185
186 /**********************************/
187 /* External function definitions. */
188 /**********************************/
189
190 /* General macros:
191 Note: SLJIT is designed to be independent from them as possible.
192
193 In release mode (SLJIT_DEBUG is not defined) only the following
194 external functions are needed:
195 */
196
197 #ifndef SLJIT_MALLOC
198 #define SLJIT_MALLOC(size, allocator_data) malloc(size)
199 #endif
200
201 #ifndef SLJIT_FREE
202 #define SLJIT_FREE(ptr, allocator_data) free(ptr)
203 #endif
204
205 #ifndef SLJIT_MEMCPY
206 #define SLJIT_MEMCPY(dest, src, len) memcpy(dest, src, len)
207 #endif
208
209 #ifndef SLJIT_ZEROMEM
210 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
211 #endif
212
213 /***************************/
214 /* Compiler helper macros. */
215 /***************************/
216
217 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
218
219 #if defined(__GNUC__) && (__GNUC__ >= 3)
220 #define SLJIT_LIKELY(x) __builtin_expect((x), 1)
221 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0)
222 #else
223 #define SLJIT_LIKELY(x) (x)
224 #define SLJIT_UNLIKELY(x) (x)
225 #endif
226
227 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
228
229 #ifndef SLJIT_INLINE
230 /* Inline functions. Some old compilers do not support them. */
231 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
232 #define SLJIT_INLINE
233 #else
234 #define SLJIT_INLINE __inline
235 #endif
236 #endif /* !SLJIT_INLINE */
237
238 #ifndef SLJIT_NOINLINE
239 /* Not inline functions. */
240 #if defined(__GNUC__)
241 #define SLJIT_NOINLINE __attribute__ ((noinline))
242 #else
243 #define SLJIT_NOINLINE
244 #endif
245 #endif /* !SLJIT_INLINE */
246
247 #ifndef SLJIT_UNUSED_ARG
248 /* Unused arguments. */
249 #define SLJIT_UNUSED_ARG(arg) (void)arg
250 #endif
251
252 /*********************************/
253 /* Type of public API functions. */
254 /*********************************/
255
256 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
257 /* Static ABI functions. For all-in-one programs. */
258
259 #if defined(__GNUC__)
260 /* Disable unused warnings in gcc. */
261 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
262 #else
263 #define SLJIT_API_FUNC_ATTRIBUTE static
264 #endif
265
266 #else
267 #define SLJIT_API_FUNC_ATTRIBUTE
268 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
269
270 /****************************/
271 /* Instruction cache flush. */
272 /****************************/
273
274 #if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin)
275 #if __has_builtin(__builtin___clear_cache)
276
277 #define SLJIT_CACHE_FLUSH(from, to) \
278 __builtin___clear_cache((char*)from, (char*)to)
279
280 #endif /* __has_builtin(__builtin___clear_cache) */
281 #endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */
282
283 #ifndef SLJIT_CACHE_FLUSH
284
285 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
286
287 /* Not required to implement on archs with unified caches. */
288 #define SLJIT_CACHE_FLUSH(from, to)
289
290 #elif defined __APPLE__
291
292 /* Supported by all macs since Mac OS 10.5.
293 However, it does not work on non-jailbroken iOS devices,
294 although the compilation is successful. */
295
296 #define SLJIT_CACHE_FLUSH(from, to) \
297 sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
298
299 #elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
300
301 #define SLJIT_CACHE_FLUSH(from, to) \
302 __builtin___clear_cache((char*)from, (char*)to)
303
304 #elif defined __ANDROID__
305
306 /* Android lacks __clear_cache; instead, cacheflush should be used. */
307
308 #define SLJIT_CACHE_FLUSH(from, to) \
309 cacheflush((long)(from), (long)(to), 0)
310
311 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
312
313 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
314 #define SLJIT_CACHE_FLUSH(from, to) \
315 ppc_cache_flush((from), (to))
316 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1
317
318 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
319
320 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
321 #define SLJIT_CACHE_FLUSH(from, to) \
322 sparc_cache_flush((from), (to))
323 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1
324
325 #else
326
327 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
328 #define SLJIT_CACHE_FLUSH(from, to) \
329 __clear_cache((char*)(from), (char*)(to))
330
331 #endif
332
333 #endif /* !SLJIT_CACHE_FLUSH */
334
335 /******************************************************/
336 /* Integer and floating point type definitions. */
337 /******************************************************/
338
339 /* 8 bit byte type. */
340 typedef unsigned char sljit_u8;
341 typedef signed char sljit_s8;
342
343 /* 16 bit half-word type. */
344 typedef unsigned short int sljit_u16;
345 typedef signed short int sljit_s16;
346
347 /* 32 bit integer type. */
348 typedef unsigned int sljit_u32;
349 typedef signed int sljit_s32;
350
351 /* Machine word type. Enough for storing a pointer.
352 32 bit for 32 bit machines.
353 64 bit for 64 bit machines. */
354 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
355 /* Just to have something. */
356 #define SLJIT_WORD_SHIFT 0
357 typedef unsigned long int sljit_uw;
358 typedef long int sljit_sw;
359 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
360 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
361 && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
362 && !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
363 && !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
364 #define SLJIT_32BIT_ARCHITECTURE 1
365 #define SLJIT_WORD_SHIFT 2
366 typedef unsigned int sljit_uw;
367 typedef int sljit_sw;
368 #else
369 #define SLJIT_64BIT_ARCHITECTURE 1
370 #define SLJIT_WORD_SHIFT 3
371 #ifdef _WIN32
372 typedef unsigned __int64 sljit_uw;
373 typedef __int64 sljit_sw;
374 #else
375 typedef unsigned long int sljit_uw;
376 typedef long int sljit_sw;
377 #endif
378 #endif
379
380 typedef sljit_uw sljit_p;
381
382 /* Floating point types. */
383 typedef float sljit_f32;
384 typedef double sljit_f64;
385
386 /* Shift for pointer sized data. */
387 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
388
389 /* Shift for double precision sized data. */
390 #define SLJIT_F32_SHIFT 2
391 #define SLJIT_F64_SHIFT 3
392
393 #ifndef SLJIT_W
394
395 /* Defining long constants. */
396 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
397 #define SLJIT_W(w) (w##ll)
398 #else
399 #define SLJIT_W(w) (w)
400 #endif
401
402 #endif /* !SLJIT_W */
403
404 /*************************/
405 /* Endianness detection. */
406 /*************************/
407
408 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
409
410 /* These macros are mostly useful for the applications. */
411 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
412 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
413
414 #ifdef __LITTLE_ENDIAN__
415 #define SLJIT_LITTLE_ENDIAN 1
416 #else
417 #define SLJIT_BIG_ENDIAN 1
418 #endif
419
420 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
421 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
422
423 #ifdef __MIPSEL__
424 #define SLJIT_LITTLE_ENDIAN 1
425 #else
426 #define SLJIT_BIG_ENDIAN 1
427 #endif
428
429 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
430
431 #define SLJIT_BIG_ENDIAN 1
432
433 #else
434 #define SLJIT_LITTLE_ENDIAN 1
435 #endif
436
437 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
438
439 /* Sanity check. */
440 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
441 #error "Exactly one endianness must be selected"
442 #endif
443
444 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
445 #error "Exactly one endianness must be selected"
446 #endif
447
448 #ifndef SLJIT_UNALIGNED
449
450 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
451 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
452 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
453 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
454 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
455 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
456 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
457 #define SLJIT_UNALIGNED 1
458 #endif
459
460 #endif /* !SLJIT_UNALIGNED */
461
462 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
463 /* Auto detect SSE2 support using CPUID.
464 On 64 bit x86 cpus, sse2 must be present. */
465 #define SLJIT_DETECT_SSE2 1
466 #endif
467
468 /*****************************************************************************************/
469 /* Calling convention of functions generated by SLJIT or called from the generated code. */
470 /*****************************************************************************************/
471
472 #ifndef SLJIT_CALL
473
474 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
475
476 /* Force cdecl. */
477 #define SLJIT_CALL
478
479 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
480
481 #if defined(__GNUC__) && !defined(__APPLE__)
482
483 #define SLJIT_CALL __attribute__ ((fastcall))
484 #define SLJIT_X86_32_FASTCALL 1
485
486 #elif defined(_MSC_VER)
487
488 #define SLJIT_CALL __fastcall
489 #define SLJIT_X86_32_FASTCALL 1
490
491 #elif defined(__BORLANDC__)
492
493 #define SLJIT_CALL __msfastcall
494 #define SLJIT_X86_32_FASTCALL 1
495
496 #else /* Unknown compiler. */
497
498 /* The cdecl attribute is the default. */
499 #define SLJIT_CALL
500
501 #endif
502
503 #else /* Non x86-32 architectures. */
504
505 #define SLJIT_CALL
506
507 #endif /* SLJIT_CONFIG_X86_32 */
508
509 #endif /* !SLJIT_CALL */
510
511 #ifndef SLJIT_INDIRECT_CALL
512 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
513 || ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
514 /* It seems certain ppc compilers use an indirect addressing for functions
515 which makes things complicated. */
516 #define SLJIT_INDIRECT_CALL 1
517 #endif
518 #endif /* SLJIT_INDIRECT_CALL */
519
520 /* The offset which needs to be substracted from the return address to
521 determine the next executed instruction after return. */
522 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
523 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
524 #define SLJIT_RETURN_ADDRESS_OFFSET 8
525 #else
526 #define SLJIT_RETURN_ADDRESS_OFFSET 0
527 #endif
528 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
529
530 /***************************************************/
531 /* Functions of the built-in executable allocator. */
532 /***************************************************/
533
534 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
535 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
536 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
537 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
538 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
539 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
540
541 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
542 SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void* ptr);
543 #define SLJIT_EXEC_OFFSET(ptr) sljit_exec_offset(ptr)
544 #else
545 #define SLJIT_EXEC_OFFSET(ptr) 0
546 #endif
547
548 #endif
549
550 /**********************************************/
551 /* Registers and locals offset determination. */
552 /**********************************************/
553
554 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
555
556 #define SLJIT_NUMBER_OF_REGISTERS 10
557 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
558 #if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
559 #define SLJIT_LOCALS_OFFSET_BASE ((2 + 4) * sizeof(sljit_sw))
560 #else
561 /* Maximum 3 arguments are passed on the stack, +1 for double alignment. */
562 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1 + 4) * sizeof(sljit_sw))
563 #endif /* SLJIT_X86_32_FASTCALL */
564
565 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
566
567 #ifndef _WIN64
568 #define SLJIT_NUMBER_OF_REGISTERS 12
569 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
570 #define SLJIT_LOCALS_OFFSET_BASE (sizeof(sljit_sw))
571 #else
572 #define SLJIT_NUMBER_OF_REGISTERS 12
573 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
574 #define SLJIT_LOCALS_OFFSET_BASE ((4 + 2) * sizeof(sljit_sw))
575 #endif /* _WIN64 */
576
577 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
578
579 #define SLJIT_NUMBER_OF_REGISTERS 11
580 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
581 #define SLJIT_LOCALS_OFFSET_BASE 0
582
583 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
584
585 #define SLJIT_NUMBER_OF_REGISTERS 11
586 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
587 #define SLJIT_LOCALS_OFFSET_BASE 0
588
589 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
590
591 #define SLJIT_NUMBER_OF_REGISTERS 25
592 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10
593 #define SLJIT_LOCALS_OFFSET_BASE (2 * sizeof(sljit_sw))
594
595 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
596
597 #define SLJIT_NUMBER_OF_REGISTERS 22
598 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17
599 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX)
600 #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw))
601 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
602 /* Add +1 for double alignment. */
603 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * sizeof(sljit_sw))
604 #else
605 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
606 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
607
608 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
609
610 #define SLJIT_NUMBER_OF_REGISTERS 17
611 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
612 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
613 #define SLJIT_LOCALS_OFFSET_BASE (4 * sizeof(sljit_sw))
614 #else
615 #define SLJIT_LOCALS_OFFSET_BASE 0
616 #endif
617
618 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
619
620 #define SLJIT_NUMBER_OF_REGISTERS 18
621 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14
622 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
623 /* Add +1 for double alignment. */
624 #define SLJIT_LOCALS_OFFSET_BASE ((23 + 1) * sizeof(sljit_sw))
625 #endif
626
627 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
628
629 #define SLJIT_NUMBER_OF_REGISTERS 10
630 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
631 #define SLJIT_LOCALS_OFFSET_BASE 0
632
633 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
634
635 #define SLJIT_NUMBER_OF_REGISTERS 0
636 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
637 #define SLJIT_LOCALS_OFFSET_BASE 0
638
639 #endif
640
641 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
642
643 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
644 (SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
645
646 #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 6
647 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && (defined _WIN64)
648 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 1
649 #else
650 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
651 #endif
652
653 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
654 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
655
656 /*************************************/
657 /* Debug and verbose related macros. */
658 /*************************************/
659
660 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
661 #include <stdio.h>
662 #endif
663
664 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
665
666 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
667
668 /* SLJIT_HALT_PROCESS must halt the process. */
669 #ifndef SLJIT_HALT_PROCESS
670 #include <stdlib.h>
671
672 #define SLJIT_HALT_PROCESS() \
673 abort();
674 #endif /* !SLJIT_HALT_PROCESS */
675
676 #include <stdio.h>
677
678 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
679
680 /* Feel free to redefine these two macros. */
681 #ifndef SLJIT_ASSERT
682
683 #define SLJIT_ASSERT(x) \
684 do { \
685 if (SLJIT_UNLIKELY(!(x))) { \
686 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
687 SLJIT_HALT_PROCESS(); \
688 } \
689 } while (0)
690
691 #endif /* !SLJIT_ASSERT */
692
693 #ifndef SLJIT_ASSERT_STOP
694
695 #define SLJIT_ASSERT_STOP() \
696 do { \
697 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
698 SLJIT_HALT_PROCESS(); \
699 } while (0)
700
701 #endif /* !SLJIT_ASSERT_STOP */
702
703 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
704
705 /* Forcing empty, but valid statements. */
706 #undef SLJIT_ASSERT
707 #undef SLJIT_ASSERT_STOP
708
709 #define SLJIT_ASSERT(x) \
710 do { } while (0)
711 #define SLJIT_ASSERT_STOP() \
712 do { } while (0)
713
714 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
715
716 #ifndef SLJIT_COMPILE_ASSERT
717
718 /* Should be improved eventually. */
719 #define SLJIT_COMPILE_ASSERT(x, description) \
720 SLJIT_ASSERT(x)
721
722 #endif /* !SLJIT_COMPILE_ASSERT */
723
724 #endif

  ViewVC Help
Powered by ViewVC 1.1.5