Path: blob/master/thirdparty/pcre2/deps/sljit/sljit_src/sljitLir.h
9913 views
/*1* Stack-less Just-In-Time compiler2*3* Copyright Zoltan Herczeg ([email protected]). All rights reserved.4*5* Redistribution and use in source and binary forms, with or without modification, are6* permitted provided that the following conditions are met:7*8* 1. Redistributions of source code must retain the above copyright notice, this list of9* conditions and the following disclaimer.10*11* 2. Redistributions in binary form must reproduce the above copyright notice, this list12* of conditions and the following disclaimer in the documentation and/or other materials13* provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY16* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT18* SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED20* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR21* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN22* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN23* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.24*/2526#ifndef SLJIT_LIR_H_27#define SLJIT_LIR_H_2829/*30------------------------------------------------------------------------31Stack-Less JIT compiler for multiple architectures (x86, ARM, PowerPC)32------------------------------------------------------------------------3334Short description35Advantages:36- The execution can be continued from any LIR instruction. In other37words, it is possible to jump to any label from anywhere, even from38a code fragment, which is compiled later, as long as the compiling39context is the same. See sljit_emit_enter for more details.40- Supports self modifying code: target of any jump and call41instructions and some constant values can be dynamically modified42during runtime. See SLJIT_REWRITABLE_JUMP.43- although it is not suggested to do it frequently44- can be used for inline caching: save an important value once45in the instruction stream46- A fixed stack space can be allocated for local variables47- The compiler is thread-safe48- The compiler is highly configurable through preprocessor macros.49You can disable unneeded features (multithreading in single50threaded applications), and you can use your own system functions51(including memory allocators). See sljitConfig.h.52Disadvantages:53- The compiler is more like a platform independent assembler, so54there is no built-in variable management. Registers and stack must55be managed manually (the name of the compiler refers to this).56In practice:57- This approach is very effective for interpreters58- One of the saved registers typically points to a stack interface59- It can jump to any exception handler anytime (even if it belongs60to another function)61- Hot paths can be modified during runtime reflecting the changes62of the fastest execution path of the dynamic language63- SLJIT supports complex memory addressing modes64- mainly position and context independent code (except some cases)6566For valgrind users:67- pass --smc-check=all argument to valgrind, since JIT is a "self-modifying code"68*/6970#if (defined SLJIT_HAVE_CONFIG_PRE && SLJIT_HAVE_CONFIG_PRE)71#include "sljitConfigPre.h"72#endif /* SLJIT_HAVE_CONFIG_PRE */7374#include "sljitConfigCPU.h"75#include "sljitConfig.h"7677/* The following header file defines useful macros for fine tuning78SLJIT based code generators. They are listed in the beginning79of sljitConfigInternal.h */8081#include "sljitConfigInternal.h"8283#if (defined SLJIT_HAVE_CONFIG_POST && SLJIT_HAVE_CONFIG_POST)84#include "sljitConfigPost.h"85#endif /* SLJIT_HAVE_CONFIG_POST */8687#ifdef __cplusplus88extern "C" {89#endif /* __cplusplus */9091/* Version numbers. */92#define SLJIT_MAJOR_VERSION 093#define SLJIT_MINOR_VERSION 959495/* --------------------------------------------------------------------- */96/* Error codes */97/* --------------------------------------------------------------------- */9899/* Indicates no error. */100#define SLJIT_SUCCESS 0101/* After the call of sljit_generate_code(), the error code of the compiler102is set to this value to avoid further code generation.103The complier should be freed after sljit_generate_code(). */104#define SLJIT_ERR_COMPILED 1105/* Cannot allocate non-executable memory. */106#define SLJIT_ERR_ALLOC_FAILED 2107/* Cannot allocate executable memory.108Only sljit_generate_code() returns with this error code. */109#define SLJIT_ERR_EX_ALLOC_FAILED 3110/* Unsupported instruction form. */111#define SLJIT_ERR_UNSUPPORTED 4112/* An invalid argument is passed to any SLJIT function. */113#define SLJIT_ERR_BAD_ARGUMENT 5114115/* --------------------------------------------------------------------- */116/* Registers */117/* --------------------------------------------------------------------- */118119/*120Scratch (R) registers: registers which may not preserve their values121across function calls.122123Saved (S) registers: registers which preserve their values across124function calls.125126The scratch and saved register sets overlap. The last scratch register127is the first saved register, the one before the last is the second saved128register, and so on.129130For example, in an architecture with only five registers (A-E), if two131are scratch and three saved registers, they will be defined as follows:132133A | R0 | | R0 always represent scratch register A134B | R1 | | R1 always represent scratch register B135C | [R2] | S2 | R2 and S2 represent the same physical register C136D | [R3] | S1 | R3 and S1 represent the same physical register D137E | [R4] | S0 | R4 and S0 represent the same physical register E138139Note: SLJIT_NUMBER_OF_SCRATCH_REGISTERS will be 2 and140SLJIT_NUMBER_OF_SAVED_REGISTERS will be 3.141142Note: For all supported architectures SLJIT_NUMBER_OF_REGISTERS >= 12143and SLJIT_NUMBER_OF_SAVED_REGISTERS >= 6. However, 6 registers144are virtual on x86-32. See below.145146The purpose of this definition is convenience: saved registers can147be used as extra scratch registers. For example, building in the148previous example, four registers can be specified as scratch registers149and the fifth one as saved register, allowing any user code which requires150four scratch registers to run unmodified. The SLJIT compiler automatically151saves the content of the two extra scratch register on the stack. Scratch152registers can also be preserved by saving their value on the stack but153that needs to be done manually.154155Note: To emphasize that registers assigned to R2-R4 are saved156registers, they are enclosed by square brackets.157158Note: sljit_emit_enter and sljit_set_context define whether a register159is S or R register. E.g: if in the previous example 3 scratches and1601 saved are mapped by sljit_emit_enter, the allowed register set161will be: R0-R2 and S0. Although S2 is mapped to the same register162than R2, it is not available in that configuration. Furthermore163the S1 register cannot be used at all.164*/165166/* Scratch registers. */167#define SLJIT_R0 1168#define SLJIT_R1 2169#define SLJIT_R2 3170/* Note: on x86-32, R3 - R6 (same as S3 - S6) are emulated (they171are allocated on the stack). These registers are called virtual172and cannot be used for memory addressing (cannot be part of173any SLJIT_MEM1, SLJIT_MEM2 construct). There is no such174limitation on other CPUs. See sljit_get_register_index(). */175#define SLJIT_R3 4176#define SLJIT_R4 5177#define SLJIT_R5 6178#define SLJIT_R6 7179#define SLJIT_R7 8180#define SLJIT_R8 9181#define SLJIT_R9 10182/* All R registers provided by the architecture can be accessed by SLJIT_R(i)183The i parameter must be >= 0 and < SLJIT_NUMBER_OF_REGISTERS. */184#define SLJIT_R(i) (1 + (i))185186/* Saved registers. */187#define SLJIT_S0 (SLJIT_NUMBER_OF_REGISTERS)188#define SLJIT_S1 (SLJIT_NUMBER_OF_REGISTERS - 1)189#define SLJIT_S2 (SLJIT_NUMBER_OF_REGISTERS - 2)190/* Note: on x86-32, S3 - S6 (same as R3 - R6) are emulated (they191are allocated on the stack). These registers are called virtual192and cannot be used for memory addressing (cannot be part of193any SLJIT_MEM1, SLJIT_MEM2 construct). There is no such194limitation on other CPUs. See sljit_get_register_index(). */195#define SLJIT_S3 (SLJIT_NUMBER_OF_REGISTERS - 3)196#define SLJIT_S4 (SLJIT_NUMBER_OF_REGISTERS - 4)197#define SLJIT_S5 (SLJIT_NUMBER_OF_REGISTERS - 5)198#define SLJIT_S6 (SLJIT_NUMBER_OF_REGISTERS - 6)199#define SLJIT_S7 (SLJIT_NUMBER_OF_REGISTERS - 7)200#define SLJIT_S8 (SLJIT_NUMBER_OF_REGISTERS - 8)201#define SLJIT_S9 (SLJIT_NUMBER_OF_REGISTERS - 9)202/* All S registers provided by the architecture can be accessed by SLJIT_S(i)203The i parameter must be >= 0 and < SLJIT_NUMBER_OF_SAVED_REGISTERS. */204#define SLJIT_S(i) (SLJIT_NUMBER_OF_REGISTERS - (i))205206/* Registers >= SLJIT_FIRST_SAVED_REG are saved registers. */207#define SLJIT_FIRST_SAVED_REG (SLJIT_S0 - SLJIT_NUMBER_OF_SAVED_REGISTERS + 1)208209/* The SLJIT_SP provides direct access to the linear stack space allocated by210sljit_emit_enter. It can only be used in the following form: SLJIT_MEM1(SLJIT_SP).211The immediate offset is extended by the relative stack offset automatically.212sljit_get_local_base can be used to obtain the real address of a value. */213#define SLJIT_SP (SLJIT_NUMBER_OF_REGISTERS + 1)214215/* Return with machine word. */216217#define SLJIT_RETURN_REG SLJIT_R0218219/* --------------------------------------------------------------------- */220/* Floating point registers */221/* --------------------------------------------------------------------- */222223/* Each floating point register can store a 32 or a 64 bit precision224value. The FR and FS register sets overlap in the same way as R225and S register sets. See above. */226227/* Floating point scratch registers. */228#define SLJIT_FR0 1229#define SLJIT_FR1 2230#define SLJIT_FR2 3231#define SLJIT_FR3 4232#define SLJIT_FR4 5233#define SLJIT_FR5 6234#define SLJIT_FR6 7235#define SLJIT_FR7 8236#define SLJIT_FR8 9237#define SLJIT_FR9 10238/* All FR registers provided by the architecture can be accessed by SLJIT_FR(i)239The i parameter must be >= 0 and < SLJIT_NUMBER_OF_FLOAT_REGISTERS. */240#define SLJIT_FR(i) (1 + (i))241242/* Floating point saved registers. */243#define SLJIT_FS0 (SLJIT_NUMBER_OF_FLOAT_REGISTERS)244#define SLJIT_FS1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 1)245#define SLJIT_FS2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2)246#define SLJIT_FS3 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 3)247#define SLJIT_FS4 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 4)248#define SLJIT_FS5 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 5)249#define SLJIT_FS6 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 6)250#define SLJIT_FS7 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 7)251#define SLJIT_FS8 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 8)252#define SLJIT_FS9 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 9)253/* All FS registers provided by the architecture can be accessed by SLJIT_FS(i)254The i parameter must be >= 0 and < SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS. */255#define SLJIT_FS(i) (SLJIT_NUMBER_OF_FLOAT_REGISTERS - (i))256257/* Float registers >= SLJIT_FIRST_SAVED_FLOAT_REG are saved registers. */258#define SLJIT_FIRST_SAVED_FLOAT_REG (SLJIT_FS0 - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS + 1)259260/* Return with floating point arg. */261262#define SLJIT_RETURN_FREG SLJIT_FR0263264/* --------------------------------------------------------------------- */265/* Vector registers */266/* --------------------------------------------------------------------- */267268/* Vector registers are storage areas, which are used for Single Instruction269Multiple Data (SIMD) computations. The VR and VS register sets overlap270in the same way as R and S register sets. See above.271272The storage space of vector registers often overlap with floating point273registers. In this case setting the value of SLJIT_VR(i) destroys the274value of SLJIT_FR(i) and vice versa. See SLJIT_SEPARATE_VECTOR_REGISTERS275macro. */276277/* Vector scratch registers. */278#define SLJIT_VR0 1279#define SLJIT_VR1 2280#define SLJIT_VR2 3281#define SLJIT_VR3 4282#define SLJIT_VR4 5283#define SLJIT_VR5 6284#define SLJIT_VR6 7285#define SLJIT_VR7 8286#define SLJIT_VR8 9287#define SLJIT_VR9 10288/* All VR registers provided by the architecture can be accessed by SLJIT_VR(i)289The i parameter must be >= 0 and < SLJIT_NUMBER_OF_VECTOR_REGISTERS. */290#define SLJIT_VR(i) (1 + (i))291292/* Vector saved registers. */293#define SLJIT_VS0 (SLJIT_NUMBER_OF_VECTOR_REGISTERS)294#define SLJIT_VS1 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 1)295#define SLJIT_VS2 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 2)296#define SLJIT_VS3 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 3)297#define SLJIT_VS4 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 4)298#define SLJIT_VS5 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 5)299#define SLJIT_VS6 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 6)300#define SLJIT_VS7 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 7)301#define SLJIT_VS8 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 8)302#define SLJIT_VS9 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 9)303/* All VS registers provided by the architecture can be accessed by SLJIT_VS(i)304The i parameter must be >= 0 and < SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS. */305#define SLJIT_VS(i) (SLJIT_NUMBER_OF_VECTOR_REGISTERS - (i))306307/* Vector registers >= SLJIT_FIRST_SAVED_VECTOR_REG are saved registers. */308#define SLJIT_FIRST_SAVED_VECTOR_REG (SLJIT_VS0 - SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS + 1)309310/* --------------------------------------------------------------------- */311/* Argument type definitions */312/* --------------------------------------------------------------------- */313314/* The following argument type definitions are used by sljit_emit_enter,315sljit_set_context, sljit_emit_call, and sljit_emit_icall functions.316317For sljit_emit_call and sljit_emit_icall, the first integer argument318must be placed into SLJIT_R0, the second one into SLJIT_R1, and so on.319Similarly the first floating point argument must be placed into SLJIT_FR0,320the second one into SLJIT_FR1, and so on.321322For sljit_emit_enter, the integer arguments can be stored in scratch323or saved registers. Scratch registers are identified by a _R suffix.324325If only saved registers are used, then the allocation mirrors what is326done for the "call" functions but using saved registers, meaning that327the first integer argument goes to SLJIT_S0, the second one goes into328SLJIT_S1, and so on.329330If scratch registers are used, then the way the integer registers are331allocated changes so that SLJIT_S0, SLJIT_S1, etc; will be assigned332only for the arguments not using scratch registers, while SLJIT_R<n>333will be used for the ones using scratch registers.334335Furthermore, the index (shown as "n" above) that will be used for the336scratch register depends on how many previous integer registers337(scratch or saved) were used already, starting with SLJIT_R0.338Eventhough some indexes will be likely skipped, they still need to be339accounted for in the scratches parameter of sljit_emit_enter. See below340for some examples.341342The floating point arguments always use scratch registers (but not the343_R suffix like the integer arguments) and must use SLJIT_FR0, SLJIT_FR1,344just like in the "call" functions.345346Note: the mapping for scratch registers is part of the compiler context347and therefore a new context after sljit_emit_call/sljit_emit_icall348could remove access to some scratch registers that were used as349arguments.350351Example function definition:352sljit_f32 SLJIT_FUNC example_c_callback(void *arg_a,353sljit_f64 arg_b, sljit_u32 arg_c, sljit_f32 arg_d);354355Argument type definition:356SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_F32)357| SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_P, 1) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_F64, 2)358| SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_32, 3) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_F32, 4)359360Short form of argument type definition:361SLJIT_ARGS4(F32, P, F64, 32, F32)362363Argument passing:364arg_a must be placed in SLJIT_R0365arg_b must be placed in SLJIT_FR0366arg_c must be placed in SLJIT_R1367arg_d must be placed in SLJIT_FR1368369Examples for argument processing by sljit_emit_enter:370SLJIT_ARGS4V(P, 32_R, F32, W)371Arguments are placed into: SLJIT_S0, SLJIT_R1, SLJIT_FR0, SLJIT_S1372The type of the result is void.373374SLJIT_ARGS4(F32, W, W_R, W, W_R)375Arguments are placed into: SLJIT_S0, SLJIT_R1, SLJIT_S1, SLJIT_R3376The type of the result is sljit_f32.377378SLJIT_ARGS4(P, W, F32, P_R)379Arguments are placed into: SLJIT_FR0, SLJIT_S0, SLJIT_FR1, SLJIT_R1380The type of the result is pointer.381382Note: it is recommended to pass the scratch arguments first383followed by the saved arguments:384385SLJIT_ARGS4(W, W_R, W_R, W, W)386Arguments are placed into: SLJIT_R0, SLJIT_R1, SLJIT_S0, SLJIT_S1387The type of the result is sljit_sw / sljit_uw.388*/389390/* The following flag is only allowed for the integer arguments of391sljit_emit_enter. When the flag is set, the integer argument is392stored in a scratch register instead of a saved register. */393#define SLJIT_ARG_TYPE_SCRATCH_REG 0x8394395/* No return value, only supported by SLJIT_ARG_RETURN. */396#define SLJIT_ARG_TYPE_RET_VOID 0397/* Machine word sized integer argument or result. */398#define SLJIT_ARG_TYPE_W 1399#define SLJIT_ARG_TYPE_W_R (SLJIT_ARG_TYPE_W | SLJIT_ARG_TYPE_SCRATCH_REG)400/* 32 bit integer argument or result. */401#define SLJIT_ARG_TYPE_32 2402#define SLJIT_ARG_TYPE_32_R (SLJIT_ARG_TYPE_32 | SLJIT_ARG_TYPE_SCRATCH_REG)403/* Pointer sized integer argument or result. */404#define SLJIT_ARG_TYPE_P 3405#define SLJIT_ARG_TYPE_P_R (SLJIT_ARG_TYPE_P | SLJIT_ARG_TYPE_SCRATCH_REG)406/* 64 bit floating point argument or result. */407#define SLJIT_ARG_TYPE_F64 4408/* 32 bit floating point argument or result. */409#define SLJIT_ARG_TYPE_F32 5410411#define SLJIT_ARG_SHIFT 4412#define SLJIT_ARG_RETURN(type) (type)413#define SLJIT_ARG_VALUE(type, idx) ((type) << ((idx) * SLJIT_ARG_SHIFT))414415/* Simplified argument list definitions.416417The following definition:418SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_W) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_F32, 1)419420can be shortened to:421SLJIT_ARGS1(W, F32)422423Another example where no value is returned:424SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_RET_VOID) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_W_R, 1)425426can be shortened to:427SLJIT_ARGS1V(W_R)428*/429430#define SLJIT_ARG_TO_TYPE(type) SLJIT_ARG_TYPE_ ## type431432#define SLJIT_ARGS0(ret) \433SLJIT_ARG_RETURN(SLJIT_ARG_TO_TYPE(ret))434#define SLJIT_ARGS0V() \435SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_RET_VOID)436437#define SLJIT_ARGS1(ret, arg1) \438(SLJIT_ARGS0(ret) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg1), 1))439#define SLJIT_ARGS1V(arg1) \440(SLJIT_ARGS0V() | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg1), 1))441442#define SLJIT_ARGS2(ret, arg1, arg2) \443(SLJIT_ARGS1(ret, arg1) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg2), 2))444#define SLJIT_ARGS2V(arg1, arg2) \445(SLJIT_ARGS1V(arg1) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg2), 2))446447#define SLJIT_ARGS3(ret, arg1, arg2, arg3) \448(SLJIT_ARGS2(ret, arg1, arg2) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg3), 3))449#define SLJIT_ARGS3V(arg1, arg2, arg3) \450(SLJIT_ARGS2V(arg1, arg2) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg3), 3))451452#define SLJIT_ARGS4(ret, arg1, arg2, arg3, arg4) \453(SLJIT_ARGS3(ret, arg1, arg2, arg3) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg4), 4))454#define SLJIT_ARGS4V(arg1, arg2, arg3, arg4) \455(SLJIT_ARGS3V(arg1, arg2, arg3) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg4), 4))456457/* --------------------------------------------------------------------- */458/* Main structures and functions */459/* --------------------------------------------------------------------- */460461/*462The following structures are private, and can be changed in the463future. Keeping them here allows code inlining.464*/465466struct sljit_memory_fragment {467struct sljit_memory_fragment *next;468sljit_uw used_size;469/* Must be aligned to sljit_sw. */470sljit_u8 memory[1];471};472473struct sljit_label {474struct sljit_label *next;475union {476sljit_uw index;477sljit_uw addr;478} u;479/* The maximum size difference. */480sljit_uw size;481};482483struct sljit_jump {484struct sljit_jump *next;485sljit_uw addr;486/* Architecture dependent flags. */487sljit_uw flags;488union {489sljit_uw target;490struct sljit_label *label;491} u;492};493494struct sljit_const {495struct sljit_const *next;496sljit_uw addr;497};498499struct sljit_generate_code_buffer {500void *buffer;501sljit_uw size;502sljit_sw executable_offset;503};504505struct sljit_compiler {506sljit_s32 error;507sljit_s32 options;508509struct sljit_label *labels;510struct sljit_jump *jumps;511struct sljit_const *consts;512struct sljit_label *last_label;513struct sljit_jump *last_jump;514struct sljit_const *last_const;515516void *allocator_data;517void *user_data;518struct sljit_memory_fragment *buf;519struct sljit_memory_fragment *abuf;520521/* Number of labels created by the compiler. */522sljit_uw label_count;523/* Available scratch registers. */524sljit_s32 scratches;525/* Available saved registers. */526sljit_s32 saveds;527/* Available float scratch registers. */528sljit_s32 fscratches;529/* Available float saved registers. */530sljit_s32 fsaveds;531#if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) \532|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \533|| (defined SLJIT_DEBUG && SLJIT_DEBUG) \534|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)535/* Available vector scratch registers. */536sljit_s32 vscratches;537/* Available vector saved registers. */538sljit_s32 vsaveds;539#endif /* SLJIT_SEPARATE_VECTOR_REGISTERS || SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG || SLJIT_VERBOSE */540/* Local stack size. */541sljit_s32 local_size;542/* Maximum code size. */543sljit_uw size;544/* Relative offset of the executable mapping from the writable mapping. */545sljit_sw executable_offset;546/* Executable size for statistical purposes. */547sljit_uw executable_size;548549#if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)550sljit_s32 status_flags_state;551#endif /* SLJIT_HAS_STATUS_FLAGS_STATE */552553#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)554sljit_s32 args_size;555#endif /* SLJIT_CONFIG_X86_32 */556557#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)558/* Temporary fields. */559sljit_s32 mode32;560#endif /* SLJIT_CONFIG_X86_64 */561562#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6)563/* Constant pool handling. */564sljit_uw *cpool;565sljit_u8 *cpool_unique;566sljit_uw cpool_diff;567sljit_uw cpool_fill;568/* Other members. */569/* Contains pointer, "ldr pc, [...]" pairs. */570sljit_uw patches;571#endif /* SLJIT_CONFIG_ARM_V6 */572573#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)574/* Temporary fields. */575sljit_uw shift_imm;576#endif /* SLJIT_CONFIG_ARM_V6 || SLJIT_CONFIG_ARM_V6 */577578#if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && (defined __SOFTFP__)579sljit_uw args_size;580#endif /* SLJIT_CONFIG_ARM_32 && __SOFTFP__ */581582#if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)583/* Temporary fields. */584sljit_u32 imm;585#endif /* SLJIT_CONFIG_PPC */586587#if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)588sljit_s32 delay_slot;589/* Temporary fields. */590sljit_s32 cache_arg;591sljit_sw cache_argw;592#endif /* SLJIT_CONFIG_MIPS */593594#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)595sljit_uw args_size;596#endif /* SLJIT_CONFIG_MIPS_32 */597598#if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)599/* Temporary fields. */600sljit_s32 cache_arg;601sljit_sw cache_argw;602#endif /* SLJIT_CONFIG_RISCV */603604#if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)605/* Need to allocate register save area to make calls. */606/* Temporary fields. */607sljit_s32 mode;608#endif /* SLJIT_CONFIG_S390X */609610#if (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH)611/* Temporary fields. */612sljit_s32 cache_arg;613sljit_sw cache_argw;614#endif /* SLJIT_CONFIG_LOONGARCH */615616#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)617FILE* verbose;618#endif /* SLJIT_VERBOSE */619620/* Note: SLJIT_DEBUG enables SLJIT_ARGUMENT_CHECKS. */621#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \622|| (defined SLJIT_DEBUG && SLJIT_DEBUG)623/* Flags specified by the last arithmetic instruction.624It contains the type of the variable flag. */625sljit_s32 last_flags;626/* Return value type set by entry functions. */627sljit_s32 last_return;628/* Local size passed to entry functions. */629sljit_s32 logical_local_size;630#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */631632#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \633|| (defined SLJIT_DEBUG && SLJIT_DEBUG) \634|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)635#if !(defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS)636/* Available float scratch registers. */637sljit_s32 real_fscratches;638/* Available float saved registers. */639sljit_s32 real_fsaveds;640#endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */641642/* Trust arguments when an API function is called.643Used internally for calling API functions. */644sljit_s32 skip_checks;645#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG || SLJIT_VERBOSE */646};647648/* --------------------------------------------------------------------- */649/* Main functions */650/* --------------------------------------------------------------------- */651652/* Creates an SLJIT compiler. The allocator_data is required by some653custom memory managers. This pointer is passed to SLJIT_MALLOC654and SLJIT_FREE macros. Most allocators (including the default655one) ignores this value, and it is recommended to pass NULL656as a dummy value for allocator_data.657658Returns NULL if failed. */659SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data);660661/* Frees everything except the compiled machine code. */662SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler);663664/* Returns the current error code. If an error occurres, future calls665which uses the same compiler argument returns early with the same666error code. Thus there is no need for checking the error after every667call, it is enough to do it after the code is compiled. Removing668these checks increases the performance of the compiling process. */669static SLJIT_INLINE sljit_s32 sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; }670671/* Sets the compiler error code to SLJIT_ERR_ALLOC_FAILED except672if an error was detected before. After the error code is set673the compiler behaves as if the allocation failure happened674during an SLJIT function call. This can greatly simplify error675checking, since it is enough to check the compiler status676after the code is compiled. */677SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler);678679/* Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit,680and <= 128 bytes on 64 bit architectures. The memory area is owned by the681compiler, and freed by sljit_free_compiler. The returned pointer is682sizeof(sljit_sw) aligned. Excellent for allocating small blocks during683compiling, and no need to worry about freeing them. The size is enough684to contain at most 16 pointers. If the size is outside of the range,685the function will return with NULL. However, this return value does not686indicate that there is no more memory (does not set the current error code687of the compiler to out-of-memory status). */688SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size);689690/* Returns the allocator data passed to sljit_create_compiler. */691static SLJIT_INLINE void* sljit_compiler_get_allocator_data(struct sljit_compiler *compiler) { return compiler->allocator_data; }692/* Sets/get the user data for a compiler. */693static SLJIT_INLINE void sljit_compiler_set_user_data(struct sljit_compiler *compiler, void *user_data) { compiler->user_data = user_data; }694static SLJIT_INLINE void* sljit_compiler_get_user_data(struct sljit_compiler *compiler) { return compiler->user_data; }695696#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)697/* Passing NULL disables verbose. */698SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose);699#endif /* SLJIT_VERBOSE */700701/* Option bits for sljit_generate_code. */702703/* The exec_allocator_data points to a pre-allocated704buffer which type is sljit_generate_code_buffer. */705#define SLJIT_GENERATE_CODE_BUFFER 0x1706707/* Create executable code from the instruction stream. This is the final step708of the code generation, and no more instructions can be emitted after this call.709710options is the combination of SLJIT_GENERATE_CODE_* bits711exec_allocator_data is passed to SLJIT_MALLOC_EXEC and712SLJIT_MALLOC_FREE functions */713714SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options, void *exec_allocator_data);715716/* Free executable code. */717718SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data);719720/* When the protected executable allocator is used the JIT code is mapped721twice. The first mapping has read/write and the second mapping has read/exec722permissions. This function returns with the relative offset of the executable723mapping using the writable mapping as the base after the machine code is724successfully generated. The returned value is always 0 for the normal executable725allocator, since it uses only one mapping with read/write/exec permissions.726Dynamic code modifications requires this value.727728Before a successful code generation, this function returns with 0. */729static SLJIT_INLINE sljit_sw sljit_get_executable_offset(struct sljit_compiler *compiler) { return compiler->executable_offset; }730731/* The executable memory consumption of the generated code can be retrieved by732this function. The returned value can be used for statistical purposes.733734Before a successful code generation, this function returns with 0. */735static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; }736737/* Returns with non-zero if the feature or limitation type passed as its738argument is present on the current CPU. The return value is one, if a739feature is fully supported, and it is two, if partially supported.740741Some features (e.g. floating point operations) require hardware (CPU)742support while others (e.g. move with update) are emulated if not available.743However, even when a feature is emulated, specialized code paths may be744faster than the emulation. Some limitations are emulated as well so their745general case is supported but it has extra performance costs.746747Note: sljitConfigInternal.h also provides several feature detection macros. */748749/* [Not emulated] Floating-point support is available. */750#define SLJIT_HAS_FPU 0751/* [Limitation] Some registers are virtual registers. */752#define SLJIT_HAS_VIRTUAL_REGISTERS 1753/* [Emulated] Has zero register (setting a memory location to zero is efficient). */754#define SLJIT_HAS_ZERO_REGISTER 2755/* [Emulated] Count leading zero is supported. */756#define SLJIT_HAS_CLZ 3757/* [Emulated] Count trailing zero is supported. */758#define SLJIT_HAS_CTZ 4759/* [Emulated] Reverse the order of bytes is supported. */760#define SLJIT_HAS_REV 5761/* [Emulated] Rotate left/right is supported. */762#define SLJIT_HAS_ROT 6763/* [Emulated] Conditional move is supported. */764#define SLJIT_HAS_CMOV 7765/* [Emulated] Prefetch instruction is available (emulated as a nop). */766#define SLJIT_HAS_PREFETCH 8767/* [Emulated] Copy from/to f32 operation is available (see sljit_emit_fcopy). */768#define SLJIT_HAS_COPY_F32 9769/* [Emulated] Copy from/to f64 operation is available (see sljit_emit_fcopy). */770#define SLJIT_HAS_COPY_F64 10771/* [Not emulated] The 64 bit floating point registers can be used as772two separate 32 bit floating point registers (e.g. ARM32). The773second 32 bit part can be accessed by SLJIT_F64_SECOND. */774#define SLJIT_HAS_F64_AS_F32_PAIR 11775/* [Not emulated] Some SIMD operations are supported by the compiler. */776#define SLJIT_HAS_SIMD 12777/* [Not emulated] SIMD registers are mapped to a pair of double precision778floating point registers. E.g. passing either SLJIT_FR0 or SLJIT_FR1 to779a simd operation represents the same 128 bit register, and both SLJIT_FR0780and SLJIT_FR1 are overwritten. */781#define SLJIT_SIMD_REGS_ARE_PAIRS 13782/* [Not emulated] Atomic support is available. */783#define SLJIT_HAS_ATOMIC 14784/* [Not emulated] Memory barrier support is available. */785#define SLJIT_HAS_MEMORY_BARRIER 15786787#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)788/* [Not emulated] AVX support is available on x86. */789#define SLJIT_HAS_AVX 100790/* [Not emulated] AVX2 support is available on x86. */791#define SLJIT_HAS_AVX2 101792#endif /* SLJIT_CONFIG_X86 */793794#if (defined SLJIT_CONFIG_LOONGARCH)795/* [Not emulated] LASX support is available on LoongArch */796#define SLJIT_HAS_LASX 201797#endif /* SLJIT_CONFIG_LOONGARCH */798799SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type);800801/* If type is between SLJIT_ORDERED_EQUAL and SLJIT_ORDERED_LESS_EQUAL,802sljit_cmp_info returns with:803zero - if the cpu supports the floating point comparison type804one - if the comparison requires two machine instructions805two - if the comparison requires more than two machine instructions806807When the result is non-zero, it is recommended to avoid808using the specified comparison type if it is easy to do so.809810Otherwise it returns zero. */811SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type);812813/* The following functions generate machine code. If there is no814error, they return with SLJIT_SUCCESS, otherwise they return815with an error code. */816817/*818The executable code is a callable function from the viewpoint819of the C language. Function calls must conform with the ABI820(Application Binary Interface) of the target platform, which821specify the purpose of machine registers and stack handling822among other things. The sljit_emit_enter function emits the823necessary instructions for setting up an entry point for the824executable code. This is often called as function prologue.825826The "options" argument can be used to pass configuration options827to the sljit compiler which affects the generated code, until828another sljit_emit_enter or sljit_set_context is called. The829available options are listed before sljit_emit_enter.830831The function argument list is specified by the SLJIT_ARGSx832(SLJIT_ARGS0 .. SLJIT_ARGS4) macros. Currently maximum four833arguments are supported. See the description of SLJIT_ARGSx834macros about argument passing.835836The register set used by the function must be declared as well.837The number of scratch and saved registers available to the838function must be passed to sljit_emit_enter. Only R registers839between R0 and "scratches" argument can be used later. E.g.840if "scratches" is set to two, the scratch register set will841be limited to SLJIT_R0 and SLJIT_R1. The S registers are842declared in a similar manner, but their count is specified843by "saveds" argument. The floating point scratch and saved844registers can be set by using "scratches" and "saveds" argument845as well, but their value must be passed to the SLJIT_ENTER_FLOAT846macro, see below.847848The sljit_emit_enter is also capable of allocating a stack849space for local data. The "local_size" argument contains the850size in bytes of this local area, and it can be accessed using851SLJIT_MEM1(SLJIT_SP). The memory area between SLJIT_SP (inclusive)852and SLJIT_SP + local_size (exclusive) can be modified freely853until the function returns. The alocated stack space is an854uninitialized memory area.855856Floating point scratch and saved registers must be specified857by the SLJIT_ENTER_FLOAT macro, which result value should be858combined with scratches / saveds argument.859860Examples:861To use three scratch and four floating point scratch862registers, the "scratches" argument must be set to:8633 | SLJIT_ENTER_FLOAT(4)864865To use six saved and five floating point saved866registers, the "saveds" argument must be set to:8676 | SLJIT_ENTER_FLOAT(5)868869Note: the following conditions must met:8700 <= scratches <= SLJIT_NUMBER_OF_REGISTERS8710 <= saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS872scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS8738740 <= float scratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS8750 <= float saveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS876float scratches + float saveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS877878Note: the compiler can use saved registers as scratch registers,879but the opposite is not supported880881Note: every call of sljit_emit_enter and sljit_set_context882overwrites the previous context.883*/884885/* The following options are available for sljit_emit_enter. */886887/* Saved registers between SLJIT_S0 and SLJIT_S(n - 1) (inclusive)888are not saved / restored on function enter / return. Instead,889these registers can be used to pass / return data (such as890global / local context pointers) across function calls. The891value of n must be between 1 and 3. This option is only892supported by SLJIT_ENTER_REG_ARG calling convention. */893#define SLJIT_ENTER_KEEP(n) (n)894895/* The compiled function uses an SLJIT specific register argument896calling convention. This is a lightweight function call type where897both the caller and the called functions must be compiled by898SLJIT. The type argument of the call must be SLJIT_CALL_REG_ARG899and all arguments must be stored in scratch registers. */900#define SLJIT_ENTER_REG_ARG 0x00000004901902#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)903/* Use VEX prefix for all SIMD operations on x86. */904#define SLJIT_ENTER_USE_VEX 0x00010000905#endif /* !SLJIT_CONFIG_X86 */906907/* Macros for other sljit_emit_enter arguments. */908909/* Floating point scratch and saved registers can be910specified by SLJIT_ENTER_FLOAT. */911#define SLJIT_ENTER_FLOAT(regs) ((regs) << 8)912913/* Vector scratch and saved registers can be specified914by SLJIT_ENTER_VECTOR. */915#define SLJIT_ENTER_VECTOR(regs) ((regs) << 16)916917/* The local_size must be >= 0 and <= SLJIT_MAX_LOCAL_SIZE. */918#define SLJIT_MAX_LOCAL_SIZE 1048576919920SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,921sljit_s32 options, sljit_s32 arg_types,922sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size);923924/* The SLJIT compiler has a current context (which contains the local925stack space size, number of used registers, etc.) which is initialized926by sljit_emit_enter. Several functions (such as sljit_emit_return)927requires this context to be able to generate the appropriate code.928However, some code fragments (compiled separately) may have no929normal entry point so their context is unknown to the compiler.930931sljit_set_context and sljit_emit_enter have the same arguments,932but sljit_set_context does not generate any machine code.933934Note: every call of sljit_emit_enter and sljit_set_context overwrites935the previous context. */936937SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,938sljit_s32 options, sljit_s32 arg_types,939sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size);940941/* Return to the caller function. The sljit_emit_return_void function942does not return with any value. The sljit_emit_return function returns943with a single value loaded from its source operand. The load operation944can be between SLJIT_MOV and SLJIT_MOV_P (see sljit_emit_op1) and945SLJIT_MOV_F32/SLJIT_MOV_F64 (see sljit_emit_fop1) depending on the946return value specified by sljit_emit_enter/sljit_set_context. */947948SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler);949950SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op,951sljit_s32 src, sljit_sw srcw);952953/* Restores the saved registers and free the stack area, then the execution954continues from the address specified by the source operand. This955operation is similar to sljit_emit_return, but it ignores the return956address. The code where the exection continues should use the same context957as the caller function (see sljit_set_context). A word (pointer) value958can be passed in the SLJIT_RETURN_REG register. This function can be used959to jump to exception handlers. */960961SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_to(struct sljit_compiler *compiler,962sljit_s32 src, sljit_sw srcw);963964/*965Source and destination operands for arithmetical instructions966imm - a simple immediate value (cannot be used as a destination)967reg - any of the available registers (immediate argument must be 0)968[imm] - absolute memory address969[reg+imm] - indirect memory address970[reg+(reg<<imm)] - indirect indexed memory address (shift must be between 0 and 3)971useful for accessing arrays (fully supported by both x86 and972ARM architectures, and cheap operation on others)973*/974975/*976IMPORTANT NOTE: memory accesses MUST be naturally aligned unless977SLJIT_UNALIGNED macro is defined and its value is 1.978979length | alignment980---------+-----------981byte | 1 byte (any physical_address is accepted)982half | 2 byte (physical_address & 0x1 == 0)983int | 4 byte (physical_address & 0x3 == 0)984word | 4 byte if SLJIT_32BIT_ARCHITECTURE is defined and its value is 1985| 8 byte if SLJIT_64BIT_ARCHITECTURE is defined and its value is 1986pointer | size of sljit_up type (4 byte on 32 bit machines, 4 or 8 byte987| on 64 bit machines)988989Note: Different architectures have different addressing limitations.990A single instruction is enough for the following addressing991modes. Other addressing modes are emulated by instruction992sequences. This information could help to improve those code993generators which focuses only a few architectures.994995x86: [reg+imm], -2^32+1 <= imm <= 2^32-1 (full address space on x86-32)996[reg+(reg<<imm)] is supported997[imm], -2^32+1 <= imm <= 2^32-1 is supported998Write-back is not supported999arm: [reg+imm], -4095 <= imm <= 4095 or -255 <= imm <= 255 for signed1000bytes, any halfs or floating point values)1001[reg+(reg<<imm)] is supported1002Write-back is supported1003arm-t2: [reg+imm], -255 <= imm <= 40951004[reg+(reg<<imm)] is supported1005Write back is supported only for [reg+imm], where -255 <= imm <= 2551006arm64: [reg+imm], -256 <= imm <= 255, 0 <= aligned imm <= 4095 * alignment1007[reg+(reg<<imm)] is supported1008Write back is supported only for [reg+imm], where -256 <= imm <= 2551009ppc: [reg+imm], -65536 <= imm <= 65535. 64 bit loads/stores and 32 bit1010signed load on 64 bit requires immediates divisible by 4.1011[reg+imm] is not supported for signed 8 bit values.1012[reg+reg] is supported1013Write-back is supported except for one instruction: 32 bit signed1014load with [reg+imm] addressing mode on 64 bit.1015mips: [reg+imm], -65536 <= imm <= 655351016Write-back is not supported1017riscv: [reg+imm], -2048 <= imm <= 20471018Write-back is not supported1019s390x: [reg+imm], -2^19 <= imm < 2^191020[reg+reg] is supported1021Write-back is not supported1022loongarch: [reg+imm], -2048 <= imm <= 20471023[reg+reg] is supported1024Write-back is not supported1025*/10261027/* Macros for specifying operand types. */1028#define SLJIT_MEM 0x801029#define SLJIT_MEM0() (SLJIT_MEM)1030#define SLJIT_MEM1(r1) (SLJIT_MEM | (r1))1031#define SLJIT_MEM2(r1, r2) (SLJIT_MEM | (r1) | ((r2) << 8))1032#define SLJIT_IMM 0x7f1033#define SLJIT_REG_PAIR(r1, r2) ((r1) | ((r2) << 8))10341035/* Macros for checking operand types (only for valid arguments). */1036#define SLJIT_IS_REG(arg) ((arg) > 0 && (arg) < SLJIT_IMM)1037#define SLJIT_IS_MEM(arg) ((arg) & SLJIT_MEM)1038#define SLJIT_IS_MEM0(arg) ((arg) == SLJIT_MEM)1039#define SLJIT_IS_MEM1(arg) ((arg) > SLJIT_MEM && (arg) < (SLJIT_MEM << 1))1040#define SLJIT_IS_MEM2(arg) (((arg) & SLJIT_MEM) && (arg) >= (SLJIT_MEM << 1))1041#define SLJIT_IS_IMM(arg) ((arg) == SLJIT_IMM)1042#define SLJIT_IS_REG_PAIR(arg) (!((arg) & SLJIT_MEM) && (arg) >= (SLJIT_MEM << 1))10431044/* Macros for extracting registers from operands. */1045/* Support operands which contains a single register or1046constructed using SLJIT_MEM1, SLJIT_MEM2, or SLJIT_REG_PAIR. */1047#define SLJIT_EXTRACT_REG(arg) ((arg) & 0x7f)1048/* Support operands which constructed using SLJIT_MEM2, or SLJIT_REG_PAIR. */1049#define SLJIT_EXTRACT_SECOND_REG(arg) ((arg) >> 8)10501051/* Sets 32 bit operation mode on 64 bit CPUs. This option is ignored on105232 bit CPUs. When this option is set for an arithmetic operation, only1053the lower 32 bits of the input registers are used, and the CPU status1054flags are set according to the 32 bit result. Although the higher 32 bit1055of the input and the result registers are not defined by SLJIT, it might1056be defined by the CPU architecture (e.g. MIPS). To satisfy these CPU1057requirements all source registers must be the result of those operations1058where this option was also set. Memory loads read 32 bit values rather1059than 64 bit ones. In other words 32 bit and 64 bit operations cannot be1060mixed. The only exception is SLJIT_MOV32 which source register can hold1061any 32 or 64 bit value, and it is converted to a 32 bit compatible format1062first. When the source and destination registers are the same, this1063conversion is free (no instructions are emitted) on most CPUs. A 32 bit1064value can also be converted to a 64 bit value by SLJIT_MOV_S321065(sign extension) or SLJIT_MOV_U32 (zero extension).10661067As for floating-point operations, this option sets 32 bit single1068precision mode. Similar to the integer operations, all register arguments1069must be the result of those operations where this option was also set.10701071Note: memory addressing always uses 64 bit values on 64 bit systems so1072the result of a 32 bit operation must not be used with SLJIT_MEMx1073macros.10741075This option is part of the instruction name, so there is no need to1076manually set it. E.g:10771078SLJIT_ADD32 == (SLJIT_ADD | SLJIT_32) */1079#define SLJIT_32 0x10010801081/* Many CPUs (x86, ARM, PPC) have status flag bits which can be set according1082to the result of an operation. Other CPUs (MIPS) do not have status1083flag bits, and results must be stored in registers. To cover both1084architecture types efficiently only two flags are defined by SLJIT:10851086* Zero (equal) flag: it is set if the result is zero1087* Variable flag: its value is defined by the arithmetic operation10881089SLJIT instructions can set any or both of these flags. The value of1090these flags is undefined if the instruction does not specify their1091value. The description of each instruction contains the list of1092allowed flag types.10931094Note: the logical or operation can be used to set flags.10951096Example: SLJIT_ADD can set the Z, OVERFLOW, CARRY flags hence10971098sljit_op2(..., SLJIT_ADD, ...)1099Both the zero and variable flags are undefined so they can1100have any value after the operation is completed.11011102sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...)1103Sets the zero flag if the result is zero, clears it otherwise.1104The variable flag is undefined.11051106sljit_op2(..., SLJIT_ADD | SLJIT_SET_OVERFLOW, ...)1107Sets the variable flag if an integer overflow occurs, clears1108it otherwise. The zero flag is undefined.11091110sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_CARRY, ...)1111Sets the zero flag if the result is zero, clears it otherwise.1112Sets the variable flag if unsigned overflow (carry) occurs,1113clears it otherwise.11141115Certain instructions (e.g. SLJIT_MOV) does not modify flags, so1116status flags are unchanged.11171118Example:11191120sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...)1121sljit_op1(..., SLJIT_MOV, ...)1122Zero flag is set according to the result of SLJIT_ADD.11231124sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...)1125sljit_op2(..., SLJIT_ADD, ...)1126Zero flag has unknown value.11271128These flags can be used for code optimization. E.g. a fast loop can be1129implemented by decreasing a counter register and set the zero flag1130using a single instruction. The zero register can be used by a1131conditional jump to restart the loop. A single comparison can set a1132zero and less flags to check if a value is less, equal, or greater1133than another value.11341135Motivation: although some CPUs can set a large number of flag bits,1136usually their values are ignored or only a few of them are used. Emulating1137a large number of flags on systems without a flag register is complicated1138so SLJIT instructions must specify the flag they want to use and only1139that flag is computed. The last arithmetic instruction can be repeated if1140multiple flags need to be checked.1141*/11421143/* Set Zero status flag. */1144#define SLJIT_SET_Z 0x02001145/* Set the variable status flag if condition is true.1146See comparison types (e.g. SLJIT_SET_LESS, SLJIT_SET_F_EQUAL). */1147#define SLJIT_SET(condition) ((condition) << 10)11481149/* Starting index of opcodes for sljit_emit_op0. */1150#define SLJIT_OP0_BASE 011511152/* Flags: - (does not modify flags)1153Note: breakpoint instruction is not supported by all architectures (e.g. ppc)1154It falls back to SLJIT_NOP in those cases. */1155#define SLJIT_BREAKPOINT (SLJIT_OP0_BASE + 0)1156/* Flags: - (does not modify flags)1157Note: may or may not cause an extra cycle wait1158it can even decrease the runtime in a few cases. */1159#define SLJIT_NOP (SLJIT_OP0_BASE + 1)1160/* Flags: - (may destroy flags)1161Unsigned multiplication of SLJIT_R0 and SLJIT_R1.1162Result is placed into SLJIT_R1:SLJIT_R0 (high:low) word */1163#define SLJIT_LMUL_UW (SLJIT_OP0_BASE + 2)1164/* Flags: - (may destroy flags)1165Signed multiplication of SLJIT_R0 and SLJIT_R1.1166Result is placed into SLJIT_R1:SLJIT_R0 (high:low) word */1167#define SLJIT_LMUL_SW (SLJIT_OP0_BASE + 3)1168/* Flags: - (may destroy flags)1169Unsigned divide of the value in SLJIT_R0 by the value in SLJIT_R1.1170The result is placed into SLJIT_R0 and the remainder into SLJIT_R1.1171Note: if SLJIT_R1 is 0, the behaviour is undefined. */1172#define SLJIT_DIVMOD_UW (SLJIT_OP0_BASE + 4)1173#define SLJIT_DIVMOD_U32 (SLJIT_DIVMOD_UW | SLJIT_32)1174/* Flags: - (may destroy flags)1175Signed divide of the value in SLJIT_R0 by the value in SLJIT_R1.1176The result is placed into SLJIT_R0 and the remainder into SLJIT_R1.1177Note: if SLJIT_R1 is 0, the behaviour is undefined.1178Note: if SLJIT_R1 is -1 and SLJIT_R0 is integer min (0x800..00),1179the behaviour is undefined. */1180#define SLJIT_DIVMOD_SW (SLJIT_OP0_BASE + 5)1181#define SLJIT_DIVMOD_S32 (SLJIT_DIVMOD_SW | SLJIT_32)1182/* Flags: - (may destroy flags)1183Unsigned divide of the value in SLJIT_R0 by the value in SLJIT_R1.1184The result is placed into SLJIT_R0. SLJIT_R1 preserves its value.1185Note: if SLJIT_R1 is 0, the behaviour is undefined. */1186#define SLJIT_DIV_UW (SLJIT_OP0_BASE + 6)1187#define SLJIT_DIV_U32 (SLJIT_DIV_UW | SLJIT_32)1188/* Flags: - (may destroy flags)1189Signed divide of the value in SLJIT_R0 by the value in SLJIT_R1.1190The result is placed into SLJIT_R0. SLJIT_R1 preserves its value.1191Note: if SLJIT_R1 is 0, the behaviour is undefined.1192Note: if SLJIT_R1 is -1 and SLJIT_R0 is integer min (0x800..00),1193the behaviour is undefined. */1194#define SLJIT_DIV_SW (SLJIT_OP0_BASE + 7)1195#define SLJIT_DIV_S32 (SLJIT_DIV_SW | SLJIT_32)1196/* Flags: - (does not modify flags)1197May return with SLJIT_ERR_UNSUPPORTED if SLJIT_HAS_MEMORY_BARRIER1198feature is not supported (calling sljit_has_cpu_feature() with1199this feature option returns with 0). */1200#define SLJIT_MEMORY_BARRIER (SLJIT_OP0_BASE + 8)1201/* Flags: - (does not modify flags)1202ENDBR32 instruction for x86-32 and ENDBR64 instruction for x86-641203when Intel Control-flow Enforcement Technology (CET) is enabled.1204No instructions are emitted for other architectures. */1205#define SLJIT_ENDBR (SLJIT_OP0_BASE + 9)1206/* Flags: - (may destroy flags)1207Skip stack frames before return when Intel Control-flow1208Enforcement Technology (CET) is enabled. No instructions1209are emitted for other architectures. */1210#define SLJIT_SKIP_FRAMES_BEFORE_RETURN (SLJIT_OP0_BASE + 10)12111212SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op);12131214/* Starting index of opcodes for sljit_emit_op1. */1215#define SLJIT_OP1_BASE 3212161217/* The MOV instruction transfers data from source to destination.12181219MOV instruction suffixes:12201221U8 - unsigned 8 bit data transfer1222S8 - signed 8 bit data transfer1223U16 - unsigned 16 bit data transfer1224S16 - signed 16 bit data transfer1225U32 - unsigned int (32 bit) data transfer1226S32 - signed int (32 bit) data transfer1227P - pointer (sljit_up) data transfer1228*/12291230/* Flags: - (does not modify flags) */1231#define SLJIT_MOV (SLJIT_OP1_BASE + 0)1232/* Flags: - (does not modify flags) */1233#define SLJIT_MOV_U8 (SLJIT_OP1_BASE + 1)1234#define SLJIT_MOV32_U8 (SLJIT_MOV_U8 | SLJIT_32)1235/* Flags: - (does not modify flags) */1236#define SLJIT_MOV_S8 (SLJIT_OP1_BASE + 2)1237#define SLJIT_MOV32_S8 (SLJIT_MOV_S8 | SLJIT_32)1238/* Flags: - (does not modify flags) */1239#define SLJIT_MOV_U16 (SLJIT_OP1_BASE + 3)1240#define SLJIT_MOV32_U16 (SLJIT_MOV_U16 | SLJIT_32)1241/* Flags: - (does not modify flags) */1242#define SLJIT_MOV_S16 (SLJIT_OP1_BASE + 4)1243#define SLJIT_MOV32_S16 (SLJIT_MOV_S16 | SLJIT_32)1244/* Flags: - (does not modify flags)1245Note: no SLJIT_MOV32_U32 form, since it is the same as SLJIT_MOV32 */1246#define SLJIT_MOV_U32 (SLJIT_OP1_BASE + 5)1247/* Flags: - (does not modify flags)1248Note: no SLJIT_MOV32_S32 form, since it is the same as SLJIT_MOV32 */1249#define SLJIT_MOV_S32 (SLJIT_OP1_BASE + 6)1250/* Flags: - (does not modify flags) */1251#define SLJIT_MOV32 (SLJIT_OP1_BASE + 7)1252/* Flags: - (does not modify flags)1253Note: loads a pointer sized data, useful on x32 mode (a 64 bit mode1254on x86-64 which uses 32 bit pointers) or similar compiling modes */1255#define SLJIT_MOV_P (SLJIT_OP1_BASE + 8)1256/* Count leading zeroes1257Flags: - (may destroy flags)1258Note: immediate source argument is not supported */1259#define SLJIT_CLZ (SLJIT_OP1_BASE + 9)1260#define SLJIT_CLZ32 (SLJIT_CLZ | SLJIT_32)1261/* Count trailing zeroes1262Flags: - (may destroy flags)1263Note: immediate source argument is not supported */1264#define SLJIT_CTZ (SLJIT_OP1_BASE + 10)1265#define SLJIT_CTZ32 (SLJIT_CTZ | SLJIT_32)1266/* Reverse the order of bytes1267Flags: - (may destroy flags)1268Note: converts between little and big endian formats1269Note: immediate source argument is not supported */1270#define SLJIT_REV (SLJIT_OP1_BASE + 11)1271#define SLJIT_REV32 (SLJIT_REV | SLJIT_32)1272/* Reverse the order of bytes in the lower 16 bit and extend as unsigned1273Flags: - (may destroy flags)1274Note: converts between little and big endian formats1275Note: immediate source argument is not supported */1276#define SLJIT_REV_U16 (SLJIT_OP1_BASE + 12)1277#define SLJIT_REV32_U16 (SLJIT_REV_U16 | SLJIT_32)1278/* Reverse the order of bytes in the lower 16 bit and extend as signed1279Flags: - (may destroy flags)1280Note: converts between little and big endian formats1281Note: immediate source argument is not supported */1282#define SLJIT_REV_S16 (SLJIT_OP1_BASE + 13)1283#define SLJIT_REV32_S16 (SLJIT_REV_S16 | SLJIT_32)1284/* Reverse the order of bytes in the lower 32 bit and extend as unsigned1285Flags: - (may destroy flags)1286Note: converts between little and big endian formats1287Note: immediate source argument is not supported */1288#define SLJIT_REV_U32 (SLJIT_OP1_BASE + 14)1289/* Reverse the order of bytes in the lower 32 bit and extend as signed1290Flags: - (may destroy flags)1291Note: converts between little and big endian formats1292Note: immediate source argument is not supported */1293#define SLJIT_REV_S32 (SLJIT_OP1_BASE + 15)12941295/* The following unary operations are supported by using sljit_emit_op2:1296- binary not: SLJIT_XOR with immedate -1 as src1 or src21297- negate: SLJIT_SUB with immedate 0 as src11298Note: these operations are optimized by the compiler if the1299target CPU has specialized instruction forms for them. */13001301SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,1302sljit_s32 dst, sljit_sw dstw,1303sljit_s32 src, sljit_sw srcw);13041305/* Starting index of opcodes for sljit_emit_op2. */1306#define SLJIT_OP2_BASE 6413071308/* Flags: Z | OVERFLOW | CARRY */1309#define SLJIT_ADD (SLJIT_OP2_BASE + 0)1310#define SLJIT_ADD32 (SLJIT_ADD | SLJIT_32)1311/* Flags: CARRY */1312#define SLJIT_ADDC (SLJIT_OP2_BASE + 1)1313#define SLJIT_ADDC32 (SLJIT_ADDC | SLJIT_32)1314/* Flags: Z | LESS | GREATER_EQUAL | GREATER | LESS_EQUAL1315SIG_LESS | SIG_GREATER_EQUAL | SIG_GREATER1316SIG_LESS_EQUAL | OVERFLOW | CARRY */1317#define SLJIT_SUB (SLJIT_OP2_BASE + 2)1318#define SLJIT_SUB32 (SLJIT_SUB | SLJIT_32)1319/* Flags: CARRY */1320#define SLJIT_SUBC (SLJIT_OP2_BASE + 3)1321#define SLJIT_SUBC32 (SLJIT_SUBC | SLJIT_32)1322/* Note: integer mul1323Flags: OVERFLOW */1324#define SLJIT_MUL (SLJIT_OP2_BASE + 4)1325#define SLJIT_MUL32 (SLJIT_MUL | SLJIT_32)1326/* Flags: Z */1327#define SLJIT_AND (SLJIT_OP2_BASE + 5)1328#define SLJIT_AND32 (SLJIT_AND | SLJIT_32)1329/* Flags: Z */1330#define SLJIT_OR (SLJIT_OP2_BASE + 6)1331#define SLJIT_OR32 (SLJIT_OR | SLJIT_32)1332/* Flags: Z */1333#define SLJIT_XOR (SLJIT_OP2_BASE + 7)1334#define SLJIT_XOR32 (SLJIT_XOR | SLJIT_32)1335/* Flags: Z1336Let bit_length be the length of the shift operation: 32 or 64.1337If src2 is immediate, src2w is masked by (bit_length - 1).1338Otherwise, if the content of src2 is outside the range from 01339to bit_length - 1, the result is undefined. */1340#define SLJIT_SHL (SLJIT_OP2_BASE + 8)1341#define SLJIT_SHL32 (SLJIT_SHL | SLJIT_32)1342/* Flags: Z1343Same as SLJIT_SHL, except the the second operand is1344always masked by the length of the shift operation. */1345#define SLJIT_MSHL (SLJIT_OP2_BASE + 9)1346#define SLJIT_MSHL32 (SLJIT_MSHL | SLJIT_32)1347/* Flags: Z1348Let bit_length be the length of the shift operation: 32 or 64.1349If src2 is immediate, src2w is masked by (bit_length - 1).1350Otherwise, if the content of src2 is outside the range from 01351to bit_length - 1, the result is undefined. */1352#define SLJIT_LSHR (SLJIT_OP2_BASE + 10)1353#define SLJIT_LSHR32 (SLJIT_LSHR | SLJIT_32)1354/* Flags: Z1355Same as SLJIT_LSHR, except the the second operand is1356always masked by the length of the shift operation. */1357#define SLJIT_MLSHR (SLJIT_OP2_BASE + 11)1358#define SLJIT_MLSHR32 (SLJIT_MLSHR | SLJIT_32)1359/* Flags: Z1360Let bit_length be the length of the shift operation: 32 or 64.1361If src2 is immediate, src2w is masked by (bit_length - 1).1362Otherwise, if the content of src2 is outside the range from 01363to bit_length - 1, the result is undefined. */1364#define SLJIT_ASHR (SLJIT_OP2_BASE + 12)1365#define SLJIT_ASHR32 (SLJIT_ASHR | SLJIT_32)1366/* Flags: Z1367Same as SLJIT_ASHR, except the the second operand is1368always masked by the length of the shift operation. */1369#define SLJIT_MASHR (SLJIT_OP2_BASE + 13)1370#define SLJIT_MASHR32 (SLJIT_MASHR | SLJIT_32)1371/* Flags: - (may destroy flags)1372Let bit_length be the length of the rotate operation: 32 or 64.1373The second operand is always masked by (bit_length - 1). */1374#define SLJIT_ROTL (SLJIT_OP2_BASE + 14)1375#define SLJIT_ROTL32 (SLJIT_ROTL | SLJIT_32)1376/* Flags: - (may destroy flags)1377Let bit_length be the length of the rotate operation: 32 or 64.1378The second operand is always masked by (bit_length - 1). */1379#define SLJIT_ROTR (SLJIT_OP2_BASE + 15)1380#define SLJIT_ROTR32 (SLJIT_ROTR | SLJIT_32)13811382SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,1383sljit_s32 dst, sljit_sw dstw,1384sljit_s32 src1, sljit_sw src1w,1385sljit_s32 src2, sljit_sw src2w);13861387/* The sljit_emit_op2u function is the same as sljit_emit_op21388except the result is discarded. */13891390SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,1391sljit_s32 src1, sljit_sw src1w,1392sljit_s32 src2, sljit_sw src2w);13931394/* Starting index of opcodes for sljit_emit_op2r. */1395#define SLJIT_OP2R_BASE 9613961397/* Flags: - (may destroy flags) */1398#define SLJIT_MULADD (SLJIT_OP2R_BASE + 0)1399#define SLJIT_MULADD32 (SLJIT_MULADD | SLJIT_32)14001401/* Similar to sljit_emit_fop2, except the destination is always a register. */1402SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2r(struct sljit_compiler *compiler, sljit_s32 op,1403sljit_s32 dst_reg,1404sljit_s32 src1, sljit_sw src1w,1405sljit_s32 src2, sljit_sw src2w);14061407/* Emit a left or right shift operation, where the bits shifted1408in comes from a separate source operand. All operands are1409interpreted as unsigned integers.14101411In the followings the value_mask variable is 31 for 32 bit1412operations and word_size - 1 otherwise.14131414op must be one of the following operations:1415SLJIT_SHL or SLJIT_SHL32:1416dst_reg = src1_reg << src3_reg1417dst_reg |= ((src2_reg >> 1) >> (src3 ^ value_mask))1418SLJIT_MSHL or SLJIT_MSHL32:1419src3 &= value_mask1420perform the SLJIT_SHL or SLJIT_SHL32 operation1421SLJIT_LSHR or SLJIT_LSHR32:1422dst_reg = src1_reg >> src3_reg1423dst_reg |= ((src2_reg << 1) << (src3 ^ value_mask))1424SLJIT_MLSHR or SLJIT_MLSHR32:1425src3 &= value_mask1426perform the SLJIT_LSHR or SLJIT_LSHR32 operation14271428op can be combined (or'ed) with SLJIT_SHIFT_INTO_NON_ZERO14291430dst_reg specifies the destination register, where dst_reg1431and src2_reg cannot be the same registers1432src1_reg specifies the source register1433src2_reg specifies the register which is shifted into src1_reg1434src3 / src3w contains the shift amount14351436Note: a rotate operation is performed if src1_reg and1437src2_reg are the same registers14381439Flags: - (may destroy flags) */14401441/* The src3 operand contains a non-zero value. Improves1442the generated code on certain architectures, which1443provides a small performance improvement. */1444#define SLJIT_SHIFT_INTO_NON_ZERO 0x20014451446SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler *compiler, sljit_s32 op,1447sljit_s32 dst_reg,1448sljit_s32 src1_reg,1449sljit_s32 src2_reg,1450sljit_s32 src3, sljit_sw src3w);14511452/* Starting index of opcodes for sljit_emit_op_src1453and sljit_emit_op_dst. */1454#define SLJIT_OP_SRC_DST_BASE 11214551456/* Fast return, see SLJIT_FAST_CALL for more details.1457Note: src cannot be an immedate value1458Flags: - (does not modify flags) */1459#define SLJIT_FAST_RETURN (SLJIT_OP_SRC_DST_BASE + 0)1460/* Skip stack frames before fast return.1461Note: src cannot be an immedate value1462Flags: may destroy flags. */1463#define SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN (SLJIT_OP_SRC_DST_BASE + 1)1464/* Prefetch value into the level 1 data cache1465Note: if the target CPU does not support data prefetch,1466no instructions are emitted.1467Note: this instruction never fails, even if the memory address is invalid.1468Flags: - (does not modify flags) */1469#define SLJIT_PREFETCH_L1 (SLJIT_OP_SRC_DST_BASE + 2)1470/* Prefetch value into the level 2 data cache1471Note: same as SLJIT_PREFETCH_L1 if the target CPU1472does not support this instruction form.1473Note: this instruction never fails, even if the memory address is invalid.1474Flags: - (does not modify flags) */1475#define SLJIT_PREFETCH_L2 (SLJIT_OP_SRC_DST_BASE + 3)1476/* Prefetch value into the level 3 data cache1477Note: same as SLJIT_PREFETCH_L2 if the target CPU1478does not support this instruction form.1479Note: this instruction never fails, even if the memory address is invalid.1480Flags: - (does not modify flags) */1481#define SLJIT_PREFETCH_L3 (SLJIT_OP_SRC_DST_BASE + 4)1482/* Prefetch a value which is only used once (and can be discarded afterwards)1483Note: same as SLJIT_PREFETCH_L1 if the target CPU1484does not support this instruction form.1485Note: this instruction never fails, even if the memory address is invalid.1486Flags: - (does not modify flags) */1487#define SLJIT_PREFETCH_ONCE (SLJIT_OP_SRC_DST_BASE + 5)14881489SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,1490sljit_s32 src, sljit_sw srcw);14911492/* Fast enter, see SLJIT_FAST_CALL for more details.1493Flags: - (does not modify flags) */1494#define SLJIT_FAST_ENTER (SLJIT_OP_SRC_DST_BASE + 6)14951496/* Copies the return address into dst. The return address is the1497address where the execution continues after the called function1498returns (see: sljit_emit_return / sljit_emit_return_void).1499Flags: - (does not modify flags) */1500#define SLJIT_GET_RETURN_ADDRESS (SLJIT_OP_SRC_DST_BASE + 7)15011502SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *compiler, sljit_s32 op,1503sljit_s32 dst, sljit_sw dstw);15041505/* Starting index of opcodes for sljit_emit_fop1. */1506#define SLJIT_FOP1_BASE 14415071508/* Flags: - (does not modify flags) */1509#define SLJIT_MOV_F64 (SLJIT_FOP1_BASE + 0)1510#define SLJIT_MOV_F32 (SLJIT_MOV_F64 | SLJIT_32)1511/* Convert opcodes: CONV[DST_TYPE].FROM[SRC_TYPE]1512SRC/DST TYPE can be: F64, F32, S32, SW1513Rounding mode when the destination is SW or S32: round towards zero. */1514/* Flags: - (may destroy flags) */1515#define SLJIT_CONV_F64_FROM_F32 (SLJIT_FOP1_BASE + 1)1516#define SLJIT_CONV_F32_FROM_F64 (SLJIT_CONV_F64_FROM_F32 | SLJIT_32)1517/* Flags: - (may destroy flags) */1518#define SLJIT_CONV_SW_FROM_F64 (SLJIT_FOP1_BASE + 2)1519#define SLJIT_CONV_SW_FROM_F32 (SLJIT_CONV_SW_FROM_F64 | SLJIT_32)1520/* Flags: - (may destroy flags) */1521#define SLJIT_CONV_S32_FROM_F64 (SLJIT_FOP1_BASE + 3)1522#define SLJIT_CONV_S32_FROM_F32 (SLJIT_CONV_S32_FROM_F64 | SLJIT_32)1523/* Flags: - (may destroy flags) */1524#define SLJIT_CONV_F64_FROM_SW (SLJIT_FOP1_BASE + 4)1525#define SLJIT_CONV_F32_FROM_SW (SLJIT_CONV_F64_FROM_SW | SLJIT_32)1526/* Flags: - (may destroy flags) */1527#define SLJIT_CONV_F64_FROM_S32 (SLJIT_FOP1_BASE + 5)1528#define SLJIT_CONV_F32_FROM_S32 (SLJIT_CONV_F64_FROM_S32 | SLJIT_32)1529/* Flags: - (may destroy flags) */1530#define SLJIT_CONV_F64_FROM_UW (SLJIT_FOP1_BASE + 6)1531#define SLJIT_CONV_F32_FROM_UW (SLJIT_CONV_F64_FROM_UW | SLJIT_32)1532/* Flags: - (may destroy flags) */1533#define SLJIT_CONV_F64_FROM_U32 (SLJIT_FOP1_BASE + 7)1534#define SLJIT_CONV_F32_FROM_U32 (SLJIT_CONV_F64_FROM_U32 | SLJIT_32)1535/* Note: dst is the left and src is the right operand for SLJIT_CMP_F32/64.1536Flags: EQUAL_F | LESS_F | GREATER_EQUAL_F | GREATER_F | LESS_EQUAL_F */1537#define SLJIT_CMP_F64 (SLJIT_FOP1_BASE + 8)1538#define SLJIT_CMP_F32 (SLJIT_CMP_F64 | SLJIT_32)1539/* Flags: - (may destroy flags) */1540#define SLJIT_NEG_F64 (SLJIT_FOP1_BASE + 9)1541#define SLJIT_NEG_F32 (SLJIT_NEG_F64 | SLJIT_32)1542/* Flags: - (may destroy flags) */1543#define SLJIT_ABS_F64 (SLJIT_FOP1_BASE + 10)1544#define SLJIT_ABS_F32 (SLJIT_ABS_F64 | SLJIT_32)15451546SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,1547sljit_s32 dst, sljit_sw dstw,1548sljit_s32 src, sljit_sw srcw);15491550/* Starting index of opcodes for sljit_emit_fop2. */1551#define SLJIT_FOP2_BASE 17615521553/* Flags: - (may destroy flags) */1554#define SLJIT_ADD_F64 (SLJIT_FOP2_BASE + 0)1555#define SLJIT_ADD_F32 (SLJIT_ADD_F64 | SLJIT_32)1556/* Flags: - (may destroy flags) */1557#define SLJIT_SUB_F64 (SLJIT_FOP2_BASE + 1)1558#define SLJIT_SUB_F32 (SLJIT_SUB_F64 | SLJIT_32)1559/* Flags: - (may destroy flags) */1560#define SLJIT_MUL_F64 (SLJIT_FOP2_BASE + 2)1561#define SLJIT_MUL_F32 (SLJIT_MUL_F64 | SLJIT_32)1562/* Flags: - (may destroy flags) */1563#define SLJIT_DIV_F64 (SLJIT_FOP2_BASE + 3)1564#define SLJIT_DIV_F32 (SLJIT_DIV_F64 | SLJIT_32)15651566SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,1567sljit_s32 dst, sljit_sw dstw,1568sljit_s32 src1, sljit_sw src1w,1569sljit_s32 src2, sljit_sw src2w);15701571/* Starting index of opcodes for sljit_emit_fop2r. */1572#define SLJIT_FOP2R_BASE 19215731574/* Flags: - (may destroy flags) */1575#define SLJIT_COPYSIGN_F64 (SLJIT_FOP2R_BASE + 0)1576#define SLJIT_COPYSIGN_F32 (SLJIT_COPYSIGN_F64 | SLJIT_32)15771578/* Similar to sljit_emit_fop2, except the destination is always a register. */1579SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2r(struct sljit_compiler *compiler, sljit_s32 op,1580sljit_s32 dst_freg,1581sljit_s32 src1, sljit_sw src1w,1582sljit_s32 src2, sljit_sw src2w);15831584/* Sets a floating point register to an immediate value. */15851586SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset32(struct sljit_compiler *compiler,1587sljit_s32 freg, sljit_f32 value);1588SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset64(struct sljit_compiler *compiler,1589sljit_s32 freg, sljit_f64 value);15901591/* The following opcodes are used by sljit_emit_fcopy(). */15921593/* 64 bit: copy a 64 bit value from an integer register into a159464 bit floating point register without any modifications.159532 bit: copy a 32 bit register or register pair into a 64 bit1596floating point register without any modifications. The1597register, or the first register of the register pair1598replaces the high order 32 bit of the floating point1599register. If a register pair is passed, the low1600order 32 bit is replaced by the second register.1601Otherwise, the low order 32 bit is unchanged. */1602#define SLJIT_COPY_TO_F64 11603/* Copy a 32 bit value from an integer register into a 32 bit1604floating point register without any modifications. */1605#define SLJIT_COPY32_TO_F32 (SLJIT_COPY_TO_F64 | SLJIT_32)1606/* 64 bit: copy the value of a 64 bit floating point register into1607an integer register without any modifications.160832 bit: copy a 64 bit floating point register into a 32 bit register1609or a 32 bit register pair without any modifications. The1610high order 32 bit of the floating point register is copied1611into the register, or the first register of the register1612pair. If a register pair is passed, the low order 32 bit1613is copied into the second register. */1614#define SLJIT_COPY_FROM_F64 21615/* Copy the value of a 32 bit floating point register into an integer1616register without any modifications. The register should be processed1617with 32 bit operations later. */1618#define SLJIT_COPY32_FROM_F32 (SLJIT_COPY_FROM_F64 | SLJIT_32)16191620/* Special data copy which involves floating point registers.16211622op must be between SLJIT_COPY_TO_F64 and SLJIT_COPY32_FROM_F321623freg must be a floating point register1624reg must be a register or register pair */16251626SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fcopy(struct sljit_compiler *compiler, sljit_s32 op,1627sljit_s32 freg, sljit_s32 reg);16281629/* Label and jump instructions. */16301631SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler);16321633/* The SLJIT_FAST_CALL is a calling method for creating lightweight function1634calls. This type of calls preserve the values of all registers and stack1635frame. Unlike normal function calls, the enter and return operations must1636be performed by the SLJIT_FAST_ENTER and SLJIT_FAST_RETURN operations1637respectively. The return address is stored in the dst argument of the1638SLJIT_FAST_ENTER operation, and this return address should be passed as1639the src argument for the SLJIT_FAST_RETURN operation to return from the1640called function.16411642Fast calls are cheap operations (usually only a single call instruction is1643emitted) but they do not preserve any registers. However the callee function1644can freely use / update any registers and the locals area which can be1645efficiently exploited by various optimizations. Registers can be saved1646and restored manually if needed.16471648Although returning to different address by SLJIT_FAST_RETURN is possible,1649this address usually cannot be predicted by the return address predictor of1650modern CPUs which may reduce performance. Furthermore certain security1651enhancement technologies such as Intel Control-flow Enforcement Technology1652(CET) may disallow returning to a different address (indirect jumps1653can be used instead, see SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN). */16541655/* Invert (negate) conditional type: xor (^) with 0x1 */16561657/* Integer comparison types. */1658#define SLJIT_EQUAL 01659#define SLJIT_ZERO SLJIT_EQUAL1660#define SLJIT_NOT_EQUAL 11661#define SLJIT_NOT_ZERO SLJIT_NOT_EQUAL16621663#define SLJIT_LESS 21664#define SLJIT_SET_LESS SLJIT_SET(SLJIT_LESS)1665#define SLJIT_GREATER_EQUAL 31666#define SLJIT_SET_GREATER_EQUAL SLJIT_SET(SLJIT_LESS)1667#define SLJIT_GREATER 41668#define SLJIT_SET_GREATER SLJIT_SET(SLJIT_GREATER)1669#define SLJIT_LESS_EQUAL 51670#define SLJIT_SET_LESS_EQUAL SLJIT_SET(SLJIT_GREATER)1671#define SLJIT_SIG_LESS 61672#define SLJIT_SET_SIG_LESS SLJIT_SET(SLJIT_SIG_LESS)1673#define SLJIT_SIG_GREATER_EQUAL 71674#define SLJIT_SET_SIG_GREATER_EQUAL SLJIT_SET(SLJIT_SIG_LESS)1675#define SLJIT_SIG_GREATER 81676#define SLJIT_SET_SIG_GREATER SLJIT_SET(SLJIT_SIG_GREATER)1677#define SLJIT_SIG_LESS_EQUAL 91678#define SLJIT_SET_SIG_LESS_EQUAL SLJIT_SET(SLJIT_SIG_GREATER)16791680#define SLJIT_OVERFLOW 101681#define SLJIT_SET_OVERFLOW SLJIT_SET(SLJIT_OVERFLOW)1682#define SLJIT_NOT_OVERFLOW 1116831684/* Unlike other flags, sljit_emit_jump may destroy the carry flag. */1685#define SLJIT_CARRY 121686#define SLJIT_SET_CARRY SLJIT_SET(SLJIT_CARRY)1687#define SLJIT_NOT_CARRY 1316881689#define SLJIT_ATOMIC_STORED 141690#define SLJIT_SET_ATOMIC_STORED SLJIT_SET(SLJIT_ATOMIC_STORED)1691#define SLJIT_ATOMIC_NOT_STORED 1516921693/* Basic floating point comparison types.16941695Note: when the comparison result is unordered, their behaviour is unspecified. */16961697#define SLJIT_F_EQUAL 161698#define SLJIT_SET_F_EQUAL SLJIT_SET(SLJIT_F_EQUAL)1699#define SLJIT_F_NOT_EQUAL 171700#define SLJIT_SET_F_NOT_EQUAL SLJIT_SET(SLJIT_F_EQUAL)1701#define SLJIT_F_LESS 181702#define SLJIT_SET_F_LESS SLJIT_SET(SLJIT_F_LESS)1703#define SLJIT_F_GREATER_EQUAL 191704#define SLJIT_SET_F_GREATER_EQUAL SLJIT_SET(SLJIT_F_LESS)1705#define SLJIT_F_GREATER 201706#define SLJIT_SET_F_GREATER SLJIT_SET(SLJIT_F_GREATER)1707#define SLJIT_F_LESS_EQUAL 211708#define SLJIT_SET_F_LESS_EQUAL SLJIT_SET(SLJIT_F_GREATER)17091710/* Jumps when either argument contains a NaN value. */1711#define SLJIT_UNORDERED 221712#define SLJIT_SET_UNORDERED SLJIT_SET(SLJIT_UNORDERED)1713/* Jumps when neither argument contains a NaN value. */1714#define SLJIT_ORDERED 231715#define SLJIT_SET_ORDERED SLJIT_SET(SLJIT_UNORDERED)17161717/* Ordered / unordered floating point comparison types.17181719Note: each comparison type has an ordered and unordered form. Some1720architectures supports only either of them (see: sljit_cmp_info). */17211722#define SLJIT_ORDERED_EQUAL 241723#define SLJIT_SET_ORDERED_EQUAL SLJIT_SET(SLJIT_ORDERED_EQUAL)1724#define SLJIT_UNORDERED_OR_NOT_EQUAL 251725#define SLJIT_SET_UNORDERED_OR_NOT_EQUAL SLJIT_SET(SLJIT_ORDERED_EQUAL)1726#define SLJIT_ORDERED_LESS 261727#define SLJIT_SET_ORDERED_LESS SLJIT_SET(SLJIT_ORDERED_LESS)1728#define SLJIT_UNORDERED_OR_GREATER_EQUAL 271729#define SLJIT_SET_UNORDERED_OR_GREATER_EQUAL SLJIT_SET(SLJIT_ORDERED_LESS)1730#define SLJIT_ORDERED_GREATER 281731#define SLJIT_SET_ORDERED_GREATER SLJIT_SET(SLJIT_ORDERED_GREATER)1732#define SLJIT_UNORDERED_OR_LESS_EQUAL 291733#define SLJIT_SET_UNORDERED_OR_LESS_EQUAL SLJIT_SET(SLJIT_ORDERED_GREATER)17341735#define SLJIT_UNORDERED_OR_EQUAL 301736#define SLJIT_SET_UNORDERED_OR_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_EQUAL)1737#define SLJIT_ORDERED_NOT_EQUAL 311738#define SLJIT_SET_ORDERED_NOT_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_EQUAL)1739#define SLJIT_UNORDERED_OR_LESS 321740#define SLJIT_SET_UNORDERED_OR_LESS SLJIT_SET(SLJIT_UNORDERED_OR_LESS)1741#define SLJIT_ORDERED_GREATER_EQUAL 331742#define SLJIT_SET_ORDERED_GREATER_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_LESS)1743#define SLJIT_UNORDERED_OR_GREATER 341744#define SLJIT_SET_UNORDERED_OR_GREATER SLJIT_SET(SLJIT_UNORDERED_OR_GREATER)1745#define SLJIT_ORDERED_LESS_EQUAL 351746#define SLJIT_SET_ORDERED_LESS_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_GREATER)17471748/* Unconditional jump types. */1749#define SLJIT_JUMP 361750/* Fast calling method. See the description above. */1751#define SLJIT_FAST_CALL 371752/* Default C calling convention. */1753#define SLJIT_CALL 381754/* Called function must be compiled by SLJIT.1755See SLJIT_ENTER_REG_ARG option. */1756#define SLJIT_CALL_REG_ARG 3917571758/* The target can be changed during runtime (see: sljit_set_jump_addr). */1759#define SLJIT_REWRITABLE_JUMP 0x10001760/* When this flag is passed, the execution of the current function ends and1761the called function returns to the caller of the current function. The1762stack usage is reduced before the call, but it is not necessarily reduced1763to zero. In the latter case the compiler needs to allocate space for some1764arguments and the return address must be stored on the stack as well. */1765#define SLJIT_CALL_RETURN 0x200017661767/* Emit a jump instruction. The destination is not set, only the type of the jump.1768type must be between SLJIT_EQUAL and SLJIT_FAST_CALL1769type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP17701771Flags: does not modify flags. */1772SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type);17731774/* Emit a C compiler (ABI) compatible function call.1775type must be SLJIT_CALL or SLJIT_CALL_REG_ARG1776type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP and/or SLJIT_CALL_RETURN1777arg_types can be specified by SLJIT_ARGSx (SLJIT_ARG_RETURN / SLJIT_ARG_VALUE) macros17781779Flags: destroy all flags. */1780SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 arg_types);17811782/* Basic arithmetic comparison. In most architectures it is implemented as1783a compare operation followed by a sljit_emit_jump. However some1784architectures (i.e: ARM64 or MIPS) may employ special optimizations1785here. It is suggested to use this comparison form when appropriate.1786type must be between SLJIT_EQUAL and SLJIT_SIG_LESS_EQUAL1787type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP17881789Flags: may destroy flags. */1790SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,1791sljit_s32 src1, sljit_sw src1w,1792sljit_s32 src2, sljit_sw src2w);17931794/* Basic floating point comparison. In most architectures it is implemented as1795a SLJIT_CMP_F32/64 operation (setting appropriate flags) followed by a1796sljit_emit_jump. However some architectures (i.e: MIPS) may employ1797special optimizations here. It is suggested to use this comparison form1798when appropriate.1799type must be between SLJIT_F_EQUAL and SLJIT_ORDERED_LESS_EQUAL1800type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP1801Flags: destroy flags.1802Note: when an operand is NaN the behaviour depends on the comparison type. */1803SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,1804sljit_s32 src1, sljit_sw src1w,1805sljit_s32 src2, sljit_sw src2w);18061807/* Set the destination of the jump to this label. */1808SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label);1809/* Set the destination address of the jump to this label. */1810SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target);18111812/* Emit an indirect jump or fast call.1813Direct form: set src to SLJIT_IMM() and srcw to the address1814Indirect form: any other valid addressing mode1815type must be between SLJIT_JUMP and SLJIT_FAST_CALL18161817Flags: does not modify flags. */1818SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw);18191820/* Emit a C compiler (ABI) compatible function call.1821Direct form: set src to SLJIT_IMM() and srcw to the address1822Indirect form: any other valid addressing mode1823type must be SLJIT_CALL or SLJIT_CALL_REG_ARG1824type can be combined (or'ed) with SLJIT_CALL_RETURN1825arg_types can be specified by SLJIT_ARGSx (SLJIT_ARG_RETURN / SLJIT_ARG_VALUE) macros18261827Flags: destroy all flags. */1828SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 arg_types, sljit_s32 src, sljit_sw srcw);18291830/* Perform an operation using the conditional flags as the second argument.1831Type must always be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL.1832The value represented by the type is 1, if the condition represented1833by the type is fulfilled, and 0 otherwise.18341835When op is SLJIT_MOV or SLJIT_MOV32:1836Set dst to the value represented by the type (0 or 1).1837Flags: - (does not modify flags)1838When op is SLJIT_AND, SLJIT_AND32, SLJIT_OR, SLJIT_OR32, SLJIT_XOR, or SLJIT_XOR321839Performs the binary operation using dst as the first, and the value1840represented by type as the second argument. Result is written into dst.1841Flags: Z (may destroy flags) */1842SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,1843sljit_s32 dst, sljit_sw dstw,1844sljit_s32 type);18451846/* Emit a conditional select instruction which moves src1 to dst_reg,1847if the condition is satisfied, or src2_reg to dst_reg otherwise.18481849type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL1850type can be combined (or'ed) with SLJIT_32 to move 32 bit1851register values instead of word sized ones1852dst_reg and src2_reg must be valid registers1853src1 must be valid operand18541855Note: if src1 is a memory operand, its value1856might be loaded even if the condition is false.18571858Flags: - (does not modify flags) */1859SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *compiler, sljit_s32 type,1860sljit_s32 dst_reg,1861sljit_s32 src1, sljit_sw src1w,1862sljit_s32 src2_reg);18631864/* Emit a conditional floating point select instruction which moves1865src1 to dst_reg, if the condition is satisfied, or src2_reg to1866dst_reg otherwise.18671868type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL1869type can be combined (or'ed) with SLJIT_32 to move 32 bit1870floating point values instead of 64 bit ones1871dst_freg and src2_freg must be valid floating point registers1872src1 must be valid operand18731874Note: if src1 is a memory operand, its value1875might be loaded even if the condition is false.18761877Flags: - (does not modify flags) */1878SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *compiler, sljit_s32 type,1879sljit_s32 dst_freg,1880sljit_s32 src1, sljit_sw src1w,1881sljit_s32 src2_freg);18821883/* The following flags are used by sljit_emit_mem(), sljit_emit_mem_update(),1884sljit_emit_fmem(), and sljit_emit_fmem_update(). */18851886/* Memory load operation. This is the default. */1887#define SLJIT_MEM_LOAD 0x0000001888/* Memory store operation. */1889#define SLJIT_MEM_STORE 0x00020018901891/* The following flags are used by sljit_emit_mem() and sljit_emit_fmem(). */18921893/* Load or stora data from an unaligned (byte aligned) address. */1894#define SLJIT_MEM_UNALIGNED 0x0004001895/* Load or stora data from a 16 bit aligned address. */1896#define SLJIT_MEM_ALIGNED_16 0x0008001897/* Load or stora data from a 32 bit aligned address. */1898#define SLJIT_MEM_ALIGNED_32 0x00100018991900/* The following flags are used by sljit_emit_mem_update(),1901and sljit_emit_fmem_update(). */19021903/* Base register is updated before the memory access (default). */1904#define SLJIT_MEM_PRE 0x0000001905/* Base register is updated after the memory access. */1906#define SLJIT_MEM_POST 0x00040019071908/* When SLJIT_MEM_SUPP is passed, no instructions are emitted.1909Instead the function returns with SLJIT_SUCCESS if the instruction1910form is supported and SLJIT_ERR_UNSUPPORTED otherwise. This flag1911allows runtime checking of available instruction forms. */1912#define SLJIT_MEM_SUPP 0x00080019131914/* The sljit_emit_mem emits instructions for various memory operations:19151916When SLJIT_MEM_UNALIGNED / SLJIT_MEM_ALIGNED_16 /1917SLJIT_MEM_ALIGNED_32 is set in type argument:1918Emit instructions for unaligned memory loads or stores. When1919SLJIT_UNALIGNED is not defined, the only way to access unaligned1920memory data is using sljit_emit_mem. Otherwise all operations (e.g.1921sljit_emit_op1/2, or sljit_emit_fop1/2) supports unaligned access.1922In general, the performance of unaligned memory accesses are often1923lower than aligned and should be avoided.19241925When a pair of registers is passed in reg argument:1926Emit instructions for moving data between a register pair and1927memory. The register pair can be specified by the SLJIT_REG_PAIR1928macro. The first register is loaded from or stored into the1929location specified by the mem/memw arguments, and the end address1930of this operation is the starting address of the data transfer1931between the second register and memory. The type argument must1932be SLJIT_MOV. The SLJIT_MEM_UNALIGNED / SLJIT_MEM_ALIGNED_*1933options are allowed for this operation.19341935type must be between SLJIT_MOV and SLJIT_MOV_P and can be1936combined (or'ed) with SLJIT_MEM_* flags1937reg is a register or register pair, which is the source or1938destination of the operation1939mem must be a memory operand19401941Flags: - (does not modify flags) */1942SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,1943sljit_s32 reg,1944sljit_s32 mem, sljit_sw memw);19451946/* Emit a single memory load or store with update instruction.1947When the requested instruction form is not supported by the CPU,1948it returns with SLJIT_ERR_UNSUPPORTED instead of emulating the1949instruction. This allows specializing tight loops based on1950the supported instruction forms (see SLJIT_MEM_SUPP flag).1951Absolute address (SLJIT_MEM0) forms are never supported1952and the base (first) register specified by the mem argument1953must not be SLJIT_SP and must also be different from the1954register specified by the reg argument.19551956type must be between SLJIT_MOV and SLJIT_MOV_P and can be1957combined (or'ed) with SLJIT_MEM_* flags1958reg is the source or destination register of the operation1959mem must be a memory operand19601961Flags: - (does not modify flags) */19621963SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type,1964sljit_s32 reg,1965sljit_s32 mem, sljit_sw memw);19661967/* Same as sljit_emit_mem except the followings:19681969Loading or storing a pair of registers is not supported.19701971type must be SLJIT_MOV_F64 or SLJIT_MOV_F32 and can be1972combined (or'ed) with SLJIT_MEM_* flags.1973freg is the source or destination floating point register1974of the operation1975mem must be a memory operand19761977Flags: - (does not modify flags) */19781979SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,1980sljit_s32 freg,1981sljit_s32 mem, sljit_sw memw);19821983/* Same as sljit_emit_mem_update except the followings:19841985type must be SLJIT_MOV_F64 or SLJIT_MOV_F32 and can be1986combined (or'ed) with SLJIT_MEM_* flags1987freg is the source or destination floating point register1988of the operation1989mem must be a memory operand19901991Flags: - (does not modify flags) */19921993SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type,1994sljit_s32 freg,1995sljit_s32 mem, sljit_sw memw);19961997/* The following options are used by several simd operations. */19981999/* Load data into a vector register, this is the default */2000#define SLJIT_SIMD_LOAD 0x0000002001/* Store data from a vector register */2002#define SLJIT_SIMD_STORE 0x0000012003/* The vector register contains floating point values */2004#define SLJIT_SIMD_FLOAT 0x0004002005/* Tests whether the operation is available */2006#define SLJIT_SIMD_TEST 0x0008002007/* Move data to/from a 64 bit (8 byte) long vector register */2008#define SLJIT_SIMD_REG_64 (3 << 12)2009/* Move data to/from a 128 bit (16 byte) long vector register */2010#define SLJIT_SIMD_REG_128 (4 << 12)2011/* Move data to/from a 256 bit (32 byte) long vector register */2012#define SLJIT_SIMD_REG_256 (5 << 12)2013/* Move data to/from a 512 bit (64 byte) long vector register */2014#define SLJIT_SIMD_REG_512 (6 << 12)2015/* Element size is 8 bit long (this is the default), usually cannot be combined with SLJIT_SIMD_FLOAT */2016#define SLJIT_SIMD_ELEM_8 (0 << 18)2017/* Element size is 16 bit long, usually cannot be combined with SLJIT_SIMD_FLOAT */2018#define SLJIT_SIMD_ELEM_16 (1 << 18)2019/* Element size is 32 bit long */2020#define SLJIT_SIMD_ELEM_32 (2 << 18)2021/* Element size is 64 bit long */2022#define SLJIT_SIMD_ELEM_64 (3 << 18)2023/* Element size is 128 bit long */2024#define SLJIT_SIMD_ELEM_128 (4 << 18)2025/* Element size is 256 bit long */2026#define SLJIT_SIMD_ELEM_256 (5 << 18)20272028/* The following options are used by sljit_emit_simd_mov()2029and sljit_emit_simd_op2(). */20302031/* Memory address is unaligned (this is the default) */2032#define SLJIT_SIMD_MEM_UNALIGNED (0 << 24)2033/* Memory address is 16 bit aligned */2034#define SLJIT_SIMD_MEM_ALIGNED_16 (1 << 24)2035/* Memory address is 32 bit aligned */2036#define SLJIT_SIMD_MEM_ALIGNED_32 (2 << 24)2037/* Memory address is 64 bit aligned */2038#define SLJIT_SIMD_MEM_ALIGNED_64 (3 << 24)2039/* Memory address is 128 bit aligned */2040#define SLJIT_SIMD_MEM_ALIGNED_128 (4 << 24)2041/* Memory address is 256 bit aligned */2042#define SLJIT_SIMD_MEM_ALIGNED_256 (5 << 24)2043/* Memory address is 512 bit aligned */2044#define SLJIT_SIMD_MEM_ALIGNED_512 (6 << 24)20452046/* Moves data between a vector register and memory.20472048If the operation is not supported, it returns with2049SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2050it does not emit any instructions.20512052type must be a combination of SLJIT_SIMD_* and2053SLJIT_SIMD_MEM_* options2054vreg is the source or destination vector register2055of the operation2056srcdst must be a memory operand or a vector register20572058Note:2059The alignment and element size must be2060less or equal than vector register size.20612062Flags: - (does not modify flags) */20632064SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_mov(struct sljit_compiler *compiler, sljit_s32 type,2065sljit_s32 vreg,2066sljit_s32 srcdst, sljit_sw srcdstw);20672068/* Replicates a scalar value to all lanes of a vector2069register.20702071If the operation is not supported, it returns with2072SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2073it does not emit any instructions.20742075type must be a combination of SLJIT_SIMD_* options2076except SLJIT_SIMD_STORE.2077vreg is the destination vector register of the operation2078src is the value which is replicated20792080Note:2081The src == SLJIT_IMM and srcw == 0 can be used to2082clear a register even when SLJIT_SIMD_FLOAT is set.20832084Flags: - (does not modify flags) */20852086SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_replicate(struct sljit_compiler *compiler, sljit_s32 type,2087sljit_s32 vreg,2088sljit_s32 src, sljit_sw srcw);20892090/* The following options are used by sljit_emit_simd_lane_mov(). */20912092/* Clear all bits of the simd register before loading the lane. */2093#define SLJIT_SIMD_LANE_ZERO 0x0000022094/* Sign extend the integer value stored from the lane. */2095#define SLJIT_SIMD_LANE_SIGNED 0x00000420962097/* Moves data between a vector register lane and a register or2098memory. If the srcdst argument is a register, it must be2099a floating point register when SLJIT_SIMD_FLOAT is specified,2100or a general purpose register otherwise.21012102If the operation is not supported, it returns with2103SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2104it does not emit any instructions.21052106type must be a combination of SLJIT_SIMD_* options2107Further options:2108SLJIT_32 - when SLJIT_SIMD_FLOAT is not set2109SLJIT_SIMD_LANE_SIGNED - when SLJIT_SIMD_STORE2110is set and SLJIT_SIMD_FLOAT is not set2111SLJIT_SIMD_LANE_ZERO - when SLJIT_SIMD_LOAD2112is specified2113vreg is the source or destination vector register2114of the operation2115lane_index is the index of the lane2116srcdst is the destination operand for loads, and2117source operand for stores21182119Note:2120The elem size must be lower than register size.21212122Flags: - (does not modify flags) */21232124SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_mov(struct sljit_compiler *compiler, sljit_s32 type,2125sljit_s32 vreg, sljit_s32 lane_index,2126sljit_s32 srcdst, sljit_sw srcdstw);21272128/* Replicates a scalar value from a lane to all lanes2129of a vector register.21302131If the operation is not supported, it returns with2132SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2133it does not emit any instructions.21342135type must be a combination of SLJIT_SIMD_* options2136except SLJIT_SIMD_STORE.2137vreg is the destination vector register of the operation2138src is the vector register which lane is replicated2139src_lane_index is the lane index of the src register21402141Flags: - (does not modify flags) */21422143SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_replicate(struct sljit_compiler *compiler, sljit_s32 type,2144sljit_s32 vreg,2145sljit_s32 src, sljit_s32 src_lane_index);21462147/* The following options are used by sljit_emit_simd_load_extend(). */21482149/* Sign extend the integer elements */2150#define SLJIT_SIMD_EXTEND_SIGNED 0x0000022151/* Extend data to 16 bit */2152#define SLJIT_SIMD_EXTEND_16 (1 << 24)2153/* Extend data to 32 bit */2154#define SLJIT_SIMD_EXTEND_32 (2 << 24)2155/* Extend data to 64 bit */2156#define SLJIT_SIMD_EXTEND_64 (3 << 24)21572158/* Extend elements and stores them in a vector register.2159The extension operation increases the size of the2160elements (e.g. from 16 bit to 64 bit). For integer2161values, the extension can be signed or unsigned.21622163If the operation is not supported, it returns with2164SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2165it does not emit any instructions.21662167type must be a combination of SLJIT_SIMD_*, and2168SLJIT_SIMD_EXTEND_* options except SLJIT_SIMD_STORE2169vreg is the destination vector register of the operation2170src must be a memory operand or a vector register.2171In the latter case, the source elements are stored2172in the lower half of the register.21732174Flags: - (does not modify flags) */21752176SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_extend(struct sljit_compiler *compiler, sljit_s32 type,2177sljit_s32 vreg,2178sljit_s32 src, sljit_sw srcw);21792180/* Extract the highest bit (usually the sign bit) from2181each elements of a vector.21822183If the operation is not supported, it returns with2184SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2185it does not emit any instructions.21862187type must be a combination of SLJIT_SIMD_* and SLJIT_322188options except SLJIT_SIMD_LOAD2189vreg is the source vector register of the operation2190dst is the destination operand21912192Flags: - (does not modify flags) */21932194SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *compiler, sljit_s32 type,2195sljit_s32 vreg,2196sljit_s32 dst, sljit_sw dstw);21972198/* The following operations are used by sljit_emit_simd_op2(). */21992200/* Binary 'and' operation */2201#define SLJIT_SIMD_OP2_AND 0x0000012202/* Binary 'or' operation */2203#define SLJIT_SIMD_OP2_OR 0x0000022204/* Binary 'xor' operation */2205#define SLJIT_SIMD_OP2_XOR 0x0000032206/* Shuffle bytes of src1 using the indicies in src2 */2207#define SLJIT_SIMD_OP2_SHUFFLE 0x00000422082209/* Perform simd operations using vector registers.22102211If the operation is not supported, it returns with2212SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2213it does not emit any instructions.22142215type must be a combination of SLJIT_SIMD_*, SLJIT_SIMD_MEM_*2216and SLJIT_SIMD_OP2_* options except SLJIT_SIMD_LOAD2217and SLJIT_SIMD_STORE2218dst_vreg is the destination register of the operation2219src1_vreg is the first source register of the operation2220src2 is the second source operand of the operation22212222Flags: - (does not modify flags) */22232224SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *compiler, sljit_s32 type,2225sljit_s32 dst_vreg, sljit_s32 src1_vreg, sljit_s32 src2, sljit_sw src2w);22262227/* The following operations are used by sljit_emit_atomic_load() and2228sljit_emit_atomic_store() operations. */22292230/* Tests whether the atomic operation is available (does not generate2231any instructions). When a load from is allowed, its corresponding2232store form is allowed and vice versa. */2233#define SLJIT_ATOMIC_TEST 0x100002234/* The compiler must generate compare and swap instruction.2235When this bit is set, calling sljit_emit_atomic_load() is optional. */2236#define SLJIT_ATOMIC_USE_CAS 0x200002237/* The compiler must generate load-acquire and store-release instructions.2238When this bit is set, the temp_reg for sljit_emit_atomic_store is not used. */2239#define SLJIT_ATOMIC_USE_LS 0x4000022402241/* The sljit_emit_atomic_load and sljit_emit_atomic_store operation pair2242can perform an atomic read-modify-write operation. First, an unsigned2243value must be loaded from memory using sljit_emit_atomic_load. Then,2244the updated value must be written back to the same memory location by2245sljit_emit_atomic_store. A thread can only perform a single atomic2246operation at a time.22472248The following conditions must be satisfied, or the operation2249is undefined:2250- the address provided in mem_reg must be divisible by the size of2251the value (only naturally aligned updates are supported)2252- no memory operations are allowed between the load and store operations2253- the memory operation (op) and the base address (stored in mem_reg)2254passed to the load/store operations must be the same (the mem_reg2255can be a different register, only its value must be the same)2256- a store must always follow a load for the same transaction.22572258op must be between SLJIT_MOV and SLJIT_MOV_P2259dst_reg is the register where the data will be loaded into2260mem_reg is the base address of the memory load (it cannot be2261SLJIT_SP or a virtual register on x86-32)22622263Flags: - (does not modify flags) */2264SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_load(struct sljit_compiler *compiler, sljit_s32 op,2265sljit_s32 dst_reg,2266sljit_s32 mem_reg);22672268/* The sljit_emit_atomic_load and sljit_emit_atomic_store operations2269allows performing an atomic read-modify-write operation. See the2270description of sljit_emit_atomic_load.22712272op must be between SLJIT_MOV and SLJIT_MOV_P2273src_reg is the register which value is stored into the memory2274mem_reg is the base address of the memory store (it cannot be2275SLJIT_SP or a virtual register on x86-32)2276temp_reg is a scratch register, which must be initialized with2277the value loaded into the dst_reg during the corresponding2278sljit_emit_atomic_load operation, or the operation is undefined.2279The temp_reg register preserves its value, if the memory store2280is successful. Otherwise, its value is undefined.22812282Flags: ATOMIC_STORED2283if ATOMIC_STORED flag is set, it represents that the memory2284is updated with a new value. Otherwise the memory is unchanged. */2285SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler *compiler, sljit_s32 op,2286sljit_s32 src_reg,2287sljit_s32 mem_reg,2288sljit_s32 temp_reg);22892290/* Copies the base address of SLJIT_SP + offset to dst. The offset can2291represent the starting address of a value in the local data (stack).2292The offset is not limited by the local data limits, it can be any value.2293For example if an array of bytes are stored on the stack from2294offset 0x40, and R0 contains the offset of an array item plus 0x120,2295this item can be changed by two SLJIT instructions:22962297sljit_get_local_base(compiler, SLJIT_R1, 0, 0x40 - 0x120);2298sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0, SLJIT_IMM, 0x5);22992300Flags: - (may destroy flags) */2301SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset);23022303/* Store a value that can be changed runtime (see: sljit_get_const_addr / sljit_set_const)2304Flags: - (does not modify flags) */2305SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value);23062307/* Store the value of a label (see: sljit_set_label / sljit_set_target)2308Flags: - (does not modify flags) */2309SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw);23102311/* Provides the address of label, jump and const instructions after sljit_generate_code2312is called. The returned value is unspecified before the sljit_generate_code call.2313Since these structures are freed by sljit_free_compiler, the addresses must be2314preserved by the user program elsewere. */2315static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->u.addr; }2316static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; }2317static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { return const_->addr; }23182319/* Only the address and executable offset are required to perform dynamic2320code modifications. See sljit_get_executable_offset function. */2321SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset);2322SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset);23232324/* --------------------------------------------------------------------- */2325/* CPU specific functions */2326/* --------------------------------------------------------------------- */23272328/* Types for sljit_get_register_index */23292330/* General purpose (integer) registers. */2331#define SLJIT_GP_REGISTER 02332/* Floating point registers. */2333#define SLJIT_FLOAT_REGISTER 123342335/* The following function is a helper function for sljit_emit_op_custom.2336It returns with the real machine register index ( >=0 ) of any registers.23372338When type is SLJIT_GP_REGISTER:2339reg must be an SLJIT_R(i), SLJIT_S(i), or SLJIT_SP register23402341When type is SLJIT_FLOAT_REGISTER:2342reg must be an SLJIT_FR(i) or SLJIT_FS(i) register23432344When type is SLJIT_SIMD_REG_64 / 128 / 256 / 512 :2345reg must be an SLJIT_FR(i) or SLJIT_FS(i) register23462347Note: it returns with -1 for unknown registers, such as virtual2348registers on x86-32 or unsupported simd registers. */23492350SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 type, sljit_s32 reg);23512352/* Any instruction can be inserted into the instruction stream by2353sljit_emit_op_custom. It has a similar purpose as inline assembly.2354The size parameter must match to the instruction size of the target2355architecture:23562357x86: 0 < size <= 15, the instruction argument can be byte aligned.2358Thumb2: if size == 2, the instruction argument must be 2 byte aligned.2359if size == 4, the instruction argument must be 4 byte aligned.2360s390x: size can be 2, 4, or 6, the instruction argument can be byte aligned.2361Otherwise: size must be 4 and instruction argument must be 4 byte aligned. */23622363SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,2364void *instruction, sljit_u32 size);23652366/* Flags were set by a 32 bit operation. */2367#define SLJIT_CURRENT_FLAGS_32 SLJIT_3223682369/* Flags were set by an ADD or ADDC operations. */2370#define SLJIT_CURRENT_FLAGS_ADD 0x012371/* Flags were set by a SUB, SUBC, or NEG operation. */2372#define SLJIT_CURRENT_FLAGS_SUB 0x0223732374/* Flags were set by sljit_emit_op2u with SLJIT_SUB opcode.2375Must be combined with SLJIT_CURRENT_FLAGS_SUB. */2376#define SLJIT_CURRENT_FLAGS_COMPARE 0x0423772378/* Define the currently available CPU status flags. It is usually used after2379an sljit_emit_label or sljit_emit_op_custom operations to define which CPU2380status flags are available.23812382The current_flags must be a valid combination of SLJIT_SET_* and2383SLJIT_CURRENT_FLAGS_* constants. */23842385SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler,2386sljit_s32 current_flags);23872388/* --------------------------------------------------------------------- */2389/* Serialization functions */2390/* --------------------------------------------------------------------- */23912392/* Label/jump/const enumeration functions. The items in each group2393are enumerated in creation order. Serialization / deserialization2394preserves this order for each group. For example the fifth label2395after deserialization refers to the same machine code location as2396the fifth label before the serialization. */2397static SLJIT_INLINE struct sljit_label *sljit_get_first_label(struct sljit_compiler *compiler) { return compiler->labels; }2398static SLJIT_INLINE struct sljit_jump *sljit_get_first_jump(struct sljit_compiler *compiler) { return compiler->jumps; }2399static SLJIT_INLINE struct sljit_const *sljit_get_first_const(struct sljit_compiler *compiler) { return compiler->consts; }24002401static SLJIT_INLINE struct sljit_label *sljit_get_next_label(struct sljit_label *label) { return label->next; }2402static SLJIT_INLINE struct sljit_jump *sljit_get_next_jump(struct sljit_jump *jump) { return jump->next; }2403static SLJIT_INLINE struct sljit_const *sljit_get_next_const(struct sljit_const *const_) { return const_->next; }24042405/* A number starting from 0 is assigned to each label, which2406represents its creation index. The first label created by the2407compiler has index 0, the second has index 1, the third has2408index 2, and so on. The returned value is unspecified after2409sljit_generate_code() is called. */2410static SLJIT_INLINE sljit_uw sljit_get_label_index(struct sljit_label *label) { return label->u.index; }24112412/* The sljit_jump_has_label() and sljit_jump_has_target() functions2413returns non-zero value if a label or target is set for the jump2414respectively. Both may return with a zero value. The other two2415functions return the value assigned to the jump. */2416SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_label(struct sljit_jump *jump);2417static SLJIT_INLINE struct sljit_label *sljit_jump_get_label(struct sljit_jump *jump) { return jump->u.label; }2418SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_target(struct sljit_jump *jump);2419static SLJIT_INLINE sljit_uw sljit_jump_get_target(struct sljit_jump *jump) { return jump->u.target; }2420SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_is_mov_addr(struct sljit_jump *jump);24212422/* Option bits for sljit_serialize_compiler. */24232424/* When debugging is enabled, the serialized buffer contains2425debugging information unless this option is specified. */2426#define SLJIT_SERIALIZE_IGNORE_DEBUG 0x124272428/* Serialize the internal structure of the compiler into a buffer.2429If the serialization is successful, the returned value is a newly2430allocated buffer which is allocated by the memory allocator assigned2431to the compiler. Otherwise the returned value is NULL. Unlike2432sljit_generate_code(), serialization does not modify the internal2433state of the compiler, so the code generation can be continued.24342435options must be the combination of SLJIT_SERIALIZE_* option bits2436size is an output argument, which is set to the byte size of2437the result buffer if the operation is successful24382439Notes:2440- This function is useful for ahead-of-time compilation (AOT).2441- The returned buffer must be freed later by the caller.2442The SLJIT_FREE() macro is suitable for this purpose:2443SLJIT_FREE(returned_buffer, sljit_get_allocator_data(compiler))2444- Memory allocated by sljit_alloc_memory() is not serialized.2445- The type of the returned buffer is sljit_uw* to emphasize that2446the buffer is word aligned. However, the 'size' output argument2447contains the byte size, so this value is always divisible by2448sizeof(sljit_uw).2449*/2450SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compiler *compiler,2451sljit_s32 options, sljit_uw *size);24522453/* Construct a new compiler instance from a buffer produced by2454sljit_serialize_compiler(). If the operation is successful, the new2455compiler instance is returned. Otherwise the returned value is NULL.24562457buffer points to a word aligned memory data which was2458created by sljit_serialize_compiler()2459size is the byte size of the buffer2460options must be 02461allocator_data specify an allocator specific data, see2462sljit_create_compiler() for further details24632464Notes:2465- Labels assigned to jumps are restored with their2466corresponding label in the label set created by2467the deserializer. Target addresses assigned to2468jumps are also restored. Uninitialized jumps2469remain uninitialized.2470- After the deserialization, sljit_generate_code() does2471not need to be the next operation on the returned2472compiler, the code generation can be continued.2473Even sljit_serialize_compiler() can be called again.2474- When debugging is enabled, a buffers without debug2475information cannot be deserialized.2476*/2477SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit_uw* buffer, sljit_uw size,2478sljit_s32 options, void *allocator_data);24792480/* --------------------------------------------------------------------- */2481/* Miscellaneous utility functions */2482/* --------------------------------------------------------------------- */24832484/* Get the human readable name of the platform. Can be useful on platforms2485like ARM, where ARM and Thumb2 functions can be mixed, and it is useful2486to know the type of the code generator. */2487SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void);24882489/* Portable helper function to get an offset of a member.2490Same as offsetof() macro defined in stddef.h */2491#define SLJIT_OFFSETOF(base, member) ((sljit_sw)(&((base*)0x10)->member) - 0x10)24922493#if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)24942495/* The sljit_stack structure and its manipulation functions provides2496an implementation for a top-down stack. The stack top is stored2497in the end field of the sljit_stack structure and the stack goes2498down to the min_start field, so the memory region reserved for2499this stack is between min_start (inclusive) and end (exclusive)2500fields. However the application can only use the region between2501start (inclusive) and end (exclusive) fields. The sljit_stack_resize2502function can be used to extend this region up to min_start.25032504This feature uses the "address space reserve" feature of modern2505operating systems. Instead of allocating a large memory block2506applications can allocate a small memory region and extend it2507later without moving the content of the memory area. Therefore2508after a successful resize by sljit_stack_resize all pointers into2509this region are still valid.25102511Note:2512this structure may not be supported by all operating systems.2513end and max_limit fields are aligned to PAGE_SIZE bytes (usually25144 Kbyte or more).2515stack should grow in larger steps, e.g. 4Kbyte, 16Kbyte or more. */25162517struct sljit_stack {2518/* User data, anything can be stored here.2519Initialized to the same value as the end field. */2520sljit_u8 *top;2521/* These members are read only. */2522/* End address of the stack */2523sljit_u8 *end;2524/* Current start address of the stack. */2525sljit_u8 *start;2526/* Lowest start address of the stack. */2527sljit_u8 *min_start;2528};25292530/* Allocates a new stack. Returns NULL if unsuccessful.2531Note: see sljit_create_compiler for the explanation of allocator_data. */2532SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_FUNC sljit_allocate_stack(sljit_uw start_size, sljit_uw max_size, void *allocator_data);2533SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_free_stack(struct sljit_stack *stack, void *allocator_data);25342535/* Can be used to increase (extend) or decrease (shrink) the stack2536memory area. Returns with new_start if successful and NULL otherwise.2537It always fails if new_start is less than min_start or greater or equal2538than end fields. The fields of the stack are not changed if the returned2539value is NULL (the current memory content is never lost). */2540SLJIT_API_FUNC_ATTRIBUTE sljit_u8 *SLJIT_FUNC sljit_stack_resize(struct sljit_stack *stack, sljit_u8 *new_start);25412542#endif /* (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) */25432544#if !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)25452546/* Get the entry address of a given function (signed, unsigned result). */2547#define SLJIT_FUNC_ADDR(func_name) ((sljit_sw)func_name)2548#define SLJIT_FUNC_UADDR(func_name) ((sljit_uw)func_name)25492550#else /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */25512552/* All JIT related code should be placed in the same context (library, binary, etc.). */25532554/* Get the entry address of a given function (signed, unsigned result). */2555#define SLJIT_FUNC_ADDR(func_name) (*(sljit_sw*)(void*)func_name)2556#define SLJIT_FUNC_UADDR(func_name) (*(sljit_uw*)(void*)func_name)25572558/* For powerpc64, the function pointers point to a context descriptor. */2559struct sljit_function_context {2560sljit_uw addr;2561sljit_uw r2;2562sljit_uw r11;2563};25642565/* Fill the context arguments using the addr and the function.2566If func_ptr is NULL, it will not be set to the address of context2567If addr is NULL, the function address also comes from the func pointer. */2568SLJIT_API_FUNC_ATTRIBUTE void sljit_set_function_context(void** func_ptr, struct sljit_function_context* context, sljit_uw addr, void* func);25692570#endif /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */25712572#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)2573/* Free unused executable memory. The allocator keeps some free memory2574around to reduce the number of OS executable memory allocations.2575This improves performance since these calls are costly. However2576it is sometimes desired to free all unused memory regions, e.g.2577before the application terminates. */2578SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);2579#endif /* SLJIT_EXECUTABLE_ALLOCATOR */25802581#ifdef __cplusplus2582} /* extern "C" */2583#endif /* __cplusplus */25842585#endif /* SLJIT_LIR_H_ */258625872588