2 * Stack-less Just-In-Time compiler
4 * Copyright 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_PREF_SHIFT_REG : x86 systems prefers ecx for shifting by register
64 the scratch register index of ecx is stored in this variable
65 SLJIT_LOCALS_OFFSET : local space starting offset (SLJIT_SP + SLJIT_LOCALS_OFFSET)
66 SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address
69 SLJIT_FUNC : calling convention attribute for both calling JIT from C and C calling back from JIT
70 SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (compiler independent helper)
77 #if !((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
78 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
79 || (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
80 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
81 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
82 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
83 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
84 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
85 || (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
86 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
87 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
88 || (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
89 || (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
90 || (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED))
91 #error "An architecture must be selected"
94 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
95 + (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
96 + (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) \
97 + (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
98 + (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
99 + (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
100 + (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
101 + (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
102 + (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) \
103 + (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
104 + (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
105 + (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
106 + (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO) \
107 + (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) >= 2
108 #error "Multiple architectures are selected"
111 /********************************************************/
112 /* Automatic CPU detection (requires compiler support). */
113 /********************************************************/
115 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
119 #if defined(__i386__) || defined(__i386)
120 #define SLJIT_CONFIG_X86_32 1
121 #elif defined(__x86_64__)
122 #define SLJIT_CONFIG_X86_64 1
123 #elif defined(__arm__) || defined(__ARM__)
125 #define SLJIT_CONFIG_ARM_THUMB2 1
126 #elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__)
127 #define SLJIT_CONFIG_ARM_V7 1
129 #define SLJIT_CONFIG_ARM_V5 1
131 #elif defined (__aarch64__)
132 #define SLJIT_CONFIG_ARM_64 1
133 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(_ARCH_PPC64) || (defined(_POWER) && defined(__64BIT__))
134 #define SLJIT_CONFIG_PPC_64 1
135 #elif defined(__ppc__) || defined(__powerpc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_POWER)
136 #define SLJIT_CONFIG_PPC_32 1
137 #elif defined(__mips__) && !defined(_LP64)
138 #define SLJIT_CONFIG_MIPS_32 1
139 #elif defined(__mips64)
140 #define SLJIT_CONFIG_MIPS_64 1
141 #elif defined(__sparc__) || defined(__sparc)
142 #define SLJIT_CONFIG_SPARC_32 1
143 #elif defined(__tilegx__)
144 #define SLJIT_CONFIG_TILEGX 1
146 /* Unsupported architecture */
147 #define SLJIT_CONFIG_UNSUPPORTED 1
152 #if defined(_M_X64) || defined(__x86_64__)
153 #define SLJIT_CONFIG_X86_64 1
154 #elif (defined(_M_ARM) && _M_ARM >= 7 && defined(_M_ARMT)) || defined(__thumb2__)
155 #define SLJIT_CONFIG_ARM_THUMB2 1
156 #elif (defined(_M_ARM) && _M_ARM >= 7)
157 #define SLJIT_CONFIG_ARM_V7 1
159 #define SLJIT_CONFIG_ARM_V5 1
160 #elif defined(_M_ARM64) || defined(__aarch64__)
161 #define SLJIT_CONFIG_ARM_64 1
163 #define SLJIT_CONFIG_X86_32 1
167 #endif /* SLJIT_CONFIG_AUTO */
169 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
170 #undef SLJIT_EXECUTABLE_ALLOCATOR
173 /******************************/
174 /* CPU family type detection. */
175 /******************************/
177 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
178 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
179 #define SLJIT_CONFIG_ARM_32 1
182 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
183 #define SLJIT_CONFIG_X86 1
184 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
185 #define SLJIT_CONFIG_ARM 1
186 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
187 #define SLJIT_CONFIG_PPC 1
188 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
189 #define SLJIT_CONFIG_MIPS 1
190 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) || (defined SLJIT_CONFIG_SPARC_64 && SLJIT_CONFIG_SPARC_64)
191 #define SLJIT_CONFIG_SPARC 1
194 /**********************************/
195 /* External function definitions. */
196 /**********************************/
199 Note: SLJIT is designed to be independent from them as possible.
201 In release mode (SLJIT_DEBUG is not defined) only the following
202 external functions are needed:
206 #define SLJIT_MALLOC(size, allocator_data) malloc(size)
210 #define SLJIT_FREE(ptr, allocator_data) free(ptr)
214 #define SLJIT_MEMCPY(dest, src, len) memcpy(dest, src, len)
217 #ifndef SLJIT_ZEROMEM
218 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
221 /***************************/
222 /* Compiler helper macros. */
223 /***************************/
225 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
227 #if defined(__GNUC__) && (__GNUC__ >= 3)
228 #define SLJIT_LIKELY(x) __builtin_expect((x), 1)
229 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0)
231 #define SLJIT_LIKELY(x) (x)
232 #define SLJIT_UNLIKELY(x) (x)
235 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
238 /* Inline functions. Some old compilers do not support them. */
239 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
242 #define SLJIT_INLINE __inline
244 #endif /* !SLJIT_INLINE */
246 #ifndef SLJIT_NOINLINE
247 /* Not inline functions. */
248 #if defined(__GNUC__)
249 #define SLJIT_NOINLINE __attribute__ ((noinline))
251 #define SLJIT_NOINLINE
253 #endif /* !SLJIT_INLINE */
255 #ifndef SLJIT_UNUSED_ARG
256 /* Unused arguments. */
257 #define SLJIT_UNUSED_ARG(arg) (void)arg
260 /*********************************/
261 /* Type of public API functions. */
262 /*********************************/
264 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
265 /* Static ABI functions. For all-in-one programs. */
267 #if defined(__GNUC__)
268 /* Disable unused warnings in gcc. */
269 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
271 #define SLJIT_API_FUNC_ATTRIBUTE static
275 #define SLJIT_API_FUNC_ATTRIBUTE
276 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
278 /****************************/
279 /* Instruction cache flush. */
280 /****************************/
282 #if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin)
283 #if __has_builtin(__builtin___clear_cache)
285 #define SLJIT_CACHE_FLUSH(from, to) \
286 __builtin___clear_cache((char*)from, (char*)to)
288 #endif /* __has_builtin(__builtin___clear_cache) */
289 #endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */
291 #ifndef SLJIT_CACHE_FLUSH
293 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
295 /* Not required to implement on archs with unified caches. */
296 #define SLJIT_CACHE_FLUSH(from, to)
298 #elif defined __APPLE__
300 /* Supported by all macs since Mac OS 10.5.
301 However, it does not work on non-jailbroken iOS devices,
302 although the compilation is successful. */
304 #define SLJIT_CACHE_FLUSH(from, to) \
305 sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
307 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
309 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
310 #define SLJIT_CACHE_FLUSH(from, to) \
311 ppc_cache_flush((from), (to))
312 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1
314 #elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
316 #define SLJIT_CACHE_FLUSH(from, to) \
317 __builtin___clear_cache((char*)from, (char*)to)
319 #elif defined __ANDROID__
321 /* Android lacks __clear_cache; instead, cacheflush should be used. */
323 #define SLJIT_CACHE_FLUSH(from, to) \
324 cacheflush((long)(from), (long)(to), 0)
326 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
328 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
329 #define SLJIT_CACHE_FLUSH(from, to) \
330 sparc_cache_flush((from), (to))
331 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1
335 #define SLJIT_CACHE_FLUSH(from, to) \
336 FlushInstructionCache(GetCurrentProcess(), (char*)(from), (char*)(to) - (char*)(from))
340 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
341 #define SLJIT_CACHE_FLUSH(from, to) \
342 __clear_cache((char*)(from), (char*)(to))
346 #endif /* !SLJIT_CACHE_FLUSH */
348 /******************************************************/
349 /* Integer and floating point type definitions. */
350 /******************************************************/
352 /* 8 bit byte type. */
353 typedef unsigned char sljit_u8;
354 typedef signed char sljit_s8;
356 /* 16 bit half-word type. */
357 typedef unsigned short int sljit_u16;
358 typedef signed short int sljit_s16;
360 /* 32 bit integer type. */
361 typedef unsigned int sljit_u32;
362 typedef signed int sljit_s32;
364 /* Machine word type. Enough for storing a pointer.
365 32 bit for 32 bit machines.
366 64 bit for 64 bit machines. */
367 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
368 /* Just to have something. */
369 #define SLJIT_WORD_SHIFT 0
370 typedef unsigned long int sljit_uw;
371 typedef long int sljit_sw;
372 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
373 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
374 && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
375 && !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
376 && !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
377 #define SLJIT_32BIT_ARCHITECTURE 1
378 #define SLJIT_WORD_SHIFT 2
379 typedef unsigned int sljit_uw;
380 typedef int sljit_sw;
382 #define SLJIT_64BIT_ARCHITECTURE 1
383 #define SLJIT_WORD_SHIFT 3
386 /* These types do not require windows.h */
387 typedef unsigned long long sljit_uw;
388 typedef long long sljit_sw;
390 typedef unsigned __int64 sljit_uw;
391 typedef __int64 sljit_sw;
394 typedef unsigned long int sljit_uw;
395 typedef long int sljit_sw;
399 typedef sljit_uw sljit_p;
401 /* Floating point types. */
402 typedef float sljit_f32;
403 typedef double sljit_f64;
405 /* Shift for pointer sized data. */
406 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
408 /* Shift for double precision sized data. */
409 #define SLJIT_F32_SHIFT 2
410 #define SLJIT_F64_SHIFT 3
414 /* Defining long constants. */
415 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
416 #define SLJIT_W(w) (w##l)
417 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
418 #define SLJIT_W(w) (w##ll)
420 #define SLJIT_W(w) (w)
423 #endif /* !SLJIT_W */
425 /*************************/
426 /* Endianness detection. */
427 /*************************/
429 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
431 /* These macros are mostly useful for the applications. */
432 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
433 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
435 #ifdef __LITTLE_ENDIAN__
436 #define SLJIT_LITTLE_ENDIAN 1
438 #define SLJIT_BIG_ENDIAN 1
441 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
442 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
445 #define SLJIT_LITTLE_ENDIAN 1
447 #define SLJIT_BIG_ENDIAN 1
450 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
452 #define SLJIT_BIG_ENDIAN 1
455 #define SLJIT_LITTLE_ENDIAN 1
458 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
461 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
462 #error "Exactly one endianness must be selected"
465 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
466 #error "Exactly one endianness must be selected"
469 #ifndef SLJIT_UNALIGNED
471 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
472 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
473 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
474 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
475 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
476 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
477 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
478 #define SLJIT_UNALIGNED 1
481 #endif /* !SLJIT_UNALIGNED */
483 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
484 /* Auto detect SSE2 support using CPUID.
485 On 64 bit x86 cpus, sse2 must be present. */
486 #define SLJIT_DETECT_SSE2 1
489 /*****************************************************************************************/
490 /* Calling convention of functions generated by SLJIT or called from the generated code. */
491 /*****************************************************************************************/
495 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
500 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
502 #if defined(__GNUC__) && !defined(__APPLE__)
504 #define SLJIT_FUNC __attribute__ ((fastcall))
505 #define SLJIT_X86_32_FASTCALL 1
507 #elif defined(_MSC_VER)
509 #define SLJIT_FUNC __fastcall
510 #define SLJIT_X86_32_FASTCALL 1
512 #elif defined(__BORLANDC__)
514 #define SLJIT_FUNC __msfastcall
515 #define SLJIT_X86_32_FASTCALL 1
517 #else /* Unknown compiler. */
519 /* The cdecl attribute is the default. */
524 #else /* Non x86-32 architectures. */
528 #endif /* SLJIT_CONFIG_X86_32 */
530 #endif /* !SLJIT_FUNC */
532 #ifndef SLJIT_INDIRECT_CALL
533 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
534 || ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
535 /* It seems certain ppc compilers use an indirect addressing for functions
536 which makes things complicated. */
537 #define SLJIT_INDIRECT_CALL 1
539 #endif /* SLJIT_INDIRECT_CALL */
541 /* The offset which needs to be substracted from the return address to
542 determine the next executed instruction after return. */
543 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
544 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
545 #define SLJIT_RETURN_ADDRESS_OFFSET 8
547 #define SLJIT_RETURN_ADDRESS_OFFSET 0
549 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
551 /***************************************************/
552 /* Functions of the built-in executable allocator. */
553 /***************************************************/
555 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
556 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
557 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
558 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
559 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
560 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
562 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
563 SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void* ptr);
564 #define SLJIT_EXEC_OFFSET(ptr) sljit_exec_offset(ptr)
566 #define SLJIT_EXEC_OFFSET(ptr) 0
571 /**********************************************/
572 /* Registers and locals offset determination. */
573 /**********************************************/
575 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
577 #define SLJIT_NUMBER_OF_REGISTERS 12
578 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 9
579 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset)
580 #define SLJIT_PREF_SHIFT_REG SLJIT_R2
582 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
584 #define SLJIT_NUMBER_OF_REGISTERS 13
586 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
587 #define SLJIT_LOCALS_OFFSET_BASE 0
589 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
590 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset)
592 #define SLJIT_PREF_SHIFT_REG SLJIT_R3
594 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
596 #define SLJIT_NUMBER_OF_REGISTERS 12
597 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
598 #define SLJIT_LOCALS_OFFSET_BASE 0
600 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
602 #define SLJIT_NUMBER_OF_REGISTERS 12
603 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
604 #define SLJIT_LOCALS_OFFSET_BASE 0
606 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
608 #define SLJIT_NUMBER_OF_REGISTERS 26
609 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10
610 #define SLJIT_LOCALS_OFFSET_BASE 0
612 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
614 #define SLJIT_NUMBER_OF_REGISTERS 23
615 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17
616 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX)
617 #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw))
618 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
619 /* Add +1 for double alignment. */
620 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * sizeof(sljit_sw))
622 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
623 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
625 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
627 #define SLJIT_NUMBER_OF_REGISTERS 21
628 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
629 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
630 #define SLJIT_LOCALS_OFFSET_BASE (4 * sizeof(sljit_sw))
632 #define SLJIT_LOCALS_OFFSET_BASE 0
635 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
637 #define SLJIT_NUMBER_OF_REGISTERS 18
638 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14
639 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
640 /* saved registers (16), return struct pointer (1), space for 6 argument words (1),
641 4th double arg (2), double alignment (1). */
642 #define SLJIT_LOCALS_OFFSET_BASE ((16 + 1 + 6 + 2 + 1) * sizeof(sljit_sw))
645 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
647 #define SLJIT_NUMBER_OF_REGISTERS 10
648 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
649 #define SLJIT_LOCALS_OFFSET_BASE 0
651 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
653 #define SLJIT_NUMBER_OF_REGISTERS 0
654 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
655 #define SLJIT_LOCALS_OFFSET_BASE 0
659 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
661 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
662 (SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
664 #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 6
665 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && (defined _WIN64)
666 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 1
668 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
671 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
672 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
674 /*************************************/
675 /* Debug and verbose related macros. */
676 /*************************************/
678 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
682 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
684 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_UNREACHABLE)
686 /* SLJIT_HALT_PROCESS must halt the process. */
687 #ifndef SLJIT_HALT_PROCESS
690 #define SLJIT_HALT_PROCESS() \
692 #endif /* !SLJIT_HALT_PROCESS */
696 #endif /* !SLJIT_ASSERT || !SLJIT_UNREACHABLE */
698 /* Feel free to redefine these two macros. */
701 #define SLJIT_ASSERT(x) \
703 if (SLJIT_UNLIKELY(!(x))) { \
704 printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
705 SLJIT_HALT_PROCESS(); \
709 #endif /* !SLJIT_ASSERT */
711 #ifndef SLJIT_UNREACHABLE
713 #define SLJIT_UNREACHABLE() \
715 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
716 SLJIT_HALT_PROCESS(); \
719 #endif /* !SLJIT_UNREACHABLE */
721 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
723 /* Forcing empty, but valid statements. */
725 #undef SLJIT_UNREACHABLE
727 #define SLJIT_ASSERT(x) \
729 #define SLJIT_UNREACHABLE() \
732 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
734 #ifndef SLJIT_COMPILE_ASSERT
736 #define SLJIT_COMPILE_ASSERT(x, description) \
737 switch(0) { case 0: case ((x) ? 1 : 0): break; }
739 #endif /* !SLJIT_COMPILE_ASSERT */