Improve sljit abi calling convention
[sljit.git] / sljit_src / sljitLir.c
blob4e2555611893d14ab488b15bb58b4d384aa64b25
1 /*
2 * Stack-less Just-In-Time compiler
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
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.
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.
27 #include "sljitLir.h"
29 #ifdef _WIN32
31 #include <windows.h>
33 #endif /* _WIN32 */
35 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
37 /* These libraries are needed for the macros below. */
38 #include <stdlib.h>
39 #include <string.h>
41 #endif /* SLJIT_STD_MACROS_DEFINED */
43 #define CHECK_ERROR() \
44 do { \
45 if (SLJIT_UNLIKELY(compiler->error)) \
46 return compiler->error; \
47 } while (0)
49 #define CHECK_ERROR_PTR() \
50 do { \
51 if (SLJIT_UNLIKELY(compiler->error)) \
52 return NULL; \
53 } while (0)
55 #define FAIL_IF(expr) \
56 do { \
57 if (SLJIT_UNLIKELY(expr)) \
58 return compiler->error; \
59 } while (0)
61 #define PTR_FAIL_IF(expr) \
62 do { \
63 if (SLJIT_UNLIKELY(expr)) \
64 return NULL; \
65 } while (0)
67 #define FAIL_IF_NULL(ptr) \
68 do { \
69 if (SLJIT_UNLIKELY(!(ptr))) { \
70 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
71 return SLJIT_ERR_ALLOC_FAILED; \
72 } \
73 } while (0)
75 #define PTR_FAIL_IF_NULL(ptr) \
76 do { \
77 if (SLJIT_UNLIKELY(!(ptr))) { \
78 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
79 return NULL; \
80 } \
81 } while (0)
83 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
84 do { \
85 if (SLJIT_UNLIKELY(!(ptr))) { \
86 compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
87 return NULL; \
88 } \
89 } while (0)
91 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
93 #define SSIZE_OF(type) ((sljit_s32)sizeof(sljit_ ## type))
95 #define VARIABLE_FLAG_SHIFT (10)
96 #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
97 #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
99 #define GET_OPCODE(op) \
100 ((op) & ~(SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
102 #define HAS_FLAGS(op) \
103 ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
105 #define GET_ALL_FLAGS(op) \
106 ((op) & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
108 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
109 #define TYPE_CAST_NEEDED(op) \
110 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32)
111 #else /* !SLJIT_64BIT_ARCHITECTURE */
112 #define TYPE_CAST_NEEDED(op) \
113 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16)
114 #endif /* SLJIT_64BIT_ARCHITECTURE */
116 #define BUF_SIZE 4096
118 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
119 #define ABUF_SIZE 2048
120 #else
121 #define ABUF_SIZE 4096
122 #endif
124 /* Parameter parsing. */
125 #define REG_MASK 0x3f
126 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
127 #define OFFS_REG_MASK (REG_MASK << 8)
128 #define TO_OFFS_REG(reg) ((reg) << 8)
129 /* When reg cannot be unused. */
130 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
132 /* Mask for argument types. */
133 #define SLJIT_ARG_MASK 0x7
134 #define SLJIT_ARG_FULL_MASK (SLJIT_ARG_MASK | SLJIT_ARG_TYPE_SCRATCH_REG)
136 /* Mask for sljit_emit_enter. */
137 #define SLJIT_KEPT_SAVEDS_COUNT(options) ((options) & 0x3)
139 /* Jump flags. */
140 #define JUMP_LABEL 0x1
141 #define JUMP_ADDR 0x2
142 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
144 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
145 # define PATCH_MB 0x4
146 # define PATCH_MW 0x8
147 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
148 # define PATCH_MD 0x10
149 #endif
150 # define TYPE_SHIFT 13
151 #endif /* SLJIT_CONFIG_X86 */
153 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
154 # define IS_BL 0x4
155 # define PATCH_B 0x8
156 #endif /* SLJIT_CONFIG_ARM_V5 || SLJIT_CONFIG_ARM_V7 */
158 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
159 # define CPOOL_SIZE 512
160 #endif /* SLJIT_CONFIG_ARM_V5 */
162 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
163 # define IS_COND 0x04
164 # define IS_BL 0x08
165 /* conditional + imm8 */
166 # define PATCH_TYPE1 0x10
167 /* conditional + imm20 */
168 # define PATCH_TYPE2 0x20
169 /* IT + imm24 */
170 # define PATCH_TYPE3 0x30
171 /* imm11 */
172 # define PATCH_TYPE4 0x40
173 /* imm24 */
174 # define PATCH_TYPE5 0x50
175 /* BL + imm24 */
176 # define PATCH_BL 0x60
177 /* 0xf00 cc code for branches */
178 #endif /* SLJIT_CONFIG_ARM_THUMB2 */
180 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
181 # define IS_COND 0x004
182 # define IS_CBZ 0x008
183 # define IS_BL 0x010
184 # define PATCH_B 0x020
185 # define PATCH_COND 0x040
186 # define PATCH_ABS48 0x080
187 # define PATCH_ABS64 0x100
188 #endif /* SLJIT_CONFIG_ARM_64 */
190 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
191 # define IS_COND 0x004
192 # define IS_CALL 0x008
193 # define PATCH_B 0x010
194 # define PATCH_ABS_B 0x020
195 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
196 # define PATCH_ABS32 0x040
197 # define PATCH_ABS48 0x080
198 #endif /* SLJIT_CONFIG_PPC_64 */
199 # define REMOVE_COND 0x100
200 #endif /* SLJIT_CONFIG_PPC */
202 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
203 # define IS_MOVABLE 0x004
204 # define IS_JAL 0x008
205 # define IS_CALL 0x010
206 # define IS_BIT26_COND 0x020
207 # define IS_BIT16_COND 0x040
208 # define IS_BIT23_COND 0x080
210 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND)
212 # define PATCH_B 0x100
213 # define PATCH_J 0x200
215 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
216 # define PATCH_ABS32 0x400
217 # define PATCH_ABS48 0x800
218 #endif /* SLJIT_CONFIG_MIPS_64 */
220 /* instruction types */
221 # define MOVABLE_INS 0
222 /* 1 - 31 last destination register */
223 /* no destination (i.e: store) */
224 # define UNMOVABLE_INS 32
225 /* FPU status register */
226 # define FCSR_FCC 33
227 #endif /* SLJIT_CONFIG_MIPS */
229 #if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
230 # define IS_COND 0x004
231 # define IS_CALL 0x008
233 # define PATCH_B 0x010
234 # define PATCH_J 0x020
236 #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64)
237 # define PATCH_REL32 0x040
238 # define PATCH_ABS32 0x080
239 # define PATCH_ABS44 0x100
240 # define PATCH_ABS52 0x200
241 #else /* !SLJIT_CONFIG_RISCV_64 */
242 # define PATCH_REL32 0x0
243 #endif /* SLJIT_CONFIG_RISCV_64 */
244 #endif /* SLJIT_CONFIG_RISCV */
246 /* Stack management. */
248 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
249 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
250 (saveds) + (sljit_s32)(extra)) * (sljit_s32)sizeof(sljit_sw))
252 #define GET_SAVED_FLOAT_REGISTERS_SIZE(fscratches, fsaveds, size) \
253 (((fscratches < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS ? 0 : (fscratches - SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS)) + \
254 (fsaveds)) * (sljit_s32)(size))
256 #define ADJUST_LOCAL_OFFSET(p, i) \
257 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
258 (i) += SLJIT_LOCALS_OFFSET;
260 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
262 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
263 #include "sljitUtils.c"
265 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
267 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
269 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
270 #include "sljitProtExecAllocator.c"
271 #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR)
272 #include "sljitWXExecAllocator.c"
273 #else
274 #include "sljitExecAllocator.c"
275 #endif
277 #endif
279 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
280 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
281 #else
282 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
283 #endif
285 #ifndef SLJIT_UPDATE_WX_FLAGS
286 #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)
287 #endif
289 /* Argument checking features. */
291 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
293 /* Returns with error when an invalid argument is passed. */
295 #define CHECK_ARGUMENT(x) \
296 do { \
297 if (SLJIT_UNLIKELY(!(x))) \
298 return 1; \
299 } while (0)
301 #define CHECK_RETURN_TYPE sljit_s32
302 #define CHECK_RETURN_OK return 0
304 #define CHECK(x) \
305 do { \
306 if (SLJIT_UNLIKELY(x)) { \
307 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
308 return SLJIT_ERR_BAD_ARGUMENT; \
310 } while (0)
312 #define CHECK_PTR(x) \
313 do { \
314 if (SLJIT_UNLIKELY(x)) { \
315 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
316 return NULL; \
318 } while (0)
320 #define CHECK_REG_INDEX(x) \
321 do { \
322 if (SLJIT_UNLIKELY(x)) { \
323 return -2; \
325 } while (0)
327 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
329 /* Assertion failure occures if an invalid argument is passed. */
330 #undef SLJIT_ARGUMENT_CHECKS
331 #define SLJIT_ARGUMENT_CHECKS 1
333 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
334 #define CHECK_RETURN_TYPE void
335 #define CHECK_RETURN_OK return
336 #define CHECK(x) x
337 #define CHECK_PTR(x) x
338 #define CHECK_REG_INDEX(x) x
340 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
342 /* Arguments are not checked. */
343 #define CHECK_RETURN_TYPE void
344 #define CHECK_RETURN_OK return
345 #define CHECK(x) x
346 #define CHECK_PTR(x) x
347 #define CHECK_REG_INDEX(x) x
349 #else
351 /* Arguments are not checked. */
352 #define CHECK(x)
353 #define CHECK_PTR(x)
354 #define CHECK_REG_INDEX(x)
356 #endif /* SLJIT_ARGUMENT_CHECKS */
358 /* --------------------------------------------------------------------- */
359 /* Public functions */
360 /* --------------------------------------------------------------------- */
362 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
363 #define SLJIT_NEEDS_COMPILER_INIT 1
364 static sljit_s32 compiler_initialized = 0;
365 /* A thread safe initialization. */
366 static void init_compiler(void);
367 #endif
369 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
371 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
372 if (!compiler)
373 return NULL;
374 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
376 SLJIT_COMPILE_ASSERT(
377 sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
378 && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
379 && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
380 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
381 && sizeof(sljit_p) <= sizeof(sljit_sw)
382 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
383 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
384 invalid_integer_types);
385 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_32,
386 rewritable_jump_and_single_op_must_not_be_the_same);
387 SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_F_EQUAL & 0x1) && !(SLJIT_JUMP & 0x1),
388 conditional_flags_must_be_even_numbers);
390 /* Only the non-zero members must be set. */
391 compiler->error = SLJIT_SUCCESS;
393 compiler->allocator_data = allocator_data;
394 compiler->exec_allocator_data = exec_allocator_data;
395 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
396 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
398 if (!compiler->buf || !compiler->abuf) {
399 if (compiler->buf)
400 SLJIT_FREE(compiler->buf, allocator_data);
401 if (compiler->abuf)
402 SLJIT_FREE(compiler->abuf, allocator_data);
403 SLJIT_FREE(compiler, allocator_data);
404 return NULL;
407 compiler->buf->next = NULL;
408 compiler->buf->used_size = 0;
409 compiler->abuf->next = NULL;
410 compiler->abuf->used_size = 0;
412 compiler->scratches = -1;
413 compiler->saveds = -1;
414 compiler->fscratches = -1;
415 compiler->fsaveds = -1;
416 compiler->local_size = -1;
418 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
419 compiler->args_size = -1;
420 #endif
422 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
423 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
424 + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
425 if (!compiler->cpool) {
426 SLJIT_FREE(compiler->buf, allocator_data);
427 SLJIT_FREE(compiler->abuf, allocator_data);
428 SLJIT_FREE(compiler, allocator_data);
429 return NULL;
431 compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
432 compiler->cpool_diff = 0xffffffff;
433 #endif
435 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
436 compiler->delay_slot = UNMOVABLE_INS;
437 #endif
439 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
440 || (defined SLJIT_DEBUG && SLJIT_DEBUG)
441 compiler->last_flags = 0;
442 compiler->last_return = -1;
443 compiler->logical_local_size = 0;
444 #endif
446 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
447 if (!compiler_initialized) {
448 init_compiler();
449 compiler_initialized = 1;
451 #endif
453 return compiler;
456 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
458 struct sljit_memory_fragment *buf;
459 struct sljit_memory_fragment *curr;
460 void *allocator_data = compiler->allocator_data;
461 SLJIT_UNUSED_ARG(allocator_data);
463 buf = compiler->buf;
464 while (buf) {
465 curr = buf;
466 buf = buf->next;
467 SLJIT_FREE(curr, allocator_data);
470 buf = compiler->abuf;
471 while (buf) {
472 curr = buf;
473 buf = buf->next;
474 SLJIT_FREE(curr, allocator_data);
477 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
478 SLJIT_FREE(compiler->cpool, allocator_data);
479 #endif
480 SLJIT_FREE(compiler, allocator_data);
483 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
485 if (compiler->error == SLJIT_SUCCESS)
486 compiler->error = SLJIT_ERR_ALLOC_FAILED;
489 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
490 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
492 SLJIT_UNUSED_ARG(exec_allocator_data);
494 /* Remove thumb mode flag. */
495 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~(sljit_uw)0x1), exec_allocator_data);
497 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
498 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
500 SLJIT_UNUSED_ARG(exec_allocator_data);
502 /* Resolve indirection. */
503 code = (void*)(*(sljit_uw*)code);
504 SLJIT_FREE_EXEC(code, exec_allocator_data);
506 #else
507 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
509 SLJIT_UNUSED_ARG(exec_allocator_data);
511 SLJIT_FREE_EXEC(code, exec_allocator_data);
513 #endif
515 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
517 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
518 jump->flags &= (sljit_uw)~JUMP_ADDR;
519 jump->flags |= JUMP_LABEL;
520 jump->u.label = label;
524 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
526 if (SLJIT_LIKELY(!!jump)) {
527 jump->flags &= (sljit_uw)~JUMP_LABEL;
528 jump->flags |= JUMP_ADDR;
529 jump->u.target = target;
533 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
535 if (SLJIT_LIKELY(!!put_label))
536 put_label->label = label;
539 #define SLJIT_CURRENT_FLAGS_ALL \
540 (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE)
542 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
544 SLJIT_UNUSED_ARG(compiler);
545 SLJIT_UNUSED_ARG(current_flags);
547 #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
548 compiler->status_flags_state = current_flags;
549 #endif
551 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
552 compiler->last_flags = 0;
553 if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) {
554 compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z));
556 #endif
559 /* --------------------------------------------------------------------- */
560 /* Private functions */
561 /* --------------------------------------------------------------------- */
563 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
565 sljit_u8 *ret;
566 struct sljit_memory_fragment *new_frag;
568 SLJIT_ASSERT(size <= 256);
569 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
570 ret = compiler->buf->memory + compiler->buf->used_size;
571 compiler->buf->used_size += size;
572 return ret;
574 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
575 PTR_FAIL_IF_NULL(new_frag);
576 new_frag->next = compiler->buf;
577 compiler->buf = new_frag;
578 new_frag->used_size = size;
579 return new_frag->memory;
582 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
584 sljit_u8 *ret;
585 struct sljit_memory_fragment *new_frag;
587 SLJIT_ASSERT(size <= 256);
588 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
589 ret = compiler->abuf->memory + compiler->abuf->used_size;
590 compiler->abuf->used_size += size;
591 return ret;
593 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
594 PTR_FAIL_IF_NULL(new_frag);
595 new_frag->next = compiler->abuf;
596 compiler->abuf = new_frag;
597 new_frag->used_size = size;
598 return new_frag->memory;
601 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
603 CHECK_ERROR_PTR();
605 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
606 if (size <= 0 || size > 128)
607 return NULL;
608 size = (size + 7) & ~7;
609 #else
610 if (size <= 0 || size > 64)
611 return NULL;
612 size = (size + 3) & ~3;
613 #endif
614 return ensure_abuf(compiler, (sljit_uw)size);
617 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
619 struct sljit_memory_fragment *buf = compiler->buf;
620 struct sljit_memory_fragment *prev = NULL;
621 struct sljit_memory_fragment *tmp;
623 do {
624 tmp = buf->next;
625 buf->next = prev;
626 prev = buf;
627 buf = tmp;
628 } while (buf != NULL);
630 compiler->buf = prev;
633 /* Only used in RISC architectures where the instruction size is constant */
634 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
635 && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
637 static SLJIT_INLINE sljit_uw compute_next_addr(struct sljit_label *label, struct sljit_jump *jump,
638 struct sljit_const *const_, struct sljit_put_label *put_label)
640 sljit_uw result = ~(sljit_uw)0;
642 if (label)
643 result = label->size;
645 if (jump && jump->addr < result)
646 result = jump->addr;
648 if (const_ && const_->addr < result)
649 result = const_->addr;
651 if (put_label && put_label->addr < result)
652 result = put_label->addr;
654 return result;
657 #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X */
659 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
660 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
661 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
663 SLJIT_UNUSED_ARG(args);
664 SLJIT_UNUSED_ARG(local_size);
666 compiler->options = options;
667 compiler->scratches = scratches;
668 compiler->saveds = saveds;
669 compiler->fscratches = fscratches;
670 compiler->fsaveds = fsaveds;
671 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
672 compiler->last_return = args & SLJIT_ARG_MASK;
673 compiler->logical_local_size = local_size;
674 #endif
677 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
678 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
679 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
681 SLJIT_UNUSED_ARG(args);
682 SLJIT_UNUSED_ARG(local_size);
684 compiler->options = options;
685 compiler->scratches = scratches;
686 compiler->saveds = saveds;
687 compiler->fscratches = fscratches;
688 compiler->fsaveds = fsaveds;
689 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
690 compiler->last_return = args & SLJIT_ARG_MASK;
691 compiler->logical_local_size = local_size;
692 #endif
695 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
697 label->next = NULL;
698 label->size = compiler->size;
699 if (compiler->last_label)
700 compiler->last_label->next = label;
701 else
702 compiler->labels = label;
703 compiler->last_label = label;
706 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_u32 flags)
708 jump->next = NULL;
709 jump->flags = flags;
710 if (compiler->last_jump)
711 compiler->last_jump->next = jump;
712 else
713 compiler->jumps = jump;
714 compiler->last_jump = jump;
717 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
719 const_->next = NULL;
720 const_->addr = compiler->size;
721 if (compiler->last_const)
722 compiler->last_const->next = const_;
723 else
724 compiler->consts = const_;
725 compiler->last_const = const_;
728 static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
730 put_label->next = NULL;
731 put_label->label = NULL;
732 put_label->addr = compiler->size - offset;
733 put_label->flags = 0;
734 if (compiler->last_put_label)
735 compiler->last_put_label->next = put_label;
736 else
737 compiler->put_labels = put_label;
738 compiler->last_put_label = put_label;
741 #define ADDRESSING_DEPENDS_ON(exp, reg) \
742 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
744 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
746 static sljit_s32 function_check_arguments(sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches)
748 sljit_s32 word_arg_count, scratch_arg_end, saved_arg_count, float_arg_count, curr_type;
750 curr_type = (arg_types & SLJIT_ARG_FULL_MASK);
752 if (curr_type >= SLJIT_ARG_TYPE_F64) {
753 if (curr_type > SLJIT_ARG_TYPE_F32 || fscratches == 0)
754 return 0;
755 } else if (curr_type >= SLJIT_ARG_TYPE_W) {
756 if (scratches == 0)
757 return 0;
760 arg_types >>= SLJIT_ARG_SHIFT;
762 word_arg_count = 0;
763 scratch_arg_end = 0;
764 saved_arg_count = 0;
765 float_arg_count = 0;
766 while (arg_types != 0) {
767 if (word_arg_count + float_arg_count >= 4)
768 return 0;
770 curr_type = (arg_types & SLJIT_ARG_MASK);
772 if (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) {
773 if (saveds == -1 || curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_P)
774 return 0;
776 word_arg_count++;
777 scratch_arg_end = word_arg_count;
778 } else {
779 if (curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_F32)
780 return 0;
782 if (curr_type < SLJIT_ARG_TYPE_F64) {
783 word_arg_count++;
784 saved_arg_count++;
785 } else
786 float_arg_count++;
789 arg_types >>= SLJIT_ARG_SHIFT;
792 if (saveds == -1)
793 return (word_arg_count <= scratches && float_arg_count <= fscratches);
795 return (saved_arg_count <= saveds && scratch_arg_end <= scratches && float_arg_count <= fscratches);
798 #define FUNCTION_CHECK_IS_REG(r) \
799 (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
800 || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
802 #define FUNCTION_CHECK_IS_FREG(fr) \
803 (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
804 || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
806 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
807 #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
808 #else
809 #define CHECK_IF_VIRTUAL_REGISTER(p) 0
810 #endif
812 static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
814 if (compiler->scratches == -1 || compiler->saveds == -1)
815 return 0;
817 if (!(p & SLJIT_MEM))
818 return 0;
820 if (p == SLJIT_MEM1(SLJIT_SP))
821 return (i >= 0 && i < compiler->logical_local_size);
823 if (!(!(p & REG_MASK) || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
824 return 0;
826 if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
827 return 0;
829 if (p & OFFS_REG_MASK) {
830 if (!(p & REG_MASK))
831 return 0;
833 if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
834 return 0;
836 if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
837 return 0;
839 if ((i & ~0x3) != 0)
840 return 0;
843 return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
846 #define FUNCTION_CHECK_SRC_MEM(p, i) \
847 CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
849 static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
851 if (compiler->scratches == -1 || compiler->saveds == -1)
852 return 0;
854 if (FUNCTION_CHECK_IS_REG(p))
855 return (i == 0);
857 if (p == SLJIT_IMM)
858 return 1;
860 return function_check_src_mem(compiler, p, i);
863 #define FUNCTION_CHECK_SRC(p, i) \
864 CHECK_ARGUMENT(function_check_src(compiler, p, i));
866 static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
868 if (compiler->scratches == -1 || compiler->saveds == -1)
869 return 0;
871 if (FUNCTION_CHECK_IS_REG(p))
872 return (i == 0);
874 return function_check_src_mem(compiler, p, i);
877 #define FUNCTION_CHECK_DST(p, i) \
878 CHECK_ARGUMENT(function_check_dst(compiler, p, i));
880 static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
882 if (compiler->scratches == -1 || compiler->saveds == -1)
883 return 0;
885 if (FUNCTION_CHECK_IS_FREG(p))
886 return (i == 0);
888 return function_check_src_mem(compiler, p, i);
891 #define FUNCTION_FCHECK(p, i) \
892 CHECK_ARGUMENT(function_fcheck(compiler, p, i));
894 #endif /* SLJIT_ARGUMENT_CHECKS */
896 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
898 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
900 compiler->verbose = verbose;
903 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
904 #ifdef _WIN64
905 #ifdef __GNUC__
906 # define SLJIT_PRINT_D "ll"
907 #else
908 # define SLJIT_PRINT_D "I64"
909 #endif
910 #else
911 # define SLJIT_PRINT_D "l"
912 #endif
913 #else
914 # define SLJIT_PRINT_D ""
915 #endif
917 static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
919 if (r < (SLJIT_R0 + compiler->scratches))
920 fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
921 else if (r != SLJIT_SP)
922 fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
923 else
924 fprintf(compiler->verbose, "sp");
927 static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
929 if (r < (SLJIT_FR0 + compiler->fscratches))
930 fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
931 else
932 fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
935 static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
937 if ((p) & SLJIT_IMM)
938 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
939 else if ((p) & SLJIT_MEM) {
940 if ((p) & REG_MASK) {
941 fputc('[', compiler->verbose);
942 sljit_verbose_reg(compiler, (p) & REG_MASK);
943 if ((p) & OFFS_REG_MASK) {
944 fprintf(compiler->verbose, " + ");
945 sljit_verbose_reg(compiler, OFFS_REG(p));
946 if (i)
947 fprintf(compiler->verbose, " * %d", 1 << (i));
949 else if (i)
950 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
951 fputc(']', compiler->verbose);
953 else
954 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
955 } else
956 sljit_verbose_reg(compiler, p);
959 static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
961 if ((p) & SLJIT_MEM) {
962 if ((p) & REG_MASK) {
963 fputc('[', compiler->verbose);
964 sljit_verbose_reg(compiler, (p) & REG_MASK);
965 if ((p) & OFFS_REG_MASK) {
966 fprintf(compiler->verbose, " + ");
967 sljit_verbose_reg(compiler, OFFS_REG(p));
968 if (i)
969 fprintf(compiler->verbose, "%d", 1 << (i));
971 else if (i)
972 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
973 fputc(']', compiler->verbose);
975 else
976 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
978 else
979 sljit_verbose_freg(compiler, p);
982 static const char* op0_names[] = {
983 "breakpoint", "nop", "lmul.uw", "lmul.sw",
984 "divmod.u", "divmod.s", "div.u", "div.s",
985 "endbr", "skip_frames_before_return"
988 static const char* op1_names[] = {
989 "", ".u8", ".s8", ".u16",
990 ".s16", ".u32", ".s32", "32",
991 ".p", "not", "clz",
994 static const char* op2_names[] = {
995 "add", "addc", "sub", "subc",
996 "mul", "and", "or", "xor",
997 "shl", "lshr", "ashr",
1000 static const char* op_src_names[] = {
1001 "fast_return", "skip_frames_before_fast_return",
1002 "prefetch_l1", "prefetch_l2",
1003 "prefetch_l3", "prefetch_once",
1006 static const char* fop1_names[] = {
1007 "mov", "conv", "conv", "conv",
1008 "conv", "conv", "cmp", "neg",
1009 "abs",
1012 static const char* fop2_names[] = {
1013 "add", "sub", "mul", "div"
1016 static const char* jump_names[] = {
1017 "equal", "not_equal",
1018 "less", "greater_equal",
1019 "greater", "less_equal",
1020 "sig_less", "sig_greater_equal",
1021 "sig_greater", "sig_less_equal",
1022 "overflow", "not_overflow",
1023 "carry", "",
1024 "f_equal", "f_not_equal",
1025 "f_less", "f_greater_equal",
1026 "f_greater", "f_less_equal",
1027 "unordered", "ordered",
1028 "ordered_equal", "unordered_or_not_equal",
1029 "ordered_less", "unordered_or_greater_equal",
1030 "ordered_greater", "unordered_or_less_equal",
1031 "unordered_or_equal", "ordered_not_equal",
1032 "unordered_or_less", "ordered_greater_equal",
1033 "unordered_or_greater", "ordered_less_equal",
1034 "jump", "fast_call",
1035 "call", "call_reg_arg"
1038 static const char* call_arg_names[] = {
1039 "void", "w", "32", "p", "f64", "f32"
1042 #endif /* SLJIT_VERBOSE */
1044 /* --------------------------------------------------------------------- */
1045 /* Arch dependent */
1046 /* --------------------------------------------------------------------- */
1048 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1049 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1051 #define SLJIT_SKIP_CHECKS(compiler) (compiler)->skip_checks = 1
1053 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
1055 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1056 struct sljit_jump *jump;
1057 #endif
1059 SLJIT_UNUSED_ARG(compiler);
1061 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1062 CHECK_ARGUMENT(compiler->size > 0);
1063 jump = compiler->jumps;
1064 while (jump) {
1065 /* All jumps have target. */
1066 CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
1067 jump = jump->next;
1069 #endif
1070 CHECK_RETURN_OK;
1073 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
1074 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1075 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1077 SLJIT_UNUSED_ARG(compiler);
1079 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1080 if (options & SLJIT_ENTER_REG_ARG) {
1081 CHECK_ARGUMENT(!(options & ~(0x3 | SLJIT_ENTER_REG_ARG)));
1082 } else {
1083 CHECK_ARGUMENT(options == 0);
1085 CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 3 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1086 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1087 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1088 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1089 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1090 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1091 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1092 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1093 CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1094 CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, (options & SLJIT_ENTER_REG_ARG) ? 0 : saveds, fscratches));
1096 compiler->last_flags = 0;
1097 #endif
1098 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1099 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1100 fprintf(compiler->verbose, " enter ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1102 arg_types >>= SLJIT_ARG_SHIFT;
1103 if (arg_types) {
1104 fprintf(compiler->verbose, "], args[");
1105 do {
1106 fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1107 (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1108 arg_types >>= SLJIT_ARG_SHIFT;
1109 if (arg_types)
1110 fprintf(compiler->verbose, ",");
1111 } while (arg_types);
1114 fprintf(compiler->verbose, "],");
1116 if (options & SLJIT_ENTER_REG_ARG) {
1117 fprintf(compiler->verbose, " enter:reg_arg,");
1119 if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1120 fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1123 fprintf(compiler->verbose, "scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1124 scratches, saveds, fscratches, fsaveds, local_size);
1126 #endif
1127 CHECK_RETURN_OK;
1130 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
1131 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1132 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1134 SLJIT_UNUSED_ARG(compiler);
1136 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1137 if (options & SLJIT_ENTER_REG_ARG) {
1138 CHECK_ARGUMENT(!(options & ~(0x3 | SLJIT_ENTER_REG_ARG)));
1139 } else {
1140 CHECK_ARGUMENT(options == 0);
1142 CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 3 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1143 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1144 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1145 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1146 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1147 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1148 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1149 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1150 CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1151 CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, (options & SLJIT_ENTER_REG_ARG) ? 0 : saveds, fscratches));
1153 compiler->last_flags = 0;
1154 #endif
1155 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1156 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1157 fprintf(compiler->verbose, " set_context ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1159 arg_types >>= SLJIT_ARG_SHIFT;
1160 if (arg_types) {
1161 fprintf(compiler->verbose, "], args[");
1162 do {
1163 fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1164 (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1165 arg_types >>= SLJIT_ARG_SHIFT;
1166 if (arg_types)
1167 fprintf(compiler->verbose, ",");
1168 } while (arg_types);
1171 fprintf(compiler->verbose, "],");
1173 if (options & SLJIT_ENTER_REG_ARG) {
1174 fprintf(compiler->verbose, " enter:reg_arg,");
1176 if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1177 fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1180 fprintf(compiler->verbose, " scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1181 scratches, saveds, fscratches, fsaveds, local_size);
1183 #endif
1184 CHECK_RETURN_OK;
1187 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_compiler *compiler)
1189 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1190 compiler->skip_checks = 0;
1191 CHECK_RETURN_OK;
1194 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1195 CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_VOID);
1196 #endif
1198 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1199 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1200 fprintf(compiler->verbose, " return_void\n");
1202 #endif
1203 CHECK_RETURN_OK;
1206 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1208 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1209 CHECK_ARGUMENT(compiler->scratches >= 0);
1211 switch (compiler->last_return) {
1212 case SLJIT_ARG_TYPE_W:
1213 CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_S32);
1214 break;
1215 case SLJIT_ARG_TYPE_32:
1216 CHECK_ARGUMENT(op == SLJIT_MOV32 || (op >= SLJIT_MOV32_U8 && op <= SLJIT_MOV32_S16));
1217 break;
1218 case SLJIT_ARG_TYPE_P:
1219 CHECK_ARGUMENT(op == SLJIT_MOV_P);
1220 break;
1221 default:
1222 /* Context not initialized, void, etc. */
1223 CHECK_ARGUMENT(0);
1224 break;
1226 FUNCTION_CHECK_SRC(src, srcw);
1227 compiler->last_flags = 0;
1228 #endif
1229 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1230 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1231 fprintf(compiler->verbose, " return%s%s ", !(op & SLJIT_32) ? "" : "32",
1232 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1233 sljit_verbose_param(compiler, src, srcw);
1234 fprintf(compiler->verbose, "\n");
1236 #endif
1237 CHECK_RETURN_OK;
1240 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1242 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1243 FUNCTION_CHECK_DST(dst, dstw);
1244 compiler->last_flags = 0;
1245 #endif
1246 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1247 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1248 fprintf(compiler->verbose, " fast_enter ");
1249 sljit_verbose_param(compiler, dst, dstw);
1250 fprintf(compiler->verbose, "\n");
1252 #endif
1253 CHECK_RETURN_OK;
1256 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1258 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1259 CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1260 || ((op & ~SLJIT_32) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_32) <= SLJIT_DIV_SW)
1261 || (op >= SLJIT_ENDBR && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN));
1262 CHECK_ARGUMENT(GET_OPCODE(op) < SLJIT_LMUL_UW || GET_OPCODE(op) >= SLJIT_ENDBR || compiler->scratches >= 2);
1263 if ((GET_OPCODE(op) >= SLJIT_LMUL_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN)
1264 compiler->last_flags = 0;
1265 #endif
1266 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1267 if (SLJIT_UNLIKELY(!!compiler->verbose))
1269 fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1270 if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) {
1271 fprintf(compiler->verbose, (op & SLJIT_32) ? "32" : "w");
1273 fprintf(compiler->verbose, "\n");
1275 #endif
1276 CHECK_RETURN_OK;
1279 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1280 sljit_s32 dst, sljit_sw dstw,
1281 sljit_s32 src, sljit_sw srcw)
1283 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1284 compiler->skip_checks = 0;
1285 CHECK_RETURN_OK;
1288 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1289 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1291 switch (GET_OPCODE(op)) {
1292 case SLJIT_NOT:
1293 /* Only SLJIT_32 and SLJIT_SET_Z are allowed. */
1294 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1295 break;
1296 case SLJIT_MOV:
1297 case SLJIT_MOV_U32:
1298 case SLJIT_MOV_P:
1299 /* Nothing allowed */
1300 CHECK_ARGUMENT(!(op & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1301 break;
1302 default:
1303 /* Only SLJIT_32 is allowed. */
1304 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1305 break;
1308 FUNCTION_CHECK_DST(dst, dstw);
1309 FUNCTION_CHECK_SRC(src, srcw);
1311 if (GET_OPCODE(op) >= SLJIT_NOT) {
1312 CHECK_ARGUMENT(src != SLJIT_IMM);
1313 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1315 #endif
1316 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1317 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1318 if (GET_OPCODE(op) <= SLJIT_MOV_P)
1320 fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_32) ? "" : "32",
1321 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1323 else
1325 fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_32) ? "" : "32",
1326 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1327 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1330 sljit_verbose_param(compiler, dst, dstw);
1331 fprintf(compiler->verbose, ", ");
1332 sljit_verbose_param(compiler, src, srcw);
1333 fprintf(compiler->verbose, "\n");
1335 #endif
1336 CHECK_RETURN_OK;
1339 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset,
1340 sljit_s32 dst, sljit_sw dstw,
1341 sljit_s32 src1, sljit_sw src1w,
1342 sljit_s32 src2, sljit_sw src2w)
1344 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1345 compiler->skip_checks = 0;
1346 CHECK_RETURN_OK;
1349 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1350 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1352 switch (GET_OPCODE(op)) {
1353 case SLJIT_AND:
1354 case SLJIT_OR:
1355 case SLJIT_XOR:
1356 case SLJIT_SHL:
1357 case SLJIT_LSHR:
1358 case SLJIT_ASHR:
1359 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1360 break;
1361 case SLJIT_MUL:
1362 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1363 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1364 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1365 break;
1366 case SLJIT_ADD:
1367 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1368 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1369 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1370 break;
1371 case SLJIT_SUB:
1372 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1373 || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1374 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1375 break;
1376 case SLJIT_ADDC:
1377 case SLJIT_SUBC:
1378 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1379 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1380 CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1381 CHECK_ARGUMENT((op & SLJIT_32) == (compiler->last_flags & SLJIT_32));
1382 break;
1383 default:
1384 SLJIT_UNREACHABLE();
1385 break;
1388 if (unset) {
1389 CHECK_ARGUMENT(HAS_FLAGS(op));
1390 } else {
1391 FUNCTION_CHECK_DST(dst, dstw);
1393 FUNCTION_CHECK_SRC(src1, src1w);
1394 FUNCTION_CHECK_SRC(src2, src2w);
1395 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1396 #endif
1397 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1398 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1399 fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32",
1400 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1401 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1402 if (unset)
1403 fprintf(compiler->verbose, "unset");
1404 else
1405 sljit_verbose_param(compiler, dst, dstw);
1406 fprintf(compiler->verbose, ", ");
1407 sljit_verbose_param(compiler, src1, src1w);
1408 fprintf(compiler->verbose, ", ");
1409 sljit_verbose_param(compiler, src2, src2w);
1410 fprintf(compiler->verbose, "\n");
1412 #endif
1413 CHECK_RETURN_OK;
1416 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
1417 sljit_s32 src, sljit_sw srcw)
1419 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1420 CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE);
1421 FUNCTION_CHECK_SRC(src, srcw);
1423 if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN)
1425 CHECK_ARGUMENT(src != SLJIT_IMM);
1426 compiler->last_flags = 0;
1428 else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE)
1430 CHECK_ARGUMENT(src & SLJIT_MEM);
1432 #endif
1433 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1434 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1435 fprintf(compiler->verbose, " %s ", op_src_names[op - SLJIT_OP_SRC_BASE]);
1436 sljit_verbose_param(compiler, src, srcw);
1437 fprintf(compiler->verbose, "\n");
1439 #endif
1440 CHECK_RETURN_OK;
1443 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1445 SLJIT_UNUSED_ARG(reg);
1446 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1447 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1448 #endif
1449 CHECK_RETURN_OK;
1452 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1454 SLJIT_UNUSED_ARG(reg);
1455 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1456 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1457 #endif
1458 CHECK_RETURN_OK;
1461 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1462 void *instruction, sljit_u32 size)
1464 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1465 sljit_u32 i;
1466 #endif
1468 SLJIT_UNUSED_ARG(compiler);
1470 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1471 CHECK_ARGUMENT(instruction);
1473 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1474 CHECK_ARGUMENT(size > 0 && size < 16);
1475 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1476 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1477 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1478 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
1479 CHECK_ARGUMENT(size == 2 || size == 4 || size == 6);
1480 #else
1481 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1482 #endif
1484 compiler->last_flags = 0;
1485 #endif
1486 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1487 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1488 fprintf(compiler->verbose, " op_custom");
1489 for (i = 0; i < size; i++)
1490 fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1491 fprintf(compiler->verbose, "\n");
1493 #endif
1494 CHECK_RETURN_OK;
1497 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1498 sljit_s32 dst, sljit_sw dstw,
1499 sljit_s32 src, sljit_sw srcw)
1501 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1502 compiler->skip_checks = 0;
1503 CHECK_RETURN_OK;
1506 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1507 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1508 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1509 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1510 FUNCTION_FCHECK(src, srcw);
1511 FUNCTION_FCHECK(dst, dstw);
1512 #endif
1513 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1514 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1515 if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1516 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1517 (op & SLJIT_32) ? ".f32.from.f64" : ".f64.from.f32");
1518 else
1519 fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1520 (op & SLJIT_32) ? ".f32" : ".f64");
1522 sljit_verbose_fparam(compiler, dst, dstw);
1523 fprintf(compiler->verbose, ", ");
1524 sljit_verbose_fparam(compiler, src, srcw);
1525 fprintf(compiler->verbose, "\n");
1527 #endif
1528 CHECK_RETURN_OK;
1531 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1532 sljit_s32 src1, sljit_sw src1w,
1533 sljit_s32 src2, sljit_sw src2w)
1535 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1536 compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32);
1537 #endif
1539 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1540 compiler->skip_checks = 0;
1541 CHECK_RETURN_OK;
1544 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1545 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1546 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1547 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1548 CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1549 || (GET_FLAG_TYPE(op) >= SLJIT_F_EQUAL && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_LESS_EQUAL));
1550 FUNCTION_FCHECK(src1, src1w);
1551 FUNCTION_FCHECK(src2, src2w);
1552 #endif
1553 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1554 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1555 fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1556 if (op & VARIABLE_FLAG_MASK) {
1557 fprintf(compiler->verbose, ".%s", jump_names[GET_FLAG_TYPE(op)]);
1559 fprintf(compiler->verbose, " ");
1560 sljit_verbose_fparam(compiler, src1, src1w);
1561 fprintf(compiler->verbose, ", ");
1562 sljit_verbose_fparam(compiler, src2, src2w);
1563 fprintf(compiler->verbose, "\n");
1565 #endif
1566 CHECK_RETURN_OK;
1569 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1570 sljit_s32 dst, sljit_sw dstw,
1571 sljit_s32 src, sljit_sw srcw)
1573 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1574 compiler->skip_checks = 0;
1575 CHECK_RETURN_OK;
1578 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1579 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1580 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1581 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1582 FUNCTION_FCHECK(src, srcw);
1583 FUNCTION_CHECK_DST(dst, dstw);
1584 #endif
1585 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1586 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1587 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1588 (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1589 (op & SLJIT_32) ? ".f32" : ".f64");
1590 sljit_verbose_param(compiler, dst, dstw);
1591 fprintf(compiler->verbose, ", ");
1592 sljit_verbose_fparam(compiler, src, srcw);
1593 fprintf(compiler->verbose, "\n");
1595 #endif
1596 CHECK_RETURN_OK;
1599 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1600 sljit_s32 dst, sljit_sw dstw,
1601 sljit_s32 src, sljit_sw srcw)
1603 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1604 compiler->skip_checks = 0;
1605 CHECK_RETURN_OK;
1608 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1609 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1610 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1611 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1612 FUNCTION_CHECK_SRC(src, srcw);
1613 FUNCTION_FCHECK(dst, dstw);
1614 #endif
1615 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1616 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1617 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1618 (op & SLJIT_32) ? ".f32" : ".f64",
1619 (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1620 sljit_verbose_fparam(compiler, dst, dstw);
1621 fprintf(compiler->verbose, ", ");
1622 sljit_verbose_param(compiler, src, srcw);
1623 fprintf(compiler->verbose, "\n");
1625 #endif
1626 CHECK_RETURN_OK;
1629 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1630 sljit_s32 dst, sljit_sw dstw,
1631 sljit_s32 src1, sljit_sw src1w,
1632 sljit_s32 src2, sljit_sw src2w)
1634 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1635 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1636 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1637 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1638 FUNCTION_FCHECK(src1, src1w);
1639 FUNCTION_FCHECK(src2, src2w);
1640 FUNCTION_FCHECK(dst, dstw);
1641 #endif
1642 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1643 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1644 fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1645 sljit_verbose_fparam(compiler, dst, dstw);
1646 fprintf(compiler->verbose, ", ");
1647 sljit_verbose_fparam(compiler, src1, src1w);
1648 fprintf(compiler->verbose, ", ");
1649 sljit_verbose_fparam(compiler, src2, src2w);
1650 fprintf(compiler->verbose, "\n");
1652 #endif
1653 CHECK_RETURN_OK;
1656 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1658 SLJIT_UNUSED_ARG(compiler);
1660 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1661 compiler->skip_checks = 0;
1662 CHECK_RETURN_OK;
1665 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1666 compiler->last_flags = 0;
1667 #endif
1669 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1670 if (SLJIT_UNLIKELY(!!compiler->verbose))
1671 fprintf(compiler->verbose, "label:\n");
1672 #endif
1673 CHECK_RETURN_OK;
1676 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1677 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
1678 || (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1679 #define CHECK_UNORDERED(type, last_flags) \
1680 ((((type) & 0xff) == SLJIT_UNORDERED || ((type) & 0xff) == SLJIT_ORDERED) && \
1681 ((last_flags) & 0xff) >= SLJIT_UNORDERED && ((last_flags) & 0xff) <= SLJIT_ORDERED_LESS_EQUAL)
1682 #else
1683 #define CHECK_UNORDERED(type, last_flags) 0
1684 #endif
1685 #endif /* SLJIT_ARGUMENT_CHECKS */
1687 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1689 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1690 compiler->skip_checks = 0;
1691 CHECK_RETURN_OK;
1694 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1695 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1696 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
1698 if ((type & 0xff) < SLJIT_JUMP) {
1699 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1700 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1701 else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) {
1702 CHECK_ARGUMENT((type & 0xff) == SLJIT_CARRY || (type & 0xff) == SLJIT_NOT_CARRY);
1703 compiler->last_flags = 0;
1704 } else
1705 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1706 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1707 || CHECK_UNORDERED(type, compiler->last_flags));
1709 #endif
1710 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1711 if (SLJIT_UNLIKELY(!!compiler->verbose))
1712 fprintf(compiler->verbose, " jump%s %s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1713 jump_names[type & 0xff]);
1714 #endif
1715 CHECK_RETURN_OK;
1718 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
1719 sljit_s32 arg_types)
1721 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1722 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_CALL_RETURN)));
1723 CHECK_ARGUMENT((type & 0xff) >= SLJIT_CALL && (type & 0xff) <= SLJIT_CALL_REG_ARG);
1724 CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1726 if (type & SLJIT_CALL_RETURN) {
1727 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1729 if (compiler->options & SLJIT_ENTER_REG_ARG) {
1730 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL_REG_ARG);
1731 } else {
1732 CHECK_ARGUMENT((type & 0xff) != SLJIT_CALL_REG_ARG);
1735 #endif
1736 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1737 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1738 fprintf(compiler->verbose, " %s%s%s ret[%s", jump_names[type & 0xff],
1739 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1740 !(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1741 call_arg_names[arg_types & SLJIT_ARG_MASK]);
1743 arg_types >>= SLJIT_ARG_SHIFT;
1744 if (arg_types) {
1745 fprintf(compiler->verbose, "], args[");
1746 do {
1747 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1748 arg_types >>= SLJIT_ARG_SHIFT;
1749 if (arg_types)
1750 fprintf(compiler->verbose, ",");
1751 } while (arg_types);
1753 fprintf(compiler->verbose, "]\n");
1755 #endif
1756 CHECK_RETURN_OK;
1759 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1760 sljit_s32 src1, sljit_sw src1w,
1761 sljit_s32 src2, sljit_sw src2w)
1763 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1764 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1765 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1766 FUNCTION_CHECK_SRC(src1, src1w);
1767 FUNCTION_CHECK_SRC(src2, src2w);
1768 compiler->last_flags = 0;
1769 #endif
1770 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1771 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1772 fprintf(compiler->verbose, " cmp%s%s %s, ", (type & SLJIT_32) ? "32" : "",
1773 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1774 sljit_verbose_param(compiler, src1, src1w);
1775 fprintf(compiler->verbose, ", ");
1776 sljit_verbose_param(compiler, src2, src2w);
1777 fprintf(compiler->verbose, "\n");
1779 #endif
1780 CHECK_RETURN_OK;
1783 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1784 sljit_s32 src1, sljit_sw src1w,
1785 sljit_s32 src2, sljit_sw src2w)
1787 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1788 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1789 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1790 CHECK_ARGUMENT((type & 0xff) >= SLJIT_F_EQUAL && (type & 0xff) <= SLJIT_ORDERED_LESS_EQUAL
1791 && ((type & 0xff) <= SLJIT_ORDERED || sljit_cmp_info(type & 0xff)));
1792 FUNCTION_FCHECK(src1, src1w);
1793 FUNCTION_FCHECK(src2, src2w);
1794 compiler->last_flags = 0;
1795 #endif
1796 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1797 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1798 fprintf(compiler->verbose, " fcmp%s%s %s, ", (type & SLJIT_32) ? ".f32" : ".f64",
1799 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1800 sljit_verbose_fparam(compiler, src1, src1w);
1801 fprintf(compiler->verbose, ", ");
1802 sljit_verbose_fparam(compiler, src2, src2w);
1803 fprintf(compiler->verbose, "\n");
1805 #endif
1806 CHECK_RETURN_OK;
1809 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
1810 sljit_s32 src, sljit_sw srcw)
1812 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1813 compiler->skip_checks = 0;
1814 CHECK_RETURN_OK;
1817 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1818 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
1819 FUNCTION_CHECK_SRC(src, srcw);
1820 #endif
1821 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1822 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1823 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1824 sljit_verbose_param(compiler, src, srcw);
1825 fprintf(compiler->verbose, "\n");
1827 #endif
1828 CHECK_RETURN_OK;
1831 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
1832 sljit_s32 arg_types,
1833 sljit_s32 src, sljit_sw srcw)
1835 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1836 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_CALL_RETURN)));
1837 CHECK_ARGUMENT((type & 0xff) >= SLJIT_CALL && (type & 0xff) <= SLJIT_CALL_REG_ARG);
1838 CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1839 FUNCTION_CHECK_SRC(src, srcw);
1841 if (type & SLJIT_CALL_RETURN) {
1842 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1844 if (compiler->options & SLJIT_ENTER_REG_ARG) {
1845 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL_REG_ARG);
1846 } else {
1847 CHECK_ARGUMENT((type & 0xff) != SLJIT_CALL_REG_ARG);
1850 #endif
1851 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1852 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1853 fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff],
1854 !(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1855 call_arg_names[arg_types & SLJIT_ARG_MASK]);
1857 arg_types >>= SLJIT_ARG_SHIFT;
1858 if (arg_types) {
1859 fprintf(compiler->verbose, "], args[");
1860 do {
1861 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1862 arg_types >>= SLJIT_ARG_SHIFT;
1863 if (arg_types)
1864 fprintf(compiler->verbose, ",");
1865 } while (arg_types);
1867 fprintf(compiler->verbose, "], ");
1868 sljit_verbose_param(compiler, src, srcw);
1869 fprintf(compiler->verbose, "\n");
1871 #endif
1872 CHECK_RETURN_OK;
1875 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1876 sljit_s32 dst, sljit_sw dstw,
1877 sljit_s32 type)
1879 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1880 CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1881 CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1882 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1883 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1885 if (type <= SLJIT_NOT_ZERO)
1886 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1887 else
1888 CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1889 || (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1890 || (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1891 || CHECK_UNORDERED(type, compiler->last_flags));
1893 FUNCTION_CHECK_DST(dst, dstw);
1895 if (GET_OPCODE(op) >= SLJIT_ADD)
1896 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1897 #endif
1898 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1899 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1900 fprintf(compiler->verbose, " flags.%s%s%s ",
1901 GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1902 GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_32) ? "32" : ""),
1903 !(op & SLJIT_SET_Z) ? "" : ".z");
1904 sljit_verbose_param(compiler, dst, dstw);
1905 fprintf(compiler->verbose, ", %s\n", jump_names[type]);
1907 #endif
1908 CHECK_RETURN_OK;
1911 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1912 sljit_s32 dst_reg,
1913 sljit_s32 src, sljit_sw srcw)
1915 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1916 CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1918 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
1919 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_32));
1920 if (src != SLJIT_IMM) {
1921 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
1922 CHECK_ARGUMENT(srcw == 0);
1925 if (type <= SLJIT_NOT_ZERO)
1926 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1927 else
1928 CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1929 || (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1930 || (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1931 || CHECK_UNORDERED(type, compiler->last_flags));
1932 #endif
1933 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1934 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1935 fprintf(compiler->verbose, " cmov%s %s, ",
1936 !(dst_reg & SLJIT_32) ? "" : "32",
1937 jump_names[type]);
1938 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_32);
1939 fprintf(compiler->verbose, ", ");
1940 sljit_verbose_param(compiler, src, srcw);
1941 fprintf(compiler->verbose, "\n");
1943 #endif
1944 CHECK_RETURN_OK;
1947 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
1948 sljit_s32 reg,
1949 sljit_s32 mem, sljit_sw memw)
1951 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1952 sljit_s32 allowed_flags;
1954 CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
1955 CHECK_ARGUMENT(!(type & SLJIT_32) || ((type & 0xff) >= SLJIT_MOV_U8 && (type & 0xff) <= SLJIT_MOV_S16));
1957 if (type & SLJIT_MEM_UNALIGNED) {
1958 allowed_flags = SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32;
1960 switch (type & 0xff) {
1961 case SLJIT_MOV_U8:
1962 case SLJIT_MOV_S8:
1963 case SLJIT_MOV_U16:
1964 case SLJIT_MOV_S16:
1965 allowed_flags = 0;
1966 break;
1967 case SLJIT_MOV_U32:
1968 case SLJIT_MOV_S32:
1969 case SLJIT_MOV32:
1970 allowed_flags = SLJIT_MEM_ALIGNED_16;
1971 break;
1973 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_UNALIGNED | allowed_flags)) == 0);
1974 CHECK_ARGUMENT((type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32)) != (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32));
1975 } else {
1976 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1977 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1978 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1979 CHECK_ARGUMENT((mem & REG_MASK) != 0 && (mem & REG_MASK) != reg);
1982 FUNCTION_CHECK_SRC_MEM(mem, memw);
1983 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
1984 #endif
1985 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1986 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1987 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) {
1988 if (type & SLJIT_MEM_SUPP)
1989 CHECK_RETURN_OK;
1990 if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED) {
1991 fprintf(compiler->verbose, " // mem: unsupported form, no instructions are emitted");
1992 CHECK_RETURN_OK;
1996 if ((type & 0xff) == SLJIT_MOV32)
1997 fprintf(compiler->verbose, " mem32.%s",
1998 (type & SLJIT_MEM_STORE) ? "st" : "ld");
1999 else
2000 fprintf(compiler->verbose, " mem%s.%s%s",
2001 !(type & SLJIT_32) ? "" : "32",
2002 (type & SLJIT_MEM_STORE) ? "st" : "ld",
2003 op1_names[(type & 0xff) - SLJIT_OP1_BASE]);
2005 if (type & SLJIT_MEM_UNALIGNED) {
2006 printf(".un%s%s ", (type & SLJIT_MEM_ALIGNED_16) ? ".16" : "", (type & SLJIT_MEM_ALIGNED_32) ? ".32" : "");
2007 } else
2008 printf((type & SLJIT_MEM_PRE) ? ".pre " : ".post ");
2009 sljit_verbose_reg(compiler, reg);
2010 fprintf(compiler->verbose, ", ");
2011 sljit_verbose_param(compiler, mem, memw);
2012 fprintf(compiler->verbose, "\n");
2014 #endif
2015 CHECK_RETURN_OK;
2018 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2019 sljit_s32 freg,
2020 sljit_s32 mem, sljit_sw memw)
2022 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2023 CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
2024 if (type & SLJIT_MEM_UNALIGNED) {
2025 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_UNALIGNED | SLJIT_MEM_ALIGNED_16 | (type & SLJIT_32 ? 0 : SLJIT_MEM_ALIGNED_32))) == 0);
2026 CHECK_ARGUMENT((type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32)) != (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32));
2027 } else {
2028 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
2029 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
2030 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
2033 FUNCTION_CHECK_SRC_MEM(mem, memw);
2034 CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
2035 #endif
2036 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2037 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2038 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) {
2039 if (type & SLJIT_MEM_SUPP)
2040 CHECK_RETURN_OK;
2041 if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED) {
2042 fprintf(compiler->verbose, " // fmem: unsupported form, no instructions are emitted");
2043 CHECK_RETURN_OK;
2047 fprintf(compiler->verbose, " fmem.%s%s",
2048 (type & SLJIT_MEM_STORE) ? "st" : "ld",
2049 !(type & SLJIT_32) ? ".f64" : ".f32");
2051 if (type & SLJIT_MEM_UNALIGNED) {
2052 printf(".un%s%s ", (type & SLJIT_MEM_ALIGNED_16) ? ".16" : "", (type & SLJIT_MEM_ALIGNED_32) ? ".32" : "");
2053 } else
2054 printf((type & SLJIT_MEM_PRE) ? ".pre " : ".post ");
2055 sljit_verbose_freg(compiler, freg);
2056 fprintf(compiler->verbose, ", ");
2057 sljit_verbose_param(compiler, mem, memw);
2058 fprintf(compiler->verbose, "\n");
2060 #endif
2061 CHECK_RETURN_OK;
2064 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2066 /* Any offset is allowed. */
2067 SLJIT_UNUSED_ARG(offset);
2069 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2070 FUNCTION_CHECK_DST(dst, dstw);
2071 #endif
2072 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2073 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2074 fprintf(compiler->verbose, " local_base ");
2075 sljit_verbose_param(compiler, dst, dstw);
2076 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
2078 #endif
2079 CHECK_RETURN_OK;
2082 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
2084 SLJIT_UNUSED_ARG(init_value);
2086 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2087 FUNCTION_CHECK_DST(dst, dstw);
2088 #endif
2089 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2090 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2091 fprintf(compiler->verbose, " const ");
2092 sljit_verbose_param(compiler, dst, dstw);
2093 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
2095 #endif
2096 CHECK_RETURN_OK;
2099 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2101 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2102 FUNCTION_CHECK_DST(dst, dstw);
2103 #endif
2104 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2105 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2106 fprintf(compiler->verbose, " put_label ");
2107 sljit_verbose_param(compiler, dst, dstw);
2108 fprintf(compiler->verbose, "\n");
2110 #endif
2111 CHECK_RETURN_OK;
2114 #else /* !SLJIT_ARGUMENT_CHECKS && !SLJIT_VERBOSE */
2116 #define SLJIT_SKIP_CHECKS(compiler)
2118 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
2120 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
2121 SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
2122 invalid_float_opcodes); \
2123 if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
2124 if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
2125 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
2126 ADJUST_LOCAL_OFFSET(dst, dstw); \
2127 ADJUST_LOCAL_OFFSET(src, srcw); \
2128 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
2130 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
2131 CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
2132 ADJUST_LOCAL_OFFSET(dst, dstw); \
2133 ADJUST_LOCAL_OFFSET(src, srcw); \
2134 return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
2136 CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
2137 ADJUST_LOCAL_OFFSET(dst, dstw); \
2138 ADJUST_LOCAL_OFFSET(src, srcw); \
2139 return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
2141 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
2142 ADJUST_LOCAL_OFFSET(dst, dstw); \
2143 ADJUST_LOCAL_OFFSET(src, srcw);
2145 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2147 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2148 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
2149 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
2150 return SLJIT_SUCCESS;
2151 #else
2152 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
2153 return SLJIT_SUCCESS;
2154 #endif
2156 SLJIT_SKIP_CHECKS(compiler);
2157 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
2160 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2162 CHECK_ERROR();
2163 CHECK(check_sljit_emit_return(compiler, op, src, srcw));
2165 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
2167 SLJIT_SKIP_CHECKS(compiler);
2168 return sljit_emit_return_void(compiler);
2171 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2172 || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
2173 || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6)) \
2174 || (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2176 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
2177 sljit_s32 dst_reg,
2178 sljit_s32 src, sljit_sw srcw)
2180 struct sljit_label *label;
2181 struct sljit_jump *jump;
2182 sljit_s32 op = (dst_reg & SLJIT_32) ? SLJIT_MOV32 : SLJIT_MOV;
2184 SLJIT_SKIP_CHECKS(compiler);
2185 jump = sljit_emit_jump(compiler, type ^ 0x1);
2186 FAIL_IF(!jump);
2188 SLJIT_SKIP_CHECKS(compiler);
2189 FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_32, 0, src, srcw));
2191 SLJIT_SKIP_CHECKS(compiler);
2192 label = sljit_emit_label(compiler);
2193 FAIL_IF(!label);
2195 sljit_set_label(jump, label);
2196 return SLJIT_SUCCESS;
2199 #endif
2201 #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \
2202 && !(defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2204 static sljit_s32 sljit_emit_mem_unaligned(struct sljit_compiler *compiler, sljit_s32 type,
2205 sljit_s32 reg,
2206 sljit_s32 mem, sljit_sw memw)
2208 SLJIT_SKIP_CHECKS(compiler);
2210 if (type & SLJIT_MEM_STORE)
2211 return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), mem, memw, reg, 0);
2212 return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), reg, 0, mem, memw);
2215 #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM_V5 */
2217 #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \
2218 && !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
2220 static sljit_s32 sljit_emit_fmem_unaligned(struct sljit_compiler *compiler, sljit_s32 type,
2221 sljit_s32 freg,
2222 sljit_s32 mem, sljit_sw memw)
2224 SLJIT_SKIP_CHECKS(compiler);
2226 if (type & SLJIT_MEM_STORE)
2227 return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), mem, memw, freg, 0);
2228 return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), freg, 0, mem, memw);
2231 #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM */
2233 /* CPU description section */
2235 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
2236 #define SLJIT_CPUINFO_PART1 " 32bit ("
2237 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2238 #define SLJIT_CPUINFO_PART1 " 64bit ("
2239 #else
2240 #error "Internal error: CPU type info missing"
2241 #endif
2243 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
2244 #define SLJIT_CPUINFO_PART2 "little endian + "
2245 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
2246 #define SLJIT_CPUINFO_PART2 "big endian + "
2247 #else
2248 #error "Internal error: CPU type info missing"
2249 #endif
2251 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
2252 #define SLJIT_CPUINFO_PART3 "unaligned)"
2253 #else
2254 #define SLJIT_CPUINFO_PART3 "aligned)"
2255 #endif
2257 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
2259 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
2260 # include "sljitNativeX86_common.c"
2261 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2262 # include "sljitNativeARM_32.c"
2263 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
2264 # include "sljitNativeARM_32.c"
2265 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
2266 # include "sljitNativeARM_T2_32.c"
2267 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2268 # include "sljitNativeARM_64.c"
2269 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2270 # include "sljitNativePPC_common.c"
2271 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2272 # include "sljitNativeMIPS_common.c"
2273 #elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2274 # include "sljitNativeRISCV_common.c"
2275 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
2276 # include "sljitNativeS390X.c"
2277 #endif
2279 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2280 && !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2282 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2283 sljit_s32 src1, sljit_sw src1w,
2284 sljit_s32 src2, sljit_sw src2w)
2286 /* Default compare for most architectures. */
2287 sljit_s32 flags, tmp_src, condition;
2288 sljit_sw tmp_srcw;
2290 CHECK_ERROR_PTR();
2291 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
2293 condition = type & 0xff;
2294 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2295 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
2296 if ((src1 & SLJIT_IMM) && !src1w) {
2297 src1 = src2;
2298 src1w = src2w;
2299 src2 = SLJIT_IMM;
2300 src2w = 0;
2302 if ((src2 & SLJIT_IMM) && !src2w)
2303 return emit_cmp_to0(compiler, type, src1, src1w);
2305 #endif
2307 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
2308 /* Immediate is preferred as second argument by most architectures. */
2309 switch (condition) {
2310 case SLJIT_LESS:
2311 condition = SLJIT_GREATER;
2312 break;
2313 case SLJIT_GREATER_EQUAL:
2314 condition = SLJIT_LESS_EQUAL;
2315 break;
2316 case SLJIT_GREATER:
2317 condition = SLJIT_LESS;
2318 break;
2319 case SLJIT_LESS_EQUAL:
2320 condition = SLJIT_GREATER_EQUAL;
2321 break;
2322 case SLJIT_SIG_LESS:
2323 condition = SLJIT_SIG_GREATER;
2324 break;
2325 case SLJIT_SIG_GREATER_EQUAL:
2326 condition = SLJIT_SIG_LESS_EQUAL;
2327 break;
2328 case SLJIT_SIG_GREATER:
2329 condition = SLJIT_SIG_LESS;
2330 break;
2331 case SLJIT_SIG_LESS_EQUAL:
2332 condition = SLJIT_SIG_GREATER_EQUAL;
2333 break;
2336 type = condition | (type & (SLJIT_32 | SLJIT_REWRITABLE_JUMP));
2337 tmp_src = src1;
2338 src1 = src2;
2339 src2 = tmp_src;
2340 tmp_srcw = src1w;
2341 src1w = src2w;
2342 src2w = tmp_srcw;
2345 if (condition <= SLJIT_NOT_ZERO)
2346 flags = SLJIT_SET_Z;
2347 else
2348 flags = condition << VARIABLE_FLAG_SHIFT;
2350 SLJIT_SKIP_CHECKS(compiler);
2351 PTR_FAIL_IF(sljit_emit_op2u(compiler,
2352 SLJIT_SUB | flags | (type & SLJIT_32), src1, src1w, src2, src2w));
2354 SLJIT_SKIP_CHECKS(compiler);
2355 return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_32)));
2358 #endif /* !SLJIT_CONFIG_MIPS */
2360 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
2362 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2364 if (type < SLJIT_UNORDERED || type > SLJIT_ORDERED_LESS_EQUAL)
2365 return 0;
2367 switch (type) {
2368 case SLJIT_UNORDERED_OR_EQUAL:
2369 case SLJIT_ORDERED_NOT_EQUAL:
2370 return 0;
2373 return 1;
2376 #endif /* SLJIT_CONFIG_ARM */
2378 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2379 sljit_s32 src1, sljit_sw src1w,
2380 sljit_s32 src2, sljit_sw src2w)
2382 CHECK_ERROR_PTR();
2383 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
2385 SLJIT_SKIP_CHECKS(compiler);
2386 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_32), src1, src1w, src2, src2w);
2388 SLJIT_SKIP_CHECKS(compiler);
2389 return sljit_emit_jump(compiler, type);
2392 #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \
2393 && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2394 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2396 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
2397 sljit_s32 reg,
2398 sljit_s32 mem, sljit_sw memw)
2400 CHECK_ERROR();
2401 CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw));
2403 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST))
2404 return SLJIT_ERR_UNSUPPORTED;
2406 return sljit_emit_mem_unaligned(compiler, type, reg, mem, memw);
2409 #endif
2411 #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \
2412 && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2413 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2415 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2416 sljit_s32 freg,
2417 sljit_s32 mem, sljit_sw memw)
2419 CHECK_ERROR();
2420 CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
2422 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST))
2423 return SLJIT_ERR_UNSUPPORTED;
2425 return sljit_emit_fmem_unaligned(compiler, type, freg, mem, memw);
2428 #endif
2430 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2431 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2433 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2435 CHECK_ERROR();
2436 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2438 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
2440 SLJIT_SKIP_CHECKS(compiler);
2442 if (offset != 0)
2443 return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2444 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
2447 #endif
2449 #else /* SLJIT_CONFIG_UNSUPPORTED */
2451 /* Empty function bodies for those machines, which are not (yet) supported. */
2453 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2455 return "unsupported";
2458 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
2460 SLJIT_UNUSED_ARG(allocator_data);
2461 SLJIT_UNUSED_ARG(exec_allocator_data);
2462 SLJIT_UNREACHABLE();
2463 return NULL;
2466 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
2468 SLJIT_UNUSED_ARG(compiler);
2469 SLJIT_UNREACHABLE();
2472 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
2474 SLJIT_UNUSED_ARG(compiler);
2475 SLJIT_UNREACHABLE();
2478 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
2480 SLJIT_UNUSED_ARG(compiler);
2481 SLJIT_UNUSED_ARG(size);
2482 SLJIT_UNREACHABLE();
2483 return NULL;
2486 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2487 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
2489 SLJIT_UNUSED_ARG(compiler);
2490 SLJIT_UNUSED_ARG(verbose);
2491 SLJIT_UNREACHABLE();
2493 #endif
2495 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
2497 SLJIT_UNUSED_ARG(compiler);
2498 SLJIT_UNREACHABLE();
2499 return NULL;
2502 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
2504 SLJIT_UNUSED_ARG(feature_type);
2505 SLJIT_UNREACHABLE();
2506 return 0;
2509 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2511 SLJIT_UNUSED_ARG(type);
2512 SLJIT_UNREACHABLE();
2513 return 0;
2516 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
2518 SLJIT_UNUSED_ARG(code);
2519 SLJIT_UNUSED_ARG(exec_allocator_data);
2520 SLJIT_UNREACHABLE();
2523 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
2524 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2525 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2527 SLJIT_UNUSED_ARG(compiler);
2528 SLJIT_UNUSED_ARG(options);
2529 SLJIT_UNUSED_ARG(arg_types);
2530 SLJIT_UNUSED_ARG(scratches);
2531 SLJIT_UNUSED_ARG(saveds);
2532 SLJIT_UNUSED_ARG(fscratches);
2533 SLJIT_UNUSED_ARG(fsaveds);
2534 SLJIT_UNUSED_ARG(local_size);
2535 SLJIT_UNREACHABLE();
2536 return SLJIT_ERR_UNSUPPORTED;
2539 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
2540 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2541 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2543 SLJIT_UNUSED_ARG(compiler);
2544 SLJIT_UNUSED_ARG(options);
2545 SLJIT_UNUSED_ARG(arg_types);
2546 SLJIT_UNUSED_ARG(scratches);
2547 SLJIT_UNUSED_ARG(saveds);
2548 SLJIT_UNUSED_ARG(fscratches);
2549 SLJIT_UNUSED_ARG(fsaveds);
2550 SLJIT_UNUSED_ARG(local_size);
2551 SLJIT_UNREACHABLE();
2552 return SLJIT_ERR_UNSUPPORTED;
2555 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2557 SLJIT_UNUSED_ARG(compiler);
2558 SLJIT_UNUSED_ARG(op);
2559 SLJIT_UNUSED_ARG(src);
2560 SLJIT_UNUSED_ARG(srcw);
2561 SLJIT_UNREACHABLE();
2562 return SLJIT_ERR_UNSUPPORTED;
2565 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler)
2567 SLJIT_UNUSED_ARG(compiler);
2568 SLJIT_UNREACHABLE();
2569 return SLJIT_ERR_UNSUPPORTED;
2572 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2574 SLJIT_UNUSED_ARG(compiler);
2575 SLJIT_UNUSED_ARG(dst);
2576 SLJIT_UNUSED_ARG(dstw);
2577 SLJIT_UNREACHABLE();
2578 return SLJIT_ERR_UNSUPPORTED;
2581 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2583 SLJIT_UNUSED_ARG(compiler);
2584 SLJIT_UNUSED_ARG(op);
2585 SLJIT_UNREACHABLE();
2586 return SLJIT_ERR_UNSUPPORTED;
2589 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2590 sljit_s32 dst, sljit_sw dstw,
2591 sljit_s32 src, sljit_sw srcw)
2593 SLJIT_UNUSED_ARG(compiler);
2594 SLJIT_UNUSED_ARG(op);
2595 SLJIT_UNUSED_ARG(dst);
2596 SLJIT_UNUSED_ARG(dstw);
2597 SLJIT_UNUSED_ARG(src);
2598 SLJIT_UNUSED_ARG(srcw);
2599 SLJIT_UNREACHABLE();
2600 return SLJIT_ERR_UNSUPPORTED;
2603 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2604 sljit_s32 dst, sljit_sw dstw,
2605 sljit_s32 src1, sljit_sw src1w,
2606 sljit_s32 src2, sljit_sw src2w)
2608 SLJIT_UNUSED_ARG(compiler);
2609 SLJIT_UNUSED_ARG(op);
2610 SLJIT_UNUSED_ARG(dst);
2611 SLJIT_UNUSED_ARG(dstw);
2612 SLJIT_UNUSED_ARG(src1);
2613 SLJIT_UNUSED_ARG(src1w);
2614 SLJIT_UNUSED_ARG(src2);
2615 SLJIT_UNUSED_ARG(src2w);
2616 SLJIT_UNREACHABLE();
2617 return SLJIT_ERR_UNSUPPORTED;
2620 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,
2621 sljit_s32 src1, sljit_sw src1w,
2622 sljit_s32 src2, sljit_sw src2w)
2624 SLJIT_UNUSED_ARG(compiler);
2625 SLJIT_UNUSED_ARG(op);
2626 SLJIT_UNUSED_ARG(src1);
2627 SLJIT_UNUSED_ARG(src1w);
2628 SLJIT_UNUSED_ARG(src2);
2629 SLJIT_UNUSED_ARG(src2w);
2630 SLJIT_UNREACHABLE();
2631 return SLJIT_ERR_UNSUPPORTED;
2634 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
2635 sljit_s32 src, sljit_sw srcw)
2637 SLJIT_UNUSED_ARG(compiler);
2638 SLJIT_UNUSED_ARG(op);
2639 SLJIT_UNUSED_ARG(src);
2640 SLJIT_UNUSED_ARG(srcw);
2641 SLJIT_UNREACHABLE();
2642 return SLJIT_ERR_UNSUPPORTED;
2645 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2647 SLJIT_UNREACHABLE();
2648 return reg;
2651 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2652 void *instruction, sljit_u32 size)
2654 SLJIT_UNUSED_ARG(compiler);
2655 SLJIT_UNUSED_ARG(instruction);
2656 SLJIT_UNUSED_ARG(size);
2657 SLJIT_UNREACHABLE();
2658 return SLJIT_ERR_UNSUPPORTED;
2661 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2663 SLJIT_UNUSED_ARG(compiler);
2664 SLJIT_UNUSED_ARG(current_flags);
2667 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2668 sljit_s32 dst, sljit_sw dstw,
2669 sljit_s32 src, sljit_sw srcw)
2671 SLJIT_UNUSED_ARG(compiler);
2672 SLJIT_UNUSED_ARG(op);
2673 SLJIT_UNUSED_ARG(dst);
2674 SLJIT_UNUSED_ARG(dstw);
2675 SLJIT_UNUSED_ARG(src);
2676 SLJIT_UNUSED_ARG(srcw);
2677 SLJIT_UNREACHABLE();
2678 return SLJIT_ERR_UNSUPPORTED;
2681 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2682 sljit_s32 dst, sljit_sw dstw,
2683 sljit_s32 src1, sljit_sw src1w,
2684 sljit_s32 src2, sljit_sw src2w)
2686 SLJIT_UNUSED_ARG(compiler);
2687 SLJIT_UNUSED_ARG(op);
2688 SLJIT_UNUSED_ARG(dst);
2689 SLJIT_UNUSED_ARG(dstw);
2690 SLJIT_UNUSED_ARG(src1);
2691 SLJIT_UNUSED_ARG(src1w);
2692 SLJIT_UNUSED_ARG(src2);
2693 SLJIT_UNUSED_ARG(src2w);
2694 SLJIT_UNREACHABLE();
2695 return SLJIT_ERR_UNSUPPORTED;
2698 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2700 SLJIT_UNUSED_ARG(compiler);
2701 SLJIT_UNREACHABLE();
2702 return NULL;
2705 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2707 SLJIT_UNUSED_ARG(compiler);
2708 SLJIT_UNUSED_ARG(type);
2709 SLJIT_UNREACHABLE();
2710 return NULL;
2713 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
2714 sljit_s32 arg_types)
2716 SLJIT_UNUSED_ARG(compiler);
2717 SLJIT_UNUSED_ARG(type);
2718 SLJIT_UNUSED_ARG(arg_types);
2719 SLJIT_UNREACHABLE();
2720 return NULL;
2723 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2724 sljit_s32 src1, sljit_sw src1w,
2725 sljit_s32 src2, sljit_sw src2w)
2727 SLJIT_UNUSED_ARG(compiler);
2728 SLJIT_UNUSED_ARG(type);
2729 SLJIT_UNUSED_ARG(src1);
2730 SLJIT_UNUSED_ARG(src1w);
2731 SLJIT_UNUSED_ARG(src2);
2732 SLJIT_UNUSED_ARG(src2w);
2733 SLJIT_UNREACHABLE();
2734 return NULL;
2737 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2738 sljit_s32 src1, sljit_sw src1w,
2739 sljit_s32 src2, sljit_sw src2w)
2741 SLJIT_UNUSED_ARG(compiler);
2742 SLJIT_UNUSED_ARG(type);
2743 SLJIT_UNUSED_ARG(src1);
2744 SLJIT_UNUSED_ARG(src1w);
2745 SLJIT_UNUSED_ARG(src2);
2746 SLJIT_UNUSED_ARG(src2w);
2747 SLJIT_UNREACHABLE();
2748 return NULL;
2751 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2753 SLJIT_UNUSED_ARG(jump);
2754 SLJIT_UNUSED_ARG(label);
2755 SLJIT_UNREACHABLE();
2758 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2760 SLJIT_UNUSED_ARG(jump);
2761 SLJIT_UNUSED_ARG(target);
2762 SLJIT_UNREACHABLE();
2765 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
2767 SLJIT_UNUSED_ARG(put_label);
2768 SLJIT_UNUSED_ARG(label);
2769 SLJIT_UNREACHABLE();
2772 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2774 SLJIT_UNUSED_ARG(compiler);
2775 SLJIT_UNUSED_ARG(type);
2776 SLJIT_UNUSED_ARG(src);
2777 SLJIT_UNUSED_ARG(srcw);
2778 SLJIT_UNREACHABLE();
2779 return SLJIT_ERR_UNSUPPORTED;
2782 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
2783 sljit_s32 arg_types,
2784 sljit_s32 src, sljit_sw srcw)
2786 SLJIT_UNUSED_ARG(compiler);
2787 SLJIT_UNUSED_ARG(type);
2788 SLJIT_UNUSED_ARG(arg_types);
2789 SLJIT_UNUSED_ARG(src);
2790 SLJIT_UNUSED_ARG(srcw);
2791 SLJIT_UNREACHABLE();
2792 return SLJIT_ERR_UNSUPPORTED;
2795 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2796 sljit_s32 dst, sljit_sw dstw,
2797 sljit_s32 type)
2799 SLJIT_UNUSED_ARG(compiler);
2800 SLJIT_UNUSED_ARG(op);
2801 SLJIT_UNUSED_ARG(dst);
2802 SLJIT_UNUSED_ARG(dstw);
2803 SLJIT_UNUSED_ARG(type);
2804 SLJIT_UNREACHABLE();
2805 return SLJIT_ERR_UNSUPPORTED;
2808 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
2809 sljit_s32 dst_reg,
2810 sljit_s32 src, sljit_sw srcw)
2812 SLJIT_UNUSED_ARG(compiler);
2813 SLJIT_UNUSED_ARG(type);
2814 SLJIT_UNUSED_ARG(dst_reg);
2815 SLJIT_UNUSED_ARG(src);
2816 SLJIT_UNUSED_ARG(srcw);
2817 SLJIT_UNREACHABLE();
2818 return SLJIT_ERR_UNSUPPORTED;
2821 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 reg, sljit_s32 mem, sljit_sw memw)
2823 SLJIT_UNUSED_ARG(compiler);
2824 SLJIT_UNUSED_ARG(type);
2825 SLJIT_UNUSED_ARG(reg);
2826 SLJIT_UNUSED_ARG(mem);
2827 SLJIT_UNUSED_ARG(memw);
2828 SLJIT_UNREACHABLE();
2829 return SLJIT_ERR_UNSUPPORTED;
2832 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 freg, sljit_s32 mem, sljit_sw memw)
2834 SLJIT_UNUSED_ARG(compiler);
2835 SLJIT_UNUSED_ARG(type);
2836 SLJIT_UNUSED_ARG(freg);
2837 SLJIT_UNUSED_ARG(mem);
2838 SLJIT_UNUSED_ARG(memw);
2839 SLJIT_UNREACHABLE();
2840 return SLJIT_ERR_UNSUPPORTED;
2843 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2845 SLJIT_UNUSED_ARG(compiler);
2846 SLJIT_UNUSED_ARG(dst);
2847 SLJIT_UNUSED_ARG(dstw);
2848 SLJIT_UNUSED_ARG(offset);
2849 SLJIT_UNREACHABLE();
2850 return SLJIT_ERR_UNSUPPORTED;
2853 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2855 SLJIT_UNUSED_ARG(compiler);
2856 SLJIT_UNUSED_ARG(dst);
2857 SLJIT_UNUSED_ARG(dstw);
2858 SLJIT_UNUSED_ARG(initval);
2859 SLJIT_UNREACHABLE();
2860 return NULL;
2863 SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2865 SLJIT_UNUSED_ARG(compiler);
2866 SLJIT_UNUSED_ARG(dst);
2867 SLJIT_UNUSED_ARG(dstw);
2868 return NULL;
2871 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2873 SLJIT_UNUSED_ARG(addr);
2874 SLJIT_UNUSED_ARG(new_target);
2875 SLJIT_UNUSED_ARG(executable_offset);
2876 SLJIT_UNREACHABLE();
2879 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2881 SLJIT_UNUSED_ARG(addr);
2882 SLJIT_UNUSED_ARG(new_constant);
2883 SLJIT_UNUSED_ARG(executable_offset);
2884 SLJIT_UNREACHABLE();
2887 #endif /* !SLJIT_CONFIG_UNSUPPORTED */