• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Stack-less Just-In-Time compiler
3  *
4  *    Copyright 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_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
67 
68    Other macros:
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)
71 */
72 
73 /*****************/
74 /* Sanity check. */
75 /*****************/
76 
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"
92 #endif
93 
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"
109 #endif
110 
111 /********************************************************/
112 /* Automatic CPU detection (requires compiler support). */
113 /********************************************************/
114 
115 #if (defined SLJIT_CONFIG_AUTO && SLJIT_CONFIG_AUTO)
116 
117 #ifndef _WIN32
118 
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__)
124 #ifdef __thumb2__
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
128 #else
129 #define SLJIT_CONFIG_ARM_V5 1
130 #endif
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
145 #else
146 /* Unsupported architecture */
147 #define SLJIT_CONFIG_UNSUPPORTED 1
148 #endif
149 
150 #else /* _WIN32 */
151 
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
158 #elif defined(_ARM_)
159 #define SLJIT_CONFIG_ARM_V5 1
160 #elif defined(_M_ARM64) || defined(__aarch64__)
161 #define SLJIT_CONFIG_ARM_64 1
162 #else
163 #define SLJIT_CONFIG_X86_32 1
164 #endif
165 
166 #endif /* !_WIN32 */
167 #endif /* SLJIT_CONFIG_AUTO */
168 
169 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
170 #undef SLJIT_EXECUTABLE_ALLOCATOR
171 #endif
172 
173 /******************************/
174 /* CPU family type detection. */
175 /******************************/
176 
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
180 #endif
181 
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
192 #endif
193 
194 /**********************************/
195 /* External function definitions. */
196 /**********************************/
197 
198 /* General macros:
199    Note: SLJIT is designed to be independent from them as possible.
200 
201    In release mode (SLJIT_DEBUG is not defined) only the following
202    external functions are needed:
203 */
204 
205 #ifndef SLJIT_MALLOC
206 #define SLJIT_MALLOC(size, allocator_data) malloc(size)
207 #endif
208 
209 #ifndef SLJIT_FREE
210 #define SLJIT_FREE(ptr, allocator_data) free(ptr)
211 #endif
212 
213 #ifndef SLJIT_MEMCPY
214 #define SLJIT_MEMCPY(dest, src, len) memcpy(dest, src, len)
215 #endif
216 
217 #ifndef SLJIT_ZEROMEM
218 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
219 #endif
220 
221 /***************************/
222 /* Compiler helper macros. */
223 /***************************/
224 
225 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
226 
227 #if defined(__GNUC__) && (__GNUC__ >= 3)
228 #define SLJIT_LIKELY(x)		__builtin_expect((x), 1)
229 #define SLJIT_UNLIKELY(x)	__builtin_expect((x), 0)
230 #else
231 #define SLJIT_LIKELY(x)		(x)
232 #define SLJIT_UNLIKELY(x)	(x)
233 #endif
234 
235 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
236 
237 #ifndef SLJIT_INLINE
238 /* Inline functions. Some old compilers do not support them. */
239 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
240 #define SLJIT_INLINE
241 #else
242 #define SLJIT_INLINE __inline
243 #endif
244 #endif /* !SLJIT_INLINE */
245 
246 #ifndef SLJIT_NOINLINE
247 /* Not inline functions. */
248 #if defined(__GNUC__)
249 #define SLJIT_NOINLINE __attribute__ ((noinline))
250 #else
251 #define SLJIT_NOINLINE
252 #endif
253 #endif /* !SLJIT_INLINE */
254 
255 #ifndef SLJIT_UNUSED_ARG
256 /* Unused arguments. */
257 #define SLJIT_UNUSED_ARG(arg) (void)arg
258 #endif
259 
260 /*********************************/
261 /* Type of public API functions. */
262 /*********************************/
263 
264 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
265 /* Static ABI functions. For all-in-one programs. */
266 
267 #if defined(__GNUC__)
268 /* Disable unused warnings in gcc. */
269 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
270 #else
271 #define SLJIT_API_FUNC_ATTRIBUTE static
272 #endif
273 
274 #else
275 #define SLJIT_API_FUNC_ATTRIBUTE
276 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
277 
278 /****************************/
279 /* Instruction cache flush. */
280 /****************************/
281 
282 #if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin)
283 #if __has_builtin(__builtin___clear_cache)
284 
285 #define SLJIT_CACHE_FLUSH(from, to) \
286 	__builtin___clear_cache((char*)from, (char*)to)
287 
288 #endif /* __has_builtin(__builtin___clear_cache) */
289 #endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */
290 
291 #ifndef SLJIT_CACHE_FLUSH
292 
293 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
294 
295 /* Not required to implement on archs with unified caches. */
296 #define SLJIT_CACHE_FLUSH(from, to)
297 
298 #elif defined __APPLE__
299 
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. */
303 
304 #define SLJIT_CACHE_FLUSH(from, to) \
305 	sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
306 
307 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
308 
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
313 
314 #elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
315 
316 #define SLJIT_CACHE_FLUSH(from, to) \
317 	__builtin___clear_cache((char*)from, (char*)to)
318 
319 #elif defined __ANDROID__
320 
321 /* Android lacks __clear_cache; instead, cacheflush should be used. */
322 
323 #define SLJIT_CACHE_FLUSH(from, to) \
324     cacheflush((long)(from), (long)(to), 0)
325 
326 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
327 
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
332 
333 #elif defined _WIN32
334 
335 #define SLJIT_CACHE_FLUSH(from, to) \
336 	FlushInstructionCache(GetCurrentProcess(), (char*)(from), (char*)(to) - (char*)(from))
337 
338 #else
339 
340 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
341 #define SLJIT_CACHE_FLUSH(from, to) \
342 	__clear_cache((char*)(from), (char*)(to))
343 
344 #endif
345 
346 #endif /* !SLJIT_CACHE_FLUSH */
347 
348 /******************************************************/
349 /*    Integer and floating point type definitions.    */
350 /******************************************************/
351 
352 /* 8 bit byte type. */
353 typedef unsigned char sljit_u8;
354 typedef signed char sljit_s8;
355 
356 /* 16 bit half-word type. */
357 typedef unsigned short int sljit_u16;
358 typedef signed short int sljit_s16;
359 
360 /* 32 bit integer type. */
361 typedef unsigned int sljit_u32;
362 typedef signed int sljit_s32;
363 
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;
381 #else
382 #define SLJIT_64BIT_ARCHITECTURE 1
383 #define SLJIT_WORD_SHIFT 3
384 #ifdef _WIN32
385 #ifdef __GNUC__
386 /* These types do not require windows.h */
387 typedef unsigned long long sljit_uw;
388 typedef long long sljit_sw;
389 #else
390 typedef unsigned __int64 sljit_uw;
391 typedef __int64 sljit_sw;
392 #endif
393 #else /* !_WIN32 */
394 typedef unsigned long int sljit_uw;
395 typedef long int sljit_sw;
396 #endif /* _WIN32 */
397 #endif
398 
399 typedef sljit_uw sljit_p;
400 
401 /* Floating point types. */
402 typedef float sljit_f32;
403 typedef double sljit_f64;
404 
405 /* Shift for pointer sized data. */
406 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
407 
408 /* Shift for double precision sized data. */
409 #define SLJIT_F32_SHIFT 2
410 #define SLJIT_F64_SHIFT 3
411 
412 #ifndef SLJIT_W
413 
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)
419 #else
420 #define SLJIT_W(w)	(w)
421 #endif
422 
423 #endif /* !SLJIT_W */
424 
425 /*************************/
426 /* Endianness detection. */
427 /*************************/
428 
429 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
430 
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)
434 
435 #ifdef __LITTLE_ENDIAN__
436 #define SLJIT_LITTLE_ENDIAN 1
437 #else
438 #define SLJIT_BIG_ENDIAN 1
439 #endif
440 
441 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
442 	|| (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
443 
444 #ifdef __MIPSEL__
445 #define SLJIT_LITTLE_ENDIAN 1
446 #else
447 #define SLJIT_BIG_ENDIAN 1
448 #endif
449 
450 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
451 
452 #define SLJIT_BIG_ENDIAN 1
453 
454 #else
455 #define SLJIT_LITTLE_ENDIAN 1
456 #endif
457 
458 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
459 
460 /* Sanity check. */
461 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
462 #error "Exactly one endianness must be selected"
463 #endif
464 
465 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
466 #error "Exactly one endianness must be selected"
467 #endif
468 
469 #ifndef SLJIT_UNALIGNED
470 
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
479 #endif
480 
481 #endif /* !SLJIT_UNALIGNED */
482 
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
487 #endif
488 
489 /*****************************************************************************************/
490 /* Calling convention of functions generated by SLJIT or called from the generated code. */
491 /*****************************************************************************************/
492 
493 #ifndef SLJIT_FUNC
494 
495 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
496 
497 /* Force cdecl. */
498 #define SLJIT_FUNC
499 
500 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
501 
502 #if defined(__GNUC__) && !defined(__APPLE__)
503 
504 #define SLJIT_FUNC __attribute__ ((fastcall))
505 #define SLJIT_X86_32_FASTCALL 1
506 
507 #elif defined(_MSC_VER)
508 
509 #define SLJIT_FUNC __fastcall
510 #define SLJIT_X86_32_FASTCALL 1
511 
512 #elif defined(__BORLANDC__)
513 
514 #define SLJIT_FUNC __msfastcall
515 #define SLJIT_X86_32_FASTCALL 1
516 
517 #else /* Unknown compiler. */
518 
519 /* The cdecl attribute is the default. */
520 #define SLJIT_FUNC
521 
522 #endif
523 
524 #else /* Non x86-32 architectures. */
525 
526 #define SLJIT_FUNC
527 
528 #endif /* SLJIT_CONFIG_X86_32 */
529 
530 #endif /* !SLJIT_FUNC */
531 
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
538 #endif
539 #endif /* SLJIT_INDIRECT_CALL */
540 
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
546 #else
547 #define SLJIT_RETURN_ADDRESS_OFFSET 0
548 #endif
549 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
550 
551 /***************************************************/
552 /* Functions of the built-in executable allocator. */
553 /***************************************************/
554 
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)
561 
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)
565 #else
566 #define SLJIT_EXEC_OFFSET(ptr) 0
567 #endif
568 
569 #endif
570 
571 /**********************************************/
572 /* Registers and locals offset determination. */
573 /**********************************************/
574 
575 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
576 
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
581 
582 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
583 
584 #define SLJIT_NUMBER_OF_REGISTERS 13
585 #ifndef _WIN64
586 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
587 #define SLJIT_LOCALS_OFFSET_BASE 0
588 #else /* _WIN64 */
589 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
590 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset)
591 #endif /* !_WIN64 */
592 #define SLJIT_PREF_SHIFT_REG SLJIT_R3
593 
594 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
595 
596 #define SLJIT_NUMBER_OF_REGISTERS 12
597 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
598 #define SLJIT_LOCALS_OFFSET_BASE 0
599 
600 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
601 
602 #define SLJIT_NUMBER_OF_REGISTERS 12
603 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
604 #define SLJIT_LOCALS_OFFSET_BASE 0
605 
606 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
607 
608 #define SLJIT_NUMBER_OF_REGISTERS 26
609 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10
610 #define SLJIT_LOCALS_OFFSET_BASE 0
611 
612 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
613 
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))
621 #else
622 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
623 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
624 
625 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
626 
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))
631 #else
632 #define SLJIT_LOCALS_OFFSET_BASE 0
633 #endif
634 
635 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
636 
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))
643 #endif
644 
645 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
646 
647 #define SLJIT_NUMBER_OF_REGISTERS 10
648 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
649 #define SLJIT_LOCALS_OFFSET_BASE 0
650 
651 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
652 
653 #define SLJIT_NUMBER_OF_REGISTERS 0
654 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
655 #define SLJIT_LOCALS_OFFSET_BASE 0
656 
657 #endif
658 
659 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
660 
661 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
662 	(SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
663 
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
667 #else
668 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
669 #endif
670 
671 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
672 	(SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
673 
674 /*************************************/
675 /* Debug and verbose related macros. */
676 /*************************************/
677 
678 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
679 #include <stdio.h>
680 #endif
681 
682 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
683 
684 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_UNREACHABLE)
685 
686 /* SLJIT_HALT_PROCESS must halt the process. */
687 #ifndef SLJIT_HALT_PROCESS
688 #include <stdlib.h>
689 
690 #define SLJIT_HALT_PROCESS() \
691 	abort();
692 #endif /* !SLJIT_HALT_PROCESS */
693 
694 #include <stdio.h>
695 
696 #endif /* !SLJIT_ASSERT || !SLJIT_UNREACHABLE */
697 
698 /* Feel free to redefine these two macros. */
699 #ifndef SLJIT_ASSERT
700 
701 #define SLJIT_ASSERT(x) \
702 	do { \
703 		if (SLJIT_UNLIKELY(!(x))) { \
704 			printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \
705 			SLJIT_HALT_PROCESS(); \
706 		} \
707 	} while (0)
708 
709 #endif /* !SLJIT_ASSERT */
710 
711 #ifndef SLJIT_UNREACHABLE
712 
713 #define SLJIT_UNREACHABLE() \
714 	do { \
715 		printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
716 		SLJIT_HALT_PROCESS(); \
717 	} while (0)
718 
719 #endif /* !SLJIT_UNREACHABLE */
720 
721 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
722 
723 /* Forcing empty, but valid statements. */
724 #undef SLJIT_ASSERT
725 #undef SLJIT_UNREACHABLE
726 
727 #define SLJIT_ASSERT(x) \
728 	do { } while (0)
729 #define SLJIT_UNREACHABLE() \
730 	do { } while (0)
731 
732 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
733 
734 #ifndef SLJIT_COMPILE_ASSERT
735 
736 #define SLJIT_COMPILE_ASSERT(x, description) \
737 	switch(0) { case 0: case ((x) ? 1 : 0): break; }
738 
739 #endif /* !SLJIT_COMPILE_ASSERT */
740 
741 #endif
742