Path: blob/master/thirdparty/pcre2/deps/sljit/sljit_src/sljitLir.h
22438 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_read_only_buffer {506struct sljit_read_only_buffer *next;507sljit_uw size;508/* Label can be replaced by address after sljit_generate_code. */509union {510struct sljit_label *label;511sljit_uw addr;512} u;513};514515struct sljit_compiler {516sljit_s32 error;517sljit_s32 options;518519struct sljit_label *labels;520struct sljit_jump *jumps;521struct sljit_const *consts;522struct sljit_label *last_label;523struct sljit_jump *last_jump;524struct sljit_const *last_const;525526void *allocator_data;527void *user_data;528struct sljit_memory_fragment *buf;529struct sljit_memory_fragment *abuf;530531/* Number of labels created by the compiler. */532sljit_uw label_count;533/* Available scratch registers. */534sljit_s32 scratches;535/* Available saved registers. */536sljit_s32 saveds;537/* Available float scratch registers. */538sljit_s32 fscratches;539/* Available float saved registers. */540sljit_s32 fsaveds;541#if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) \542|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \543|| (defined SLJIT_DEBUG && SLJIT_DEBUG) \544|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)545/* Available vector scratch registers. */546sljit_s32 vscratches;547/* Available vector saved registers. */548sljit_s32 vsaveds;549#endif /* SLJIT_SEPARATE_VECTOR_REGISTERS || SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG || SLJIT_VERBOSE */550/* Local stack size. */551sljit_s32 local_size;552/* Maximum code size. */553sljit_uw size;554/* Relative offset of the executable mapping from the writable mapping. */555sljit_sw executable_offset;556/* Executable size for statistical purposes. */557sljit_uw executable_size;558559#if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)560sljit_s32 status_flags_state;561#endif /* SLJIT_HAS_STATUS_FLAGS_STATE */562563#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)564sljit_s32 args_size;565#endif /* SLJIT_CONFIG_X86_32 */566567#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)568/* Temporary fields. */569sljit_s32 mode32;570#endif /* SLJIT_CONFIG_X86_64 */571572#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6)573/* Constant pool handling. */574sljit_uw *cpool;575sljit_u8 *cpool_unique;576sljit_uw cpool_diff;577sljit_uw cpool_fill;578/* Other members. */579/* Contains pointer, "ldr pc, [...]" pairs. */580sljit_uw patches;581#endif /* SLJIT_CONFIG_ARM_V6 */582583#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)584/* Temporary fields. */585sljit_uw shift_imm;586#endif /* SLJIT_CONFIG_ARM_V6 || SLJIT_CONFIG_ARM_V6 */587588#if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && (defined __SOFTFP__)589sljit_uw args_size;590#endif /* SLJIT_CONFIG_ARM_32 && __SOFTFP__ */591592#if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)593/* Temporary fields. */594sljit_u32 imm;595#endif /* SLJIT_CONFIG_PPC */596597#if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)598sljit_s32 delay_slot;599/* Temporary fields. */600sljit_s32 cache_arg;601sljit_sw cache_argw;602#endif /* SLJIT_CONFIG_MIPS */603604#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)605sljit_uw args_size;606#endif /* SLJIT_CONFIG_MIPS_32 */607608#if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)609/* Temporary fields. */610sljit_s32 cache_arg;611sljit_sw cache_argw;612#endif /* SLJIT_CONFIG_RISCV */613614#if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)615/* Need to allocate register save area to make calls. */616/* Temporary fields. */617sljit_s32 mode;618#endif /* SLJIT_CONFIG_S390X */619620#if (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH)621/* Temporary fields. */622sljit_s32 cache_arg;623sljit_sw cache_argw;624#endif /* SLJIT_CONFIG_LOONGARCH */625626#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)627FILE* verbose;628#endif /* SLJIT_VERBOSE */629630/* Note: SLJIT_DEBUG enables SLJIT_ARGUMENT_CHECKS. */631#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \632|| (defined SLJIT_DEBUG && SLJIT_DEBUG)633/* Flags specified by the last arithmetic instruction.634It contains the type of the variable flag. */635sljit_s32 last_flags;636/* Return value type set by entry functions. */637sljit_s32 last_return;638/* Local size passed to entry functions. */639sljit_s32 logical_local_size;640#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */641642#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \643|| (defined SLJIT_DEBUG && SLJIT_DEBUG) \644|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)645#if !(defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS)646/* Available float scratch registers. */647sljit_s32 real_fscratches;648/* Available float saved registers. */649sljit_s32 real_fsaveds;650#endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */651652/* Trust arguments when an API function is called.653Used internally for calling API functions. */654sljit_s32 skip_checks;655#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG || SLJIT_VERBOSE */656};657658/* --------------------------------------------------------------------- */659/* Main functions */660/* --------------------------------------------------------------------- */661662/* Creates an SLJIT compiler. The allocator_data is required by some663custom memory managers. This pointer is passed to SLJIT_MALLOC664and SLJIT_FREE macros. Most allocators (including the default665one) ignores this value, and it is recommended to pass NULL666as a dummy value for allocator_data.667668Returns NULL if failed. */669SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data);670671/* Frees everything except the compiled machine code. */672SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler);673674/* Returns the current error code. If an error occurres, future calls675which uses the same compiler argument returns early with the same676error code. Thus there is no need for checking the error after every677call, it is enough to do it after the code is compiled. Removing678these checks increases the performance of the compiling process. */679static SLJIT_INLINE sljit_s32 sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; }680681/* Sets the compiler error code to SLJIT_ERR_ALLOC_FAILED except682if an error was detected before. After the error code is set683the compiler behaves as if the allocation failure happened684during an SLJIT function call. This can greatly simplify error685checking, since it is enough to check the compiler status686after the code is compiled. */687SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler);688689/* Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit,690and <= 128 bytes on 64 bit architectures. The memory area is owned by the691compiler, and freed by sljit_free_compiler. The returned pointer is692sizeof(sljit_sw) aligned. Excellent for allocating small blocks during693compiling, and no need to worry about freeing them. The size is enough694to contain at most 16 pointers. If the size is outside of the range,695the function will return with NULL. However, this return value does not696indicate that there is no more memory (does not set the current error code697of the compiler to out-of-memory status). */698SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size);699700/* Returns the allocator data passed to sljit_create_compiler. */701static SLJIT_INLINE void* sljit_compiler_get_allocator_data(struct sljit_compiler *compiler) { return compiler->allocator_data; }702/* Sets/get the user data for a compiler. */703static SLJIT_INLINE void sljit_compiler_set_user_data(struct sljit_compiler *compiler, void *user_data) { compiler->user_data = user_data; }704static SLJIT_INLINE void* sljit_compiler_get_user_data(struct sljit_compiler *compiler) { return compiler->user_data; }705706#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)707/* Passing NULL disables verbose. */708SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose);709#endif /* SLJIT_VERBOSE */710711/* Option bits for sljit_generate_code. */712713/* The exec_allocator_data points to a pre-allocated714buffer which type is sljit_generate_code_buffer. */715#define SLJIT_GENERATE_CODE_BUFFER 0x1716717/* When SLJIT_INDIRECT_CALL is defined, no function context is718created for the generated code (see sljit_set_function_context),719so the returned pointer cannot be directly called from C code.720The flag is ignored when SLJIT_INDIRECT_CALL is not defined. */721#define SLJIT_GENERATE_CODE_NO_CONTEXT 0x2722723/* Create executable code from the instruction stream. This is the final step724of the code generation, and no more instructions can be emitted after this call.725726options is the combination of SLJIT_GENERATE_CODE_* bits727exec_allocator_data is passed to SLJIT_MALLOC_EXEC and728SLJIT_MALLOC_FREE functions */729730SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options, void *exec_allocator_data);731732/* Free executable code. */733734SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data);735736/* When the protected executable allocator is used the JIT code is mapped737twice. The first mapping has read/write and the second mapping has read/exec738permissions. This function returns with the relative offset of the executable739mapping using the writable mapping as the base after the machine code is740successfully generated. The returned value is always 0 for the normal executable741allocator, since it uses only one mapping with read/write/exec permissions.742Dynamic code modifications requires this value.743744Before a successful code generation, this function returns with 0. */745static SLJIT_INLINE sljit_sw sljit_get_executable_offset(struct sljit_compiler *compiler) { return compiler->executable_offset; }746747/* The executable memory consumption of the generated code can be retrieved by748this function. The returned value can be used for statistical purposes.749750Before a successful code generation, this function returns with 0. */751static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; }752753/* Returns with non-zero if the feature or limitation type passed as its754argument is present on the current CPU. The return value is one, if a755feature is fully supported, and it is two, if partially supported.756757Some features (e.g. floating point operations) require hardware (CPU)758support while others (e.g. move with update) are emulated if not available.759However, even when a feature is emulated, specialized code paths may be760faster than the emulation. Some limitations are emulated as well so their761general case is supported but it has extra performance costs.762763Note: sljitConfigInternal.h also provides several feature detection macros. */764765/* [Not emulated] Floating-point support is available. */766#define SLJIT_HAS_FPU 0767/* [Limitation] Some registers are virtual registers. */768#define SLJIT_HAS_VIRTUAL_REGISTERS 1769/* [Emulated] Has zero register (setting a memory location to zero is efficient). */770#define SLJIT_HAS_ZERO_REGISTER 2771/* [Emulated] Count leading zero is supported. */772#define SLJIT_HAS_CLZ 3773/* [Emulated] Count trailing zero is supported. */774#define SLJIT_HAS_CTZ 4775/* [Emulated] Reverse the order of bytes is supported. */776#define SLJIT_HAS_REV 5777/* [Emulated] Rotate left/right is supported. */778#define SLJIT_HAS_ROT 6779/* [Emulated] Conditional move is supported. */780#define SLJIT_HAS_CMOV 7781/* [Emulated] Prefetch instruction is available (emulated as a nop). */782#define SLJIT_HAS_PREFETCH 8783/* [Emulated] Copy from/to f32 operation is available (see sljit_emit_fcopy). */784#define SLJIT_HAS_COPY_F32 9785/* [Emulated] Copy from/to f64 operation is available (see sljit_emit_fcopy). */786#define SLJIT_HAS_COPY_F64 10787/* [Not emulated] The 64 bit floating point registers can be used as788two separate 32 bit floating point registers (e.g. ARM32). The789second 32 bit part can be accessed by SLJIT_F64_SECOND. */790#define SLJIT_HAS_F64_AS_F32_PAIR 11791/* [Not emulated] Some SIMD operations are supported by the compiler. */792#define SLJIT_HAS_SIMD 12793/* [Not emulated] SIMD registers are mapped to a pair of double precision794floating point registers. E.g. passing either SLJIT_FR0 or SLJIT_FR1 to795a simd operation represents the same 128 bit register, and both SLJIT_FR0796and SLJIT_FR1 are overwritten. */797#define SLJIT_SIMD_REGS_ARE_PAIRS 13798/* [Not emulated] Atomic support is available. */799#define SLJIT_HAS_ATOMIC 14800/* [Not emulated] Memory barrier support is available. */801#define SLJIT_HAS_MEMORY_BARRIER 15802803#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)804/* [Not emulated] AVX support is available on x86. */805#define SLJIT_HAS_AVX 100806/* [Not emulated] AVX2 support is available on x86. */807#define SLJIT_HAS_AVX2 101808#endif /* SLJIT_CONFIG_X86 */809810#if (defined SLJIT_CONFIG_LOONGARCH)811/* [Not emulated] LASX support is available on LoongArch */812#define SLJIT_HAS_LASX 201813#endif /* SLJIT_CONFIG_LOONGARCH */814815SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type);816817/* If type is between SLJIT_ORDERED_EQUAL and SLJIT_ORDERED_LESS_EQUAL,818sljit_cmp_info returns with:819zero - if the cpu supports the floating point comparison type820one - if the comparison requires two machine instructions821two - if the comparison requires more than two machine instructions822823When the result is non-zero, it is recommended to avoid824using the specified comparison type if it is easy to do so.825826Otherwise it returns zero. */827SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type);828829/* The following functions generate machine code. If there is no830error, they return with SLJIT_SUCCESS, otherwise they return831with an error code. */832833/*834The executable code is a callable function from the viewpoint835of the C language. Function calls must conform with the ABI836(Application Binary Interface) of the target platform, which837specify the purpose of machine registers and stack handling838among other things. The sljit_emit_enter function emits the839necessary instructions for setting up an entry point for the840executable code. This is often called as function prologue.841842The "options" argument can be used to pass configuration options843to the sljit compiler which affects the generated code, until844another sljit_emit_enter or sljit_set_context is called. The845available options are listed before sljit_emit_enter.846847The function argument list is specified by the SLJIT_ARGSx848(SLJIT_ARGS0 .. SLJIT_ARGS4) macros. Currently maximum four849arguments are supported. See the description of SLJIT_ARGSx850macros about argument passing.851852The register set used by the function must be declared as well.853The number of scratch and saved registers available to the854function must be passed to sljit_emit_enter. Only R registers855between R0 and "scratches" argument can be used later. E.g.856if "scratches" is set to two, the scratch register set will857be limited to SLJIT_R0 and SLJIT_R1. The S registers are858declared in a similar manner, but their count is specified859by "saveds" argument. The floating point scratch and saved860registers can be set by using "scratches" and "saveds" argument861as well, but their value must be passed to the SLJIT_ENTER_FLOAT862macro, see below.863864The sljit_emit_enter is also capable of allocating a stack865space for local data. The "local_size" argument contains the866size in bytes of this local area, and it can be accessed using867SLJIT_MEM1(SLJIT_SP). The memory area between SLJIT_SP (inclusive)868and SLJIT_SP + local_size (exclusive) can be modified freely869until the function returns. The alocated stack space is an870uninitialized memory area.871872Floating point scratch and saved registers must be specified873by the SLJIT_ENTER_FLOAT macro, which result value should be874combined with scratches / saveds argument.875876Examples:877To use three scratch and four floating point scratch878registers, the "scratches" argument must be set to:8793 | SLJIT_ENTER_FLOAT(4)880881To use six saved and five floating point saved882registers, the "saveds" argument must be set to:8836 | SLJIT_ENTER_FLOAT(5)884885Note: the following conditions must met:8860 <= scratches <= SLJIT_NUMBER_OF_REGISTERS8870 <= saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS888scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS8898900 <= float scratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS8910 <= float saveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS892float scratches + float saveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS893894Note: the compiler can use saved registers as scratch registers,895but the opposite is not supported896897Note: every call of sljit_emit_enter and sljit_set_context898overwrites the previous context.899*/900901/* The following options are available for sljit_emit_enter. */902903/* Saved registers between SLJIT_S0 and SLJIT_S(n - 1) (inclusive)904are not saved / restored on function enter / return. Instead,905these registers can be used to pass / return data (such as906global / local context pointers) across function calls. The907value of n must be between 1 and 3. This option is only908supported by SLJIT_ENTER_REG_ARG calling convention. */909#define SLJIT_ENTER_KEEP(n) (n)910911/* The compiled function uses an SLJIT specific register argument912calling convention. This is a lightweight function call type where913both the caller and the called functions must be compiled by914SLJIT. The type argument of the call must be SLJIT_CALL_REG_ARG915and all arguments must be stored in scratch registers. */916#define SLJIT_ENTER_REG_ARG 0x00000004917918#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)919/* Use VEX prefix for all SIMD operations on x86. */920#define SLJIT_ENTER_USE_VEX 0x00010000921#endif /* !SLJIT_CONFIG_X86 */922923/* Macros for other sljit_emit_enter arguments. */924925/* Floating point scratch and saved registers can be926specified by SLJIT_ENTER_FLOAT. */927#define SLJIT_ENTER_FLOAT(regs) ((regs) << 8)928929/* Vector scratch and saved registers can be specified930by SLJIT_ENTER_VECTOR. */931#define SLJIT_ENTER_VECTOR(regs) ((regs) << 16)932933/* The local_size must be >= 0 and <= SLJIT_MAX_LOCAL_SIZE. */934#define SLJIT_MAX_LOCAL_SIZE 1048576935936SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,937sljit_s32 options, sljit_s32 arg_types,938sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size);939940/* The SLJIT compiler has a current context (which contains the local941stack space size, number of used registers, etc.) which is initialized942by sljit_emit_enter. Several functions (such as sljit_emit_return)943requires this context to be able to generate the appropriate code.944However, some code fragments (compiled separately) may have no945normal entry point so their context is unknown to the compiler.946947sljit_set_context and sljit_emit_enter have the same arguments,948but sljit_set_context does not generate any machine code.949950Note: every call of sljit_emit_enter and sljit_set_context overwrites951the previous context. */952953SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,954sljit_s32 options, sljit_s32 arg_types,955sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size);956957/* Return to the caller function. The sljit_emit_return_void function958does not return with any value. The sljit_emit_return function returns959with a single value loaded from its source operand. The load operation960can be between SLJIT_MOV and SLJIT_MOV_P (see sljit_emit_op1) and961SLJIT_MOV_F32/SLJIT_MOV_F64 (see sljit_emit_fop1) depending on the962return value specified by sljit_emit_enter/sljit_set_context. */963964SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler);965966SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op,967sljit_s32 src, sljit_sw srcw);968969/* Restores the saved registers and free the stack area, then the execution970continues from the address specified by the source operand. This971operation is similar to sljit_emit_return, but it ignores the return972address. The code where the exection continues should use the same context973as the caller function (see sljit_set_context). A word (pointer) value974can be passed in the SLJIT_RETURN_REG register. This function can be used975to jump to exception handlers. */976977SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_to(struct sljit_compiler *compiler,978sljit_s32 src, sljit_sw srcw);979980/*981Source and destination operands for arithmetical instructions982imm - a simple immediate value (cannot be used as a destination)983reg - any of the available registers (immediate argument must be 0)984[imm] - absolute memory address985[reg+imm] - indirect memory address986[reg+(reg<<imm)] - indirect indexed memory address (shift must be between 0 and 3)987useful for accessing arrays (fully supported by both x86 and988ARM architectures, and cheap operation on others)989*/990991/*992IMPORTANT NOTE: memory accesses MUST be naturally aligned unless993SLJIT_UNALIGNED macro is defined and its value is 1.994995length | alignment996---------+-----------997byte | 1 byte (any physical_address is accepted)998half | 2 byte (physical_address & 0x1 == 0)999int | 4 byte (physical_address & 0x3 == 0)1000word | 4 byte if SLJIT_32BIT_ARCHITECTURE is defined and its value is 11001| 8 byte if SLJIT_64BIT_ARCHITECTURE is defined and its value is 11002pointer | size of sljit_up type (4 byte on 32 bit machines, 4 or 8 byte1003| on 64 bit machines)10041005Note: Different architectures have different addressing limitations.1006A single instruction is enough for the following addressing1007modes. Other addressing modes are emulated by instruction1008sequences. This information could help to improve those code1009generators which focuses only a few architectures.10101011x86: [reg+imm], -2^32+1 <= imm <= 2^32-1 (full address space on x86-32)1012[reg+(reg<<imm)] is supported1013[imm], -2^32+1 <= imm <= 2^32-1 is supported1014Write-back is not supported1015arm: [reg+imm], -4095 <= imm <= 4095 or -255 <= imm <= 255 for signed1016bytes, any halfs or floating point values)1017[reg+(reg<<imm)] is supported1018Write-back is supported1019arm-t2: [reg+imm], -255 <= imm <= 40951020[reg+(reg<<imm)] is supported1021Write back is supported only for [reg+imm], where -255 <= imm <= 2551022arm64: [reg+imm], -256 <= imm <= 255, 0 <= aligned imm <= 4095 * alignment1023[reg+(reg<<imm)] is supported1024Write back is supported only for [reg+imm], where -256 <= imm <= 2551025ppc: [reg+imm], -65536 <= imm <= 65535. 64 bit loads/stores and 32 bit1026signed load on 64 bit requires immediates divisible by 4.1027[reg+imm] is not supported for signed 8 bit values.1028[reg+reg] is supported1029Write-back is supported except for one instruction: 32 bit signed1030load with [reg+imm] addressing mode on 64 bit.1031mips: [reg+imm], -65536 <= imm <= 655351032Write-back is not supported1033riscv: [reg+imm], -2048 <= imm <= 20471034Write-back is not supported1035s390x: [reg+imm], -2^19 <= imm < 2^191036[reg+reg] is supported1037Write-back is not supported1038loongarch: [reg+imm], -2048 <= imm <= 20471039[reg+reg] is supported1040Write-back is not supported1041*/10421043/* Macros for specifying operand types. */1044#define SLJIT_MEM 0x801045#define SLJIT_MEM0() (SLJIT_MEM)1046#define SLJIT_MEM1(r1) (SLJIT_MEM | (r1))1047#define SLJIT_MEM2(r1, r2) (SLJIT_MEM | (r1) | ((r2) << 8))1048#define SLJIT_IMM 0x7f1049#define SLJIT_REG_PAIR(r1, r2) ((r1) | ((r2) << 8))10501051/* Macros for checking operand types (only for valid arguments). */1052#define SLJIT_IS_REG(arg) ((arg) > 0 && (arg) < SLJIT_IMM)1053#define SLJIT_IS_MEM(arg) ((arg) & SLJIT_MEM)1054#define SLJIT_IS_MEM0(arg) ((arg) == SLJIT_MEM)1055#define SLJIT_IS_MEM1(arg) ((arg) > SLJIT_MEM && (arg) < (SLJIT_MEM << 1))1056#define SLJIT_IS_MEM2(arg) (((arg) & SLJIT_MEM) && (arg) >= (SLJIT_MEM << 1))1057#define SLJIT_IS_IMM(arg) ((arg) == SLJIT_IMM)1058#define SLJIT_IS_REG_PAIR(arg) (!((arg) & SLJIT_MEM) && (arg) >= (SLJIT_MEM << 1))10591060/* Macros for extracting registers from operands. */1061/* Support operands which contains a single register or1062constructed using SLJIT_MEM1, SLJIT_MEM2, or SLJIT_REG_PAIR. */1063#define SLJIT_EXTRACT_REG(arg) ((arg) & 0x7f)1064/* Support operands which constructed using SLJIT_MEM2, or SLJIT_REG_PAIR. */1065#define SLJIT_EXTRACT_SECOND_REG(arg) ((arg) >> 8)10661067/* Sets 32 bit operation mode on 64 bit CPUs. This option is ignored on106832 bit CPUs. When this option is set for an arithmetic operation, only1069the lower 32 bits of the input registers are used, and the CPU status1070flags are set according to the 32 bit result. Although the higher 32 bit1071of the input and the result registers are not defined by SLJIT, it might1072be defined by the CPU architecture (e.g. MIPS). To satisfy these CPU1073requirements all source registers must be the result of those operations1074where this option was also set. Memory loads read 32 bit values rather1075than 64 bit ones. In other words 32 bit and 64 bit operations cannot be1076mixed. The only exception is SLJIT_MOV32 which source register can hold1077any 32 or 64 bit value, and it is converted to a 32 bit compatible format1078first. When the source and destination registers are the same, this1079conversion is free (no instructions are emitted) on most CPUs. A 32 bit1080value can also be converted to a 64 bit value by SLJIT_MOV_S321081(sign extension) or SLJIT_MOV_U32 (zero extension).10821083As for floating-point operations, this option sets 32 bit single1084precision mode. Similar to the integer operations, all register arguments1085must be the result of those operations where this option was also set.10861087Note: memory addressing always uses 64 bit values on 64 bit systems so1088the result of a 32 bit operation must not be used with SLJIT_MEMx1089macros.10901091This option is part of the instruction name, so there is no need to1092manually set it. E.g:10931094SLJIT_ADD32 == (SLJIT_ADD | SLJIT_32) */1095#define SLJIT_32 0x10010961097/* Many CPUs (x86, ARM, PPC) have status flag bits which can be set according1098to the result of an operation. Other CPUs (MIPS) do not have status1099flag bits, and results must be stored in registers. To cover both1100architecture types efficiently only two flags are defined by SLJIT:11011102* Zero (equal) flag: it is set if the result is zero1103* Variable flag: its value is defined by the arithmetic operation11041105SLJIT instructions can set any or both of these flags. The value of1106these flags is undefined if the instruction does not specify their1107value. The description of each instruction contains the list of1108allowed flag types.11091110Note: the logical or operation can be used to set flags.11111112Example: SLJIT_ADD can set the Z, OVERFLOW, CARRY flags hence11131114sljit_op2(..., SLJIT_ADD, ...)1115Both the zero and variable flags are undefined so they can1116have any value after the operation is completed.11171118sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...)1119Sets the zero flag if the result is zero, clears it otherwise.1120The variable flag is undefined.11211122sljit_op2(..., SLJIT_ADD | SLJIT_SET_OVERFLOW, ...)1123Sets the variable flag if an integer overflow occurs, clears1124it otherwise. The zero flag is undefined.11251126sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_CARRY, ...)1127Sets the zero flag if the result is zero, clears it otherwise.1128Sets the variable flag if unsigned overflow (carry) occurs,1129clears it otherwise.11301131Certain instructions (e.g. SLJIT_MOV) does not modify flags, so1132status flags are unchanged.11331134Example:11351136sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...)1137sljit_op1(..., SLJIT_MOV, ...)1138Zero flag is set according to the result of SLJIT_ADD.11391140sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...)1141sljit_op2(..., SLJIT_ADD, ...)1142Zero flag has unknown value.11431144These flags can be used for code optimization. E.g. a fast loop can be1145implemented by decreasing a counter register and set the zero flag1146using a single instruction. The zero register can be used by a1147conditional jump to restart the loop. A single comparison can set a1148zero and less flags to check if a value is less, equal, or greater1149than another value.11501151Motivation: although some CPUs can set a large number of flag bits,1152usually their values are ignored or only a few of them are used. Emulating1153a large number of flags on systems without a flag register is complicated1154so SLJIT instructions must specify the flag they want to use and only1155that flag is computed. The last arithmetic instruction can be repeated if1156multiple flags need to be checked.1157*/11581159/* Set Zero status flag. */1160#define SLJIT_SET_Z 0x02001161/* Set the variable status flag if condition is true.1162See comparison types (e.g. SLJIT_SET_LESS, SLJIT_SET_F_EQUAL). */1163#define SLJIT_SET(condition) ((condition) << 10)11641165/* Starting index of opcodes for sljit_emit_op0. */1166#define SLJIT_OP0_BASE 011671168/* Flags: - (does not modify flags)1169Note: breakpoint instruction is not supported by all architectures (e.g. ppc)1170It falls back to SLJIT_NOP in those cases. */1171#define SLJIT_BREAKPOINT (SLJIT_OP0_BASE + 0)1172/* Flags: - (does not modify flags)1173Note: may or may not cause an extra cycle wait1174it can even decrease the runtime in a few cases. */1175#define SLJIT_NOP (SLJIT_OP0_BASE + 1)1176/* Flags: - (may destroy flags)1177Unsigned multiplication of SLJIT_R0 and SLJIT_R1.1178Result is placed into SLJIT_R1:SLJIT_R0 (high:low) word */1179#define SLJIT_LMUL_UW (SLJIT_OP0_BASE + 2)1180/* Flags: - (may destroy flags)1181Signed multiplication of SLJIT_R0 and SLJIT_R1.1182Result is placed into SLJIT_R1:SLJIT_R0 (high:low) word */1183#define SLJIT_LMUL_SW (SLJIT_OP0_BASE + 3)1184/* Flags: - (may destroy flags)1185Unsigned divide of the value in SLJIT_R0 by the value in SLJIT_R1.1186The result is placed into SLJIT_R0 and the remainder into SLJIT_R1.1187Note: if SLJIT_R1 is 0, the behaviour is undefined. */1188#define SLJIT_DIVMOD_UW (SLJIT_OP0_BASE + 4)1189#define SLJIT_DIVMOD_U32 (SLJIT_DIVMOD_UW | SLJIT_32)1190/* Flags: - (may destroy flags)1191Signed divide of the value in SLJIT_R0 by the value in SLJIT_R1.1192The result is placed into SLJIT_R0 and the remainder into SLJIT_R1.1193Note: if SLJIT_R1 is 0, the behaviour is undefined.1194Note: if SLJIT_R1 is -1 and SLJIT_R0 is integer min (0x800..00),1195the behaviour is undefined. */1196#define SLJIT_DIVMOD_SW (SLJIT_OP0_BASE + 5)1197#define SLJIT_DIVMOD_S32 (SLJIT_DIVMOD_SW | SLJIT_32)1198/* Flags: - (may destroy flags)1199Unsigned divide of the value in SLJIT_R0 by the value in SLJIT_R1.1200The result is placed into SLJIT_R0. SLJIT_R1 preserves its value.1201Note: if SLJIT_R1 is 0, the behaviour is undefined. */1202#define SLJIT_DIV_UW (SLJIT_OP0_BASE + 6)1203#define SLJIT_DIV_U32 (SLJIT_DIV_UW | SLJIT_32)1204/* Flags: - (may destroy flags)1205Signed divide of the value in SLJIT_R0 by the value in SLJIT_R1.1206The result is placed into SLJIT_R0. SLJIT_R1 preserves its value.1207Note: if SLJIT_R1 is 0, the behaviour is undefined.1208Note: if SLJIT_R1 is -1 and SLJIT_R0 is integer min (0x800..00),1209the behaviour is undefined. */1210#define SLJIT_DIV_SW (SLJIT_OP0_BASE + 7)1211#define SLJIT_DIV_S32 (SLJIT_DIV_SW | SLJIT_32)1212/* Flags: - (does not modify flags)1213May return with SLJIT_ERR_UNSUPPORTED if SLJIT_HAS_MEMORY_BARRIER1214feature is not supported (calling sljit_has_cpu_feature() with1215this feature option returns with 0). */1216#define SLJIT_MEMORY_BARRIER (SLJIT_OP0_BASE + 8)1217/* Flags: - (does not modify flags)1218ENDBR32 instruction for x86-32 and ENDBR64 instruction for x86-641219when Intel Control-flow Enforcement Technology (CET) is enabled.1220No instructions are emitted for other architectures. */1221#define SLJIT_ENDBR (SLJIT_OP0_BASE + 9)1222/* Flags: - (may destroy flags)1223Skip stack frames before return when Intel Control-flow1224Enforcement Technology (CET) is enabled. No instructions1225are emitted for other architectures. */1226#define SLJIT_SKIP_FRAMES_BEFORE_RETURN (SLJIT_OP0_BASE + 10)12271228SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op);12291230/* Starting index of opcodes for sljit_emit_op1. */1231#define SLJIT_OP1_BASE 3212321233/* The MOV instruction transfers data from source to destination.12341235MOV instruction suffixes:12361237U8 - unsigned 8 bit data transfer1238S8 - signed 8 bit data transfer1239U16 - unsigned 16 bit data transfer1240S16 - signed 16 bit data transfer1241U32 - unsigned int (32 bit) data transfer1242S32 - signed int (32 bit) data transfer1243P - pointer (sljit_up) data transfer1244*/12451246/* Flags: - (does not modify flags) */1247#define SLJIT_MOV (SLJIT_OP1_BASE + 0)1248/* Flags: - (does not modify flags) */1249#define SLJIT_MOV_U8 (SLJIT_OP1_BASE + 1)1250#define SLJIT_MOV32_U8 (SLJIT_MOV_U8 | SLJIT_32)1251/* Flags: - (does not modify flags) */1252#define SLJIT_MOV_S8 (SLJIT_OP1_BASE + 2)1253#define SLJIT_MOV32_S8 (SLJIT_MOV_S8 | SLJIT_32)1254/* Flags: - (does not modify flags) */1255#define SLJIT_MOV_U16 (SLJIT_OP1_BASE + 3)1256#define SLJIT_MOV32_U16 (SLJIT_MOV_U16 | SLJIT_32)1257/* Flags: - (does not modify flags) */1258#define SLJIT_MOV_S16 (SLJIT_OP1_BASE + 4)1259#define SLJIT_MOV32_S16 (SLJIT_MOV_S16 | SLJIT_32)1260/* Flags: - (does not modify flags)1261Note: no SLJIT_MOV32_U32 form, since it is the same as SLJIT_MOV32 */1262#define SLJIT_MOV_U32 (SLJIT_OP1_BASE + 5)1263/* Flags: - (does not modify flags)1264Note: no SLJIT_MOV32_S32 form, since it is the same as SLJIT_MOV32 */1265#define SLJIT_MOV_S32 (SLJIT_OP1_BASE + 6)1266/* Flags: - (does not modify flags) */1267#define SLJIT_MOV32 (SLJIT_OP1_BASE + 7)1268/* Flags: - (does not modify flags)1269Note: loads a pointer sized data, useful on x32 mode (a 64 bit mode1270on x86-64 which uses 32 bit pointers) or similar compiling modes */1271#define SLJIT_MOV_P (SLJIT_OP1_BASE + 8)1272/* Count leading zeroes1273Flags: - (may destroy flags)1274Note: immediate source argument is not supported */1275#define SLJIT_CLZ (SLJIT_OP1_BASE + 9)1276#define SLJIT_CLZ32 (SLJIT_CLZ | SLJIT_32)1277/* Count trailing zeroes1278Flags: - (may destroy flags)1279Note: immediate source argument is not supported */1280#define SLJIT_CTZ (SLJIT_OP1_BASE + 10)1281#define SLJIT_CTZ32 (SLJIT_CTZ | SLJIT_32)1282/* Reverse the order of bytes1283Flags: - (may destroy flags)1284Note: converts between little and big endian formats1285Note: immediate source argument is not supported */1286#define SLJIT_REV (SLJIT_OP1_BASE + 11)1287#define SLJIT_REV32 (SLJIT_REV | SLJIT_32)1288/* Reverse the order of bytes in the lower 16 bit and extend as unsigned1289Flags: - (may destroy flags)1290Note: converts between little and big endian formats1291Note: immediate source argument is not supported */1292#define SLJIT_REV_U16 (SLJIT_OP1_BASE + 12)1293#define SLJIT_REV32_U16 (SLJIT_REV_U16 | SLJIT_32)1294/* Reverse the order of bytes in the lower 16 bit and extend as signed1295Flags: - (may destroy flags)1296Note: converts between little and big endian formats1297Note: immediate source argument is not supported */1298#define SLJIT_REV_S16 (SLJIT_OP1_BASE + 13)1299#define SLJIT_REV32_S16 (SLJIT_REV_S16 | SLJIT_32)1300/* Reverse the order of bytes in the lower 32 bit and extend as unsigned1301Flags: - (may destroy flags)1302Note: converts between little and big endian formats1303Note: immediate source argument is not supported */1304#define SLJIT_REV_U32 (SLJIT_OP1_BASE + 14)1305/* Reverse the order of bytes in the lower 32 bit and extend as signed1306Flags: - (may destroy flags)1307Note: converts between little and big endian formats1308Note: immediate source argument is not supported */1309#define SLJIT_REV_S32 (SLJIT_OP1_BASE + 15)13101311/* The following unary operations are supported by using sljit_emit_op2:1312- binary not: SLJIT_XOR with immedate -1 as src1 or src21313- negate: SLJIT_SUB with immedate 0 as src11314Note: these operations are optimized by the compiler if the1315target CPU has specialized instruction forms for them. */13161317SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,1318sljit_s32 dst, sljit_sw dstw,1319sljit_s32 src, sljit_sw srcw);13201321/* Starting index of opcodes for sljit_emit_op2. */1322#define SLJIT_OP2_BASE 6413231324/* Flags: Z | OVERFLOW | CARRY */1325#define SLJIT_ADD (SLJIT_OP2_BASE + 0)1326#define SLJIT_ADD32 (SLJIT_ADD | SLJIT_32)1327/* Flags: CARRY */1328#define SLJIT_ADDC (SLJIT_OP2_BASE + 1)1329#define SLJIT_ADDC32 (SLJIT_ADDC | SLJIT_32)1330/* Flags: Z | LESS | GREATER_EQUAL | GREATER | LESS_EQUAL1331SIG_LESS | SIG_GREATER_EQUAL | SIG_GREATER1332SIG_LESS_EQUAL | OVERFLOW | CARRY */1333#define SLJIT_SUB (SLJIT_OP2_BASE + 2)1334#define SLJIT_SUB32 (SLJIT_SUB | SLJIT_32)1335/* Flags: CARRY */1336#define SLJIT_SUBC (SLJIT_OP2_BASE + 3)1337#define SLJIT_SUBC32 (SLJIT_SUBC | SLJIT_32)1338/* Note: integer mul1339Flags: OVERFLOW */1340#define SLJIT_MUL (SLJIT_OP2_BASE + 4)1341#define SLJIT_MUL32 (SLJIT_MUL | SLJIT_32)1342/* Flags: Z */1343#define SLJIT_AND (SLJIT_OP2_BASE + 5)1344#define SLJIT_AND32 (SLJIT_AND | SLJIT_32)1345/* Flags: Z */1346#define SLJIT_OR (SLJIT_OP2_BASE + 6)1347#define SLJIT_OR32 (SLJIT_OR | SLJIT_32)1348/* Flags: Z */1349#define SLJIT_XOR (SLJIT_OP2_BASE + 7)1350#define SLJIT_XOR32 (SLJIT_XOR | SLJIT_32)1351/* Flags: Z1352Let bit_length be the length of the shift operation: 32 or 64.1353If src2 is immediate, src2w is masked by (bit_length - 1).1354Otherwise, if the content of src2 is outside the range from 01355to bit_length - 1, the result is undefined. */1356#define SLJIT_SHL (SLJIT_OP2_BASE + 8)1357#define SLJIT_SHL32 (SLJIT_SHL | SLJIT_32)1358/* Flags: Z1359Same as SLJIT_SHL, except the the second operand is1360always masked by the length of the shift operation. */1361#define SLJIT_MSHL (SLJIT_OP2_BASE + 9)1362#define SLJIT_MSHL32 (SLJIT_MSHL | SLJIT_32)1363/* Flags: Z1364Let bit_length be the length of the shift operation: 32 or 64.1365If src2 is immediate, src2w is masked by (bit_length - 1).1366Otherwise, if the content of src2 is outside the range from 01367to bit_length - 1, the result is undefined. */1368#define SLJIT_LSHR (SLJIT_OP2_BASE + 10)1369#define SLJIT_LSHR32 (SLJIT_LSHR | SLJIT_32)1370/* Flags: Z1371Same as SLJIT_LSHR, except the the second operand is1372always masked by the length of the shift operation. */1373#define SLJIT_MLSHR (SLJIT_OP2_BASE + 11)1374#define SLJIT_MLSHR32 (SLJIT_MLSHR | SLJIT_32)1375/* Flags: Z1376Let bit_length be the length of the shift operation: 32 or 64.1377If src2 is immediate, src2w is masked by (bit_length - 1).1378Otherwise, if the content of src2 is outside the range from 01379to bit_length - 1, the result is undefined. */1380#define SLJIT_ASHR (SLJIT_OP2_BASE + 12)1381#define SLJIT_ASHR32 (SLJIT_ASHR | SLJIT_32)1382/* Flags: Z1383Same as SLJIT_ASHR, except the the second operand is1384always masked by the length of the shift operation. */1385#define SLJIT_MASHR (SLJIT_OP2_BASE + 13)1386#define SLJIT_MASHR32 (SLJIT_MASHR | SLJIT_32)1387/* Flags: - (may destroy flags)1388Let bit_length be the length of the rotate operation: 32 or 64.1389The second operand is always masked by (bit_length - 1). */1390#define SLJIT_ROTL (SLJIT_OP2_BASE + 14)1391#define SLJIT_ROTL32 (SLJIT_ROTL | SLJIT_32)1392/* Flags: - (may destroy flags)1393Let bit_length be the length of the rotate operation: 32 or 64.1394The second operand is always masked by (bit_length - 1). */1395#define SLJIT_ROTR (SLJIT_OP2_BASE + 15)1396#define SLJIT_ROTR32 (SLJIT_ROTR | SLJIT_32)13971398SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,1399sljit_s32 dst, sljit_sw dstw,1400sljit_s32 src1, sljit_sw src1w,1401sljit_s32 src2, sljit_sw src2w);14021403/* The sljit_emit_op2u function is the same as sljit_emit_op21404except the result is discarded. */14051406SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,1407sljit_s32 src1, sljit_sw src1w,1408sljit_s32 src2, sljit_sw src2w);14091410/* Starting index of opcodes for sljit_emit_op2r. */1411#define SLJIT_OP2R_BASE 9614121413/* Flags: - (may destroy flags) */1414#define SLJIT_MULADD (SLJIT_OP2R_BASE + 0)1415#define SLJIT_MULADD32 (SLJIT_MULADD | SLJIT_32)14161417/* Similar to sljit_emit_fop2, except the destination is always a register. */1418SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2r(struct sljit_compiler *compiler, sljit_s32 op,1419sljit_s32 dst_reg,1420sljit_s32 src1, sljit_sw src1w,1421sljit_s32 src2, sljit_sw src2w);14221423/* Emit a left or right shift operation, where the bits shifted1424in comes from a separate source operand. All operands are1425interpreted as unsigned integers.14261427In the followings the value_mask variable is 31 for 32 bit1428operations and word_size - 1 otherwise.14291430op must be one of the following operations:1431SLJIT_SHL or SLJIT_SHL32:1432dst_reg = src1_reg << src3_reg1433dst_reg |= ((src2_reg >> 1) >> (src3 ^ value_mask))1434SLJIT_MSHL or SLJIT_MSHL32:1435src3 &= value_mask1436perform the SLJIT_SHL or SLJIT_SHL32 operation1437SLJIT_LSHR or SLJIT_LSHR32:1438dst_reg = src1_reg >> src3_reg1439dst_reg |= ((src2_reg << 1) << (src3 ^ value_mask))1440SLJIT_MLSHR or SLJIT_MLSHR32:1441src3 &= value_mask1442perform the SLJIT_LSHR or SLJIT_LSHR32 operation14431444op can be combined (or'ed) with SLJIT_SHIFT_INTO_NON_ZERO14451446dst_reg specifies the destination register, where dst_reg1447and src2_reg cannot be the same registers1448src1_reg specifies the source register1449src2_reg specifies the register which is shifted into src1_reg1450src3 / src3w contains the shift amount14511452Note: a rotate operation is performed if src1_reg and1453src2_reg are the same registers14541455Flags: - (may destroy flags) */14561457/* The src3 operand contains a non-zero value. Improves1458the generated code on certain architectures, which1459provides a small performance improvement. */1460#define SLJIT_SHIFT_INTO_NON_ZERO 0x20014611462SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler *compiler, sljit_s32 op,1463sljit_s32 dst_reg,1464sljit_s32 src1_reg,1465sljit_s32 src2_reg,1466sljit_s32 src3, sljit_sw src3w);14671468/* The following options are used by sljit_emit_op2_shift. */14691470/* The src2 argument is shifted left by an immedate value. */1471#define SLJIT_SHL_IMM (1 << 9)1472/* When src2 argument is a register, its value is undefined after the operation. */1473#define SLJIT_SRC2_UNDEFINED (1 << 10)14741475/* Emits an addition operation, where the second argument is shifted by a value.14761477op must be SLJIT_ADD | SLJIT_SHL_IMM, where the immedate value is stored in shift_arg14781479Flags: - (may destroy flags) */1480SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2_shift(struct sljit_compiler *compiler, sljit_s32 op,1481sljit_s32 dst, sljit_sw dstw,1482sljit_s32 src1, sljit_sw src1w,1483sljit_s32 src2, sljit_sw src2w,1484sljit_sw shift_arg);14851486/* Starting index of opcodes for sljit_emit_op_src1487and sljit_emit_op_dst. */1488#define SLJIT_OP_SRC_DST_BASE 11214891490/* Fast return, see SLJIT_FAST_CALL for more details.1491Note: src cannot be an immedate value1492Flags: - (does not modify flags) */1493#define SLJIT_FAST_RETURN (SLJIT_OP_SRC_DST_BASE + 0)1494/* Skip stack frames before fast return.1495Note: src cannot be an immedate value1496Flags: may destroy flags. */1497#define SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN (SLJIT_OP_SRC_DST_BASE + 1)1498/* Prefetch value into the level 1 data cache1499Note: if the target CPU does not support data prefetch,1500no instructions are emitted.1501Note: this instruction never fails, even if the memory address is invalid.1502Flags: - (does not modify flags) */1503#define SLJIT_PREFETCH_L1 (SLJIT_OP_SRC_DST_BASE + 2)1504/* Prefetch value into the level 2 data cache1505Note: same as SLJIT_PREFETCH_L1 if the target CPU1506does not support this instruction form.1507Note: this instruction never fails, even if the memory address is invalid.1508Flags: - (does not modify flags) */1509#define SLJIT_PREFETCH_L2 (SLJIT_OP_SRC_DST_BASE + 3)1510/* Prefetch value into the level 3 data cache1511Note: same as SLJIT_PREFETCH_L2 if the target CPU1512does not support this instruction form.1513Note: this instruction never fails, even if the memory address is invalid.1514Flags: - (does not modify flags) */1515#define SLJIT_PREFETCH_L3 (SLJIT_OP_SRC_DST_BASE + 4)1516/* Prefetch a value which is only used once (and can be discarded afterwards)1517Note: same as SLJIT_PREFETCH_L1 if the target CPU1518does not support this instruction form.1519Note: this instruction never fails, even if the memory address is invalid.1520Flags: - (does not modify flags) */1521#define SLJIT_PREFETCH_ONCE (SLJIT_OP_SRC_DST_BASE + 5)15221523SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,1524sljit_s32 src, sljit_sw srcw);15251526/* Fast enter, see SLJIT_FAST_CALL for more details.1527Flags: - (does not modify flags) */1528#define SLJIT_FAST_ENTER (SLJIT_OP_SRC_DST_BASE + 6)15291530/* Copies the return address into dst. The return address is the1531address where the execution continues after the called function1532returns (see: sljit_emit_return / sljit_emit_return_void).1533Flags: - (does not modify flags) */1534#define SLJIT_GET_RETURN_ADDRESS (SLJIT_OP_SRC_DST_BASE + 7)15351536SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *compiler, sljit_s32 op,1537sljit_s32 dst, sljit_sw dstw);15381539/* Starting index of opcodes for sljit_emit_fop1. */1540#define SLJIT_FOP1_BASE 14415411542/* Flags: - (does not modify flags) */1543#define SLJIT_MOV_F64 (SLJIT_FOP1_BASE + 0)1544#define SLJIT_MOV_F32 (SLJIT_MOV_F64 | SLJIT_32)1545/* Convert opcodes: CONV[DST_TYPE].FROM[SRC_TYPE]1546SRC/DST TYPE can be: F64, F32, S32, SW1547Rounding mode when the destination is SW or S32: round towards zero. */1548/* Flags: - (may destroy flags) */1549#define SLJIT_CONV_F64_FROM_F32 (SLJIT_FOP1_BASE + 1)1550#define SLJIT_CONV_F32_FROM_F64 (SLJIT_CONV_F64_FROM_F32 | SLJIT_32)1551/* Flags: - (may destroy flags) */1552#define SLJIT_CONV_SW_FROM_F64 (SLJIT_FOP1_BASE + 2)1553#define SLJIT_CONV_SW_FROM_F32 (SLJIT_CONV_SW_FROM_F64 | SLJIT_32)1554/* Flags: - (may destroy flags) */1555#define SLJIT_CONV_S32_FROM_F64 (SLJIT_FOP1_BASE + 3)1556#define SLJIT_CONV_S32_FROM_F32 (SLJIT_CONV_S32_FROM_F64 | SLJIT_32)1557/* Flags: - (may destroy flags) */1558#define SLJIT_CONV_F64_FROM_SW (SLJIT_FOP1_BASE + 4)1559#define SLJIT_CONV_F32_FROM_SW (SLJIT_CONV_F64_FROM_SW | SLJIT_32)1560/* Flags: - (may destroy flags) */1561#define SLJIT_CONV_F64_FROM_S32 (SLJIT_FOP1_BASE + 5)1562#define SLJIT_CONV_F32_FROM_S32 (SLJIT_CONV_F64_FROM_S32 | SLJIT_32)1563/* Flags: - (may destroy flags) */1564#define SLJIT_CONV_F64_FROM_UW (SLJIT_FOP1_BASE + 6)1565#define SLJIT_CONV_F32_FROM_UW (SLJIT_CONV_F64_FROM_UW | SLJIT_32)1566/* Flags: - (may destroy flags) */1567#define SLJIT_CONV_F64_FROM_U32 (SLJIT_FOP1_BASE + 7)1568#define SLJIT_CONV_F32_FROM_U32 (SLJIT_CONV_F64_FROM_U32 | SLJIT_32)1569/* Note: dst is the left and src is the right operand for SLJIT_CMP_F32/64.1570Flags: EQUAL_F | LESS_F | GREATER_EQUAL_F | GREATER_F | LESS_EQUAL_F */1571#define SLJIT_CMP_F64 (SLJIT_FOP1_BASE + 8)1572#define SLJIT_CMP_F32 (SLJIT_CMP_F64 | SLJIT_32)1573/* Flags: - (may destroy flags) */1574#define SLJIT_NEG_F64 (SLJIT_FOP1_BASE + 9)1575#define SLJIT_NEG_F32 (SLJIT_NEG_F64 | SLJIT_32)1576/* Flags: - (may destroy flags) */1577#define SLJIT_ABS_F64 (SLJIT_FOP1_BASE + 10)1578#define SLJIT_ABS_F32 (SLJIT_ABS_F64 | SLJIT_32)15791580SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,1581sljit_s32 dst, sljit_sw dstw,1582sljit_s32 src, sljit_sw srcw);15831584/* Starting index of opcodes for sljit_emit_fop2. */1585#define SLJIT_FOP2_BASE 17615861587/* Flags: - (may destroy flags) */1588#define SLJIT_ADD_F64 (SLJIT_FOP2_BASE + 0)1589#define SLJIT_ADD_F32 (SLJIT_ADD_F64 | SLJIT_32)1590/* Flags: - (may destroy flags) */1591#define SLJIT_SUB_F64 (SLJIT_FOP2_BASE + 1)1592#define SLJIT_SUB_F32 (SLJIT_SUB_F64 | SLJIT_32)1593/* Flags: - (may destroy flags) */1594#define SLJIT_MUL_F64 (SLJIT_FOP2_BASE + 2)1595#define SLJIT_MUL_F32 (SLJIT_MUL_F64 | SLJIT_32)1596/* Flags: - (may destroy flags) */1597#define SLJIT_DIV_F64 (SLJIT_FOP2_BASE + 3)1598#define SLJIT_DIV_F32 (SLJIT_DIV_F64 | SLJIT_32)15991600SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,1601sljit_s32 dst, sljit_sw dstw,1602sljit_s32 src1, sljit_sw src1w,1603sljit_s32 src2, sljit_sw src2w);16041605/* Starting index of opcodes for sljit_emit_fop2r. */1606#define SLJIT_FOP2R_BASE 19216071608/* Flags: - (may destroy flags) */1609#define SLJIT_COPYSIGN_F64 (SLJIT_FOP2R_BASE + 0)1610#define SLJIT_COPYSIGN_F32 (SLJIT_COPYSIGN_F64 | SLJIT_32)16111612/* Similar to sljit_emit_fop2, except the destination is always a register. */1613SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2r(struct sljit_compiler *compiler, sljit_s32 op,1614sljit_s32 dst_freg,1615sljit_s32 src1, sljit_sw src1w,1616sljit_s32 src2, sljit_sw src2w);16171618/* Sets a floating point register to an immediate value. */16191620SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset32(struct sljit_compiler *compiler,1621sljit_s32 freg, sljit_f32 value);1622SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset64(struct sljit_compiler *compiler,1623sljit_s32 freg, sljit_f64 value);16241625/* The following opcodes are used by sljit_emit_fcopy(). */16261627/* 64 bit: copy a 64 bit value from an integer register into a162864 bit floating point register without any modifications.162932 bit: copy a 32 bit register or register pair into a 64 bit1630floating point register without any modifications. The1631register, or the first register of the register pair1632replaces the high order 32 bit of the floating point1633register. If a register pair is passed, the low1634order 32 bit is replaced by the second register.1635Otherwise, the low order 32 bit is unchanged. */1636#define SLJIT_COPY_TO_F64 11637/* Copy a 32 bit value from an integer register into a 32 bit1638floating point register without any modifications. */1639#define SLJIT_COPY32_TO_F32 (SLJIT_COPY_TO_F64 | SLJIT_32)1640/* 64 bit: copy the value of a 64 bit floating point register into1641an integer register without any modifications.164232 bit: copy a 64 bit floating point register into a 32 bit register1643or a 32 bit register pair without any modifications. The1644high order 32 bit of the floating point register is copied1645into the register, or the first register of the register1646pair. If a register pair is passed, the low order 32 bit1647is copied into the second register. */1648#define SLJIT_COPY_FROM_F64 21649/* Copy the value of a 32 bit floating point register into an integer1650register without any modifications. The register should be processed1651with 32 bit operations later. */1652#define SLJIT_COPY32_FROM_F32 (SLJIT_COPY_FROM_F64 | SLJIT_32)16531654/* Special data copy which involves floating point registers.16551656op must be between SLJIT_COPY_TO_F64 and SLJIT_COPY32_FROM_F321657freg must be a floating point register1658reg must be a register or register pair */16591660SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fcopy(struct sljit_compiler *compiler, sljit_s32 op,1661sljit_s32 freg, sljit_s32 reg);16621663/* Label and jump instructions. */16641665/* Emits a label which can be the target of jump / mov_addr instructions. */16661667SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler);16681669/* Alignment values for sljit_emit_aligned_label. */16701671#define SLJIT_LABEL_ALIGN_1 01672#define SLJIT_LABEL_ALIGN_2 11673#define SLJIT_LABEL_ALIGN_4 21674#define SLJIT_LABEL_ALIGN_8 31675#define SLJIT_LABEL_ALIGN_16 41676#define SLJIT_LABEL_ALIGN_W SLJIT_WORD_SHIFT1677#define SLJIT_LABEL_ALIGN_P SLJIT_POINTER_SHIFT16781679/* Emits a label which address is aligned to a power of 2 value. When some1680extra space needs to be added to align the label, that space is filled1681with SLJIT_NOP instructions. These labels usually represent the end of a1682compilation block, and a new function or some read-only data (e.g. a1683jump table) follows it. In these typical cases the SLJIT_NOPs are never1684executed.16851686Optionally, buffers for storing read-only data or code can be allocated1687by this operation. The buffers are passed as a chain list, and a separate1688memory area is allocated for each item in the list. All buffers are aligned1689to SLJIT_NOP instruction size, and their starting address is returned as1690as a label. The sljit_get_label_abs_addr function or the SLJIT_MOV_ABS_ADDR1691operation can be used to get the real address. The label of the first buffer1692is always the same as the returned label. The buffers are initially1693initialized with SLJIT_NOP instructions. The alignment of the buffers can1694be controlled by their starting address and sizes. If the starting address1695is aligned to N, and size is also divisible by N, the next buffer is aligned1696to N. I.e. if a buffer is 16 byte aligned, and its size is divisible by 4,1697the next buffer is 4 byte aligned. Note: if a buffer is N (>=2) byte aligned,1698it is also N/2 byte aligned.16991700align represents the alignment, and its value can1701be specified by SLJIT_LABEL_* constants17021703buffers is a list of read-only buffers stored in a chain list.1704After calling sljit_generate_code, these buffers can be1705modified by sljit_read_only_buffer_start_writing() /1706sljit_read_only_buffer_end_writing() functions17071708Note: the constant pool (if present) may be stored before the label. */1709SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_aligned_label(struct sljit_compiler *compiler,1710sljit_s32 alignment, struct sljit_read_only_buffer *buffers);17111712/* The SLJIT_FAST_CALL is a calling method for creating lightweight function1713calls. This type of calls preserve the values of all registers and stack1714frame. Unlike normal function calls, the enter and return operations must1715be performed by the SLJIT_FAST_ENTER and SLJIT_FAST_RETURN operations1716respectively. The return address is stored in the dst argument of the1717SLJIT_FAST_ENTER operation, and this return address should be passed as1718the src argument for the SLJIT_FAST_RETURN operation to return from the1719called function.17201721Fast calls are cheap operations (usually only a single call instruction is1722emitted) but they do not preserve any registers. However the callee function1723can freely use / update any registers and the locals area which can be1724efficiently exploited by various optimizations. Registers can be saved1725and restored manually if needed.17261727Although returning to different address by SLJIT_FAST_RETURN is possible,1728this address usually cannot be predicted by the return address predictor of1729modern CPUs which may reduce performance. Furthermore certain security1730enhancement technologies such as Intel Control-flow Enforcement Technology1731(CET) may disallow returning to a different address (indirect jumps1732can be used instead, see SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN). */17331734/* Invert (negate) conditional type: xor (^) with 0x1 */17351736/* Integer comparison types. */1737#define SLJIT_EQUAL 01738#define SLJIT_ZERO SLJIT_EQUAL1739#define SLJIT_NOT_EQUAL 11740#define SLJIT_NOT_ZERO SLJIT_NOT_EQUAL17411742#define SLJIT_LESS 21743#define SLJIT_SET_LESS SLJIT_SET(SLJIT_LESS)1744#define SLJIT_GREATER_EQUAL 31745#define SLJIT_SET_GREATER_EQUAL SLJIT_SET(SLJIT_LESS)1746#define SLJIT_GREATER 41747#define SLJIT_SET_GREATER SLJIT_SET(SLJIT_GREATER)1748#define SLJIT_LESS_EQUAL 51749#define SLJIT_SET_LESS_EQUAL SLJIT_SET(SLJIT_GREATER)1750#define SLJIT_SIG_LESS 61751#define SLJIT_SET_SIG_LESS SLJIT_SET(SLJIT_SIG_LESS)1752#define SLJIT_SIG_GREATER_EQUAL 71753#define SLJIT_SET_SIG_GREATER_EQUAL SLJIT_SET(SLJIT_SIG_LESS)1754#define SLJIT_SIG_GREATER 81755#define SLJIT_SET_SIG_GREATER SLJIT_SET(SLJIT_SIG_GREATER)1756#define SLJIT_SIG_LESS_EQUAL 91757#define SLJIT_SET_SIG_LESS_EQUAL SLJIT_SET(SLJIT_SIG_GREATER)17581759#define SLJIT_OVERFLOW 101760#define SLJIT_SET_OVERFLOW SLJIT_SET(SLJIT_OVERFLOW)1761#define SLJIT_NOT_OVERFLOW 1117621763/* Unlike other flags, sljit_emit_jump may destroy the carry flag. */1764#define SLJIT_CARRY 121765#define SLJIT_SET_CARRY SLJIT_SET(SLJIT_CARRY)1766#define SLJIT_NOT_CARRY 1317671768#define SLJIT_ATOMIC_STORED 141769#define SLJIT_SET_ATOMIC_STORED SLJIT_SET(SLJIT_ATOMIC_STORED)1770#define SLJIT_ATOMIC_NOT_STORED 1517711772/* Basic floating point comparison types.17731774Note: when the comparison result is unordered, their behaviour is unspecified. */17751776#define SLJIT_F_EQUAL 161777#define SLJIT_SET_F_EQUAL SLJIT_SET(SLJIT_F_EQUAL)1778#define SLJIT_F_NOT_EQUAL 171779#define SLJIT_SET_F_NOT_EQUAL SLJIT_SET(SLJIT_F_EQUAL)1780#define SLJIT_F_LESS 181781#define SLJIT_SET_F_LESS SLJIT_SET(SLJIT_F_LESS)1782#define SLJIT_F_GREATER_EQUAL 191783#define SLJIT_SET_F_GREATER_EQUAL SLJIT_SET(SLJIT_F_LESS)1784#define SLJIT_F_GREATER 201785#define SLJIT_SET_F_GREATER SLJIT_SET(SLJIT_F_GREATER)1786#define SLJIT_F_LESS_EQUAL 211787#define SLJIT_SET_F_LESS_EQUAL SLJIT_SET(SLJIT_F_GREATER)17881789/* Jumps when either argument contains a NaN value. */1790#define SLJIT_UNORDERED 221791#define SLJIT_SET_UNORDERED SLJIT_SET(SLJIT_UNORDERED)1792/* Jumps when neither argument contains a NaN value. */1793#define SLJIT_ORDERED 231794#define SLJIT_SET_ORDERED SLJIT_SET(SLJIT_UNORDERED)17951796/* Ordered / unordered floating point comparison types.17971798Note: each comparison type has an ordered and unordered form. Some1799architectures supports only either of them (see: sljit_cmp_info). */18001801#define SLJIT_ORDERED_EQUAL 241802#define SLJIT_SET_ORDERED_EQUAL SLJIT_SET(SLJIT_ORDERED_EQUAL)1803#define SLJIT_UNORDERED_OR_NOT_EQUAL 251804#define SLJIT_SET_UNORDERED_OR_NOT_EQUAL SLJIT_SET(SLJIT_ORDERED_EQUAL)1805#define SLJIT_ORDERED_LESS 261806#define SLJIT_SET_ORDERED_LESS SLJIT_SET(SLJIT_ORDERED_LESS)1807#define SLJIT_UNORDERED_OR_GREATER_EQUAL 271808#define SLJIT_SET_UNORDERED_OR_GREATER_EQUAL SLJIT_SET(SLJIT_ORDERED_LESS)1809#define SLJIT_ORDERED_GREATER 281810#define SLJIT_SET_ORDERED_GREATER SLJIT_SET(SLJIT_ORDERED_GREATER)1811#define SLJIT_UNORDERED_OR_LESS_EQUAL 291812#define SLJIT_SET_UNORDERED_OR_LESS_EQUAL SLJIT_SET(SLJIT_ORDERED_GREATER)18131814#define SLJIT_UNORDERED_OR_EQUAL 301815#define SLJIT_SET_UNORDERED_OR_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_EQUAL)1816#define SLJIT_ORDERED_NOT_EQUAL 311817#define SLJIT_SET_ORDERED_NOT_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_EQUAL)1818#define SLJIT_UNORDERED_OR_LESS 321819#define SLJIT_SET_UNORDERED_OR_LESS SLJIT_SET(SLJIT_UNORDERED_OR_LESS)1820#define SLJIT_ORDERED_GREATER_EQUAL 331821#define SLJIT_SET_ORDERED_GREATER_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_LESS)1822#define SLJIT_UNORDERED_OR_GREATER 341823#define SLJIT_SET_UNORDERED_OR_GREATER SLJIT_SET(SLJIT_UNORDERED_OR_GREATER)1824#define SLJIT_ORDERED_LESS_EQUAL 351825#define SLJIT_SET_ORDERED_LESS_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_GREATER)18261827/* Unconditional jump types. */1828#define SLJIT_JUMP 361829/* Fast calling method. See the description above. */1830#define SLJIT_FAST_CALL 371831/* Default C calling convention. */1832#define SLJIT_CALL 381833/* Called function must be compiled by SLJIT.1834See SLJIT_ENTER_REG_ARG option. */1835#define SLJIT_CALL_REG_ARG 3918361837/* The target can be changed during runtime (see: sljit_set_jump_addr). */1838#define SLJIT_REWRITABLE_JUMP 0x100001839/* When this flag is passed, the execution of the current function ends and1840the called function returns to the caller of the current function. The1841stack usage is reduced before the call, but it is not necessarily reduced1842to zero. In the latter case the compiler needs to allocate space for some1843arguments and the return address must be stored on the stack as well. */1844#define SLJIT_CALL_RETURN 0x2000018451846/* Emit a jump instruction. The destination is not set, only the type of the jump.1847type must be between SLJIT_JUMP and SLJIT_FAST_CALL1848type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP18491850Flags: does not modify flags. */1851SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type);18521853/* Emit a C compiler (ABI) compatible function call.1854type must be SLJIT_CALL or SLJIT_CALL_REG_ARG1855type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP and/or SLJIT_CALL_RETURN1856arg_types can be specified by SLJIT_ARGSx (SLJIT_ARG_RETURN / SLJIT_ARG_VALUE) macros18571858Flags: destroy all flags. */1859SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 arg_types);18601861/* Integer comparison operation. In most architectures it is implemented1862as a compare (sljit_emit_op2u with SLJIT_SUB) operation followed by1863an sljit_emit_jump. However, some architectures (e.g: ARM64 or RISCV)1864may optimize the generated code further. It is suggested to use this1865comparison form when appropriate.1866type must be between SLJIT_EQUAL and SLJIT_SIG_LESS_EQUAL1867type can be combined (or'ed) with SLJIT_32 or SLJIT_REWRITABLE_JUMP18681869Flags: may destroy flags. */1870SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,1871sljit_s32 src1, sljit_sw src1w,1872sljit_s32 src2, sljit_sw src2w);18731874/* Floating point comparison operation. In most architectures it is1875implemented as a SLJIT_CMP_F32/64 operation (setting appropriate1876flags) followed by a sljit_emit_jump. However, some architectures1877(e.g: MIPS) may optimize the generated code further. It is suggested1878to use this comparison form when appropriate.1879type must be between SLJIT_F_EQUAL and SLJIT_ORDERED_LESS_EQUAL1880type can be combined (or'ed) with SLJIT_32 or SLJIT_REWRITABLE_JUMP18811882Flags: destroy flags.1883Note: when any operand is NaN the behaviour depends on the comparison type. */1884SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,1885sljit_s32 src1, sljit_sw src1w,1886sljit_s32 src2, sljit_sw src2w);18871888/* The following flags are used by sljit_emit_op2cmpz(). */1889#define SLJIT_JUMP_IF_NON_ZERO 01890#define SLJIT_JUMP_IF_ZERO SLJIT_SET_Z18911892/* Perform an integer arithmetic operation, then its result is compared to1893zero. In most architectures it is implemented as an sljit_emit_op21894followed by an sljit_emit_jump. However, some architectures (e.g: RISCV)1895may optimize the generated code further. It is suggested to use this1896operation form when appropriate (e.g. for loops with counters).18971898op must be an sljit_emit_op2 operation where zero flag can be set,1899op can be combined with SLJIT_SET_* status flag setters except1900SLJIT_SET_Z, SLJIT_REWRITABLE_JUMP or SLJIT_JUMP_IF_* option bits.19011902Note: SLJIT_JUMP_IF_NON_ZERO is the default operation if neither1903SLJIT_JUMP_IF_ZERO or SLJIT_JUMP_IF_NON_ZERO is specified.1904Flags: sets the variable flag depending on op argument, the1905zero flag is undefined. */1906SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op2cmpz(struct sljit_compiler *compiler, sljit_s32 op,1907sljit_s32 dst, sljit_sw dstw,1908sljit_s32 src1, sljit_sw src1w,1909sljit_s32 src2, sljit_sw src2w);19101911/* Set the destination of the jump to this label. */1912SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label);1913/* Set the destination address of the jump to this label. */1914SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target);19151916/* Emit an indirect jump or fast call.1917Direct form: set src to SLJIT_IMM() and srcw to the address1918Indirect form: any other valid addressing mode1919type must be between SLJIT_JUMP and SLJIT_FAST_CALL19201921Flags: does not modify flags. */1922SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw);19231924/* Emit a C compiler (ABI) compatible function call.1925Direct form: set src to SLJIT_IMM() and srcw to the address1926Indirect form: any other valid addressing mode1927type must be SLJIT_CALL or SLJIT_CALL_REG_ARG1928type can be combined (or'ed) with SLJIT_CALL_RETURN1929arg_types can be specified by SLJIT_ARGSx (SLJIT_ARG_RETURN / SLJIT_ARG_VALUE) macros19301931Flags: destroy all flags. */1932SLJIT_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);19331934/* Perform an operation using the conditional flags as the second argument.1935Type must always be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL.1936The value represented by the type is 1, if the condition represented1937by type is fulfilled, and 0 otherwise.19381939When op is SLJIT_MOV or SLJIT_MOV32:1940Set dst to the value represented by the type (0 or 1).1941Flags: - (does not modify flags)1942When op is SLJIT_AND, SLJIT_AND32, SLJIT_OR, SLJIT_OR32, SLJIT_XOR, or SLJIT_XOR321943Performs the binary operation using dst as the first, and the value1944represented by type as the second argument. Result is written into dst.1945Flags: Z (may destroy flags) */1946SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,1947sljit_s32 dst, sljit_sw dstw,1948sljit_s32 type);19491950/* The following flags are used by sljit_emit_select(). */19511952/* Compare src1 and src2_reg operands before executing select1953(i.e. converts the select operation to a min/max operation). */1954#define SLJIT_COMPARE_SELECT SLJIT_SET_Z19551956/* Emit a conditional select instruction which moves src1 to dst_reg,1957if the conditional flag is set, or src2_reg to dst_reg otherwise.1958The conditional flag should be set before executing the select1959instruction unless SLJIT_COMPARE_SELECT is specified.19601961type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL1962when SLJIT_COMPARE_SELECT option is NOT specified1963type must be between SLJIT_LESS and SLJIT_SET_SIG_LESS_EQUAL1964when SLJIT_COMPARE_SELECT option is specified1965type can be combined (or'ed) with SLJIT_32 to move 32 bit1966register values instead of word sized ones1967type can be combined (or'ed) with SLJIT_COMPARE_SELECT1968which compares src1 and src2_reg before executing the select1969dst_reg and src2_reg must be valid registers1970src1 must be valid operand19711972Note: if src1 is a memory operand, its value1973might be loaded even if the condition is false19741975Note: when SLJIT_COMPARE_SELECT is specified, the status flag1976bits might not represent the result of a normal compare1977operation, hence flags are not specified after the operation19781979Note: if sljit_has_cpu_feature(SLJIT_HAS_CMOV) returns with a non-zero value:1980(a) conditional register move (dst_reg==src2_reg, src1 is register)1981can be performed using a single instruction, except on RISCV,1982where three instructions are needed1983(b) conditional clearing (dst_reg==src2_reg, src1==SLJIT_IMM,1984src1w==0) can be performed using a single instruction,1985except on x86, where two instructions are needed19861987Flags:1988When SLJIT_COMPARE_SELECT is NOT specified: - (does not modify flags)1989When SLJIT_COMPARE_SELECT is specified: - (may destroy flags) */1990SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *compiler, sljit_s32 type,1991sljit_s32 dst_reg,1992sljit_s32 src1, sljit_sw src1w,1993sljit_s32 src2_reg);19941995/* Emit a conditional floating point select instruction which moves1996src1 to dst_reg, if the conditional flag is set, or src2_reg to1997dst_reg otherwise. The conditional flag should be set before1998executing the select instruction.19992000type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL2001type can be combined (or'ed) with SLJIT_32 to move 32 bit2002floating point values instead of 64 bit ones2003dst_freg and src2_freg must be valid floating point registers2004src1 must be valid operand20052006Note: if src1 is a memory operand, its value2007might be loaded even if the condition is false.20082009Flags: - (does not modify flags) */2010SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *compiler, sljit_s32 type,2011sljit_s32 dst_freg,2012sljit_s32 src1, sljit_sw src1w,2013sljit_s32 src2_freg);20142015/* The following flags are used by sljit_emit_mem(), sljit_emit_mem_update(),2016sljit_emit_fmem(), and sljit_emit_fmem_update(). */20172018/* Memory load operation. This is the default. */2019#define SLJIT_MEM_LOAD 0x0000002020/* Memory store operation. */2021#define SLJIT_MEM_STORE 0x00020020222023/* The following flags are used by sljit_emit_mem() and sljit_emit_fmem(). */20242025/* Load or stora data from an unaligned (byte aligned) address. */2026#define SLJIT_MEM_UNALIGNED 0x0004002027/* Load or stora data from a 16 bit aligned address. */2028#define SLJIT_MEM_ALIGNED_16 0x0008002029/* Load or stora data from a 32 bit aligned address. */2030#define SLJIT_MEM_ALIGNED_32 0x00100020312032/* The following flags are used by sljit_emit_mem_update(),2033and sljit_emit_fmem_update(). */20342035/* Base register is updated before the memory access (default). */2036#define SLJIT_MEM_PRE 0x0000002037/* Base register is updated after the memory access. */2038#define SLJIT_MEM_POST 0x00040020392040/* When SLJIT_MEM_SUPP is passed, no instructions are emitted.2041Instead the function returns with SLJIT_SUCCESS if the instruction2042form is supported and SLJIT_ERR_UNSUPPORTED otherwise. This flag2043allows runtime checking of available instruction forms. */2044#define SLJIT_MEM_SUPP 0x00080020452046/* The sljit_emit_mem emits instructions for various memory operations:20472048When SLJIT_MEM_UNALIGNED / SLJIT_MEM_ALIGNED_16 /2049SLJIT_MEM_ALIGNED_32 is set in type argument:2050Emit instructions for unaligned memory loads or stores. When2051SLJIT_UNALIGNED is not defined, the only way to access unaligned2052memory data is using sljit_emit_mem. Otherwise all operations (e.g.2053sljit_emit_op1/2, or sljit_emit_fop1/2) supports unaligned access.2054In general, the performance of unaligned memory accesses are often2055lower than aligned and should be avoided.20562057When a pair of registers is passed in reg argument:2058Emit instructions for moving data between a register pair and2059memory. The register pair can be specified by the SLJIT_REG_PAIR2060macro. The first register is loaded from or stored into the2061location specified by the mem/memw arguments, and the end address2062of this operation is the starting address of the data transfer2063between the second register and memory. The type argument must2064be SLJIT_MOV. The SLJIT_MEM_UNALIGNED / SLJIT_MEM_ALIGNED_*2065options are allowed for this operation.20662067type must be between SLJIT_MOV and SLJIT_MOV_P and can be2068combined (or'ed) with SLJIT_MEM_* flags2069reg is a register or register pair, which is the source or2070destination of the operation2071mem must be a memory operand20722073Flags: - (does not modify flags) */2074SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,2075sljit_s32 reg,2076sljit_s32 mem, sljit_sw memw);20772078/* Emit a single memory load or store with update instruction.2079When the requested instruction form is not supported by the CPU,2080it returns with SLJIT_ERR_UNSUPPORTED instead of emulating the2081instruction. This allows specializing tight loops based on2082the supported instruction forms (see SLJIT_MEM_SUPP flag).2083Absolute address (SLJIT_MEM0) forms are never supported2084and the base (first) register specified by the mem argument2085must not be SLJIT_SP and must also be different from the2086register specified by the reg argument.20872088type must be between SLJIT_MOV and SLJIT_MOV_P and can be2089combined (or'ed) with SLJIT_MEM_* flags2090reg is the source or destination register of the operation2091mem must be a memory operand20922093Flags: - (does not modify flags) */20942095SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type,2096sljit_s32 reg,2097sljit_s32 mem, sljit_sw memw);20982099/* Same as sljit_emit_mem except the followings:21002101Loading or storing a pair of registers is not supported.21022103type must be SLJIT_MOV_F64 or SLJIT_MOV_F32 and can be2104combined (or'ed) with SLJIT_MEM_* flags.2105freg is the source or destination floating point register2106of the operation2107mem must be a memory operand21082109Flags: - (does not modify flags) */21102111SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,2112sljit_s32 freg,2113sljit_s32 mem, sljit_sw memw);21142115/* Same as sljit_emit_mem_update except the followings:21162117type must be SLJIT_MOV_F64 or SLJIT_MOV_F32 and can be2118combined (or'ed) with SLJIT_MEM_* flags2119freg is the source or destination floating point register2120of the operation2121mem must be a memory operand21222123Flags: - (does not modify flags) */21242125SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type,2126sljit_s32 freg,2127sljit_s32 mem, sljit_sw memw);21282129/* The following options are used by several simd operations. */21302131/* Load data into a vector register, this is the default */2132#define SLJIT_SIMD_LOAD 0x0000002133/* Store data from a vector register */2134#define SLJIT_SIMD_STORE 0x0000012135/* The vector register contains floating point values */2136#define SLJIT_SIMD_FLOAT 0x0004002137/* Tests whether the operation is available */2138#define SLJIT_SIMD_TEST 0x0008002139/* Move data to/from a 64 bit (8 byte) long vector register */2140#define SLJIT_SIMD_REG_64 (3 << 12)2141/* Move data to/from a 128 bit (16 byte) long vector register */2142#define SLJIT_SIMD_REG_128 (4 << 12)2143/* Move data to/from a 256 bit (32 byte) long vector register */2144#define SLJIT_SIMD_REG_256 (5 << 12)2145/* Move data to/from a 512 bit (64 byte) long vector register */2146#define SLJIT_SIMD_REG_512 (6 << 12)2147/* Element size is 8 bit long (this is the default), usually cannot be combined with SLJIT_SIMD_FLOAT */2148#define SLJIT_SIMD_ELEM_8 (0 << 18)2149/* Element size is 16 bit long, usually cannot be combined with SLJIT_SIMD_FLOAT */2150#define SLJIT_SIMD_ELEM_16 (1 << 18)2151/* Element size is 32 bit long */2152#define SLJIT_SIMD_ELEM_32 (2 << 18)2153/* Element size is 64 bit long */2154#define SLJIT_SIMD_ELEM_64 (3 << 18)2155/* Element size is 128 bit long */2156#define SLJIT_SIMD_ELEM_128 (4 << 18)2157/* Element size is 256 bit long */2158#define SLJIT_SIMD_ELEM_256 (5 << 18)21592160/* The following options are used by sljit_emit_simd_mov()2161and sljit_emit_simd_op2(). */21622163/* Memory address is unaligned (this is the default) */2164#define SLJIT_SIMD_MEM_UNALIGNED (0 << 24)2165/* Memory address is 16 bit aligned */2166#define SLJIT_SIMD_MEM_ALIGNED_16 (1 << 24)2167/* Memory address is 32 bit aligned */2168#define SLJIT_SIMD_MEM_ALIGNED_32 (2 << 24)2169/* Memory address is 64 bit aligned */2170#define SLJIT_SIMD_MEM_ALIGNED_64 (3 << 24)2171/* Memory address is 128 bit aligned */2172#define SLJIT_SIMD_MEM_ALIGNED_128 (4 << 24)2173/* Memory address is 256 bit aligned */2174#define SLJIT_SIMD_MEM_ALIGNED_256 (5 << 24)2175/* Memory address is 512 bit aligned */2176#define SLJIT_SIMD_MEM_ALIGNED_512 (6 << 24)21772178/* Moves data between a vector register and memory.21792180If the operation is not supported, it returns with2181SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2182it does not emit any instructions.21832184type must be a combination of SLJIT_SIMD_* and2185SLJIT_SIMD_MEM_* options2186vreg is the source or destination vector register2187of the operation2188srcdst must be a memory operand or a vector register21892190Note:2191The alignment and element size must be2192less or equal than vector register size.21932194Flags: - (does not modify flags) */21952196SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_mov(struct sljit_compiler *compiler, sljit_s32 type,2197sljit_s32 vreg,2198sljit_s32 srcdst, sljit_sw srcdstw);21992200/* Replicates a scalar value to all lanes of a vector2201register.22022203If the operation is not supported, it returns with2204SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2205it does not emit any instructions.22062207type must be a combination of SLJIT_SIMD_* options2208except SLJIT_SIMD_STORE.2209vreg is the destination vector register of the operation2210src is the value which is replicated22112212Note:2213The src == SLJIT_IMM and srcw == 0 can be used to2214clear a register even when SLJIT_SIMD_FLOAT is set.22152216Flags: - (does not modify flags) */22172218SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_replicate(struct sljit_compiler *compiler, sljit_s32 type,2219sljit_s32 vreg,2220sljit_s32 src, sljit_sw srcw);22212222/* The following options are used by sljit_emit_simd_lane_mov(). */22232224/* Clear all bits of the simd register before loading the lane. */2225#define SLJIT_SIMD_LANE_ZERO 0x0000022226/* Sign extend the integer value stored from the lane. */2227#define SLJIT_SIMD_LANE_SIGNED 0x00000422282229/* Moves data between a vector register lane and a register or2230memory. If the srcdst argument is a register, it must be2231a floating point register when SLJIT_SIMD_FLOAT is specified,2232or a general purpose register otherwise.22332234If the operation is not supported, it returns with2235SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2236it does not emit any instructions.22372238type must be a combination of SLJIT_SIMD_* options2239Further options:2240SLJIT_32 - when SLJIT_SIMD_FLOAT is not set2241SLJIT_SIMD_LANE_SIGNED - when SLJIT_SIMD_STORE2242is set and SLJIT_SIMD_FLOAT is not set2243SLJIT_SIMD_LANE_ZERO - when SLJIT_SIMD_LOAD2244is specified2245vreg is the source or destination vector register2246of the operation2247lane_index is the index of the lane2248srcdst is the destination operand for loads, and2249source operand for stores22502251Note:2252The elem size must be lower than register size.22532254Flags: - (does not modify flags) */22552256SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_mov(struct sljit_compiler *compiler, sljit_s32 type,2257sljit_s32 vreg, sljit_s32 lane_index,2258sljit_s32 srcdst, sljit_sw srcdstw);22592260/* Replicates a scalar value from a lane to all lanes2261of a vector register.22622263If the operation is not supported, it returns with2264SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2265it does not emit any instructions.22662267type must be a combination of SLJIT_SIMD_* options2268except SLJIT_SIMD_STORE.2269vreg is the destination vector register of the operation2270src is the vector register which lane is replicated2271src_lane_index is the lane index of the src register22722273Flags: - (does not modify flags) */22742275SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_replicate(struct sljit_compiler *compiler, sljit_s32 type,2276sljit_s32 vreg,2277sljit_s32 src, sljit_s32 src_lane_index);22782279/* The following options are used by sljit_emit_simd_load_extend(). */22802281/* Sign extend the integer elements */2282#define SLJIT_SIMD_EXTEND_SIGNED 0x0000022283/* Extend data to 16 bit */2284#define SLJIT_SIMD_EXTEND_16 (1 << 24)2285/* Extend data to 32 bit */2286#define SLJIT_SIMD_EXTEND_32 (2 << 24)2287/* Extend data to 64 bit */2288#define SLJIT_SIMD_EXTEND_64 (3 << 24)22892290/* Extend elements and stores them in a vector register.2291The extension operation increases the size of the2292elements (e.g. from 16 bit to 64 bit). For integer2293values, the extension can be signed or unsigned.22942295If the operation is not supported, it returns with2296SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2297it does not emit any instructions.22982299type must be a combination of SLJIT_SIMD_*, and2300SLJIT_SIMD_EXTEND_* options except SLJIT_SIMD_STORE2301vreg is the destination vector register of the operation2302src must be a memory operand or a vector register.2303In the latter case, the source elements are stored2304in the lower half of the register.23052306Flags: - (does not modify flags) */23072308SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_extend(struct sljit_compiler *compiler, sljit_s32 type,2309sljit_s32 vreg,2310sljit_s32 src, sljit_sw srcw);23112312/* Extract the highest bit (usually the sign bit) from2313each elements of a vector.23142315If the operation is not supported, it returns with2316SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2317it does not emit any instructions.23182319type must be a combination of SLJIT_SIMD_* and SLJIT_322320options except SLJIT_SIMD_LOAD2321vreg is the source vector register of the operation2322dst is the destination operand23232324Flags: - (does not modify flags) */23252326SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *compiler, sljit_s32 type,2327sljit_s32 vreg,2328sljit_s32 dst, sljit_sw dstw);23292330/* The following operations are used by sljit_emit_simd_op2(). */23312332/* Binary 'and' operation */2333#define SLJIT_SIMD_OP2_AND 0x0000012334/* Binary 'or' operation */2335#define SLJIT_SIMD_OP2_OR 0x0000022336/* Binary 'xor' operation */2337#define SLJIT_SIMD_OP2_XOR 0x0000032338/* Shuffle bytes of src1 using the indicies in src2 */2339#define SLJIT_SIMD_OP2_SHUFFLE 0x00000423402341/* Perform simd operations using vector registers.23422343If the operation is not supported, it returns with2344SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed,2345it does not emit any instructions.23462347type must be a combination of SLJIT_SIMD_*, SLJIT_SIMD_MEM_*2348and SLJIT_SIMD_OP2_* options except SLJIT_SIMD_LOAD2349and SLJIT_SIMD_STORE2350dst_vreg is the destination register of the operation2351src1_vreg is the first source register of the operation2352src2 is the second source operand of the operation23532354Flags: - (does not modify flags) */23552356SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *compiler, sljit_s32 type,2357sljit_s32 dst_vreg, sljit_s32 src1_vreg, sljit_s32 src2, sljit_sw src2w);23582359/* The following operations are used by sljit_emit_atomic_load() and2360sljit_emit_atomic_store() operations. */23612362/* Tests whether the atomic operation is available (does not generate2363any instructions). When a load from is allowed, its corresponding2364store form is allowed and vice versa. */2365#define SLJIT_ATOMIC_TEST 0x100002366/* The compiler must generate compare and swap instruction.2367When this bit is set, calling sljit_emit_atomic_load() is optional. */2368#define SLJIT_ATOMIC_USE_CAS 0x200002369/* The compiler must generate load-acquire and store-release instructions.2370When this bit is set, the temp_reg for sljit_emit_atomic_store is not used. */2371#define SLJIT_ATOMIC_USE_LS 0x4000023722373/* The sljit_emit_atomic_load and sljit_emit_atomic_store operation pair2374can perform an atomic read-modify-write operation. First, an unsigned2375value must be loaded from memory using sljit_emit_atomic_load. Then,2376the updated value must be written back to the same memory location by2377sljit_emit_atomic_store. A thread can only perform a single atomic2378operation at a time.23792380The following conditions must be satisfied, or the operation2381is undefined:2382- the address provided in mem_reg must be divisible by the size of2383the value (only naturally aligned updates are supported)2384- no memory operations are allowed between the load and store operations2385- the memory operation (op) and the base address (stored in mem_reg)2386passed to the load/store operations must be the same (the mem_reg2387can be a different register, only its value must be the same)2388- a store must always follow a load for the same transaction.23892390op must be between SLJIT_MOV and SLJIT_MOV_P2391dst_reg is the register where the data will be loaded into2392mem_reg is the base address of the memory load (it cannot be2393SLJIT_SP or a virtual register on x86-32)23942395Flags: - (does not modify flags) */2396SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_load(struct sljit_compiler *compiler, sljit_s32 op,2397sljit_s32 dst_reg,2398sljit_s32 mem_reg);23992400/* The sljit_emit_atomic_load and sljit_emit_atomic_store operations2401allows performing an atomic read-modify-write operation. See the2402description of sljit_emit_atomic_load.24032404op must be between SLJIT_MOV and SLJIT_MOV_P2405src_reg is the register which value is stored into the memory2406mem_reg is the base address of the memory store (it cannot be2407SLJIT_SP or a virtual register on x86-32)2408temp_reg is a scratch register, which must be initialized with2409the value loaded into the dst_reg during the corresponding2410sljit_emit_atomic_load operation, or the operation is undefined.2411The temp_reg register preserves its value, if the memory store2412is successful. Otherwise, its value is undefined.24132414Flags: ATOMIC_STORED2415if ATOMIC_STORED flag is set, it represents that the memory2416is updated with a new value. Otherwise the memory is unchanged. */2417SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler *compiler, sljit_s32 op,2418sljit_s32 src_reg,2419sljit_s32 mem_reg,2420sljit_s32 temp_reg);24212422/* Copies the base address of SLJIT_SP + offset to dst. The offset can2423represent the starting address of a value in the local data (stack).2424The offset is not limited by the local data limits, it can be any value.2425For example if an array of bytes are stored on the stack from2426offset 0x40, and R0 contains the offset of an array item plus 0x120,2427this item can be changed by two SLJIT instructions:24282429sljit_get_local_base(compiler, SLJIT_R1, 0, 0x40 - 0x120);2430sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0, SLJIT_IMM, 0x5);24312432Flags: - (may destroy flags) */2433SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset);24342435/* Store a value that can be changed at runtime. The constant2436can be managed by sljit_get_const_addr and sljit_set_const.24372438op must be SLJIT_MOV, SLJIT_MOV32, SLJIT_MOV_S32,2439SLJIT_MOV_U8, SLJIT_MOV32_U824402441Note: when SLJIT_MOV_U8 is used, and dst is a register,2442init_value supports a 9 bit signed value between [-256..255]24432444Flags: - (does not modify flags) */2445SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op,2446sljit_s32 dst, sljit_sw dstw,2447sljit_sw init_value);24482449/* Opcodes for sljit_emit_mov_addr. */24502451/* The address is suitable for jump/call target. */2452#define SLJIT_MOV_ADDR 02453/* The address is suitable for reading memory. */2454#define SLJIT_MOV_ABS_ADDR 12455/* Add absolute address. */2456#define SLJIT_ADD_ABS_ADDR 224572458/* Store the value of a label (see: sljit_set_label / sljit_set_target)2459Flags: - (does not modify flags) */2460SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_op_addr(struct sljit_compiler *compiler, sljit_s32 op,2461sljit_s32 dst, sljit_sw dstw);24622463/* Returns the address of a label after sljit_generate_code is called, and2464before the compiler is freed by sljit_free_compiler. It is recommended2465to save these addresses elsewhere before sljit_free_compiler is called.24662467The address returned by sljit_get_label_addr is suitable for a jump/call2468target, and the address returned by sljit_get_label_abs_addr is suitable2469for reading memory. */24702471static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->u.addr; }2472#if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)2473static SLJIT_INLINE sljit_uw sljit_get_label_abs_addr(struct sljit_label *label) { return label->u.addr & ~(sljit_uw)1; }2474#else /* !SLJIT_CONFIG_ARM_THUMB2 */2475static SLJIT_INLINE sljit_uw sljit_get_label_abs_addr(struct sljit_label *label) { return label->u.addr; }2476#endif /* SLJIT_CONFIG_ARM_THUMB2 */24772478/* Returns the address of jump and const instructions after sljit_generate_code2479is called, and before the compiler is freed by sljit_free_compiler. It is2480recommended to save these addresses elsewhere before sljit_free_compiler is called. */24812482static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; }2483static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { return const_->addr; }24842485/* Only the address and executable offset are required to perform dynamic2486code modifications. See sljit_get_executable_offset function. */2487SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset);2488/* The op opcode must be set to the same value that was passed to sljit_emit_const. */2489SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset);24902491/* Only a single buffer is writable at a time, so sljit_read_only_buffer_end_writing()2492must be called before sljit_read_only_buffer_start_writing() is called again. */2493SLJIT_API_FUNC_ATTRIBUTE void* sljit_read_only_buffer_start_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset);2494SLJIT_API_FUNC_ATTRIBUTE void sljit_read_only_buffer_end_writing(sljit_uw addr, sljit_uw size, sljit_sw executable_offset);24952496/* --------------------------------------------------------------------- */2497/* CPU specific functions */2498/* --------------------------------------------------------------------- */24992500/* Types for sljit_get_register_index */25012502/* General purpose (integer) registers. */2503#define SLJIT_GP_REGISTER 02504/* Floating point registers. */2505#define SLJIT_FLOAT_REGISTER 125062507/* The following function is a helper function for sljit_emit_op_custom.2508It returns with the real machine register index ( >=0 ) of any registers.25092510When type is SLJIT_GP_REGISTER:2511reg must be an SLJIT_R(i), SLJIT_S(i), or SLJIT_SP register25122513When type is SLJIT_FLOAT_REGISTER:2514reg must be an SLJIT_FR(i) or SLJIT_FS(i) register25152516When type is SLJIT_SIMD_REG_64 / 128 / 256 / 512 :2517reg must be an SLJIT_FR(i) or SLJIT_FS(i) register25182519Note: it returns with -1 for unknown registers, such as virtual2520registers on x86-32 or unsupported simd registers. */25212522SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 type, sljit_s32 reg);25232524/* Any instruction can be inserted into the instruction stream by2525sljit_emit_op_custom. It has a similar purpose as inline assembly.2526The size parameter must match to the instruction size of the target2527architecture:25282529x86: 0 < size <= 15, the instruction argument can be byte aligned.2530Thumb2: if size == 2, the instruction argument must be 2 byte aligned.2531if size == 4, the instruction argument must be 4 byte aligned.2532s390x: size can be 2, 4, or 6, the instruction argument can be byte aligned.2533Otherwise: size must be 4 and instruction argument must be 4 byte aligned. */25342535SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,2536void *instruction, sljit_u32 size);25372538/* Flags were set by a 32 bit operation. */2539#define SLJIT_CURRENT_FLAGS_32 SLJIT_3225402541/* Flags were set by an ADD or ADDC operations. */2542#define SLJIT_CURRENT_FLAGS_ADD 0x012543/* Flags were set by a SUB or SUBC operation. */2544#define SLJIT_CURRENT_FLAGS_SUB 0x0225452546/* Flags were set by sljit_emit_op2u with SLJIT_SUB opcode.2547Must be combined with SLJIT_CURRENT_FLAGS_SUB. */2548#define SLJIT_CURRENT_FLAGS_COMPARE 0x0425492550/* Flags were set by sljit_emit_op2cmpz operation. */2551#define SLJIT_CURRENT_FLAGS_OP2CMPZ 0x0825522553/* Define the currently available CPU status flags. It is usually used after2554an sljit_emit_label or sljit_emit_op_custom operations to define which CPU2555status flags are available.25562557The current_flags must be a valid combination of SLJIT_SET_* and2558SLJIT_CURRENT_FLAGS_* constants. */25592560SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler,2561sljit_s32 current_flags);25622563/* --------------------------------------------------------------------- */2564/* Serialization functions */2565/* --------------------------------------------------------------------- */25662567/* Label/jump/const enumeration functions. The items in each group2568are enumerated in creation order. Serialization / deserialization2569preserves this order for each group. For example the fifth label2570after deserialization refers to the same machine code location as2571the fifth label before the serialization. */2572static SLJIT_INLINE struct sljit_label *sljit_get_first_label(struct sljit_compiler *compiler) { return compiler->labels; }2573static SLJIT_INLINE struct sljit_jump *sljit_get_first_jump(struct sljit_compiler *compiler) { return compiler->jumps; }2574static SLJIT_INLINE struct sljit_const *sljit_get_first_const(struct sljit_compiler *compiler) { return compiler->consts; }25752576static SLJIT_INLINE struct sljit_label *sljit_get_next_label(struct sljit_label *label) { return label->next; }2577static SLJIT_INLINE struct sljit_jump *sljit_get_next_jump(struct sljit_jump *jump) { return jump->next; }2578static SLJIT_INLINE struct sljit_const *sljit_get_next_const(struct sljit_const *const_) { return const_->next; }25792580/* A number starting from 0 is assigned to each label, which2581represents its creation index. The first label created by the2582compiler has index 0, the second one has index 1, the third one2583has index 2, and so on. The returned value is unspecified after2584sljit_generate_code() is called.25852586It is recommended to use this function to get the creation index2587of a label, since sljit_emit_label() may return with the last label,2588if no code is generated since the last sljit_emit_label() call. */2589SLJIT_API_FUNC_ATTRIBUTE sljit_uw sljit_get_label_index(struct sljit_label *label);25902591/* The sljit_jump_has_label() and sljit_jump_has_target() functions2592returns non-zero value if a label or target is set for the jump2593respectively. Both may return with a zero value. The other two2594functions return the value assigned to the jump. */2595SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_label(struct sljit_jump *jump);2596static SLJIT_INLINE struct sljit_label *sljit_jump_get_label(struct sljit_jump *jump) { return jump->u.label; }2597SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_target(struct sljit_jump *jump);2598static SLJIT_INLINE sljit_uw sljit_jump_get_target(struct sljit_jump *jump) { return jump->u.target; }2599SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_is_mov_addr(struct sljit_jump *jump);26002601/* Option bits for sljit_serialize_compiler. */26022603/* When debugging is enabled, the serialized buffer contains2604debugging information unless this option is specified. */2605#define SLJIT_SERIALIZE_IGNORE_DEBUG 0x126062607/* Serialize the internal structure of the compiler into a buffer.2608If the serialization is successful, the returned value is a newly2609allocated buffer which is allocated by the memory allocator assigned2610to the compiler. Otherwise the returned value is NULL. Unlike2611sljit_generate_code(), serialization does not modify the internal2612state of the compiler, so the code generation can be continued.26132614options must be the combination of SLJIT_SERIALIZE_* option bits2615size is an output argument, which is set to the byte size of2616the result buffer if the operation is successful26172618Notes:2619- This function is useful for ahead-of-time compilation (AOT).2620- The returned buffer must be freed later by the caller.2621The SLJIT_FREE() macro is suitable for this purpose:2622SLJIT_FREE(returned_buffer, sljit_get_allocator_data(compiler))2623- Memory allocated by sljit_alloc_memory() is not serialized.2624- The type of the returned buffer is sljit_uw* to emphasize that2625the buffer is word aligned. However, the 'size' output argument2626contains the byte size, so this value is always divisible by2627sizeof(sljit_uw).2628*/2629SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compiler *compiler,2630sljit_s32 options, sljit_uw *size);26312632/* Construct a new compiler instance from a buffer produced by2633sljit_serialize_compiler(). If the operation is successful, the new2634compiler instance is returned. Otherwise the returned value is NULL.26352636buffer points to a word aligned memory data which was2637created by sljit_serialize_compiler()2638size is the byte size of the buffer2639options must be 02640allocator_data specify an allocator specific data, see2641sljit_create_compiler() for further details26422643Notes:2644- Labels assigned to jumps are restored with their2645corresponding label in the label set created by2646the deserializer. Target addresses assigned to2647jumps are also restored. Uninitialized jumps2648remain uninitialized.2649- After the deserialization, sljit_generate_code() does2650not need to be the next operation on the returned2651compiler, the code generation can be continued.2652Even sljit_serialize_compiler() can be called again.2653- When debugging is enabled, a buffers without debug2654information cannot be deserialized.2655*/2656SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit_uw* buffer, sljit_uw size,2657sljit_s32 options, void *allocator_data);26582659/* --------------------------------------------------------------------- */2660/* Miscellaneous utility functions */2661/* --------------------------------------------------------------------- */26622663/* Get the human readable name of the platform. Can be useful on platforms2664like ARM, where ARM and Thumb2 functions can be mixed, and it is useful2665to know the type of the code generator. */2666SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void);26672668/* Portable helper function to get an offset of a member.2669Same as offsetof() macro defined in stddef.h */2670#define SLJIT_OFFSETOF(base, member) ((sljit_sw)(&((base*)0x10)->member) - 0x10)26712672#if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)26732674/* The sljit_stack structure and its manipulation functions provides2675an implementation for a top-down stack. The stack top is stored2676in the end field of the sljit_stack structure and the stack goes2677down to the min_start field, so the memory region reserved for2678this stack is between min_start (inclusive) and end (exclusive)2679fields. However the application can only use the region between2680start (inclusive) and end (exclusive) fields. The sljit_stack_resize2681function can be used to extend this region up to min_start.26822683This feature uses the "address space reserve" feature of modern2684operating systems. Instead of allocating a large memory block2685applications can allocate a small memory region and extend it2686later without moving the content of the memory area. Therefore2687after a successful resize by sljit_stack_resize all pointers into2688this region are still valid.26892690Note:2691this structure may not be supported by all operating systems.2692end and max_limit fields are aligned to PAGE_SIZE bytes (usually26934 Kbyte or more).2694stack should grow in larger steps, e.g. 4Kbyte, 16Kbyte or more. */26952696struct sljit_stack {2697/* User data, anything can be stored here.2698Initialized to the same value as the end field. */2699sljit_u8 *top;2700/* These members are read only. */2701/* End address of the stack */2702sljit_u8 *end;2703/* Current start address of the stack. */2704sljit_u8 *start;2705/* Lowest start address of the stack. */2706sljit_u8 *min_start;2707};27082709/* Allocates a new stack. Returns NULL if unsuccessful.2710Note: see sljit_create_compiler for the explanation of allocator_data. */2711SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_FUNC sljit_allocate_stack(sljit_uw start_size, sljit_uw max_size, void *allocator_data);2712SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_free_stack(struct sljit_stack *stack, void *allocator_data);27132714/* Can be used to increase (extend) or decrease (shrink) the stack2715memory area. Returns with new_start if successful and NULL otherwise.2716It always fails if new_start is less than min_start or greater or equal2717than end fields. The fields of the stack are not changed if the returned2718value is NULL (the current memory content is never lost). */2719SLJIT_API_FUNC_ATTRIBUTE sljit_u8 *SLJIT_FUNC sljit_stack_resize(struct sljit_stack *stack, sljit_u8 *new_start);27202721#endif /* (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) */27222723#if !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)27242725/* Get the entry address of a given function (signed, unsigned result). */2726#define SLJIT_FUNC_ADDR(func_name) ((sljit_sw)func_name)2727#define SLJIT_FUNC_UADDR(func_name) ((sljit_uw)func_name)27282729#else /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */27302731/* All JIT related code should be placed in the same context (library, binary, etc.). */27322733/* Get the entry address of a given function (signed, unsigned result). */2734#define SLJIT_FUNC_ADDR(func_name) (*(sljit_sw*)(void*)func_name)2735#define SLJIT_FUNC_UADDR(func_name) (*(sljit_uw*)(void*)func_name)27362737/* For powerpc64, the function pointers point to a context descriptor. */2738struct sljit_function_context {2739sljit_uw addr;2740sljit_uw r2;2741sljit_uw r11;2742};27432744/* Fill the context arguments using the addr and the function.2745If func_ptr is NULL, it will not be set to the address of context2746If addr is NULL, the function address also comes from the func pointer. */2747SLJIT_API_FUNC_ATTRIBUTE void sljit_set_function_context(void** func_ptr, struct sljit_function_context* context, sljit_uw addr, void* func);27482749#endif /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */27502751#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)2752/* Free unused executable memory. The allocator keeps some free memory2753around to reduce the number of OS executable memory allocations.2754This improves performance since these calls are costly. However2755it is sometimes desired to free all unused memory regions, e.g.2756before the application terminates. */2757SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);2758#endif /* SLJIT_EXECUTABLE_ALLOCATOR */27592760#ifdef __cplusplus2761} /* extern "C" */2762#endif /* __cplusplus */27632764#endif /* SLJIT_LIR_H_ */276527662767