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.
31 /* For SLJIT_CACHE_FLUSH, which can expand to FlushInstructionCache. */
36 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
38 /* These libraries are needed for the macros below. */
42 #endif /* SLJIT_STD_MACROS_DEFINED */
44 #define CHECK_ERROR() \
46 if (SLJIT_UNLIKELY(compiler->error)) \
47 return compiler->error; \
50 #define CHECK_ERROR_PTR() \
52 if (SLJIT_UNLIKELY(compiler->error)) \
56 #define FAIL_IF(expr) \
58 if (SLJIT_UNLIKELY(expr)) \
59 return compiler->error; \
62 #define PTR_FAIL_IF(expr) \
64 if (SLJIT_UNLIKELY(expr)) \
68 #define FAIL_IF_NULL(ptr) \
70 if (SLJIT_UNLIKELY(!(ptr))) { \
71 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
72 return SLJIT_ERR_ALLOC_FAILED; \
76 #define PTR_FAIL_IF_NULL(ptr) \
78 if (SLJIT_UNLIKELY(!(ptr))) { \
79 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
84 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
86 if (SLJIT_UNLIKELY(!(ptr))) { \
87 compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
92 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
94 #define VARIABLE_FLAG_SHIFT (10)
95 #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
96 #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
98 #define GET_OPCODE(op) \
99 ((op) & ~(SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
101 #define HAS_FLAGS(op) \
102 ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
104 #define GET_ALL_FLAGS(op) \
105 ((op) & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
107 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
108 #define TYPE_CAST_NEEDED(op) \
109 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32)
111 #define TYPE_CAST_NEEDED(op) \
112 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16)
115 #define BUF_SIZE 4096
117 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
118 #define ABUF_SIZE 2048
120 #define ABUF_SIZE 4096
123 /* Parameter parsing. */
124 #define REG_MASK 0x3f
125 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
126 #define OFFS_REG_MASK (REG_MASK << 8)
127 #define TO_OFFS_REG(reg) ((reg) << 8)
128 /* When reg cannot be unused. */
129 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
130 /* When reg can be unused. */
131 #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK)
133 /* Mask for argument types. */
134 #define SLJIT_DEF_MASK ((1 << SLJIT_DEF_SHIFT) - 1)
137 #define JUMP_LABEL 0x1
138 #define JUMP_ADDR 0x2
139 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
141 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
142 # define PATCH_MB 0x4
143 # define PATCH_MW 0x8
144 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
145 # define PATCH_MD 0x10
149 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
154 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
155 # define CPOOL_SIZE 512
158 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
159 # define IS_COND 0x04
161 /* conditional + imm8 */
162 # define PATCH_TYPE1 0x10
163 /* conditional + imm20 */
164 # define PATCH_TYPE2 0x20
166 # define PATCH_TYPE3 0x30
168 # define PATCH_TYPE4 0x40
170 # define PATCH_TYPE5 0x50
172 # define PATCH_BL 0x60
173 /* 0xf00 cc code for branches */
176 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
177 # define IS_COND 0x004
178 # define IS_CBZ 0x008
180 # define PATCH_B 0x020
181 # define PATCH_COND 0x040
182 # define PATCH_ABS48 0x080
183 # define PATCH_ABS64 0x100
186 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
187 # define IS_COND 0x004
188 # define IS_CALL 0x008
189 # define PATCH_B 0x010
190 # define PATCH_ABS_B 0x020
191 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
192 # define PATCH_ABS32 0x040
193 # define PATCH_ABS48 0x080
195 # define REMOVE_COND 0x100
198 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
199 # define IS_MOVABLE 0x004
200 # define IS_JAL 0x008
201 # define IS_CALL 0x010
202 # define IS_BIT26_COND 0x020
203 # define IS_BIT16_COND 0x040
205 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
207 # define PATCH_B 0x080
208 # define PATCH_J 0x100
210 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
211 # define PATCH_ABS32 0x200
212 # define PATCH_ABS48 0x400
215 /* instruction types */
216 # define MOVABLE_INS 0
217 /* 1 - 31 last destination register */
218 /* no destination (i.e: store) */
219 # define UNMOVABLE_INS 32
220 /* FPU status register */
224 #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
226 # define IS_COND 0x08
228 # define PATCH_B 0x10
229 # define PATCH_J 0x20
232 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
233 # define IS_MOVABLE 0x04
234 # define IS_COND 0x08
235 # define IS_CALL 0x10
237 # define PATCH_B 0x20
238 # define PATCH_CALL 0x40
240 /* instruction types */
241 # define MOVABLE_INS 0
242 /* 1 - 31 last destination register */
243 /* no destination (i.e: store) */
244 # define UNMOVABLE_INS 32
246 # define DST_INS_MASK 0xff
248 /* ICC_SET is the same as SET_FLAGS. */
249 # define ICC_IS_SET (1 << 23)
250 # define FCC_IS_SET (1 << 24)
253 /* Stack management. */
255 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
256 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
257 (saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
258 extra) * sizeof(sljit_sw))
260 #define ADJUST_LOCAL_OFFSET(p, i) \
261 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
262 (i) += SLJIT_LOCALS_OFFSET;
264 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
266 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
267 #include "sljitUtils.c"
269 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
271 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
273 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
274 #include "sljitProtExecAllocator.c"
276 #include "sljitExecAllocator.c"
281 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
282 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
284 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
287 /* Argument checking features. */
289 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
291 /* Returns with error when an invalid argument is passed. */
293 #define CHECK_ARGUMENT(x) \
295 if (SLJIT_UNLIKELY(!(x))) \
299 #define CHECK_RETURN_TYPE sljit_s32
300 #define CHECK_RETURN_OK return 0
304 if (SLJIT_UNLIKELY(x)) { \
305 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
306 return SLJIT_ERR_BAD_ARGUMENT; \
310 #define CHECK_PTR(x) \
312 if (SLJIT_UNLIKELY(x)) { \
313 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
318 #define CHECK_REG_INDEX(x) \
320 if (SLJIT_UNLIKELY(x)) { \
325 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
327 /* Assertion failure occures if an invalid argument is passed. */
328 #undef SLJIT_ARGUMENT_CHECKS
329 #define SLJIT_ARGUMENT_CHECKS 1
331 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
332 #define CHECK_RETURN_TYPE void
333 #define CHECK_RETURN_OK return
335 #define CHECK_PTR(x) x
336 #define CHECK_REG_INDEX(x) x
338 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
340 /* Arguments are not checked. */
341 #define CHECK_RETURN_TYPE void
342 #define CHECK_RETURN_OK return
344 #define CHECK_PTR(x) x
345 #define CHECK_REG_INDEX(x) x
349 /* Arguments are not checked. */
352 #define CHECK_REG_INDEX(x)
354 #endif /* SLJIT_ARGUMENT_CHECKS */
356 /* --------------------------------------------------------------------- */
357 /* Public functions */
358 /* --------------------------------------------------------------------- */
360 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
361 #define SLJIT_NEEDS_COMPILER_INIT 1
362 static sljit_s32 compiler_initialized = 0;
363 /* A thread safe initialization. */
364 static void init_compiler(void);
367 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
369 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
372 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
374 SLJIT_COMPILE_ASSERT(
375 sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
376 && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
377 && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
378 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
379 && sizeof(sljit_p) <= sizeof(sljit_sw)
380 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
381 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
382 invalid_integer_types);
383 SLJIT_COMPILE_ASSERT(SLJIT_I32_OP == SLJIT_F32_OP,
384 int_op_and_single_op_must_be_the_same);
385 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_F32_OP,
386 rewritable_jump_and_single_op_must_not_be_the_same);
387 SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_EQUAL_F64 & 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->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
395 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
397 if (!compiler->buf || !compiler->abuf) {
399 SLJIT_FREE(compiler->buf, allocator_data);
401 SLJIT_FREE(compiler->abuf, allocator_data);
402 SLJIT_FREE(compiler, allocator_data);
406 compiler->buf->next = NULL;
407 compiler->buf->used_size = 0;
408 compiler->abuf->next = NULL;
409 compiler->abuf->used_size = 0;
411 compiler->scratches = -1;
412 compiler->saveds = -1;
413 compiler->fscratches = -1;
414 compiler->fsaveds = -1;
415 compiler->local_size = -1;
417 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
421 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
422 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
423 + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
424 if (!compiler->cpool) {
425 SLJIT_FREE(compiler->buf, allocator_data);
426 SLJIT_FREE(compiler->abuf, allocator_data);
427 SLJIT_FREE(compiler, allocator_data);
430 compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
431 compiler->cpool_diff = 0xffffffff;
434 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
435 compiler->delay_slot = UNMOVABLE_INS;
438 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
439 compiler->delay_slot = UNMOVABLE_INS;
442 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
443 if (!compiler_initialized) {
445 compiler_initialized = 1;
452 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
454 struct sljit_memory_fragment *buf;
455 struct sljit_memory_fragment *curr;
456 void *allocator_data = compiler->allocator_data;
457 SLJIT_UNUSED_ARG(allocator_data);
463 SLJIT_FREE(curr, allocator_data);
466 buf = compiler->abuf;
470 SLJIT_FREE(curr, allocator_data);
473 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
474 SLJIT_FREE(compiler->cpool, allocator_data);
476 SLJIT_FREE(compiler, allocator_data);
479 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
481 if (compiler->error == SLJIT_SUCCESS)
482 compiler->error = SLJIT_ERR_ALLOC_FAILED;
485 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
486 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
488 /* Remove thumb mode flag. */
489 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1));
491 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
492 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
494 /* Resolve indirection. */
495 code = (void*)(*(sljit_uw*)code);
496 SLJIT_FREE_EXEC(code);
499 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
501 SLJIT_FREE_EXEC(code);
505 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
507 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
508 jump->flags &= ~JUMP_ADDR;
509 jump->flags |= JUMP_LABEL;
510 jump->u.label = label;
514 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
516 if (SLJIT_LIKELY(!!jump)) {
517 jump->flags &= ~JUMP_LABEL;
518 jump->flags |= JUMP_ADDR;
519 jump->u.target = target;
523 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
525 SLJIT_UNUSED_ARG(compiler);
526 SLJIT_UNUSED_ARG(current_flags);
528 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
529 if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_I32_OP | SLJIT_SET_Z)) == 0) {
530 compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_I32_OP | SLJIT_SET_Z));
535 /* --------------------------------------------------------------------- */
536 /* Private functions */
537 /* --------------------------------------------------------------------- */
539 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
542 struct sljit_memory_fragment *new_frag;
544 SLJIT_ASSERT(size <= 256);
545 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
546 ret = compiler->buf->memory + compiler->buf->used_size;
547 compiler->buf->used_size += size;
550 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
551 PTR_FAIL_IF_NULL(new_frag);
552 new_frag->next = compiler->buf;
553 compiler->buf = new_frag;
554 new_frag->used_size = size;
555 return new_frag->memory;
558 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
561 struct sljit_memory_fragment *new_frag;
563 SLJIT_ASSERT(size <= 256);
564 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
565 ret = compiler->abuf->memory + compiler->abuf->used_size;
566 compiler->abuf->used_size += size;
569 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
570 PTR_FAIL_IF_NULL(new_frag);
571 new_frag->next = compiler->abuf;
572 compiler->abuf = new_frag;
573 new_frag->used_size = size;
574 return new_frag->memory;
577 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
581 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
582 if (size <= 0 || size > 128)
584 size = (size + 7) & ~7;
586 if (size <= 0 || size > 64)
588 size = (size + 3) & ~3;
590 return ensure_abuf(compiler, size);
593 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
595 struct sljit_memory_fragment *buf = compiler->buf;
596 struct sljit_memory_fragment *prev = NULL;
597 struct sljit_memory_fragment *tmp;
604 } while (buf != NULL);
606 compiler->buf = prev;
609 static SLJIT_INLINE sljit_s32 get_arg_count(sljit_s32 arg_types)
611 sljit_s32 arg_count = 0;
613 arg_types >>= SLJIT_DEF_SHIFT;
616 arg_types >>= SLJIT_DEF_SHIFT;
622 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
623 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
624 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
626 SLJIT_UNUSED_ARG(args);
627 SLJIT_UNUSED_ARG(local_size);
629 compiler->options = options;
630 compiler->scratches = scratches;
631 compiler->saveds = saveds;
632 compiler->fscratches = fscratches;
633 compiler->fsaveds = fsaveds;
634 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
635 compiler->logical_local_size = local_size;
639 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
640 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
641 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
643 SLJIT_UNUSED_ARG(args);
644 SLJIT_UNUSED_ARG(local_size);
646 compiler->options = options;
647 compiler->scratches = scratches;
648 compiler->saveds = saveds;
649 compiler->fscratches = fscratches;
650 compiler->fsaveds = fsaveds;
651 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
652 compiler->logical_local_size = local_size;
656 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
659 label->size = compiler->size;
660 if (compiler->last_label)
661 compiler->last_label->next = label;
663 compiler->labels = label;
664 compiler->last_label = label;
667 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_s32 flags)
671 if (compiler->last_jump)
672 compiler->last_jump->next = jump;
674 compiler->jumps = jump;
675 compiler->last_jump = jump;
678 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
681 const_->addr = compiler->size;
682 if (compiler->last_const)
683 compiler->last_const->next = const_;
685 compiler->consts = const_;
686 compiler->last_const = const_;
689 #define ADDRESSING_DEPENDS_ON(exp, reg) \
690 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
692 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
694 #define FUNCTION_CHECK_IS_REG(r) \
695 (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
696 || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
698 #define FUNCTION_CHECK_IS_FREG(fr) \
699 (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
700 || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
702 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
703 #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
705 #define CHECK_IF_VIRTUAL_REGISTER(p) 0
708 static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
710 if (compiler->scratches == -1 || compiler->saveds == -1)
713 if (!(p & SLJIT_MEM))
716 if (!((p & REG_MASK) == SLJIT_UNUSED || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
719 if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
722 if (p & OFFS_REG_MASK) {
723 if ((p & REG_MASK) == SLJIT_UNUSED)
726 if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
729 if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
736 return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
739 #define FUNCTION_CHECK_SRC_MEM(p, i) \
740 CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
742 static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
744 if (compiler->scratches == -1 || compiler->saveds == -1)
747 if (FUNCTION_CHECK_IS_REG(p))
753 if (p == SLJIT_MEM1(SLJIT_SP))
754 return (i >= 0 && i < compiler->logical_local_size);
756 return function_check_src_mem(compiler, p, i);
759 #define FUNCTION_CHECK_SRC(p, i) \
760 CHECK_ARGUMENT(function_check_src(compiler, p, i));
762 static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i, sljit_s32 unused)
764 if (compiler->scratches == -1 || compiler->saveds == -1)
767 if (FUNCTION_CHECK_IS_REG(p) || ((unused) && (p) == SLJIT_UNUSED))
770 if (p == SLJIT_MEM1(SLJIT_SP))
771 return (i >= 0 && i < compiler->logical_local_size);
773 return function_check_src_mem(compiler, p, i);
776 #define FUNCTION_CHECK_DST(p, i, unused) \
777 CHECK_ARGUMENT(function_check_dst(compiler, p, i, unused));
779 static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
781 if (compiler->scratches == -1 || compiler->saveds == -1)
784 if (FUNCTION_CHECK_IS_FREG(p))
787 if (p == SLJIT_MEM1(SLJIT_SP))
788 return (i >= 0 && i < compiler->logical_local_size);
790 return function_check_src_mem(compiler, p, i);
793 #define FUNCTION_FCHECK(p, i) \
794 CHECK_ARGUMENT(function_fcheck(compiler, p, i));
796 #endif /* SLJIT_ARGUMENT_CHECKS */
798 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
800 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
802 compiler->verbose = verbose;
805 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
807 # define SLJIT_PRINT_D "I64"
809 # define SLJIT_PRINT_D "l"
812 # define SLJIT_PRINT_D ""
815 static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
817 if (r < (SLJIT_R0 + compiler->scratches))
818 fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
819 else if (r != SLJIT_SP)
820 fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
822 fprintf(compiler->verbose, "sp");
825 static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
827 if (r < (SLJIT_FR0 + compiler->fscratches))
828 fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
830 fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
833 static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
836 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
837 else if ((p) & SLJIT_MEM) {
838 if ((p) & REG_MASK) {
839 fputc('[', compiler->verbose);
840 sljit_verbose_reg(compiler, (p) & REG_MASK);
841 if ((p) & OFFS_REG_MASK) {
842 fprintf(compiler->verbose, " + ");
843 sljit_verbose_reg(compiler, OFFS_REG(p));
845 fprintf(compiler->verbose, " * %d", 1 << (i));
848 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
849 fputc(']', compiler->verbose);
852 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
854 sljit_verbose_reg(compiler, p);
856 fprintf(compiler->verbose, "unused");
859 static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
861 if ((p) & SLJIT_MEM) {
862 if ((p) & REG_MASK) {
863 fputc('[', compiler->verbose);
864 sljit_verbose_reg(compiler, (p) & REG_MASK);
865 if ((p) & OFFS_REG_MASK) {
866 fprintf(compiler->verbose, " + ");
867 sljit_verbose_reg(compiler, OFFS_REG(p));
869 fprintf(compiler->verbose, "%d", 1 << (i));
872 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
873 fputc(']', compiler->verbose);
876 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
879 sljit_verbose_freg(compiler, p);
882 static const char* op0_names[] = {
883 (char*)"breakpoint", (char*)"nop", (char*)"lmul.uw", (char*)"lmul.sw",
884 (char*)"divmod.u", (char*)"divmod.s", (char*)"div.u", (char*)"div.s"
887 static const char* op1_names[] = {
888 (char*)"", (char*)".u8", (char*)".s8", (char*)".u16",
889 (char*)".s16", (char*)".u32", (char*)".s32", (char*)".p",
890 (char*)"", (char*)".u8", (char*)".s8", (char*)".u16",
891 (char*)".s16", (char*)".u32", (char*)".s32", (char*)".p",
892 (char*)"not", (char*)"neg", (char*)"clz",
895 static const char* op2_names[] = {
896 (char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
897 (char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
898 (char*)"shl", (char*)"lshr", (char*)"ashr",
901 static const char* fop1_names[] = {
902 (char*)"mov", (char*)"conv", (char*)"conv", (char*)"conv",
903 (char*)"conv", (char*)"conv", (char*)"cmp", (char*)"neg",
907 static const char* fop2_names[] = {
908 (char*)"add", (char*)"sub", (char*)"mul", (char*)"div"
911 #define JUMP_POSTFIX(type) \
912 ((type & 0xff) <= SLJIT_MUL_NOT_OVERFLOW ? ((type & SLJIT_I32_OP) ? "32" : "") \
913 : ((type & 0xff) <= SLJIT_ORDERED_F64 ? ((type & SLJIT_F32_OP) ? ".f32" : ".f64") : ""))
915 static char* jump_names[] = {
916 (char*)"equal", (char*)"not_equal",
917 (char*)"less", (char*)"greater_equal",
918 (char*)"greater", (char*)"less_equal",
919 (char*)"sig_less", (char*)"sig_greater_equal",
920 (char*)"sig_greater", (char*)"sig_less_equal",
921 (char*)"overflow", (char*)"not_overflow",
922 (char*)"mul_overflow", (char*)"mul_not_overflow",
923 (char*)"carry", (char*)"",
924 (char*)"equal", (char*)"not_equal",
925 (char*)"less", (char*)"greater_equal",
926 (char*)"greater", (char*)"less_equal",
927 (char*)"unordered", (char*)"ordered",
928 (char*)"jump", (char*)"fast_call",
929 (char*)"call", (char*)"call.cdecl"
932 static char* call_arg_names[] = {
933 (char*)"void", (char*)"sw", (char*)"uw", (char*)"s32", (char*)"u32", (char*)"f32", (char*)"f64"
936 #endif /* SLJIT_VERBOSE */
938 /* --------------------------------------------------------------------- */
940 /* --------------------------------------------------------------------- */
942 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
943 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
945 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
947 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
948 struct sljit_jump *jump;
951 SLJIT_UNUSED_ARG(compiler);
953 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
954 CHECK_ARGUMENT(compiler->size > 0);
955 jump = compiler->jumps;
957 /* All jumps have target. */
958 CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
965 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
966 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
967 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
969 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
970 sljit_s32 types, arg_count, curr_type;
973 SLJIT_UNUSED_ARG(compiler);
975 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
976 CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
977 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
978 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
979 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
980 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
981 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
982 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
983 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
984 CHECK_ARGUMENT((arg_types & SLJIT_DEF_MASK) == 0);
986 types = (arg_types >> SLJIT_DEF_SHIFT);
988 while (types != 0 && arg_count < 3) {
989 curr_type = (types & SLJIT_DEF_MASK);
990 CHECK_ARGUMENT(curr_type == SLJIT_ARG_TYPE_SW || curr_type == SLJIT_ARG_TYPE_UW);
992 types >>= SLJIT_DEF_SHIFT;
994 CHECK_ARGUMENT(arg_count <= saveds && types == 0);
996 compiler->last_flags = 0;
998 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
999 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1000 fprintf(compiler->verbose, " enter options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : "");
1002 arg_types >>= SLJIT_DEF_SHIFT;
1004 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
1005 arg_types >>= SLJIT_DEF_SHIFT;
1007 fprintf(compiler->verbose, ",");
1010 fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
1011 scratches, saveds, fscratches, fsaveds, local_size);
1017 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
1018 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1019 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1021 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1022 sljit_s32 types, arg_count, curr_type;
1025 SLJIT_UNUSED_ARG(compiler);
1027 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1028 CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
1029 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1030 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
1031 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1032 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1033 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1034 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1035 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1037 types = (arg_types >> SLJIT_DEF_SHIFT);
1039 while (types != 0 && arg_count < 3) {
1040 curr_type = (types & SLJIT_DEF_MASK);
1041 CHECK_ARGUMENT(curr_type == SLJIT_ARG_TYPE_SW || curr_type == SLJIT_ARG_TYPE_UW);
1043 types >>= SLJIT_DEF_SHIFT;
1045 CHECK_ARGUMENT(arg_count <= saveds && types == 0);
1047 compiler->last_flags = 0;
1049 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1050 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1051 fprintf(compiler->verbose, " set_context options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : "");
1053 arg_types >>= SLJIT_DEF_SHIFT;
1055 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
1056 arg_types >>= SLJIT_DEF_SHIFT;
1058 fprintf(compiler->verbose, ",");
1061 fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
1062 scratches, saveds, fscratches, fsaveds, local_size);
1068 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1070 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1071 CHECK_ARGUMENT(compiler->scratches >= 0);
1072 if (op != SLJIT_UNUSED) {
1073 CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
1074 FUNCTION_CHECK_SRC(src, srcw);
1077 CHECK_ARGUMENT(src == 0 && srcw == 0);
1078 compiler->last_flags = 0;
1080 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1081 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1082 if (op == SLJIT_UNUSED)
1083 fprintf(compiler->verbose, " return\n");
1085 fprintf(compiler->verbose, " return%s ", op1_names[op - SLJIT_OP1_BASE]);
1086 sljit_verbose_param(compiler, src, srcw);
1087 fprintf(compiler->verbose, "\n");
1094 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1096 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1097 FUNCTION_CHECK_DST(dst, dstw, 0);
1098 compiler->last_flags = 0;
1100 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1101 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1102 fprintf(compiler->verbose, " fast_enter ");
1103 sljit_verbose_param(compiler, dst, dstw);
1104 fprintf(compiler->verbose, "\n");
1110 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
1112 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1113 FUNCTION_CHECK_SRC(src, srcw);
1114 CHECK_ARGUMENT(src != SLJIT_IMM);
1115 compiler->last_flags = 0;
1117 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1118 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1119 fprintf(compiler->verbose, " fast_return ");
1120 sljit_verbose_param(compiler, src, srcw);
1121 fprintf(compiler->verbose, "\n");
1127 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1129 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1130 CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1131 || ((op & ~SLJIT_I32_OP) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_I32_OP) <= SLJIT_DIV_SW));
1132 CHECK_ARGUMENT(op < SLJIT_LMUL_UW || compiler->scratches >= 2);
1133 if (op >= SLJIT_LMUL_UW)
1134 compiler->last_flags = 0;
1136 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1137 if (SLJIT_UNLIKELY(!!compiler->verbose))
1139 fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1140 if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW) {
1141 fprintf(compiler->verbose, (op & SLJIT_I32_OP) ? "32" : "w");
1143 fprintf(compiler->verbose, "\n");
1149 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1150 sljit_s32 dst, sljit_sw dstw,
1151 sljit_s32 src, sljit_sw srcw)
1153 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1154 compiler->skip_checks = 0;
1158 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1159 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1161 switch (GET_OPCODE(op)) {
1163 /* Only SLJIT_I32_OP and SLJIT_SET_Z are allowed. */
1164 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1167 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1168 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1173 /* Nothing allowed */
1174 CHECK_ARGUMENT(!(op & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1177 /* Only SLJIT_I32_OP is allowed. */
1178 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1182 FUNCTION_CHECK_DST(dst, dstw, 1);
1183 FUNCTION_CHECK_SRC(src, srcw);
1185 if (GET_OPCODE(op) >= SLJIT_NOT) {
1186 CHECK_ARGUMENT(src != SLJIT_IMM);
1187 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1190 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1191 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1192 if (GET_OPCODE(op) <= SLJIT_MOV_P)
1194 fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_I32_OP) ? "" : "32",
1195 (op != SLJIT_MOV32) ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : "");
1199 fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
1200 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1201 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1204 sljit_verbose_param(compiler, dst, dstw);
1205 fprintf(compiler->verbose, ", ");
1206 sljit_verbose_param(compiler, src, srcw);
1207 fprintf(compiler->verbose, "\n");
1213 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
1214 sljit_s32 dst, sljit_sw dstw,
1215 sljit_s32 src1, sljit_sw src1w,
1216 sljit_s32 src2, sljit_sw src2w)
1218 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1219 compiler->skip_checks = 0;
1223 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1224 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1226 switch (GET_OPCODE(op)) {
1233 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1236 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1237 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1238 || GET_FLAG_TYPE(op) == SLJIT_MUL_OVERFLOW);
1241 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1242 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1243 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1246 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1247 || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1248 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1252 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1253 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1254 CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1255 CHECK_ARGUMENT((op & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
1258 SLJIT_UNREACHABLE();
1262 FUNCTION_CHECK_DST(dst, dstw, 1);
1263 FUNCTION_CHECK_SRC(src1, src1w);
1264 FUNCTION_CHECK_SRC(src2, src2w);
1265 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1267 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1268 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1269 fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
1270 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1271 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1272 sljit_verbose_param(compiler, dst, dstw);
1273 fprintf(compiler->verbose, ", ");
1274 sljit_verbose_param(compiler, src1, src1w);
1275 fprintf(compiler->verbose, ", ");
1276 sljit_verbose_param(compiler, src2, src2w);
1277 fprintf(compiler->verbose, "\n");
1283 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1285 SLJIT_UNUSED_ARG(reg);
1286 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1287 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1292 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1294 SLJIT_UNUSED_ARG(reg);
1295 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1296 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1301 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1302 void *instruction, sljit_s32 size)
1304 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1308 SLJIT_UNUSED_ARG(compiler);
1310 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1311 CHECK_ARGUMENT(instruction);
1313 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1314 CHECK_ARGUMENT(size > 0 && size < 16);
1315 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1316 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1317 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1319 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1322 compiler->last_flags = 0;
1324 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1325 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1326 fprintf(compiler->verbose, " op_custom");
1327 for (i = 0; i < size; i++)
1328 fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1329 fprintf(compiler->verbose, "\n");
1335 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1336 sljit_s32 dst, sljit_sw dstw,
1337 sljit_s32 src, sljit_sw srcw)
1339 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1340 compiler->skip_checks = 0;
1344 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1345 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1346 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1347 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1348 FUNCTION_FCHECK(src, srcw);
1349 FUNCTION_FCHECK(dst, dstw);
1351 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1352 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1353 if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1354 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1355 (op & SLJIT_F32_OP) ? ".f32.from.f64" : ".f64.from.f32");
1357 fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1358 (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1360 sljit_verbose_fparam(compiler, dst, dstw);
1361 fprintf(compiler->verbose, ", ");
1362 sljit_verbose_fparam(compiler, src, srcw);
1363 fprintf(compiler->verbose, "\n");
1369 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1370 sljit_s32 src1, sljit_sw src1w,
1371 sljit_s32 src2, sljit_sw src2w)
1373 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1374 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1377 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1378 compiler->skip_checks = 0;
1382 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1383 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1384 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1385 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1386 CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1387 || (GET_FLAG_TYPE(op) >= SLJIT_EQUAL_F64 && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_F64));
1388 FUNCTION_FCHECK(src1, src1w);
1389 FUNCTION_FCHECK(src2, src2w);
1391 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1392 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1393 fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1394 if (op & VARIABLE_FLAG_MASK) {
1395 fprintf(compiler->verbose, ".%s_f", jump_names[GET_FLAG_TYPE(op)]);
1397 fprintf(compiler->verbose, " ");
1398 sljit_verbose_fparam(compiler, src1, src1w);
1399 fprintf(compiler->verbose, ", ");
1400 sljit_verbose_fparam(compiler, src2, src2w);
1401 fprintf(compiler->verbose, "\n");
1407 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1408 sljit_s32 dst, sljit_sw dstw,
1409 sljit_s32 src, sljit_sw srcw)
1411 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1412 compiler->skip_checks = 0;
1416 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1417 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1418 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1419 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1420 FUNCTION_FCHECK(src, srcw);
1421 FUNCTION_CHECK_DST(dst, dstw, 0);
1423 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1424 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1425 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1426 (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1427 (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1428 sljit_verbose_param(compiler, dst, dstw);
1429 fprintf(compiler->verbose, ", ");
1430 sljit_verbose_fparam(compiler, src, srcw);
1431 fprintf(compiler->verbose, "\n");
1437 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1438 sljit_s32 dst, sljit_sw dstw,
1439 sljit_s32 src, sljit_sw srcw)
1441 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1442 compiler->skip_checks = 0;
1446 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1447 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1448 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1449 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1450 FUNCTION_CHECK_SRC(src, srcw);
1451 FUNCTION_FCHECK(dst, dstw);
1453 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1454 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1455 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1456 (op & SLJIT_F32_OP) ? ".f32" : ".f64",
1457 (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1458 sljit_verbose_fparam(compiler, dst, dstw);
1459 fprintf(compiler->verbose, ", ");
1460 sljit_verbose_param(compiler, src, srcw);
1461 fprintf(compiler->verbose, "\n");
1467 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1468 sljit_s32 dst, sljit_sw dstw,
1469 sljit_s32 src1, sljit_sw src1w,
1470 sljit_s32 src2, sljit_sw src2w)
1472 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1473 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1474 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1475 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1476 FUNCTION_FCHECK(src1, src1w);
1477 FUNCTION_FCHECK(src2, src2w);
1478 FUNCTION_FCHECK(dst, dstw);
1480 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1481 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1482 fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1483 sljit_verbose_fparam(compiler, dst, dstw);
1484 fprintf(compiler->verbose, ", ");
1485 sljit_verbose_fparam(compiler, src1, src1w);
1486 fprintf(compiler->verbose, ", ");
1487 sljit_verbose_fparam(compiler, src2, src2w);
1488 fprintf(compiler->verbose, "\n");
1494 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1496 SLJIT_UNUSED_ARG(compiler);
1498 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1499 compiler->skip_checks = 0;
1503 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1504 compiler->last_flags = 0;
1507 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1508 if (SLJIT_UNLIKELY(!!compiler->verbose))
1509 fprintf(compiler->verbose, "label:\n");
1514 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1516 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1517 compiler->skip_checks = 0;
1521 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1522 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1523 CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1524 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
1525 CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_I32_OP));
1527 if ((type & 0xff) < SLJIT_JUMP) {
1528 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1529 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1531 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1532 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1533 || ((type & 0xff) == SLJIT_MUL_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_MUL_OVERFLOW));
1534 CHECK_ARGUMENT((type & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
1537 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1538 if (SLJIT_UNLIKELY(!!compiler->verbose))
1539 fprintf(compiler->verbose, " jump%s %s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1540 jump_names[type & 0xff], JUMP_POSTFIX(type));
1545 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
1546 sljit_s32 arg_types)
1548 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1549 sljit_s32 i, types, curr_type, scratches, fscratches;
1551 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1552 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
1557 for (i = 0; i < 5; i++) {
1558 curr_type = (types & SLJIT_DEF_MASK);
1559 CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64);
1561 if (curr_type == 0) {
1564 if (curr_type >= SLJIT_ARG_TYPE_F32)
1569 if (curr_type >= SLJIT_ARG_TYPE_F32) {
1570 CHECK_ARGUMENT(compiler->fscratches > 0);
1571 } else if (curr_type >= SLJIT_ARG_TYPE_SW) {
1572 CHECK_ARGUMENT(compiler->scratches > 0);
1575 types >>= SLJIT_DEF_SHIFT;
1577 CHECK_ARGUMENT(compiler->scratches >= scratches);
1578 CHECK_ARGUMENT(compiler->fscratches >= fscratches);
1579 CHECK_ARGUMENT(types == 0);
1581 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1582 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1583 fprintf(compiler->verbose, " %s%s ret[%s", jump_names[type & 0xff],
1584 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_DEF_MASK]);
1586 arg_types >>= SLJIT_DEF_SHIFT;
1588 fprintf(compiler->verbose, "], args[");
1590 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
1591 arg_types >>= SLJIT_DEF_SHIFT;
1593 fprintf(compiler->verbose, ",");
1594 } while (arg_types);
1596 fprintf(compiler->verbose, "]\n");
1602 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1603 sljit_s32 src1, sljit_sw src1w,
1604 sljit_s32 src2, sljit_sw src2w)
1606 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1607 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1608 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1609 FUNCTION_CHECK_SRC(src1, src1w);
1610 FUNCTION_CHECK_SRC(src2, src2w);
1611 compiler->last_flags = 0;
1613 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1614 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1615 fprintf(compiler->verbose, " cmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1616 jump_names[type & 0xff], (type & SLJIT_I32_OP) ? "32" : "");
1617 sljit_verbose_param(compiler, src1, src1w);
1618 fprintf(compiler->verbose, ", ");
1619 sljit_verbose_param(compiler, src2, src2w);
1620 fprintf(compiler->verbose, "\n");
1626 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1627 sljit_s32 src1, sljit_sw src1w,
1628 sljit_s32 src2, sljit_sw src2w)
1630 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1631 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1632 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_F32_OP)));
1633 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL_F64 && (type & 0xff) <= SLJIT_ORDERED_F64);
1634 FUNCTION_FCHECK(src1, src1w);
1635 FUNCTION_FCHECK(src2, src2w);
1636 compiler->last_flags = 0;
1638 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1639 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1640 fprintf(compiler->verbose, " fcmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1641 jump_names[type & 0xff], (type & SLJIT_F32_OP) ? ".f32" : ".f64");
1642 sljit_verbose_fparam(compiler, src1, src1w);
1643 fprintf(compiler->verbose, ", ");
1644 sljit_verbose_fparam(compiler, src2, src2w);
1645 fprintf(compiler->verbose, "\n");
1651 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
1652 sljit_s32 src, sljit_sw srcw)
1654 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1655 compiler->skip_checks = 0;
1659 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1660 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
1661 FUNCTION_CHECK_SRC(src, srcw);
1663 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1664 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1665 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1666 sljit_verbose_param(compiler, src, srcw);
1667 fprintf(compiler->verbose, "\n");
1673 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
1674 sljit_s32 arg_types,
1675 sljit_s32 src, sljit_sw srcw)
1677 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1678 sljit_s32 i, types, curr_type, scratches, fscratches;
1680 CHECK_ARGUMENT(type == SLJIT_CALL || type == SLJIT_CALL_CDECL);
1681 FUNCTION_CHECK_SRC(src, srcw);
1686 for (i = 0; i < 5; i++) {
1687 curr_type = (types & SLJIT_DEF_MASK);
1688 CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64);
1690 if (curr_type == 0) {
1693 if (curr_type >= SLJIT_ARG_TYPE_F32)
1698 if (curr_type >= SLJIT_ARG_TYPE_F32) {
1699 CHECK_ARGUMENT(compiler->fscratches > 0);
1700 } else if (curr_type >= SLJIT_ARG_TYPE_SW) {
1701 CHECK_ARGUMENT(compiler->scratches > 0);
1704 types >>= SLJIT_DEF_SHIFT;
1706 CHECK_ARGUMENT(compiler->scratches >= scratches);
1707 CHECK_ARGUMENT(compiler->fscratches >= fscratches);
1708 CHECK_ARGUMENT(types == 0);
1710 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1711 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1712 fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff],
1713 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_DEF_MASK]);
1715 arg_types >>= SLJIT_DEF_SHIFT;
1717 fprintf(compiler->verbose, "], args[");
1719 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_DEF_MASK]);
1720 arg_types >>= SLJIT_DEF_SHIFT;
1722 fprintf(compiler->verbose, ",");
1723 } while (arg_types);
1725 fprintf(compiler->verbose, "], ");
1726 sljit_verbose_param(compiler, src, srcw);
1727 fprintf(compiler->verbose, "\n");
1733 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1734 sljit_s32 dst, sljit_sw dstw,
1737 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1738 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
1739 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1740 CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1741 CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1742 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1743 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1745 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1746 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1748 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1749 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1750 || ((type & 0xff) == SLJIT_MUL_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_MUL_OVERFLOW));
1752 FUNCTION_CHECK_DST(dst, dstw, 0);
1754 if (GET_OPCODE(op) >= SLJIT_ADD)
1755 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1757 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1758 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1759 fprintf(compiler->verbose, " flags%s %s%s, ",
1760 !(op & SLJIT_SET_Z) ? "" : ".z",
1761 GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1762 GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_I32_OP) ? "32" : ""));
1763 sljit_verbose_param(compiler, dst, dstw);
1764 fprintf(compiler->verbose, ", %s%s\n", jump_names[type & 0xff], JUMP_POSTFIX(type));
1770 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1772 sljit_s32 src, sljit_sw srcw)
1774 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1775 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
1776 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1778 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
1779 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_I32_OP));
1780 if (src != SLJIT_IMM) {
1781 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
1782 CHECK_ARGUMENT(srcw == 0);
1785 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1786 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1788 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1789 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1790 || ((type & 0xff) == SLJIT_MUL_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_MUL_OVERFLOW));
1792 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1793 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1794 fprintf(compiler->verbose, " cmov%s %s%s, ",
1795 !(dst_reg & SLJIT_I32_OP) ? "" : "32",
1796 jump_names[type & 0xff], JUMP_POSTFIX(type));
1797 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_I32_OP);
1798 fprintf(compiler->verbose, ", ");
1799 sljit_verbose_param(compiler, src, srcw);
1800 fprintf(compiler->verbose, "\n");
1806 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
1808 sljit_s32 mem, sljit_sw memw)
1810 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1811 CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
1812 CHECK_ARGUMENT(!(type & SLJIT_I32_OP) || ((type & 0xff) != SLJIT_MOV && (type & 0xff) != SLJIT_MOV_U32 && (type & 0xff) != SLJIT_MOV_P));
1813 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1814 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1815 CHECK_ARGUMENT((type & ~(0xff | SLJIT_I32_OP | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1817 FUNCTION_CHECK_SRC_MEM(mem, memw);
1818 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
1820 CHECK_ARGUMENT((mem & REG_MASK) != SLJIT_UNUSED && (mem & REG_MASK) != reg);
1822 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1823 if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
1824 if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
1825 fprintf(compiler->verbose, " //");
1827 fprintf(compiler->verbose, " mem%s.%s%s%s ",
1828 !(type & SLJIT_I32_OP) ? "" : "32",
1829 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1830 op1_names[(type & 0xff) - SLJIT_OP1_BASE],
1831 (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
1832 sljit_verbose_reg(compiler, reg);
1833 fprintf(compiler->verbose, ", ");
1834 sljit_verbose_param(compiler, mem, memw);
1835 fprintf(compiler->verbose, "\n");
1841 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
1843 sljit_s32 mem, sljit_sw memw)
1845 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1846 CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
1847 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1848 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1849 CHECK_ARGUMENT((type & ~(0xff | SLJIT_I32_OP | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1851 FUNCTION_CHECK_SRC_MEM(mem, memw);
1852 CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
1854 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1855 if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
1856 if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
1857 fprintf(compiler->verbose, " //");
1859 fprintf(compiler->verbose, " fmem.%s%s%s ",
1860 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1861 !(type & SLJIT_I32_OP) ? ".f64" : ".f32",
1862 (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
1863 sljit_verbose_freg(compiler, freg);
1864 fprintf(compiler->verbose, ", ");
1865 sljit_verbose_param(compiler, mem, memw);
1866 fprintf(compiler->verbose, "\n");
1872 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
1874 /* Any offset is allowed. */
1875 SLJIT_UNUSED_ARG(offset);
1877 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1878 FUNCTION_CHECK_DST(dst, dstw, 0);
1880 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1881 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1882 fprintf(compiler->verbose, " local_base ");
1883 sljit_verbose_param(compiler, dst, dstw);
1884 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1890 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
1892 SLJIT_UNUSED_ARG(init_value);
1894 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1895 FUNCTION_CHECK_DST(dst, dstw, 0);
1897 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1898 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1899 fprintf(compiler->verbose, " const ");
1900 sljit_verbose_param(compiler, dst, dstw);
1901 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1907 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
1909 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
1910 SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
1911 invalid_float_opcodes); \
1912 if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
1913 if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
1914 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
1915 ADJUST_LOCAL_OFFSET(dst, dstw); \
1916 ADJUST_LOCAL_OFFSET(src, srcw); \
1917 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
1919 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
1920 CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
1921 ADJUST_LOCAL_OFFSET(dst, dstw); \
1922 ADJUST_LOCAL_OFFSET(src, srcw); \
1923 return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
1925 CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
1926 ADJUST_LOCAL_OFFSET(dst, dstw); \
1927 ADJUST_LOCAL_OFFSET(src, srcw); \
1928 return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
1930 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
1931 ADJUST_LOCAL_OFFSET(dst, dstw); \
1932 ADJUST_LOCAL_OFFSET(src, srcw);
1934 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1936 /* Return if don't need to do anything. */
1937 if (op == SLJIT_UNUSED)
1938 return SLJIT_SUCCESS;
1940 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1941 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1942 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1943 return SLJIT_SUCCESS;
1945 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
1946 return SLJIT_SUCCESS;
1949 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1950 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1951 compiler->skip_checks = 1;
1953 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1956 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
1957 || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
1958 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
1959 || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1))
1961 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
1963 sljit_s32 src, sljit_sw srcw)
1965 struct sljit_label *label;
1966 struct sljit_jump *jump;
1967 sljit_s32 op = (dst_reg & SLJIT_I32_OP) ? SLJIT_MOV32 : SLJIT_MOV;
1969 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1970 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1971 compiler->skip_checks = 1;
1973 jump = sljit_emit_jump(compiler, type ^ 0x1);
1976 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1977 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1978 compiler->skip_checks = 1;
1980 FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_I32_OP, 0, src, srcw));
1982 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1983 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1984 compiler->skip_checks = 1;
1986 label = sljit_emit_label(compiler);
1988 sljit_set_label(jump, label);
1989 return SLJIT_SUCCESS;
1994 /* CPU description section */
1996 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1997 #define SLJIT_CPUINFO_PART1 " 32bit ("
1998 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1999 #define SLJIT_CPUINFO_PART1 " 64bit ("
2001 #error "Internal error: CPU type info missing"
2004 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
2005 #define SLJIT_CPUINFO_PART2 "little endian + "
2006 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
2007 #define SLJIT_CPUINFO_PART2 "big endian + "
2009 #error "Internal error: CPU type info missing"
2012 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
2013 #define SLJIT_CPUINFO_PART3 "unaligned)"
2015 #define SLJIT_CPUINFO_PART3 "aligned)"
2018 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
2020 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
2021 # include "sljitNativeX86_common.c"
2022 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2023 # include "sljitNativeARM_32.c"
2024 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
2025 # include "sljitNativeARM_32.c"
2026 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
2027 # include "sljitNativeARM_T2_32.c"
2028 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2029 # include "sljitNativeARM_64.c"
2030 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2031 # include "sljitNativePPC_common.c"
2032 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2033 # include "sljitNativeMIPS_common.c"
2034 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
2035 # include "sljitNativeSPARC_common.c"
2036 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
2037 # include "sljitNativeTILEGX_64.c"
2040 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2042 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2043 sljit_s32 src1, sljit_sw src1w,
2044 sljit_s32 src2, sljit_sw src2w)
2046 /* Default compare for most architectures. */
2047 sljit_s32 flags, tmp_src, condition;
2051 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
2053 condition = type & 0xff;
2054 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2055 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
2056 if ((src1 & SLJIT_IMM) && !src1w) {
2062 if ((src2 & SLJIT_IMM) && !src2w)
2063 return emit_cmp_to0(compiler, type, src1, src1w);
2067 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
2068 /* Immediate is prefered as second argument by most architectures. */
2069 switch (condition) {
2071 condition = SLJIT_GREATER;
2073 case SLJIT_GREATER_EQUAL:
2074 condition = SLJIT_LESS_EQUAL;
2077 condition = SLJIT_LESS;
2079 case SLJIT_LESS_EQUAL:
2080 condition = SLJIT_GREATER_EQUAL;
2082 case SLJIT_SIG_LESS:
2083 condition = SLJIT_SIG_GREATER;
2085 case SLJIT_SIG_GREATER_EQUAL:
2086 condition = SLJIT_SIG_LESS_EQUAL;
2088 case SLJIT_SIG_GREATER:
2089 condition = SLJIT_SIG_LESS;
2091 case SLJIT_SIG_LESS_EQUAL:
2092 condition = SLJIT_SIG_GREATER_EQUAL;
2096 type = condition | (type & (SLJIT_I32_OP | SLJIT_REWRITABLE_JUMP));
2105 if (condition <= SLJIT_NOT_ZERO)
2106 flags = SLJIT_SET_Z;
2108 flags = condition << VARIABLE_FLAG_SHIFT;
2110 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2111 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2112 compiler->skip_checks = 1;
2114 PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_I32_OP),
2115 SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
2116 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2117 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2118 compiler->skip_checks = 1;
2120 return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
2125 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2126 sljit_s32 src1, sljit_sw src1w,
2127 sljit_s32 src2, sljit_sw src2w)
2130 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
2132 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2133 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2134 compiler->skip_checks = 1;
2136 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_I32_OP), src1, src1w, src2, src2w);
2138 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2139 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2140 compiler->skip_checks = 1;
2142 return sljit_emit_jump(compiler, type);
2145 #if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \
2146 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2147 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2149 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
2151 sljit_s32 mem, sljit_sw memw)
2153 SLJIT_UNUSED_ARG(compiler);
2154 SLJIT_UNUSED_ARG(type);
2155 SLJIT_UNUSED_ARG(reg);
2156 SLJIT_UNUSED_ARG(mem);
2157 SLJIT_UNUSED_ARG(memw);
2160 CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw));
2162 return SLJIT_ERR_UNSUPPORTED;
2167 #if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2168 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2170 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2172 sljit_s32 mem, sljit_sw memw)
2174 SLJIT_UNUSED_ARG(compiler);
2175 SLJIT_UNUSED_ARG(type);
2176 SLJIT_UNUSED_ARG(freg);
2177 SLJIT_UNUSED_ARG(mem);
2178 SLJIT_UNUSED_ARG(memw);
2181 CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
2183 return SLJIT_ERR_UNSUPPORTED;
2188 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2189 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2191 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2194 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2196 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
2197 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2198 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2199 compiler->skip_checks = 1;
2202 return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2203 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
2208 #else /* SLJIT_CONFIG_UNSUPPORTED */
2210 /* Empty function bodies for those machines, which are not (yet) supported. */
2212 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2214 return "unsupported";
2217 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
2219 SLJIT_UNUSED_ARG(allocator_data);
2220 SLJIT_UNREACHABLE();
2224 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
2226 SLJIT_UNUSED_ARG(compiler);
2227 SLJIT_UNREACHABLE();
2230 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
2232 SLJIT_UNUSED_ARG(compiler);
2233 SLJIT_UNREACHABLE();
2236 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
2238 SLJIT_UNUSED_ARG(compiler);
2239 SLJIT_UNUSED_ARG(size);
2240 SLJIT_UNREACHABLE();
2244 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2245 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
2247 SLJIT_UNUSED_ARG(compiler);
2248 SLJIT_UNUSED_ARG(verbose);
2249 SLJIT_UNREACHABLE();
2253 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
2255 SLJIT_UNUSED_ARG(compiler);
2256 SLJIT_UNREACHABLE();
2260 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
2262 SLJIT_UNUSED_ARG(feature_type);
2263 SLJIT_UNREACHABLE();
2267 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
2269 SLJIT_UNUSED_ARG(code);
2270 SLJIT_UNREACHABLE();
2273 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
2274 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2275 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2277 SLJIT_UNUSED_ARG(compiler);
2278 SLJIT_UNUSED_ARG(options);
2279 SLJIT_UNUSED_ARG(arg_types);
2280 SLJIT_UNUSED_ARG(scratches);
2281 SLJIT_UNUSED_ARG(saveds);
2282 SLJIT_UNUSED_ARG(fscratches);
2283 SLJIT_UNUSED_ARG(fsaveds);
2284 SLJIT_UNUSED_ARG(local_size);
2285 SLJIT_UNREACHABLE();
2286 return SLJIT_ERR_UNSUPPORTED;
2289 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
2290 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2291 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2293 SLJIT_UNUSED_ARG(compiler);
2294 SLJIT_UNUSED_ARG(options);
2295 SLJIT_UNUSED_ARG(arg_types);
2296 SLJIT_UNUSED_ARG(scratches);
2297 SLJIT_UNUSED_ARG(saveds);
2298 SLJIT_UNUSED_ARG(fscratches);
2299 SLJIT_UNUSED_ARG(fsaveds);
2300 SLJIT_UNUSED_ARG(local_size);
2301 SLJIT_UNREACHABLE();
2302 return SLJIT_ERR_UNSUPPORTED;
2305 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2307 SLJIT_UNUSED_ARG(compiler);
2308 SLJIT_UNUSED_ARG(op);
2309 SLJIT_UNUSED_ARG(src);
2310 SLJIT_UNUSED_ARG(srcw);
2311 SLJIT_UNREACHABLE();
2312 return SLJIT_ERR_UNSUPPORTED;
2315 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2317 SLJIT_UNUSED_ARG(compiler);
2318 SLJIT_UNUSED_ARG(dst);
2319 SLJIT_UNUSED_ARG(dstw);
2320 SLJIT_UNREACHABLE();
2321 return SLJIT_ERR_UNSUPPORTED;
2324 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
2326 SLJIT_UNUSED_ARG(compiler);
2327 SLJIT_UNUSED_ARG(src);
2328 SLJIT_UNUSED_ARG(srcw);
2329 SLJIT_UNREACHABLE();
2330 return SLJIT_ERR_UNSUPPORTED;
2333 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2335 SLJIT_UNUSED_ARG(compiler);
2336 SLJIT_UNUSED_ARG(op);
2337 SLJIT_UNREACHABLE();
2338 return SLJIT_ERR_UNSUPPORTED;
2341 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2342 sljit_s32 dst, sljit_sw dstw,
2343 sljit_s32 src, sljit_sw srcw)
2345 SLJIT_UNUSED_ARG(compiler);
2346 SLJIT_UNUSED_ARG(op);
2347 SLJIT_UNUSED_ARG(dst);
2348 SLJIT_UNUSED_ARG(dstw);
2349 SLJIT_UNUSED_ARG(src);
2350 SLJIT_UNUSED_ARG(srcw);
2351 SLJIT_UNREACHABLE();
2352 return SLJIT_ERR_UNSUPPORTED;
2355 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2356 sljit_s32 dst, sljit_sw dstw,
2357 sljit_s32 src1, sljit_sw src1w,
2358 sljit_s32 src2, sljit_sw src2w)
2360 SLJIT_UNUSED_ARG(compiler);
2361 SLJIT_UNUSED_ARG(op);
2362 SLJIT_UNUSED_ARG(dst);
2363 SLJIT_UNUSED_ARG(dstw);
2364 SLJIT_UNUSED_ARG(src1);
2365 SLJIT_UNUSED_ARG(src1w);
2366 SLJIT_UNUSED_ARG(src2);
2367 SLJIT_UNUSED_ARG(src2w);
2368 SLJIT_UNREACHABLE();
2369 return SLJIT_ERR_UNSUPPORTED;
2372 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2374 SLJIT_UNREACHABLE();
2378 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2379 void *instruction, sljit_s32 size)
2381 SLJIT_UNUSED_ARG(compiler);
2382 SLJIT_UNUSED_ARG(instruction);
2383 SLJIT_UNUSED_ARG(size);
2384 SLJIT_UNREACHABLE();
2385 return SLJIT_ERR_UNSUPPORTED;
2388 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2390 SLJIT_UNUSED_ARG(compiler);
2391 SLJIT_UNUSED_ARG(current_flags);
2394 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2395 sljit_s32 dst, sljit_sw dstw,
2396 sljit_s32 src, sljit_sw srcw)
2398 SLJIT_UNUSED_ARG(compiler);
2399 SLJIT_UNUSED_ARG(op);
2400 SLJIT_UNUSED_ARG(dst);
2401 SLJIT_UNUSED_ARG(dstw);
2402 SLJIT_UNUSED_ARG(src);
2403 SLJIT_UNUSED_ARG(srcw);
2404 SLJIT_UNREACHABLE();
2405 return SLJIT_ERR_UNSUPPORTED;
2408 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2409 sljit_s32 dst, sljit_sw dstw,
2410 sljit_s32 src1, sljit_sw src1w,
2411 sljit_s32 src2, sljit_sw src2w)
2413 SLJIT_UNUSED_ARG(compiler);
2414 SLJIT_UNUSED_ARG(op);
2415 SLJIT_UNUSED_ARG(dst);
2416 SLJIT_UNUSED_ARG(dstw);
2417 SLJIT_UNUSED_ARG(src1);
2418 SLJIT_UNUSED_ARG(src1w);
2419 SLJIT_UNUSED_ARG(src2);
2420 SLJIT_UNUSED_ARG(src2w);
2421 SLJIT_UNREACHABLE();
2422 return SLJIT_ERR_UNSUPPORTED;
2425 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2427 SLJIT_UNUSED_ARG(compiler);
2428 SLJIT_UNREACHABLE();
2432 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2434 SLJIT_UNUSED_ARG(compiler);
2435 SLJIT_UNUSED_ARG(type);
2436 SLJIT_UNREACHABLE();
2440 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
2441 sljit_s32 arg_types)
2443 SLJIT_UNUSED_ARG(compiler);
2444 SLJIT_UNUSED_ARG(type);
2445 SLJIT_UNUSED_ARG(arg_types);
2446 SLJIT_UNREACHABLE();
2450 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2451 sljit_s32 src1, sljit_sw src1w,
2452 sljit_s32 src2, sljit_sw src2w)
2454 SLJIT_UNUSED_ARG(compiler);
2455 SLJIT_UNUSED_ARG(type);
2456 SLJIT_UNUSED_ARG(src1);
2457 SLJIT_UNUSED_ARG(src1w);
2458 SLJIT_UNUSED_ARG(src2);
2459 SLJIT_UNUSED_ARG(src2w);
2460 SLJIT_UNREACHABLE();
2464 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2465 sljit_s32 src1, sljit_sw src1w,
2466 sljit_s32 src2, sljit_sw src2w)
2468 SLJIT_UNUSED_ARG(compiler);
2469 SLJIT_UNUSED_ARG(type);
2470 SLJIT_UNUSED_ARG(src1);
2471 SLJIT_UNUSED_ARG(src1w);
2472 SLJIT_UNUSED_ARG(src2);
2473 SLJIT_UNUSED_ARG(src2w);
2474 SLJIT_UNREACHABLE();
2478 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2480 SLJIT_UNUSED_ARG(jump);
2481 SLJIT_UNUSED_ARG(label);
2482 SLJIT_UNREACHABLE();
2485 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2487 SLJIT_UNUSED_ARG(jump);
2488 SLJIT_UNUSED_ARG(target);
2489 SLJIT_UNREACHABLE();
2492 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2494 SLJIT_UNUSED_ARG(compiler);
2495 SLJIT_UNUSED_ARG(type);
2496 SLJIT_UNUSED_ARG(src);
2497 SLJIT_UNUSED_ARG(srcw);
2498 SLJIT_UNREACHABLE();
2499 return SLJIT_ERR_UNSUPPORTED;
2502 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
2503 sljit_s32 arg_types,
2504 sljit_s32 src, sljit_sw srcw)
2506 SLJIT_UNUSED_ARG(compiler);
2507 SLJIT_UNUSED_ARG(type);
2508 SLJIT_UNUSED_ARG(arg_types);
2509 SLJIT_UNUSED_ARG(src);
2510 SLJIT_UNUSED_ARG(srcw);
2511 SLJIT_UNREACHABLE();
2512 return SLJIT_ERR_UNSUPPORTED;
2515 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2516 sljit_s32 dst, sljit_sw dstw,
2519 SLJIT_UNUSED_ARG(compiler);
2520 SLJIT_UNUSED_ARG(op);
2521 SLJIT_UNUSED_ARG(dst);
2522 SLJIT_UNUSED_ARG(dstw);
2523 SLJIT_UNUSED_ARG(type);
2524 SLJIT_UNREACHABLE();
2525 return SLJIT_ERR_UNSUPPORTED;
2528 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
2530 sljit_s32 src, sljit_sw srcw)
2532 SLJIT_UNUSED_ARG(compiler);
2533 SLJIT_UNUSED_ARG(type);
2534 SLJIT_UNUSED_ARG(dst_reg);
2535 SLJIT_UNUSED_ARG(src);
2536 SLJIT_UNUSED_ARG(srcw);
2537 SLJIT_UNREACHABLE();
2538 return SLJIT_ERR_UNSUPPORTED;
2541 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)
2543 SLJIT_UNUSED_ARG(compiler);
2544 SLJIT_UNUSED_ARG(type);
2545 SLJIT_UNUSED_ARG(reg);
2546 SLJIT_UNUSED_ARG(mem);
2547 SLJIT_UNUSED_ARG(memw);
2548 SLJIT_UNREACHABLE();
2549 return SLJIT_ERR_UNSUPPORTED;
2552 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)
2554 SLJIT_UNUSED_ARG(compiler);
2555 SLJIT_UNUSED_ARG(type);
2556 SLJIT_UNUSED_ARG(freg);
2557 SLJIT_UNUSED_ARG(mem);
2558 SLJIT_UNUSED_ARG(memw);
2559 SLJIT_UNREACHABLE();
2560 return SLJIT_ERR_UNSUPPORTED;
2563 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2565 SLJIT_UNUSED_ARG(compiler);
2566 SLJIT_UNUSED_ARG(dst);
2567 SLJIT_UNUSED_ARG(dstw);
2568 SLJIT_UNUSED_ARG(offset);
2569 SLJIT_UNREACHABLE();
2570 return SLJIT_ERR_UNSUPPORTED;
2573 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2575 SLJIT_UNUSED_ARG(compiler);
2576 SLJIT_UNUSED_ARG(dst);
2577 SLJIT_UNUSED_ARG(dstw);
2578 SLJIT_UNUSED_ARG(initval);
2579 SLJIT_UNREACHABLE();
2583 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2585 SLJIT_UNUSED_ARG(addr);
2586 SLJIT_UNUSED_ARG(new_target);
2587 SLJIT_UNUSED_ARG(executable_offset);
2588 SLJIT_UNREACHABLE();
2591 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2593 SLJIT_UNUSED_ARG(addr);
2594 SLJIT_UNUSED_ARG(new_constant);
2595 SLJIT_UNUSED_ARG(executable_offset);
2596 SLJIT_UNREACHABLE();