Annotation of embedaddon/pcre/sljit/sljitLir.h, revision 1.1.1.5

1.1       misho       1: /*
                      2:  *    Stack-less Just-In-Time compiler
                      3:  *
1.1.1.2   misho       4:  *    Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
1.1       misho       5:  *
                      6:  * Redistribution and use in source and binary forms, with or without modification, are
                      7:  * permitted provided that the following conditions are met:
                      8:  *
                      9:  *   1. Redistributions of source code must retain the above copyright notice, this list of
                     10:  *      conditions and the following disclaimer.
                     11:  *
                     12:  *   2. Redistributions in binary form must reproduce the above copyright notice, this list
                     13:  *      of conditions and the following disclaimer in the documentation and/or other materials
                     14:  *      provided with the distribution.
                     15:  *
                     16:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
                     17:  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     18:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
                     19:  * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
                     20:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
                     21:  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
                     22:  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     23:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
                     24:  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     25:  */
                     26: 
                     27: #ifndef _SLJIT_LIR_H_
                     28: #define _SLJIT_LIR_H_
                     29: 
                     30: /*
                     31:    ------------------------------------------------------------------------
                     32:     Stack-Less JIT compiler for multiple architectures (x86, ARM, PowerPC)
                     33:    ------------------------------------------------------------------------
                     34: 
                     35:    Short description
                     36:     Advantages:
1.1.1.4   misho      37:       - The execution can be continued from any LIR instruction. In other
                     38:         words, it is possible to jump to any label from anywhere, even from
                     39:         a code fragment, which is compiled later, if both compiled code
                     40:         shares the same context. See sljit_emit_enter for more details
                     41:       - Supports self modifying code: target of (conditional) jump and call
                     42:         instructions and some constant values can be dynamically modified
                     43:         during runtime
1.1       misho      44:         - although it is not suggested to do it frequently
1.1.1.4   misho      45:         - can be used for inline caching: save an important value once
                     46:           in the instruction stream
                     47:         - since this feature limits the optimization possibilities, a
                     48:           special flag must be passed at compile time when these
                     49:           instructions are emitted
1.1       misho      50:       - A fixed stack space can be allocated for local variables
                     51:       - The compiler is thread-safe
1.1.1.3   misho      52:       - The compiler is highly configurable through preprocessor macros.
                     53:         You can disable unneeded features (multithreading in single
                     54:         threaded applications), and you can use your own system functions
                     55:         (including memory allocators). See sljitConfig.h
1.1       misho      56:     Disadvantages:
1.1.1.4   misho      57:       - No automatic register allocation, and temporary results are
                     58:         not stored on the stack. (hence the name comes)
1.1       misho      59:       - Limited number of registers (only 6+4 integer registers, max 3+2
1.1.1.4   misho      60:         scratch, max 3+2 saved and 6 floating point registers)
1.1       misho      61:     In practice:
                     62:       - This approach is very effective for interpreters
1.1.1.2   misho      63:         - One of the saved registers typically points to a stack interface
1.1.1.4   misho      64:         - It can jump to any exception handler anytime (even if it belongs
                     65:           to another function)
                     66:         - Hot paths can be modified during runtime reflecting the changes
1.1       misho      67:           of the fastest execution path of the dynamic language
                     68:         - SLJIT supports complex memory addressing modes
1.1.1.4   misho      69:         - mainly position and context independent code (except some cases)
1.1       misho      70: 
                     71:     For valgrind users:
                     72:       - pass --smc-check=all argument to valgrind, since JIT is a "self-modifying code"
                     73: */
                     74: 
                     75: #if !(defined SLJIT_NO_DEFAULT_CONFIG && SLJIT_NO_DEFAULT_CONFIG)
                     76: #include "sljitConfig.h"
                     77: #endif
1.1.1.2   misho      78: 
                     79: /* The following header file defines useful macros for fine tuning
1.1.1.4   misho      80: sljit based code generators. They are listed in the beginning
1.1.1.2   misho      81: of sljitConfigInternal.h */
                     82: 
1.1       misho      83: #include "sljitConfigInternal.h"
                     84: 
                     85: /* --------------------------------------------------------------------- */
                     86: /*  Error codes                                                          */
                     87: /* --------------------------------------------------------------------- */
                     88: 
                     89: /* Indicates no error. */
                     90: #define SLJIT_SUCCESS                  0
                     91: /* After the call of sljit_generate_code(), the error code of the compiler
                     92:    is set to this value to avoid future sljit calls (in debug mode at least).
                     93:    The complier should be freed after sljit_generate_code(). */
                     94: #define SLJIT_ERR_COMPILED             1
                     95: /* Cannot allocate non executable memory. */
                     96: #define SLJIT_ERR_ALLOC_FAILED         2
                     97: /* Cannot allocate executable memory.
                     98:    Only for sljit_generate_code() */
                     99: #define SLJIT_ERR_EX_ALLOC_FAILED      3
                    100: /* return value for SLJIT_CONFIG_UNSUPPORTED empty architecture. */
                    101: #define SLJIT_ERR_UNSUPPORTED          4
                    102: 
                    103: /* --------------------------------------------------------------------- */
                    104: /*  Registers                                                            */
                    105: /* --------------------------------------------------------------------- */
                    106: 
                    107: #define SLJIT_UNUSED           0
                    108: 
1.1.1.4   misho     109: /* Scratch (temporary) registers whose may not preserve their values
                    110:    across function calls. */
                    111: #define SLJIT_SCRATCH_REG1     1
                    112: #define SLJIT_SCRATCH_REG2     2
                    113: #define SLJIT_SCRATCH_REG3     3
                    114: /* Note: extra registers cannot be used for memory addressing. */
                    115: /* Note: on x86-32, these registers are emulated (using stack
                    116:    loads & stores). */
1.1       misho     117: #define SLJIT_TEMPORARY_EREG1  4
                    118: #define SLJIT_TEMPORARY_EREG2  5
                    119: 
1.1.1.2   misho     120: /* Saved registers whose preserve their values across function calls. */
                    121: #define SLJIT_SAVED_REG1       6
                    122: #define SLJIT_SAVED_REG2       7
                    123: #define SLJIT_SAVED_REG3       8
1.1.1.4   misho     124: /* Note: extra registers cannot be used for memory addressing. */
                    125: /* Note: on x86-32, these registers are emulated (using stack
                    126:    loads & stores). */
1.1.1.2   misho     127: #define SLJIT_SAVED_EREG1      9
                    128: #define SLJIT_SAVED_EREG2      10
1.1       misho     129: 
1.1.1.3   misho     130: /* Read-only register (cannot be the destination of an operation).
                    131:    Only SLJIT_MEM1(SLJIT_LOCALS_REG) addressing mode is allowed since
                    132:    several ABIs has certain limitations about the stack layout. However
1.1.1.4   misho     133:    sljit_get_local_base() can be used to obtain the offset of a value
                    134:    on the stack. */
1.1       misho     135: #define SLJIT_LOCALS_REG       11
                    136: 
                    137: /* Number of registers. */
                    138: #define SLJIT_NO_TMP_REGISTERS 5
                    139: #define SLJIT_NO_GEN_REGISTERS 5
                    140: #define SLJIT_NO_REGISTERS     11
                    141: 
                    142: /* Return with machine word. */
                    143: 
1.1.1.4   misho     144: #define SLJIT_RETURN_REG       SLJIT_SCRATCH_REG1
1.1       misho     145: 
1.1.1.2   misho     146: /* x86 prefers specific registers for special purposes. In case of shift
1.1.1.4   misho     147:    by register it supports only SLJIT_SCRATCH_REG3 for shift argument
1.1.1.2   misho     148:    (which is the src2 argument of sljit_emit_op2). If another register is
                    149:    used, sljit must exchange data between registers which cause a minor
                    150:    slowdown. Other architectures has no such limitation. */
1.1       misho     151: 
1.1.1.4   misho     152: #define SLJIT_PREF_SHIFT_REG   SLJIT_SCRATCH_REG3
1.1       misho     153: 
                    154: /* --------------------------------------------------------------------- */
                    155: /*  Floating point registers                                             */
                    156: /* --------------------------------------------------------------------- */
                    157: 
                    158: /* Note: SLJIT_UNUSED as destination is not valid for floating point
                    159:      operations, since they cannot be used for setting flags. */
                    160: 
1.1.1.4   misho     161: /* Floating point operations are performed on double or
                    162:    single precision values. */
1.1       misho     163: 
1.1.1.4   misho     164: #define SLJIT_FLOAT_REG1               1
                    165: #define SLJIT_FLOAT_REG2               2
                    166: #define SLJIT_FLOAT_REG3               3
                    167: #define SLJIT_FLOAT_REG4               4
                    168: #define SLJIT_FLOAT_REG5               5
                    169: #define SLJIT_FLOAT_REG6               6
                    170: 
                    171: #define SLJIT_NO_FLOAT_REGISTERS       6
1.1       misho     172: 
                    173: /* --------------------------------------------------------------------- */
                    174: /*  Main structures and functions                                        */
                    175: /* --------------------------------------------------------------------- */
                    176: 
                    177: struct sljit_memory_fragment {
                    178:        struct sljit_memory_fragment *next;
                    179:        sljit_uw used_size;
1.1.1.4   misho     180:        /* Must be aligned to sljit_sw. */
1.1       misho     181:        sljit_ub memory[1];
                    182: };
                    183: 
                    184: struct sljit_label {
                    185:        struct sljit_label *next;
                    186:        sljit_uw addr;
                    187:        /* The maximum size difference. */
                    188:        sljit_uw size;
                    189: };
                    190: 
                    191: struct sljit_jump {
                    192:        struct sljit_jump *next;
                    193:        sljit_uw addr;
1.1.1.4   misho     194:        sljit_sw flags;
1.1       misho     195:        union {
                    196:                sljit_uw target;
                    197:                struct sljit_label* label;
                    198:        } u;
                    199: };
                    200: 
                    201: struct sljit_const {
                    202:        struct sljit_const *next;
                    203:        sljit_uw addr;
                    204: };
                    205: 
                    206: struct sljit_compiler {
1.1.1.4   misho     207:        sljit_si error;
1.1       misho     208: 
                    209:        struct sljit_label *labels;
                    210:        struct sljit_jump *jumps;
                    211:        struct sljit_const *consts;
                    212:        struct sljit_label *last_label;
                    213:        struct sljit_jump *last_jump;
                    214:        struct sljit_const *last_const;
                    215: 
                    216:        struct sljit_memory_fragment *buf;
                    217:        struct sljit_memory_fragment *abuf;
                    218: 
                    219:        /* Used local registers. */
1.1.1.4   misho     220:        sljit_si scratches;
1.1.1.2   misho     221:        /* Used saved registers. */
1.1.1.4   misho     222:        sljit_si saveds;
1.1       misho     223:        /* Local stack size. */
1.1.1.4   misho     224:        sljit_si local_size;
1.1       misho     225:        /* Code size. */
                    226:        sljit_uw size;
                    227:        /* For statistical purposes. */
                    228:        sljit_uw executable_size;
                    229: 
                    230: #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
1.1.1.4   misho     231:        sljit_si args;
                    232:        sljit_si locals_offset;
                    233:        sljit_si scratches_start;
                    234:        sljit_si saveds_start;
1.1       misho     235: #endif
                    236: 
                    237: #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1.1.1.4   misho     238:        sljit_si mode32;
1.1       misho     239: #endif
                    240: 
                    241: #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1.1.1.4   misho     242:        sljit_si flags_saved;
1.1       misho     243: #endif
                    244: 
                    245: #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
                    246:        /* Constant pool handling. */
                    247:        sljit_uw *cpool;
                    248:        sljit_ub *cpool_unique;
                    249:        sljit_uw cpool_diff;
                    250:        sljit_uw cpool_fill;
1.1.1.2   misho     251:        /* Other members. */
1.1       misho     252:        /* Contains pointer, "ldr pc, [...]" pairs. */
                    253:        sljit_uw patches;
                    254: #endif
                    255: 
                    256: #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
                    257:        /* Temporary fields. */
                    258:        sljit_uw shift_imm;
1.1.1.4   misho     259:        sljit_si cache_arg;
                    260:        sljit_sw cache_argw;
1.1       misho     261: #endif
                    262: 
                    263: #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1.1.1.4   misho     264:        sljit_si cache_arg;
                    265:        sljit_sw cache_argw;
1.1       misho     266: #endif
                    267: 
                    268: #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
1.1.1.4   misho     269:        sljit_sw imm;
                    270:        sljit_si cache_arg;
                    271:        sljit_sw cache_argw;
1.1       misho     272: #endif
                    273: 
                    274: #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1.1.1.4   misho     275:        sljit_si delay_slot;
                    276:        sljit_si cache_arg;
                    277:        sljit_sw cache_argw;
                    278: #endif
                    279: 
                    280: #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
                    281:        sljit_si delay_slot;
                    282:        sljit_si cache_arg;
                    283:        sljit_sw cache_argw;
1.1       misho     284: #endif
                    285: 
1.1.1.5 ! misho     286: #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
        !           287:        sljit_si cache_arg;
        !           288:        sljit_sw cache_argw;
        !           289: #endif
        !           290: 
1.1       misho     291: #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
                    292:        FILE* verbose;
                    293: #endif
                    294: 
1.1.1.3   misho     295: #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
                    296:        /* Local size passed to the functions. */
1.1.1.4   misho     297:        sljit_si logical_local_size;
1.1.1.3   misho     298: #endif
                    299: 
1.1       misho     300: #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1.1.1.4   misho     301:        sljit_si skip_checks;
1.1       misho     302: #endif
                    303: };
                    304: 
                    305: /* --------------------------------------------------------------------- */
                    306: /*  Main functions                                                       */
                    307: /* --------------------------------------------------------------------- */
                    308: 
                    309: /* Creates an sljit compiler.
                    310:    Returns NULL if failed. */
                    311: SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void);
1.1.1.4   misho     312: 
                    313: /* Free everything except the compiled machine code. */
1.1       misho     314: SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler);
                    315: 
1.1.1.4   misho     316: /* Returns the current error code. If an error is occurred, future sljit
                    317:    calls which uses the same compiler argument returns early with the same
                    318:    error code. Thus there is no need for checking the error after every
                    319:    call, it is enough to do it before the code is compiled. Removing
                    320:    these checks increases the performance of the compiling process. */
                    321: static SLJIT_INLINE sljit_si sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; }
1.1       misho     322: 
                    323: /*
                    324:    Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit,
1.1.1.4   misho     325:    and <= 128 bytes on 64 bit architectures. The memory area is owned by the
                    326:    compiler, and freed by sljit_free_compiler. The returned pointer is
                    327:    sizeof(sljit_sw) aligned. Excellent for allocating small blocks during
                    328:    the compiling, and no need to worry about freeing them. The size is
                    329:    enough to contain at most 16 pointers. If the size is outside of the range,
                    330:    the function will return with NULL. However, this return value does not
                    331:    indicate that there is no more memory (does not set the current error code
                    332:    of the compiler to out-of-memory status).
1.1       misho     333: */
1.1.1.4   misho     334: SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size);
1.1       misho     335: 
                    336: #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
                    337: /* Passing NULL disables verbose. */
                    338: SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose);
                    339: #endif
                    340: 
                    341: SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler);
                    342: SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code);
                    343: 
                    344: /*
1.1.1.4   misho     345:    After the machine code generation is finished we can retrieve the allocated
                    346:    executable memory size, although this area may not be fully filled with
                    347:    instructions depending on some optimizations. This function is useful only
                    348:    for statistical purposes.
1.1       misho     349: 
                    350:    Before a successful code generation, this function returns with 0.
                    351: */
                    352: static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; }
                    353: 
1.1.1.4   misho     354: /* Instruction generation. Returns with any error code. If there is no
                    355:    error, they return with SLJIT_SUCCESS. */
1.1       misho     356: 
                    357: /*
1.1.1.2   misho     358:    The executable code is basically a function call from the viewpoint of
                    359:    the C language. The function calls must obey to the ABI (Application
                    360:    Binary Interface) of the platform, which specify the purpose of machine
                    361:    registers and stack handling among other things. The sljit_emit_enter
                    362:    function emits the necessary instructions for setting up a new context
                    363:    for the executable code and moves function arguments to the saved
                    364:    registers. The number of arguments are specified in the "args"
                    365:    parameter and the first argument goes to SLJIT_SAVED_REG1, the second
1.1.1.4   misho     366:    goes to SLJIT_SAVED_REG2 and so on. The number of scratch and
                    367:    saved registers are passed in "scratches" and "saveds" arguments
1.1.1.2   misho     368:    respectively. Since the saved registers contains the arguments,
                    369:    "args" must be less or equal than "saveds". The sljit_emit_enter
                    370:    is also capable of allocating a stack space for local variables. The
                    371:    "local_size" argument contains the size in bytes of this local area
                    372:    and its staring address is stored in SLJIT_LOCALS_REG. However
                    373:    the SLJIT_LOCALS_REG is not necessary the machine stack pointer.
                    374:    The memory bytes between SLJIT_LOCALS_REG (inclusive) and
                    375:    SLJIT_LOCALS_REG + local_size (exclusive) can be modified freely
                    376:    until the function returns. The stack space is uninitialized.
1.1       misho     377: 
1.1.1.4   misho     378:    Note: every call of sljit_emit_enter and sljit_set_context
                    379:          overwrites the previous context. */
1.1       misho     380: 
                    381: #define SLJIT_MAX_LOCAL_SIZE   65536
                    382: 
1.1.1.4   misho     383: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_enter(struct sljit_compiler *compiler,
                    384:        sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size);
1.1.1.2   misho     385: 
                    386: /* The machine code has a context (which contains the local stack space size,
                    387:    number of used registers, etc.) which initialized by sljit_emit_enter. Several
                    388:    functions (like sljit_emit_return) requres this context to be able to generate
                    389:    the appropriate code. However, some code fragments (like inline cache) may have
                    390:    no normal entry point so their context is unknown for the compiler. Using the
1.1.1.4   misho     391:    function below we can specify their context.
1.1       misho     392: 
1.1.1.2   misho     393:    Note: every call of sljit_emit_enter and sljit_set_context overwrites
                    394:          the previous context. */
1.1       misho     395: 
1.1.1.2   misho     396: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler,
1.1.1.4   misho     397:        sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size);
1.1       misho     398: 
1.1.1.2   misho     399: /* Return from machine code.  The op argument can be SLJIT_UNUSED which means the
                    400:    function does not return with anything or any opcode between SLJIT_MOV and
1.1.1.4   misho     401:    SLJIT_MOV_P (see sljit_emit_op1). As for src and srcw they must be 0 if op
1.1.1.2   misho     402:    is SLJIT_UNUSED, otherwise see below the description about source and
                    403:    destination arguments. */
1.1       misho     404: 
1.1.1.4   misho     405: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op,
                    406:        sljit_si src, sljit_sw srcw);
                    407: 
                    408: /* Fast calling mechanism for utility functions (see SLJIT_FAST_CALL). All registers and
                    409:    even the stack frame is passed to the callee. The return address is preserved in
                    410:    dst/dstw by sljit_emit_fast_enter (the type of the value stored by this function
                    411:    is sljit_p), and sljit_emit_fast_return can use this as a return value later. */
                    412: 
                    413: /* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine
                    414:    instructions are needed. Excellent for small uility functions, where saving registers
                    415:    and setting up a new stack frame would cost too much performance. However, it is still
                    416:    possible to return to the address of the caller (or anywhere else). */
1.1       misho     417: 
                    418: /* Note: flags are not changed (unlike sljit_emit_enter / sljit_emit_return). */
                    419: 
                    420: /* Note: although sljit_emit_fast_return could be replaced by an ijump, it is not suggested,
                    421:    since many architectures do clever branch prediction on call / return instruction pairs. */
                    422: 
1.1.1.4   misho     423: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw);
                    424: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw);
1.1       misho     425: 
                    426: /*
                    427:    Source and destination values for arithmetical instructions
                    428:     imm              - a simple immediate value (cannot be used as a destination)
                    429:     reg              - any of the registers (immediate argument must be 0)
                    430:     [imm]            - absolute immediate memory address
                    431:     [reg+imm]        - indirect memory address
                    432:     [reg+(reg<<imm)] - indirect indexed memory address (shift must be between 0 and 3)
1.1.1.4   misho     433:                        useful for (byte, half, int, sljit_sw) array access
1.1       misho     434:                        (fully supported by both x86 and ARM architectures, and cheap operation on others)
                    435: */
                    436: 
                    437: /*
1.1.1.2   misho     438:    IMPORATNT NOTE: memory access MUST be naturally aligned except
                    439:                    SLJIT_UNALIGNED macro is defined and its value is 1.
                    440: 
1.1       misho     441:      length | alignment
                    442:    ---------+-----------
1.1.1.4   misho     443:      byte   | 1 byte (any physical_address is accepted)
                    444:      half   | 2 byte (physical_address & 0x1 == 0)
                    445:      int    | 4 byte (physical_address & 0x3 == 0)
                    446:      word   | 4 byte if SLJIT_32BIT_ARCHITECTURE is defined and its value is 1
1.1.1.2   misho     447:             | 8 byte if SLJIT_64BIT_ARCHITECTURE is defined and its value is 1
1.1.1.4   misho     448:     pointer | size of sljit_p type (4 byte on 32 bit machines, 4 or 8 byte
                    449:             | on 64 bit machines)
1.1       misho     450: 
1.1.1.4   misho     451:    Note:   Different architectures have different addressing limitations.
                    452:            A single instruction is enough for the following addressing
                    453:            modes. Other adrressing modes are emulated by instruction
                    454:            sequences. This information could help to improve those code
                    455:            generators which focuses only a few architectures.
                    456: 
                    457:    x86:    [reg+imm], -2^32+1 <= imm <= 2^32-1 (full address space on x86-32)
                    458:            [reg+(reg<<imm)] is supported
                    459:            [imm], -2^32+1 <= imm <= 2^32-1 is supported
                    460:            Write-back is not supported
                    461:    arm:    [reg+imm], -4095 <= imm <= 4095 or -255 <= imm <= 255 for signed
                    462:                 bytes, any halfs or floating point values)
                    463:            [reg+(reg<<imm)] is supported
                    464:            Write-back is supported
                    465:    arm-t2: [reg+imm], -255 <= imm <= 4095
                    466:            [reg+(reg<<imm)] is supported
                    467:            Write back is supported only for [reg+imm], where -255 <= imm <= 255
                    468:    ppc:    [reg+imm], -65536 <= imm <= 65535. 64 bit loads/stores and 32 bit
                    469:                 signed load on 64 bit requires immediates divisible by 4.
                    470:                 [reg+imm] is not supported for signed 8 bit values.
                    471:            [reg+reg] is supported
                    472:            Write-back is supported except for one instruction: 32 bit signed
                    473:                 load with [reg+imm] addressing mode on 64 bit.
                    474:    mips:   [reg+imm], -65536 <= imm <= 65535
                    475:    sparc:  [reg+imm], -4096 <= imm <= 4095
                    476:            [reg+reg] is supported
1.1       misho     477: */
                    478: 
                    479: /* Register output: simply the name of the register.
                    480:    For destination, you can use SLJIT_UNUSED as well. */
                    481: #define SLJIT_MEM              0x100
                    482: #define SLJIT_MEM0()           (SLJIT_MEM)
                    483: #define SLJIT_MEM1(r1)         (SLJIT_MEM | (r1))
                    484: #define SLJIT_MEM2(r1, r2)     (SLJIT_MEM | (r1) | ((r2) << 4))
                    485: #define SLJIT_IMM              0x200
                    486: 
                    487: /* Set 32 bit operation mode (I) on 64 bit CPUs. The flag is totally ignored on
1.1.1.4   misho     488:    32 bit CPUs. If this flag is set for an arithmetic operation, it uses only the
                    489:    lower 32 bit of the input register(s), and set the CPU status flags according
                    490:    to the 32 bit result. The higher 32 bits are undefined for both the input and
                    491:    output. However, the CPU might not ignore those higher 32 bits, like MIPS, which
                    492:    expects it to be the sign extension of the lower 32 bit. All 32 bit operations
                    493:    are undefined, if this condition is not fulfilled. Therefore, when SLJIT_INT_OP
                    494:    is specified, all register arguments must be the result of other operations with
                    495:    the same SLJIT_INT_OP flag. In other words, although a register can hold either
                    496:    a 64 or 32 bit value, these values cannot be mixed. The only exceptions are
                    497:    SLJIT_IMOV and SLJIT_IMOVU (SLJIT_MOV_SI/SLJIT_MOV_UI/SLJIT_MOVU_SI/SLJIT_MOV_UI
                    498:    with SLJIT_INT_OP flag) which can convert any source argument to SLJIT_INT_OP
                    499:    compatible result. This conversion might be unnecessary on some CPUs like x86-64,
                    500:    since the upper 32 bit is always ignored. In this case SLJIT is clever enough
                    501:    to not generate any instructions if the source and destination operands are the
                    502:    same registers. Affects sljit_emit_op0, sljit_emit_op1 and sljit_emit_op2. */
1.1       misho     503: #define SLJIT_INT_OP           0x100
                    504: 
1.1.1.4   misho     505: /* Single precision mode (SP). This flag is similar to SLJIT_INT_OP, just
                    506:    it applies to floating point registers (it is even the same bit). When
                    507:    this flag is passed, the CPU performs single precision floating point
                    508:    operations. Similar to SLJIT_INT_OP, all register arguments must be the
                    509:    result of other floating point operations with this flag. Affects
                    510:    sljit_emit_fop1, sljit_emit_fop2 and sljit_emit_fcmp. */
                    511: #define SLJIT_SINGLE_OP                0x100
                    512: 
1.1       misho     513: /* Common CPU status flags for all architectures (x86, ARM, PPC)
                    514:     - carry flag
                    515:     - overflow flag
                    516:     - zero flag
                    517:     - negative/positive flag (depends on arc)
                    518:    On mips, these flags are emulated by software. */
                    519: 
                    520: /* By default, the instructions may, or may not set the CPU status flags.
                    521:    Forcing to set or keep status flags can be done with the following flags: */
                    522: 
                    523: /* Note: sljit tries to emit the minimum number of instructions. Using these
                    524:    flags can increase them, so use them wisely to avoid unnecessary code generation. */
                    525: 
                    526: /* Set Equal (Zero) status flag (E). */
                    527: #define SLJIT_SET_E                    0x0200
                    528: /* Set signed status flag (S). */
                    529: #define SLJIT_SET_S                    0x0400
                    530: /* Set unsgined status flag (U). */
                    531: #define SLJIT_SET_U                    0x0800
                    532: /* Set signed overflow flag (O). */
                    533: #define SLJIT_SET_O                    0x1000
                    534: /* Set carry flag (C).
                    535:    Note: Kinda unsigned overflow, but behaves differently on various cpus. */
                    536: #define SLJIT_SET_C                    0x2000
                    537: /* Do not modify the flags (K).
                    538:    Note: This flag cannot be combined with any other SLJIT_SET_* flag. */
                    539: #define SLJIT_KEEP_FLAGS               0x4000
                    540: 
                    541: /* Notes:
                    542:      - you cannot postpone conditional jump instructions except if noted that
                    543:        the instruction does not set flags (See: SLJIT_KEEP_FLAGS).
                    544:      - flag combinations: '|' means 'logical or'. */
                    545: 
                    546: /* Flags: - (never set any flags)
                    547:    Note: breakpoint instruction is not supported by all architectures (namely ppc)
                    548:          It falls back to SLJIT_NOP in those cases. */
                    549: #define SLJIT_BREAKPOINT               0
                    550: /* Flags: - (never set any flags)
                    551:    Note: may or may not cause an extra cycle wait
                    552:          it can even decrease the runtime in a few cases. */
                    553: #define SLJIT_NOP                      1
1.1.1.4   misho     554: /* Flags: - (may destroy flags)
                    555:    Unsigned multiplication of SLJIT_SCRATCH_REG1 and SLJIT_SCRATCH_REG2.
                    556:    Result goes to SLJIT_SCRATCH_REG2:SLJIT_SCRATCH_REG1 (high:low) word */
1.1.1.2   misho     557: #define SLJIT_UMUL                     2
1.1.1.4   misho     558: /* Flags: - (may destroy flags)
                    559:    Signed multiplication of SLJIT_SCRATCH_REG1 and SLJIT_SCRATCH_REG2.
                    560:    Result goes to SLJIT_SCRATCH_REG2:SLJIT_SCRATCH_REG1 (high:low) word */
1.1.1.2   misho     561: #define SLJIT_SMUL                     3
1.1.1.4   misho     562: /* Flags: I - (may destroy flags)
                    563:    Unsigned divide of the value in SLJIT_SCRATCH_REG1 by the value in SLJIT_SCRATCH_REG2.
                    564:    The result is placed in SLJIT_SCRATCH_REG1 and the remainder goes to SLJIT_SCRATCH_REG2.
                    565:    Note: if SLJIT_SCRATCH_REG2 contains 0, the behaviour is undefined. */
1.1.1.2   misho     566: #define SLJIT_UDIV                     4
1.1.1.4   misho     567: #define SLJIT_IUDIV                    (SLJIT_UDIV | SLJIT_INT_OP)
                    568: /* Flags: I - (may destroy flags)
                    569:    Signed divide of the value in SLJIT_SCRATCH_REG1 by the value in SLJIT_SCRATCH_REG2.
                    570:    The result is placed in SLJIT_SCRATCH_REG1 and the remainder goes to SLJIT_SCRATCH_REG2.
                    571:    Note: if SLJIT_SCRATCH_REG2 contains 0, the behaviour is undefined. */
1.1.1.2   misho     572: #define SLJIT_SDIV                     5
1.1.1.4   misho     573: #define SLJIT_ISDIV                    (SLJIT_SDIV | SLJIT_INT_OP)
1.1       misho     574: 
1.1.1.4   misho     575: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op);
1.1       misho     576: 
                    577: /* Notes for MOV instructions:
                    578:    U = Mov with update (post form). If source or destination defined as SLJIT_MEM1(r1)
                    579:        or SLJIT_MEM2(r1, r2), r1 is increased by the sum of r2 and the constant argument
                    580:    UB = unsigned byte (8 bit)
                    581:    SB = signed byte (8 bit)
1.1.1.4   misho     582:    UH = unsigned half (16 bit)
                    583:    SH = signed half (16 bit)
                    584:    UI = unsigned int (32 bit)
                    585:    SI = signed int (32 bit)
                    586:    P  = pointer (sljit_p) size */
1.1       misho     587: 
                    588: /* Flags: - (never set any flags) */
1.1.1.2   misho     589: #define SLJIT_MOV                      6
1.1.1.4   misho     590: /* Flags: I - (never set any flags) */
1.1.1.2   misho     591: #define SLJIT_MOV_UB                   7
1.1.1.4   misho     592: #define SLJIT_IMOV_UB                  (SLJIT_MOV_UB | SLJIT_INT_OP)
                    593: /* Flags: I - (never set any flags) */
1.1.1.2   misho     594: #define SLJIT_MOV_SB                   8
1.1.1.4   misho     595: #define SLJIT_IMOV_SB                  (SLJIT_MOV_SB | SLJIT_INT_OP)
                    596: /* Flags: I - (never set any flags) */
1.1.1.2   misho     597: #define SLJIT_MOV_UH                   9
1.1.1.4   misho     598: #define SLJIT_IMOV_UH                  (SLJIT_MOV_UH | SLJIT_INT_OP)
                    599: /* Flags: I - (never set any flags) */
1.1.1.2   misho     600: #define SLJIT_MOV_SH                   10
1.1.1.4   misho     601: #define SLJIT_IMOV_SH                  (SLJIT_MOV_SH | SLJIT_INT_OP)
                    602: /* Flags: I - (never set any flags)
                    603:    Note: see SLJIT_INT_OP for further details. */
1.1.1.2   misho     604: #define SLJIT_MOV_UI                   11
1.1.1.4   misho     605: /* No SLJIT_INT_OP form, since it the same as SLJIT_IMOVU. */
                    606: /* Flags: I - (never set any flags)
                    607:    Note: see SLJIT_INT_OP for further details. */
1.1.1.2   misho     608: #define SLJIT_MOV_SI                   12
1.1.1.4   misho     609: #define SLJIT_IMOV                     (SLJIT_MOV_SI | SLJIT_INT_OP)
1.1       misho     610: /* Flags: - (never set any flags) */
1.1.1.4   misho     611: #define SLJIT_MOV_P                    13
1.1       misho     612: /* Flags: - (never set any flags) */
1.1.1.4   misho     613: #define SLJIT_MOVU                     14
                    614: /* Flags: I - (never set any flags) */
                    615: #define SLJIT_MOVU_UB                  15
                    616: #define SLJIT_IMOVU_UB                 (SLJIT_MOVU_UB | SLJIT_INT_OP)
                    617: /* Flags: I - (never set any flags) */
                    618: #define SLJIT_MOVU_SB                  16
                    619: #define SLJIT_IMOVU_SB                 (SLJIT_MOVU_SB | SLJIT_INT_OP)
                    620: /* Flags: I - (never set any flags) */
                    621: #define SLJIT_MOVU_UH                  17
                    622: #define SLJIT_IMOVU_UH                 (SLJIT_MOVU_UH | SLJIT_INT_OP)
                    623: /* Flags: I - (never set any flags) */
                    624: #define SLJIT_MOVU_SH                  18
                    625: #define SLJIT_IMOVU_SH                 (SLJIT_MOVU_SH | SLJIT_INT_OP)
                    626: /* Flags: I - (never set any flags)
                    627:    Note: see SLJIT_INT_OP for further details. */
                    628: #define SLJIT_MOVU_UI                  19
                    629: /* No SLJIT_INT_OP form, since it the same as SLJIT_IMOVU. */
                    630: /* Flags: I - (never set any flags)
                    631:    Note: see SLJIT_INT_OP for further details. */
                    632: #define SLJIT_MOVU_SI                  20
                    633: #define SLJIT_IMOVU                    (SLJIT_MOVU_SI | SLJIT_INT_OP)
1.1       misho     634: /* Flags: - (never set any flags) */
1.1.1.4   misho     635: #define SLJIT_MOVU_P                   21
1.1       misho     636: /* Flags: I | E | K */
1.1.1.4   misho     637: #define SLJIT_NOT                      22
                    638: #define SLJIT_INOT                     (SLJIT_NOT | SLJIT_INT_OP)
1.1       misho     639: /* Flags: I | E | O | K */
1.1.1.4   misho     640: #define SLJIT_NEG                      23
                    641: #define SLJIT_INEG                     (SLJIT_NEG | SLJIT_INT_OP)
1.1       misho     642: /* Count leading zeroes
1.1.1.4   misho     643:    Flags: I | E | K
                    644:    Important note! Sparc 32 does not support K flag, since
                    645:    the required popc instruction is introduced only in sparc 64. */
                    646: #define SLJIT_CLZ                      24
                    647: #define SLJIT_ICLZ                     (SLJIT_CLZ | SLJIT_INT_OP)
                    648: 
                    649: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
                    650:        sljit_si dst, sljit_sw dstw,
                    651:        sljit_si src, sljit_sw srcw);
1.1       misho     652: 
                    653: /* Flags: I | E | O | C | K */
1.1.1.4   misho     654: #define SLJIT_ADD                      25
                    655: #define SLJIT_IADD                     (SLJIT_ADD | SLJIT_INT_OP)
1.1       misho     656: /* Flags: I | C | K */
1.1.1.4   misho     657: #define SLJIT_ADDC                     26
                    658: #define SLJIT_IADDC                    (SLJIT_ADDC | SLJIT_INT_OP)
1.1       misho     659: /* Flags: I | E | S | U | O | C | K */
1.1.1.4   misho     660: #define SLJIT_SUB                      27
                    661: #define SLJIT_ISUB                     (SLJIT_SUB | SLJIT_INT_OP)
1.1       misho     662: /* Flags: I | C | K */
1.1.1.4   misho     663: #define SLJIT_SUBC                     28
                    664: #define SLJIT_ISUBC                    (SLJIT_SUBC | SLJIT_INT_OP)
1.1.1.2   misho     665: /* Note: integer mul
                    666:    Flags: I | O (see SLJIT_C_MUL_*) | K */
1.1.1.4   misho     667: #define SLJIT_MUL                      29
                    668: #define SLJIT_IMUL                     (SLJIT_MUL | SLJIT_INT_OP)
1.1       misho     669: /* Flags: I | E | K */
1.1.1.4   misho     670: #define SLJIT_AND                      30
                    671: #define SLJIT_IAND                     (SLJIT_AND | SLJIT_INT_OP)
1.1       misho     672: /* Flags: I | E | K */
1.1.1.4   misho     673: #define SLJIT_OR                       31
                    674: #define SLJIT_IOR                      (SLJIT_OR | SLJIT_INT_OP)
1.1       misho     675: /* Flags: I | E | K */
1.1.1.4   misho     676: #define SLJIT_XOR                      32
                    677: #define SLJIT_IXOR                     (SLJIT_XOR | SLJIT_INT_OP)
1.1.1.2   misho     678: /* Flags: I | E | K
                    679:    Let bit_length be the length of the shift operation: 32 or 64.
                    680:    If src2 is immediate, src2w is masked by (bit_length - 1).
                    681:    Otherwise, if the content of src2 is outside the range from 0
                    682:    to bit_length - 1, the operation is undefined. */
1.1.1.4   misho     683: #define SLJIT_SHL                      33
                    684: #define SLJIT_ISHL                     (SLJIT_SHL | SLJIT_INT_OP)
1.1.1.2   misho     685: /* Flags: I | E | K
                    686:    Let bit_length be the length of the shift operation: 32 or 64.
                    687:    If src2 is immediate, src2w is masked by (bit_length - 1).
                    688:    Otherwise, if the content of src2 is outside the range from 0
                    689:    to bit_length - 1, the operation is undefined. */
1.1.1.4   misho     690: #define SLJIT_LSHR                     34
                    691: #define SLJIT_ILSHR                    (SLJIT_LSHR | SLJIT_INT_OP)
1.1.1.2   misho     692: /* Flags: I | E | K
                    693:    Let bit_length be the length of the shift operation: 32 or 64.
                    694:    If src2 is immediate, src2w is masked by (bit_length - 1).
                    695:    Otherwise, if the content of src2 is outside the range from 0
                    696:    to bit_length - 1, the operation is undefined. */
1.1.1.4   misho     697: #define SLJIT_ASHR                     35
                    698: #define SLJIT_IASHR                    (SLJIT_ASHR | SLJIT_INT_OP)
1.1       misho     699: 
1.1.1.4   misho     700: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
                    701:        sljit_si dst, sljit_sw dstw,
                    702:        sljit_si src1, sljit_sw src1w,
                    703:        sljit_si src2, sljit_sw src2w);
1.1       misho     704: 
1.1.1.2   misho     705: /* The following function is a helper function for sljit_emit_op_custom.
1.1.1.4   misho     706:    It returns with the real machine register index of any SLJIT_SCRATCH
1.1.1.2   misho     707:    SLJIT_SAVED or SLJIT_LOCALS register.
1.1.1.4   misho     708:    Note: it returns with -1 for virtual registers (all EREGs on x86-32). */
1.1.1.2   misho     709: 
1.1.1.4   misho     710: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg);
                    711: 
                    712: /* The following function is a helper function for sljit_emit_op_custom.
                    713:    It returns with the real machine register index of any SLJIT_FLOAT register.
                    714:    Note: the index is divided by 2 on ARM 32 bit architectures. */
                    715: 
                    716: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_float_register_index(sljit_si reg);
1.1.1.2   misho     717: 
                    718: /* Any instruction can be inserted into the instruction stream by
                    719:    sljit_emit_op_custom. It has a similar purpose as inline assembly.
                    720:    The size parameter must match to the instruction size of the target
                    721:    architecture:
                    722: 
                    723:          x86: 0 < size <= 15. The instruction argument can be byte aligned.
                    724:       Thumb2: if size == 2, the instruction argument must be 2 byte aligned.
                    725:               if size == 4, the instruction argument must be 4 byte aligned.
                    726:    Otherwise: size must be 4 and instruction argument must be 4 byte aligned. */
                    727: 
1.1.1.4   misho     728: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
                    729:        void *instruction, sljit_si size);
1.1.1.2   misho     730: 
                    731: /* Returns with non-zero if fpu is available. */
                    732: 
1.1.1.4   misho     733: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void);
1.1       misho     734: 
                    735: /* Note: dst is the left and src is the right operand for SLJIT_FCMP.
1.1.1.4   misho     736:    Note: NaN check is always performed. If SLJIT_C_FLOAT_UNORDERED is set,
1.1       misho     737:          the comparison result is unpredictable.
1.1.1.4   misho     738:    Flags: SP | E | S (see SLJIT_C_FLOAT_*) */
                    739: #define SLJIT_CMPD                     36
                    740: #define SLJIT_CMPS                     (SLJIT_CMPD | SLJIT_SINGLE_OP)
                    741: /* Flags: SP - (never set any flags) */
                    742: #define SLJIT_MOVD                     37
                    743: #define SLJIT_MOVS                     (SLJIT_MOVD | SLJIT_SINGLE_OP)
                    744: /* Flags: SP - (never set any flags) */
                    745: #define SLJIT_NEGD                     38
                    746: #define SLJIT_NEGS                     (SLJIT_NEGD | SLJIT_SINGLE_OP)
                    747: /* Flags: SP - (never set any flags) */
                    748: #define SLJIT_ABSD                     39
                    749: #define SLJIT_ABSS                     (SLJIT_ABSD | SLJIT_SINGLE_OP)
                    750: 
                    751: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
                    752:        sljit_si dst, sljit_sw dstw,
                    753:        sljit_si src, sljit_sw srcw);
                    754: 
                    755: /* Flags: SP - (never set any flags) */
                    756: #define SLJIT_ADDD                     40
                    757: #define SLJIT_ADDS                     (SLJIT_ADDD | SLJIT_SINGLE_OP)
                    758: /* Flags: SP - (never set any flags) */
                    759: #define SLJIT_SUBD                     41
                    760: #define SLJIT_SUBS                     (SLJIT_SUBD | SLJIT_SINGLE_OP)
                    761: /* Flags: SP - (never set any flags) */
                    762: #define SLJIT_MULD                     42
                    763: #define SLJIT_MULS                     (SLJIT_MULD | SLJIT_SINGLE_OP)
                    764: /* Flags: SP - (never set any flags) */
                    765: #define SLJIT_DIVD                     43
                    766: #define SLJIT_DIVS                     (SLJIT_DIVD | SLJIT_SINGLE_OP)
                    767: 
                    768: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
                    769:        sljit_si dst, sljit_sw dstw,
                    770:        sljit_si src1, sljit_sw src1w,
                    771:        sljit_si src2, sljit_sw src2w);
1.1       misho     772: 
                    773: /* Label and jump instructions. */
                    774: 
                    775: SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler);
                    776: 
                    777: /* Invert conditional instruction: xor (^) with 0x1 */
                    778: #define SLJIT_C_EQUAL                  0
                    779: #define SLJIT_C_ZERO                   0
                    780: #define SLJIT_C_NOT_EQUAL              1
                    781: #define SLJIT_C_NOT_ZERO               1
                    782: 
                    783: #define SLJIT_C_LESS                   2
                    784: #define SLJIT_C_GREATER_EQUAL          3
                    785: #define SLJIT_C_GREATER                        4
                    786: #define SLJIT_C_LESS_EQUAL             5
                    787: #define SLJIT_C_SIG_LESS               6
                    788: #define SLJIT_C_SIG_GREATER_EQUAL      7
                    789: #define SLJIT_C_SIG_GREATER            8
                    790: #define SLJIT_C_SIG_LESS_EQUAL         9
                    791: 
                    792: #define SLJIT_C_OVERFLOW               10
                    793: #define SLJIT_C_NOT_OVERFLOW           11
                    794: 
                    795: #define SLJIT_C_MUL_OVERFLOW           12
                    796: #define SLJIT_C_MUL_NOT_OVERFLOW       13
                    797: 
                    798: #define SLJIT_C_FLOAT_EQUAL            14
                    799: #define SLJIT_C_FLOAT_NOT_EQUAL                15
                    800: #define SLJIT_C_FLOAT_LESS             16
                    801: #define SLJIT_C_FLOAT_GREATER_EQUAL    17
                    802: #define SLJIT_C_FLOAT_GREATER          18
                    803: #define SLJIT_C_FLOAT_LESS_EQUAL       19
1.1.1.4   misho     804: #define SLJIT_C_FLOAT_UNORDERED                20
                    805: #define SLJIT_C_FLOAT_ORDERED          21
1.1       misho     806: 
                    807: #define SLJIT_JUMP                     22
                    808: #define SLJIT_FAST_CALL                        23
                    809: #define SLJIT_CALL0                    24
                    810: #define SLJIT_CALL1                    25
                    811: #define SLJIT_CALL2                    26
                    812: #define SLJIT_CALL3                    27
                    813: 
                    814: /* Fast calling method. See sljit_emit_fast_enter / sljit_emit_fast_return. */
                    815: 
                    816: /* The target can be changed during runtime (see: sljit_set_jump_addr). */
                    817: #define SLJIT_REWRITABLE_JUMP          0x1000
                    818: 
                    819: /* Emit a jump instruction. The destination is not set, only the type of the jump.
                    820:     type must be between SLJIT_C_EQUAL and SLJIT_CALL3
                    821:     type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP
                    822:    Flags: - (never set any flags) for both conditional and unconditional jumps.
                    823:    Flags: destroy all flags for calls. */
1.1.1.4   misho     824: SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type);
1.1       misho     825: 
1.1.1.2   misho     826: /* Basic arithmetic comparison. In most architectures it is implemented as
                    827:    an SLJIT_SUB operation (with SLJIT_UNUSED destination and setting
                    828:    appropriate flags) followed by a sljit_emit_jump. However some
                    829:    architectures (i.e: MIPS) may employ special optimizations here. It is
                    830:    suggested to use this comparison form when appropriate.
1.1       misho     831:     type must be between SLJIT_C_EQUAL and SLJIT_C_SIG_LESS_EQUAL
                    832:     type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP or SLJIT_INT_OP
                    833:    Flags: destroy flags. */
1.1.1.4   misho     834: SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
                    835:        sljit_si src1, sljit_sw src1w,
                    836:        sljit_si src2, sljit_sw src2w);
1.1       misho     837: 
1.1.1.2   misho     838: /* Basic floating point comparison. In most architectures it is implemented as
                    839:    an SLJIT_FCMP operation (setting appropriate flags) followed by a
                    840:    sljit_emit_jump. However some architectures (i.e: MIPS) may employ
                    841:    special optimizations here. It is suggested to use this comparison form
                    842:    when appropriate.
1.1.1.4   misho     843:     type must be between SLJIT_C_FLOAT_EQUAL and SLJIT_C_FLOAT_ORDERED
                    844:     type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP and SLJIT_SINGLE_OP
1.1.1.2   misho     845:    Flags: destroy flags.
                    846:    Note: if either operand is NaN, the behaviour is undefined for
                    847:          type <= SLJIT_C_FLOAT_LESS_EQUAL. */
1.1.1.4   misho     848: SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
                    849:        sljit_si src1, sljit_sw src1w,
                    850:        sljit_si src2, sljit_sw src2w);
1.1.1.2   misho     851: 
1.1       misho     852: /* Set the destination of the jump to this label. */
                    853: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label);
                    854: /* Only for jumps defined with SLJIT_REWRITABLE_JUMP flag.
                    855:    Note: use sljit_emit_ijump for fixed jumps. */
                    856: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target);
                    857: 
                    858: /* Call function or jump anywhere. Both direct and indirect form
                    859:     type must be between SLJIT_JUMP and SLJIT_CALL3
                    860:     Direct form: set src to SLJIT_IMM() and srcw to the address
                    861:     Indirect form: any other valid addressing mode
                    862:    Flags: - (never set any flags) for unconditional jumps.
                    863:    Flags: destroy all flags for calls. */
1.1.1.4   misho     864: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw);
1.1       misho     865: 
1.1.1.4   misho     866: /* Perform the operation using the conditional flags as the second argument.
                    867:    Type must always be between SLJIT_C_EQUAL and SLJIT_C_FLOAT_ORDERED. The
                    868:    value represented by the type is 1, if the condition represented by the type
                    869:    is fulfilled, and 0 otherwise.
                    870: 
                    871:    If op == SLJIT_MOV, SLJIT_MOV_SI, SLJIT_MOV_UI:
                    872:      Set dst to the value represented by the type (0 or 1).
                    873:      Src must be SLJIT_UNUSED, and srcw must be 0
1.1       misho     874:      Flags: - (never set any flags)
1.1.1.4   misho     875:    If op == SLJIT_OR, op == SLJIT_AND, op == SLJIT_XOR
                    876:      Performs the binary operation using src as the first, and the value
                    877:      represented by type as the second argument.
                    878:      Important note: only dst=src and dstw=srcw is supported at the moment!
                    879:      Flags: I | E | K
                    880:    Note: sljit_emit_op_flags does nothing, if dst is SLJIT_UNUSED (regardless of op). */
                    881: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
                    882:        sljit_si dst, sljit_sw dstw,
                    883:        sljit_si src, sljit_sw srcw,
                    884:        sljit_si type);
1.1       misho     885: 
1.1.1.4   misho     886: /* Copies the base address of SLJIT_LOCALS_REG+offset to dst.
1.1.1.3   misho     887:    Flags: - (never set any flags) */
1.1.1.4   misho     888: SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset);
1.1.1.3   misho     889: 
1.1       misho     890: /* The constant can be changed runtime (see: sljit_set_const)
                    891:    Flags: - (never set any flags) */
1.1.1.4   misho     892: SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value);
1.1       misho     893: 
                    894: /* After the code generation the address for label, jump and const instructions
1.1.1.4   misho     895:    are computed. Since these structures are freed by sljit_free_compiler, the
1.1       misho     896:    addresses must be preserved by the user program elsewere. */
                    897: static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->addr; }
                    898: static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; }
                    899: static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { return const_->addr; }
                    900: 
                    901: /* Only the address is required to rewrite the code. */
                    902: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr);
1.1.1.4   misho     903: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant);
1.1       misho     904: 
                    905: /* --------------------------------------------------------------------- */
                    906: /*  Miscellaneous utility functions                                      */
                    907: /* --------------------------------------------------------------------- */
                    908: 
                    909: #define SLJIT_MAJOR_VERSION    0
1.1.1.4   misho     910: #define SLJIT_MINOR_VERSION    91
1.1       misho     911: 
1.1.1.4   misho     912: /* Get the human readable name of the platform. Can be useful on platforms
                    913:    like ARM, where ARM and Thumb2 functions can be mixed, and
                    914:    it is useful to know the type of the code generator. */
1.1       misho     915: SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void);
                    916: 
1.1.1.4   misho     917: /* Portable helper function to get an offset of a member. */
                    918: #define SLJIT_OFFSETOF(base, member) ((sljit_sw)(&((base*)0x10)->member) - 0x10)
1.1       misho     919: 
                    920: #if (defined SLJIT_UTIL_GLOBAL_LOCK && SLJIT_UTIL_GLOBAL_LOCK)
                    921: /* This global lock is useful to compile common functions. */
                    922: SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_grab_lock(void);
                    923: SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_release_lock(void);
                    924: #endif
                    925: 
                    926: #if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK)
                    927: 
                    928: /* The sljit_stack is a utiliy feature of sljit, which allocates a
                    929:    writable memory region between base (inclusive) and limit (exclusive).
                    930:    Both base and limit is a pointer, and base is always <= than limit.
                    931:    This feature uses the "address space reserve" feature
                    932:    of modern operating systems. Basically we don't need to allocate a
                    933:    huge memory block in one step for the worst case, we can start with
                    934:    a smaller chunk and extend it later. Since the address space is
                    935:    reserved, the data never copied to other regions, thus it is safe
                    936:    to store pointers here. */
                    937: 
                    938: /* Note: The base field is aligned to PAGE_SIZE bytes (usually 4k or more).
                    939:    Note: stack growing should not happen in small steps: 4k, 16k or even
                    940:      bigger growth is better.
                    941:    Note: this structure may not be supported by all operating systems.
                    942:      Some kind of fallback mechanism is suggested when SLJIT_UTIL_STACK
                    943:      is not defined. */
                    944: 
                    945: struct sljit_stack {
                    946:        /* User data, anything can be stored here.
                    947:           Starting with the same value as base. */
                    948:        sljit_uw top;
                    949:        /* These members are read only. */
                    950:        sljit_uw base;
                    951:        sljit_uw limit;
                    952:        sljit_uw max_limit;
                    953: };
                    954: 
                    955: /* Returns NULL if unsuccessful.
                    956:    Note: limit and max_limit contains the size for stack allocation
                    957:    Note: the top field is initialized to base. */
                    958: SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_CALL sljit_allocate_stack(sljit_uw limit, sljit_uw max_limit);
                    959: SLJIT_API_FUNC_ATTRIBUTE void SLJIT_CALL sljit_free_stack(struct sljit_stack* stack);
                    960: 
                    961: /* Can be used to increase (allocate) or decrease (free) the memory area.
                    962:    Returns with a non-zero value if unsuccessful. If new_limit is greater than
                    963:    max_limit, it will fail. It is very easy to implement a stack data structure,
                    964:    since the growth ratio can be added to the current limit, and sljit_stack_resize
                    965:    will do all the necessary checks. The fields of the stack are not changed if
                    966:    sljit_stack_resize fails. */
1.1.1.4   misho     967: SLJIT_API_FUNC_ATTRIBUTE sljit_sw SLJIT_CALL sljit_stack_resize(struct sljit_stack* stack, sljit_uw new_limit);
1.1       misho     968: 
                    969: #endif /* (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) */
                    970: 
                    971: #if !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
                    972: 
                    973: /* Get the entry address of a given function. */
1.1.1.4   misho     974: #define SLJIT_FUNC_OFFSET(func_name)   ((sljit_sw)func_name)
1.1       misho     975: 
                    976: #else /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */
                    977: 
                    978: /* All JIT related code should be placed in the same context (library, binary, etc.). */
                    979: 
1.1.1.4   misho     980: #define SLJIT_FUNC_OFFSET(func_name)   (*(sljit_sw*)(void*)func_name)
1.1       misho     981: 
                    982: /* For powerpc64, the function pointers point to a context descriptor. */
                    983: struct sljit_function_context {
1.1.1.4   misho     984:        sljit_sw addr;
                    985:        sljit_sw r2;
                    986:        sljit_sw r11;
1.1       misho     987: };
                    988: 
                    989: /* Fill the context arguments using the addr and the function.
                    990:    If func_ptr is NULL, it will not be set to the address of context
                    991:    If addr is NULL, the function address also comes from the func pointer. */
1.1.1.4   misho     992: SLJIT_API_FUNC_ATTRIBUTE void sljit_set_function_context(void** func_ptr, struct sljit_function_context* context, sljit_sw addr, void* func);
1.1       misho     993: 
                    994: #endif /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */
                    995: 
                    996: #endif /* _SLJIT_LIR_H_ */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>