| 1 |
/* |
| 2 |
* Stack-less Just-In-Time compiler |
| 3 |
* |
| 4 |
* Copyright Zoltan Herczeg ([email protected]). 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_sp, sljit_up : signed and unsigned pointer value (usually the same as |
| 39 |
sljit_uw, but 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 : unaligned memory accesses for non-fpu operations are supported |
| 49 |
SLJIT_FPU_UNALIGNED : unaligned memory accesses for fpu operations are supported |
| 50 |
SLJIT_MASKED_SHIFT : all word shifts are always masked |
| 51 |
SLJIT_MASKED_SHIFT32 : all 32 bit shifts are always masked |
| 52 |
SLJIT_INDIRECT_CALL : see SLJIT_FUNC_ADDR() for more information |
| 53 |
SLJIT_UPPER_BITS_IGNORED : 32 bit operations ignores the upper bits of source registers |
| 54 |
SLJIT_UPPER_BITS_ZERO_EXTENDED : 32 bit operations clears the upper bits of destination registers |
| 55 |
SLJIT_UPPER_BITS_SIGN_EXTENDED : 32 bit operations replicates the sign bit in the upper bits of destination registers |
| 56 |
SLJIT_UPPER_BITS_PRESERVED : 32 bit operations preserves the upper bits of destination registers |
| 57 |
|
| 58 |
Constants: |
| 59 |
SLJIT_NUMBER_OF_REGISTERS : number of available registers |
| 60 |
SLJIT_NUMBER_OF_SCRATCH_REGISTERS : number of available scratch registers |
| 61 |
SLJIT_NUMBER_OF_SAVED_REGISTERS : number of available saved registers |
| 62 |
SLJIT_NUMBER_OF_FLOAT_REGISTERS : number of available floating point registers |
| 63 |
SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS : number of available scratch floating point registers |
| 64 |
SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS : number of available saved floating point registers |
| 65 |
SLJIT_NUMBER_OF_VECTOR_REGISTERS : number of available vector registers |
| 66 |
SLJIT_NUMBER_OF_SCRATCH_VECTOR_REGISTERS : number of available scratch vector registers |
| 67 |
SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS : number of available saved vector registers |
| 68 |
SLJIT_NUMBER_OF_TEMPORARY_REGISTERS : number of available temporary registers |
| 69 |
SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS : number of available temporary floating point registers |
| 70 |
SLJIT_NUMBER_OF_TEMPORARY_VECTOR_REGISTERS : number of available temporary vector registers |
| 71 |
SLJIT_SEPARATE_VECTOR_REGISTERS : if this macro is defined, the vector registers do not |
| 72 |
overlap with floating point registers |
| 73 |
SLJIT_WORD_SHIFT : the shift required to apply when accessing a sljit_sw/sljit_uw array by index |
| 74 |
SLJIT_POINTER_SHIFT : the shift required to apply when accessing a sljit_sp/sljit_up array by index |
| 75 |
SLJIT_F32_SHIFT : the shift required to apply when accessing |
| 76 |
a single precision floating point array by index |
| 77 |
SLJIT_F64_SHIFT : the shift required to apply when accessing |
| 78 |
a double precision floating point array by index |
| 79 |
SLJIT_PREF_SHIFT_REG : x86 systems prefers ecx for shifting by register |
| 80 |
the scratch register index of ecx is stored in this variable |
| 81 |
SLJIT_LOCALS_OFFSET : local space starting offset (SLJIT_SP + SLJIT_LOCALS_OFFSET) |
| 82 |
SLJIT_RETURN_ADDRESS_OFFSET : a return instruction always adds this offset to the return address |
| 83 |
SLJIT_CONV_MAX_FLOAT : result when a floating point value is converted to integer |
| 84 |
and the floating point value is higher than the maximum integer value |
| 85 |
(possible values: SLJIT_CONV_RESULT_MAX_INT or SLJIT_CONV_RESULT_MIN_INT) |
| 86 |
SLJIT_CONV_MIN_FLOAT : result when a floating point value is converted to integer |
| 87 |
and the floating point value is lower than the minimum integer value |
| 88 |
(possible values: SLJIT_CONV_RESULT_MAX_INT or SLJIT_CONV_RESULT_MIN_INT) |
| 89 |
SLJIT_CONV_NAN_FLOAT : result when a NaN floating point value is converted to integer |
| 90 |
(possible values: SLJIT_CONV_RESULT_MAX_INT, SLJIT_CONV_RESULT_MIN_INT, |
| 91 |
or SLJIT_CONV_RESULT_ZERO) |
| 92 |
|
| 93 |
Other macros: |
| 94 |
SLJIT_TMP_R0 .. R9 : accessing temporary registers |
| 95 |
SLJIT_TMP_R(i) : accessing temporary registers |
| 96 |
SLJIT_TMP_FR0 .. FR9 : accessing temporary floating point registers |
| 97 |
SLJIT_TMP_FR(i) : accessing temporary floating point registers |
| 98 |
SLJIT_TMP_VR0 .. VR9 : accessing temporary vector registers |
| 99 |
SLJIT_TMP_VR(i) : accessing temporary vector registers |
| 100 |
SLJIT_TMP_DEST_REG : a temporary register for results, see the rules below |
| 101 |
SLJIT_TMP_DEST_FREG : a temporary register for float results, see the rules below |
| 102 |
SLJIT_TMP_DEST_VREG : a temporary register for vector results, see the rules below |
| 103 |
SLJIT_TMP_OPT_REG : a temporary register which might not be defined, see the rules below |
| 104 |
SLJIT_FUNC : calling convention attribute for both calling JIT from C and C calling back from JIT |
| 105 |
SLJIT_W(number) : defining 64 bit constants on 64 bit architectures (platform independent helper) |
| 106 |
SLJIT_F64_SECOND(reg) : provides the register index of the second 32 bit part of a 64 bit |
| 107 |
floating point register when SLJIT_HAS_F64_AS_F32_PAIR returns non-zero |
| 108 |
|
| 109 |
Temporary register rules (e.g. SLJIT_TMP_DEST_REG / SLJIT_TMP_OPT_REG): |
| 110 |
Sljit tries to emit instructions without using any temporary registers whenever it is possible. |
| 111 |
When a single temporary register is needed, it is always the "OPT" register. When two temporary |
| 112 |
registers are needed, both the "DEST" and "OPT" are used. The x86-32 does not define an "OPT" |
| 113 |
register, and handles all cases without an "OPT" register which requires an "OPT" register |
| 114 |
on other architectures. |
| 115 |
*/ |
| 116 |
|
| 117 |
#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \ |
| 118 |
|| (defined SLJIT_DEBUG && SLJIT_DEBUG && (!defined(SLJIT_ASSERT) || !defined(SLJIT_UNREACHABLE))) |
| 119 |
#include <stdio.h> |
| 120 |
#endif |
| 121 |
|
| 122 |
#if (defined SLJIT_DEBUG && SLJIT_DEBUG \ |
| 123 |
&& (!defined(SLJIT_ASSERT) || !defined(SLJIT_UNREACHABLE) || !defined(SLJIT_HALT_PROCESS))) |
| 124 |
#include <stdlib.h> |
| 125 |
#endif |
| 126 |
|
| 127 |
#ifdef __cplusplus |
| 128 |
extern "C" { |
| 129 |
#endif |
| 130 |
|
| 131 |
/***********************************************************/ |
| 132 |
/* Intel Control-flow Enforcement Technology (CET) spport. */ |
| 133 |
/***********************************************************/ |
| 134 |
|
| 135 |
#ifdef SLJIT_CONFIG_X86 |
| 136 |
|
| 137 |
#if defined(__CET__) && !(defined SLJIT_CONFIG_X86_CET && SLJIT_CONFIG_X86_CET) |
| 138 |
#define SLJIT_CONFIG_X86_CET 1 |
| 139 |
#endif |
| 140 |
|
| 141 |
#if (defined SLJIT_CONFIG_X86_CET && SLJIT_CONFIG_X86_CET) && defined(__GNUC__) |
| 142 |
#include <x86intrin.h> |
| 143 |
#endif |
| 144 |
|
| 145 |
#endif /* SLJIT_CONFIG_X86 */ |
| 146 |
|
| 147 |
/**********************************/ |
| 148 |
/* External function definitions. */ |
| 149 |
/**********************************/ |
| 150 |
|
| 151 |
/* General macros: |
| 152 |
Note: SLJIT is designed to be independent from them as possible. |
| 153 |
|
| 154 |
In release mode (SLJIT_DEBUG is not defined) only the following |
| 155 |
external functions are needed: |
| 156 |
*/ |
| 157 |
|
| 158 |
#ifndef SLJIT_MALLOC |
| 159 |
#define SLJIT_MALLOC(size, allocator_data) (malloc(size)) |
| 160 |
#endif |
| 161 |
|
| 162 |
#ifndef SLJIT_FREE |
| 163 |
#define SLJIT_FREE(ptr, allocator_data) (free(ptr)) |
| 164 |
#endif |
| 165 |
|
| 166 |
#ifndef SLJIT_MEMCPY |
| 167 |
#define SLJIT_MEMCPY(dest, src, len) (memcpy(dest, src, len)) |
| 168 |
#endif |
| 169 |
|
| 170 |
#ifndef SLJIT_MEMMOVE |
| 171 |
#define SLJIT_MEMMOVE(dest, src, len) (memmove(dest, src, len)) |
| 172 |
#endif |
| 173 |
|
| 174 |
#ifndef SLJIT_ZEROMEM |
| 175 |
#define SLJIT_ZEROMEM(dest, len) (memset(dest, 0, len)) |
| 176 |
#endif |
| 177 |
|
| 178 |
/***************************/ |
| 179 |
/* Compiler helper macros. */ |
| 180 |
/***************************/ |
| 181 |
|
| 182 |
#if !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) |
| 183 |
|
| 184 |
#if defined(__GNUC__) && (__GNUC__ >= 3) |
| 185 |
#define SLJIT_LIKELY(x) __builtin_expect((x), 1) |
| 186 |
#define SLJIT_UNLIKELY(x) __builtin_expect((x), 0) |
| 187 |
#else |
| 188 |
#define SLJIT_LIKELY(x) (x) |
| 189 |
#define SLJIT_UNLIKELY(x) (x) |
| 190 |
#endif |
| 191 |
|
| 192 |
#endif /* !defined(SLJIT_LIKELY) && !defined(SLJIT_UNLIKELY) */ |
| 193 |
|
| 194 |
#ifndef SLJIT_INLINE |
| 195 |
/* Inline functions. Some old compilers do not support them. */ |
| 196 |
#ifdef __SUNPRO_C |
| 197 |
#if __SUNPRO_C < 0x560 |
| 198 |
#define SLJIT_INLINE |
| 199 |
#else |
| 200 |
#define SLJIT_INLINE inline |
| 201 |
#endif /* __SUNPRO_C */ |
| 202 |
#else |
| 203 |
#define SLJIT_INLINE __inline |
| 204 |
#endif |
| 205 |
#endif /* !SLJIT_INLINE */ |
| 206 |
|
| 207 |
#ifndef SLJIT_NOINLINE |
| 208 |
/* Not inline functions. */ |
| 209 |
#if defined(__GNUC__) |
| 210 |
#define SLJIT_NOINLINE __attribute__ ((noinline)) |
| 211 |
#else |
| 212 |
#define SLJIT_NOINLINE |
| 213 |
#endif |
| 214 |
#endif /* !SLJIT_INLINE */ |
| 215 |
|
| 216 |
#ifndef SLJIT_UNUSED_ARG |
| 217 |
/* Unused arguments. */ |
| 218 |
#define SLJIT_UNUSED_ARG(arg) (void)arg |
| 219 |
#endif |
| 220 |
|
| 221 |
/*********************************/ |
| 222 |
/* Type of public API functions. */ |
| 223 |
/*********************************/ |
| 224 |
|
| 225 |
#ifndef SLJIT_API_FUNC_ATTRIBUTE |
| 226 |
#if (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) |
| 227 |
/* Static ABI functions. For all-in-one programs. */ |
| 228 |
|
| 229 |
#if defined(__GNUC__) |
| 230 |
/* Disable unused warnings in gcc. */ |
| 231 |
#define SLJIT_API_FUNC_ATTRIBUTE static __attribute__((unused)) |
| 232 |
#else |
| 233 |
#define SLJIT_API_FUNC_ATTRIBUTE static |
| 234 |
#endif |
| 235 |
|
| 236 |
#else |
| 237 |
#define SLJIT_API_FUNC_ATTRIBUTE |
| 238 |
#endif /* (defined SLJIT_CONFIG_STATIC && SLJIT_CONFIG_STATIC) */ |
| 239 |
#endif /* defined SLJIT_API_FUNC_ATTRIBUTE */ |
| 240 |
|
| 241 |
/****************************/ |
| 242 |
/* Instruction cache flush. */ |
| 243 |
/****************************/ |
| 244 |
|
| 245 |
#ifdef __APPLE__ |
| 246 |
#include <AvailabilityMacros.h> |
| 247 |
#endif |
| 248 |
|
| 249 |
/* |
| 250 |
* TODO: |
| 251 |
* |
| 252 |
* clang >= 15 could be safe to enable below |
| 253 |
* older versions are known to abort in some targets |
| 254 |
* https://github.com/PhilipHazel/pcre2/issues/92 |
| 255 |
* |
| 256 |
* beware some vendors (ex: Microsoft, Apple) are known to have |
| 257 |
* removed the code to support this builtin even if the call for |
| 258 |
* __has_builtin reports it is available. |
| 259 |
* |
| 260 |
* make sure linking doesn't fail because __clear_cache() is |
| 261 |
* missing before changing it or add an exception so that the |
| 262 |
* system provided method that should be defined below is used |
| 263 |
* instead. |
| 264 |
*/ |
| 265 |
#if (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) |
| 266 |
#if __has_builtin(__builtin___clear_cache) && !defined(__clang__) |
| 267 |
|
| 268 |
/* |
| 269 |
* https://gcc.gnu.org/bugzilla//show_bug.cgi?id=91248 |
| 270 |
* https://gcc.gnu.org/bugzilla//show_bug.cgi?id=93811 |
| 271 |
* gcc's clear_cache builtin for power is broken |
| 272 |
*/ |
| 273 |
#if !defined(SLJIT_CONFIG_PPC) |
| 274 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 275 |
__builtin___clear_cache((char*)(from), (char*)(to)) |
| 276 |
#endif |
| 277 |
|
| 278 |
#endif /* gcc >= 10 */ |
| 279 |
#endif /* (!defined SLJIT_CACHE_FLUSH && defined __has_builtin) */ |
| 280 |
|
| 281 |
#ifndef SLJIT_CACHE_FLUSH |
| 282 |
|
| 283 |
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
| 284 |
|| (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
| 285 |
|
| 286 |
/* Not required to implement on archs with unified caches. */ |
| 287 |
#define SLJIT_CACHE_FLUSH(from, to) |
| 288 |
|
| 289 |
#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 |
| 290 |
|
| 291 |
/* Supported by all macs since Mac OS 10.5. |
| 292 |
However, it does not work on non-jailbroken iOS devices, |
| 293 |
although the compilation is successful. */ |
| 294 |
#include <libkern/OSCacheControl.h> |
| 295 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 296 |
sys_icache_invalidate((void*)(from), (size_t)((char*)(to) - (char*)(from))) |
| 297 |
|
| 298 |
#elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
| 299 |
|
| 300 |
/* The __clear_cache() implementation of GCC is a dummy function on PowerPC. */ |
| 301 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 302 |
ppc_cache_flush((from), (to)) |
| 303 |
#define SLJIT_CACHE_FLUSH_OWN_IMPL 1 |
| 304 |
|
| 305 |
#elif defined(_WIN32) |
| 306 |
|
| 307 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 308 |
FlushInstructionCache(GetCurrentProcess(), (void*)(from), (size_t)((char*)(to) - (char*)(from))) |
| 309 |
|
| 310 |
#elif (defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || defined(__clang__) |
| 311 |
|
| 312 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 313 |
__builtin___clear_cache((char*)(from), (char*)(to)) |
| 314 |
|
| 315 |
#elif defined __ANDROID__ |
| 316 |
|
| 317 |
/* Android ARMv7 with gcc lacks __clear_cache; use cacheflush instead. */ |
| 318 |
#include <sys/cachectl.h> |
| 319 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 320 |
cacheflush((long)(from), (long)(to), 0) |
| 321 |
|
| 322 |
#else |
| 323 |
|
| 324 |
/* Call __ARM_NR_cacheflush on ARM-Linux or the corresponding MIPS syscall. */ |
| 325 |
#define SLJIT_CACHE_FLUSH(from, to) \ |
| 326 |
__clear_cache((char*)(from), (char*)(to)) |
| 327 |
|
| 328 |
#endif |
| 329 |
|
| 330 |
#endif /* !SLJIT_CACHE_FLUSH */ |
| 331 |
|
| 332 |
/******************************************************/ |
| 333 |
/* Integer and floating point type definitions. */ |
| 334 |
/******************************************************/ |
| 335 |
|
| 336 |
/* 8 bit byte type. */ |
| 337 |
typedef unsigned char sljit_u8; |
| 338 |
typedef signed char sljit_s8; |
| 339 |
|
| 340 |
/* 16 bit half-word type. */ |
| 341 |
typedef unsigned short int sljit_u16; |
| 342 |
typedef signed short int sljit_s16; |
| 343 |
|
| 344 |
/* 32 bit integer type. */ |
| 345 |
typedef unsigned int sljit_u32; |
| 346 |
typedef signed int sljit_s32; |
| 347 |
|
| 348 |
/* Machine word type. Enough for storing a pointer. |
| 349 |
32 bit for 32 bit machines. |
| 350 |
64 bit for 64 bit machines. */ |
| 351 |
#if (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) |
| 352 |
/* Just to have something. */ |
| 353 |
#define SLJIT_WORD_SHIFT 0 |
| 354 |
typedef unsigned int sljit_uw; |
| 355 |
typedef int sljit_sw; |
| 356 |
#elif !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \ |
| 357 |
&& !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ |
| 358 |
&& !(defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) \ |
| 359 |
&& !(defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64) \ |
| 360 |
&& !(defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) \ |
| 361 |
&& !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ |
| 362 |
&& !(defined SLJIT_CONFIG_LOONGARCH_64 && SLJIT_CONFIG_LOONGARCH_64) |
| 363 |
#define SLJIT_32BIT_ARCHITECTURE 1 |
| 364 |
#define SLJIT_WORD_SHIFT 2 |
| 365 |
typedef unsigned int sljit_uw; |
| 366 |
typedef int sljit_sw; |
| 367 |
#else |
| 368 |
#define SLJIT_64BIT_ARCHITECTURE 1 |
| 369 |
#define SLJIT_WORD_SHIFT 3 |
| 370 |
#ifdef _WIN32 |
| 371 |
#ifdef __GNUC__ |
| 372 |
/* These types do not require windows.h */ |
| 373 |
typedef unsigned long long sljit_uw; |
| 374 |
typedef long long sljit_sw; |
| 375 |
#else |
| 376 |
typedef unsigned __int64 sljit_uw; |
| 377 |
typedef __int64 sljit_sw; |
| 378 |
#endif |
| 379 |
#else /* !_WIN32 */ |
| 380 |
typedef unsigned long int sljit_uw; |
| 381 |
typedef long int sljit_sw; |
| 382 |
#endif /* _WIN32 */ |
| 383 |
#endif |
| 384 |
|
| 385 |
typedef sljit_sw sljit_sp; |
| 386 |
typedef sljit_uw sljit_up; |
| 387 |
|
| 388 |
/* Floating point types. */ |
| 389 |
typedef float sljit_f32; |
| 390 |
typedef double sljit_f64; |
| 391 |
|
| 392 |
/* Shift for pointer sized data. */ |
| 393 |
#define SLJIT_POINTER_SHIFT SLJIT_WORD_SHIFT |
| 394 |
|
| 395 |
/* Shift for double precision sized data. */ |
| 396 |
#define SLJIT_F32_SHIFT 2 |
| 397 |
#define SLJIT_F64_SHIFT 3 |
| 398 |
|
| 399 |
#define SLJIT_CONV_RESULT_MAX_INT 0 |
| 400 |
#define SLJIT_CONV_RESULT_MIN_INT 1 |
| 401 |
#define SLJIT_CONV_RESULT_ZERO 2 |
| 402 |
|
| 403 |
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
| 404 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 405 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 406 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 407 |
#elif (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) |
| 408 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 409 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 410 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_ZERO |
| 411 |
#elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
| 412 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 413 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 414 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 415 |
#elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
| 416 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 417 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 418 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 419 |
#elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
| 420 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 421 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 422 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 423 |
#elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
| 424 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 425 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 426 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 427 |
#elif (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
| 428 |
#define SLJIT_CONV_MAX_FLOAT SLJIT_CONV_RESULT_MAX_INT |
| 429 |
#define SLJIT_CONV_MIN_FLOAT SLJIT_CONV_RESULT_MIN_INT |
| 430 |
#define SLJIT_CONV_NAN_FLOAT SLJIT_CONV_RESULT_ZERO |
| 431 |
#else |
| 432 |
#error "Result for float to integer conversion is not defined" |
| 433 |
#endif |
| 434 |
|
| 435 |
#ifndef SLJIT_W |
| 436 |
|
| 437 |
/* Defining long constants. */ |
| 438 |
#if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE) |
| 439 |
#ifdef _WIN64 |
| 440 |
#define SLJIT_W(w) (w##ll) |
| 441 |
#else /* !windows */ |
| 442 |
#define SLJIT_W(w) (w##l) |
| 443 |
#endif /* windows */ |
| 444 |
#else /* 32 bit */ |
| 445 |
#define SLJIT_W(w) (w) |
| 446 |
#endif /* unknown */ |
| 447 |
|
| 448 |
#endif /* !SLJIT_W */ |
| 449 |
|
| 450 |
/*************************/ |
| 451 |
/* Endianness detection. */ |
| 452 |
/*************************/ |
| 453 |
|
| 454 |
#if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) |
| 455 |
|
| 456 |
/* These macros are mostly useful for the applications. */ |
| 457 |
#if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
| 458 |
|
| 459 |
#ifdef __LITTLE_ENDIAN__ |
| 460 |
#define SLJIT_LITTLE_ENDIAN 1 |
| 461 |
#else |
| 462 |
#define SLJIT_BIG_ENDIAN 1 |
| 463 |
#endif |
| 464 |
|
| 465 |
#elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
| 466 |
|
| 467 |
#ifdef __MIPSEL__ |
| 468 |
#define SLJIT_LITTLE_ENDIAN 1 |
| 469 |
#else |
| 470 |
#define SLJIT_BIG_ENDIAN 1 |
| 471 |
#endif |
| 472 |
|
| 473 |
#ifndef SLJIT_MIPS_REV |
| 474 |
|
| 475 |
/* Auto detecting mips revision. */ |
| 476 |
#if (defined __mips_isa_rev) && (__mips_isa_rev >= 6) |
| 477 |
#define SLJIT_MIPS_REV 6 |
| 478 |
#elif defined(__mips_isa_rev) && __mips_isa_rev >= 1 |
| 479 |
#define SLJIT_MIPS_REV __mips_isa_rev |
| 480 |
#elif defined(__clang__) \ |
| 481 |
&& (defined(_MIPS_ARCH_OCTEON) || defined(_MIPS_ARCH_P5600)) |
| 482 |
/* clang either forgets to define (clang-7) __mips_isa_rev at all |
| 483 |
* or sets it to zero (clang-8,-9) for -march=octeon (MIPS64 R2+) |
| 484 |
* and -march=p5600 (MIPS32 R5). |
| 485 |
* It also sets the __mips macro to 64 or 32 for -mipsN when N <= 5 |
| 486 |
* (should be set to N exactly) so we cannot rely on this too. |
| 487 |
*/ |
| 488 |
#define SLJIT_MIPS_REV 1 |
| 489 |
#endif |
| 490 |
|
| 491 |
#endif /* !SLJIT_MIPS_REV */ |
| 492 |
|
| 493 |
#elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
| 494 |
|
| 495 |
#define SLJIT_BIG_ENDIAN 1 |
| 496 |
|
| 497 |
#else |
| 498 |
#define SLJIT_LITTLE_ENDIAN 1 |
| 499 |
#endif |
| 500 |
|
| 501 |
#endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */ |
| 502 |
|
| 503 |
/* Sanity check. */ |
| 504 |
#if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN) |
| 505 |
#error "Exactly one endianness must be selected" |
| 506 |
#endif |
| 507 |
|
| 508 |
#if !(defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && !(defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN) |
| 509 |
#error "Exactly one endianness must be selected" |
| 510 |
#endif |
| 511 |
|
| 512 |
#ifndef SLJIT_UNALIGNED |
| 513 |
|
| 514 |
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
| 515 |
|| (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) \ |
| 516 |
|| (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2) \ |
| 517 |
|| (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ |
| 518 |
|| (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \ |
| 519 |
|| (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ |
| 520 |
|| (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ |
| 521 |
|| (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
| 522 |
#define SLJIT_UNALIGNED 1 |
| 523 |
#endif |
| 524 |
|
| 525 |
#endif /* !SLJIT_UNALIGNED */ |
| 526 |
|
| 527 |
#ifndef SLJIT_FPU_UNALIGNED |
| 528 |
|
| 529 |
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \ |
| 530 |
|| (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \ |
| 531 |
|| (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \ |
| 532 |
|| (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ |
| 533 |
|| (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ |
| 534 |
|| (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
| 535 |
#define SLJIT_FPU_UNALIGNED 1 |
| 536 |
#endif |
| 537 |
|
| 538 |
#endif /* !SLJIT_FPU_UNALIGNED */ |
| 539 |
|
| 540 |
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
| 541 |
/* Auto detect SSE2 support using CPUID. |
| 542 |
On 64 bit x86 cpus, sse2 must be present. */ |
| 543 |
#define SLJIT_DETECT_SSE2 1 |
| 544 |
#endif |
| 545 |
|
| 546 |
/*****************************************************************************************/ |
| 547 |
/* Calling convention of functions generated by SLJIT or called from the generated code. */ |
| 548 |
/*****************************************************************************************/ |
| 549 |
|
| 550 |
#ifndef SLJIT_FUNC |
| 551 |
#define SLJIT_FUNC |
| 552 |
#endif /* !SLJIT_FUNC */ |
| 553 |
|
| 554 |
#ifndef SLJIT_INDIRECT_CALL |
| 555 |
#if ((defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) && (!defined _CALL_ELF || _CALL_ELF == 1)) \ |
| 556 |
|| ((defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) && defined _AIX) |
| 557 |
/* It seems certain ppc compilers use an indirect addressing for functions |
| 558 |
which makes things complicated. */ |
| 559 |
#define SLJIT_INDIRECT_CALL 1 |
| 560 |
#endif |
| 561 |
#endif /* SLJIT_INDIRECT_CALL */ |
| 562 |
|
| 563 |
/* The offset which needs to be subtracted from the return address to |
| 564 |
determine the next executed instruction after return. */ |
| 565 |
#ifndef SLJIT_RETURN_ADDRESS_OFFSET |
| 566 |
#define SLJIT_RETURN_ADDRESS_OFFSET 0 |
| 567 |
#endif /* SLJIT_RETURN_ADDRESS_OFFSET */ |
| 568 |
|
| 569 |
/***************************************************/ |
| 570 |
/* Functions of the built-in executable allocator. */ |
| 571 |
/***************************************************/ |
| 572 |
|
| 573 |
#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) |
| 574 |
SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size); |
| 575 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr); |
| 576 |
/* Note: sljitLir.h also defines sljit_free_unused_memory_exec() function. */ |
| 577 |
#define SLJIT_BUILTIN_MALLOC_EXEC(size, exec_allocator_data) sljit_malloc_exec(size) |
| 578 |
#define SLJIT_BUILTIN_FREE_EXEC(ptr, exec_allocator_data) sljit_free_exec(ptr) |
| 579 |
|
| 580 |
#ifndef SLJIT_MALLOC_EXEC |
| 581 |
#define SLJIT_MALLOC_EXEC(size, exec_allocator_data) SLJIT_BUILTIN_MALLOC_EXEC((size), (exec_allocator_data)) |
| 582 |
#endif /* SLJIT_MALLOC_EXEC */ |
| 583 |
|
| 584 |
#ifndef SLJIT_FREE_EXEC |
| 585 |
#define SLJIT_FREE_EXEC(ptr, exec_allocator_data) SLJIT_BUILTIN_FREE_EXEC((ptr), (exec_allocator_data)) |
| 586 |
#endif /* SLJIT_FREE_EXEC */ |
| 587 |
|
| 588 |
#if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR) |
| 589 |
SLJIT_API_FUNC_ATTRIBUTE sljit_sw sljit_exec_offset(void *code); |
| 590 |
#define SLJIT_EXEC_OFFSET(code) sljit_exec_offset(code) |
| 591 |
#endif /* SLJIT_PROT_EXECUTABLE_ALLOCATOR */ |
| 592 |
|
| 593 |
#endif /* SLJIT_EXECUTABLE_ALLOCATOR */ |
| 594 |
|
| 595 |
#ifndef SLJIT_EXEC_OFFSET |
| 596 |
#define SLJIT_EXEC_OFFSET(ptr) 0 |
| 597 |
#endif |
| 598 |
|
| 599 |
/**********************************************/ |
| 600 |
/* Registers and locals offset determination. */ |
| 601 |
/**********************************************/ |
| 602 |
|
| 603 |
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
| 604 |
|
| 605 |
#define SLJIT_NUMBER_OF_REGISTERS 12 |
| 606 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 7 |
| 607 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 1 |
| 608 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 7 |
| 609 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0 |
| 610 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 1 |
| 611 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 |
| 612 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 613 |
#define SLJIT_LOCALS_OFFSET_BASE (8 * (sljit_s32)sizeof(sljit_sw)) |
| 614 |
#define SLJIT_PREF_SHIFT_REG SLJIT_R2 |
| 615 |
#define SLJIT_MASKED_SHIFT 1 |
| 616 |
#define SLJIT_MASKED_SHIFT32 1 |
| 617 |
#define SLJIT_UPPER_BITS_IGNORED 1 |
| 618 |
#define SLJIT_UPPER_BITS_ZERO_EXTENDED 1 |
| 619 |
|
| 620 |
#elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
| 621 |
|
| 622 |
#define SLJIT_NUMBER_OF_REGISTERS 13 |
| 623 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 2 |
| 624 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 15 |
| 625 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 1 |
| 626 |
#ifndef _WIN64 |
| 627 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 6 |
| 628 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0 |
| 629 |
#define SLJIT_LOCALS_OFFSET_BASE 0 |
| 630 |
#else /* _WIN64 */ |
| 631 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 |
| 632 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 10 |
| 633 |
#define SLJIT_LOCALS_OFFSET_BASE (4 * (sljit_s32)sizeof(sljit_sw)) |
| 634 |
#endif /* !_WIN64 */ |
| 635 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 |
| 636 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R1 |
| 637 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 638 |
#define SLJIT_PREF_SHIFT_REG SLJIT_R3 |
| 639 |
#define SLJIT_MASKED_SHIFT 1 |
| 640 |
#define SLJIT_MASKED_SHIFT32 1 |
| 641 |
#define SLJIT_UPPER_BITS_IGNORED 1 |
| 642 |
#define SLJIT_UPPER_BITS_ZERO_EXTENDED 1 |
| 643 |
|
| 644 |
#elif (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) |
| 645 |
|
| 646 |
#define SLJIT_NUMBER_OF_REGISTERS 12 |
| 647 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 |
| 648 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 2 |
| 649 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 14 |
| 650 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 |
| 651 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 |
| 652 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 |
| 653 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 |
| 654 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 655 |
#define SLJIT_LOCALS_OFFSET_BASE 0 |
| 656 |
|
| 657 |
#elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) |
| 658 |
|
| 659 |
#define SLJIT_NUMBER_OF_REGISTERS 26 |
| 660 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 10 |
| 661 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 3 |
| 662 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 30 |
| 663 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 |
| 664 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 |
| 665 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R0 |
| 666 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R1 |
| 667 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 668 |
#define SLJIT_LOCALS_OFFSET_BASE (2 * (sljit_s32)sizeof(sljit_sw)) |
| 669 |
#define SLJIT_MASKED_SHIFT 1 |
| 670 |
#define SLJIT_MASKED_SHIFT32 1 |
| 671 |
#define SLJIT_UPPER_BITS_IGNORED 1 |
| 672 |
#define SLJIT_UPPER_BITS_ZERO_EXTENDED 1 |
| 673 |
|
| 674 |
#elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
| 675 |
|
| 676 |
#define SLJIT_NUMBER_OF_REGISTERS 23 |
| 677 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 17 |
| 678 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 3 |
| 679 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 30 |
| 680 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 18 |
| 681 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 |
| 682 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 |
| 683 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 |
| 684 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 685 |
#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) || (defined _AIX) |
| 686 |
#define SLJIT_LOCALS_OFFSET_BASE ((6 + 8) * (sljit_s32)sizeof(sljit_sw)) |
| 687 |
#elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) |
| 688 |
/* Add +1 for double alignment. */ |
| 689 |
#define SLJIT_LOCALS_OFFSET_BASE ((3 + 1) * (sljit_s32)sizeof(sljit_sw)) |
| 690 |
#else |
| 691 |
#define SLJIT_LOCALS_OFFSET_BASE (3 * (sljit_s32)sizeof(sljit_sw)) |
| 692 |
#endif /* SLJIT_CONFIG_PPC_64 || _AIX */ |
| 693 |
#define SLJIT_UPPER_BITS_IGNORED 1 |
| 694 |
|
| 695 |
#elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
| 696 |
|
| 697 |
#define SLJIT_NUMBER_OF_REGISTERS 21 |
| 698 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 |
| 699 |
#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) |
| 700 |
#define SLJIT_LOCALS_OFFSET_BASE (4 * (sljit_s32)sizeof(sljit_sw)) |
| 701 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 13 |
| 702 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 6 |
| 703 |
#else |
| 704 |
#define SLJIT_LOCALS_OFFSET_BASE 0 |
| 705 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 29 |
| 706 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 |
| 707 |
#endif |
| 708 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 5 |
| 709 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 3 |
| 710 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 |
| 711 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 |
| 712 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 713 |
#define SLJIT_MASKED_SHIFT 1 |
| 714 |
#define SLJIT_MASKED_SHIFT32 1 |
| 715 |
#define SLJIT_UPPER_BITS_SIGN_EXTENDED 1 |
| 716 |
|
| 717 |
#elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
| 718 |
|
| 719 |
#define SLJIT_NUMBER_OF_REGISTERS 23 |
| 720 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 12 |
| 721 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 5 |
| 722 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 30 |
| 723 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 12 |
| 724 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 |
| 725 |
#define SLJIT_SEPARATE_VECTOR_REGISTERS 1 |
| 726 |
#define SLJIT_NUMBER_OF_VECTOR_REGISTERS 30 |
| 727 |
#define SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS 0 |
| 728 |
#define SLJIT_NUMBER_OF_TEMPORARY_VECTOR_REGISTERS 2 |
| 729 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 |
| 730 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 |
| 731 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 732 |
#define SLJIT_TMP_DEST_VREG SLJIT_TMP_VR0 |
| 733 |
#define SLJIT_LOCALS_OFFSET_BASE 0 |
| 734 |
#define SLJIT_MASKED_SHIFT 1 |
| 735 |
#define SLJIT_MASKED_SHIFT32 1 |
| 736 |
#define SLJIT_UPPER_BITS_IGNORED 1 |
| 737 |
#define SLJIT_UPPER_BITS_SIGN_EXTENDED 1 |
| 738 |
|
| 739 |
#elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
| 740 |
|
| 741 |
/* |
| 742 |
* https://refspecs.linuxbase.org/ELF/zSeries/lzsabi0_zSeries.html#STACKFRAME |
| 743 |
* |
| 744 |
* 160 |
| 745 |
* .. FR6 |
| 746 |
* .. FR4 |
| 747 |
* .. FR2 |
| 748 |
* 128 FR0 |
| 749 |
* 120 R15 (used for SP) |
| 750 |
* 112 R14 |
| 751 |
* 104 R13 |
| 752 |
* 96 R12 |
| 753 |
* .. |
| 754 |
* 48 R6 |
| 755 |
* .. |
| 756 |
* 16 R2 |
| 757 |
* 8 RESERVED |
| 758 |
* 0 SP |
| 759 |
*/ |
| 760 |
#define SLJIT_S390X_DEFAULT_STACK_FRAME_SIZE 160 |
| 761 |
|
| 762 |
#define SLJIT_NUMBER_OF_REGISTERS 12 |
| 763 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 8 |
| 764 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 3 |
| 765 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 15 |
| 766 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 8 |
| 767 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 1 |
| 768 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R2 |
| 769 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R1 |
| 770 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 771 |
#define SLJIT_LOCALS_OFFSET_BASE SLJIT_S390X_DEFAULT_STACK_FRAME_SIZE |
| 772 |
#define SLJIT_MASKED_SHIFT 1 |
| 773 |
#define SLJIT_UPPER_BITS_IGNORED 1 |
| 774 |
#define SLJIT_UPPER_BITS_PRESERVED 1 |
| 775 |
|
| 776 |
#elif (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
| 777 |
|
| 778 |
#define SLJIT_NUMBER_OF_REGISTERS 23 |
| 779 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 10 |
| 780 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 5 |
| 781 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 30 |
| 782 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 12 |
| 783 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 2 |
| 784 |
#define SLJIT_TMP_DEST_REG SLJIT_TMP_R1 |
| 785 |
#define SLJIT_TMP_OPT_REG SLJIT_TMP_R0 |
| 786 |
#define SLJIT_TMP_DEST_FREG SLJIT_TMP_FR0 |
| 787 |
#define SLJIT_LOCALS_OFFSET_BASE 0 |
| 788 |
#define SLJIT_MASKED_SHIFT 1 |
| 789 |
#define SLJIT_MASKED_SHIFT32 1 |
| 790 |
#define SLJIT_UPPER_BITS_SIGN_EXTENDED 1 |
| 791 |
|
| 792 |
#elif (defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) |
| 793 |
|
| 794 |
/* Just to have something. */ |
| 795 |
#define SLJIT_NUMBER_OF_REGISTERS 0 |
| 796 |
#define SLJIT_NUMBER_OF_SAVED_REGISTERS 0 |
| 797 |
#define SLJIT_NUMBER_OF_TEMPORARY_REGISTERS 0 |
| 798 |
#define SLJIT_NUMBER_OF_FLOAT_REGISTERS 0 |
| 799 |
#define SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS 0 |
| 800 |
#define SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS 0 |
| 801 |
#define SLJIT_TMP_DEST_REG 0 |
| 802 |
#define SLJIT_TMP_DEST_FREG 0 |
| 803 |
#define SLJIT_LOCALS_OFFSET_BASE 0 |
| 804 |
|
| 805 |
#endif |
| 806 |
|
| 807 |
#if !(defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
| 808 |
#define SLJIT_NUMBER_OF_VECTOR_REGISTERS (SLJIT_NUMBER_OF_FLOAT_REGISTERS) |
| 809 |
#define SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS (SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS) |
| 810 |
#define SLJIT_NUMBER_OF_TEMPORARY_VECTOR_REGISTERS (SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS) |
| 811 |
#define SLJIT_TMP_DEST_VREG (SLJIT_TMP_DEST_FREG) |
| 812 |
#endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */ |
| 813 |
|
| 814 |
#define SLJIT_LOCALS_OFFSET (SLJIT_LOCALS_OFFSET_BASE) |
| 815 |
|
| 816 |
#define SLJIT_NUMBER_OF_SCRATCH_REGISTERS \ |
| 817 |
(SLJIT_NUMBER_OF_REGISTERS - SLJIT_NUMBER_OF_SAVED_REGISTERS) |
| 818 |
|
| 819 |
#define SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS \ |
| 820 |
(SLJIT_NUMBER_OF_FLOAT_REGISTERS - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS) |
| 821 |
|
| 822 |
#define SLJIT_NUMBER_OF_SCRATCH_VECTOR_REGISTERS \ |
| 823 |
(SLJIT_NUMBER_OF_VECTOR_REGISTERS - SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS) |
| 824 |
|
| 825 |
#if (defined SLJIT_UPPER_BITS_ZERO_EXTENDED && SLJIT_UPPER_BITS_ZERO_EXTENDED) \ |
| 826 |
+ (defined SLJIT_UPPER_BITS_SIGN_EXTENDED && SLJIT_UPPER_BITS_SIGN_EXTENDED) \ |
| 827 |
+ (defined SLJIT_UPPER_BITS_PRESERVED && SLJIT_UPPER_BITS_PRESERVED) > 1 |
| 828 |
#error "Invalid upper bits defintion" |
| 829 |
#endif |
| 830 |
|
| 831 |
#if (defined SLJIT_UPPER_BITS_PRESERVED && SLJIT_UPPER_BITS_PRESERVED) \ |
| 832 |
&& !(defined SLJIT_UPPER_BITS_IGNORED && SLJIT_UPPER_BITS_IGNORED) |
| 833 |
#error "Upper bits preserved requires bits ignored" |
| 834 |
#endif |
| 835 |
|
| 836 |
/**********************************/ |
| 837 |
/* Temporary register management. */ |
| 838 |
/**********************************/ |
| 839 |
|
| 840 |
#define SLJIT_TMP_REGISTER_BASE (SLJIT_NUMBER_OF_REGISTERS + 2) |
| 841 |
#define SLJIT_TMP_FREGISTER_BASE (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1) |
| 842 |
#define SLJIT_TMP_VREGISTER_BASE (SLJIT_NUMBER_OF_VECTOR_REGISTERS + 1) |
| 843 |
|
| 844 |
/* WARNING: Accessing temporary registers is not recommended, because they |
| 845 |
are also used by the JIT compiler for various computations. Using them |
| 846 |
might have any side effects including incorrect operations and crashes, |
| 847 |
so use them at your own risk. The machine registers themselves might have |
| 848 |
limitations, e.g. the r0 register on s390x / ppc cannot be used as |
| 849 |
base address for memory operations. */ |
| 850 |
|
| 851 |
/* Temporary registers */ |
| 852 |
#define SLJIT_TMP_R0 (SLJIT_TMP_REGISTER_BASE + 0) |
| 853 |
#define SLJIT_TMP_R1 (SLJIT_TMP_REGISTER_BASE + 1) |
| 854 |
#define SLJIT_TMP_R2 (SLJIT_TMP_REGISTER_BASE + 2) |
| 855 |
#define SLJIT_TMP_R3 (SLJIT_TMP_REGISTER_BASE + 3) |
| 856 |
#define SLJIT_TMP_R4 (SLJIT_TMP_REGISTER_BASE + 4) |
| 857 |
#define SLJIT_TMP_R5 (SLJIT_TMP_REGISTER_BASE + 5) |
| 858 |
#define SLJIT_TMP_R6 (SLJIT_TMP_REGISTER_BASE + 6) |
| 859 |
#define SLJIT_TMP_R7 (SLJIT_TMP_REGISTER_BASE + 7) |
| 860 |
#define SLJIT_TMP_R8 (SLJIT_TMP_REGISTER_BASE + 8) |
| 861 |
#define SLJIT_TMP_R9 (SLJIT_TMP_REGISTER_BASE + 9) |
| 862 |
#define SLJIT_TMP_R(i) (SLJIT_TMP_REGISTER_BASE + (i)) |
| 863 |
|
| 864 |
#define SLJIT_TMP_FR0 (SLJIT_TMP_FREGISTER_BASE + 0) |
| 865 |
#define SLJIT_TMP_FR1 (SLJIT_TMP_FREGISTER_BASE + 1) |
| 866 |
#define SLJIT_TMP_FR2 (SLJIT_TMP_FREGISTER_BASE + 2) |
| 867 |
#define SLJIT_TMP_FR3 (SLJIT_TMP_FREGISTER_BASE + 3) |
| 868 |
#define SLJIT_TMP_FR4 (SLJIT_TMP_FREGISTER_BASE + 4) |
| 869 |
#define SLJIT_TMP_FR5 (SLJIT_TMP_FREGISTER_BASE + 5) |
| 870 |
#define SLJIT_TMP_FR6 (SLJIT_TMP_FREGISTER_BASE + 6) |
| 871 |
#define SLJIT_TMP_FR7 (SLJIT_TMP_FREGISTER_BASE + 7) |
| 872 |
#define SLJIT_TMP_FR8 (SLJIT_TMP_FREGISTER_BASE + 8) |
| 873 |
#define SLJIT_TMP_FR9 (SLJIT_TMP_FREGISTER_BASE + 9) |
| 874 |
#define SLJIT_TMP_FR(i) (SLJIT_TMP_FREGISTER_BASE + (i)) |
| 875 |
|
| 876 |
#define SLJIT_TMP_VR0 (SLJIT_TMP_VREGISTER_BASE + 0) |
| 877 |
#define SLJIT_TMP_VR1 (SLJIT_TMP_VREGISTER_BASE + 1) |
| 878 |
#define SLJIT_TMP_VR2 (SLJIT_TMP_VREGISTER_BASE + 2) |
| 879 |
#define SLJIT_TMP_VR3 (SLJIT_TMP_VREGISTER_BASE + 3) |
| 880 |
#define SLJIT_TMP_VR4 (SLJIT_TMP_VREGISTER_BASE + 4) |
| 881 |
#define SLJIT_TMP_VR5 (SLJIT_TMP_VREGISTER_BASE + 5) |
| 882 |
#define SLJIT_TMP_VR6 (SLJIT_TMP_VREGISTER_BASE + 6) |
| 883 |
#define SLJIT_TMP_VR7 (SLJIT_TMP_VREGISTER_BASE + 7) |
| 884 |
#define SLJIT_TMP_VR8 (SLJIT_TMP_VREGISTER_BASE + 8) |
| 885 |
#define SLJIT_TMP_VR9 (SLJIT_TMP_VREGISTER_BASE + 9) |
| 886 |
#define SLJIT_TMP_VR(i) (SLJIT_TMP_VREGISTER_BASE + (i)) |
| 887 |
|
| 888 |
/********************************/ |
| 889 |
/* CPU status flags management. */ |
| 890 |
/********************************/ |
| 891 |
|
| 892 |
#if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \ |
| 893 |
|| (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \ |
| 894 |
|| (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \ |
| 895 |
|| (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \ |
| 896 |
|| (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) \ |
| 897 |
|| (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
| 898 |
#define SLJIT_HAS_STATUS_FLAGS_STATE 1 |
| 899 |
#endif |
| 900 |
|
| 901 |
/***************************************/ |
| 902 |
/* Floating point register management. */ |
| 903 |
/***************************************/ |
| 904 |
|
| 905 |
#if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \ |
| 906 |
|| (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) |
| 907 |
#define SLJIT_F64_SECOND(reg) \ |
| 908 |
((reg) + SLJIT_FS0 + SLJIT_NUMBER_OF_TEMPORARY_FLOAT_REGISTERS) |
| 909 |
#else /* !SLJIT_CONFIG_ARM_32 && !SLJIT_CONFIG_MIPS_32 */ |
| 910 |
#define SLJIT_F64_SECOND(reg) \ |
| 911 |
(reg) |
| 912 |
#endif /* SLJIT_CONFIG_ARM_32 || SLJIT_CONFIG_MIPS_32 */ |
| 913 |
|
| 914 |
/*************************************/ |
| 915 |
/* Debug and verbose related macros. */ |
| 916 |
/*************************************/ |
| 917 |
|
| 918 |
#if (defined SLJIT_DEBUG && SLJIT_DEBUG) |
| 919 |
|
| 920 |
#if !defined(SLJIT_ASSERT) || !defined(SLJIT_UNREACHABLE) |
| 921 |
|
| 922 |
/* SLJIT_HALT_PROCESS must halt the process. */ |
| 923 |
#ifndef SLJIT_HALT_PROCESS |
| 924 |
#define SLJIT_HALT_PROCESS() \ |
| 925 |
abort(); |
| 926 |
#endif /* !SLJIT_HALT_PROCESS */ |
| 927 |
|
| 928 |
#endif /* !SLJIT_ASSERT || !SLJIT_UNREACHABLE */ |
| 929 |
|
| 930 |
/* Feel free to redefine these two macros. */ |
| 931 |
#ifndef SLJIT_ASSERT |
| 932 |
|
| 933 |
#define SLJIT_ASSERT(x) \ |
| 934 |
do { \ |
| 935 |
if (SLJIT_UNLIKELY(!(x))) { \ |
| 936 |
printf("Assertion failed at " __FILE__ ":%d\n", __LINE__); \ |
| 937 |
SLJIT_HALT_PROCESS(); \ |
| 938 |
} \ |
| 939 |
} while (0) |
| 940 |
|
| 941 |
#endif /* !SLJIT_ASSERT */ |
| 942 |
|
| 943 |
#ifndef SLJIT_UNREACHABLE |
| 944 |
|
| 945 |
#define SLJIT_UNREACHABLE() \ |
| 946 |
do { \ |
| 947 |
printf("Should never been reached " __FILE__ ":%d\n", __LINE__); \ |
| 948 |
SLJIT_HALT_PROCESS(); \ |
| 949 |
} while (0) |
| 950 |
|
| 951 |
#endif /* !SLJIT_UNREACHABLE */ |
| 952 |
|
| 953 |
#else /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */ |
| 954 |
|
| 955 |
/* Forcing empty, but valid statements. */ |
| 956 |
#undef SLJIT_ASSERT |
| 957 |
#undef SLJIT_UNREACHABLE |
| 958 |
|
| 959 |
#define SLJIT_ASSERT(x) \ |
| 960 |
do { } while (0) |
| 961 |
#define SLJIT_UNREACHABLE() \ |
| 962 |
do { } while (0) |
| 963 |
|
| 964 |
#endif /* (defined SLJIT_DEBUG && SLJIT_DEBUG) */ |
| 965 |
|
| 966 |
#ifndef SLJIT_COMPILE_ASSERT |
| 967 |
|
| 968 |
#define SLJIT_COMPILE_ASSERT(x, description) \ |
| 969 |
switch(0) { case 0: case ((x) ? 1 : 0): break; } |
| 970 |
|
| 971 |
#endif /* !SLJIT_COMPILE_ASSERT */ |
| 972 |
|
| 973 |
#ifndef SLJIT_FALLTHROUGH |
| 974 |
|
| 975 |
#if defined(__cplusplus) && __cplusplus >= 202002L && \ |
| 976 |
defined(__has_cpp_attribute) |
| 977 |
/* Standards-compatible C++ variant. */ |
| 978 |
#if __has_cpp_attribute(fallthrough) |
| 979 |
#define SLJIT_FALLTHROUGH [[fallthrough]]; |
| 980 |
#endif |
| 981 |
#elif !defined(__cplusplus) && \ |
| 982 |
defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L && \ |
| 983 |
defined(__has_c_attribute) |
| 984 |
/* Standards-compatible C variant. */ |
| 985 |
#if __has_c_attribute(fallthrough) |
| 986 |
#define SLJIT_FALLTHROUGH [[fallthrough]]; |
| 987 |
#endif |
| 988 |
#elif ((defined(__clang__) && __clang_major__ >= 10) || \ |
| 989 |
(defined(__GNUC__) && __GNUC__ >= 7)) && \ |
| 990 |
defined(__has_attribute) |
| 991 |
/* Clang and GCC syntax. Rule out old versions because apparently Clang at |
| 992 |
least has a broken implementation of __has_attribute. */ |
| 993 |
#if __has_attribute(fallthrough) |
| 994 |
#define SLJIT_FALLTHROUGH __attribute__((fallthrough)); |
| 995 |
#endif |
| 996 |
#endif |
| 997 |
|
| 998 |
#ifndef SLJIT_FALLTHROUGH |
| 999 |
#define SLJIT_FALLTHROUGH |
| 1000 |
#endif |
| 1001 |
|
| 1002 |
#endif /* !SLJIT_FALLTHROUGH */ |
| 1003 |
|
| 1004 |
#ifdef __cplusplus |
| 1005 |
} /* extern "C" */ |
| 1006 |
#endif |
| 1007 |
|
| 1008 |
#endif /* SLJIT_CONFIG_INTERNAL_H_ */ |