| 42 |
- very effective to cache an important value once |
- very effective to cache an important value once |
| 43 |
- A fixed stack space can be allocated for local variables |
- A fixed stack space can be allocated for local variables |
| 44 |
- The compiler is thread-safe |
- The compiler is thread-safe |
| 45 |
|
- The compiler is highly configurable through preprocessor macros. |
| 46 |
|
You can disable unneeded features (multithreading in single |
| 47 |
|
threaded applications), and you can use your own system functions |
| 48 |
|
(including memory allocators). See sljitConfig.h |
| 49 |
Disadvantages: |
Disadvantages: |
| 50 |
- Limited number of registers (only 6+4 integer registers, max 3+2 |
- Limited number of registers (only 6+4 integer registers, max 3+2 |
| 51 |
temporary and max 3+2 general, and 4 floating point registers) |
temporary, max 3+2 saved and 4 floating point registers) |
| 52 |
In practice: |
In practice: |
| 53 |
- This approach is very effective for interpreters |
- This approach is very effective for interpreters |
| 54 |
- One of the general registers typically points to a stack interface |
- One of the saved registers typically points to a stack interface |
| 55 |
- It can jump to any exception handler anytime (even for another |
- It can jump to any exception handler anytime (even for another |
| 56 |
function. It is safe for SLJIT.) |
function. It is safe for SLJIT.) |
| 57 |
- Fast paths can be modified during runtime reflecting the changes |
- Fast paths can be modified during runtime reflecting the changes |
| 108 |
#define SLJIT_TEMPORARY_EREG1 4 |
#define SLJIT_TEMPORARY_EREG1 4 |
| 109 |
#define SLJIT_TEMPORARY_EREG2 5 |
#define SLJIT_TEMPORARY_EREG2 5 |
| 110 |
|
|
| 111 |
/* General (saved) registers preserve their values across function calls. */ |
/* Saved registers whose preserve their values across function calls. */ |
| 112 |
#define SLJIT_GENERAL_REG1 6 |
#define SLJIT_SAVED_REG1 6 |
| 113 |
#define SLJIT_GENERAL_REG2 7 |
#define SLJIT_SAVED_REG2 7 |
| 114 |
#define SLJIT_GENERAL_REG3 8 |
#define SLJIT_SAVED_REG3 8 |
| 115 |
/* Note: Extra Registers cannot be used for memory addressing. */ |
/* Note: Extra Registers cannot be used for memory addressing. */ |
| 116 |
/* Note: on x86-32, these registers are emulated (using stack loads & stores). */ |
/* Note: on x86-32, these registers are emulated (using stack loads & stores). */ |
| 117 |
#define SLJIT_GENERAL_EREG1 9 |
#define SLJIT_SAVED_EREG1 9 |
| 118 |
#define SLJIT_GENERAL_EREG2 10 |
#define SLJIT_SAVED_EREG2 10 |
| 119 |
|
|
| 120 |
/* Read-only register (cannot be the destination of an operation). */ |
/* Read-only register (cannot be the destination of an operation). */ |
| 121 |
/* Note: SLJIT_MEM2( ... , SLJIT_LOCALS_REG) is not supported (x86 limitation). */ |
/* Note: SLJIT_MEM2( ... , SLJIT_LOCALS_REG) is not supported (x86 limitation). */ |
| 200 |
|
|
| 201 |
/* Used local registers. */ |
/* Used local registers. */ |
| 202 |
int temporaries; |
int temporaries; |
| 203 |
/* Used general registers. */ |
/* Used saved registers. */ |
| 204 |
int generals; |
int saveds; |
| 205 |
/* Local stack size. */ |
/* Local stack size. */ |
| 206 |
int local_size; |
int local_size; |
| 207 |
/* Code size. */ |
/* Code size. */ |
| 212 |
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
| 213 |
int args; |
int args; |
| 214 |
int temporaries_start; |
int temporaries_start; |
| 215 |
int generals_start; |
int saveds_start; |
| 216 |
#endif |
#endif |
| 217 |
|
|
| 218 |
#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
| 232 |
sljit_ub *cpool_unique; |
sljit_ub *cpool_unique; |
| 233 |
sljit_uw cpool_diff; |
sljit_uw cpool_diff; |
| 234 |
sljit_uw cpool_fill; |
sljit_uw cpool_fill; |
| 235 |
/* General fields. */ |
/* Other members. */ |
| 236 |
/* Contains pointer, "ldr pc, [...]" pairs. */ |
/* Contains pointer, "ldr pc, [...]" pairs. */ |
| 237 |
sljit_uw patches; |
sljit_uw patches; |
| 238 |
#endif |
#endif |
| 321 |
Binary Interface) of the platform, which specify the purpose of machine |
Binary Interface) of the platform, which specify the purpose of machine |
| 322 |
registers and stack handling among other things. The sljit_emit_enter |
registers and stack handling among other things. The sljit_emit_enter |
| 323 |
function emits the necessary instructions for setting up a new context |
function emits the necessary instructions for setting up a new context |
| 324 |
for the executable code and moves function arguments to the general |
for the executable code and moves function arguments to the saved |
| 325 |
registers. The number of arguments are specified in the "args" |
registers. The number of arguments are specified in the "args" |
| 326 |
parameter and the first argument goes to SLJIT_GENERAL_REG1, the second |
parameter and the first argument goes to SLJIT_SAVED_REG1, the second |
| 327 |
goes to SLJIT_GENERAL_REG2 and so on. The number of temporary and |
goes to SLJIT_SAVED_REG2 and so on. The number of temporary and |
| 328 |
general registers are passed in "temporaries" and "generals" arguments |
saved registers are passed in "temporaries" and "saveds" arguments |
| 329 |
respectively. Since the general registers contains the arguments, |
respectively. Since the saved registers contains the arguments, |
| 330 |
"args" must be less or equal than "generals". The sljit_emit_enter |
"args" must be less or equal than "saveds". The sljit_emit_enter |
| 331 |
is also capable of allocating a stack space for local variables. The |
is also capable of allocating a stack space for local variables. The |
| 332 |
"local_size" argument contains the size in bytes of this local area |
"local_size" argument contains the size in bytes of this local area |
| 333 |
and its staring address is stored in SLJIT_LOCALS_REG. However |
and its staring address is stored in SLJIT_LOCALS_REG. However |
| 342 |
#define SLJIT_MAX_LOCAL_SIZE 65536 |
#define SLJIT_MAX_LOCAL_SIZE 65536 |
| 343 |
|
|
| 344 |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler, |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_enter(struct sljit_compiler *compiler, |
| 345 |
int args, int temporaries, int generals, int local_size); |
int args, int temporaries, int saveds, int local_size); |
| 346 |
|
|
| 347 |
/* The machine code has a context (which contains the local stack space size, |
/* The machine code has a context (which contains the local stack space size, |
| 348 |
number of used registers, etc.) which initialized by sljit_emit_enter. Several |
number of used registers, etc.) which initialized by sljit_emit_enter. Several |
| 357 |
/* Note: multiple calls of this function overwrites the previous call. */ |
/* Note: multiple calls of this function overwrites the previous call. */ |
| 358 |
|
|
| 359 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, |
| 360 |
int args, int temporaries, int generals, int local_size); |
int args, int temporaries, int saveds, int local_size); |
| 361 |
|
|
| 362 |
/* Return from machine code. The op argument can be SLJIT_UNUSED which means the |
/* Return from machine code. The op argument can be SLJIT_UNUSED which means the |
| 363 |
function does not return with anything or any opcode between SLJIT_MOV and |
function does not return with anything or any opcode between SLJIT_MOV and |
| 373 |
use this as a return value later. */ |
use this as a return value later. */ |
| 374 |
|
|
| 375 |
/* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine instructions |
/* Note: only for sljit specific, non ABI compilant calls. Fast, since only a few machine instructions |
| 376 |
are needed. Excellent for small uility functions, where saving general registers and setting up |
are needed. Excellent for small uility functions, where saving registers and setting up |
| 377 |
a new stack frame would cost too much performance. However, it is still possible to return |
a new stack frame would cost too much performance. However, it is still possible to return |
| 378 |
to the address of the caller (or anywhere else). */ |
to the address of the caller (or anywhere else). */ |
| 379 |
|
|
| 382 |
/* Note: although sljit_emit_fast_return could be replaced by an ijump, it is not suggested, |
/* Note: although sljit_emit_fast_return could be replaced by an ijump, it is not suggested, |
| 383 |
since many architectures do clever branch prediction on call / return instruction pairs. */ |
since many architectures do clever branch prediction on call / return instruction pairs. */ |
| 384 |
|
|
| 385 |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int generals, int local_size); |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int saveds, int local_size); |
| 386 |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_return(struct sljit_compiler *compiler, int src, sljit_w srcw); |
SLJIT_API_FUNC_ATTRIBUTE int sljit_emit_fast_return(struct sljit_compiler *compiler, int src, sljit_w srcw); |
| 387 |
|
|
| 388 |
/* |
/* |
| 590 |
|
|
| 591 |
/* The following function is a helper function for sljit_emit_op_custom. |
/* The following function is a helper function for sljit_emit_op_custom. |
| 592 |
It returns with the real machine register index of any SLJIT_TEMPORARY |
It returns with the real machine register index of any SLJIT_TEMPORARY |
| 593 |
SLJIT_GENERAL or SLJIT_LOCALS register. |
SLJIT_SAVED or SLJIT_LOCALS register. |
| 594 |
Note: it returns with -1 for virtual registers (all EREGs on x86-32). |
Note: it returns with -1 for virtual registers (all EREGs on x86-32). |
| 595 |
Note: register returned by SLJIT_LOCALS_REG is not necessary the real |
Note: register returned by SLJIT_LOCALS_REG is not necessary the real |
| 596 |
stack pointer register of the target architecture. */ |
stack pointer register of the target architecture. */ |