Home | History | Annotate | Line # | Download | only in sljit_src
sljitConfigInternal.h revision 1.10
      1 /*	$NetBSD: sljitConfigInternal.h,v 1.10 2016/05/29 17:09:33 alnsn Exp $	*/
      2 
      3 /*
      4  *    Stack-less Just-In-Time compiler
      5  *
      6  *    Copyright 2009-2012 Zoltan Herczeg (hzmester (at) freemail.hu). All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without modification, are
      9  * permitted provided that the following conditions are met:
     10  *
     11  *   1. Redistributions of source code must retain the above copyright notice, this list of
     12  *      conditions and the following disclaimer.
     13  *
     14  *   2. Redistributions in binary form must reproduce the above copyright notice, this list
     15  *      of conditions and the following disclaimer in the documentation and/or other materials
     16  *      provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
     19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
     21  * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
     23  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     24  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     26  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _SLJIT_CONFIG_INTERNAL_H_
     30 #define _SLJIT_CONFIG_INTERNAL_H_
     31 
     32 /*
     33    SLJIT defines the following architecture dependent types and macros:
     34 
     35    Types:
     36      sljit_s8, sljit_u8   : signed and unsigned 8 bit integer type
     37      sljit_s16, sljit_u16 : signed and unsigned 16 bit integer type
     38      sljit_s32, sljit_u32 : signed and unsigned 32 bit integer type
     39      sljit_sw, sljit_uw   : signed and unsigned machine word, enough to store a pointer
     40      sljit_p              : unsgined pointer value (usually the same as sljit_uw, but
     41                             some 64 bit ABIs may use 32 bit pointers)
     42      sljit_f32            : 32 bit single precision floating point value
     43      sljit_f64            : 64 bit double precision floating point value
     44 
     45    Macros for feature detection (boolean):
     46      SLJIT_32BIT_ARCHITECTURE : 32 bit architecture
     47      SLJIT_64BIT_ARCHITECTURE : 64 bit architecture
     48      SLJIT_LITTLE_ENDIAN : little endian architecture
     49      SLJIT_BIG_ENDIAN : big endian architecture
     50      SLJIT_UNALIGNED : allows unaligned memory accesses for non-fpu operations (only!)
     51      SLJIT_INDIRECT_CALL : see SLJIT_FUNC_OFFSET() for more information
     52 
     53    Constants:
     54      SLJIT_NUMBER_OF_REGISTERS : number of available registers
     55      SLJIT_NUMBER_OF_SCRATCH_REGISTERS : number of available scratch registers
     56      SLJIT_NUMBER_OF_SAVED_REGISTERS : number of available saved registers
     57      SLJIT_NUMBER_OF_FLOAT_REGISTERS : number of available floating point registers
     58      SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS : number of available floating point scratch registers
     59      SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS : number of available floating point saved registers
     60      SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index
     61      SLJIT_F32_SHIFT : the shift required to apply when accessing
     62                        a single precision floating point array by index
     63      SLJIT_F64_SHIFT : the shift required to apply when accessing
     64                        a double precision floating point array by index
     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_CALL : C calling convention define for both calling JIT form C and C callbacks for 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(_ARM_)
    155 #define SLJIT_CONFIG_ARM_V5 1
    156 #else
    157 #define SLJIT_CONFIG_X86_32 1
    158 #endif
    159 
    160 #endif /* !WIN32 */
    161 #endif /* SLJIT_CONFIG_AUTO */
    162 
    163 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
    164 #undef SLJIT_EXECUTABLE_ALLOCATOR
    165 #endif
    166 
    167 /******************************/
    168 /* CPU family type detection. */
    169 /******************************/
    170 
    171 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
    172 	|| (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
    173 #define SLJIT_CONFIG_ARM_32 1
    174 #endif
    175 
    176 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
    177 #define SLJIT_CONFIG_X86 1
    178 #elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
    179 #define SLJIT_CONFIG_ARM 1
    180 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
    181 #define SLJIT_CONFIG_PPC 1
    182 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
    183 #define SLJIT_CONFIG_MIPS 1
    184 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) || (defined SLJIT_CONFIG_SPARC_64 && SLJIT_CONFIG_SPARC_64)
    185 #define SLJIT_CONFIG_SPARC 1
    186 #endif
    187 
    188 /**********************************/
    189 /* External function definitions. */
    190 /**********************************/
    191 
    192 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
    193 
    194 #ifndef _KERNEL
    195 /* These libraries are needed for the macros below. */
    196 #include <stdlib.h>
    197 #include <string.h>
    198 #endif
    199 
    200 #endif /* SLJIT_STD_MACROS_DEFINED */
    201 
    202 /* General macros:
    203    Note: SLJIT is designed to be independent from them as possible.
    204 
    205    In release mode (SLJIT_DEBUG is not defined) only the following
    206    external functions are needed:
    207 */
    208 
    209 #ifndef SLJIT_MALLOC
    210 #define SLJIT_MALLOC(size, allocator_data) malloc(size)
    211 #endif
    212 
    213 #ifndef SLJIT_FREE
    214 #define SLJIT_FREE(ptr, allocator_data) free(ptr)
    215 #endif
    216 
    217 #ifndef SLJIT_MEMMOVE
    218 #define SLJIT_MEMMOVE(dest, src, len) memmove(dest, src, len)
    219 #endif
    220 
    221 #ifndef SLJIT_ZEROMEM
    222 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len)
    223 #endif
    224 
    225 /***************************/
    226 /* Compiler helper macros. */
    227 /***************************/
    228 
    229 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY)
    230 
    231 #if defined(__GNUC__) && (__GNUC__ >= 3)
    232 #define SLJIT_LIKELY(x)		__builtin_expect((x), 1)
    233 #define SLJIT_UNLIKELY(x)	__builtin_expect((x), 0)
    234 #else
    235 #define SLJIT_LIKELY(x)		(x)
    236 #define SLJIT_UNLIKELY(x)	(x)
    237 #endif
    238 
    239 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */
    240 
    241 #ifndef SLJIT_INLINE
    242 /* Inline functions. Some old compilers do not support them. */
    243 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510
    244 #define SLJIT_INLINE
    245 #else
    246 #define SLJIT_INLINE __inline
    247 #endif
    248 #endif /* !SLJIT_INLINE */
    249 
    250 #ifndef SLJIT_NOINLINE
    251 /* Not inline functions. */
    252 #if defined(__GNUC__)
    253 #define SLJIT_NOINLINE __attribute__ ((noinline))
    254 #else
    255 #define SLJIT_NOINLINE
    256 #endif
    257 #endif /* !SLJIT_INLINE */
    258 
    259 #ifndef SLJIT_UNUSED_ARG
    260 /* Unused arguments. */
    261 #define SLJIT_UNUSED_ARG(arg) (void)arg
    262 #endif
    263 
    264 /*********************************/
    265 /* Type of public API functions. */
    266 /*********************************/
    267 
    268 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC)
    269 /* Static ABI functions. For all-in-one programs. */
    270 
    271 #if defined(__GNUC__)
    272 /* Disable unused warnings in gcc. */
    273 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused))
    274 #else
    275 #define SLJIT_API_FUNC_ATTRIBUTE static
    276 #endif
    277 
    278 #else
    279 #define SLJIT_API_FUNC_ATTRIBUTE
    280 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */
    281 
    282 /****************************/
    283 /* Instruction cache flush. */
    284 /****************************/
    285 
    286 #if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin)
    287 #if __has_builtin(__builtin___clear_cache)
    288 
    289 #define SLJIT_CACHE_FLUSH(from, to) \
    290 	__builtin___clear_cache((char*)from, (char*)to)
    291 
    292 #endif /* __has_builtin(__builtin___clear_cache) */
    293 #endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */
    294 
    295 #ifndef SLJIT_CACHE_FLUSH
    296 
    297 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
    298 
    299 /* Not required to implement on archs with unified caches. */
    300 #define SLJIT_CACHE_FLUSH(from, to)
    301 
    302 #elif defined __APPLE__
    303 
    304 /* Supported by all macs since Mac OS 10.5.
    305    However, it does not work on non-jailbroken iOS devices,
    306    although the compilation is successful. */
    307 
    308 #define SLJIT_CACHE_FLUSH(from, to) \
    309 	sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from))
    310 
    311 #elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)))
    312 
    313 #define SLJIT_CACHE_FLUSH(from, to) \
    314 	__builtin___clear_cache((char*)from, (char*)to)
    315 
    316 #elif defined __ANDROID__
    317 
    318 /* Android lacks __clear_cache; instead, cacheflush should be used. */
    319 
    320 #define SLJIT_CACHE_FLUSH(from, to) \
    321     cacheflush((long)(from), (long)(to), 0)
    322 
    323 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
    324 
    325 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */
    326 #define SLJIT_CACHE_FLUSH(from, to) \
    327 	ppc_cache_flush((from), (to))
    328 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1
    329 
    330 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
    331 
    332 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */
    333 #define SLJIT_CACHE_FLUSH(from, to) \
    334 	sparc_cache_flush((from), (to))
    335 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1
    336 
    337 #else
    338 
    339 /* Calls __ARM_NR_cacheflush on ARM-Linux. */
    340 #define SLJIT_CACHE_FLUSH(from, to) \
    341 	__clear_cache((char*)(from), (char*)(to))
    342 
    343 #endif
    344 
    345 #endif /* !SLJIT_CACHE_FLUSH */
    346 
    347 /******************************************************/
    348 /*    Integer and floating point type definitions.    */
    349 /******************************************************/
    350 
    351 /* 8 bit byte type. */
    352 typedef unsigned char sljit_u8;
    353 typedef signed char sljit_s8;
    354 
    355 /* 16 bit half-word type. */
    356 typedef unsigned short int sljit_u16;
    357 typedef signed short int sljit_s16;
    358 
    359 /* 32 bit integer type. */
    360 typedef unsigned int sljit_u32;
    361 typedef signed int sljit_s32;
    362 
    363 /* Machine word type. Enough for storing a pointer.
    364      32 bit for 32 bit machines.
    365      64 bit for 64 bit machines. */
    366 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
    367 /* Just to have something. */
    368 #define SLJIT_WORD_SHIFT 0
    369 typedef unsigned long int sljit_uw;
    370 typedef long int sljit_sw;
    371 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
    372 	&& !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
    373 	&& !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \
    374 	&& !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \
    375 	&& !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
    376 #define SLJIT_32BIT_ARCHITECTURE 1
    377 #define SLJIT_WORD_SHIFT 2
    378 typedef unsigned int sljit_uw;
    379 typedef int sljit_sw;
    380 #else
    381 #define SLJIT_64BIT_ARCHITECTURE 1
    382 #define SLJIT_WORD_SHIFT 3
    383 #ifdef _WIN32
    384 typedef unsigned __int64 sljit_uw;
    385 typedef __int64 sljit_sw;
    386 #else
    387 typedef unsigned long int sljit_uw;
    388 typedef long int sljit_sw;
    389 #endif
    390 #endif
    391 
    392 typedef sljit_uw sljit_p;
    393 
    394 /* Floating point types. */
    395 typedef float sljit_f32;
    396 typedef double sljit_f64;
    397 
    398 /* Shift for pointer sized data. */
    399 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT
    400 
    401 /* Shift for double precision sized data. */
    402 #define SLJIT_F32_SHIFT 2
    403 #define SLJIT_F64_SHIFT 3
    404 
    405 #ifndef SLJIT_W
    406 
    407 /* Defining long constants. */
    408 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
    409 #define SLJIT_W(w)	(w##ll)
    410 #else
    411 #define SLJIT_W(w)	(w)
    412 #endif
    413 
    414 #endif /* !SLJIT_W */
    415 
    416 /*************************/
    417 /* Endianness detection. */
    418 /*************************/
    419 
    420 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
    421 
    422 /* These macros are mostly useful for the applications. */
    423 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
    424 	|| (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
    425 
    426 #ifdef __LITTLE_ENDIAN__
    427 #define SLJIT_LITTLE_ENDIAN 1
    428 #else
    429 #define SLJIT_BIG_ENDIAN 1
    430 #endif
    431 
    432 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \
    433 	|| (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
    434 
    435 #ifdef __MIPSEL__
    436 #define SLJIT_LITTLE_ENDIAN 1
    437 #else
    438 #define SLJIT_BIG_ENDIAN 1
    439 #endif
    440 
    441 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
    442 
    443 #define SLJIT_BIG_ENDIAN 1
    444 
    445 #else
    446 #define SLJIT_LITTLE_ENDIAN 1
    447 #endif
    448 
    449 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
    450 
    451 /* Sanity check. */
    452 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
    453 #error "Exactly one endianness must be selected"
    454 #endif
    455 
    456 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
    457 #error "Exactly one endianness must be selected"
    458 #endif
    459 
    460 #ifndef SLJIT_UNALIGNED
    461 
    462 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
    463 	|| (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
    464 	|| (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \
    465 	|| (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \
    466 	|| (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
    467 	|| (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \
    468 	|| (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
    469 #define SLJIT_UNALIGNED 1
    470 #endif
    471 
    472 #endif /* !SLJIT_UNALIGNED */
    473 
    474 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
    475 /* Auto detect SSE2 support using CPUID.
    476    On 64 bit x86 cpus, sse2 must be present. */
    477 #define SLJIT_DETECT_SSE2 1
    478 #endif
    479 
    480 /*****************************************************************************************/
    481 /* Calling convention of functions generated by SLJIT or called from the generated code. */
    482 /*****************************************************************************************/
    483 
    484 #ifndef SLJIT_CALL
    485 
    486 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION)
    487 
    488 /* Force cdecl. */
    489 #define SLJIT_CALL
    490 
    491 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
    492 
    493 #if defined(__GNUC__) && !defined(__APPLE__)
    494 
    495 #define SLJIT_CALL __attribute__ ((fastcall))
    496 #define SLJIT_X86_32_FASTCALL 1
    497 
    498 #elif defined(_MSC_VER)
    499 
    500 #define SLJIT_CALL __fastcall
    501 #define SLJIT_X86_32_FASTCALL 1
    502 
    503 #elif defined(__BORLANDC__)
    504 
    505 #define SLJIT_CALL __msfastcall
    506 #define SLJIT_X86_32_FASTCALL 1
    507 
    508 #else /* Unknown compiler. */
    509 
    510 /* The cdecl attribute is the default. */
    511 #define SLJIT_CALL
    512 
    513 #endif
    514 
    515 #else /* Non x86-32 architectures. */
    516 
    517 #define SLJIT_CALL
    518 
    519 #endif /* SLJIT_CONFIG_X86_32 */
    520 
    521 #endif /* !SLJIT_CALL */
    522 
    523 #ifndef SLJIT_INDIRECT_CALL
    524 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \
    525 	|| ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX)
    526 /* It seems certain ppc compilers use an indirect addressing for functions
    527    which makes things complicated. */
    528 #define SLJIT_INDIRECT_CALL 1
    529 #endif
    530 #endif /* SLJIT_INDIRECT_CALL */
    531 
    532 /* The offset which needs to be substracted from the return address to
    533 determine the next executed instruction after return. */
    534 #ifndef SLJIT_RETURN_ADDRESS_OFFSET
    535 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
    536 #define SLJIT_RETURN_ADDRESS_OFFSET 8
    537 #else
    538 #define SLJIT_RETURN_ADDRESS_OFFSET 0
    539 #endif
    540 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */
    541 
    542 /***************************************************/
    543 /* Functions of the built-in executable allocator. */
    544 /***************************************************/
    545 
    546 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
    547 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
    548 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
    549 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
    550 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
    551 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
    552 #endif
    553 
    554 /**********************************************/
    555 /* Registers and locals offset determination. */
    556 /**********************************************/
    557 
    558 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
    559 
    560 #define SLJIT_NUMBER_OF_REGISTERS 10
    561 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
    562 #if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
    563 #define SLJIT_LOCALS_OFFSET_BASE ((2 + 4) * sizeof(sljit_sw))
    564 #else
    565 /* Maximum 3 arguments are passed on the stack, +1 for double alignment. */
    566 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1 + 4) * sizeof(sljit_sw))
    567 #endif /* SLJIT_X86_32_FASTCALL */
    568 
    569 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
    570 
    571 #ifndef _WIN64
    572 #define SLJIT_NUMBER_OF_REGISTERS 12
    573 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6
    574 #define SLJIT_LOCALS_OFFSET_BASE (sizeof(sljit_sw))
    575 #else
    576 #define SLJIT_NUMBER_OF_REGISTERS 12
    577 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
    578 #define SLJIT_LOCALS_OFFSET_BASE ((4 + 2) * sizeof(sljit_sw))
    579 #endif /* _WIN64 */
    580 
    581 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
    582 
    583 #define SLJIT_NUMBER_OF_REGISTERS 11
    584 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
    585 #define SLJIT_LOCALS_OFFSET_BASE 0
    586 
    587 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
    588 
    589 #define SLJIT_NUMBER_OF_REGISTERS 11
    590 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 7
    591 #define SLJIT_LOCALS_OFFSET_BASE 0
    592 
    593 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
    594 
    595 #define SLJIT_NUMBER_OF_REGISTERS 25
    596 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10
    597 #define SLJIT_LOCALS_OFFSET_BASE (2 * sizeof(sljit_sw))
    598 
    599 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
    600 
    601 #define SLJIT_NUMBER_OF_REGISTERS 22
    602 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17
    603 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX)
    604 #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw))
    605 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
    606 /* Add +1 for double alignment. */
    607 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * sizeof(sljit_sw))
    608 #else
    609 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw))
    610 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */
    611 
    612 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
    613 
    614 #define SLJIT_NUMBER_OF_REGISTERS 17
    615 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8
    616 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
    617 #define SLJIT_LOCALS_OFFSET_BASE (4 * sizeof(sljit_sw))
    618 #else
    619 #define SLJIT_LOCALS_OFFSET_BASE 0
    620 #endif
    621 
    622 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
    623 
    624 #define SLJIT_NUMBER_OF_REGISTERS 18
    625 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14
    626 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
    627 /* Add +1 for double alignment. */
    628 #define SLJIT_LOCALS_OFFSET_BASE ((23 + 1) * sizeof(sljit_sw))
    629 #endif
    630 
    631 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
    632 
    633 #define SLJIT_NUMBER_OF_REGISTERS 10
    634 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5
    635 #define SLJIT_LOCALS_OFFSET_BASE 0
    636 
    637 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
    638 
    639 #define SLJIT_NUMBER_OF_REGISTERS 0
    640 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0
    641 #define SLJIT_LOCALS_OFFSET_BASE 0
    642 
    643 #endif
    644 
    645 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE)
    646 
    647 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \
    648 	(SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS)
    649 
    650 #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 6
    651 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && (defined _WIN64)
    652 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 1
    653 #else
    654 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0
    655 #endif
    656 
    657 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \
    658 	(SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS)
    659 
    660 /*************************************/
    661 /* Debug and verbose related macros. */
    662 /*************************************/
    663 
    664 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
    665 #ifdef _KERNEL
    666 #include <sys/systm.h>
    667 #else
    668 #include <stdio.h>
    669 #endif
    670 #endif
    671 
    672 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
    673 
    674 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_ASSERT_STOP)
    675 
    676 /* SLJIT_HALT_PROCESS must halt the process. */
    677 #ifndef SLJIT_HALT_PROCESS
    678 #include <stdlib.h>
    679 
    680 #define SLJIT_HALT_PROCESS() \
    681 	abort();
    682 #endif /* !SLJIT_HALT_PROCESS */
    683 
    684 #include <stdio.h>
    685 
    686 #endif /* !SLJIT_ASSERT || !SLJIT_ASSERT_STOP */
    687 
    688 /* Feel free to redefine these two macros. */
    689 #ifndef SLJIT_ASSERT
    690 
    691 #include <assert.h>
    692 #include <stdlib.h>
    693 
    694 #define SLJIT_ASSERT(x) assert(x)
    695 
    696 #endif /* !SLJIT_ASSERT */
    697 
    698 #ifndef SLJIT_ASSERT_STOP
    699 
    700 #define SLJIT_ASSERT_STOP() \
    701 	do { \
    702 		printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \
    703 		SLJIT_HALT_PROCESS(); \
    704 	} while (0)
    705 
    706 #endif /* !SLJIT_ASSERT_STOP */
    707 
    708 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
    709 
    710 /* Forcing empty, but valid statements. */
    711 #undef SLJIT_ASSERT
    712 #undef SLJIT_ASSERT_STOP
    713 
    714 #define SLJIT_ASSERT(x) \
    715 	do { } while (0)
    716 #define SLJIT_ASSERT_STOP() \
    717 	do { } while (0)
    718 
    719 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */
    720 
    721 #ifndef SLJIT_COMPILE_ASSERT
    722 
    723 /* Should be improved eventually. */
    724 #define SLJIT_COMPILE_ASSERT(x, description) \
    725 	SLJIT_ASSERT(x)
    726 
    727 #endif /* !SLJIT_COMPILE_ASSERT */
    728 
    729 #endif
    730