2 * Stack-less Just-In-Time compiler
4 * Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
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.
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.
27 #ifndef _SLJIT_CONFIG_INTERNAL_H_
28 #define _SLJIT_CONFIG_INTERNAL_H_
31 SLJIT defines the following architecture dependent types and macros:
34 sljit_sb, sljit_ub : signed and unsigned 8 bit byte
35 sljit_sh, sljit_uh : signed and unsigned 16 bit half-word (short) type
36 sljit_si, sljit_ui : 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_s : single precision floating point value
41 sljit_d : double precision floating point value
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
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_DOUBLE_SHIFT : the shift required to apply when accessing
60 a double precision floating point array by index
61 SLJIT_SINGLE_SHIFT : the shift required to apply when accessing
62 a single 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
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)
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"
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"
109 /********************************************************/
110 /* Automatic CPU detection (requires compiler support). */
111 /********************************************************/
113 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
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
123 # define SLJIT_CONFIG_X86_64 1
125 #elif defined(__arm__) || defined(__ARM__)
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
131 #define SLJIT_CONFIG_ARM_V5 1
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)
139 # define SLJIT_CONFIG_PPC_32 1
141 # define SLJIT_CONFIG_UNSUPPORTED 1
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
151 # define SLJIT_CONFIG_SPARC_32 1
153 #elif defined(__tilegx__)
154 #define SLJIT_CONFIG_TILEGX 1
156 /* Unsupported architecture */
157 #define SLJIT_CONFIG_UNSUPPORTED 1
162 #if defined(_M_X64) || defined(__x86_64__)
163 #define SLJIT_CONFIG_X86_64 1
165 #define SLJIT_CONFIG_ARM_V5 1
167 #define SLJIT_CONFIG_X86_32 1
171 #endif /* SLJIT_CONFIG_AUTO */
173 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
174 #undef SLJIT_EXECUTABLE_ALLOCATOR
177 /******************************/
178 /* CPU family type detection. */
179 /******************************/
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
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
198 /**********************************/
199 /* External function definitions. */
200 /**********************************/
202 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
204 /* These libraries are needed for the macros below. */
208 #endif /* SLJIT_STD_MACROS_DEFINED */
211 Note: SLJIT is designed to be independent from them as possible.
213 In release mode (SLJIT_DEBUG is not defined) only the following
214 external functions are needed:
218 #define SLJIT_MALLOC(size, allocator_data) malloc(size)
222 #define SLJIT_FREE(ptr, allocator_data) free(ptr)
225 #ifndef SLJIT_MEMMOVE
226 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
229 #ifndef SLJIT_ZEROMEM
230 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
233 /***************************/
234 /* Compiler helper macros. */
235 /***************************/
237 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
239 #if defined(__GNUC__) && (__GNUC__ >= 3)
240 #define SLJIT_LIKELY(x) __builtin_expect((x), 1)
241 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0)
243 #define SLJIT_LIKELY(x) (x)
244 #define SLJIT_UNLIKELY(x) (x)
247 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
250 /* Inline functions. Some old compilers do not support them. */
251 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
254 #define SLJIT_INLINE __inline
256 #endif /* !SLJIT_INLINE */
258 #ifndef SLJIT_NOINLINE
259 /* Not inline functions. */
260 #if defined(__GNUC__)
261 #define SLJIT_NOINLINE __attribute__ ((noinline))
263 #define SLJIT_NOINLINE
265 #endif /* !SLJIT_INLINE */
268 /* Const variables. */
269 #define SLJIT_CONST const
272 #ifndef SLJIT_UNUSED_ARG
273 /* Unused arguments. */
274 #define SLJIT_UNUSED_ARG(arg) (void)arg
277 /*********************************/
278 /* Type of public API functions. */
279 /*********************************/
281 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
282 /* Static ABI functions. For all-in-one programs. */
284 #if defined(__GNUC__)
285 /* Disable unused warnings in gcc. */
286 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
288 #define SLJIT_API_FUNC_ATTRIBUTE static
292 #define SLJIT_API_FUNC_ATTRIBUTE
293 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
295 /****************************/
296 /* Instruction cache flush. */
297 /****************************/
299 #ifndef SLJIT_CACHE_FLUSH
301 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
303 /* Not required to implement on archs with unified caches. */
304 #define SLJIT_CACHE_FLUSH(from, to)
306 #elif defined __APPLE__
308 /* Supported by all macs since Mac OS 10.5.
309 However, it does not work on non-jailbroken iOS devices,
310 although the compilation is successful. */
312 #define SLJIT_CACHE_FLUSH(from, to) \
313 sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
315 #elif defined __ANDROID__
317 /* Android lacks __clear_cache; instead, cacheflush should be used. */
319 #define SLJIT_CACHE_FLUSH(from, to) \
320 cacheflush((long)(from), (long)(to), 0)
322 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
324 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
325 #define SLJIT_CACHE_FLUSH(from, to) \
326 ppc_cache_flush((from), (to))
328 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
330 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
331 #define SLJIT_CACHE_FLUSH(from, to) \
332 sparc_cache_flush((from), (to))
336 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
337 #define SLJIT_CACHE_FLUSH(from, to) \
338 __clear_cache((char*)(from), (char*)(to))
342 #endif /* !SLJIT_CACHE_FLUSH */
344 /******************************************************/
345 /* Byte/half/int/word/single/double type definitions. */
346 /******************************************************/
348 /* 8 bit byte type. */
349 typedef unsigned char sljit_ub;
350 typedef signed char sljit_sb;
352 /* 16 bit half-word type. */
353 typedef unsigned short int sljit_uh;
354 typedef signed short int sljit_sh;
356 /* 32 bit integer type. */
357 typedef unsigned int sljit_ui;
358 typedef signed int sljit_si;
360 /* Machine word type. Enough for storing a pointer.
361 32 bit for 32 bit machines.
362 64 bit for 64 bit machines. */
363 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
364 /* Just to have something. */
365 #define SLJIT_WORD_SHIFT 0
366 typedef unsigned long int sljit_uw;
367 typedef long int sljit_sw;
368 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
369 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
370 && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
371 && !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
372 && !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
373 #define SLJIT_32BIT_ARCHITECTURE 1
374 #define SLJIT_WORD_SHIFT 2
375 typedef unsigned int sljit_uw;
376 typedef int sljit_sw;
378 #define SLJIT_64BIT_ARCHITECTURE 1
379 #define SLJIT_WORD_SHIFT 3
381 typedef unsigned __int64 sljit_uw;
382 typedef __int64 sljit_sw;
384 typedef unsigned long int sljit_uw;
385 typedef long int sljit_sw;
389 typedef sljit_uw sljit_p;
391 /* Floating point types. */
392 typedef float sljit_s;
393 typedef double sljit_d;
395 /* Shift for pointer sized data. */
396 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
398 /* Shift for double precision sized data. */
399 #define SLJIT_DOUBLE_SHIFT 3
400 #define SLJIT_SINGLE_SHIFT 2
404 /* Defining long constants. */
405 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
406 #define SLJIT_W(w) (w##ll)
408 #define SLJIT_W(w) (w)
411 #endif /* !SLJIT_W */
413 /*************************/
414 /* Endianness detection. */
415 /*************************/
417 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
419 /* These macros are mostly useful for the applications. */
420 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
421 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
423 #ifdef __LITTLE_ENDIAN__
424 #define SLJIT_LITTLE_ENDIAN 1
426 #define SLJIT_BIG_ENDIAN 1
429 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
430 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
433 #define SLJIT_LITTLE_ENDIAN 1
435 #define SLJIT_BIG_ENDIAN 1
438 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
440 #define SLJIT_BIG_ENDIAN 1
443 #define SLJIT_LITTLE_ENDIAN 1
446 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
449 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
450 #error "Exactly one endianness must be selected"
453 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
454 #error "Exactly one endianness must be selected"
457 #ifndef SLJIT_UNALIGNED
459 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
460 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
461 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
462 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
463 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
464 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
465 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
466 #define SLJIT_UNALIGNED 1
469 #endif /* !SLJIT_UNALIGNED */
471 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
472 /* Auto detect SSE2 support using CPUID.
473 On 64 bit x86 cpus, sse2 must be present. */
474 #define SLJIT_DETECT_SSE2 1
477 /*****************************************************************************************/
478 /* Calling convention of functions generated by SLJIT or called from the generated code. */
479 /*****************************************************************************************/
483 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
488 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
490 #if defined(__GNUC__) && !defined(__APPLE__)
492 #define SLJIT_CALL __attribute__ ((fastcall))
493 #define SLJIT_X86_32_FASTCALL 1
495 #elif defined(_MSC_VER)
497 #define SLJIT_CALL __fastcall
498 #define SLJIT_X86_32_FASTCALL 1
500 #elif defined(__BORLANDC__)
502 #define SLJIT_CALL __msfastcall
503 #define SLJIT_X86_32_FASTCALL 1
505 #else /* Unknown compiler. */
507 /* The cdecl attribute is the default. */
512 #else /* Non x86-32 architectures. */
516 #endif /* SLJIT_CONFIG_X86_32 */
518 #endif /* !SLJIT_CALL */
520 #ifndef SLJIT_INDIRECT_CALL
521 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
522 || ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
523 /* It seems certain ppc compilers use an indirect addressing for functions
524 which makes things complicated. */
525 #define SLJIT_INDIRECT_CALL 1
527 #endif /* SLJIT_INDIRECT_CALL */
529 /* The offset which needs to be substracted from the return address to
530 determine the next executed instruction after return. */
531 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
532 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
533 #define SLJIT_RETURN_ADDRESS_OFFSET 8
535 #define SLJIT_RETURN_ADDRESS_OFFSET 0
537 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
539 /***************************************************/
540 /* Functions of the built-in executable allocator. */
541 /***************************************************/
543 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
544 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
545 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
546 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
547 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
548 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
551 /**********************************************/
552 /* Registers and locals offset determination. */
553 /**********************************************/
555 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
557 #define SLJIT_NUMBER_OF_REGISTERS 10
558 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
559 #if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
560 #define SLJIT_LOCALS_OFFSET_BASE ((2 + 4) * sizeof(sljit_sw))
562 /* Maximum 3 arguments are passed on the stack, +1 for double alignment. */
563 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1 + 4) * sizeof(sljit_sw))
564 #endif /* SLJIT_X86_32_FASTCALL */
566 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
569 #define SLJIT_NUMBER_OF_REGISTERS 12
570 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
571 #define SLJIT_LOCALS_OFFSET_BASE (sizeof(sljit_sw))
573 #define SLJIT_NUMBER_OF_REGISTERS 12
574 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
575 #define SLJIT_LOCALS_OFFSET_BASE ((4 + 2) * sizeof(sljit_sw))
578 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
580 #define SLJIT_NUMBER_OF_REGISTERS 11
581 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
582 #define SLJIT_LOCALS_OFFSET_BASE 0
584 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
586 #define SLJIT_NUMBER_OF_REGISTERS 11
587 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
588 #define SLJIT_LOCALS_OFFSET_BASE 0
590 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
592 #define SLJIT_NUMBER_OF_REGISTERS 25
593 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10
594 #define SLJIT_LOCALS_OFFSET_BASE (2 * sizeof(sljit_sw))
596 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
598 #define SLJIT_NUMBER_OF_REGISTERS 22
599 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17
600 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX)
601 #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw))
602 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
603 /* Add +1 for double alignment. */
604 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * sizeof(sljit_sw))
606 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
607 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
609 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
611 #define SLJIT_NUMBER_OF_REGISTERS 17
612 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
613 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
614 #define SLJIT_LOCALS_OFFSET_BASE (4 * sizeof(sljit_sw))
616 #define SLJIT_LOCALS_OFFSET_BASE 0
619 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
621 #define SLJIT_NUMBER_OF_REGISTERS 18
622 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14
623 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
624 /* Add +1 for double alignment. */
625 #define SLJIT_LOCALS_OFFSET_BASE ((23 + 1) * sizeof(sljit_sw))
628 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
630 #define SLJIT_NUMBER_OF_REGISTERS 10
631 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
632 #define SLJIT_LOCALS_OFFSET_BASE 0
634 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
636 #define SLJIT_NUMBER_OF_REGISTERS 0
637 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
638 #define SLJIT_LOCALS_OFFSET_BASE 0
642 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
644 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
645 (SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
647 #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 6
648 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && (defined _WIN64)
649 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 1
651 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
654 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
655 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
657 /*************************************/
658 /* Debug and verbose related macros. */
659 /*************************************/
661 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
665 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
667 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
669 /* SLJIT_HALT_PROCESS must halt the process. */
670 #ifndef SLJIT_HALT_PROCESS
673 #define SLJIT_HALT_PROCESS() \
675 #endif /* !SLJIT_HALT_PROCESS */
679 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
681 /* Feel free to redefine these two macros. */
684 #define SLJIT_ASSERT(x) \
686 if (SLJIT_UNLIKELY(!(x))) { \
687 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
688 SLJIT_HALT_PROCESS(); \
692 #endif /* !SLJIT_ASSERT */
694 #ifndef SLJIT_ASSERT_STOP
696 #define SLJIT_ASSERT_STOP() \
698 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
699 SLJIT_HALT_PROCESS(); \
702 #endif /* !SLJIT_ASSERT_STOP */
704 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
706 /* Forcing empty, but valid statements. */
708 #undef SLJIT_ASSERT_STOP
710 #define SLJIT_ASSERT(x) \
712 #define SLJIT_ASSERT_STOP() \
715 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
717 #ifndef SLJIT_COMPILE_ASSERT
719 /* Should be improved eventually. */
720 #define SLJIT_COMPILE_ASSERT(x, description) \
723 #endif /* !SLJIT_COMPILE_ASSERT */