Rework function argument list descriptor macros.
[sljit.git] / sljit_src / sljitLir.c
blob37210c76b1fef3017fbe48d651e500c69707b933
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 VARIABLE_FLAG_SHIFT (10)
94 #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
95 #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
97 #define GET_OPCODE(op) \
98 ((op) & ~(SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
100 #define HAS_FLAGS(op) \
101 ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
103 #define GET_ALL_FLAGS(op) \
104 ((op) & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
106 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
107 #define TYPE_CAST_NEEDED(op) \
108 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32)
109 #else /* !SLJIT_64BIT_ARCHITECTURE */
110 #define TYPE_CAST_NEEDED(op) \
111 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16)
112 #endif /* SLJIT_64BIT_ARCHITECTURE */
114 #define BUF_SIZE 4096
116 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
117 #define ABUF_SIZE 2048
118 #else
119 #define ABUF_SIZE 4096
120 #endif
122 /* Parameter parsing. */
123 #define REG_MASK 0x3f
124 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
125 #define OFFS_REG_MASK (REG_MASK << 8)
126 #define TO_OFFS_REG(reg) ((reg) << 8)
127 /* When reg cannot be unused. */
128 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
130 /* Mask for argument types. */
131 #define SLJIT_ARG_MASK ((1 << SLJIT_ARG_SHIFT) - 1)
133 /* Jump flags. */
134 #define JUMP_LABEL 0x1
135 #define JUMP_ADDR 0x2
136 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
138 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
139 # define PATCH_MB 0x4
140 # define PATCH_MW 0x8
141 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
142 # define PATCH_MD 0x10
143 #endif
144 # define TYPE_SHIFT 13
145 #endif
147 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
148 # define IS_BL 0x4
149 # define PATCH_B 0x8
150 #endif
152 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
153 # define CPOOL_SIZE 512
154 #endif
156 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
157 # define IS_COND 0x04
158 # define IS_BL 0x08
159 /* conditional + imm8 */
160 # define PATCH_TYPE1 0x10
161 /* conditional + imm20 */
162 # define PATCH_TYPE2 0x20
163 /* IT + imm24 */
164 # define PATCH_TYPE3 0x30
165 /* imm11 */
166 # define PATCH_TYPE4 0x40
167 /* imm24 */
168 # define PATCH_TYPE5 0x50
169 /* BL + imm24 */
170 # define PATCH_BL 0x60
171 /* 0xf00 cc code for branches */
172 #endif
174 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
175 # define IS_COND 0x004
176 # define IS_CBZ 0x008
177 # define IS_BL 0x010
178 # define PATCH_B 0x020
179 # define PATCH_COND 0x040
180 # define PATCH_ABS48 0x080
181 # define PATCH_ABS64 0x100
182 #endif
184 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
185 # define IS_COND 0x004
186 # define IS_CALL 0x008
187 # define PATCH_B 0x010
188 # define PATCH_ABS_B 0x020
189 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
190 # define PATCH_ABS32 0x040
191 # define PATCH_ABS48 0x080
192 #endif
193 # define REMOVE_COND 0x100
194 #endif
196 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
197 # define IS_MOVABLE 0x004
198 # define IS_JAL 0x008
199 # define IS_CALL 0x010
200 # define IS_BIT26_COND 0x020
201 # define IS_BIT16_COND 0x040
202 # define IS_BIT23_COND 0x080
204 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND)
206 # define PATCH_B 0x100
207 # define PATCH_J 0x200
209 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
210 # define PATCH_ABS32 0x400
211 # define PATCH_ABS48 0x800
212 #endif
214 /* instruction types */
215 # define MOVABLE_INS 0
216 /* 1 - 31 last destination register */
217 /* no destination (i.e: store) */
218 # define UNMOVABLE_INS 32
219 /* FPU status register */
220 # define FCSR_FCC 33
221 #endif
223 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
224 # define IS_MOVABLE 0x04
225 # define IS_COND 0x08
226 # define IS_CALL 0x10
228 # define PATCH_B 0x20
229 # define PATCH_CALL 0x40
231 /* instruction types */
232 # define MOVABLE_INS 0
233 /* 1 - 31 last destination register */
234 /* no destination (i.e: store) */
235 # define UNMOVABLE_INS 32
237 # define DST_INS_MASK 0xff
239 /* ICC_SET is the same as SET_FLAGS. */
240 # define ICC_IS_SET (1 << 23)
241 # define FCC_IS_SET (1 << 24)
242 #endif
244 /* Stack management. */
246 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
247 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
248 (saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
249 extra) * sizeof(sljit_sw))
251 #define ADJUST_LOCAL_OFFSET(p, i) \
252 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
253 (i) += SLJIT_LOCALS_OFFSET;
255 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
257 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
258 #include "sljitUtils.c"
260 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
262 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
264 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
265 #include "sljitProtExecAllocator.c"
266 #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR)
267 #include "sljitWXExecAllocator.c"
268 #else
269 #include "sljitExecAllocator.c"
270 #endif
272 #endif
274 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
275 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
276 #else
277 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
278 #endif
280 #ifndef SLJIT_UPDATE_WX_FLAGS
281 #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)
282 #endif
284 /* Argument checking features. */
286 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
288 /* Returns with error when an invalid argument is passed. */
290 #define CHECK_ARGUMENT(x) \
291 do { \
292 if (SLJIT_UNLIKELY(!(x))) \
293 return 1; \
294 } while (0)
296 #define CHECK_RETURN_TYPE sljit_s32
297 #define CHECK_RETURN_OK return 0
299 #define CHECK(x) \
300 do { \
301 if (SLJIT_UNLIKELY(x)) { \
302 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
303 return SLJIT_ERR_BAD_ARGUMENT; \
305 } while (0)
307 #define CHECK_PTR(x) \
308 do { \
309 if (SLJIT_UNLIKELY(x)) { \
310 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
311 return NULL; \
313 } while (0)
315 #define CHECK_REG_INDEX(x) \
316 do { \
317 if (SLJIT_UNLIKELY(x)) { \
318 return -2; \
320 } while (0)
322 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
324 /* Assertion failure occures if an invalid argument is passed. */
325 #undef SLJIT_ARGUMENT_CHECKS
326 #define SLJIT_ARGUMENT_CHECKS 1
328 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
329 #define CHECK_RETURN_TYPE void
330 #define CHECK_RETURN_OK return
331 #define CHECK(x) x
332 #define CHECK_PTR(x) x
333 #define CHECK_REG_INDEX(x) x
335 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
337 /* Arguments are not checked. */
338 #define CHECK_RETURN_TYPE void
339 #define CHECK_RETURN_OK return
340 #define CHECK(x) x
341 #define CHECK_PTR(x) x
342 #define CHECK_REG_INDEX(x) x
344 #else
346 /* Arguments are not checked. */
347 #define CHECK(x)
348 #define CHECK_PTR(x)
349 #define CHECK_REG_INDEX(x)
351 #endif /* SLJIT_ARGUMENT_CHECKS */
353 /* --------------------------------------------------------------------- */
354 /* Public functions */
355 /* --------------------------------------------------------------------- */
357 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
358 #define SLJIT_NEEDS_COMPILER_INIT 1
359 static sljit_s32 compiler_initialized = 0;
360 /* A thread safe initialization. */
361 static void init_compiler(void);
362 #endif
364 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
366 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
367 if (!compiler)
368 return NULL;
369 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
371 SLJIT_COMPILE_ASSERT(
372 sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
373 && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
374 && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
375 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
376 && sizeof(sljit_p) <= sizeof(sljit_sw)
377 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
378 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
379 invalid_integer_types);
380 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_32,
381 rewritable_jump_and_single_op_must_not_be_the_same);
382 SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_EQUAL_F64 & 0x1) && !(SLJIT_JUMP & 0x1),
383 conditional_flags_must_be_even_numbers);
385 /* Only the non-zero members must be set. */
386 compiler->error = SLJIT_SUCCESS;
388 compiler->allocator_data = allocator_data;
389 compiler->exec_allocator_data = exec_allocator_data;
390 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
391 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
393 if (!compiler->buf || !compiler->abuf) {
394 if (compiler->buf)
395 SLJIT_FREE(compiler->buf, allocator_data);
396 if (compiler->abuf)
397 SLJIT_FREE(compiler->abuf, allocator_data);
398 SLJIT_FREE(compiler, allocator_data);
399 return NULL;
402 compiler->buf->next = NULL;
403 compiler->buf->used_size = 0;
404 compiler->abuf->next = NULL;
405 compiler->abuf->used_size = 0;
407 compiler->scratches = -1;
408 compiler->saveds = -1;
409 compiler->fscratches = -1;
410 compiler->fsaveds = -1;
411 compiler->local_size = -1;
413 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
414 compiler->args_size = -1;
415 #endif
417 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
418 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
419 + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
420 if (!compiler->cpool) {
421 SLJIT_FREE(compiler->buf, allocator_data);
422 SLJIT_FREE(compiler->abuf, allocator_data);
423 SLJIT_FREE(compiler, allocator_data);
424 return NULL;
426 compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
427 compiler->cpool_diff = 0xffffffff;
428 #endif
430 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
431 compiler->delay_slot = UNMOVABLE_INS;
432 #endif
434 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
435 compiler->delay_slot = UNMOVABLE_INS;
436 #endif
438 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
439 if (!compiler_initialized) {
440 init_compiler();
441 compiler_initialized = 1;
443 #endif
445 return compiler;
448 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
450 struct sljit_memory_fragment *buf;
451 struct sljit_memory_fragment *curr;
452 void *allocator_data = compiler->allocator_data;
453 SLJIT_UNUSED_ARG(allocator_data);
455 buf = compiler->buf;
456 while (buf) {
457 curr = buf;
458 buf = buf->next;
459 SLJIT_FREE(curr, allocator_data);
462 buf = compiler->abuf;
463 while (buf) {
464 curr = buf;
465 buf = buf->next;
466 SLJIT_FREE(curr, allocator_data);
469 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
470 SLJIT_FREE(compiler->cpool, allocator_data);
471 #endif
472 SLJIT_FREE(compiler, allocator_data);
475 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
477 if (compiler->error == SLJIT_SUCCESS)
478 compiler->error = SLJIT_ERR_ALLOC_FAILED;
481 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
482 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
484 SLJIT_UNUSED_ARG(exec_allocator_data);
486 /* Remove thumb mode flag. */
487 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1), exec_allocator_data);
489 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
490 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
492 SLJIT_UNUSED_ARG(exec_allocator_data);
494 /* Resolve indirection. */
495 code = (void*)(*(sljit_uw*)code);
496 SLJIT_FREE_EXEC(code, exec_allocator_data);
498 #else
499 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
501 SLJIT_UNUSED_ARG(exec_allocator_data);
503 SLJIT_FREE_EXEC(code, exec_allocator_data);
505 #endif
507 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
509 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
510 jump->flags &= ~JUMP_ADDR;
511 jump->flags |= JUMP_LABEL;
512 jump->u.label = label;
516 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
518 if (SLJIT_LIKELY(!!jump)) {
519 jump->flags &= ~JUMP_LABEL;
520 jump->flags |= JUMP_ADDR;
521 jump->u.target = target;
525 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
527 if (SLJIT_LIKELY(!!put_label))
528 put_label->label = label;
531 #define SLJIT_CURRENT_FLAGS_ALL \
532 (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD_SUB | SLJIT_CURRENT_FLAGS_COMPARE)
534 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
536 SLJIT_UNUSED_ARG(compiler);
537 SLJIT_UNUSED_ARG(current_flags);
539 #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
540 compiler->status_flags_state = current_flags;
541 #endif
543 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
544 compiler->last_flags = 0;
545 if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) {
546 compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z));
548 #endif
551 /* --------------------------------------------------------------------- */
552 /* Private functions */
553 /* --------------------------------------------------------------------- */
555 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
557 sljit_u8 *ret;
558 struct sljit_memory_fragment *new_frag;
560 SLJIT_ASSERT(size <= 256);
561 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
562 ret = compiler->buf->memory + compiler->buf->used_size;
563 compiler->buf->used_size += size;
564 return ret;
566 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
567 PTR_FAIL_IF_NULL(new_frag);
568 new_frag->next = compiler->buf;
569 compiler->buf = new_frag;
570 new_frag->used_size = size;
571 return new_frag->memory;
574 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
576 sljit_u8 *ret;
577 struct sljit_memory_fragment *new_frag;
579 SLJIT_ASSERT(size <= 256);
580 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
581 ret = compiler->abuf->memory + compiler->abuf->used_size;
582 compiler->abuf->used_size += size;
583 return ret;
585 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
586 PTR_FAIL_IF_NULL(new_frag);
587 new_frag->next = compiler->abuf;
588 compiler->abuf = new_frag;
589 new_frag->used_size = size;
590 return new_frag->memory;
593 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
595 CHECK_ERROR_PTR();
597 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
598 if (size <= 0 || size > 128)
599 return NULL;
600 size = (size + 7) & ~7;
601 #else
602 if (size <= 0 || size > 64)
603 return NULL;
604 size = (size + 3) & ~3;
605 #endif
606 return ensure_abuf(compiler, size);
609 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
611 struct sljit_memory_fragment *buf = compiler->buf;
612 struct sljit_memory_fragment *prev = NULL;
613 struct sljit_memory_fragment *tmp;
615 do {
616 tmp = buf->next;
617 buf->next = prev;
618 prev = buf;
619 buf = tmp;
620 } while (buf != NULL);
622 compiler->buf = prev;
625 /* Only used in RISC architectures where the instruction size is constant */
626 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
627 && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
629 static SLJIT_INLINE sljit_uw compute_next_addr(struct sljit_label *label, struct sljit_jump *jump,
630 struct sljit_const *const_, struct sljit_put_label *put_label)
632 sljit_uw result = ~(sljit_uw)0;
634 if (label)
635 result = label->size;
637 if (jump && jump->addr < result)
638 result = jump->addr;
640 if (const_ && const_->addr < result)
641 result = const_->addr;
643 if (put_label && put_label->addr < result)
644 result = put_label->addr;
646 return result;
649 #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X */
651 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
652 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
653 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
655 SLJIT_UNUSED_ARG(args);
656 SLJIT_UNUSED_ARG(local_size);
658 compiler->options = options;
659 compiler->scratches = scratches;
660 compiler->saveds = saveds;
661 compiler->fscratches = fscratches;
662 compiler->fsaveds = fsaveds;
663 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
664 compiler->logical_local_size = local_size;
665 #endif
668 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
669 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
670 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
672 SLJIT_UNUSED_ARG(args);
673 SLJIT_UNUSED_ARG(local_size);
675 compiler->options = options;
676 compiler->scratches = scratches;
677 compiler->saveds = saveds;
678 compiler->fscratches = fscratches;
679 compiler->fsaveds = fsaveds;
680 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
681 compiler->logical_local_size = local_size;
682 #endif
685 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
687 label->next = NULL;
688 label->size = compiler->size;
689 if (compiler->last_label)
690 compiler->last_label->next = label;
691 else
692 compiler->labels = label;
693 compiler->last_label = label;
696 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_s32 flags)
698 jump->next = NULL;
699 jump->flags = flags;
700 if (compiler->last_jump)
701 compiler->last_jump->next = jump;
702 else
703 compiler->jumps = jump;
704 compiler->last_jump = jump;
707 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
709 const_->next = NULL;
710 const_->addr = compiler->size;
711 if (compiler->last_const)
712 compiler->last_const->next = const_;
713 else
714 compiler->consts = const_;
715 compiler->last_const = const_;
718 static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
720 put_label->next = NULL;
721 put_label->label = NULL;
722 put_label->addr = compiler->size - offset;
723 put_label->flags = 0;
724 if (compiler->last_put_label)
725 compiler->last_put_label->next = put_label;
726 else
727 compiler->put_labels = put_label;
728 compiler->last_put_label = put_label;
731 #define ADDRESSING_DEPENDS_ON(exp, reg) \
732 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
734 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
736 #define FUNCTION_CHECK_IS_REG(r) \
737 (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
738 || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
740 #define FUNCTION_CHECK_IS_FREG(fr) \
741 (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
742 || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
744 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
745 #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
746 #else
747 #define CHECK_IF_VIRTUAL_REGISTER(p) 0
748 #endif
750 static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
752 if (compiler->scratches == -1 || compiler->saveds == -1)
753 return 0;
755 if (!(p & SLJIT_MEM))
756 return 0;
758 if (!(!(p & REG_MASK) || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
759 return 0;
761 if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
762 return 0;
764 if (p & OFFS_REG_MASK) {
765 if (!(p & REG_MASK))
766 return 0;
768 if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
769 return 0;
771 if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
772 return 0;
774 if ((i & ~0x3) != 0)
775 return 0;
778 return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
781 #define FUNCTION_CHECK_SRC_MEM(p, i) \
782 CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
784 static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
786 if (compiler->scratches == -1 || compiler->saveds == -1)
787 return 0;
789 if (FUNCTION_CHECK_IS_REG(p))
790 return (i == 0);
792 if (p == SLJIT_IMM)
793 return 1;
795 if (p == SLJIT_MEM1(SLJIT_SP))
796 return (i >= 0 && i < compiler->logical_local_size);
798 return function_check_src_mem(compiler, p, i);
801 #define FUNCTION_CHECK_SRC(p, i) \
802 CHECK_ARGUMENT(function_check_src(compiler, p, i));
804 static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
806 if (compiler->scratches == -1 || compiler->saveds == -1)
807 return 0;
809 if (FUNCTION_CHECK_IS_REG(p))
810 return (i == 0);
812 if (p == SLJIT_MEM1(SLJIT_SP))
813 return (i >= 0 && i < compiler->logical_local_size);
815 return function_check_src_mem(compiler, p, i);
818 #define FUNCTION_CHECK_DST(p, i) \
819 CHECK_ARGUMENT(function_check_dst(compiler, p, i));
821 static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
823 if (compiler->scratches == -1 || compiler->saveds == -1)
824 return 0;
826 if (FUNCTION_CHECK_IS_FREG(p))
827 return (i == 0);
829 if (p == SLJIT_MEM1(SLJIT_SP))
830 return (i >= 0 && i < compiler->logical_local_size);
832 return function_check_src_mem(compiler, p, i);
835 #define FUNCTION_FCHECK(p, i) \
836 CHECK_ARGUMENT(function_fcheck(compiler, p, i));
838 #endif /* SLJIT_ARGUMENT_CHECKS */
840 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
842 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
844 compiler->verbose = verbose;
847 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
848 #ifdef _WIN64
849 # define SLJIT_PRINT_D "I64"
850 #else
851 # define SLJIT_PRINT_D "l"
852 #endif
853 #else
854 # define SLJIT_PRINT_D ""
855 #endif
857 static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
859 if (r < (SLJIT_R0 + compiler->scratches))
860 fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
861 else if (r != SLJIT_SP)
862 fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
863 else
864 fprintf(compiler->verbose, "sp");
867 static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
869 if (r < (SLJIT_FR0 + compiler->fscratches))
870 fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
871 else
872 fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
875 static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
877 if ((p) & SLJIT_IMM)
878 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
879 else if ((p) & SLJIT_MEM) {
880 if ((p) & REG_MASK) {
881 fputc('[', compiler->verbose);
882 sljit_verbose_reg(compiler, (p) & REG_MASK);
883 if ((p) & OFFS_REG_MASK) {
884 fprintf(compiler->verbose, " + ");
885 sljit_verbose_reg(compiler, OFFS_REG(p));
886 if (i)
887 fprintf(compiler->verbose, " * %d", 1 << (i));
889 else if (i)
890 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
891 fputc(']', compiler->verbose);
893 else
894 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
895 } else
896 sljit_verbose_reg(compiler, p);
899 static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
901 if ((p) & SLJIT_MEM) {
902 if ((p) & REG_MASK) {
903 fputc('[', compiler->verbose);
904 sljit_verbose_reg(compiler, (p) & REG_MASK);
905 if ((p) & OFFS_REG_MASK) {
906 fprintf(compiler->verbose, " + ");
907 sljit_verbose_reg(compiler, OFFS_REG(p));
908 if (i)
909 fprintf(compiler->verbose, "%d", 1 << (i));
911 else if (i)
912 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
913 fputc(']', compiler->verbose);
915 else
916 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
918 else
919 sljit_verbose_freg(compiler, p);
922 static const char* op0_names[] = {
923 "breakpoint", "nop", "lmul.uw", "lmul.sw",
924 "divmod.u", "divmod.s", "div.u", "div.s",
925 "endbr", "skip_frames_before_return"
928 static const char* op1_names[] = {
929 "", ".u8", ".s8", ".u16",
930 ".s16", ".u32", ".s32", "32",
931 ".p", "not", "neg", "clz",
934 static const char* op2_names[] = {
935 "add", "addc", "sub", "subc",
936 "mul", "and", "or", "xor",
937 "shl", "lshr", "ashr",
940 static const char* op_src_names[] = {
941 "fast_return", "skip_frames_before_fast_return",
942 "prefetch_l1", "prefetch_l2",
943 "prefetch_l3", "prefetch_once",
946 static const char* fop1_names[] = {
947 "mov", "conv", "conv", "conv",
948 "conv", "conv", "cmp", "neg",
949 "abs",
952 static const char* fop2_names[] = {
953 "add", "sub", "mul", "div"
956 #define JUMP_POSTFIX(type) \
957 ((type & 0xff) <= SLJIT_NOT_OVERFLOW ? ((type & SLJIT_32) ? "32" : "") \
958 : ((type & 0xff) <= SLJIT_ORDERED_F64 ? ((type & SLJIT_32) ? ".f32" : ".f64") : ""))
960 static const char* jump_names[] = {
961 "equal", "not_equal",
962 "less", "greater_equal",
963 "greater", "less_equal",
964 "sig_less", "sig_greater_equal",
965 "sig_greater", "sig_less_equal",
966 "overflow", "not_overflow",
967 "carry", "",
968 "equal", "not_equal",
969 "less", "greater_equal",
970 "greater", "less_equal",
971 "unordered", "ordered",
972 "jump", "fast_call",
973 "call", "call.cdecl"
976 static const char* call_arg_names[] = {
977 "void", "w", "32", "p", "f32", "f64"
980 #endif /* SLJIT_VERBOSE */
982 /* --------------------------------------------------------------------- */
983 /* Arch dependent */
984 /* --------------------------------------------------------------------- */
986 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
987 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
989 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
991 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
992 struct sljit_jump *jump;
993 #endif
995 SLJIT_UNUSED_ARG(compiler);
997 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
998 CHECK_ARGUMENT(compiler->size > 0);
999 jump = compiler->jumps;
1000 while (jump) {
1001 /* All jumps have target. */
1002 CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
1003 jump = jump->next;
1005 #endif
1006 CHECK_RETURN_OK;
1009 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
1010 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1011 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1013 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1014 sljit_s32 types, word_arg_count, float_arg_count, curr_type;
1015 #endif
1017 SLJIT_UNUSED_ARG(compiler);
1019 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1020 CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
1021 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1022 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
1023 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1024 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1025 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1026 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1027 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1028 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) <= SLJIT_ARG_TYPE_F64);
1030 types = (arg_types >> SLJIT_ARG_SHIFT);
1031 word_arg_count = 0;
1032 float_arg_count = 0;
1033 while (types != 0 && word_arg_count + float_arg_count < 4) {
1034 curr_type = (types & SLJIT_ARG_MASK);
1035 CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64 && curr_type > SLJIT_ARG_TYPE_VOID);
1037 if (curr_type < SLJIT_ARG_TYPE_F32)
1038 word_arg_count++;
1039 else
1040 float_arg_count++;
1042 types >>= SLJIT_ARG_SHIFT;
1044 CHECK_ARGUMENT(word_arg_count <= saveds);
1045 CHECK_ARGUMENT(float_arg_count <= fscratches);
1046 CHECK_ARGUMENT(types == 0);
1048 compiler->last_flags = 0;
1049 #endif
1050 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1051 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1052 fprintf(compiler->verbose, " enter options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : "");
1054 arg_types >>= SLJIT_ARG_SHIFT;
1055 while (arg_types) {
1056 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1057 arg_types >>= SLJIT_ARG_SHIFT;
1058 if (arg_types)
1059 fprintf(compiler->verbose, ",");
1062 fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
1063 scratches, saveds, fscratches, fsaveds, local_size);
1065 #endif
1066 CHECK_RETURN_OK;
1069 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
1070 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1071 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1073 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1074 sljit_s32 types, word_arg_count, float_arg_count, curr_type;
1075 #endif
1077 SLJIT_UNUSED_ARG(compiler);
1079 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1080 CHECK_ARGUMENT(!(options & ~SLJIT_F64_ALIGNMENT));
1081 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1082 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
1083 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1084 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1085 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1086 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1087 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1088 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) <= SLJIT_ARG_TYPE_F64);
1090 types = (arg_types >> SLJIT_ARG_SHIFT);
1091 word_arg_count = 0;
1092 float_arg_count = 0;
1093 while (types != 0 && word_arg_count + float_arg_count < 4) {
1094 curr_type = (types & SLJIT_ARG_MASK);
1095 CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64 && curr_type > SLJIT_ARG_TYPE_VOID);
1097 if (curr_type < SLJIT_ARG_TYPE_F32)
1098 word_arg_count++;
1099 else
1100 float_arg_count++;
1102 types >>= SLJIT_ARG_SHIFT;
1104 CHECK_ARGUMENT(word_arg_count <= saveds);
1105 CHECK_ARGUMENT(float_arg_count <= fscratches);
1106 CHECK_ARGUMENT(types == 0);
1108 compiler->last_flags = 0;
1109 #endif
1110 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1111 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1112 fprintf(compiler->verbose, " set_context options:%s args[", (options & SLJIT_F64_ALIGNMENT) ? "f64_align" : "");
1114 arg_types >>= SLJIT_ARG_SHIFT;
1115 while (arg_types) {
1116 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1117 arg_types >>= SLJIT_ARG_SHIFT;
1118 if (arg_types)
1119 fprintf(compiler->verbose, ",");
1122 fprintf(compiler->verbose, "] scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
1123 scratches, saveds, fscratches, fsaveds, local_size);
1125 #endif
1126 CHECK_RETURN_OK;
1129 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_compiler *compiler)
1131 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1132 compiler->skip_checks = 0;
1133 CHECK_RETURN_OK;
1136 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1137 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1138 fprintf(compiler->verbose, " return_void\n");
1140 #endif
1141 CHECK_RETURN_OK;
1144 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1146 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1147 CHECK_ARGUMENT(compiler->scratches >= 0);
1148 CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
1149 FUNCTION_CHECK_SRC(src, srcw);
1150 compiler->last_flags = 0;
1151 #endif
1152 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1153 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1154 fprintf(compiler->verbose, " return%s ", op1_names[op - SLJIT_OP1_BASE]);
1155 sljit_verbose_param(compiler, src, srcw);
1156 fprintf(compiler->verbose, "\n");
1158 #endif
1159 CHECK_RETURN_OK;
1162 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1164 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1165 FUNCTION_CHECK_DST(dst, dstw);
1166 compiler->last_flags = 0;
1167 #endif
1168 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1169 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1170 fprintf(compiler->verbose, " fast_enter ");
1171 sljit_verbose_param(compiler, dst, dstw);
1172 fprintf(compiler->verbose, "\n");
1174 #endif
1175 CHECK_RETURN_OK;
1178 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1180 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1181 CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1182 || ((op & ~SLJIT_32) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_32) <= SLJIT_DIV_SW)
1183 || (op >= SLJIT_ENDBR && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN));
1184 CHECK_ARGUMENT(GET_OPCODE(op) < SLJIT_LMUL_UW || GET_OPCODE(op) >= SLJIT_ENDBR || compiler->scratches >= 2);
1185 if ((GET_OPCODE(op) >= SLJIT_LMUL_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN)
1186 compiler->last_flags = 0;
1187 #endif
1188 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1189 if (SLJIT_UNLIKELY(!!compiler->verbose))
1191 fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1192 if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) {
1193 fprintf(compiler->verbose, (op & SLJIT_32) ? "32" : "w");
1195 fprintf(compiler->verbose, "\n");
1197 #endif
1198 CHECK_RETURN_OK;
1201 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1202 sljit_s32 dst, sljit_sw dstw,
1203 sljit_s32 src, sljit_sw srcw)
1205 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1206 compiler->skip_checks = 0;
1207 CHECK_RETURN_OK;
1210 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1211 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1213 switch (GET_OPCODE(op)) {
1214 case SLJIT_NOT:
1215 /* Only SLJIT_32 and SLJIT_SET_Z are allowed. */
1216 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1217 break;
1218 case SLJIT_NEG:
1219 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1220 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1221 break;
1222 case SLJIT_MOV:
1223 case SLJIT_MOV_U32:
1224 case SLJIT_MOV_P:
1225 /* Nothing allowed */
1226 CHECK_ARGUMENT(!(op & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1227 break;
1228 default:
1229 /* Only SLJIT_32 is allowed. */
1230 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1231 break;
1234 FUNCTION_CHECK_DST(dst, dstw);
1235 FUNCTION_CHECK_SRC(src, srcw);
1237 if (GET_OPCODE(op) >= SLJIT_NOT) {
1238 CHECK_ARGUMENT(src != SLJIT_IMM);
1239 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1241 #endif
1242 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1243 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1244 if (GET_OPCODE(op) <= SLJIT_MOV_P)
1246 fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_32) ? "" : "32",
1247 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1249 else
1251 fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_32) ? "" : "32",
1252 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1253 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1256 sljit_verbose_param(compiler, dst, dstw);
1257 fprintf(compiler->verbose, ", ");
1258 sljit_verbose_param(compiler, src, srcw);
1259 fprintf(compiler->verbose, "\n");
1261 #endif
1262 CHECK_RETURN_OK;
1265 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset,
1266 sljit_s32 dst, sljit_sw dstw,
1267 sljit_s32 src1, sljit_sw src1w,
1268 sljit_s32 src2, sljit_sw src2w)
1270 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1271 compiler->skip_checks = 0;
1272 CHECK_RETURN_OK;
1275 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1276 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1278 switch (GET_OPCODE(op)) {
1279 case SLJIT_AND:
1280 case SLJIT_OR:
1281 case SLJIT_XOR:
1282 case SLJIT_SHL:
1283 case SLJIT_LSHR:
1284 case SLJIT_ASHR:
1285 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1286 break;
1287 case SLJIT_MUL:
1288 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1289 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1290 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1291 break;
1292 case SLJIT_ADD:
1293 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1294 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1295 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1296 break;
1297 case SLJIT_SUB:
1298 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1299 || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1300 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1301 break;
1302 case SLJIT_ADDC:
1303 case SLJIT_SUBC:
1304 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1305 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1306 CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1307 CHECK_ARGUMENT((op & SLJIT_32) == (compiler->last_flags & SLJIT_32));
1308 break;
1309 default:
1310 SLJIT_UNREACHABLE();
1311 break;
1314 if (unset) {
1315 CHECK_ARGUMENT(HAS_FLAGS(op));
1316 } else {
1317 FUNCTION_CHECK_DST(dst, dstw);
1319 FUNCTION_CHECK_SRC(src1, src1w);
1320 FUNCTION_CHECK_SRC(src2, src2w);
1321 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1322 #endif
1323 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1324 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1325 fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_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)]);
1328 if (unset)
1329 fprintf(compiler->verbose, "unset");
1330 else
1331 sljit_verbose_param(compiler, dst, dstw);
1332 fprintf(compiler->verbose, ", ");
1333 sljit_verbose_param(compiler, src1, src1w);
1334 fprintf(compiler->verbose, ", ");
1335 sljit_verbose_param(compiler, src2, src2w);
1336 fprintf(compiler->verbose, "\n");
1338 #endif
1339 CHECK_RETURN_OK;
1342 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
1343 sljit_s32 src, sljit_sw srcw)
1345 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1346 CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE);
1347 FUNCTION_CHECK_SRC(src, srcw);
1349 if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN)
1351 CHECK_ARGUMENT(src != SLJIT_IMM);
1352 compiler->last_flags = 0;
1354 else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE)
1356 CHECK_ARGUMENT(src & SLJIT_MEM);
1358 #endif
1359 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1360 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1361 fprintf(compiler->verbose, " %s ", op_src_names[op - SLJIT_OP_SRC_BASE]);
1362 sljit_verbose_param(compiler, src, srcw);
1363 fprintf(compiler->verbose, "\n");
1365 #endif
1366 CHECK_RETURN_OK;
1369 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1371 SLJIT_UNUSED_ARG(reg);
1372 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1373 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1374 #endif
1375 CHECK_RETURN_OK;
1378 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1380 SLJIT_UNUSED_ARG(reg);
1381 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1382 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1383 #endif
1384 CHECK_RETURN_OK;
1387 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1388 void *instruction, sljit_s32 size)
1390 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1391 int i;
1392 #endif
1394 SLJIT_UNUSED_ARG(compiler);
1396 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1397 CHECK_ARGUMENT(instruction);
1399 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1400 CHECK_ARGUMENT(size > 0 && size < 16);
1401 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1402 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1403 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1404 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
1405 CHECK_ARGUMENT(size == 2 || size == 4 || size == 6);
1406 #else
1407 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1408 #endif
1410 compiler->last_flags = 0;
1411 #endif
1412 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1413 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1414 fprintf(compiler->verbose, " op_custom");
1415 for (i = 0; i < size; i++)
1416 fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1417 fprintf(compiler->verbose, "\n");
1419 #endif
1420 CHECK_RETURN_OK;
1423 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1424 sljit_s32 dst, sljit_sw dstw,
1425 sljit_s32 src, sljit_sw srcw)
1427 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1428 compiler->skip_checks = 0;
1429 CHECK_RETURN_OK;
1432 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1433 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1434 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1435 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1436 FUNCTION_FCHECK(src, srcw);
1437 FUNCTION_FCHECK(dst, dstw);
1438 #endif
1439 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1440 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1441 if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1442 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1443 (op & SLJIT_32) ? ".f32.from.f64" : ".f64.from.f32");
1444 else
1445 fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1446 (op & SLJIT_32) ? ".f32" : ".f64");
1448 sljit_verbose_fparam(compiler, dst, dstw);
1449 fprintf(compiler->verbose, ", ");
1450 sljit_verbose_fparam(compiler, src, srcw);
1451 fprintf(compiler->verbose, "\n");
1453 #endif
1454 CHECK_RETURN_OK;
1457 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1458 sljit_s32 src1, sljit_sw src1w,
1459 sljit_s32 src2, sljit_sw src2w)
1461 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1462 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1463 #endif
1465 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1466 compiler->skip_checks = 0;
1467 CHECK_RETURN_OK;
1470 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1471 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1472 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1473 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1474 CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1475 || (GET_FLAG_TYPE(op) >= SLJIT_EQUAL_F64 && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_F64));
1476 FUNCTION_FCHECK(src1, src1w);
1477 FUNCTION_FCHECK(src2, src2w);
1478 #endif
1479 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1480 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1481 fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1482 if (op & VARIABLE_FLAG_MASK) {
1483 fprintf(compiler->verbose, ".%s_f", jump_names[GET_FLAG_TYPE(op)]);
1485 fprintf(compiler->verbose, " ");
1486 sljit_verbose_fparam(compiler, src1, src1w);
1487 fprintf(compiler->verbose, ", ");
1488 sljit_verbose_fparam(compiler, src2, src2w);
1489 fprintf(compiler->verbose, "\n");
1491 #endif
1492 CHECK_RETURN_OK;
1495 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1496 sljit_s32 dst, sljit_sw dstw,
1497 sljit_s32 src, sljit_sw srcw)
1499 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1500 compiler->skip_checks = 0;
1501 CHECK_RETURN_OK;
1504 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1505 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1506 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1507 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1508 FUNCTION_FCHECK(src, srcw);
1509 FUNCTION_CHECK_DST(dst, dstw);
1510 #endif
1511 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1512 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1513 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1514 (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1515 (op & SLJIT_32) ? ".f32" : ".f64");
1516 sljit_verbose_param(compiler, dst, dstw);
1517 fprintf(compiler->verbose, ", ");
1518 sljit_verbose_fparam(compiler, src, srcw);
1519 fprintf(compiler->verbose, "\n");
1521 #endif
1522 CHECK_RETURN_OK;
1525 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1526 sljit_s32 dst, sljit_sw dstw,
1527 sljit_s32 src, sljit_sw srcw)
1529 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1530 compiler->skip_checks = 0;
1531 CHECK_RETURN_OK;
1534 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1535 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1536 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1537 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1538 FUNCTION_CHECK_SRC(src, srcw);
1539 FUNCTION_FCHECK(dst, dstw);
1540 #endif
1541 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1542 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1543 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1544 (op & SLJIT_32) ? ".f32" : ".f64",
1545 (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1546 sljit_verbose_fparam(compiler, dst, dstw);
1547 fprintf(compiler->verbose, ", ");
1548 sljit_verbose_param(compiler, src, srcw);
1549 fprintf(compiler->verbose, "\n");
1551 #endif
1552 CHECK_RETURN_OK;
1555 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1556 sljit_s32 dst, sljit_sw dstw,
1557 sljit_s32 src1, sljit_sw src1w,
1558 sljit_s32 src2, sljit_sw src2w)
1560 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1561 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1562 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1563 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1564 FUNCTION_FCHECK(src1, src1w);
1565 FUNCTION_FCHECK(src2, src2w);
1566 FUNCTION_FCHECK(dst, dstw);
1567 #endif
1568 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1569 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1570 fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1571 sljit_verbose_fparam(compiler, dst, dstw);
1572 fprintf(compiler->verbose, ", ");
1573 sljit_verbose_fparam(compiler, src1, src1w);
1574 fprintf(compiler->verbose, ", ");
1575 sljit_verbose_fparam(compiler, src2, src2w);
1576 fprintf(compiler->verbose, "\n");
1578 #endif
1579 CHECK_RETURN_OK;
1582 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1584 SLJIT_UNUSED_ARG(compiler);
1586 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1587 compiler->skip_checks = 0;
1588 CHECK_RETURN_OK;
1591 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1592 compiler->last_flags = 0;
1593 #endif
1595 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1596 if (SLJIT_UNLIKELY(!!compiler->verbose))
1597 fprintf(compiler->verbose, "label:\n");
1598 #endif
1599 CHECK_RETURN_OK;
1602 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1604 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1605 compiler->skip_checks = 0;
1606 CHECK_RETURN_OK;
1609 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1610 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1611 CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1612 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
1613 CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_32));
1615 if ((type & 0xff) < SLJIT_JUMP) {
1616 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1617 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1618 else
1619 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1620 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW));
1622 #endif
1623 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1624 if (SLJIT_UNLIKELY(!!compiler->verbose))
1625 fprintf(compiler->verbose, " jump%s %s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1626 jump_names[type & 0xff], JUMP_POSTFIX(type));
1627 #endif
1628 CHECK_RETURN_OK;
1631 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
1632 sljit_s32 arg_types)
1634 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1635 sljit_s32 types, curr_type, word_arg_count, float_arg_count;
1637 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1638 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
1640 types = arg_types;
1642 curr_type = (types & SLJIT_ARG_MASK);
1644 if (curr_type >= SLJIT_ARG_TYPE_F32) {
1645 CHECK_ARGUMENT(compiler->fscratches > 0);
1646 } else if (curr_type >= SLJIT_ARG_TYPE_W) {
1647 CHECK_ARGUMENT(compiler->scratches > 0);
1650 types = (arg_types >> SLJIT_ARG_SHIFT);
1651 word_arg_count = 0;
1652 float_arg_count = 0;
1653 while (types != 0 && word_arg_count + float_arg_count < 4) {
1654 curr_type = (types & SLJIT_ARG_MASK);
1655 CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64 && curr_type > SLJIT_ARG_TYPE_VOID);
1657 if (curr_type < SLJIT_ARG_TYPE_F32)
1658 word_arg_count++;
1659 else
1660 float_arg_count++;
1662 types >>= SLJIT_ARG_SHIFT;
1665 CHECK_ARGUMENT(compiler->scratches >= word_arg_count);
1666 CHECK_ARGUMENT(compiler->fscratches >= float_arg_count);
1667 CHECK_ARGUMENT(types == 0);
1668 #endif
1669 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1670 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1671 fprintf(compiler->verbose, " %s%s ret[%s", jump_names[type & 0xff],
1672 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1674 arg_types >>= SLJIT_ARG_SHIFT;
1675 if (arg_types) {
1676 fprintf(compiler->verbose, "], args[");
1677 do {
1678 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1679 arg_types >>= SLJIT_ARG_SHIFT;
1680 if (arg_types)
1681 fprintf(compiler->verbose, ",");
1682 } while (arg_types);
1684 fprintf(compiler->verbose, "]\n");
1686 #endif
1687 CHECK_RETURN_OK;
1690 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1691 sljit_s32 src1, sljit_sw src1w,
1692 sljit_s32 src2, sljit_sw src2w)
1694 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1695 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1696 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1697 FUNCTION_CHECK_SRC(src1, src1w);
1698 FUNCTION_CHECK_SRC(src2, src2w);
1699 compiler->last_flags = 0;
1700 #endif
1701 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1702 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1703 fprintf(compiler->verbose, " cmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1704 jump_names[type & 0xff], (type & SLJIT_32) ? "32" : "");
1705 sljit_verbose_param(compiler, src1, src1w);
1706 fprintf(compiler->verbose, ", ");
1707 sljit_verbose_param(compiler, src2, src2w);
1708 fprintf(compiler->verbose, "\n");
1710 #endif
1711 CHECK_RETURN_OK;
1714 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1715 sljit_s32 src1, sljit_sw src1w,
1716 sljit_s32 src2, sljit_sw src2w)
1718 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1719 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1720 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1721 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL_F64 && (type & 0xff) <= SLJIT_ORDERED_F64);
1722 FUNCTION_FCHECK(src1, src1w);
1723 FUNCTION_FCHECK(src2, src2w);
1724 compiler->last_flags = 0;
1725 #endif
1726 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1727 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1728 fprintf(compiler->verbose, " fcmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1729 jump_names[type & 0xff], (type & SLJIT_32) ? ".f32" : ".f64");
1730 sljit_verbose_fparam(compiler, src1, src1w);
1731 fprintf(compiler->verbose, ", ");
1732 sljit_verbose_fparam(compiler, src2, src2w);
1733 fprintf(compiler->verbose, "\n");
1735 #endif
1736 CHECK_RETURN_OK;
1739 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
1740 sljit_s32 src, sljit_sw srcw)
1742 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1743 compiler->skip_checks = 0;
1744 CHECK_RETURN_OK;
1747 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1748 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
1749 FUNCTION_CHECK_SRC(src, srcw);
1750 #endif
1751 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1752 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1753 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1754 sljit_verbose_param(compiler, src, srcw);
1755 fprintf(compiler->verbose, "\n");
1757 #endif
1758 CHECK_RETURN_OK;
1761 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
1762 sljit_s32 arg_types,
1763 sljit_s32 src, sljit_sw srcw)
1765 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1766 sljit_s32 types, curr_type, word_arg_count, float_arg_count;
1768 CHECK_ARGUMENT(type == SLJIT_CALL || type == SLJIT_CALL_CDECL);
1769 FUNCTION_CHECK_SRC(src, srcw);
1771 types = arg_types;
1773 curr_type = (types & SLJIT_ARG_MASK);
1775 if (curr_type >= SLJIT_ARG_TYPE_F32) {
1776 CHECK_ARGUMENT(compiler->fscratches > 0);
1777 } else if (curr_type >= SLJIT_ARG_TYPE_W) {
1778 CHECK_ARGUMENT(compiler->scratches > 0);
1781 types = (arg_types >> SLJIT_ARG_SHIFT);
1782 word_arg_count = 0;
1783 float_arg_count = 0;
1784 while (types != 0 && word_arg_count + float_arg_count < 4) {
1785 curr_type = (types & SLJIT_ARG_MASK);
1786 CHECK_ARGUMENT(curr_type <= SLJIT_ARG_TYPE_F64 && curr_type > SLJIT_ARG_TYPE_VOID);
1788 if (curr_type < SLJIT_ARG_TYPE_F32)
1789 word_arg_count++;
1790 else
1791 float_arg_count++;
1793 types >>= SLJIT_ARG_SHIFT;
1796 CHECK_ARGUMENT(compiler->scratches >= word_arg_count);
1797 CHECK_ARGUMENT(compiler->fscratches >= float_arg_count);
1798 CHECK_ARGUMENT(types == 0);
1799 #endif
1800 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1801 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1802 fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff],
1803 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1805 arg_types >>= SLJIT_ARG_SHIFT;
1806 if (arg_types) {
1807 fprintf(compiler->verbose, "], args[");
1808 do {
1809 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1810 arg_types >>= SLJIT_ARG_SHIFT;
1811 if (arg_types)
1812 fprintf(compiler->verbose, ",");
1813 } while (arg_types);
1815 fprintf(compiler->verbose, "], ");
1816 sljit_verbose_param(compiler, src, srcw);
1817 fprintf(compiler->verbose, "\n");
1819 #endif
1820 CHECK_RETURN_OK;
1823 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1824 sljit_s32 dst, sljit_sw dstw,
1825 sljit_s32 type)
1827 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1828 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_32)));
1829 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1830 CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1831 CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1832 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1833 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1835 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1836 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1837 else
1838 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1839 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW));
1841 FUNCTION_CHECK_DST(dst, dstw);
1843 if (GET_OPCODE(op) >= SLJIT_ADD)
1844 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1845 #endif
1846 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1847 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1848 fprintf(compiler->verbose, " flags%s %s%s, ",
1849 !(op & SLJIT_SET_Z) ? "" : ".z",
1850 GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1851 GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_32) ? "32" : ""));
1852 sljit_verbose_param(compiler, dst, dstw);
1853 fprintf(compiler->verbose, ", %s%s\n", jump_names[type & 0xff], JUMP_POSTFIX(type));
1855 #endif
1856 CHECK_RETURN_OK;
1859 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1860 sljit_s32 dst_reg,
1861 sljit_s32 src, sljit_sw srcw)
1863 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1864 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_32)));
1865 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1867 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
1868 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_32));
1869 if (src != SLJIT_IMM) {
1870 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
1871 CHECK_ARGUMENT(srcw == 0);
1874 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1875 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1876 else
1877 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1878 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW));
1879 #endif
1880 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1881 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1882 fprintf(compiler->verbose, " cmov%s %s%s, ",
1883 !(dst_reg & SLJIT_32) ? "" : "32",
1884 jump_names[type & 0xff], JUMP_POSTFIX(type));
1885 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_32);
1886 fprintf(compiler->verbose, ", ");
1887 sljit_verbose_param(compiler, src, srcw);
1888 fprintf(compiler->verbose, "\n");
1890 #endif
1891 CHECK_RETURN_OK;
1894 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
1895 sljit_s32 reg,
1896 sljit_s32 mem, sljit_sw memw)
1898 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1899 CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
1900 CHECK_ARGUMENT(!(type & SLJIT_32) || ((type & 0xff) != SLJIT_MOV && (type & 0xff) != SLJIT_MOV_U32 && (type & 0xff) != SLJIT_MOV_P));
1901 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1902 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1903 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1905 FUNCTION_CHECK_SRC_MEM(mem, memw);
1906 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
1908 CHECK_ARGUMENT((mem & REG_MASK) != 0 && (mem & REG_MASK) != reg);
1909 #endif
1910 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1911 if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
1912 if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
1913 fprintf(compiler->verbose, " //");
1915 fprintf(compiler->verbose, " mem%s.%s%s%s ",
1916 !(type & SLJIT_32) ? "" : "32",
1917 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1918 op1_names[(type & 0xff) - SLJIT_OP1_BASE],
1919 (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
1920 sljit_verbose_reg(compiler, reg);
1921 fprintf(compiler->verbose, ", ");
1922 sljit_verbose_param(compiler, mem, memw);
1923 fprintf(compiler->verbose, "\n");
1925 #endif
1926 CHECK_RETURN_OK;
1929 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
1930 sljit_s32 freg,
1931 sljit_s32 mem, sljit_sw memw)
1933 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1934 CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
1935 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1936 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1937 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1939 FUNCTION_CHECK_SRC_MEM(mem, memw);
1940 CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
1941 #endif
1942 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1943 if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
1944 if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
1945 fprintf(compiler->verbose, " //");
1947 fprintf(compiler->verbose, " fmem.%s%s%s ",
1948 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1949 !(type & SLJIT_32) ? ".f64" : ".f32",
1950 (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
1951 sljit_verbose_freg(compiler, freg);
1952 fprintf(compiler->verbose, ", ");
1953 sljit_verbose_param(compiler, mem, memw);
1954 fprintf(compiler->verbose, "\n");
1956 #endif
1957 CHECK_RETURN_OK;
1960 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
1962 /* Any offset is allowed. */
1963 SLJIT_UNUSED_ARG(offset);
1965 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1966 FUNCTION_CHECK_DST(dst, dstw);
1967 #endif
1968 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1969 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1970 fprintf(compiler->verbose, " local_base ");
1971 sljit_verbose_param(compiler, dst, dstw);
1972 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1974 #endif
1975 CHECK_RETURN_OK;
1978 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
1980 SLJIT_UNUSED_ARG(init_value);
1982 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1983 FUNCTION_CHECK_DST(dst, dstw);
1984 #endif
1985 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1986 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1987 fprintf(compiler->verbose, " const ");
1988 sljit_verbose_param(compiler, dst, dstw);
1989 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1991 #endif
1992 CHECK_RETURN_OK;
1995 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1997 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1998 FUNCTION_CHECK_DST(dst, dstw);
1999 #endif
2000 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2001 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2002 fprintf(compiler->verbose, " put_label ");
2003 sljit_verbose_param(compiler, dst, dstw);
2004 fprintf(compiler->verbose, "\n");
2006 #endif
2007 CHECK_RETURN_OK;
2010 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
2012 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
2013 SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
2014 invalid_float_opcodes); \
2015 if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
2016 if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
2017 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
2018 ADJUST_LOCAL_OFFSET(dst, dstw); \
2019 ADJUST_LOCAL_OFFSET(src, srcw); \
2020 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
2022 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
2023 CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
2024 ADJUST_LOCAL_OFFSET(dst, dstw); \
2025 ADJUST_LOCAL_OFFSET(src, srcw); \
2026 return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
2028 CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
2029 ADJUST_LOCAL_OFFSET(dst, dstw); \
2030 ADJUST_LOCAL_OFFSET(src, srcw); \
2031 return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
2033 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
2034 ADJUST_LOCAL_OFFSET(dst, dstw); \
2035 ADJUST_LOCAL_OFFSET(src, srcw);
2037 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2039 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2040 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
2041 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
2042 return SLJIT_SUCCESS;
2043 #else
2044 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
2045 return SLJIT_SUCCESS;
2046 #endif
2048 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2049 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2050 compiler->skip_checks = 1;
2051 #endif
2052 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
2055 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
2057 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2059 CHECK_ERROR();
2060 CHECK(check_sljit_emit_return(compiler, op, src, srcw));
2062 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
2064 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2065 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2066 compiler->skip_checks = 1;
2067 #endif
2068 return sljit_emit_return_void(compiler);
2071 #endif
2073 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2074 || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
2075 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
2076 || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6))
2078 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
2079 sljit_s32 dst_reg,
2080 sljit_s32 src, sljit_sw srcw)
2082 struct sljit_label *label;
2083 struct sljit_jump *jump;
2084 sljit_s32 op = (dst_reg & SLJIT_32) ? SLJIT_MOV32 : SLJIT_MOV;
2086 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2087 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2088 compiler->skip_checks = 1;
2089 #endif
2090 jump = sljit_emit_jump(compiler, type ^ 0x1);
2091 FAIL_IF(!jump);
2093 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2094 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2095 compiler->skip_checks = 1;
2096 #endif
2097 FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_32, 0, src, srcw));
2099 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2100 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2101 compiler->skip_checks = 1;
2102 #endif
2103 label = sljit_emit_label(compiler);
2104 FAIL_IF(!label);
2105 sljit_set_label(jump, label);
2106 return SLJIT_SUCCESS;
2109 #endif
2111 /* CPU description section */
2113 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
2114 #define SLJIT_CPUINFO_PART1 " 32bit ("
2115 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2116 #define SLJIT_CPUINFO_PART1 " 64bit ("
2117 #else
2118 #error "Internal error: CPU type info missing"
2119 #endif
2121 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
2122 #define SLJIT_CPUINFO_PART2 "little endian + "
2123 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
2124 #define SLJIT_CPUINFO_PART2 "big endian + "
2125 #else
2126 #error "Internal error: CPU type info missing"
2127 #endif
2129 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
2130 #define SLJIT_CPUINFO_PART3 "unaligned)"
2131 #else
2132 #define SLJIT_CPUINFO_PART3 "aligned)"
2133 #endif
2135 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
2137 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
2138 # include "sljitNativeX86_common.c"
2139 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2140 # include "sljitNativeARM_32.c"
2141 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
2142 # include "sljitNativeARM_32.c"
2143 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
2144 # include "sljitNativeARM_T2_32.c"
2145 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2146 # include "sljitNativeARM_64.c"
2147 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2148 # include "sljitNativePPC_common.c"
2149 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2150 # include "sljitNativeMIPS_common.c"
2151 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
2152 # include "sljitNativeSPARC_common.c"
2153 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
2154 # include "sljitNativeS390X.c"
2155 #endif
2157 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2159 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2160 sljit_s32 src1, sljit_sw src1w,
2161 sljit_s32 src2, sljit_sw src2w)
2163 /* Default compare for most architectures. */
2164 sljit_s32 flags, tmp_src, condition;
2165 sljit_sw tmp_srcw;
2167 CHECK_ERROR_PTR();
2168 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
2170 condition = type & 0xff;
2171 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2172 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
2173 if ((src1 & SLJIT_IMM) && !src1w) {
2174 src1 = src2;
2175 src1w = src2w;
2176 src2 = SLJIT_IMM;
2177 src2w = 0;
2179 if ((src2 & SLJIT_IMM) && !src2w)
2180 return emit_cmp_to0(compiler, type, src1, src1w);
2182 #endif
2184 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
2185 /* Immediate is preferred as second argument by most architectures. */
2186 switch (condition) {
2187 case SLJIT_LESS:
2188 condition = SLJIT_GREATER;
2189 break;
2190 case SLJIT_GREATER_EQUAL:
2191 condition = SLJIT_LESS_EQUAL;
2192 break;
2193 case SLJIT_GREATER:
2194 condition = SLJIT_LESS;
2195 break;
2196 case SLJIT_LESS_EQUAL:
2197 condition = SLJIT_GREATER_EQUAL;
2198 break;
2199 case SLJIT_SIG_LESS:
2200 condition = SLJIT_SIG_GREATER;
2201 break;
2202 case SLJIT_SIG_GREATER_EQUAL:
2203 condition = SLJIT_SIG_LESS_EQUAL;
2204 break;
2205 case SLJIT_SIG_GREATER:
2206 condition = SLJIT_SIG_LESS;
2207 break;
2208 case SLJIT_SIG_LESS_EQUAL:
2209 condition = SLJIT_SIG_GREATER_EQUAL;
2210 break;
2213 type = condition | (type & (SLJIT_32 | SLJIT_REWRITABLE_JUMP));
2214 tmp_src = src1;
2215 src1 = src2;
2216 src2 = tmp_src;
2217 tmp_srcw = src1w;
2218 src1w = src2w;
2219 src2w = tmp_srcw;
2222 if (condition <= SLJIT_NOT_ZERO)
2223 flags = SLJIT_SET_Z;
2224 else
2225 flags = condition << VARIABLE_FLAG_SHIFT;
2227 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2228 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2229 compiler->skip_checks = 1;
2230 #endif
2231 PTR_FAIL_IF(sljit_emit_op2u(compiler,
2232 SLJIT_SUB | flags | (type & SLJIT_32), src1, src1w, src2, src2w));
2233 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2234 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2235 compiler->skip_checks = 1;
2236 #endif
2237 return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_32)));
2240 #endif
2242 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2243 sljit_s32 src1, sljit_sw src1w,
2244 sljit_s32 src2, sljit_sw src2w)
2246 CHECK_ERROR_PTR();
2247 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
2249 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2250 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2251 compiler->skip_checks = 1;
2252 #endif
2253 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_32), src1, src1w, src2, src2w);
2255 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2256 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2257 compiler->skip_checks = 1;
2258 #endif
2259 return sljit_emit_jump(compiler, type);
2262 #if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \
2263 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2264 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2266 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
2267 sljit_s32 reg,
2268 sljit_s32 mem, sljit_sw memw)
2270 SLJIT_UNUSED_ARG(compiler);
2271 SLJIT_UNUSED_ARG(type);
2272 SLJIT_UNUSED_ARG(reg);
2273 SLJIT_UNUSED_ARG(mem);
2274 SLJIT_UNUSED_ARG(memw);
2276 CHECK_ERROR();
2277 CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw));
2279 return SLJIT_ERR_UNSUPPORTED;
2282 #endif
2284 #if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2285 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2287 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2288 sljit_s32 freg,
2289 sljit_s32 mem, sljit_sw memw)
2291 SLJIT_UNUSED_ARG(compiler);
2292 SLJIT_UNUSED_ARG(type);
2293 SLJIT_UNUSED_ARG(freg);
2294 SLJIT_UNUSED_ARG(mem);
2295 SLJIT_UNUSED_ARG(memw);
2297 CHECK_ERROR();
2298 CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
2300 return SLJIT_ERR_UNSUPPORTED;
2303 #endif
2305 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2306 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2308 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2310 CHECK_ERROR();
2311 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2313 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
2314 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2315 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2316 compiler->skip_checks = 1;
2317 #endif
2318 if (offset != 0)
2319 return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2320 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
2323 #endif
2325 #else /* SLJIT_CONFIG_UNSUPPORTED */
2327 /* Empty function bodies for those machines, which are not (yet) supported. */
2329 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2331 return "unsupported";
2334 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
2336 SLJIT_UNUSED_ARG(allocator_data);
2337 SLJIT_UNUSED_ARG(exec_allocator_data);
2338 SLJIT_UNREACHABLE();
2339 return NULL;
2342 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
2344 SLJIT_UNUSED_ARG(compiler);
2345 SLJIT_UNREACHABLE();
2348 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
2350 SLJIT_UNUSED_ARG(compiler);
2351 SLJIT_UNREACHABLE();
2354 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
2356 SLJIT_UNUSED_ARG(compiler);
2357 SLJIT_UNUSED_ARG(size);
2358 SLJIT_UNREACHABLE();
2359 return NULL;
2362 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2363 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
2365 SLJIT_UNUSED_ARG(compiler);
2366 SLJIT_UNUSED_ARG(verbose);
2367 SLJIT_UNREACHABLE();
2369 #endif
2371 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
2373 SLJIT_UNUSED_ARG(compiler);
2374 SLJIT_UNREACHABLE();
2375 return NULL;
2378 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
2380 SLJIT_UNUSED_ARG(feature_type);
2381 SLJIT_UNREACHABLE();
2382 return 0;
2385 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
2387 SLJIT_UNUSED_ARG(code);
2388 SLJIT_UNUSED_ARG(exec_allocator_data);
2389 SLJIT_UNREACHABLE();
2392 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
2393 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2394 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2396 SLJIT_UNUSED_ARG(compiler);
2397 SLJIT_UNUSED_ARG(options);
2398 SLJIT_UNUSED_ARG(arg_types);
2399 SLJIT_UNUSED_ARG(scratches);
2400 SLJIT_UNUSED_ARG(saveds);
2401 SLJIT_UNUSED_ARG(fscratches);
2402 SLJIT_UNUSED_ARG(fsaveds);
2403 SLJIT_UNUSED_ARG(local_size);
2404 SLJIT_UNREACHABLE();
2405 return SLJIT_ERR_UNSUPPORTED;
2408 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
2409 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2410 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2412 SLJIT_UNUSED_ARG(compiler);
2413 SLJIT_UNUSED_ARG(options);
2414 SLJIT_UNUSED_ARG(arg_types);
2415 SLJIT_UNUSED_ARG(scratches);
2416 SLJIT_UNUSED_ARG(saveds);
2417 SLJIT_UNUSED_ARG(fscratches);
2418 SLJIT_UNUSED_ARG(fsaveds);
2419 SLJIT_UNUSED_ARG(local_size);
2420 SLJIT_UNREACHABLE();
2421 return SLJIT_ERR_UNSUPPORTED;
2424 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2426 SLJIT_UNUSED_ARG(compiler);
2427 SLJIT_UNUSED_ARG(op);
2428 SLJIT_UNUSED_ARG(src);
2429 SLJIT_UNUSED_ARG(srcw);
2430 SLJIT_UNREACHABLE();
2431 return SLJIT_ERR_UNSUPPORTED;
2434 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler)
2436 SLJIT_UNUSED_ARG(compiler);
2437 SLJIT_UNREACHABLE();
2438 return SLJIT_ERR_UNSUPPORTED;
2441 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2443 SLJIT_UNUSED_ARG(compiler);
2444 SLJIT_UNUSED_ARG(dst);
2445 SLJIT_UNUSED_ARG(dstw);
2446 SLJIT_UNREACHABLE();
2447 return SLJIT_ERR_UNSUPPORTED;
2450 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2452 SLJIT_UNUSED_ARG(compiler);
2453 SLJIT_UNUSED_ARG(op);
2454 SLJIT_UNREACHABLE();
2455 return SLJIT_ERR_UNSUPPORTED;
2458 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2459 sljit_s32 dst, sljit_sw dstw,
2460 sljit_s32 src, sljit_sw srcw)
2462 SLJIT_UNUSED_ARG(compiler);
2463 SLJIT_UNUSED_ARG(op);
2464 SLJIT_UNUSED_ARG(dst);
2465 SLJIT_UNUSED_ARG(dstw);
2466 SLJIT_UNUSED_ARG(src);
2467 SLJIT_UNUSED_ARG(srcw);
2468 SLJIT_UNREACHABLE();
2469 return SLJIT_ERR_UNSUPPORTED;
2472 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2473 sljit_s32 dst, sljit_sw dstw,
2474 sljit_s32 src1, sljit_sw src1w,
2475 sljit_s32 src2, sljit_sw src2w)
2477 SLJIT_UNUSED_ARG(compiler);
2478 SLJIT_UNUSED_ARG(op);
2479 SLJIT_UNUSED_ARG(dst);
2480 SLJIT_UNUSED_ARG(dstw);
2481 SLJIT_UNUSED_ARG(src1);
2482 SLJIT_UNUSED_ARG(src1w);
2483 SLJIT_UNUSED_ARG(src2);
2484 SLJIT_UNUSED_ARG(src2w);
2485 SLJIT_UNREACHABLE();
2486 return SLJIT_ERR_UNSUPPORTED;
2489 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,
2490 sljit_s32 src1, sljit_sw src1w,
2491 sljit_s32 src2, sljit_sw src2w)
2493 SLJIT_UNUSED_ARG(compiler);
2494 SLJIT_UNUSED_ARG(op);
2495 SLJIT_UNUSED_ARG(src1);
2496 SLJIT_UNUSED_ARG(src1w);
2497 SLJIT_UNUSED_ARG(src2);
2498 SLJIT_UNUSED_ARG(src2w);
2499 SLJIT_UNREACHABLE();
2500 return SLJIT_ERR_UNSUPPORTED;
2503 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
2504 sljit_s32 src, sljit_sw srcw)
2506 SLJIT_UNUSED_ARG(compiler);
2507 SLJIT_UNUSED_ARG(op);
2508 SLJIT_UNUSED_ARG(src);
2509 SLJIT_UNUSED_ARG(srcw);
2510 SLJIT_UNREACHABLE();
2511 return SLJIT_ERR_UNSUPPORTED;
2514 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2516 SLJIT_UNREACHABLE();
2517 return reg;
2520 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2521 void *instruction, sljit_s32 size)
2523 SLJIT_UNUSED_ARG(compiler);
2524 SLJIT_UNUSED_ARG(instruction);
2525 SLJIT_UNUSED_ARG(size);
2526 SLJIT_UNREACHABLE();
2527 return SLJIT_ERR_UNSUPPORTED;
2530 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2532 SLJIT_UNUSED_ARG(compiler);
2533 SLJIT_UNUSED_ARG(current_flags);
2536 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2537 sljit_s32 dst, sljit_sw dstw,
2538 sljit_s32 src, sljit_sw srcw)
2540 SLJIT_UNUSED_ARG(compiler);
2541 SLJIT_UNUSED_ARG(op);
2542 SLJIT_UNUSED_ARG(dst);
2543 SLJIT_UNUSED_ARG(dstw);
2544 SLJIT_UNUSED_ARG(src);
2545 SLJIT_UNUSED_ARG(srcw);
2546 SLJIT_UNREACHABLE();
2547 return SLJIT_ERR_UNSUPPORTED;
2550 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2551 sljit_s32 dst, sljit_sw dstw,
2552 sljit_s32 src1, sljit_sw src1w,
2553 sljit_s32 src2, sljit_sw src2w)
2555 SLJIT_UNUSED_ARG(compiler);
2556 SLJIT_UNUSED_ARG(op);
2557 SLJIT_UNUSED_ARG(dst);
2558 SLJIT_UNUSED_ARG(dstw);
2559 SLJIT_UNUSED_ARG(src1);
2560 SLJIT_UNUSED_ARG(src1w);
2561 SLJIT_UNUSED_ARG(src2);
2562 SLJIT_UNUSED_ARG(src2w);
2563 SLJIT_UNREACHABLE();
2564 return SLJIT_ERR_UNSUPPORTED;
2567 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2569 SLJIT_UNUSED_ARG(compiler);
2570 SLJIT_UNREACHABLE();
2571 return NULL;
2574 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2576 SLJIT_UNUSED_ARG(compiler);
2577 SLJIT_UNUSED_ARG(type);
2578 SLJIT_UNREACHABLE();
2579 return NULL;
2582 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
2583 sljit_s32 arg_types)
2585 SLJIT_UNUSED_ARG(compiler);
2586 SLJIT_UNUSED_ARG(type);
2587 SLJIT_UNUSED_ARG(arg_types);
2588 SLJIT_UNREACHABLE();
2589 return NULL;
2592 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2593 sljit_s32 src1, sljit_sw src1w,
2594 sljit_s32 src2, sljit_sw src2w)
2596 SLJIT_UNUSED_ARG(compiler);
2597 SLJIT_UNUSED_ARG(type);
2598 SLJIT_UNUSED_ARG(src1);
2599 SLJIT_UNUSED_ARG(src1w);
2600 SLJIT_UNUSED_ARG(src2);
2601 SLJIT_UNUSED_ARG(src2w);
2602 SLJIT_UNREACHABLE();
2603 return NULL;
2606 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2607 sljit_s32 src1, sljit_sw src1w,
2608 sljit_s32 src2, sljit_sw src2w)
2610 SLJIT_UNUSED_ARG(compiler);
2611 SLJIT_UNUSED_ARG(type);
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 NULL;
2620 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2622 SLJIT_UNUSED_ARG(jump);
2623 SLJIT_UNUSED_ARG(label);
2624 SLJIT_UNREACHABLE();
2627 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2629 SLJIT_UNUSED_ARG(jump);
2630 SLJIT_UNUSED_ARG(target);
2631 SLJIT_UNREACHABLE();
2634 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
2636 SLJIT_UNUSED_ARG(put_label);
2637 SLJIT_UNUSED_ARG(label);
2638 SLJIT_UNREACHABLE();
2641 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2643 SLJIT_UNUSED_ARG(compiler);
2644 SLJIT_UNUSED_ARG(type);
2645 SLJIT_UNUSED_ARG(src);
2646 SLJIT_UNUSED_ARG(srcw);
2647 SLJIT_UNREACHABLE();
2648 return SLJIT_ERR_UNSUPPORTED;
2651 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
2652 sljit_s32 arg_types,
2653 sljit_s32 src, sljit_sw srcw)
2655 SLJIT_UNUSED_ARG(compiler);
2656 SLJIT_UNUSED_ARG(type);
2657 SLJIT_UNUSED_ARG(arg_types);
2658 SLJIT_UNUSED_ARG(src);
2659 SLJIT_UNUSED_ARG(srcw);
2660 SLJIT_UNREACHABLE();
2661 return SLJIT_ERR_UNSUPPORTED;
2664 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2665 sljit_s32 dst, sljit_sw dstw,
2666 sljit_s32 type)
2668 SLJIT_UNUSED_ARG(compiler);
2669 SLJIT_UNUSED_ARG(op);
2670 SLJIT_UNUSED_ARG(dst);
2671 SLJIT_UNUSED_ARG(dstw);
2672 SLJIT_UNUSED_ARG(type);
2673 SLJIT_UNREACHABLE();
2674 return SLJIT_ERR_UNSUPPORTED;
2677 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
2678 sljit_s32 dst_reg,
2679 sljit_s32 src, sljit_sw srcw)
2681 SLJIT_UNUSED_ARG(compiler);
2682 SLJIT_UNUSED_ARG(type);
2683 SLJIT_UNUSED_ARG(dst_reg);
2684 SLJIT_UNUSED_ARG(src);
2685 SLJIT_UNUSED_ARG(srcw);
2686 SLJIT_UNREACHABLE();
2687 return SLJIT_ERR_UNSUPPORTED;
2690 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)
2692 SLJIT_UNUSED_ARG(compiler);
2693 SLJIT_UNUSED_ARG(type);
2694 SLJIT_UNUSED_ARG(reg);
2695 SLJIT_UNUSED_ARG(mem);
2696 SLJIT_UNUSED_ARG(memw);
2697 SLJIT_UNREACHABLE();
2698 return SLJIT_ERR_UNSUPPORTED;
2701 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)
2703 SLJIT_UNUSED_ARG(compiler);
2704 SLJIT_UNUSED_ARG(type);
2705 SLJIT_UNUSED_ARG(freg);
2706 SLJIT_UNUSED_ARG(mem);
2707 SLJIT_UNUSED_ARG(memw);
2708 SLJIT_UNREACHABLE();
2709 return SLJIT_ERR_UNSUPPORTED;
2712 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2714 SLJIT_UNUSED_ARG(compiler);
2715 SLJIT_UNUSED_ARG(dst);
2716 SLJIT_UNUSED_ARG(dstw);
2717 SLJIT_UNUSED_ARG(offset);
2718 SLJIT_UNREACHABLE();
2719 return SLJIT_ERR_UNSUPPORTED;
2722 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2724 SLJIT_UNUSED_ARG(compiler);
2725 SLJIT_UNUSED_ARG(dst);
2726 SLJIT_UNUSED_ARG(dstw);
2727 SLJIT_UNUSED_ARG(initval);
2728 SLJIT_UNREACHABLE();
2729 return NULL;
2732 SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2734 SLJIT_UNUSED_ARG(compiler);
2735 SLJIT_UNUSED_ARG(dst);
2736 SLJIT_UNUSED_ARG(dstw);
2737 return NULL;
2740 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2742 SLJIT_UNUSED_ARG(addr);
2743 SLJIT_UNUSED_ARG(new_target);
2744 SLJIT_UNUSED_ARG(executable_offset);
2745 SLJIT_UNREACHABLE();
2748 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2750 SLJIT_UNUSED_ARG(addr);
2751 SLJIT_UNUSED_ARG(new_constant);
2752 SLJIT_UNUSED_ARG(executable_offset);
2753 SLJIT_UNREACHABLE();
2756 #endif /* !SLJIT_CONFIG_UNSUPPORTED */