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_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
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_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
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 */
267 #ifndef SLJIT_UNUSED_ARG
268 /* Unused arguments. */
269 #define SLJIT_UNUSED_ARG(arg) (void)arg
272 /*********************************/
273 /* Type of public API functions. */
274 /*********************************/
276 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
277 /* Static ABI functions. For all-in-one programs. */
279 #if defined(__GNUC__)
280 /* Disable unused warnings in gcc. */
281 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
283 #define SLJIT_API_FUNC_ATTRIBUTE static
287 #define SLJIT_API_FUNC_ATTRIBUTE
288 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
290 /****************************/
291 /* Instruction cache flush. */
292 /****************************/
294 #if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin)
295 #if __has_builtin(__builtin___clear_cache)
297 #define SLJIT_CACHE_FLUSH(from, to) \
298 __builtin___clear_cache((char*)from, (char*)to)
300 #endif /* __has_builtin(__builtin___clear_cache) */
301 #endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */
303 #ifndef SLJIT_CACHE_FLUSH
305 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
307 /* Not required to implement on archs with unified caches. */
308 #define SLJIT_CACHE_FLUSH(from, to)
310 #elif defined __APPLE__
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. */
316 #define SLJIT_CACHE_FLUSH(from, to) \
317 sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
319 #elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
321 #define SLJIT_CACHE_FLUSH(from, to) \
322 __builtin___clear_cache((char*)from, (char*)to)
324 #elif defined __ANDROID__
326 /* Android lacks __clear_cache; instead, cacheflush should be used. */
328 #define SLJIT_CACHE_FLUSH(from, to) \
329 cacheflush((long)(from), (long)(to), 0)
331 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
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
338 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
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
347 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
348 #define SLJIT_CACHE_FLUSH(from, to) \
349 __clear_cache((char*)(from), (char*)(to))
353 #endif /* !SLJIT_CACHE_FLUSH */
355 /******************************************************/
356 /* Integer and floating point type definitions. */
357 /******************************************************/
359 /* 8 bit byte type. */
360 typedef unsigned char sljit_u8;
361 typedef signed char sljit_s8;
363 /* 16 bit half-word type. */
364 typedef unsigned short int sljit_u16;
365 typedef signed short int sljit_s16;
367 /* 32 bit integer type. */
368 typedef unsigned int sljit_u32;
369 typedef signed int sljit_s32;
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;
389 #define SLJIT_64BIT_ARCHITECTURE 1
390 #define SLJIT_WORD_SHIFT 3
392 typedef unsigned __int64 sljit_uw;
393 typedef __int64 sljit_sw;
395 typedef unsigned long int sljit_uw;
396 typedef long int sljit_sw;
400 typedef sljit_uw sljit_p;
402 /* Floating point types. */
403 typedef float sljit_f32;
404 typedef double sljit_f64;
406 /* Shift for pointer sized data. */
407 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
409 /* Shift for double precision sized data. */
410 #define SLJIT_F32_SHIFT 2
411 #define SLJIT_F64_SHIFT 3
415 /* Defining long constants. */
416 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
417 #define SLJIT_W(w) (w##ll)
419 #define SLJIT_W(w) (w)
422 #endif /* !SLJIT_W */
424 /*************************/
425 /* Endianness detection. */
426 /*************************/
428 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
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)
434 #ifdef __LITTLE_ENDIAN__
435 #define SLJIT_LITTLE_ENDIAN 1
437 #define SLJIT_BIG_ENDIAN 1
440 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
441 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
444 #define SLJIT_LITTLE_ENDIAN 1
446 #define SLJIT_BIG_ENDIAN 1
449 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
451 #define SLJIT_BIG_ENDIAN 1
454 #define SLJIT_LITTLE_ENDIAN 1
457 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
460 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
461 #error "Exactly one endianness must be selected"
464 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
465 #error "Exactly one endianness must be selected"
468 #ifndef SLJIT_UNALIGNED
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
480 #endif /* !SLJIT_UNALIGNED */
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
488 /*****************************************************************************************/
489 /* Calling convention of functions generated by SLJIT or called from the generated code. */
490 /*****************************************************************************************/
494 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
499 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
501 #if defined(__GNUC__) && !defined(__APPLE__)
503 #define SLJIT_CALL __attribute__ ((fastcall))
504 #define SLJIT_X86_32_FASTCALL 1
506 #elif defined(_MSC_VER)
508 #define SLJIT_CALL __fastcall
509 #define SLJIT_X86_32_FASTCALL 1
511 #elif defined(__BORLANDC__)
513 #define SLJIT_CALL __msfastcall
514 #define SLJIT_X86_32_FASTCALL 1
516 #else /* Unknown compiler. */
518 /* The cdecl attribute is the default. */
523 #else /* Non x86-32 architectures. */
527 #endif /* SLJIT_CONFIG_X86_32 */
529 #endif /* !SLJIT_CALL */
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
538 #endif /* SLJIT_INDIRECT_CALL */
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
546 #define SLJIT_RETURN_ADDRESS_OFFSET 0
548 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
550 /***************************************************/
551 /* Functions of the built-in executable allocator. */
552 /***************************************************/
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)
562 /**********************************************/
563 /* Registers and locals offset determination. */
564 /**********************************************/
566 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
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))
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 */
577 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
580 #define SLJIT_NUMBER_OF_REGISTERS 12
581 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
582 #define SLJIT_LOCALS_OFFSET_BASE (sizeof(sljit_sw))
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))
589 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
591 #define SLJIT_NUMBER_OF_REGISTERS 11
592 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
593 #define SLJIT_LOCALS_OFFSET_BASE 0
595 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
597 #define SLJIT_NUMBER_OF_REGISTERS 11
598 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
599 #define SLJIT_LOCALS_OFFSET_BASE 0
601 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
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))
607 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
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))
617 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
618 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
620 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
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))
627 #define SLJIT_LOCALS_OFFSET_BASE 0
630 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
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))
639 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
641 #define SLJIT_NUMBER_OF_REGISTERS 10
642 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
643 #define SLJIT_LOCALS_OFFSET_BASE 0
645 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
647 #define SLJIT_NUMBER_OF_REGISTERS 0
648 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
649 #define SLJIT_LOCALS_OFFSET_BASE 0
653 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
655 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
656 (SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
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
662 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
665 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
666 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
668 /*************************************/
669 /* Debug and verbose related macros. */
670 /*************************************/
672 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
676 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
678 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
680 /* SLJIT_HALT_PROCESS must halt the process. */
681 #ifndef SLJIT_HALT_PROCESS
684 #define SLJIT_HALT_PROCESS() \
686 #endif /* !SLJIT_HALT_PROCESS */
690 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
692 /* Feel free to redefine these two macros. */
695 #define SLJIT_ASSERT(x) \
697 if (SLJIT_UNLIKELY(!(x))) { \
698 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
699 SLJIT_HALT_PROCESS(); \
703 #endif /* !SLJIT_ASSERT */
705 #ifndef SLJIT_ASSERT_STOP
707 #define SLJIT_ASSERT_STOP() \
709 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
710 SLJIT_HALT_PROCESS(); \
713 #endif /* !SLJIT_ASSERT_STOP */
715 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
717 /* Forcing empty, but valid statements. */
719 #undef SLJIT_ASSERT_STOP
721 #define SLJIT_ASSERT(x) \
723 #define SLJIT_ASSERT_STOP() \
726 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
728 #ifndef SLJIT_COMPILE_ASSERT
730 /* Should be improved eventually. */
731 #define SLJIT_COMPILE_ASSERT(x, description) \
734 #endif /* !SLJIT_COMPILE_ASSERT */