1 /* $NetBSD: sljitConfigInternal.h,v 1.11 2019/01/20 23:14:16 alnsn Exp $ */ 2 3 /* 4 * Stack-less Just-In-Time compiler 5 * 6 * Copyright Zoltan Herczeg (hzmester@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 /* General macros: 193 Note: SLJIT is designed to be independent from them as possible. 194 195 In release mode (SLJIT_DEBUG is not defined) only the following 196 external functions are needed: 197 */ 198 199 #ifndef SLJIT_MALLOC 200 #define SLJIT_MALLOC(size, allocator_data) malloc(size) 201 #endif 202 203 #ifndef SLJIT_FREE 204 #define SLJIT_FREE(ptr, allocator_data) free(ptr) 205 #endif 206 207 #ifndef SLJIT_MEMCPY 208 #define SLJIT_MEMCPY(dest, src, len) memcpy(dest, src, len) 209 #endif 210 211 #ifndef SLJIT_ZEROMEM 212 #define SLJIT_ZEROMEM(dest, len) memset(dest, 0, len) 213 #endif 214 215 /***************************/ 216 /* Compiler helper macros. */ 217 /***************************/ 218 219 #if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) 220 221 #if defined(__GNUC__) && (__GNUC__ >= 3) 222 #define SLJIT_LIKELY(x) __builtin_expect((x), 1) 223 #define SLJIT_UNLIKELY(x) __builtin_expect((x), 0) 224 #else 225 #define SLJIT_LIKELY(x) (x) 226 #define SLJIT_UNLIKELY(x) (x) 227 #endif 228 229 #endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */ 230 231 #ifndef SLJIT_INLINE 232 /* Inline functions. Some old compilers do not support them. */ 233 #if defined(__SUNPRO_C) && __SUNPRO_C <= 0x510 234 #define SLJIT_INLINE 235 #else 236 #define SLJIT_INLINE __inline 237 #endif 238 #endif /* !SLJIT_INLINE */ 239 240 #ifndef SLJIT_NOINLINE 241 /* Not inline functions. */ 242 #if defined(__GNUC__) 243 #define SLJIT_NOINLINE __attribute__ ((noinline)) 244 #else 245 #define SLJIT_NOINLINE 246 #endif 247 #endif /* !SLJIT_INLINE */ 248 249 #ifndef SLJIT_UNUSED_ARG 250 /* Unused arguments. */ 251 #define SLJIT_UNUSED_ARG(arg) (void)arg 252 #endif 253 254 /*********************************/ 255 /* Type of public API functions. */ 256 /*********************************/ 257 258 #if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) 259 /* Static ABI functions. For all-in-one programs. */ 260 261 #if defined(__GNUC__) 262 /* Disable unused warnings in gcc. */ 263 #define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused)) 264 #else 265 #define SLJIT_API_FUNC_ATTRIBUTE static 266 #endif 267 268 #else 269 #define SLJIT_API_FUNC_ATTRIBUTE 270 #endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */ 271 272 /****************************/ 273 /* Instruction cache flush. */ 274 /****************************/ 275 276 #if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) 277 #if __has_builtin(__builtin___clear_cache) 278 279 #define SLJIT_CACHE_FLUSH(from, to) \ 280 __builtin___clear_cache((char*)from, (char*)to) 281 282 #endif /* __has_builtin(__builtin___clear_cache) */ 283 #endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */ 284 285 #ifndef SLJIT_CACHE_FLUSH 286 287 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) 288 289 /* Not required to implement on archs with unified caches. */ 290 #define SLJIT_CACHE_FLUSH(from, to) 291 292 #elif defined __APPLE__ 293 294 /* Supported by all macs since Mac OS 10.5. 295 However, it does not work on non-jailbroken iOS devices, 296 although the compilation is successful. */ 297 298 #define SLJIT_CACHE_FLUSH(from, to) \ 299 sys_icache_invalidate((char*)(from), (char*)(to) - (char*)(from)) 300 301 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) 302 303 /* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */ 304 #define SLJIT_CACHE_FLUSH(from, to) \ 305 ppc_cache_flush((from), (to)) 306 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1 307 308 #elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) 309 310 #define SLJIT_CACHE_FLUSH(from, to) \ 311 __builtin___clear_cache((char*)from, (char*)to) 312 313 #elif defined __ANDROID__ 314 315 /* Android lacks __clear_cache; instead, cacheflush should be used. */ 316 317 #define SLJIT_CACHE_FLUSH(from, to) \ 318 cacheflush((long)(from), (long)(to), 0) 319 320 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) 321 322 /* The __clear_cache() implementation of GCC is a dummy function on Sparc. */ 323 #define SLJIT_CACHE_FLUSH(from, to) \ 324 sparc_cache_flush((from), (to)) 325 #define SLJIT_CACHE_FLUSH_OWN_IMPL 1 326 327 #else 328 329 /* Calls __ARM_NR_cacheflush on ARM-Linux. */ 330 #define SLJIT_CACHE_FLUSH(from, to) \ 331 __clear_cache((char*)(from), (char*)(to)) 332 333 #endif 334 335 #endif /* !SLJIT_CACHE_FLUSH */ 336 337 /******************************************************/ 338 /* Integer and floating point type definitions. */ 339 /******************************************************/ 340 341 /* 8 bit byte type. */ 342 typedef unsigned char sljit_u8; 343 typedef signed char sljit_s8; 344 345 /* 16 bit half-word type. */ 346 typedef unsigned short int sljit_u16; 347 typedef signed short int sljit_s16; 348 349 /* 32 bit integer type. */ 350 typedef unsigned int sljit_u32; 351 typedef signed int sljit_s32; 352 353 /* Machine word type. Enough for storing a pointer. 354 32 bit for 32 bit machines. 355 64 bit for 64 bit machines. */ 356 #if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) 357 /* Just to have something. */ 358 #define SLJIT_WORD_SHIFT 0 359 typedef unsigned long int sljit_uw; 360 typedef long int sljit_sw; 361 #elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \ 362 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ 363 && !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \ 364 && !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \ 365 && !(defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) 366 #define SLJIT_32BIT_ARCHITECTURE 1 367 #define SLJIT_WORD_SHIFT 2 368 typedef unsigned int sljit_uw; 369 typedef int sljit_sw; 370 #else 371 #define SLJIT_64BIT_ARCHITECTURE 1 372 #define SLJIT_WORD_SHIFT 3 373 #ifdef _WIN32 374 typedef unsigned __int64 sljit_uw; 375 typedef __int64 sljit_sw; 376 #else 377 typedef unsigned long int sljit_uw; 378 typedef long int sljit_sw; 379 #endif 380 #endif 381 382 typedef sljit_uw sljit_p; 383 384 /* Floating point types. */ 385 typedef float sljit_f32; 386 typedef double sljit_f64; 387 388 /* Shift for pointer sized data. */ 389 #define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT 390 391 /* Shift for double precision sized data. */ 392 #define SLJIT_F32_SHIFT 2 393 #define SLJIT_F64_SHIFT 3 394 395 #ifndef SLJIT_W 396 397 /* Defining long constants. */ 398 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) 399 #define SLJIT_W(w) (w##ll) 400 #else 401 #define SLJIT_W(w) (w) 402 #endif 403 404 #endif /* !SLJIT_W */ 405 406 /*************************/ 407 /* Endianness detection. */ 408 /*************************/ 409 410 #if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) 411 412 /* These macros are mostly useful for the applications. */ 413 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \ 414 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) 415 416 #ifdef __LITTLE_ENDIAN__ 417 #define SLJIT_LITTLE_ENDIAN 1 418 #else 419 #define SLJIT_BIG_ENDIAN 1 420 #endif 421 422 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) \ 423 || (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) 424 425 #ifdef __MIPSEL__ 426 #define SLJIT_LITTLE_ENDIAN 1 427 #else 428 #define SLJIT_BIG_ENDIAN 1 429 #endif 430 431 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) 432 433 #define SLJIT_BIG_ENDIAN 1 434 435 #else 436 #define SLJIT_LITTLE_ENDIAN 1 437 #endif 438 439 #endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */ 440 441 /* Sanity check. */ 442 #if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN) 443 #error "Exactly one endianness must be selected" 444 #endif 445 446 #if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN) 447 #error "Exactly one endianness must be selected" 448 #endif 449 450 #ifndef SLJIT_UNALIGNED 451 452 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \ 453 || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \ 454 || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \ 455 || (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \ 456 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ 457 || (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) \ 458 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) 459 #define SLJIT_UNALIGNED 1 460 #endif 461 462 #endif /* !SLJIT_UNALIGNED */ 463 464 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) 465 /* Auto detect SSE2 support using CPUID. 466 On 64 bit x86 cpus, sse2 must be present. */ 467 #define SLJIT_DETECT_SSE2 1 468 #endif 469 470 /*****************************************************************************************/ 471 /* Calling convention of functions generated by SLJIT or called from the generated code. */ 472 /*****************************************************************************************/ 473 474 #ifndef SLJIT_CALL 475 476 #if (defined SLJIT_USE_CDECL_CALLING_CONVENTION && SLJIT_USE_CDECL_CALLING_CONVENTION) 477 478 /* Force cdecl. */ 479 #define SLJIT_CALL 480 481 #elif (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) 482 483 #if defined(__GNUC__) && !defined(__APPLE__) 484 485 #define SLJIT_CALL __attribute__ ((fastcall)) 486 #define SLJIT_X86_32_FASTCALL 1 487 488 #elif defined(_MSC_VER) 489 490 #define SLJIT_CALL __fastcall 491 #define SLJIT_X86_32_FASTCALL 1 492 493 #elif defined(__BORLANDC__) 494 495 #define SLJIT_CALL __msfastcall 496 #define SLJIT_X86_32_FASTCALL 1 497 498 #else /* Unknown compiler. */ 499 500 /* The cdecl attribute is the default. */ 501 #define SLJIT_CALL 502 503 #endif 504 505 #else /* Non x86-32 architectures. */ 506 507 #define SLJIT_CALL 508 509 #endif /* SLJIT_CONFIG_X86_32 */ 510 511 #endif /* !SLJIT_CALL */ 512 513 #ifndef SLJIT_INDIRECT_CALL 514 #if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)) \ 515 || ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX) 516 /* It seems certain ppc compilers use an indirect addressing for functions 517 which makes things complicated. */ 518 #define SLJIT_INDIRECT_CALL 1 519 #endif 520 #endif /* SLJIT_INDIRECT_CALL */ 521 522 /* The offset which needs to be substracted from the return address to 523 determine the next executed instruction after return. */ 524 #ifndef SLJIT_RETURN_ADDRESS_OFFSET 525 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) 526 #define SLJIT_RETURN_ADDRESS_OFFSET 8 527 #else 528 #define SLJIT_RETURN_ADDRESS_OFFSET 0 529 #endif 530 #endif /* SLJIT_RETURN_ADDRESS_OFFSET */ 531 532 /***************************************************/ 533 /* Functions of the built-in executable allocator. */ 534 /***************************************************/ 535 536 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) 537 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size); 538 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr); 539 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void); 540 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size) 541 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr) 542 543 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR) 544 SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void* ptr); 545 #define SLJIT_EXEC_OFFSET(ptr) sljit_exec_offset(ptr) 546 #else 547 #define SLJIT_EXEC_OFFSET(ptr) 0 548 #endif 549 550 #endif 551 552 /**********************************************/ 553 /* Registers and locals offset determination. */ 554 /**********************************************/ 555 556 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) 557 558 #define SLJIT_NUMBER_OF_REGISTERS 12 559 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 9 560 #if (defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL) 561 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset) 562 #else 563 /* Maximum 3 arguments are passed on the stack, +1 for double alignment. */ 564 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset) 565 #endif /* SLJIT_X86_32_FASTCALL */ 566 567 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) 568 569 #ifndef _WIN64 570 #define SLJIT_NUMBER_OF_REGISTERS 12 571 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 6 572 #define SLJIT_LOCALS_OFFSET_BASE 0 573 #else 574 #define SLJIT_NUMBER_OF_REGISTERS 12 575 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 576 #define SLJIT_LOCALS_OFFSET_BASE (compiler->locals_offset) 577 #endif /* _WIN64 */ 578 579 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) 580 581 #define SLJIT_NUMBER_OF_REGISTERS 12 582 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 583 #define SLJIT_LOCALS_OFFSET_BASE 0 584 585 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) 586 587 #define SLJIT_NUMBER_OF_REGISTERS 12 588 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 589 #define SLJIT_LOCALS_OFFSET_BASE 0 590 591 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) 592 593 #define SLJIT_NUMBER_OF_REGISTERS 25 594 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 10 595 #define SLJIT_LOCALS_OFFSET_BASE (2 * sizeof(sljit_sw)) 596 597 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) 598 599 #define SLJIT_NUMBER_OF_REGISTERS 22 600 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 17 601 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX) 602 #define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * sizeof(sljit_sw)) 603 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) 604 /* Add +1 for double alignment. */ 605 #define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * sizeof(sljit_sw)) 606 #else 607 #define SLJIT_LOCALS_OFFSET_BASE (3 * sizeof(sljit_sw)) 608 #endif /* SLJIT_CONFIG_PPC_64 || _AIX */ 609 610 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) 611 612 #define SLJIT_NUMBER_OF_REGISTERS 21 613 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 614 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) 615 #define SLJIT_LOCALS_OFFSET_BASE (4 * sizeof(sljit_sw)) 616 #else 617 #define SLJIT_LOCALS_OFFSET_BASE 0 618 #endif 619 620 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC) 621 622 #define SLJIT_NUMBER_OF_REGISTERS 18 623 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 14 624 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) 625 /* Add +1 for double alignment. */ 626 #define SLJIT_LOCALS_OFFSET_BASE ((23 + 1) * sizeof(sljit_sw)) 627 #endif 628 629 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX) 630 631 #define SLJIT_NUMBER_OF_REGISTERS 10 632 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 5 633 #define SLJIT_LOCALS_OFFSET_BASE 0 634 635 #elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) 636 637 #define SLJIT_NUMBER_OF_REGISTERS 0 638 #define SLJIT_NUMBER_OF_SAVED_REGISTERS 0 639 #define SLJIT_LOCALS_OFFSET_BASE 0 640 641 #endif 642 643 #define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE) 644 645 #define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \ 646 (SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS) 647 648 #define SLJIT_NUMBER_OF_FLOAT_REGISTERS 6 649 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) && (defined _WIN64) 650 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 1 651 #else 652 #define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0 653 #endif 654 655 #define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \ 656 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS) 657 658 /*************************************/ 659 /* Debug and verbose related macros. */ 660 /*************************************/ 661 662 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) 663 #ifdef _KERNEL 664 #include <sys/systm.h> 665 #else 666 #include <stdio.h> 667 #endif 668 #endif 669 670 #if (defined SLJIT_DEBUG && SLJIT_DEBUG) 671 672 #if !defined(SLJIT_ASSERT) || !defined(SLJIT_UNREACHABLE) 673 674 /* SLJIT_HALT_PROCESS must halt the process. */ 675 #ifndef SLJIT_HALT_PROCESS 676 #ifdef _KERNEL 677 #define SLJIT_HALT_PROCESS() \ 678 panic("sljit halt"); 679 #else 680 #include <stdlib.h> 681 682 #define SLJIT_HALT_PROCESS() \ 683 abort(); 684 #endif 685 #endif /* !SLJIT_HALT_PROCESS */ 686 687 #ifndef _KERNEL 688 #include <stdio.h> 689 #endif 690 691 #endif /* !SLJIT_ASSERT || !SLJIT_UNREACHABLE */ 692 693 /* Feel free to redefine these two macros. */ 694 #ifndef SLJIT_ASSERT 695 696 #include <assert.h> 697 #include <stdlib.h> 698 699 #define SLJIT_ASSERT(x) assert(x) 700 701 #endif /* !SLJIT_ASSERT */ 702 703 #ifndef SLJIT_UNREACHABLE 704 705 #define SLJIT_UNREACHABLE() \ 706 do { \ 707 printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \ 708 SLJIT_HALT_PROCESS(); \ 709 } while (0) 710 711 #endif /* !SLJIT_UNREACHABLE */ 712 713 #else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */ 714 715 /* Forcing empty, but valid statements. */ 716 #undef SLJIT_ASSERT 717 #undef SLJIT_UNREACHABLE 718 719 #define SLJIT_ASSERT(x) \ 720 do { } while (0) 721 #define SLJIT_UNREACHABLE() \ 722 do { } while (0) 723 724 #endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */ 725 726 #ifndef SLJIT_COMPILE_ASSERT 727 728 #define SLJIT_COMPILE_ASSERT(x, description) \ 729 switch(0) { case 0: case ((x) ? 1 : 0): break; } 730 731 #endif /* !SLJIT_COMPILE_ASSERT */ 732 733 #endif 734