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