| 1 |
/* |
| 2 |
* Stack-less Just-In-Time compiler |
| 3 |
* |
| 4 |
* Copyright Zoltan Herczeg ([email protected]). All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without modification, are |
| 7 |
* permitted provided that the following conditions are met: |
| 8 |
* |
| 9 |
* 1. Redistributions of source code must retain the above copyright notice, this list of |
| 10 |
* conditions and the following disclaimer. |
| 11 |
* |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright notice, this list |
| 13 |
* of conditions and the following disclaimer in the documentation and/or other materials |
| 14 |
* provided with the distribution. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY |
| 17 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
| 19 |
* SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 21 |
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 22 |
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 24 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 |
*/ |
| 26 |
|
| 27 |
#ifndef SLJIT_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: |
| 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, as long as the compiling |
| 40 |
context is the same. See sljit_emit_enter for more details. |
| 41 |
- Supports self modifying code: target of any jump and call |
| 42 |
instructions and some constant values can be dynamically modified |
| 43 |
during runtime. See SLJIT_REWRITABLE_JUMP. |
| 44 |
- although it is not suggested to do it frequently |
| 45 |
- can be used for inline caching: save an important value once |
| 46 |
in the instruction stream |
| 47 |
- A fixed stack space can be allocated for local variables |
| 48 |
- The compiler is thread-safe |
| 49 |
- The compiler is highly configurable through preprocessor macros. |
| 50 |
You can disable unneeded features (multithreading in single |
| 51 |
threaded applications), and you can use your own system functions |
| 52 |
(including memory allocators). See sljitConfig.h. |
| 53 |
Disadvantages: |
| 54 |
- The compiler is more like a platform independent assembler, so |
| 55 |
there is no built-in variable management. Registers and stack must |
| 56 |
be managed manually (the name of the compiler refers to this). |
| 57 |
In practice: |
| 58 |
- This approach is very effective for interpreters |
| 59 |
- One of the saved registers typically points to a stack interface |
| 60 |
- It can jump to any exception handler anytime (even if it belongs |
| 61 |
to another function) |
| 62 |
- Hot paths can be modified during runtime reflecting the changes |
| 63 |
of the fastest execution path of the dynamic language |
| 64 |
- SLJIT supports complex memory addressing modes |
| 65 |
- mainly position and context independent code (except some cases) |
| 66 |
|
| 67 |
For valgrind users: |
| 68 |
- pass --smc-check=all argument to valgrind, since JIT is a "self-modifying code" |
| 69 |
*/ |
| 70 |
|
| 71 |
#if (defined SLJIT_HAVE_CONFIG_PRE && SLJIT_HAVE_CONFIG_PRE) |
| 72 |
#include "sljitConfigPre.h" |
| 73 |
#endif /* SLJIT_HAVE_CONFIG_PRE */ |
| 74 |
|
| 75 |
#include "sljitConfigCPU.h" |
| 76 |
#include "sljitConfig.h" |
| 77 |
|
| 78 |
/* The following header file defines useful macros for fine tuning |
| 79 |
SLJIT based code generators. They are listed in the beginning |
| 80 |
of sljitConfigInternal.h */ |
| 81 |
|
| 82 |
#include "sljitConfigInternal.h" |
| 83 |
|
| 84 |
#if (defined SLJIT_HAVE_CONFIG_POST && SLJIT_HAVE_CONFIG_POST) |
| 85 |
#include "sljitConfigPost.h" |
| 86 |
#endif /* SLJIT_HAVE_CONFIG_POST */ |
| 87 |
|
| 88 |
#ifdef __cplusplus |
| 89 |
extern "C" { |
| 90 |
#endif /* __cplusplus */ |
| 91 |
|
| 92 |
/* Version numbers. */ |
| 93 |
#define SLJIT_MAJOR_VERSION 0 |
| 94 |
#define SLJIT_MINOR_VERSION 95 |
| 95 |
|
| 96 |
/* --------------------------------------------------------------------- */ |
| 97 |
/* Error codes */ |
| 98 |
/* --------------------------------------------------------------------- */ |
| 99 |
|
| 100 |
/* Indicates no error. */ |
| 101 |
#define SLJIT_SUCCESS 0 |
| 102 |
/* After the call of sljit_generate_code(), the error code of the compiler |
| 103 |
is set to this value to avoid further code generation. |
| 104 |
The complier should be freed after sljit_generate_code(). */ |
| 105 |
#define SLJIT_ERR_COMPILED 1 |
| 106 |
/* Cannot allocate non-executable memory. */ |
| 107 |
#define SLJIT_ERR_ALLOC_FAILED 2 |
| 108 |
/* Cannot allocate executable memory. |
| 109 |
Only sljit_generate_code() returns with this error code. */ |
| 110 |
#define SLJIT_ERR_EX_ALLOC_FAILED 3 |
| 111 |
/* Unsupported instruction form. */ |
| 112 |
#define SLJIT_ERR_UNSUPPORTED 4 |
| 113 |
/* An invalid argument is passed to any SLJIT function. */ |
| 114 |
#define SLJIT_ERR_BAD_ARGUMENT 5 |
| 115 |
|
| 116 |
/* --------------------------------------------------------------------- */ |
| 117 |
/* Registers */ |
| 118 |
/* --------------------------------------------------------------------- */ |
| 119 |
|
| 120 |
/* |
| 121 |
Scratch (R) registers: registers which may not preserve their values |
| 122 |
across function calls. |
| 123 |
|
| 124 |
Saved (S) registers: registers which preserve their values across |
| 125 |
function calls. |
| 126 |
|
| 127 |
The scratch and saved register sets overlap. The last scratch register |
| 128 |
is the first saved register, the one before the last is the second saved |
| 129 |
register, and so on. |
| 130 |
|
| 131 |
For example, in an architecture with only five registers (A-E), if two |
| 132 |
are scratch and three saved registers, they will be defined as follows: |
| 133 |
|
| 134 |
A | R0 | | R0 always represent scratch register A |
| 135 |
B | R1 | | R1 always represent scratch register B |
| 136 |
C | [R2] | S2 | R2 and S2 represent the same physical register C |
| 137 |
D | [R3] | S1 | R3 and S1 represent the same physical register D |
| 138 |
E | [R4] | S0 | R4 and S0 represent the same physical register E |
| 139 |
|
| 140 |
Note: SLJIT_NUMBER_OF_SCRATCH_REGISTERS will be 2 and |
| 141 |
SLJIT_NUMBER_OF_SAVED_REGISTERS will be 3. |
| 142 |
|
| 143 |
Note: For all supported architectures SLJIT_NUMBER_OF_REGISTERS >= 12 |
| 144 |
and SLJIT_NUMBER_OF_SAVED_REGISTERS >= 6. However, 6 registers |
| 145 |
are virtual on x86-32. See below. |
| 146 |
|
| 147 |
The purpose of this definition is convenience: saved registers can |
| 148 |
be used as extra scratch registers. For example, building in the |
| 149 |
previous example, four registers can be specified as scratch registers |
| 150 |
and the fifth one as saved register, allowing any user code which requires |
| 151 |
four scratch registers to run unmodified. The SLJIT compiler automatically |
| 152 |
saves the content of the two extra scratch register on the stack. Scratch |
| 153 |
registers can also be preserved by saving their value on the stack but |
| 154 |
that needs to be done manually. |
| 155 |
|
| 156 |
Note: To emphasize that registers assigned to R2-R4 are saved |
| 157 |
registers, they are enclosed by square brackets. |
| 158 |
|
| 159 |
Note: sljit_emit_enter and sljit_set_context define whether a register |
| 160 |
is S or R register. E.g: if in the previous example 3 scratches and |
| 161 |
1 saved are mapped by sljit_emit_enter, the allowed register set |
| 162 |
will be: R0-R2 and S0. Although S2 is mapped to the same register |
| 163 |
than R2, it is not available in that configuration. Furthermore |
| 164 |
the S1 register cannot be used at all. |
| 165 |
*/ |
| 166 |
|
| 167 |
/* Scratch registers. */ |
| 168 |
#define SLJIT_R0 1 |
| 169 |
#define SLJIT_R1 2 |
| 170 |
#define SLJIT_R2 3 |
| 171 |
/* Note: on x86-32, R3 - R6 (same as S3 - S6) are emulated (they |
| 172 |
are allocated on the stack). These registers are called virtual |
| 173 |
and cannot be used for memory addressing (cannot be part of |
| 174 |
any SLJIT_MEM1, SLJIT_MEM2 construct). There is no such |
| 175 |
limitation on other CPUs. See sljit_get_register_index(). */ |
| 176 |
#define SLJIT_R3 4 |
| 177 |
#define SLJIT_R4 5 |
| 178 |
#define SLJIT_R5 6 |
| 179 |
#define SLJIT_R6 7 |
| 180 |
#define SLJIT_R7 8 |
| 181 |
#define SLJIT_R8 9 |
| 182 |
#define SLJIT_R9 10 |
| 183 |
/* All R registers provided by the architecture can be accessed by SLJIT_R(i) |
| 184 |
The i parameter must be >= 0 and < SLJIT_NUMBER_OF_REGISTERS. */ |
| 185 |
#define SLJIT_R(i) (1 + (i)) |
| 186 |
|
| 187 |
/* Saved registers. */ |
| 188 |
#define SLJIT_S0 (SLJIT_NUMBER_OF_REGISTERS) |
| 189 |
#define SLJIT_S1 (SLJIT_NUMBER_OF_REGISTERS - 1) |
| 190 |
#define SLJIT_S2 (SLJIT_NUMBER_OF_REGISTERS - 2) |
| 191 |
/* Note: on x86-32, S3 - S6 (same as R3 - R6) are emulated (they |
| 192 |
are allocated on the stack). These registers are called virtual |
| 193 |
and cannot be used for memory addressing (cannot be part of |
| 194 |
any SLJIT_MEM1, SLJIT_MEM2 construct). There is no such |
| 195 |
limitation on other CPUs. See sljit_get_register_index(). */ |
| 196 |
#define SLJIT_S3 (SLJIT_NUMBER_OF_REGISTERS - 3) |
| 197 |
#define SLJIT_S4 (SLJIT_NUMBER_OF_REGISTERS - 4) |
| 198 |
#define SLJIT_S5 (SLJIT_NUMBER_OF_REGISTERS - 5) |
| 199 |
#define SLJIT_S6 (SLJIT_NUMBER_OF_REGISTERS - 6) |
| 200 |
#define SLJIT_S7 (SLJIT_NUMBER_OF_REGISTERS - 7) |
| 201 |
#define SLJIT_S8 (SLJIT_NUMBER_OF_REGISTERS - 8) |
| 202 |
#define SLJIT_S9 (SLJIT_NUMBER_OF_REGISTERS - 9) |
| 203 |
/* All S registers provided by the architecture can be accessed by SLJIT_S(i) |
| 204 |
The i parameter must be >= 0 and < SLJIT_NUMBER_OF_SAVED_REGISTERS. */ |
| 205 |
#define SLJIT_S(i) (SLJIT_NUMBER_OF_REGISTERS - (i)) |
| 206 |
|
| 207 |
/* Registers >= SLJIT_FIRST_SAVED_REG are saved registers. */ |
| 208 |
#define SLJIT_FIRST_SAVED_REG (SLJIT_S0 - SLJIT_NUMBER_OF_SAVED_REGISTERS + 1) |
| 209 |
|
| 210 |
/* The SLJIT_SP provides direct access to the linear stack space allocated by |
| 211 |
sljit_emit_enter. It can only be used in the following form: SLJIT_MEM1(SLJIT_SP). |
| 212 |
The immediate offset is extended by the relative stack offset automatically. |
| 213 |
sljit_get_local_base can be used to obtain the real address of a value. */ |
| 214 |
#define SLJIT_SP (SLJIT_NUMBER_OF_REGISTERS + 1) |
| 215 |
|
| 216 |
/* Return with machine word. */ |
| 217 |
|
| 218 |
#define SLJIT_RETURN_REG SLJIT_R0 |
| 219 |
|
| 220 |
/* --------------------------------------------------------------------- */ |
| 221 |
/* Floating point registers */ |
| 222 |
/* --------------------------------------------------------------------- */ |
| 223 |
|
| 224 |
/* Each floating point register can store a 32 or a 64 bit precision |
| 225 |
value. The FR and FS register sets overlap in the same way as R |
| 226 |
and S register sets. See above. */ |
| 227 |
|
| 228 |
/* Floating point scratch registers. */ |
| 229 |
#define SLJIT_FR0 1 |
| 230 |
#define SLJIT_FR1 2 |
| 231 |
#define SLJIT_FR2 3 |
| 232 |
#define SLJIT_FR3 4 |
| 233 |
#define SLJIT_FR4 5 |
| 234 |
#define SLJIT_FR5 6 |
| 235 |
#define SLJIT_FR6 7 |
| 236 |
#define SLJIT_FR7 8 |
| 237 |
#define SLJIT_FR8 9 |
| 238 |
#define SLJIT_FR9 10 |
| 239 |
/* All FR registers provided by the architecture can be accessed by SLJIT_FR(i) |
| 240 |
The i parameter must be >= 0 and < SLJIT_NUMBER_OF_FLOAT_REGISTERS. */ |
| 241 |
#define SLJIT_FR(i) (1 + (i)) |
| 242 |
|
| 243 |
/* Floating point saved registers. */ |
| 244 |
#define SLJIT_FS0 (SLJIT_NUMBER_OF_FLOAT_REGISTERS) |
| 245 |
#define SLJIT_FS1 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 1) |
| 246 |
#define SLJIT_FS2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 2) |
| 247 |
#define SLJIT_FS3 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 3) |
| 248 |
#define SLJIT_FS4 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 4) |
| 249 |
#define SLJIT_FS5 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 5) |
| 250 |
#define SLJIT_FS6 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 6) |
| 251 |
#define SLJIT_FS7 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 7) |
| 252 |
#define SLJIT_FS8 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 8) |
| 253 |
#define SLJIT_FS9 (SLJIT_NUMBER_OF_FLOAT_REGISTERS - 9) |
| 254 |
/* All FS registers provided by the architecture can be accessed by SLJIT_FS(i) |
| 255 |
The i parameter must be >= 0 and < SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS. */ |
| 256 |
#define SLJIT_FS(i) (SLJIT_NUMBER_OF_FLOAT_REGISTERS - (i)) |
| 257 |
|
| 258 |
/* Float registers >= SLJIT_FIRST_SAVED_FLOAT_REG are saved registers. */ |
| 259 |
#define SLJIT_FIRST_SAVED_FLOAT_REG (SLJIT_FS0 - SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS + 1) |
| 260 |
|
| 261 |
/* Return with floating point arg. */ |
| 262 |
|
| 263 |
#define SLJIT_RETURN_FREG SLJIT_FR0 |
| 264 |
|
| 265 |
/* --------------------------------------------------------------------- */ |
| 266 |
/* Vector registers */ |
| 267 |
/* --------------------------------------------------------------------- */ |
| 268 |
|
| 269 |
/* Vector registers are storage areas, which are used for Single Instruction |
| 270 |
Multiple Data (SIMD) computations. The VR and VS register sets overlap |
| 271 |
in the same way as R and S register sets. See above. |
| 272 |
|
| 273 |
The storage space of vector registers often overlap with floating point |
| 274 |
registers. In this case setting the value of SLJIT_VR(i) destroys the |
| 275 |
value of SLJIT_FR(i) and vice versa. See SLJIT_SEPARATE_VECTOR_REGISTERS |
| 276 |
macro. */ |
| 277 |
|
| 278 |
/* Vector scratch registers. */ |
| 279 |
#define SLJIT_VR0 1 |
| 280 |
#define SLJIT_VR1 2 |
| 281 |
#define SLJIT_VR2 3 |
| 282 |
#define SLJIT_VR3 4 |
| 283 |
#define SLJIT_VR4 5 |
| 284 |
#define SLJIT_VR5 6 |
| 285 |
#define SLJIT_VR6 7 |
| 286 |
#define SLJIT_VR7 8 |
| 287 |
#define SLJIT_VR8 9 |
| 288 |
#define SLJIT_VR9 10 |
| 289 |
/* All VR registers provided by the architecture can be accessed by SLJIT_VR(i) |
| 290 |
The i parameter must be >= 0 and < SLJIT_NUMBER_OF_VECTOR_REGISTERS. */ |
| 291 |
#define SLJIT_VR(i) (1 + (i)) |
| 292 |
|
| 293 |
/* Vector saved registers. */ |
| 294 |
#define SLJIT_VS0 (SLJIT_NUMBER_OF_VECTOR_REGISTERS) |
| 295 |
#define SLJIT_VS1 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 1) |
| 296 |
#define SLJIT_VS2 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 2) |
| 297 |
#define SLJIT_VS3 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 3) |
| 298 |
#define SLJIT_VS4 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 4) |
| 299 |
#define SLJIT_VS5 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 5) |
| 300 |
#define SLJIT_VS6 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 6) |
| 301 |
#define SLJIT_VS7 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 7) |
| 302 |
#define SLJIT_VS8 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 8) |
| 303 |
#define SLJIT_VS9 (SLJIT_NUMBER_OF_VECTOR_REGISTERS - 9) |
| 304 |
/* All VS registers provided by the architecture can be accessed by SLJIT_VS(i) |
| 305 |
The i parameter must be >= 0 and < SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS. */ |
| 306 |
#define SLJIT_VS(i) (SLJIT_NUMBER_OF_VECTOR_REGISTERS - (i)) |
| 307 |
|
| 308 |
/* Vector registers >= SLJIT_FIRST_SAVED_VECTOR_REG are saved registers. */ |
| 309 |
#define SLJIT_FIRST_SAVED_VECTOR_REG (SLJIT_VS0 - SLJIT_NUMBER_OF_SAVED_VECTOR_REGISTERS + 1) |
| 310 |
|
| 311 |
/* --------------------------------------------------------------------- */ |
| 312 |
/* Argument type definitions */ |
| 313 |
/* --------------------------------------------------------------------- */ |
| 314 |
|
| 315 |
/* The following argument type definitions are used by sljit_emit_enter, |
| 316 |
sljit_set_context, sljit_emit_call, and sljit_emit_icall functions. |
| 317 |
|
| 318 |
For sljit_emit_call and sljit_emit_icall, the first integer argument |
| 319 |
must be placed into SLJIT_R0, the second one into SLJIT_R1, and so on. |
| 320 |
Similarly the first floating point argument must be placed into SLJIT_FR0, |
| 321 |
the second one into SLJIT_FR1, and so on. |
| 322 |
|
| 323 |
For sljit_emit_enter, the integer arguments can be stored in scratch |
| 324 |
or saved registers. Scratch registers are identified by a _R suffix. |
| 325 |
|
| 326 |
If only saved registers are used, then the allocation mirrors what is |
| 327 |
done for the "call" functions but using saved registers, meaning that |
| 328 |
the first integer argument goes to SLJIT_S0, the second one goes into |
| 329 |
SLJIT_S1, and so on. |
| 330 |
|
| 331 |
If scratch registers are used, then the way the integer registers are |
| 332 |
allocated changes so that SLJIT_S0, SLJIT_S1, etc; will be assigned |
| 333 |
only for the arguments not using scratch registers, while SLJIT_R<n> |
| 334 |
will be used for the ones using scratch registers. |
| 335 |
|
| 336 |
Furthermore, the index (shown as "n" above) that will be used for the |
| 337 |
scratch register depends on how many previous integer registers |
| 338 |
(scratch or saved) were used already, starting with SLJIT_R0. |
| 339 |
Eventhough some indexes will be likely skipped, they still need to be |
| 340 |
accounted for in the scratches parameter of sljit_emit_enter. See below |
| 341 |
for some examples. |
| 342 |
|
| 343 |
The floating point arguments always use scratch registers (but not the |
| 344 |
_R suffix like the integer arguments) and must use SLJIT_FR0, SLJIT_FR1, |
| 345 |
just like in the "call" functions. |
| 346 |
|
| 347 |
Note: the mapping for scratch registers is part of the compiler context |
| 348 |
and therefore a new context after sljit_emit_call/sljit_emit_icall |
| 349 |
could remove access to some scratch registers that were used as |
| 350 |
arguments. |
| 351 |
|
| 352 |
Example function definition: |
| 353 |
sljit_f32 SLJIT_FUNC example_c_callback(void *arg_a, |
| 354 |
sljit_f64 arg_b, sljit_u32 arg_c, sljit_f32 arg_d); |
| 355 |
|
| 356 |
Argument type definition: |
| 357 |
SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_F32) |
| 358 |
| SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_P, 1) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_F64, 2) |
| 359 |
| SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_32, 3) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_F32, 4) |
| 360 |
|
| 361 |
Short form of argument type definition: |
| 362 |
SLJIT_ARGS4(F32, P, F64, 32, F32) |
| 363 |
|
| 364 |
Argument passing: |
| 365 |
arg_a must be placed in SLJIT_R0 |
| 366 |
arg_b must be placed in SLJIT_FR0 |
| 367 |
arg_c must be placed in SLJIT_R1 |
| 368 |
arg_d must be placed in SLJIT_FR1 |
| 369 |
|
| 370 |
Examples for argument processing by sljit_emit_enter: |
| 371 |
SLJIT_ARGS4V(P, 32_R, F32, W) |
| 372 |
Arguments are placed into: SLJIT_S0, SLJIT_R1, SLJIT_FR0, SLJIT_S1 |
| 373 |
The type of the result is void. |
| 374 |
|
| 375 |
SLJIT_ARGS4(F32, W, W_R, W, W_R) |
| 376 |
Arguments are placed into: SLJIT_S0, SLJIT_R1, SLJIT_S1, SLJIT_R3 |
| 377 |
The type of the result is sljit_f32. |
| 378 |
|
| 379 |
SLJIT_ARGS4(P, W, F32, P_R) |
| 380 |
Arguments are placed into: SLJIT_FR0, SLJIT_S0, SLJIT_FR1, SLJIT_R1 |
| 381 |
The type of the result is pointer. |
| 382 |
|
| 383 |
Note: it is recommended to pass the scratch arguments first |
| 384 |
followed by the saved arguments: |
| 385 |
|
| 386 |
SLJIT_ARGS4(W, W_R, W_R, W, W) |
| 387 |
Arguments are placed into: SLJIT_R0, SLJIT_R1, SLJIT_S0, SLJIT_S1 |
| 388 |
The type of the result is sljit_sw / sljit_uw. |
| 389 |
*/ |
| 390 |
|
| 391 |
/* The following flag is only allowed for the integer arguments of |
| 392 |
sljit_emit_enter. When the flag is set, the integer argument is |
| 393 |
stored in a scratch register instead of a saved register. */ |
| 394 |
#define SLJIT_ARG_TYPE_SCRATCH_REG 0x8 |
| 395 |
|
| 396 |
/* No return value, only supported by SLJIT_ARG_RETURN. */ |
| 397 |
#define SLJIT_ARG_TYPE_RET_VOID 0 |
| 398 |
/* Machine word sized integer argument or result. */ |
| 399 |
#define SLJIT_ARG_TYPE_W 1 |
| 400 |
#define SLJIT_ARG_TYPE_W_R (SLJIT_ARG_TYPE_W | SLJIT_ARG_TYPE_SCRATCH_REG) |
| 401 |
/* 32 bit integer argument or result. */ |
| 402 |
#define SLJIT_ARG_TYPE_32 2 |
| 403 |
#define SLJIT_ARG_TYPE_32_R (SLJIT_ARG_TYPE_32 | SLJIT_ARG_TYPE_SCRATCH_REG) |
| 404 |
/* Pointer sized integer argument or result. */ |
| 405 |
#define SLJIT_ARG_TYPE_P 3 |
| 406 |
#define SLJIT_ARG_TYPE_P_R (SLJIT_ARG_TYPE_P | SLJIT_ARG_TYPE_SCRATCH_REG) |
| 407 |
/* 64 bit floating point argument or result. */ |
| 408 |
#define SLJIT_ARG_TYPE_F64 4 |
| 409 |
/* 32 bit floating point argument or result. */ |
| 410 |
#define SLJIT_ARG_TYPE_F32 5 |
| 411 |
|
| 412 |
#define SLJIT_ARG_SHIFT 4 |
| 413 |
#define SLJIT_ARG_RETURN(type) (type) |
| 414 |
#define SLJIT_ARG_VALUE(type, idx) ((type) << ((idx) * SLJIT_ARG_SHIFT)) |
| 415 |
|
| 416 |
/* Simplified argument list definitions. |
| 417 |
|
| 418 |
The following definition: |
| 419 |
SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_W) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_F32, 1) |
| 420 |
|
| 421 |
can be shortened to: |
| 422 |
SLJIT_ARGS1(W, F32) |
| 423 |
|
| 424 |
Another example where no value is returned: |
| 425 |
SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_RET_VOID) | SLJIT_ARG_VALUE(SLJIT_ARG_TYPE_W_R, 1) |
| 426 |
|
| 427 |
can be shortened to: |
| 428 |
SLJIT_ARGS1V(W_R) |
| 429 |
*/ |
| 430 |
|
| 431 |
#define SLJIT_ARG_TO_TYPE(type) SLJIT_ARG_TYPE_ ## type |
| 432 |
|
| 433 |
#define SLJIT_ARGS0(ret) \ |
| 434 |
SLJIT_ARG_RETURN(SLJIT_ARG_TO_TYPE(ret)) |
| 435 |
#define SLJIT_ARGS0V() \ |
| 436 |
SLJIT_ARG_RETURN(SLJIT_ARG_TYPE_RET_VOID) |
| 437 |
|
| 438 |
#define SLJIT_ARGS1(ret, arg1) \ |
| 439 |
(SLJIT_ARGS0(ret) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg1), 1)) |
| 440 |
#define SLJIT_ARGS1V(arg1) \ |
| 441 |
(SLJIT_ARGS0V() | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg1), 1)) |
| 442 |
|
| 443 |
#define SLJIT_ARGS2(ret, arg1, arg2) \ |
| 444 |
(SLJIT_ARGS1(ret, arg1) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg2), 2)) |
| 445 |
#define SLJIT_ARGS2V(arg1, arg2) \ |
| 446 |
(SLJIT_ARGS1V(arg1) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg2), 2)) |
| 447 |
|
| 448 |
#define SLJIT_ARGS3(ret, arg1, arg2, arg3) \ |
| 449 |
(SLJIT_ARGS2(ret, arg1, arg2) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg3), 3)) |
| 450 |
#define SLJIT_ARGS3V(arg1, arg2, arg3) \ |
| 451 |
(SLJIT_ARGS2V(arg1, arg2) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg3), 3)) |
| 452 |
|
| 453 |
#define SLJIT_ARGS4(ret, arg1, arg2, arg3, arg4) \ |
| 454 |
(SLJIT_ARGS3(ret, arg1, arg2, arg3) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg4), 4)) |
| 455 |
#define SLJIT_ARGS4V(arg1, arg2, arg3, arg4) \ |
| 456 |
(SLJIT_ARGS3V(arg1, arg2, arg3) | SLJIT_ARG_VALUE(SLJIT_ARG_TO_TYPE(arg4), 4)) |
| 457 |
|
| 458 |
/* --------------------------------------------------------------------- */ |
| 459 |
/* Main structures and functions */ |
| 460 |
/* --------------------------------------------------------------------- */ |
| 461 |
|
| 462 |
/* |
| 463 |
The following structures are private, and can be changed in the |
| 464 |
future. Keeping them here allows code inlining. |
| 465 |
*/ |
| 466 |
|
| 467 |
struct sljit_memory_fragment { |
| 468 |
struct sljit_memory_fragment *next; |
| 469 |
sljit_uw used_size; |
| 470 |
/* Must be aligned to sljit_sw. */ |
| 471 |
sljit_u8 memory[1]; |
| 472 |
}; |
| 473 |
|
| 474 |
struct sljit_label { |
| 475 |
struct sljit_label *next; |
| 476 |
union { |
| 477 |
sljit_uw index; |
| 478 |
sljit_uw addr; |
| 479 |
} u; |
| 480 |
/* The maximum size difference. */ |
| 481 |
sljit_uw size; |
| 482 |
}; |
| 483 |
|
| 484 |
struct sljit_jump { |
| 485 |
struct sljit_jump *next; |
| 486 |
sljit_uw addr; |
| 487 |
/* Architecture dependent flags. */ |
| 488 |
sljit_uw flags; |
| 489 |
union { |
| 490 |
sljit_uw target; |
| 491 |
struct sljit_label *label; |
| 492 |
} u; |
| 493 |
}; |
| 494 |
|
| 495 |
struct sljit_const { |
| 496 |
struct sljit_const *next; |
| 497 |
sljit_uw addr; |
| 498 |
}; |
| 499 |
|
| 500 |
struct sljit_generate_code_buffer { |
| 501 |
void *buffer; |
| 502 |
sljit_uw size; |
| 503 |
sljit_sw executable_offset; |
| 504 |
}; |
| 505 |
|
| 506 |
struct sljit_compiler { |
| 507 |
sljit_s32 error; |
| 508 |
sljit_s32 options; |
| 509 |
|
| 510 |
struct sljit_label *labels; |
| 511 |
struct sljit_jump *jumps; |
| 512 |
struct sljit_const *consts; |
| 513 |
struct sljit_label *last_label; |
| 514 |
struct sljit_jump *last_jump; |
| 515 |
struct sljit_const *last_const; |
| 516 |
|
| 517 |
void *allocator_data; |
| 518 |
void *user_data; |
| 519 |
struct sljit_memory_fragment *buf; |
| 520 |
struct sljit_memory_fragment *abuf; |
| 521 |
|
| 522 |
/* Number of labels created by the compiler. */ |
| 523 |
sljit_uw label_count; |
| 524 |
/* Available scratch registers. */ |
| 525 |
sljit_s32 scratches; |
| 526 |
/* Available saved registers. */ |
| 527 |
sljit_s32 saveds; |
| 528 |
/* Available float scratch registers. */ |
| 529 |
sljit_s32 fscratches; |
| 530 |
/* Available float saved registers. */ |
| 531 |
sljit_s32 fsaveds; |
| 532 |
#if (defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) \ |
| 533 |
|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
| 534 |
|| (defined SLJIT_DEBUG && SLJIT_DEBUG) \ |
| 535 |
|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
| 536 |
/* Available vector scratch registers. */ |
| 537 |
sljit_s32 vscratches; |
| 538 |
/* Available vector saved registers. */ |
| 539 |
sljit_s32 vsaveds; |
| 540 |
#endif /* SLJIT_SEPARATE_VECTOR_REGISTERS || SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG || SLJIT_VERBOSE */ |
| 541 |
/* Local stack size. */ |
| 542 |
sljit_s32 local_size; |
| 543 |
/* Maximum code size. */ |
| 544 |
sljit_uw size; |
| 545 |
/* Relative offset of the executable mapping from the writable mapping. */ |
| 546 |
sljit_sw executable_offset; |
| 547 |
/* Executable size for statistical purposes. */ |
| 548 |
sljit_uw executable_size; |
| 549 |
|
| 550 |
#if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE) |
| 551 |
sljit_s32 status_flags_state; |
| 552 |
#endif /* SLJIT_HAS_STATUS_FLAGS_STATE */ |
| 553 |
|
| 554 |
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) |
| 555 |
sljit_s32 args_size; |
| 556 |
#endif /* SLJIT_CONFIG_X86_32 */ |
| 557 |
|
| 558 |
#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) |
| 559 |
/* Temporary fields. */ |
| 560 |
sljit_s32 mode32; |
| 561 |
#endif /* SLJIT_CONFIG_X86_64 */ |
| 562 |
|
| 563 |
#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) |
| 564 |
/* Constant pool handling. */ |
| 565 |
sljit_uw *cpool; |
| 566 |
sljit_u8 *cpool_unique; |
| 567 |
sljit_uw cpool_diff; |
| 568 |
sljit_uw cpool_fill; |
| 569 |
/* Other members. */ |
| 570 |
/* Contains pointer, "ldr pc, [...]" pairs. */ |
| 571 |
sljit_uw patches; |
| 572 |
#endif /* SLJIT_CONFIG_ARM_V6 */ |
| 573 |
|
| 574 |
#if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) |
| 575 |
/* Temporary fields. */ |
| 576 |
sljit_uw shift_imm; |
| 577 |
#endif /* SLJIT_CONFIG_ARM_V6 || SLJIT_CONFIG_ARM_V6 */ |
| 578 |
|
| 579 |
#if (defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && (defined __SOFTFP__) |
| 580 |
sljit_uw args_size; |
| 581 |
#endif /* SLJIT_CONFIG_ARM_32 && __SOFTFP__ */ |
| 582 |
|
| 583 |
#if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) |
| 584 |
/* Temporary fields. */ |
| 585 |
sljit_u32 imm; |
| 586 |
#endif /* SLJIT_CONFIG_PPC */ |
| 587 |
|
| 588 |
#if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) |
| 589 |
sljit_s32 delay_slot; |
| 590 |
/* Temporary fields. */ |
| 591 |
sljit_s32 cache_arg; |
| 592 |
sljit_sw cache_argw; |
| 593 |
#endif /* SLJIT_CONFIG_MIPS */ |
| 594 |
|
| 595 |
#if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) |
| 596 |
sljit_uw args_size; |
| 597 |
#endif /* SLJIT_CONFIG_MIPS_32 */ |
| 598 |
|
| 599 |
#if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) |
| 600 |
/* Temporary fields. */ |
| 601 |
sljit_s32 cache_arg; |
| 602 |
sljit_sw cache_argw; |
| 603 |
#endif /* SLJIT_CONFIG_RISCV */ |
| 604 |
|
| 605 |
#if (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X) |
| 606 |
/* Need to allocate register save area to make calls. */ |
| 607 |
/* Temporary fields. */ |
| 608 |
sljit_s32 mode; |
| 609 |
#endif /* SLJIT_CONFIG_S390X */ |
| 610 |
|
| 611 |
#if (defined SLJIT_CONFIG_LOONGARCH && SLJIT_CONFIG_LOONGARCH) |
| 612 |
/* Temporary fields. */ |
| 613 |
sljit_s32 cache_arg; |
| 614 |
sljit_sw cache_argw; |
| 615 |
#endif /* SLJIT_CONFIG_LOONGARCH */ |
| 616 |
|
| 617 |
#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
| 618 |
FILE* verbose; |
| 619 |
#endif /* SLJIT_VERBOSE */ |
| 620 |
|
| 621 |
/* Note: SLJIT_DEBUG enables SLJIT_ARGUMENT_CHECKS. */ |
| 622 |
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
| 623 |
|| (defined SLJIT_DEBUG && SLJIT_DEBUG) |
| 624 |
/* Flags specified by the last arithmetic instruction. |
| 625 |
It contains the type of the variable flag. */ |
| 626 |
sljit_s32 last_flags; |
| 627 |
/* Return value type set by entry functions. */ |
| 628 |
sljit_s32 last_return; |
| 629 |
/* Local size passed to entry functions. */ |
| 630 |
sljit_s32 logical_local_size; |
| 631 |
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG */ |
| 632 |
|
| 633 |
#if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \ |
| 634 |
|| (defined SLJIT_DEBUG && SLJIT_DEBUG) \ |
| 635 |
|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
| 636 |
#if !(defined SLJIT_SEPARATE_VECTOR_REGISTERS && SLJIT_SEPARATE_VECTOR_REGISTERS) |
| 637 |
/* Available float scratch registers. */ |
| 638 |
sljit_s32 real_fscratches; |
| 639 |
/* Available float saved registers. */ |
| 640 |
sljit_s32 real_fsaveds; |
| 641 |
#endif /* !SLJIT_SEPARATE_VECTOR_REGISTERS */ |
| 642 |
|
| 643 |
/* Trust arguments when an API function is called. |
| 644 |
Used internally for calling API functions. */ |
| 645 |
sljit_s32 skip_checks; |
| 646 |
#endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_DEBUG || SLJIT_VERBOSE */ |
| 647 |
}; |
| 648 |
|
| 649 |
/* --------------------------------------------------------------------- */ |
| 650 |
/* Main functions */ |
| 651 |
/* --------------------------------------------------------------------- */ |
| 652 |
|
| 653 |
/* Creates an SLJIT compiler. The allocator_data is required by some |
| 654 |
custom memory managers. This pointer is passed to SLJIT_MALLOC |
| 655 |
and SLJIT_FREE macros. Most allocators (including the default |
| 656 |
one) ignores this value, and it is recommended to pass NULL |
| 657 |
as a dummy value for allocator_data. |
| 658 |
|
| 659 |
Returns NULL if failed. */ |
| 660 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data); |
| 661 |
|
| 662 |
/* Frees everything except the compiled machine code. */ |
| 663 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler); |
| 664 |
|
| 665 |
/* Returns the current error code. If an error occurres, future calls |
| 666 |
which uses the same compiler argument returns early with the same |
| 667 |
error code. Thus there is no need for checking the error after every |
| 668 |
call, it is enough to do it after the code is compiled. Removing |
| 669 |
these checks increases the performance of the compiling process. */ |
| 670 |
static SLJIT_INLINE sljit_s32 sljit_get_compiler_error(struct sljit_compiler *compiler) { return compiler->error; } |
| 671 |
|
| 672 |
/* Sets the compiler error code to SLJIT_ERR_ALLOC_FAILED except |
| 673 |
if an error was detected before. After the error code is set |
| 674 |
the compiler behaves as if the allocation failure happened |
| 675 |
during an SLJIT function call. This can greatly simplify error |
| 676 |
checking, since it is enough to check the compiler status |
| 677 |
after the code is compiled. */ |
| 678 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler); |
| 679 |
|
| 680 |
/* Allocate a small amount of memory. The size must be <= 64 bytes on 32 bit, |
| 681 |
and <= 128 bytes on 64 bit architectures. The memory area is owned by the |
| 682 |
compiler, and freed by sljit_free_compiler. The returned pointer is |
| 683 |
sizeof(sljit_sw) aligned. Excellent for allocating small blocks during |
| 684 |
compiling, and no need to worry about freeing them. The size is enough |
| 685 |
to contain at most 16 pointers. If the size is outside of the range, |
| 686 |
the function will return with NULL. However, this return value does not |
| 687 |
indicate that there is no more memory (does not set the current error code |
| 688 |
of the compiler to out-of-memory status). */ |
| 689 |
SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size); |
| 690 |
|
| 691 |
/* Returns the allocator data passed to sljit_create_compiler. */ |
| 692 |
static SLJIT_INLINE void* sljit_compiler_get_allocator_data(struct sljit_compiler *compiler) { return compiler->allocator_data; } |
| 693 |
/* Sets/get the user data for a compiler. */ |
| 694 |
static SLJIT_INLINE void sljit_compiler_set_user_data(struct sljit_compiler *compiler, void *user_data) { compiler->user_data = user_data; } |
| 695 |
static SLJIT_INLINE void* sljit_compiler_get_user_data(struct sljit_compiler *compiler) { return compiler->user_data; } |
| 696 |
|
| 697 |
#if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) |
| 698 |
/* Passing NULL disables verbose. */ |
| 699 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose); |
| 700 |
#endif /* SLJIT_VERBOSE */ |
| 701 |
|
| 702 |
/* Option bits for sljit_generate_code. */ |
| 703 |
|
| 704 |
/* The exec_allocator_data points to a pre-allocated |
| 705 |
buffer which type is sljit_generate_code_buffer. */ |
| 706 |
#define SLJIT_GENERATE_CODE_BUFFER 0x1 |
| 707 |
|
| 708 |
/* Create executable code from the instruction stream. This is the final step |
| 709 |
of the code generation, and no more instructions can be emitted after this call. |
| 710 |
|
| 711 |
options is the combination of SLJIT_GENERATE_CODE_* bits |
| 712 |
exec_allocator_data is passed to SLJIT_MALLOC_EXEC and |
| 713 |
SLJIT_MALLOC_FREE functions */ |
| 714 |
|
| 715 |
SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler, sljit_s32 options, void *exec_allocator_data); |
| 716 |
|
| 717 |
/* Free executable code. */ |
| 718 |
|
| 719 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data); |
| 720 |
|
| 721 |
/* When the protected executable allocator is used the JIT code is mapped |
| 722 |
twice. The first mapping has read/write and the second mapping has read/exec |
| 723 |
permissions. This function returns with the relative offset of the executable |
| 724 |
mapping using the writable mapping as the base after the machine code is |
| 725 |
successfully generated. The returned value is always 0 for the normal executable |
| 726 |
allocator, since it uses only one mapping with read/write/exec permissions. |
| 727 |
Dynamic code modifications requires this value. |
| 728 |
|
| 729 |
Before a successful code generation, this function returns with 0. */ |
| 730 |
static SLJIT_INLINE sljit_sw sljit_get_executable_offset(struct sljit_compiler *compiler) { return compiler->executable_offset; } |
| 731 |
|
| 732 |
/* The executable memory consumption of the generated code can be retrieved by |
| 733 |
this function. The returned value can be used for statistical purposes. |
| 734 |
|
| 735 |
Before a successful code generation, this function returns with 0. */ |
| 736 |
static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; } |
| 737 |
|
| 738 |
/* Returns with non-zero if the feature or limitation type passed as its |
| 739 |
argument is present on the current CPU. The return value is one, if a |
| 740 |
feature is fully supported, and it is two, if partially supported. |
| 741 |
|
| 742 |
Some features (e.g. floating point operations) require hardware (CPU) |
| 743 |
support while others (e.g. move with update) are emulated if not available. |
| 744 |
However, even when a feature is emulated, specialized code paths may be |
| 745 |
faster than the emulation. Some limitations are emulated as well so their |
| 746 |
general case is supported but it has extra performance costs. |
| 747 |
|
| 748 |
Note: sljitConfigInternal.h also provides several feature detection macros. */ |
| 749 |
|
| 750 |
/* [Not emulated] Floating-point support is available. */ |
| 751 |
#define SLJIT_HAS_FPU 0 |
| 752 |
/* [Limitation] Some registers are virtual registers. */ |
| 753 |
#define SLJIT_HAS_VIRTUAL_REGISTERS 1 |
| 754 |
/* [Emulated] Has zero register (setting a memory location to zero is efficient). */ |
| 755 |
#define SLJIT_HAS_ZERO_REGISTER 2 |
| 756 |
/* [Emulated] Count leading zero is supported. */ |
| 757 |
#define SLJIT_HAS_CLZ 3 |
| 758 |
/* [Emulated] Count trailing zero is supported. */ |
| 759 |
#define SLJIT_HAS_CTZ 4 |
| 760 |
/* [Emulated] Reverse the order of bytes is supported. */ |
| 761 |
#define SLJIT_HAS_REV 5 |
| 762 |
/* [Emulated] Rotate left/right is supported. */ |
| 763 |
#define SLJIT_HAS_ROT 6 |
| 764 |
/* [Emulated] Conditional move is supported. */ |
| 765 |
#define SLJIT_HAS_CMOV 7 |
| 766 |
/* [Emulated] Prefetch instruction is available (emulated as a nop). */ |
| 767 |
#define SLJIT_HAS_PREFETCH 8 |
| 768 |
/* [Emulated] Copy from/to f32 operation is available (see sljit_emit_fcopy). */ |
| 769 |
#define SLJIT_HAS_COPY_F32 9 |
| 770 |
/* [Emulated] Copy from/to f64 operation is available (see sljit_emit_fcopy). */ |
| 771 |
#define SLJIT_HAS_COPY_F64 10 |
| 772 |
/* [Not emulated] The 64 bit floating point registers can be used as |
| 773 |
two separate 32 bit floating point registers (e.g. ARM32). The |
| 774 |
second 32 bit part can be accessed by SLJIT_F64_SECOND. */ |
| 775 |
#define SLJIT_HAS_F64_AS_F32_PAIR 11 |
| 776 |
/* [Not emulated] Some SIMD operations are supported by the compiler. */ |
| 777 |
#define SLJIT_HAS_SIMD 12 |
| 778 |
/* [Not emulated] SIMD registers are mapped to a pair of double precision |
| 779 |
floating point registers. E.g. passing either SLJIT_FR0 or SLJIT_FR1 to |
| 780 |
a simd operation represents the same 128 bit register, and both SLJIT_FR0 |
| 781 |
and SLJIT_FR1 are overwritten. */ |
| 782 |
#define SLJIT_SIMD_REGS_ARE_PAIRS 13 |
| 783 |
/* [Not emulated] Atomic support is available. */ |
| 784 |
#define SLJIT_HAS_ATOMIC 14 |
| 785 |
/* [Not emulated] Memory barrier support is available. */ |
| 786 |
#define SLJIT_HAS_MEMORY_BARRIER 15 |
| 787 |
|
| 788 |
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
| 789 |
/* [Not emulated] AVX support is available on x86. */ |
| 790 |
#define SLJIT_HAS_AVX 100 |
| 791 |
/* [Not emulated] AVX2 support is available on x86. */ |
| 792 |
#define SLJIT_HAS_AVX2 101 |
| 793 |
#endif /* SLJIT_CONFIG_X86 */ |
| 794 |
|
| 795 |
#if (defined SLJIT_CONFIG_LOONGARCH) |
| 796 |
/* [Not emulated] LASX support is available on LoongArch */ |
| 797 |
#define SLJIT_HAS_LASX 201 |
| 798 |
#endif /* SLJIT_CONFIG_LOONGARCH */ |
| 799 |
|
| 800 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type); |
| 801 |
|
| 802 |
/* If type is between SLJIT_ORDERED_EQUAL and SLJIT_ORDERED_LESS_EQUAL, |
| 803 |
sljit_cmp_info returns with: |
| 804 |
zero - if the cpu supports the floating point comparison type |
| 805 |
one - if the comparison requires two machine instructions |
| 806 |
two - if the comparison requires more than two machine instructions |
| 807 |
|
| 808 |
When the result is non-zero, it is recommended to avoid |
| 809 |
using the specified comparison type if it is easy to do so. |
| 810 |
|
| 811 |
Otherwise it returns zero. */ |
| 812 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type); |
| 813 |
|
| 814 |
/* The following functions generate machine code. If there is no |
| 815 |
error, they return with SLJIT_SUCCESS, otherwise they return |
| 816 |
with an error code. */ |
| 817 |
|
| 818 |
/* |
| 819 |
The executable code is a callable function from the viewpoint |
| 820 |
of the C language. Function calls must conform with the ABI |
| 821 |
(Application Binary Interface) of the target platform, which |
| 822 |
specify the purpose of machine registers and stack handling |
| 823 |
among other things. The sljit_emit_enter function emits the |
| 824 |
necessary instructions for setting up an entry point for the |
| 825 |
executable code. This is often called as function prologue. |
| 826 |
|
| 827 |
The "options" argument can be used to pass configuration options |
| 828 |
to the sljit compiler which affects the generated code, until |
| 829 |
another sljit_emit_enter or sljit_set_context is called. The |
| 830 |
available options are listed before sljit_emit_enter. |
| 831 |
|
| 832 |
The function argument list is specified by the SLJIT_ARGSx |
| 833 |
(SLJIT_ARGS0 .. SLJIT_ARGS4) macros. Currently maximum four |
| 834 |
arguments are supported. See the description of SLJIT_ARGSx |
| 835 |
macros about argument passing. |
| 836 |
|
| 837 |
The register set used by the function must be declared as well. |
| 838 |
The number of scratch and saved registers available to the |
| 839 |
function must be passed to sljit_emit_enter. Only R registers |
| 840 |
between R0 and "scratches" argument can be used later. E.g. |
| 841 |
if "scratches" is set to two, the scratch register set will |
| 842 |
be limited to SLJIT_R0 and SLJIT_R1. The S registers are |
| 843 |
declared in a similar manner, but their count is specified |
| 844 |
by "saveds" argument. The floating point scratch and saved |
| 845 |
registers can be set by using "scratches" and "saveds" argument |
| 846 |
as well, but their value must be passed to the SLJIT_ENTER_FLOAT |
| 847 |
macro, see below. |
| 848 |
|
| 849 |
The sljit_emit_enter is also capable of allocating a stack |
| 850 |
space for local data. The "local_size" argument contains the |
| 851 |
size in bytes of this local area, and it can be accessed using |
| 852 |
SLJIT_MEM1(SLJIT_SP). The memory area between SLJIT_SP (inclusive) |
| 853 |
and SLJIT_SP + local_size (exclusive) can be modified freely |
| 854 |
until the function returns. The alocated stack space is an |
| 855 |
uninitialized memory area. |
| 856 |
|
| 857 |
Floating point scratch and saved registers must be specified |
| 858 |
by the SLJIT_ENTER_FLOAT macro, which result value should be |
| 859 |
combined with scratches / saveds argument. |
| 860 |
|
| 861 |
Examples: |
| 862 |
To use three scratch and four floating point scratch |
| 863 |
registers, the "scratches" argument must be set to: |
| 864 |
3 | SLJIT_ENTER_FLOAT(4) |
| 865 |
|
| 866 |
To use six saved and five floating point saved |
| 867 |
registers, the "saveds" argument must be set to: |
| 868 |
6 | SLJIT_ENTER_FLOAT(5) |
| 869 |
|
| 870 |
Note: the following conditions must met: |
| 871 |
0 <= scratches <= SLJIT_NUMBER_OF_REGISTERS |
| 872 |
0 <= saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS |
| 873 |
scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS |
| 874 |
|
| 875 |
0 <= float scratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS |
| 876 |
0 <= float saveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS |
| 877 |
float scratches + float saveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS |
| 878 |
|
| 879 |
Note: the compiler can use saved registers as scratch registers, |
| 880 |
but the opposite is not supported |
| 881 |
|
| 882 |
Note: every call of sljit_emit_enter and sljit_set_context |
| 883 |
overwrites the previous context. |
| 884 |
*/ |
| 885 |
|
| 886 |
/* The following options are available for sljit_emit_enter. */ |
| 887 |
|
| 888 |
/* Saved registers between SLJIT_S0 and SLJIT_S(n - 1) (inclusive) |
| 889 |
are not saved / restored on function enter / return. Instead, |
| 890 |
these registers can be used to pass / return data (such as |
| 891 |
global / local context pointers) across function calls. The |
| 892 |
value of n must be between 1 and 3. This option is only |
| 893 |
supported by SLJIT_ENTER_REG_ARG calling convention. */ |
| 894 |
#define SLJIT_ENTER_KEEP(n) (n) |
| 895 |
|
| 896 |
/* The compiled function uses an SLJIT specific register argument |
| 897 |
calling convention. This is a lightweight function call type where |
| 898 |
both the caller and the called functions must be compiled by |
| 899 |
SLJIT. The type argument of the call must be SLJIT_CALL_REG_ARG |
| 900 |
and all arguments must be stored in scratch registers. */ |
| 901 |
#define SLJIT_ENTER_REG_ARG 0x00000004 |
| 902 |
|
| 903 |
#if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) |
| 904 |
/* Use VEX prefix for all SIMD operations on x86. */ |
| 905 |
#define SLJIT_ENTER_USE_VEX 0x00010000 |
| 906 |
#endif /* !SLJIT_CONFIG_X86 */ |
| 907 |
|
| 908 |
/* Macros for other sljit_emit_enter arguments. */ |
| 909 |
|
| 910 |
/* Floating point scratch and saved registers can be |
| 911 |
specified by SLJIT_ENTER_FLOAT. */ |
| 912 |
#define SLJIT_ENTER_FLOAT(regs) ((regs) << 8) |
| 913 |
|
| 914 |
/* Vector scratch and saved registers can be specified |
| 915 |
by SLJIT_ENTER_VECTOR. */ |
| 916 |
#define SLJIT_ENTER_VECTOR(regs) ((regs) << 16) |
| 917 |
|
| 918 |
/* The local_size must be >= 0 and <= SLJIT_MAX_LOCAL_SIZE. */ |
| 919 |
#define SLJIT_MAX_LOCAL_SIZE 1048576 |
| 920 |
|
| 921 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler, |
| 922 |
sljit_s32 options, sljit_s32 arg_types, |
| 923 |
sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size); |
| 924 |
|
| 925 |
/* The SLJIT compiler has a current context (which contains the local |
| 926 |
stack space size, number of used registers, etc.) which is initialized |
| 927 |
by sljit_emit_enter. Several functions (such as sljit_emit_return) |
| 928 |
requires this context to be able to generate the appropriate code. |
| 929 |
However, some code fragments (compiled separately) may have no |
| 930 |
normal entry point so their context is unknown to the compiler. |
| 931 |
|
| 932 |
sljit_set_context and sljit_emit_enter have the same arguments, |
| 933 |
but sljit_set_context does not generate any machine code. |
| 934 |
|
| 935 |
Note: every call of sljit_emit_enter and sljit_set_context overwrites |
| 936 |
the previous context. */ |
| 937 |
|
| 938 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler, |
| 939 |
sljit_s32 options, sljit_s32 arg_types, |
| 940 |
sljit_s32 scratches, sljit_s32 saveds, sljit_s32 local_size); |
| 941 |
|
| 942 |
/* Return to the caller function. The sljit_emit_return_void function |
| 943 |
does not return with any value. The sljit_emit_return function returns |
| 944 |
with a single value loaded from its source operand. The load operation |
| 945 |
can be between SLJIT_MOV and SLJIT_MOV_P (see sljit_emit_op1) and |
| 946 |
SLJIT_MOV_F32/SLJIT_MOV_F64 (see sljit_emit_fop1) depending on the |
| 947 |
return value specified by sljit_emit_enter/sljit_set_context. */ |
| 948 |
|
| 949 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler); |
| 950 |
|
| 951 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, |
| 952 |
sljit_s32 src, sljit_sw srcw); |
| 953 |
|
| 954 |
/* Restores the saved registers and free the stack area, then the execution |
| 955 |
continues from the address specified by the source operand. This |
| 956 |
operation is similar to sljit_emit_return, but it ignores the return |
| 957 |
address. The code where the exection continues should use the same context |
| 958 |
as the caller function (see sljit_set_context). A word (pointer) value |
| 959 |
can be passed in the SLJIT_RETURN_REG register. This function can be used |
| 960 |
to jump to exception handlers. */ |
| 961 |
|
| 962 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_to(struct sljit_compiler *compiler, |
| 963 |
sljit_s32 src, sljit_sw srcw); |
| 964 |
|
| 965 |
/* |
| 966 |
Source and destination operands for arithmetical instructions |
| 967 |
imm - a simple immediate value (cannot be used as a destination) |
| 968 |
reg - any of the available registers (immediate argument must be 0) |
| 969 |
[imm] - absolute memory address |
| 970 |
[reg+imm] - indirect memory address |
| 971 |
[reg+(reg<<imm)] - indirect indexed memory address (shift must be between 0 and 3) |
| 972 |
useful for accessing arrays (fully supported by both x86 and |
| 973 |
ARM architectures, and cheap operation on others) |
| 974 |
*/ |
| 975 |
|
| 976 |
/* |
| 977 |
IMPORTANT NOTE: memory accesses MUST be naturally aligned unless |
| 978 |
SLJIT_UNALIGNED macro is defined and its value is 1. |
| 979 |
|
| 980 |
length | alignment |
| 981 |
---------+----------- |
| 982 |
byte | 1 byte (any physical_address is accepted) |
| 983 |
half | 2 byte (physical_address & 0x1 == 0) |
| 984 |
int | 4 byte (physical_address & 0x3 == 0) |
| 985 |
word | 4 byte if SLJIT_32BIT_ARCHITECTURE is defined and its value is 1 |
| 986 |
| 8 byte if SLJIT_64BIT_ARCHITECTURE is defined and its value is 1 |
| 987 |
pointer | size of sljit_up type (4 byte on 32 bit machines, 4 or 8 byte |
| 988 |
| on 64 bit machines) |
| 989 |
|
| 990 |
Note: Different architectures have different addressing limitations. |
| 991 |
A single instruction is enough for the following addressing |
| 992 |
modes. Other addressing modes are emulated by instruction |
| 993 |
sequences. This information could help to improve those code |
| 994 |
generators which focuses only a few architectures. |
| 995 |
|
| 996 |
x86: [reg+imm], -2^32+1 <= imm <= 2^32-1 (full address space on x86-32) |
| 997 |
[reg+(reg<<imm)] is supported |
| 998 |
[imm], -2^32+1 <= imm <= 2^32-1 is supported |
| 999 |
Write-back is not supported |
| 1000 |
arm: [reg+imm], -4095 <= imm <= 4095 or -255 <= imm <= 255 for signed |
| 1001 |
bytes, any halfs or floating point values) |
| 1002 |
[reg+(reg<<imm)] is supported |
| 1003 |
Write-back is supported |
| 1004 |
arm-t2: [reg+imm], -255 <= imm <= 4095 |
| 1005 |
[reg+(reg<<imm)] is supported |
| 1006 |
Write back is supported only for [reg+imm], where -255 <= imm <= 255 |
| 1007 |
arm64: [reg+imm], -256 <= imm <= 255, 0 <= aligned imm <= 4095 * alignment |
| 1008 |
[reg+(reg<<imm)] is supported |
| 1009 |
Write back is supported only for [reg+imm], where -256 <= imm <= 255 |
| 1010 |
ppc: [reg+imm], -65536 <= imm <= 65535. 64 bit loads/stores and 32 bit |
| 1011 |
signed load on 64 bit requires immediates divisible by 4. |
| 1012 |
[reg+imm] is not supported for signed 8 bit values. |
| 1013 |
[reg+reg] is supported |
| 1014 |
Write-back is supported except for one instruction: 32 bit signed |
| 1015 |
load with [reg+imm] addressing mode on 64 bit. |
| 1016 |
mips: [reg+imm], -65536 <= imm <= 65535 |
| 1017 |
Write-back is not supported |
| 1018 |
riscv: [reg+imm], -2048 <= imm <= 2047 |
| 1019 |
Write-back is not supported |
| 1020 |
s390x: [reg+imm], -2^19 <= imm < 2^19 |
| 1021 |
[reg+reg] is supported |
| 1022 |
Write-back is not supported |
| 1023 |
loongarch: [reg+imm], -2048 <= imm <= 2047 |
| 1024 |
[reg+reg] is supported |
| 1025 |
Write-back is not supported |
| 1026 |
*/ |
| 1027 |
|
| 1028 |
/* Macros for specifying operand types. */ |
| 1029 |
#define SLJIT_MEM 0x80 |
| 1030 |
#define SLJIT_MEM0() (SLJIT_MEM) |
| 1031 |
#define SLJIT_MEM1(r1) (SLJIT_MEM | (r1)) |
| 1032 |
#define SLJIT_MEM2(r1, r2) (SLJIT_MEM | (r1) | ((r2) << 8)) |
| 1033 |
#define SLJIT_IMM 0x7f |
| 1034 |
#define SLJIT_REG_PAIR(r1, r2) ((r1) | ((r2) << 8)) |
| 1035 |
|
| 1036 |
/* Macros for checking operand types (only for valid arguments). */ |
| 1037 |
#define SLJIT_IS_REG(arg) ((arg) > 0 && (arg) < SLJIT_IMM) |
| 1038 |
#define SLJIT_IS_MEM(arg) ((arg) & SLJIT_MEM) |
| 1039 |
#define SLJIT_IS_MEM0(arg) ((arg) == SLJIT_MEM) |
| 1040 |
#define SLJIT_IS_MEM1(arg) ((arg) > SLJIT_MEM && (arg) < (SLJIT_MEM << 1)) |
| 1041 |
#define SLJIT_IS_MEM2(arg) (((arg) & SLJIT_MEM) && (arg) >= (SLJIT_MEM << 1)) |
| 1042 |
#define SLJIT_IS_IMM(arg) ((arg) == SLJIT_IMM) |
| 1043 |
#define SLJIT_IS_REG_PAIR(arg) (!((arg) & SLJIT_MEM) && (arg) >= (SLJIT_MEM << 1)) |
| 1044 |
|
| 1045 |
/* Macros for extracting registers from operands. */ |
| 1046 |
/* Support operands which contains a single register or |
| 1047 |
constructed using SLJIT_MEM1, SLJIT_MEM2, or SLJIT_REG_PAIR. */ |
| 1048 |
#define SLJIT_EXTRACT_REG(arg) ((arg) & 0x7f) |
| 1049 |
/* Support operands which constructed using SLJIT_MEM2, or SLJIT_REG_PAIR. */ |
| 1050 |
#define SLJIT_EXTRACT_SECOND_REG(arg) ((arg) >> 8) |
| 1051 |
|
| 1052 |
/* Sets 32 bit operation mode on 64 bit CPUs. This option is ignored on |
| 1053 |
32 bit CPUs. When this option is set for an arithmetic operation, only |
| 1054 |
the lower 32 bits of the input registers are used, and the CPU status |
| 1055 |
flags are set according to the 32 bit result. Although the higher 32 bit |
| 1056 |
of the input and the result registers are not defined by SLJIT, it might |
| 1057 |
be defined by the CPU architecture (e.g. MIPS). To satisfy these CPU |
| 1058 |
requirements all source registers must be the result of those operations |
| 1059 |
where this option was also set. Memory loads read 32 bit values rather |
| 1060 |
than 64 bit ones. In other words 32 bit and 64 bit operations cannot be |
| 1061 |
mixed. The only exception is SLJIT_MOV32 which source register can hold |
| 1062 |
any 32 or 64 bit value, and it is converted to a 32 bit compatible format |
| 1063 |
first. When the source and destination registers are the same, this |
| 1064 |
conversion is free (no instructions are emitted) on most CPUs. A 32 bit |
| 1065 |
value can also be converted to a 64 bit value by SLJIT_MOV_S32 |
| 1066 |
(sign extension) or SLJIT_MOV_U32 (zero extension). |
| 1067 |
|
| 1068 |
As for floating-point operations, this option sets 32 bit single |
| 1069 |
precision mode. Similar to the integer operations, all register arguments |
| 1070 |
must be the result of those operations where this option was also set. |
| 1071 |
|
| 1072 |
Note: memory addressing always uses 64 bit values on 64 bit systems so |
| 1073 |
the result of a 32 bit operation must not be used with SLJIT_MEMx |
| 1074 |
macros. |
| 1075 |
|
| 1076 |
This option is part of the instruction name, so there is no need to |
| 1077 |
manually set it. E.g: |
| 1078 |
|
| 1079 |
SLJIT_ADD32 == (SLJIT_ADD | SLJIT_32) */ |
| 1080 |
#define SLJIT_32 0x100 |
| 1081 |
|
| 1082 |
/* Many CPUs (x86, ARM, PPC) have status flag bits which can be set according |
| 1083 |
to the result of an operation. Other CPUs (MIPS) do not have status |
| 1084 |
flag bits, and results must be stored in registers. To cover both |
| 1085 |
architecture types efficiently only two flags are defined by SLJIT: |
| 1086 |
|
| 1087 |
* Zero (equal) flag: it is set if the result is zero |
| 1088 |
* Variable flag: its value is defined by the arithmetic operation |
| 1089 |
|
| 1090 |
SLJIT instructions can set any or both of these flags. The value of |
| 1091 |
these flags is undefined if the instruction does not specify their |
| 1092 |
value. The description of each instruction contains the list of |
| 1093 |
allowed flag types. |
| 1094 |
|
| 1095 |
Note: the logical or operation can be used to set flags. |
| 1096 |
|
| 1097 |
Example: SLJIT_ADD can set the Z, OVERFLOW, CARRY flags hence |
| 1098 |
|
| 1099 |
sljit_op2(..., SLJIT_ADD, ...) |
| 1100 |
Both the zero and variable flags are undefined so they can |
| 1101 |
have any value after the operation is completed. |
| 1102 |
|
| 1103 |
sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...) |
| 1104 |
Sets the zero flag if the result is zero, clears it otherwise. |
| 1105 |
The variable flag is undefined. |
| 1106 |
|
| 1107 |
sljit_op2(..., SLJIT_ADD | SLJIT_SET_OVERFLOW, ...) |
| 1108 |
Sets the variable flag if an integer overflow occurs, clears |
| 1109 |
it otherwise. The zero flag is undefined. |
| 1110 |
|
| 1111 |
sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z | SLJIT_SET_CARRY, ...) |
| 1112 |
Sets the zero flag if the result is zero, clears it otherwise. |
| 1113 |
Sets the variable flag if unsigned overflow (carry) occurs, |
| 1114 |
clears it otherwise. |
| 1115 |
|
| 1116 |
Certain instructions (e.g. SLJIT_MOV) does not modify flags, so |
| 1117 |
status flags are unchanged. |
| 1118 |
|
| 1119 |
Example: |
| 1120 |
|
| 1121 |
sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...) |
| 1122 |
sljit_op1(..., SLJIT_MOV, ...) |
| 1123 |
Zero flag is set according to the result of SLJIT_ADD. |
| 1124 |
|
| 1125 |
sljit_op2(..., SLJIT_ADD | SLJIT_SET_Z, ...) |
| 1126 |
sljit_op2(..., SLJIT_ADD, ...) |
| 1127 |
Zero flag has unknown value. |
| 1128 |
|
| 1129 |
These flags can be used for code optimization. E.g. a fast loop can be |
| 1130 |
implemented by decreasing a counter register and set the zero flag |
| 1131 |
using a single instruction. The zero register can be used by a |
| 1132 |
conditional jump to restart the loop. A single comparison can set a |
| 1133 |
zero and less flags to check if a value is less, equal, or greater |
| 1134 |
than another value. |
| 1135 |
|
| 1136 |
Motivation: although some CPUs can set a large number of flag bits, |
| 1137 |
usually their values are ignored or only a few of them are used. Emulating |
| 1138 |
a large number of flags on systems without a flag register is complicated |
| 1139 |
so SLJIT instructions must specify the flag they want to use and only |
| 1140 |
that flag is computed. The last arithmetic instruction can be repeated if |
| 1141 |
multiple flags need to be checked. |
| 1142 |
*/ |
| 1143 |
|
| 1144 |
/* Set Zero status flag. */ |
| 1145 |
#define SLJIT_SET_Z 0x0200 |
| 1146 |
/* Set the variable status flag if condition is true. |
| 1147 |
See comparison types (e.g. SLJIT_SET_LESS, SLJIT_SET_F_EQUAL). */ |
| 1148 |
#define SLJIT_SET(condition) ((condition) << 10) |
| 1149 |
|
| 1150 |
/* Starting index of opcodes for sljit_emit_op0. */ |
| 1151 |
#define SLJIT_OP0_BASE 0 |
| 1152 |
|
| 1153 |
/* Flags: - (does not modify flags) |
| 1154 |
Note: breakpoint instruction is not supported by all architectures (e.g. ppc) |
| 1155 |
It falls back to SLJIT_NOP in those cases. */ |
| 1156 |
#define SLJIT_BREAKPOINT (SLJIT_OP0_BASE + 0) |
| 1157 |
/* Flags: - (does not modify flags) |
| 1158 |
Note: may or may not cause an extra cycle wait |
| 1159 |
it can even decrease the runtime in a few cases. */ |
| 1160 |
#define SLJIT_NOP (SLJIT_OP0_BASE + 1) |
| 1161 |
/* Flags: - (may destroy flags) |
| 1162 |
Unsigned multiplication of SLJIT_R0 and SLJIT_R1. |
| 1163 |
Result is placed into SLJIT_R1:SLJIT_R0 (high:low) word */ |
| 1164 |
#define SLJIT_LMUL_UW (SLJIT_OP0_BASE + 2) |
| 1165 |
/* Flags: - (may destroy flags) |
| 1166 |
Signed multiplication of SLJIT_R0 and SLJIT_R1. |
| 1167 |
Result is placed into SLJIT_R1:SLJIT_R0 (high:low) word */ |
| 1168 |
#define SLJIT_LMUL_SW (SLJIT_OP0_BASE + 3) |
| 1169 |
/* Flags: - (may destroy flags) |
| 1170 |
Unsigned divide of the value in SLJIT_R0 by the value in SLJIT_R1. |
| 1171 |
The result is placed into SLJIT_R0 and the remainder into SLJIT_R1. |
| 1172 |
Note: if SLJIT_R1 is 0, the behaviour is undefined. */ |
| 1173 |
#define SLJIT_DIVMOD_UW (SLJIT_OP0_BASE + 4) |
| 1174 |
#define SLJIT_DIVMOD_U32 (SLJIT_DIVMOD_UW | SLJIT_32) |
| 1175 |
/* Flags: - (may destroy flags) |
| 1176 |
Signed divide of the value in SLJIT_R0 by the value in SLJIT_R1. |
| 1177 |
The result is placed into SLJIT_R0 and the remainder into SLJIT_R1. |
| 1178 |
Note: if SLJIT_R1 is 0, the behaviour is undefined. |
| 1179 |
Note: if SLJIT_R1 is -1 and SLJIT_R0 is integer min (0x800..00), |
| 1180 |
the behaviour is undefined. */ |
| 1181 |
#define SLJIT_DIVMOD_SW (SLJIT_OP0_BASE + 5) |
| 1182 |
#define SLJIT_DIVMOD_S32 (SLJIT_DIVMOD_SW | SLJIT_32) |
| 1183 |
/* Flags: - (may destroy flags) |
| 1184 |
Unsigned divide of the value in SLJIT_R0 by the value in SLJIT_R1. |
| 1185 |
The result is placed into SLJIT_R0. SLJIT_R1 preserves its value. |
| 1186 |
Note: if SLJIT_R1 is 0, the behaviour is undefined. */ |
| 1187 |
#define SLJIT_DIV_UW (SLJIT_OP0_BASE + 6) |
| 1188 |
#define SLJIT_DIV_U32 (SLJIT_DIV_UW | SLJIT_32) |
| 1189 |
/* Flags: - (may destroy flags) |
| 1190 |
Signed divide of the value in SLJIT_R0 by the value in SLJIT_R1. |
| 1191 |
The result is placed into SLJIT_R0. SLJIT_R1 preserves its value. |
| 1192 |
Note: if SLJIT_R1 is 0, the behaviour is undefined. |
| 1193 |
Note: if SLJIT_R1 is -1 and SLJIT_R0 is integer min (0x800..00), |
| 1194 |
the behaviour is undefined. */ |
| 1195 |
#define SLJIT_DIV_SW (SLJIT_OP0_BASE + 7) |
| 1196 |
#define SLJIT_DIV_S32 (SLJIT_DIV_SW | SLJIT_32) |
| 1197 |
/* Flags: - (does not modify flags) |
| 1198 |
May return with SLJIT_ERR_UNSUPPORTED if SLJIT_HAS_MEMORY_BARRIER |
| 1199 |
feature is not supported (calling sljit_has_cpu_feature() with |
| 1200 |
this feature option returns with 0). */ |
| 1201 |
#define SLJIT_MEMORY_BARRIER (SLJIT_OP0_BASE + 8) |
| 1202 |
/* Flags: - (does not modify flags) |
| 1203 |
ENDBR32 instruction for x86-32 and ENDBR64 instruction for x86-64 |
| 1204 |
when Intel Control-flow Enforcement Technology (CET) is enabled. |
| 1205 |
No instructions are emitted for other architectures. */ |
| 1206 |
#define SLJIT_ENDBR (SLJIT_OP0_BASE + 9) |
| 1207 |
/* Flags: - (may destroy flags) |
| 1208 |
Skip stack frames before return when Intel Control-flow |
| 1209 |
Enforcement Technology (CET) is enabled. No instructions |
| 1210 |
are emitted for other architectures. */ |
| 1211 |
#define SLJIT_SKIP_FRAMES_BEFORE_RETURN (SLJIT_OP0_BASE + 10) |
| 1212 |
|
| 1213 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op); |
| 1214 |
|
| 1215 |
/* Starting index of opcodes for sljit_emit_op1. */ |
| 1216 |
#define SLJIT_OP1_BASE 32 |
| 1217 |
|
| 1218 |
/* The MOV instruction transfers data from source to destination. |
| 1219 |
|
| 1220 |
MOV instruction suffixes: |
| 1221 |
|
| 1222 |
U8 - unsigned 8 bit data transfer |
| 1223 |
S8 - signed 8 bit data transfer |
| 1224 |
U16 - unsigned 16 bit data transfer |
| 1225 |
S16 - signed 16 bit data transfer |
| 1226 |
U32 - unsigned int (32 bit) data transfer |
| 1227 |
S32 - signed int (32 bit) data transfer |
| 1228 |
P - pointer (sljit_up) data transfer |
| 1229 |
*/ |
| 1230 |
|
| 1231 |
/* Flags: - (does not modify flags) */ |
| 1232 |
#define SLJIT_MOV (SLJIT_OP1_BASE + 0) |
| 1233 |
/* Flags: - (does not modify flags) */ |
| 1234 |
#define SLJIT_MOV_U8 (SLJIT_OP1_BASE + 1) |
| 1235 |
#define SLJIT_MOV32_U8 (SLJIT_MOV_U8 | SLJIT_32) |
| 1236 |
/* Flags: - (does not modify flags) */ |
| 1237 |
#define SLJIT_MOV_S8 (SLJIT_OP1_BASE + 2) |
| 1238 |
#define SLJIT_MOV32_S8 (SLJIT_MOV_S8 | SLJIT_32) |
| 1239 |
/* Flags: - (does not modify flags) */ |
| 1240 |
#define SLJIT_MOV_U16 (SLJIT_OP1_BASE + 3) |
| 1241 |
#define SLJIT_MOV32_U16 (SLJIT_MOV_U16 | SLJIT_32) |
| 1242 |
/* Flags: - (does not modify flags) */ |
| 1243 |
#define SLJIT_MOV_S16 (SLJIT_OP1_BASE + 4) |
| 1244 |
#define SLJIT_MOV32_S16 (SLJIT_MOV_S16 | SLJIT_32) |
| 1245 |
/* Flags: - (does not modify flags) |
| 1246 |
Note: no SLJIT_MOV32_U32 form, since it is the same as SLJIT_MOV32 */ |
| 1247 |
#define SLJIT_MOV_U32 (SLJIT_OP1_BASE + 5) |
| 1248 |
/* Flags: - (does not modify flags) |
| 1249 |
Note: no SLJIT_MOV32_S32 form, since it is the same as SLJIT_MOV32 */ |
| 1250 |
#define SLJIT_MOV_S32 (SLJIT_OP1_BASE + 6) |
| 1251 |
/* Flags: - (does not modify flags) */ |
| 1252 |
#define SLJIT_MOV32 (SLJIT_OP1_BASE + 7) |
| 1253 |
/* Flags: - (does not modify flags) |
| 1254 |
Note: loads a pointer sized data, useful on x32 mode (a 64 bit mode |
| 1255 |
on x86-64 which uses 32 bit pointers) or similar compiling modes */ |
| 1256 |
#define SLJIT_MOV_P (SLJIT_OP1_BASE + 8) |
| 1257 |
/* Count leading zeroes |
| 1258 |
Flags: - (may destroy flags) |
| 1259 |
Note: immediate source argument is not supported */ |
| 1260 |
#define SLJIT_CLZ (SLJIT_OP1_BASE + 9) |
| 1261 |
#define SLJIT_CLZ32 (SLJIT_CLZ | SLJIT_32) |
| 1262 |
/* Count trailing zeroes |
| 1263 |
Flags: - (may destroy flags) |
| 1264 |
Note: immediate source argument is not supported */ |
| 1265 |
#define SLJIT_CTZ (SLJIT_OP1_BASE + 10) |
| 1266 |
#define SLJIT_CTZ32 (SLJIT_CTZ | SLJIT_32) |
| 1267 |
/* Reverse the order of bytes |
| 1268 |
Flags: - (may destroy flags) |
| 1269 |
Note: converts between little and big endian formats |
| 1270 |
Note: immediate source argument is not supported */ |
| 1271 |
#define SLJIT_REV (SLJIT_OP1_BASE + 11) |
| 1272 |
#define SLJIT_REV32 (SLJIT_REV | SLJIT_32) |
| 1273 |
/* Reverse the order of bytes in the lower 16 bit and extend as unsigned |
| 1274 |
Flags: - (may destroy flags) |
| 1275 |
Note: converts between little and big endian formats |
| 1276 |
Note: immediate source argument is not supported */ |
| 1277 |
#define SLJIT_REV_U16 (SLJIT_OP1_BASE + 12) |
| 1278 |
#define SLJIT_REV32_U16 (SLJIT_REV_U16 | SLJIT_32) |
| 1279 |
/* Reverse the order of bytes in the lower 16 bit and extend as signed |
| 1280 |
Flags: - (may destroy flags) |
| 1281 |
Note: converts between little and big endian formats |
| 1282 |
Note: immediate source argument is not supported */ |
| 1283 |
#define SLJIT_REV_S16 (SLJIT_OP1_BASE + 13) |
| 1284 |
#define SLJIT_REV32_S16 (SLJIT_REV_S16 | SLJIT_32) |
| 1285 |
/* Reverse the order of bytes in the lower 32 bit and extend as unsigned |
| 1286 |
Flags: - (may destroy flags) |
| 1287 |
Note: converts between little and big endian formats |
| 1288 |
Note: immediate source argument is not supported */ |
| 1289 |
#define SLJIT_REV_U32 (SLJIT_OP1_BASE + 14) |
| 1290 |
/* Reverse the order of bytes in the lower 32 bit and extend as signed |
| 1291 |
Flags: - (may destroy flags) |
| 1292 |
Note: converts between little and big endian formats |
| 1293 |
Note: immediate source argument is not supported */ |
| 1294 |
#define SLJIT_REV_S32 (SLJIT_OP1_BASE + 15) |
| 1295 |
|
| 1296 |
/* The following unary operations are supported by using sljit_emit_op2: |
| 1297 |
- binary not: SLJIT_XOR with immedate -1 as src1 or src2 |
| 1298 |
- negate: SLJIT_SUB with immedate 0 as src1 |
| 1299 |
Note: these operations are optimized by the compiler if the |
| 1300 |
target CPU has specialized instruction forms for them. */ |
| 1301 |
|
| 1302 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op, |
| 1303 |
sljit_s32 dst, sljit_sw dstw, |
| 1304 |
sljit_s32 src, sljit_sw srcw); |
| 1305 |
|
| 1306 |
/* Starting index of opcodes for sljit_emit_op2. */ |
| 1307 |
#define SLJIT_OP2_BASE 64 |
| 1308 |
|
| 1309 |
/* Flags: Z | OVERFLOW | CARRY */ |
| 1310 |
#define SLJIT_ADD (SLJIT_OP2_BASE + 0) |
| 1311 |
#define SLJIT_ADD32 (SLJIT_ADD | SLJIT_32) |
| 1312 |
/* Flags: CARRY */ |
| 1313 |
#define SLJIT_ADDC (SLJIT_OP2_BASE + 1) |
| 1314 |
#define SLJIT_ADDC32 (SLJIT_ADDC | SLJIT_32) |
| 1315 |
/* Flags: Z | LESS | GREATER_EQUAL | GREATER | LESS_EQUAL |
| 1316 |
SIG_LESS | SIG_GREATER_EQUAL | SIG_GREATER |
| 1317 |
SIG_LESS_EQUAL | OVERFLOW | CARRY */ |
| 1318 |
#define SLJIT_SUB (SLJIT_OP2_BASE + 2) |
| 1319 |
#define SLJIT_SUB32 (SLJIT_SUB | SLJIT_32) |
| 1320 |
/* Flags: CARRY */ |
| 1321 |
#define SLJIT_SUBC (SLJIT_OP2_BASE + 3) |
| 1322 |
#define SLJIT_SUBC32 (SLJIT_SUBC | SLJIT_32) |
| 1323 |
/* Note: integer mul |
| 1324 |
Flags: OVERFLOW */ |
| 1325 |
#define SLJIT_MUL (SLJIT_OP2_BASE + 4) |
| 1326 |
#define SLJIT_MUL32 (SLJIT_MUL | SLJIT_32) |
| 1327 |
/* Flags: Z */ |
| 1328 |
#define SLJIT_AND (SLJIT_OP2_BASE + 5) |
| 1329 |
#define SLJIT_AND32 (SLJIT_AND | SLJIT_32) |
| 1330 |
/* Flags: Z */ |
| 1331 |
#define SLJIT_OR (SLJIT_OP2_BASE + 6) |
| 1332 |
#define SLJIT_OR32 (SLJIT_OR | SLJIT_32) |
| 1333 |
/* Flags: Z */ |
| 1334 |
#define SLJIT_XOR (SLJIT_OP2_BASE + 7) |
| 1335 |
#define SLJIT_XOR32 (SLJIT_XOR | SLJIT_32) |
| 1336 |
/* Flags: Z |
| 1337 |
Let bit_length be the length of the shift operation: 32 or 64. |
| 1338 |
If src2 is immediate, src2w is masked by (bit_length - 1). |
| 1339 |
Otherwise, if the content of src2 is outside the range from 0 |
| 1340 |
to bit_length - 1, the result is undefined. */ |
| 1341 |
#define SLJIT_SHL (SLJIT_OP2_BASE + 8) |
| 1342 |
#define SLJIT_SHL32 (SLJIT_SHL | SLJIT_32) |
| 1343 |
/* Flags: Z |
| 1344 |
Same as SLJIT_SHL, except the the second operand is |
| 1345 |
always masked by the length of the shift operation. */ |
| 1346 |
#define SLJIT_MSHL (SLJIT_OP2_BASE + 9) |
| 1347 |
#define SLJIT_MSHL32 (SLJIT_MSHL | SLJIT_32) |
| 1348 |
/* Flags: Z |
| 1349 |
Let bit_length be the length of the shift operation: 32 or 64. |
| 1350 |
If src2 is immediate, src2w is masked by (bit_length - 1). |
| 1351 |
Otherwise, if the content of src2 is outside the range from 0 |
| 1352 |
to bit_length - 1, the result is undefined. */ |
| 1353 |
#define SLJIT_LSHR (SLJIT_OP2_BASE + 10) |
| 1354 |
#define SLJIT_LSHR32 (SLJIT_LSHR | SLJIT_32) |
| 1355 |
/* Flags: Z |
| 1356 |
Same as SLJIT_LSHR, except the the second operand is |
| 1357 |
always masked by the length of the shift operation. */ |
| 1358 |
#define SLJIT_MLSHR (SLJIT_OP2_BASE + 11) |
| 1359 |
#define SLJIT_MLSHR32 (SLJIT_MLSHR | SLJIT_32) |
| 1360 |
/* Flags: Z |
| 1361 |
Let bit_length be the length of the shift operation: 32 or 64. |
| 1362 |
If src2 is immediate, src2w is masked by (bit_length - 1). |
| 1363 |
Otherwise, if the content of src2 is outside the range from 0 |
| 1364 |
to bit_length - 1, the result is undefined. */ |
| 1365 |
#define SLJIT_ASHR (SLJIT_OP2_BASE + 12) |
| 1366 |
#define SLJIT_ASHR32 (SLJIT_ASHR | SLJIT_32) |
| 1367 |
/* Flags: Z |
| 1368 |
Same as SLJIT_ASHR, except the the second operand is |
| 1369 |
always masked by the length of the shift operation. */ |
| 1370 |
#define SLJIT_MASHR (SLJIT_OP2_BASE + 13) |
| 1371 |
#define SLJIT_MASHR32 (SLJIT_MASHR | SLJIT_32) |
| 1372 |
/* Flags: - (may destroy flags) |
| 1373 |
Let bit_length be the length of the rotate operation: 32 or 64. |
| 1374 |
The second operand is always masked by (bit_length - 1). */ |
| 1375 |
#define SLJIT_ROTL (SLJIT_OP2_BASE + 14) |
| 1376 |
#define SLJIT_ROTL32 (SLJIT_ROTL | SLJIT_32) |
| 1377 |
/* Flags: - (may destroy flags) |
| 1378 |
Let bit_length be the length of the rotate operation: 32 or 64. |
| 1379 |
The second operand is always masked by (bit_length - 1). */ |
| 1380 |
#define SLJIT_ROTR (SLJIT_OP2_BASE + 15) |
| 1381 |
#define SLJIT_ROTR32 (SLJIT_ROTR | SLJIT_32) |
| 1382 |
|
| 1383 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, |
| 1384 |
sljit_s32 dst, sljit_sw dstw, |
| 1385 |
sljit_s32 src1, sljit_sw src1w, |
| 1386 |
sljit_s32 src2, sljit_sw src2w); |
| 1387 |
|
| 1388 |
/* The sljit_emit_op2u function is the same as sljit_emit_op2 |
| 1389 |
except the result is discarded. */ |
| 1390 |
|
| 1391 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op, |
| 1392 |
sljit_s32 src1, sljit_sw src1w, |
| 1393 |
sljit_s32 src2, sljit_sw src2w); |
| 1394 |
|
| 1395 |
/* Starting index of opcodes for sljit_emit_op2r. */ |
| 1396 |
#define SLJIT_OP2R_BASE 96 |
| 1397 |
|
| 1398 |
/* Flags: - (may destroy flags) */ |
| 1399 |
#define SLJIT_MULADD (SLJIT_OP2R_BASE + 0) |
| 1400 |
#define SLJIT_MULADD32 (SLJIT_MULADD | SLJIT_32) |
| 1401 |
|
| 1402 |
/* Similar to sljit_emit_fop2, except the destination is always a register. */ |
| 1403 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2r(struct sljit_compiler *compiler, sljit_s32 op, |
| 1404 |
sljit_s32 dst_reg, |
| 1405 |
sljit_s32 src1, sljit_sw src1w, |
| 1406 |
sljit_s32 src2, sljit_sw src2w); |
| 1407 |
|
| 1408 |
/* Emit a left or right shift operation, where the bits shifted |
| 1409 |
in comes from a separate source operand. All operands are |
| 1410 |
interpreted as unsigned integers. |
| 1411 |
|
| 1412 |
In the followings the value_mask variable is 31 for 32 bit |
| 1413 |
operations and word_size - 1 otherwise. |
| 1414 |
|
| 1415 |
op must be one of the following operations: |
| 1416 |
SLJIT_SHL or SLJIT_SHL32: |
| 1417 |
dst_reg = src1_reg << src3_reg |
| 1418 |
dst_reg |= ((src2_reg >> 1) >> (src3 ^ value_mask)) |
| 1419 |
SLJIT_MSHL or SLJIT_MSHL32: |
| 1420 |
src3 &= value_mask |
| 1421 |
perform the SLJIT_SHL or SLJIT_SHL32 operation |
| 1422 |
SLJIT_LSHR or SLJIT_LSHR32: |
| 1423 |
dst_reg = src1_reg >> src3_reg |
| 1424 |
dst_reg |= ((src2_reg << 1) << (src3 ^ value_mask)) |
| 1425 |
SLJIT_MLSHR or SLJIT_MLSHR32: |
| 1426 |
src3 &= value_mask |
| 1427 |
perform the SLJIT_LSHR or SLJIT_LSHR32 operation |
| 1428 |
|
| 1429 |
op can be combined (or'ed) with SLJIT_SHIFT_INTO_NON_ZERO |
| 1430 |
|
| 1431 |
dst_reg specifies the destination register, where dst_reg |
| 1432 |
and src2_reg cannot be the same registers |
| 1433 |
src1_reg specifies the source register |
| 1434 |
src2_reg specifies the register which is shifted into src1_reg |
| 1435 |
src3 / src3w contains the shift amount |
| 1436 |
|
| 1437 |
Note: a rotate operation is performed if src1_reg and |
| 1438 |
src2_reg are the same registers |
| 1439 |
|
| 1440 |
Flags: - (may destroy flags) */ |
| 1441 |
|
| 1442 |
/* The src3 operand contains a non-zero value. Improves |
| 1443 |
the generated code on certain architectures, which |
| 1444 |
provides a small performance improvement. */ |
| 1445 |
#define SLJIT_SHIFT_INTO_NON_ZERO 0x200 |
| 1446 |
|
| 1447 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler *compiler, sljit_s32 op, |
| 1448 |
sljit_s32 dst_reg, |
| 1449 |
sljit_s32 src1_reg, |
| 1450 |
sljit_s32 src2_reg, |
| 1451 |
sljit_s32 src3, sljit_sw src3w); |
| 1452 |
|
| 1453 |
/* Starting index of opcodes for sljit_emit_op_src |
| 1454 |
and sljit_emit_op_dst. */ |
| 1455 |
#define SLJIT_OP_SRC_DST_BASE 112 |
| 1456 |
|
| 1457 |
/* Fast return, see SLJIT_FAST_CALL for more details. |
| 1458 |
Note: src cannot be an immedate value |
| 1459 |
Flags: - (does not modify flags) */ |
| 1460 |
#define SLJIT_FAST_RETURN (SLJIT_OP_SRC_DST_BASE + 0) |
| 1461 |
/* Skip stack frames before fast return. |
| 1462 |
Note: src cannot be an immedate value |
| 1463 |
Flags: may destroy flags. */ |
| 1464 |
#define SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN (SLJIT_OP_SRC_DST_BASE + 1) |
| 1465 |
/* Prefetch value into the level 1 data cache |
| 1466 |
Note: if the target CPU does not support data prefetch, |
| 1467 |
no instructions are emitted. |
| 1468 |
Note: this instruction never fails, even if the memory address is invalid. |
| 1469 |
Flags: - (does not modify flags) */ |
| 1470 |
#define SLJIT_PREFETCH_L1 (SLJIT_OP_SRC_DST_BASE + 2) |
| 1471 |
/* Prefetch value into the level 2 data cache |
| 1472 |
Note: same as SLJIT_PREFETCH_L1 if the target CPU |
| 1473 |
does not support this instruction form. |
| 1474 |
Note: this instruction never fails, even if the memory address is invalid. |
| 1475 |
Flags: - (does not modify flags) */ |
| 1476 |
#define SLJIT_PREFETCH_L2 (SLJIT_OP_SRC_DST_BASE + 3) |
| 1477 |
/* Prefetch value into the level 3 data cache |
| 1478 |
Note: same as SLJIT_PREFETCH_L2 if the target CPU |
| 1479 |
does not support this instruction form. |
| 1480 |
Note: this instruction never fails, even if the memory address is invalid. |
| 1481 |
Flags: - (does not modify flags) */ |
| 1482 |
#define SLJIT_PREFETCH_L3 (SLJIT_OP_SRC_DST_BASE + 4) |
| 1483 |
/* Prefetch a value which is only used once (and can be discarded afterwards) |
| 1484 |
Note: same as SLJIT_PREFETCH_L1 if the target CPU |
| 1485 |
does not support this instruction form. |
| 1486 |
Note: this instruction never fails, even if the memory address is invalid. |
| 1487 |
Flags: - (does not modify flags) */ |
| 1488 |
#define SLJIT_PREFETCH_ONCE (SLJIT_OP_SRC_DST_BASE + 5) |
| 1489 |
|
| 1490 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op, |
| 1491 |
sljit_s32 src, sljit_sw srcw); |
| 1492 |
|
| 1493 |
/* Fast enter, see SLJIT_FAST_CALL for more details. |
| 1494 |
Flags: - (does not modify flags) */ |
| 1495 |
#define SLJIT_FAST_ENTER (SLJIT_OP_SRC_DST_BASE + 6) |
| 1496 |
|
| 1497 |
/* Copies the return address into dst. The return address is the |
| 1498 |
address where the execution continues after the called function |
| 1499 |
returns (see: sljit_emit_return / sljit_emit_return_void). |
| 1500 |
Flags: - (does not modify flags) */ |
| 1501 |
#define SLJIT_GET_RETURN_ADDRESS (SLJIT_OP_SRC_DST_BASE + 7) |
| 1502 |
|
| 1503 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_dst(struct sljit_compiler *compiler, sljit_s32 op, |
| 1504 |
sljit_s32 dst, sljit_sw dstw); |
| 1505 |
|
| 1506 |
/* Starting index of opcodes for sljit_emit_fop1. */ |
| 1507 |
#define SLJIT_FOP1_BASE 144 |
| 1508 |
|
| 1509 |
/* Flags: - (does not modify flags) */ |
| 1510 |
#define SLJIT_MOV_F64 (SLJIT_FOP1_BASE + 0) |
| 1511 |
#define SLJIT_MOV_F32 (SLJIT_MOV_F64 | SLJIT_32) |
| 1512 |
/* Convert opcodes: CONV[DST_TYPE].FROM[SRC_TYPE] |
| 1513 |
SRC/DST TYPE can be: F64, F32, S32, SW |
| 1514 |
Rounding mode when the destination is SW or S32: round towards zero. */ |
| 1515 |
/* Flags: - (may destroy flags) */ |
| 1516 |
#define SLJIT_CONV_F64_FROM_F32 (SLJIT_FOP1_BASE + 1) |
| 1517 |
#define SLJIT_CONV_F32_FROM_F64 (SLJIT_CONV_F64_FROM_F32 | SLJIT_32) |
| 1518 |
/* Flags: - (may destroy flags) */ |
| 1519 |
#define SLJIT_CONV_SW_FROM_F64 (SLJIT_FOP1_BASE + 2) |
| 1520 |
#define SLJIT_CONV_SW_FROM_F32 (SLJIT_CONV_SW_FROM_F64 | SLJIT_32) |
| 1521 |
/* Flags: - (may destroy flags) */ |
| 1522 |
#define SLJIT_CONV_S32_FROM_F64 (SLJIT_FOP1_BASE + 3) |
| 1523 |
#define SLJIT_CONV_S32_FROM_F32 (SLJIT_CONV_S32_FROM_F64 | SLJIT_32) |
| 1524 |
/* Flags: - (may destroy flags) */ |
| 1525 |
#define SLJIT_CONV_F64_FROM_SW (SLJIT_FOP1_BASE + 4) |
| 1526 |
#define SLJIT_CONV_F32_FROM_SW (SLJIT_CONV_F64_FROM_SW | SLJIT_32) |
| 1527 |
/* Flags: - (may destroy flags) */ |
| 1528 |
#define SLJIT_CONV_F64_FROM_S32 (SLJIT_FOP1_BASE + 5) |
| 1529 |
#define SLJIT_CONV_F32_FROM_S32 (SLJIT_CONV_F64_FROM_S32 | SLJIT_32) |
| 1530 |
/* Flags: - (may destroy flags) */ |
| 1531 |
#define SLJIT_CONV_F64_FROM_UW (SLJIT_FOP1_BASE + 6) |
| 1532 |
#define SLJIT_CONV_F32_FROM_UW (SLJIT_CONV_F64_FROM_UW | SLJIT_32) |
| 1533 |
/* Flags: - (may destroy flags) */ |
| 1534 |
#define SLJIT_CONV_F64_FROM_U32 (SLJIT_FOP1_BASE + 7) |
| 1535 |
#define SLJIT_CONV_F32_FROM_U32 (SLJIT_CONV_F64_FROM_U32 | SLJIT_32) |
| 1536 |
/* Note: dst is the left and src is the right operand for SLJIT_CMP_F32/64. |
| 1537 |
Flags: EQUAL_F | LESS_F | GREATER_EQUAL_F | GREATER_F | LESS_EQUAL_F */ |
| 1538 |
#define SLJIT_CMP_F64 (SLJIT_FOP1_BASE + 8) |
| 1539 |
#define SLJIT_CMP_F32 (SLJIT_CMP_F64 | SLJIT_32) |
| 1540 |
/* Flags: - (may destroy flags) */ |
| 1541 |
#define SLJIT_NEG_F64 (SLJIT_FOP1_BASE + 9) |
| 1542 |
#define SLJIT_NEG_F32 (SLJIT_NEG_F64 | SLJIT_32) |
| 1543 |
/* Flags: - (may destroy flags) */ |
| 1544 |
#define SLJIT_ABS_F64 (SLJIT_FOP1_BASE + 10) |
| 1545 |
#define SLJIT_ABS_F32 (SLJIT_ABS_F64 | SLJIT_32) |
| 1546 |
|
| 1547 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op, |
| 1548 |
sljit_s32 dst, sljit_sw dstw, |
| 1549 |
sljit_s32 src, sljit_sw srcw); |
| 1550 |
|
| 1551 |
/* Starting index of opcodes for sljit_emit_fop2. */ |
| 1552 |
#define SLJIT_FOP2_BASE 176 |
| 1553 |
|
| 1554 |
/* Flags: - (may destroy flags) */ |
| 1555 |
#define SLJIT_ADD_F64 (SLJIT_FOP2_BASE + 0) |
| 1556 |
#define SLJIT_ADD_F32 (SLJIT_ADD_F64 | SLJIT_32) |
| 1557 |
/* Flags: - (may destroy flags) */ |
| 1558 |
#define SLJIT_SUB_F64 (SLJIT_FOP2_BASE + 1) |
| 1559 |
#define SLJIT_SUB_F32 (SLJIT_SUB_F64 | SLJIT_32) |
| 1560 |
/* Flags: - (may destroy flags) */ |
| 1561 |
#define SLJIT_MUL_F64 (SLJIT_FOP2_BASE + 2) |
| 1562 |
#define SLJIT_MUL_F32 (SLJIT_MUL_F64 | SLJIT_32) |
| 1563 |
/* Flags: - (may destroy flags) */ |
| 1564 |
#define SLJIT_DIV_F64 (SLJIT_FOP2_BASE + 3) |
| 1565 |
#define SLJIT_DIV_F32 (SLJIT_DIV_F64 | SLJIT_32) |
| 1566 |
|
| 1567 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op, |
| 1568 |
sljit_s32 dst, sljit_sw dstw, |
| 1569 |
sljit_s32 src1, sljit_sw src1w, |
| 1570 |
sljit_s32 src2, sljit_sw src2w); |
| 1571 |
|
| 1572 |
/* Starting index of opcodes for sljit_emit_fop2r. */ |
| 1573 |
#define SLJIT_FOP2R_BASE 192 |
| 1574 |
|
| 1575 |
/* Flags: - (may destroy flags) */ |
| 1576 |
#define SLJIT_COPYSIGN_F64 (SLJIT_FOP2R_BASE + 0) |
| 1577 |
#define SLJIT_COPYSIGN_F32 (SLJIT_COPYSIGN_F64 | SLJIT_32) |
| 1578 |
|
| 1579 |
/* Similar to sljit_emit_fop2, except the destination is always a register. */ |
| 1580 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2r(struct sljit_compiler *compiler, sljit_s32 op, |
| 1581 |
sljit_s32 dst_freg, |
| 1582 |
sljit_s32 src1, sljit_sw src1w, |
| 1583 |
sljit_s32 src2, sljit_sw src2w); |
| 1584 |
|
| 1585 |
/* Sets a floating point register to an immediate value. */ |
| 1586 |
|
| 1587 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset32(struct sljit_compiler *compiler, |
| 1588 |
sljit_s32 freg, sljit_f32 value); |
| 1589 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fset64(struct sljit_compiler *compiler, |
| 1590 |
sljit_s32 freg, sljit_f64 value); |
| 1591 |
|
| 1592 |
/* The following opcodes are used by sljit_emit_fcopy(). */ |
| 1593 |
|
| 1594 |
/* 64 bit: copy a 64 bit value from an integer register into a |
| 1595 |
64 bit floating point register without any modifications. |
| 1596 |
32 bit: copy a 32 bit register or register pair into a 64 bit |
| 1597 |
floating point register without any modifications. The |
| 1598 |
register, or the first register of the register pair |
| 1599 |
replaces the high order 32 bit of the floating point |
| 1600 |
register. If a register pair is passed, the low |
| 1601 |
order 32 bit is replaced by the second register. |
| 1602 |
Otherwise, the low order 32 bit is unchanged. */ |
| 1603 |
#define SLJIT_COPY_TO_F64 1 |
| 1604 |
/* Copy a 32 bit value from an integer register into a 32 bit |
| 1605 |
floating point register without any modifications. */ |
| 1606 |
#define SLJIT_COPY32_TO_F32 (SLJIT_COPY_TO_F64 | SLJIT_32) |
| 1607 |
/* 64 bit: copy the value of a 64 bit floating point register into |
| 1608 |
an integer register without any modifications. |
| 1609 |
32 bit: copy a 64 bit floating point register into a 32 bit register |
| 1610 |
or a 32 bit register pair without any modifications. The |
| 1611 |
high order 32 bit of the floating point register is copied |
| 1612 |
into the register, or the first register of the register |
| 1613 |
pair. If a register pair is passed, the low order 32 bit |
| 1614 |
is copied into the second register. */ |
| 1615 |
#define SLJIT_COPY_FROM_F64 2 |
| 1616 |
/* Copy the value of a 32 bit floating point register into an integer |
| 1617 |
register without any modifications. The register should be processed |
| 1618 |
with 32 bit operations later. */ |
| 1619 |
#define SLJIT_COPY32_FROM_F32 (SLJIT_COPY_FROM_F64 | SLJIT_32) |
| 1620 |
|
| 1621 |
/* Special data copy which involves floating point registers. |
| 1622 |
|
| 1623 |
op must be between SLJIT_COPY_TO_F64 and SLJIT_COPY32_FROM_F32 |
| 1624 |
freg must be a floating point register |
| 1625 |
reg must be a register or register pair */ |
| 1626 |
|
| 1627 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fcopy(struct sljit_compiler *compiler, sljit_s32 op, |
| 1628 |
sljit_s32 freg, sljit_s32 reg); |
| 1629 |
|
| 1630 |
/* Label and jump instructions. */ |
| 1631 |
|
| 1632 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler); |
| 1633 |
|
| 1634 |
/* The SLJIT_FAST_CALL is a calling method for creating lightweight function |
| 1635 |
calls. This type of calls preserve the values of all registers and stack |
| 1636 |
frame. Unlike normal function calls, the enter and return operations must |
| 1637 |
be performed by the SLJIT_FAST_ENTER and SLJIT_FAST_RETURN operations |
| 1638 |
respectively. The return address is stored in the dst argument of the |
| 1639 |
SLJIT_FAST_ENTER operation, and this return address should be passed as |
| 1640 |
the src argument for the SLJIT_FAST_RETURN operation to return from the |
| 1641 |
called function. |
| 1642 |
|
| 1643 |
Fast calls are cheap operations (usually only a single call instruction is |
| 1644 |
emitted) but they do not preserve any registers. However the callee function |
| 1645 |
can freely use / update any registers and the locals area which can be |
| 1646 |
efficiently exploited by various optimizations. Registers can be saved |
| 1647 |
and restored manually if needed. |
| 1648 |
|
| 1649 |
Although returning to different address by SLJIT_FAST_RETURN is possible, |
| 1650 |
this address usually cannot be predicted by the return address predictor of |
| 1651 |
modern CPUs which may reduce performance. Furthermore certain security |
| 1652 |
enhancement technologies such as Intel Control-flow Enforcement Technology |
| 1653 |
(CET) may disallow returning to a different address (indirect jumps |
| 1654 |
can be used instead, see SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN). */ |
| 1655 |
|
| 1656 |
/* Invert (negate) conditional type: xor (^) with 0x1 */ |
| 1657 |
|
| 1658 |
/* Integer comparison types. */ |
| 1659 |
#define SLJIT_EQUAL 0 |
| 1660 |
#define SLJIT_ZERO SLJIT_EQUAL |
| 1661 |
#define SLJIT_NOT_EQUAL 1 |
| 1662 |
#define SLJIT_NOT_ZERO SLJIT_NOT_EQUAL |
| 1663 |
|
| 1664 |
#define SLJIT_LESS 2 |
| 1665 |
#define SLJIT_SET_LESS SLJIT_SET(SLJIT_LESS) |
| 1666 |
#define SLJIT_GREATER_EQUAL 3 |
| 1667 |
#define SLJIT_SET_GREATER_EQUAL SLJIT_SET(SLJIT_LESS) |
| 1668 |
#define SLJIT_GREATER 4 |
| 1669 |
#define SLJIT_SET_GREATER SLJIT_SET(SLJIT_GREATER) |
| 1670 |
#define SLJIT_LESS_EQUAL 5 |
| 1671 |
#define SLJIT_SET_LESS_EQUAL SLJIT_SET(SLJIT_GREATER) |
| 1672 |
#define SLJIT_SIG_LESS 6 |
| 1673 |
#define SLJIT_SET_SIG_LESS SLJIT_SET(SLJIT_SIG_LESS) |
| 1674 |
#define SLJIT_SIG_GREATER_EQUAL 7 |
| 1675 |
#define SLJIT_SET_SIG_GREATER_EQUAL SLJIT_SET(SLJIT_SIG_LESS) |
| 1676 |
#define SLJIT_SIG_GREATER 8 |
| 1677 |
#define SLJIT_SET_SIG_GREATER SLJIT_SET(SLJIT_SIG_GREATER) |
| 1678 |
#define SLJIT_SIG_LESS_EQUAL 9 |
| 1679 |
#define SLJIT_SET_SIG_LESS_EQUAL SLJIT_SET(SLJIT_SIG_GREATER) |
| 1680 |
|
| 1681 |
#define SLJIT_OVERFLOW 10 |
| 1682 |
#define SLJIT_SET_OVERFLOW SLJIT_SET(SLJIT_OVERFLOW) |
| 1683 |
#define SLJIT_NOT_OVERFLOW 11 |
| 1684 |
|
| 1685 |
/* Unlike other flags, sljit_emit_jump may destroy the carry flag. */ |
| 1686 |
#define SLJIT_CARRY 12 |
| 1687 |
#define SLJIT_SET_CARRY SLJIT_SET(SLJIT_CARRY) |
| 1688 |
#define SLJIT_NOT_CARRY 13 |
| 1689 |
|
| 1690 |
#define SLJIT_ATOMIC_STORED 14 |
| 1691 |
#define SLJIT_SET_ATOMIC_STORED SLJIT_SET(SLJIT_ATOMIC_STORED) |
| 1692 |
#define SLJIT_ATOMIC_NOT_STORED 15 |
| 1693 |
|
| 1694 |
/* Basic floating point comparison types. |
| 1695 |
|
| 1696 |
Note: when the comparison result is unordered, their behaviour is unspecified. */ |
| 1697 |
|
| 1698 |
#define SLJIT_F_EQUAL 16 |
| 1699 |
#define SLJIT_SET_F_EQUAL SLJIT_SET(SLJIT_F_EQUAL) |
| 1700 |
#define SLJIT_F_NOT_EQUAL 17 |
| 1701 |
#define SLJIT_SET_F_NOT_EQUAL SLJIT_SET(SLJIT_F_EQUAL) |
| 1702 |
#define SLJIT_F_LESS 18 |
| 1703 |
#define SLJIT_SET_F_LESS SLJIT_SET(SLJIT_F_LESS) |
| 1704 |
#define SLJIT_F_GREATER_EQUAL 19 |
| 1705 |
#define SLJIT_SET_F_GREATER_EQUAL SLJIT_SET(SLJIT_F_LESS) |
| 1706 |
#define SLJIT_F_GREATER 20 |
| 1707 |
#define SLJIT_SET_F_GREATER SLJIT_SET(SLJIT_F_GREATER) |
| 1708 |
#define SLJIT_F_LESS_EQUAL 21 |
| 1709 |
#define SLJIT_SET_F_LESS_EQUAL SLJIT_SET(SLJIT_F_GREATER) |
| 1710 |
|
| 1711 |
/* Jumps when either argument contains a NaN value. */ |
| 1712 |
#define SLJIT_UNORDERED 22 |
| 1713 |
#define SLJIT_SET_UNORDERED SLJIT_SET(SLJIT_UNORDERED) |
| 1714 |
/* Jumps when neither argument contains a NaN value. */ |
| 1715 |
#define SLJIT_ORDERED 23 |
| 1716 |
#define SLJIT_SET_ORDERED SLJIT_SET(SLJIT_UNORDERED) |
| 1717 |
|
| 1718 |
/* Ordered / unordered floating point comparison types. |
| 1719 |
|
| 1720 |
Note: each comparison type has an ordered and unordered form. Some |
| 1721 |
architectures supports only either of them (see: sljit_cmp_info). */ |
| 1722 |
|
| 1723 |
#define SLJIT_ORDERED_EQUAL 24 |
| 1724 |
#define SLJIT_SET_ORDERED_EQUAL SLJIT_SET(SLJIT_ORDERED_EQUAL) |
| 1725 |
#define SLJIT_UNORDERED_OR_NOT_EQUAL 25 |
| 1726 |
#define SLJIT_SET_UNORDERED_OR_NOT_EQUAL SLJIT_SET(SLJIT_ORDERED_EQUAL) |
| 1727 |
#define SLJIT_ORDERED_LESS 26 |
| 1728 |
#define SLJIT_SET_ORDERED_LESS SLJIT_SET(SLJIT_ORDERED_LESS) |
| 1729 |
#define SLJIT_UNORDERED_OR_GREATER_EQUAL 27 |
| 1730 |
#define SLJIT_SET_UNORDERED_OR_GREATER_EQUAL SLJIT_SET(SLJIT_ORDERED_LESS) |
| 1731 |
#define SLJIT_ORDERED_GREATER 28 |
| 1732 |
#define SLJIT_SET_ORDERED_GREATER SLJIT_SET(SLJIT_ORDERED_GREATER) |
| 1733 |
#define SLJIT_UNORDERED_OR_LESS_EQUAL 29 |
| 1734 |
#define SLJIT_SET_UNORDERED_OR_LESS_EQUAL SLJIT_SET(SLJIT_ORDERED_GREATER) |
| 1735 |
|
| 1736 |
#define SLJIT_UNORDERED_OR_EQUAL 30 |
| 1737 |
#define SLJIT_SET_UNORDERED_OR_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_EQUAL) |
| 1738 |
#define SLJIT_ORDERED_NOT_EQUAL 31 |
| 1739 |
#define SLJIT_SET_ORDERED_NOT_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_EQUAL) |
| 1740 |
#define SLJIT_UNORDERED_OR_LESS 32 |
| 1741 |
#define SLJIT_SET_UNORDERED_OR_LESS SLJIT_SET(SLJIT_UNORDERED_OR_LESS) |
| 1742 |
#define SLJIT_ORDERED_GREATER_EQUAL 33 |
| 1743 |
#define SLJIT_SET_ORDERED_GREATER_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_LESS) |
| 1744 |
#define SLJIT_UNORDERED_OR_GREATER 34 |
| 1745 |
#define SLJIT_SET_UNORDERED_OR_GREATER SLJIT_SET(SLJIT_UNORDERED_OR_GREATER) |
| 1746 |
#define SLJIT_ORDERED_LESS_EQUAL 35 |
| 1747 |
#define SLJIT_SET_ORDERED_LESS_EQUAL SLJIT_SET(SLJIT_UNORDERED_OR_GREATER) |
| 1748 |
|
| 1749 |
/* Unconditional jump types. */ |
| 1750 |
#define SLJIT_JUMP 36 |
| 1751 |
/* Fast calling method. See the description above. */ |
| 1752 |
#define SLJIT_FAST_CALL 37 |
| 1753 |
/* Default C calling convention. */ |
| 1754 |
#define SLJIT_CALL 38 |
| 1755 |
/* Called function must be compiled by SLJIT. |
| 1756 |
See SLJIT_ENTER_REG_ARG option. */ |
| 1757 |
#define SLJIT_CALL_REG_ARG 39 |
| 1758 |
|
| 1759 |
/* The target can be changed during runtime (see: sljit_set_jump_addr). */ |
| 1760 |
#define SLJIT_REWRITABLE_JUMP 0x1000 |
| 1761 |
/* When this flag is passed, the execution of the current function ends and |
| 1762 |
the called function returns to the caller of the current function. The |
| 1763 |
stack usage is reduced before the call, but it is not necessarily reduced |
| 1764 |
to zero. In the latter case the compiler needs to allocate space for some |
| 1765 |
arguments and the return address must be stored on the stack as well. */ |
| 1766 |
#define SLJIT_CALL_RETURN 0x2000 |
| 1767 |
|
| 1768 |
/* Emit a jump instruction. The destination is not set, only the type of the jump. |
| 1769 |
type must be between SLJIT_EQUAL and SLJIT_FAST_CALL |
| 1770 |
type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP |
| 1771 |
|
| 1772 |
Flags: does not modify flags. */ |
| 1773 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type); |
| 1774 |
|
| 1775 |
/* Emit a C compiler (ABI) compatible function call. |
| 1776 |
type must be SLJIT_CALL or SLJIT_CALL_REG_ARG |
| 1777 |
type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP and/or SLJIT_CALL_RETURN |
| 1778 |
arg_types can be specified by SLJIT_ARGSx (SLJIT_ARG_RETURN / SLJIT_ARG_VALUE) macros |
| 1779 |
|
| 1780 |
Flags: destroy all flags. */ |
| 1781 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 arg_types); |
| 1782 |
|
| 1783 |
/* Basic arithmetic comparison. In most architectures it is implemented as |
| 1784 |
a compare operation followed by a sljit_emit_jump. However some |
| 1785 |
architectures (i.e: ARM64 or MIPS) may employ special optimizations |
| 1786 |
here. It is suggested to use this comparison form when appropriate. |
| 1787 |
type must be between SLJIT_EQUAL and SLJIT_SIG_LESS_EQUAL |
| 1788 |
type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP |
| 1789 |
|
| 1790 |
Flags: may destroy flags. */ |
| 1791 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type, |
| 1792 |
sljit_s32 src1, sljit_sw src1w, |
| 1793 |
sljit_s32 src2, sljit_sw src2w); |
| 1794 |
|
| 1795 |
/* Basic floating point comparison. In most architectures it is implemented as |
| 1796 |
a SLJIT_CMP_F32/64 operation (setting appropriate flags) followed by a |
| 1797 |
sljit_emit_jump. However some architectures (i.e: MIPS) may employ |
| 1798 |
special optimizations here. It is suggested to use this comparison form |
| 1799 |
when appropriate. |
| 1800 |
type must be between SLJIT_F_EQUAL and SLJIT_ORDERED_LESS_EQUAL |
| 1801 |
type can be combined (or'ed) with SLJIT_REWRITABLE_JUMP |
| 1802 |
Flags: destroy flags. |
| 1803 |
Note: when an operand is NaN the behaviour depends on the comparison type. */ |
| 1804 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type, |
| 1805 |
sljit_s32 src1, sljit_sw src1w, |
| 1806 |
sljit_s32 src2, sljit_sw src2w); |
| 1807 |
|
| 1808 |
/* Set the destination of the jump to this label. */ |
| 1809 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label); |
| 1810 |
/* Set the destination address of the jump to this label. */ |
| 1811 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target); |
| 1812 |
|
| 1813 |
/* Emit an indirect jump or fast call. |
| 1814 |
Direct form: set src to SLJIT_IMM() and srcw to the address |
| 1815 |
Indirect form: any other valid addressing mode |
| 1816 |
type must be between SLJIT_JUMP and SLJIT_FAST_CALL |
| 1817 |
|
| 1818 |
Flags: does not modify flags. */ |
| 1819 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw); |
| 1820 |
|
| 1821 |
/* Emit a C compiler (ABI) compatible function call. |
| 1822 |
Direct form: set src to SLJIT_IMM() and srcw to the address |
| 1823 |
Indirect form: any other valid addressing mode |
| 1824 |
type must be SLJIT_CALL or SLJIT_CALL_REG_ARG |
| 1825 |
type can be combined (or'ed) with SLJIT_CALL_RETURN |
| 1826 |
arg_types can be specified by SLJIT_ARGSx (SLJIT_ARG_RETURN / SLJIT_ARG_VALUE) macros |
| 1827 |
|
| 1828 |
Flags: destroy all flags. */ |
| 1829 |
SLJIT_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); |
| 1830 |
|
| 1831 |
/* Perform an operation using the conditional flags as the second argument. |
| 1832 |
Type must always be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL. |
| 1833 |
The value represented by the type is 1, if the condition represented |
| 1834 |
by the type is fulfilled, and 0 otherwise. |
| 1835 |
|
| 1836 |
When op is SLJIT_MOV or SLJIT_MOV32: |
| 1837 |
Set dst to the value represented by the type (0 or 1). |
| 1838 |
Flags: - (does not modify flags) |
| 1839 |
When op is SLJIT_AND, SLJIT_AND32, SLJIT_OR, SLJIT_OR32, SLJIT_XOR, or SLJIT_XOR32 |
| 1840 |
Performs the binary operation using dst as the first, and the value |
| 1841 |
represented by type as the second argument. Result is written into dst. |
| 1842 |
Flags: Z (may destroy flags) */ |
| 1843 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op, |
| 1844 |
sljit_s32 dst, sljit_sw dstw, |
| 1845 |
sljit_s32 type); |
| 1846 |
|
| 1847 |
/* Emit a conditional select instruction which moves src1 to dst_reg, |
| 1848 |
if the condition is satisfied, or src2_reg to dst_reg otherwise. |
| 1849 |
|
| 1850 |
type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL |
| 1851 |
type can be combined (or'ed) with SLJIT_32 to move 32 bit |
| 1852 |
register values instead of word sized ones |
| 1853 |
dst_reg and src2_reg must be valid registers |
| 1854 |
src1 must be valid operand |
| 1855 |
|
| 1856 |
Note: if src1 is a memory operand, its value |
| 1857 |
might be loaded even if the condition is false. |
| 1858 |
|
| 1859 |
Flags: - (does not modify flags) */ |
| 1860 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_select(struct sljit_compiler *compiler, sljit_s32 type, |
| 1861 |
sljit_s32 dst_reg, |
| 1862 |
sljit_s32 src1, sljit_sw src1w, |
| 1863 |
sljit_s32 src2_reg); |
| 1864 |
|
| 1865 |
/* Emit a conditional floating point select instruction which moves |
| 1866 |
src1 to dst_reg, if the condition is satisfied, or src2_reg to |
| 1867 |
dst_reg otherwise. |
| 1868 |
|
| 1869 |
type must be between SLJIT_EQUAL and SLJIT_ORDERED_LESS_EQUAL |
| 1870 |
type can be combined (or'ed) with SLJIT_32 to move 32 bit |
| 1871 |
floating point values instead of 64 bit ones |
| 1872 |
dst_freg and src2_freg must be valid floating point registers |
| 1873 |
src1 must be valid operand |
| 1874 |
|
| 1875 |
Note: if src1 is a memory operand, its value |
| 1876 |
might be loaded even if the condition is false. |
| 1877 |
|
| 1878 |
Flags: - (does not modify flags) */ |
| 1879 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fselect(struct sljit_compiler *compiler, sljit_s32 type, |
| 1880 |
sljit_s32 dst_freg, |
| 1881 |
sljit_s32 src1, sljit_sw src1w, |
| 1882 |
sljit_s32 src2_freg); |
| 1883 |
|
| 1884 |
/* The following flags are used by sljit_emit_mem(), sljit_emit_mem_update(), |
| 1885 |
sljit_emit_fmem(), and sljit_emit_fmem_update(). */ |
| 1886 |
|
| 1887 |
/* Memory load operation. This is the default. */ |
| 1888 |
#define SLJIT_MEM_LOAD 0x000000 |
| 1889 |
/* Memory store operation. */ |
| 1890 |
#define SLJIT_MEM_STORE 0x000200 |
| 1891 |
|
| 1892 |
/* The following flags are used by sljit_emit_mem() and sljit_emit_fmem(). */ |
| 1893 |
|
| 1894 |
/* Load or stora data from an unaligned (byte aligned) address. */ |
| 1895 |
#define SLJIT_MEM_UNALIGNED 0x000400 |
| 1896 |
/* Load or stora data from a 16 bit aligned address. */ |
| 1897 |
#define SLJIT_MEM_ALIGNED_16 0x000800 |
| 1898 |
/* Load or stora data from a 32 bit aligned address. */ |
| 1899 |
#define SLJIT_MEM_ALIGNED_32 0x001000 |
| 1900 |
|
| 1901 |
/* The following flags are used by sljit_emit_mem_update(), |
| 1902 |
and sljit_emit_fmem_update(). */ |
| 1903 |
|
| 1904 |
/* Base register is updated before the memory access (default). */ |
| 1905 |
#define SLJIT_MEM_PRE 0x000000 |
| 1906 |
/* Base register is updated after the memory access. */ |
| 1907 |
#define SLJIT_MEM_POST 0x000400 |
| 1908 |
|
| 1909 |
/* When SLJIT_MEM_SUPP is passed, no instructions are emitted. |
| 1910 |
Instead the function returns with SLJIT_SUCCESS if the instruction |
| 1911 |
form is supported and SLJIT_ERR_UNSUPPORTED otherwise. This flag |
| 1912 |
allows runtime checking of available instruction forms. */ |
| 1913 |
#define SLJIT_MEM_SUPP 0x000800 |
| 1914 |
|
| 1915 |
/* The sljit_emit_mem emits instructions for various memory operations: |
| 1916 |
|
| 1917 |
When SLJIT_MEM_UNALIGNED / SLJIT_MEM_ALIGNED_16 / |
| 1918 |
SLJIT_MEM_ALIGNED_32 is set in type argument: |
| 1919 |
Emit instructions for unaligned memory loads or stores. When |
| 1920 |
SLJIT_UNALIGNED is not defined, the only way to access unaligned |
| 1921 |
memory data is using sljit_emit_mem. Otherwise all operations (e.g. |
| 1922 |
sljit_emit_op1/2, or sljit_emit_fop1/2) supports unaligned access. |
| 1923 |
In general, the performance of unaligned memory accesses are often |
| 1924 |
lower than aligned and should be avoided. |
| 1925 |
|
| 1926 |
When a pair of registers is passed in reg argument: |
| 1927 |
Emit instructions for moving data between a register pair and |
| 1928 |
memory. The register pair can be specified by the SLJIT_REG_PAIR |
| 1929 |
macro. The first register is loaded from or stored into the |
| 1930 |
location specified by the mem/memw arguments, and the end address |
| 1931 |
of this operation is the starting address of the data transfer |
| 1932 |
between the second register and memory. The type argument must |
| 1933 |
be SLJIT_MOV. The SLJIT_MEM_UNALIGNED / SLJIT_MEM_ALIGNED_* |
| 1934 |
options are allowed for this operation. |
| 1935 |
|
| 1936 |
type must be between SLJIT_MOV and SLJIT_MOV_P and can be |
| 1937 |
combined (or'ed) with SLJIT_MEM_* flags |
| 1938 |
reg is a register or register pair, which is the source or |
| 1939 |
destination of the operation |
| 1940 |
mem must be a memory operand |
| 1941 |
|
| 1942 |
Flags: - (does not modify flags) */ |
| 1943 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, |
| 1944 |
sljit_s32 reg, |
| 1945 |
sljit_s32 mem, sljit_sw memw); |
| 1946 |
|
| 1947 |
/* Emit a single memory load or store with update instruction. |
| 1948 |
When the requested instruction form is not supported by the CPU, |
| 1949 |
it returns with SLJIT_ERR_UNSUPPORTED instead of emulating the |
| 1950 |
instruction. This allows specializing tight loops based on |
| 1951 |
the supported instruction forms (see SLJIT_MEM_SUPP flag). |
| 1952 |
Absolute address (SLJIT_MEM0) forms are never supported |
| 1953 |
and the base (first) register specified by the mem argument |
| 1954 |
must not be SLJIT_SP and must also be different from the |
| 1955 |
register specified by the reg argument. |
| 1956 |
|
| 1957 |
type must be between SLJIT_MOV and SLJIT_MOV_P and can be |
| 1958 |
combined (or'ed) with SLJIT_MEM_* flags |
| 1959 |
reg is the source or destination register of the operation |
| 1960 |
mem must be a memory operand |
| 1961 |
|
| 1962 |
Flags: - (does not modify flags) */ |
| 1963 |
|
| 1964 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type, |
| 1965 |
sljit_s32 reg, |
| 1966 |
sljit_s32 mem, sljit_sw memw); |
| 1967 |
|
| 1968 |
/* Same as sljit_emit_mem except the followings: |
| 1969 |
|
| 1970 |
Loading or storing a pair of registers is not supported. |
| 1971 |
|
| 1972 |
type must be SLJIT_MOV_F64 or SLJIT_MOV_F32 and can be |
| 1973 |
combined (or'ed) with SLJIT_MEM_* flags. |
| 1974 |
freg is the source or destination floating point register |
| 1975 |
of the operation |
| 1976 |
mem must be a memory operand |
| 1977 |
|
| 1978 |
Flags: - (does not modify flags) */ |
| 1979 |
|
| 1980 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, |
| 1981 |
sljit_s32 freg, |
| 1982 |
sljit_s32 mem, sljit_sw memw); |
| 1983 |
|
| 1984 |
/* Same as sljit_emit_mem_update except the followings: |
| 1985 |
|
| 1986 |
type must be SLJIT_MOV_F64 or SLJIT_MOV_F32 and can be |
| 1987 |
combined (or'ed) with SLJIT_MEM_* flags |
| 1988 |
freg is the source or destination floating point register |
| 1989 |
of the operation |
| 1990 |
mem must be a memory operand |
| 1991 |
|
| 1992 |
Flags: - (does not modify flags) */ |
| 1993 |
|
| 1994 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type, |
| 1995 |
sljit_s32 freg, |
| 1996 |
sljit_s32 mem, sljit_sw memw); |
| 1997 |
|
| 1998 |
/* The following options are used by several simd operations. */ |
| 1999 |
|
| 2000 |
/* Load data into a vector register, this is the default */ |
| 2001 |
#define SLJIT_SIMD_LOAD 0x000000 |
| 2002 |
/* Store data from a vector register */ |
| 2003 |
#define SLJIT_SIMD_STORE 0x000001 |
| 2004 |
/* The vector register contains floating point values */ |
| 2005 |
#define SLJIT_SIMD_FLOAT 0x000400 |
| 2006 |
/* Tests whether the operation is available */ |
| 2007 |
#define SLJIT_SIMD_TEST 0x000800 |
| 2008 |
/* Move data to/from a 64 bit (8 byte) long vector register */ |
| 2009 |
#define SLJIT_SIMD_REG_64 (3 << 12) |
| 2010 |
/* Move data to/from a 128 bit (16 byte) long vector register */ |
| 2011 |
#define SLJIT_SIMD_REG_128 (4 << 12) |
| 2012 |
/* Move data to/from a 256 bit (32 byte) long vector register */ |
| 2013 |
#define SLJIT_SIMD_REG_256 (5 << 12) |
| 2014 |
/* Move data to/from a 512 bit (64 byte) long vector register */ |
| 2015 |
#define SLJIT_SIMD_REG_512 (6 << 12) |
| 2016 |
/* Element size is 8 bit long (this is the default), usually cannot be combined with SLJIT_SIMD_FLOAT */ |
| 2017 |
#define SLJIT_SIMD_ELEM_8 (0 << 18) |
| 2018 |
/* Element size is 16 bit long, usually cannot be combined with SLJIT_SIMD_FLOAT */ |
| 2019 |
#define SLJIT_SIMD_ELEM_16 (1 << 18) |
| 2020 |
/* Element size is 32 bit long */ |
| 2021 |
#define SLJIT_SIMD_ELEM_32 (2 << 18) |
| 2022 |
/* Element size is 64 bit long */ |
| 2023 |
#define SLJIT_SIMD_ELEM_64 (3 << 18) |
| 2024 |
/* Element size is 128 bit long */ |
| 2025 |
#define SLJIT_SIMD_ELEM_128 (4 << 18) |
| 2026 |
/* Element size is 256 bit long */ |
| 2027 |
#define SLJIT_SIMD_ELEM_256 (5 << 18) |
| 2028 |
|
| 2029 |
/* The following options are used by sljit_emit_simd_mov() |
| 2030 |
and sljit_emit_simd_op2(). */ |
| 2031 |
|
| 2032 |
/* Memory address is unaligned (this is the default) */ |
| 2033 |
#define SLJIT_SIMD_MEM_UNALIGNED (0 << 24) |
| 2034 |
/* Memory address is 16 bit aligned */ |
| 2035 |
#define SLJIT_SIMD_MEM_ALIGNED_16 (1 << 24) |
| 2036 |
/* Memory address is 32 bit aligned */ |
| 2037 |
#define SLJIT_SIMD_MEM_ALIGNED_32 (2 << 24) |
| 2038 |
/* Memory address is 64 bit aligned */ |
| 2039 |
#define SLJIT_SIMD_MEM_ALIGNED_64 (3 << 24) |
| 2040 |
/* Memory address is 128 bit aligned */ |
| 2041 |
#define SLJIT_SIMD_MEM_ALIGNED_128 (4 << 24) |
| 2042 |
/* Memory address is 256 bit aligned */ |
| 2043 |
#define SLJIT_SIMD_MEM_ALIGNED_256 (5 << 24) |
| 2044 |
/* Memory address is 512 bit aligned */ |
| 2045 |
#define SLJIT_SIMD_MEM_ALIGNED_512 (6 << 24) |
| 2046 |
|
| 2047 |
/* Moves data between a vector register and memory. |
| 2048 |
|
| 2049 |
If the operation is not supported, it returns with |
| 2050 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2051 |
it does not emit any instructions. |
| 2052 |
|
| 2053 |
type must be a combination of SLJIT_SIMD_* and |
| 2054 |
SLJIT_SIMD_MEM_* options |
| 2055 |
vreg is the source or destination vector register |
| 2056 |
of the operation |
| 2057 |
srcdst must be a memory operand or a vector register |
| 2058 |
|
| 2059 |
Note: |
| 2060 |
The alignment and element size must be |
| 2061 |
less or equal than vector register size. |
| 2062 |
|
| 2063 |
Flags: - (does not modify flags) */ |
| 2064 |
|
| 2065 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_mov(struct sljit_compiler *compiler, sljit_s32 type, |
| 2066 |
sljit_s32 vreg, |
| 2067 |
sljit_s32 srcdst, sljit_sw srcdstw); |
| 2068 |
|
| 2069 |
/* Replicates a scalar value to all lanes of a vector |
| 2070 |
register. |
| 2071 |
|
| 2072 |
If the operation is not supported, it returns with |
| 2073 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2074 |
it does not emit any instructions. |
| 2075 |
|
| 2076 |
type must be a combination of SLJIT_SIMD_* options |
| 2077 |
except SLJIT_SIMD_STORE. |
| 2078 |
vreg is the destination vector register of the operation |
| 2079 |
src is the value which is replicated |
| 2080 |
|
| 2081 |
Note: |
| 2082 |
The src == SLJIT_IMM and srcw == 0 can be used to |
| 2083 |
clear a register even when SLJIT_SIMD_FLOAT is set. |
| 2084 |
|
| 2085 |
Flags: - (does not modify flags) */ |
| 2086 |
|
| 2087 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_replicate(struct sljit_compiler *compiler, sljit_s32 type, |
| 2088 |
sljit_s32 vreg, |
| 2089 |
sljit_s32 src, sljit_sw srcw); |
| 2090 |
|
| 2091 |
/* The following options are used by sljit_emit_simd_lane_mov(). */ |
| 2092 |
|
| 2093 |
/* Clear all bits of the simd register before loading the lane. */ |
| 2094 |
#define SLJIT_SIMD_LANE_ZERO 0x000002 |
| 2095 |
/* Sign extend the integer value stored from the lane. */ |
| 2096 |
#define SLJIT_SIMD_LANE_SIGNED 0x000004 |
| 2097 |
|
| 2098 |
/* Moves data between a vector register lane and a register or |
| 2099 |
memory. If the srcdst argument is a register, it must be |
| 2100 |
a floating point register when SLJIT_SIMD_FLOAT is specified, |
| 2101 |
or a general purpose register otherwise. |
| 2102 |
|
| 2103 |
If the operation is not supported, it returns with |
| 2104 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2105 |
it does not emit any instructions. |
| 2106 |
|
| 2107 |
type must be a combination of SLJIT_SIMD_* options |
| 2108 |
Further options: |
| 2109 |
SLJIT_32 - when SLJIT_SIMD_FLOAT is not set |
| 2110 |
SLJIT_SIMD_LANE_SIGNED - when SLJIT_SIMD_STORE |
| 2111 |
is set and SLJIT_SIMD_FLOAT is not set |
| 2112 |
SLJIT_SIMD_LANE_ZERO - when SLJIT_SIMD_LOAD |
| 2113 |
is specified |
| 2114 |
vreg is the source or destination vector register |
| 2115 |
of the operation |
| 2116 |
lane_index is the index of the lane |
| 2117 |
srcdst is the destination operand for loads, and |
| 2118 |
source operand for stores |
| 2119 |
|
| 2120 |
Note: |
| 2121 |
The elem size must be lower than register size. |
| 2122 |
|
| 2123 |
Flags: - (does not modify flags) */ |
| 2124 |
|
| 2125 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_mov(struct sljit_compiler *compiler, sljit_s32 type, |
| 2126 |
sljit_s32 vreg, sljit_s32 lane_index, |
| 2127 |
sljit_s32 srcdst, sljit_sw srcdstw); |
| 2128 |
|
| 2129 |
/* Replicates a scalar value from a lane to all lanes |
| 2130 |
of a vector register. |
| 2131 |
|
| 2132 |
If the operation is not supported, it returns with |
| 2133 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2134 |
it does not emit any instructions. |
| 2135 |
|
| 2136 |
type must be a combination of SLJIT_SIMD_* options |
| 2137 |
except SLJIT_SIMD_STORE. |
| 2138 |
vreg is the destination vector register of the operation |
| 2139 |
src is the vector register which lane is replicated |
| 2140 |
src_lane_index is the lane index of the src register |
| 2141 |
|
| 2142 |
Flags: - (does not modify flags) */ |
| 2143 |
|
| 2144 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_lane_replicate(struct sljit_compiler *compiler, sljit_s32 type, |
| 2145 |
sljit_s32 vreg, |
| 2146 |
sljit_s32 src, sljit_s32 src_lane_index); |
| 2147 |
|
| 2148 |
/* The following options are used by sljit_emit_simd_load_extend(). */ |
| 2149 |
|
| 2150 |
/* Sign extend the integer elements */ |
| 2151 |
#define SLJIT_SIMD_EXTEND_SIGNED 0x000002 |
| 2152 |
/* Extend data to 16 bit */ |
| 2153 |
#define SLJIT_SIMD_EXTEND_16 (1 << 24) |
| 2154 |
/* Extend data to 32 bit */ |
| 2155 |
#define SLJIT_SIMD_EXTEND_32 (2 << 24) |
| 2156 |
/* Extend data to 64 bit */ |
| 2157 |
#define SLJIT_SIMD_EXTEND_64 (3 << 24) |
| 2158 |
|
| 2159 |
/* Extend elements and stores them in a vector register. |
| 2160 |
The extension operation increases the size of the |
| 2161 |
elements (e.g. from 16 bit to 64 bit). For integer |
| 2162 |
values, the extension can be signed or unsigned. |
| 2163 |
|
| 2164 |
If the operation is not supported, it returns with |
| 2165 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2166 |
it does not emit any instructions. |
| 2167 |
|
| 2168 |
type must be a combination of SLJIT_SIMD_*, and |
| 2169 |
SLJIT_SIMD_EXTEND_* options except SLJIT_SIMD_STORE |
| 2170 |
vreg is the destination vector register of the operation |
| 2171 |
src must be a memory operand or a vector register. |
| 2172 |
In the latter case, the source elements are stored |
| 2173 |
in the lower half of the register. |
| 2174 |
|
| 2175 |
Flags: - (does not modify flags) */ |
| 2176 |
|
| 2177 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_extend(struct sljit_compiler *compiler, sljit_s32 type, |
| 2178 |
sljit_s32 vreg, |
| 2179 |
sljit_s32 src, sljit_sw srcw); |
| 2180 |
|
| 2181 |
/* Extract the highest bit (usually the sign bit) from |
| 2182 |
each elements of a vector. |
| 2183 |
|
| 2184 |
If the operation is not supported, it returns with |
| 2185 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2186 |
it does not emit any instructions. |
| 2187 |
|
| 2188 |
type must be a combination of SLJIT_SIMD_* and SLJIT_32 |
| 2189 |
options except SLJIT_SIMD_LOAD |
| 2190 |
vreg is the source vector register of the operation |
| 2191 |
dst is the destination operand |
| 2192 |
|
| 2193 |
Flags: - (does not modify flags) */ |
| 2194 |
|
| 2195 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_sign(struct sljit_compiler *compiler, sljit_s32 type, |
| 2196 |
sljit_s32 vreg, |
| 2197 |
sljit_s32 dst, sljit_sw dstw); |
| 2198 |
|
| 2199 |
/* The following operations are used by sljit_emit_simd_op2(). */ |
| 2200 |
|
| 2201 |
/* Binary 'and' operation */ |
| 2202 |
#define SLJIT_SIMD_OP2_AND 0x000001 |
| 2203 |
/* Binary 'or' operation */ |
| 2204 |
#define SLJIT_SIMD_OP2_OR 0x000002 |
| 2205 |
/* Binary 'xor' operation */ |
| 2206 |
#define SLJIT_SIMD_OP2_XOR 0x000003 |
| 2207 |
/* Shuffle bytes of src1 using the indicies in src2 */ |
| 2208 |
#define SLJIT_SIMD_OP2_SHUFFLE 0x000004 |
| 2209 |
|
| 2210 |
/* Perform simd operations using vector registers. |
| 2211 |
|
| 2212 |
If the operation is not supported, it returns with |
| 2213 |
SLJIT_ERR_UNSUPPORTED. If SLJIT_SIMD_TEST is passed, |
| 2214 |
it does not emit any instructions. |
| 2215 |
|
| 2216 |
type must be a combination of SLJIT_SIMD_*, SLJIT_SIMD_MEM_* |
| 2217 |
and SLJIT_SIMD_OP2_* options except SLJIT_SIMD_LOAD |
| 2218 |
and SLJIT_SIMD_STORE |
| 2219 |
dst_vreg is the destination register of the operation |
| 2220 |
src1_vreg is the first source register of the operation |
| 2221 |
src2 is the second source operand of the operation |
| 2222 |
|
| 2223 |
Flags: - (does not modify flags) */ |
| 2224 |
|
| 2225 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *compiler, sljit_s32 type, |
| 2226 |
sljit_s32 dst_vreg, sljit_s32 src1_vreg, sljit_s32 src2, sljit_sw src2w); |
| 2227 |
|
| 2228 |
/* The following operations are used by sljit_emit_atomic_load() and |
| 2229 |
sljit_emit_atomic_store() operations. */ |
| 2230 |
|
| 2231 |
/* Tests whether the atomic operation is available (does not generate |
| 2232 |
any instructions). When a load from is allowed, its corresponding |
| 2233 |
store form is allowed and vice versa. */ |
| 2234 |
#define SLJIT_ATOMIC_TEST 0x10000 |
| 2235 |
/* The compiler must generate compare and swap instruction. |
| 2236 |
When this bit is set, calling sljit_emit_atomic_load() is optional. */ |
| 2237 |
#define SLJIT_ATOMIC_USE_CAS 0x20000 |
| 2238 |
/* The compiler must generate load-acquire and store-release instructions. |
| 2239 |
When this bit is set, the temp_reg for sljit_emit_atomic_store is not used. */ |
| 2240 |
#define SLJIT_ATOMIC_USE_LS 0x40000 |
| 2241 |
|
| 2242 |
/* The sljit_emit_atomic_load and sljit_emit_atomic_store operation pair |
| 2243 |
can perform an atomic read-modify-write operation. First, an unsigned |
| 2244 |
value must be loaded from memory using sljit_emit_atomic_load. Then, |
| 2245 |
the updated value must be written back to the same memory location by |
| 2246 |
sljit_emit_atomic_store. A thread can only perform a single atomic |
| 2247 |
operation at a time. |
| 2248 |
|
| 2249 |
The following conditions must be satisfied, or the operation |
| 2250 |
is undefined: |
| 2251 |
- the address provided in mem_reg must be divisible by the size of |
| 2252 |
the value (only naturally aligned updates are supported) |
| 2253 |
- no memory operations are allowed between the load and store operations |
| 2254 |
- the memory operation (op) and the base address (stored in mem_reg) |
| 2255 |
passed to the load/store operations must be the same (the mem_reg |
| 2256 |
can be a different register, only its value must be the same) |
| 2257 |
- a store must always follow a load for the same transaction. |
| 2258 |
|
| 2259 |
op must be between SLJIT_MOV and SLJIT_MOV_P |
| 2260 |
dst_reg is the register where the data will be loaded into |
| 2261 |
mem_reg is the base address of the memory load (it cannot be |
| 2262 |
SLJIT_SP or a virtual register on x86-32) |
| 2263 |
|
| 2264 |
Flags: - (does not modify flags) */ |
| 2265 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_load(struct sljit_compiler *compiler, sljit_s32 op, |
| 2266 |
sljit_s32 dst_reg, |
| 2267 |
sljit_s32 mem_reg); |
| 2268 |
|
| 2269 |
/* The sljit_emit_atomic_load and sljit_emit_atomic_store operations |
| 2270 |
allows performing an atomic read-modify-write operation. See the |
| 2271 |
description of sljit_emit_atomic_load. |
| 2272 |
|
| 2273 |
op must be between SLJIT_MOV and SLJIT_MOV_P |
| 2274 |
src_reg is the register which value is stored into the memory |
| 2275 |
mem_reg is the base address of the memory store (it cannot be |
| 2276 |
SLJIT_SP or a virtual register on x86-32) |
| 2277 |
temp_reg is a scratch register, which must be initialized with |
| 2278 |
the value loaded into the dst_reg during the corresponding |
| 2279 |
sljit_emit_atomic_load operation, or the operation is undefined. |
| 2280 |
The temp_reg register preserves its value, if the memory store |
| 2281 |
is successful. Otherwise, its value is undefined. |
| 2282 |
|
| 2283 |
Flags: ATOMIC_STORED |
| 2284 |
if ATOMIC_STORED flag is set, it represents that the memory |
| 2285 |
is updated with a new value. Otherwise the memory is unchanged. */ |
| 2286 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler *compiler, sljit_s32 op, |
| 2287 |
sljit_s32 src_reg, |
| 2288 |
sljit_s32 mem_reg, |
| 2289 |
sljit_s32 temp_reg); |
| 2290 |
|
| 2291 |
/* Copies the base address of SLJIT_SP + offset to dst. The offset can |
| 2292 |
represent the starting address of a value in the local data (stack). |
| 2293 |
The offset is not limited by the local data limits, it can be any value. |
| 2294 |
For example if an array of bytes are stored on the stack from |
| 2295 |
offset 0x40, and R0 contains the offset of an array item plus 0x120, |
| 2296 |
this item can be changed by two SLJIT instructions: |
| 2297 |
|
| 2298 |
sljit_get_local_base(compiler, SLJIT_R1, 0, 0x40 - 0x120); |
| 2299 |
sljit_emit_op1(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), 0, SLJIT_IMM, 0x5); |
| 2300 |
|
| 2301 |
Flags: - (may destroy flags) */ |
| 2302 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset); |
| 2303 |
|
| 2304 |
/* Store a value that can be changed runtime (see: sljit_get_const_addr / sljit_set_const) |
| 2305 |
Flags: - (does not modify flags) */ |
| 2306 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value); |
| 2307 |
|
| 2308 |
/* Store the value of a label (see: sljit_set_label / sljit_set_target) |
| 2309 |
Flags: - (does not modify flags) */ |
| 2310 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw); |
| 2311 |
|
| 2312 |
/* Provides the address of label, jump and const instructions after sljit_generate_code |
| 2313 |
is called. The returned value is unspecified before the sljit_generate_code call. |
| 2314 |
Since these structures are freed by sljit_free_compiler, the addresses must be |
| 2315 |
preserved by the user program elsewere. */ |
| 2316 |
static SLJIT_INLINE sljit_uw sljit_get_label_addr(struct sljit_label *label) { return label->u.addr; } |
| 2317 |
static SLJIT_INLINE sljit_uw sljit_get_jump_addr(struct sljit_jump *jump) { return jump->addr; } |
| 2318 |
static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { return const_->addr; } |
| 2319 |
|
| 2320 |
/* Only the address and executable offset are required to perform dynamic |
| 2321 |
code modifications. See sljit_get_executable_offset function. */ |
| 2322 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset); |
| 2323 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset); |
| 2324 |
|
| 2325 |
/* --------------------------------------------------------------------- */ |
| 2326 |
/* CPU specific functions */ |
| 2327 |
/* --------------------------------------------------------------------- */ |
| 2328 |
|
| 2329 |
/* Types for sljit_get_register_index */ |
| 2330 |
|
| 2331 |
/* General purpose (integer) registers. */ |
| 2332 |
#define SLJIT_GP_REGISTER 0 |
| 2333 |
/* Floating point registers. */ |
| 2334 |
#define SLJIT_FLOAT_REGISTER 1 |
| 2335 |
|
| 2336 |
/* The following function is a helper function for sljit_emit_op_custom. |
| 2337 |
It returns with the real machine register index ( >=0 ) of any registers. |
| 2338 |
|
| 2339 |
When type is SLJIT_GP_REGISTER: |
| 2340 |
reg must be an SLJIT_R(i), SLJIT_S(i), or SLJIT_SP register |
| 2341 |
|
| 2342 |
When type is SLJIT_FLOAT_REGISTER: |
| 2343 |
reg must be an SLJIT_FR(i) or SLJIT_FS(i) register |
| 2344 |
|
| 2345 |
When type is SLJIT_SIMD_REG_64 / 128 / 256 / 512 : |
| 2346 |
reg must be an SLJIT_FR(i) or SLJIT_FS(i) register |
| 2347 |
|
| 2348 |
Note: it returns with -1 for unknown registers, such as virtual |
| 2349 |
registers on x86-32 or unsupported simd registers. */ |
| 2350 |
|
| 2351 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 type, sljit_s32 reg); |
| 2352 |
|
| 2353 |
/* Any instruction can be inserted into the instruction stream by |
| 2354 |
sljit_emit_op_custom. It has a similar purpose as inline assembly. |
| 2355 |
The size parameter must match to the instruction size of the target |
| 2356 |
architecture: |
| 2357 |
|
| 2358 |
x86: 0 < size <= 15, the instruction argument can be byte aligned. |
| 2359 |
Thumb2: if size == 2, the instruction argument must be 2 byte aligned. |
| 2360 |
if size == 4, the instruction argument must be 4 byte aligned. |
| 2361 |
s390x: size can be 2, 4, or 6, the instruction argument can be byte aligned. |
| 2362 |
Otherwise: size must be 4 and instruction argument must be 4 byte aligned. */ |
| 2363 |
|
| 2364 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler, |
| 2365 |
void *instruction, sljit_u32 size); |
| 2366 |
|
| 2367 |
/* Flags were set by a 32 bit operation. */ |
| 2368 |
#define SLJIT_CURRENT_FLAGS_32 SLJIT_32 |
| 2369 |
|
| 2370 |
/* Flags were set by an ADD or ADDC operations. */ |
| 2371 |
#define SLJIT_CURRENT_FLAGS_ADD 0x01 |
| 2372 |
/* Flags were set by a SUB, SUBC, or NEG operation. */ |
| 2373 |
#define SLJIT_CURRENT_FLAGS_SUB 0x02 |
| 2374 |
|
| 2375 |
/* Flags were set by sljit_emit_op2u with SLJIT_SUB opcode. |
| 2376 |
Must be combined with SLJIT_CURRENT_FLAGS_SUB. */ |
| 2377 |
#define SLJIT_CURRENT_FLAGS_COMPARE 0x04 |
| 2378 |
|
| 2379 |
/* Define the currently available CPU status flags. It is usually used after |
| 2380 |
an sljit_emit_label or sljit_emit_op_custom operations to define which CPU |
| 2381 |
status flags are available. |
| 2382 |
|
| 2383 |
The current_flags must be a valid combination of SLJIT_SET_* and |
| 2384 |
SLJIT_CURRENT_FLAGS_* constants. */ |
| 2385 |
|
| 2386 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, |
| 2387 |
sljit_s32 current_flags); |
| 2388 |
|
| 2389 |
/* --------------------------------------------------------------------- */ |
| 2390 |
/* Serialization functions */ |
| 2391 |
/* --------------------------------------------------------------------- */ |
| 2392 |
|
| 2393 |
/* Label/jump/const enumeration functions. The items in each group |
| 2394 |
are enumerated in creation order. Serialization / deserialization |
| 2395 |
preserves this order for each group. For example the fifth label |
| 2396 |
after deserialization refers to the same machine code location as |
| 2397 |
the fifth label before the serialization. */ |
| 2398 |
static SLJIT_INLINE struct sljit_label *sljit_get_first_label(struct sljit_compiler *compiler) { return compiler->labels; } |
| 2399 |
static SLJIT_INLINE struct sljit_jump *sljit_get_first_jump(struct sljit_compiler *compiler) { return compiler->jumps; } |
| 2400 |
static SLJIT_INLINE struct sljit_const *sljit_get_first_const(struct sljit_compiler *compiler) { return compiler->consts; } |
| 2401 |
|
| 2402 |
static SLJIT_INLINE struct sljit_label *sljit_get_next_label(struct sljit_label *label) { return label->next; } |
| 2403 |
static SLJIT_INLINE struct sljit_jump *sljit_get_next_jump(struct sljit_jump *jump) { return jump->next; } |
| 2404 |
static SLJIT_INLINE struct sljit_const *sljit_get_next_const(struct sljit_const *const_) { return const_->next; } |
| 2405 |
|
| 2406 |
/* A number starting from 0 is assigned to each label, which |
| 2407 |
represents its creation index. The first label created by the |
| 2408 |
compiler has index 0, the second has index 1, the third has |
| 2409 |
index 2, and so on. The returned value is unspecified after |
| 2410 |
sljit_generate_code() is called. */ |
| 2411 |
static SLJIT_INLINE sljit_uw sljit_get_label_index(struct sljit_label *label) { return label->u.index; } |
| 2412 |
|
| 2413 |
/* The sljit_jump_has_label() and sljit_jump_has_target() functions |
| 2414 |
returns non-zero value if a label or target is set for the jump |
| 2415 |
respectively. Both may return with a zero value. The other two |
| 2416 |
functions return the value assigned to the jump. */ |
| 2417 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_label(struct sljit_jump *jump); |
| 2418 |
static SLJIT_INLINE struct sljit_label *sljit_jump_get_label(struct sljit_jump *jump) { return jump->u.label; } |
| 2419 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_has_target(struct sljit_jump *jump); |
| 2420 |
static SLJIT_INLINE sljit_uw sljit_jump_get_target(struct sljit_jump *jump) { return jump->u.target; } |
| 2421 |
SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_jump_is_mov_addr(struct sljit_jump *jump); |
| 2422 |
|
| 2423 |
/* Option bits for sljit_serialize_compiler. */ |
| 2424 |
|
| 2425 |
/* When debugging is enabled, the serialized buffer contains |
| 2426 |
debugging information unless this option is specified. */ |
| 2427 |
#define SLJIT_SERIALIZE_IGNORE_DEBUG 0x1 |
| 2428 |
|
| 2429 |
/* Serialize the internal structure of the compiler into a buffer. |
| 2430 |
If the serialization is successful, the returned value is a newly |
| 2431 |
allocated buffer which is allocated by the memory allocator assigned |
| 2432 |
to the compiler. Otherwise the returned value is NULL. Unlike |
| 2433 |
sljit_generate_code(), serialization does not modify the internal |
| 2434 |
state of the compiler, so the code generation can be continued. |
| 2435 |
|
| 2436 |
options must be the combination of SLJIT_SERIALIZE_* option bits |
| 2437 |
size is an output argument, which is set to the byte size of |
| 2438 |
the result buffer if the operation is successful |
| 2439 |
|
| 2440 |
Notes: |
| 2441 |
- This function is useful for ahead-of-time compilation (AOT). |
| 2442 |
- The returned buffer must be freed later by the caller. |
| 2443 |
The SLJIT_FREE() macro is suitable for this purpose: |
| 2444 |
SLJIT_FREE(returned_buffer, sljit_get_allocator_data(compiler)) |
| 2445 |
- Memory allocated by sljit_alloc_memory() is not serialized. |
| 2446 |
- The type of the returned buffer is sljit_uw* to emphasize that |
| 2447 |
the buffer is word aligned. However, the 'size' output argument |
| 2448 |
contains the byte size, so this value is always divisible by |
| 2449 |
sizeof(sljit_uw). |
| 2450 |
*/ |
| 2451 |
SLJIT_API_FUNC_ATTRIBUTE sljit_uw* sljit_serialize_compiler(struct sljit_compiler *compiler, |
| 2452 |
sljit_s32 options, sljit_uw *size); |
| 2453 |
|
| 2454 |
/* Construct a new compiler instance from a buffer produced by |
| 2455 |
sljit_serialize_compiler(). If the operation is successful, the new |
| 2456 |
compiler instance is returned. Otherwise the returned value is NULL. |
| 2457 |
|
| 2458 |
buffer points to a word aligned memory data which was |
| 2459 |
created by sljit_serialize_compiler() |
| 2460 |
size is the byte size of the buffer |
| 2461 |
options must be 0 |
| 2462 |
allocator_data specify an allocator specific data, see |
| 2463 |
sljit_create_compiler() for further details |
| 2464 |
|
| 2465 |
Notes: |
| 2466 |
- Labels assigned to jumps are restored with their |
| 2467 |
corresponding label in the label set created by |
| 2468 |
the deserializer. Target addresses assigned to |
| 2469 |
jumps are also restored. Uninitialized jumps |
| 2470 |
remain uninitialized. |
| 2471 |
- After the deserialization, sljit_generate_code() does |
| 2472 |
not need to be the next operation on the returned |
| 2473 |
compiler, the code generation can be continued. |
| 2474 |
Even sljit_serialize_compiler() can be called again. |
| 2475 |
- When debugging is enabled, a buffers without debug |
| 2476 |
information cannot be deserialized. |
| 2477 |
*/ |
| 2478 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler *sljit_deserialize_compiler(sljit_uw* buffer, sljit_uw size, |
| 2479 |
sljit_s32 options, void *allocator_data); |
| 2480 |
|
| 2481 |
/* --------------------------------------------------------------------- */ |
| 2482 |
/* Miscellaneous utility functions */ |
| 2483 |
/* --------------------------------------------------------------------- */ |
| 2484 |
|
| 2485 |
/* Get the human readable name of the platform. Can be useful on platforms |
| 2486 |
like ARM, where ARM and Thumb2 functions can be mixed, and it is useful |
| 2487 |
to know the type of the code generator. */ |
| 2488 |
SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void); |
| 2489 |
|
| 2490 |
/* Portable helper function to get an offset of a member. |
| 2491 |
Same as offsetof() macro defined in stddef.h */ |
| 2492 |
#define SLJIT_OFFSETOF(base, member) ((sljit_sw)(&((base*)0x10)->member) - 0x10) |
| 2493 |
|
| 2494 |
#if (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) |
| 2495 |
|
| 2496 |
/* The sljit_stack structure and its manipulation functions provides |
| 2497 |
an implementation for a top-down stack. The stack top is stored |
| 2498 |
in the end field of the sljit_stack structure and the stack goes |
| 2499 |
down to the min_start field, so the memory region reserved for |
| 2500 |
this stack is between min_start (inclusive) and end (exclusive) |
| 2501 |
fields. However the application can only use the region between |
| 2502 |
start (inclusive) and end (exclusive) fields. The sljit_stack_resize |
| 2503 |
function can be used to extend this region up to min_start. |
| 2504 |
|
| 2505 |
This feature uses the "address space reserve" feature of modern |
| 2506 |
operating systems. Instead of allocating a large memory block |
| 2507 |
applications can allocate a small memory region and extend it |
| 2508 |
later without moving the content of the memory area. Therefore |
| 2509 |
after a successful resize by sljit_stack_resize all pointers into |
| 2510 |
this region are still valid. |
| 2511 |
|
| 2512 |
Note: |
| 2513 |
this structure may not be supported by all operating systems. |
| 2514 |
end and max_limit fields are aligned to PAGE_SIZE bytes (usually |
| 2515 |
4 Kbyte or more). |
| 2516 |
stack should grow in larger steps, e.g. 4Kbyte, 16Kbyte or more. */ |
| 2517 |
|
| 2518 |
struct sljit_stack { |
| 2519 |
/* User data, anything can be stored here. |
| 2520 |
Initialized to the same value as the end field. */ |
| 2521 |
sljit_u8 *top; |
| 2522 |
/* These members are read only. */ |
| 2523 |
/* End address of the stack */ |
| 2524 |
sljit_u8 *end; |
| 2525 |
/* Current start address of the stack. */ |
| 2526 |
sljit_u8 *start; |
| 2527 |
/* Lowest start address of the stack. */ |
| 2528 |
sljit_u8 *min_start; |
| 2529 |
}; |
| 2530 |
|
| 2531 |
/* Allocates a new stack. Returns NULL if unsuccessful. |
| 2532 |
Note: see sljit_create_compiler for the explanation of allocator_data. */ |
| 2533 |
SLJIT_API_FUNC_ATTRIBUTE struct sljit_stack* SLJIT_FUNC sljit_allocate_stack(sljit_uw start_size, sljit_uw max_size, void *allocator_data); |
| 2534 |
SLJIT_API_FUNC_ATTRIBUTE void SLJIT_FUNC sljit_free_stack(struct sljit_stack *stack, void *allocator_data); |
| 2535 |
|
| 2536 |
/* Can be used to increase (extend) or decrease (shrink) the stack |
| 2537 |
memory area. Returns with new_start if successful and NULL otherwise. |
| 2538 |
It always fails if new_start is less than min_start or greater or equal |
| 2539 |
than end fields. The fields of the stack are not changed if the returned |
| 2540 |
value is NULL (the current memory content is never lost). */ |
| 2541 |
SLJIT_API_FUNC_ATTRIBUTE sljit_u8 *SLJIT_FUNC sljit_stack_resize(struct sljit_stack *stack, sljit_u8 *new_start); |
| 2542 |
|
| 2543 |
#endif /* (defined SLJIT_UTIL_STACK && SLJIT_UTIL_STACK) */ |
| 2544 |
|
| 2545 |
#if !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) |
| 2546 |
|
| 2547 |
/* Get the entry address of a given function (signed, unsigned result). */ |
| 2548 |
#define SLJIT_FUNC_ADDR(func_name) ((sljit_sw)func_name) |
| 2549 |
#define SLJIT_FUNC_UADDR(func_name) ((sljit_uw)func_name) |
| 2550 |
|
| 2551 |
#else /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */ |
| 2552 |
|
| 2553 |
/* All JIT related code should be placed in the same context (library, binary, etc.). */ |
| 2554 |
|
| 2555 |
/* Get the entry address of a given function (signed, unsigned result). */ |
| 2556 |
#define SLJIT_FUNC_ADDR(func_name) (*(sljit_sw*)(void*)func_name) |
| 2557 |
#define SLJIT_FUNC_UADDR(func_name) (*(sljit_uw*)(void*)func_name) |
| 2558 |
|
| 2559 |
/* For powerpc64, the function pointers point to a context descriptor. */ |
| 2560 |
struct sljit_function_context { |
| 2561 |
sljit_uw addr; |
| 2562 |
sljit_uw r2; |
| 2563 |
sljit_uw r11; |
| 2564 |
}; |
| 2565 |
|
| 2566 |
/* Fill the context arguments using the addr and the function. |
| 2567 |
If func_ptr is NULL, it will not be set to the address of context |
| 2568 |
If addr is NULL, the function address also comes from the func pointer. */ |
| 2569 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_set_function_context(void** func_ptr, struct sljit_function_context* context, sljit_uw addr, void* func); |
| 2570 |
|
| 2571 |
#endif /* !(defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL) */ |
| 2572 |
|
| 2573 |
#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR) |
| 2574 |
/* Free unused executable memory. The allocator keeps some free memory |
| 2575 |
around to reduce the number of OS executable memory allocations. |
| 2576 |
This improves performance since these calls are costly. However |
| 2577 |
it is sometimes desired to free all unused memory regions, e.g. |
| 2578 |
before the application terminates. */ |
| 2579 |
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void); |
| 2580 |
#endif /* SLJIT_EXECUTABLE_ALLOCATOR */ |
| 2581 |
|
| 2582 |
#ifdef __cplusplus |
| 2583 |
} /* extern "C" */ |
| 2584 |
#endif /* __cplusplus */ |
| 2585 |
|
| 2586 |
#endif /* SLJIT_LIR_H_ */ |