Fix x86 mem address encoding
[sljit.git] / sljit_src / sljitLir.c
blobe936e49297875406234c6ec758f7321e5f53c8aa
1 /*
2 * Stack-less Just-In-Time compiler
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "sljitLir.h"
29 #ifdef _WIN32
31 #include <windows.h>
33 #endif /* _WIN32 */
35 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
37 /* These libraries are needed for the macros below. */
38 #include <stdlib.h>
39 #include <string.h>
41 #endif /* SLJIT_STD_MACROS_DEFINED */
43 #define CHECK_ERROR() \
44 do { \
45 if (SLJIT_UNLIKELY(compiler->error)) \
46 return compiler->error; \
47 } while (0)
49 #define CHECK_ERROR_PTR() \
50 do { \
51 if (SLJIT_UNLIKELY(compiler->error)) \
52 return NULL; \
53 } while (0)
55 #define FAIL_IF(expr) \
56 do { \
57 if (SLJIT_UNLIKELY(expr)) \
58 return compiler->error; \
59 } while (0)
61 #define PTR_FAIL_IF(expr) \
62 do { \
63 if (SLJIT_UNLIKELY(expr)) \
64 return NULL; \
65 } while (0)
67 #define FAIL_IF_NULL(ptr) \
68 do { \
69 if (SLJIT_UNLIKELY(!(ptr))) { \
70 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
71 return SLJIT_ERR_ALLOC_FAILED; \
72 } \
73 } while (0)
75 #define PTR_FAIL_IF_NULL(ptr) \
76 do { \
77 if (SLJIT_UNLIKELY(!(ptr))) { \
78 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
79 return NULL; \
80 } \
81 } while (0)
83 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
84 do { \
85 if (SLJIT_UNLIKELY(!(ptr))) { \
86 compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
87 return NULL; \
88 } \
89 } while (0)
91 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
93 #define SSIZE_OF(type) ((sljit_s32)sizeof(sljit_ ## type))
95 #define VARIABLE_FLAG_SHIFT (10)
96 #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
97 #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
99 #define GET_OPCODE(op) \
100 ((op) & ~(SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
102 #define HAS_FLAGS(op) \
103 ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
105 #define GET_ALL_FLAGS(op) \
106 ((op) & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
108 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
109 #define TYPE_CAST_NEEDED(op) \
110 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S32)
111 #else /* !SLJIT_64BIT_ARCHITECTURE */
112 #define TYPE_CAST_NEEDED(op) \
113 ((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16)
114 #endif /* SLJIT_64BIT_ARCHITECTURE */
116 #define BUF_SIZE 4096
118 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
119 #define ABUF_SIZE 2048
120 #else
121 #define ABUF_SIZE 4096
122 #endif
124 /* Parameter parsing. */
125 #define REG_MASK 0x3f
126 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
127 #define OFFS_REG_MASK (REG_MASK << 8)
128 #define TO_OFFS_REG(reg) ((reg) << 8)
129 /* When reg cannot be unused. */
130 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
132 /* Mask for argument types. */
133 #define SLJIT_ARG_MASK 0x7
134 #define SLJIT_ARG_FULL_MASK (SLJIT_ARG_MASK | SLJIT_ARG_TYPE_SCRATCH_REG)
136 /* Mask for sljit_emit_enter. */
137 #define SLJIT_KEPT_SAVEDS_COUNT(options) ((options) & 0x3)
139 /* Jump flags. */
140 #define JUMP_LABEL 0x1
141 #define JUMP_ADDR 0x2
142 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
144 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
145 # define PATCH_MB 0x4
146 # define PATCH_MW 0x8
147 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
148 # define PATCH_MD 0x10
149 #endif
150 # define TYPE_SHIFT 13
151 #endif /* SLJIT_CONFIG_X86 */
153 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
154 # define IS_BL 0x4
155 # define PATCH_B 0x8
156 #endif /* SLJIT_CONFIG_ARM_V5 || SLJIT_CONFIG_ARM_V7 */
158 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
159 # define CPOOL_SIZE 512
160 #endif /* SLJIT_CONFIG_ARM_V5 */
162 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
163 # define IS_COND 0x04
164 # define IS_BL 0x08
165 /* conditional + imm8 */
166 # define PATCH_TYPE1 0x10
167 /* conditional + imm20 */
168 # define PATCH_TYPE2 0x20
169 /* IT + imm24 */
170 # define PATCH_TYPE3 0x30
171 /* imm11 */
172 # define PATCH_TYPE4 0x40
173 /* imm24 */
174 # define PATCH_TYPE5 0x50
175 /* BL + imm24 */
176 # define PATCH_BL 0x60
177 /* 0xf00 cc code for branches */
178 #endif /* SLJIT_CONFIG_ARM_THUMB2 */
180 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
181 # define IS_COND 0x004
182 # define IS_CBZ 0x008
183 # define IS_BL 0x010
184 # define PATCH_B 0x020
185 # define PATCH_COND 0x040
186 # define PATCH_ABS48 0x080
187 # define PATCH_ABS64 0x100
188 #endif /* SLJIT_CONFIG_ARM_64 */
190 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
191 # define IS_COND 0x004
192 # define IS_CALL 0x008
193 # define PATCH_B 0x010
194 # define PATCH_ABS_B 0x020
195 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
196 # define PATCH_ABS32 0x040
197 # define PATCH_ABS48 0x080
198 #endif /* SLJIT_CONFIG_PPC_64 */
199 # define REMOVE_COND 0x100
200 #endif /* SLJIT_CONFIG_PPC */
202 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
203 # define IS_MOVABLE 0x004
204 # define IS_JAL 0x008
205 # define IS_CALL 0x010
206 # define IS_BIT26_COND 0x020
207 # define IS_BIT16_COND 0x040
208 # define IS_BIT23_COND 0x080
210 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND)
212 # define PATCH_B 0x100
213 # define PATCH_J 0x200
215 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
216 # define PATCH_ABS32 0x400
217 # define PATCH_ABS48 0x800
218 #endif /* SLJIT_CONFIG_MIPS_64 */
220 /* instruction types */
221 # define MOVABLE_INS 0
222 /* 1 - 31 last destination register */
223 /* no destination (i.e: store) */
224 # define UNMOVABLE_INS 32
225 /* FPU status register */
226 # define FCSR_FCC 33
227 #endif /* SLJIT_CONFIG_MIPS */
229 #if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
230 # define IS_COND 0x004
231 # define IS_CALL 0x008
233 # define PATCH_B 0x010
234 # define PATCH_J 0x020
236 #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64)
237 # define PATCH_REL32 0x040
238 # define PATCH_ABS32 0x080
239 # define PATCH_ABS44 0x100
240 # define PATCH_ABS52 0x200
241 #else /* !SLJIT_CONFIG_RISCV_64 */
242 # define PATCH_REL32 0x0
243 #endif /* SLJIT_CONFIG_RISCV_64 */
244 #endif /* SLJIT_CONFIG_RISCV */
246 /* Stack management. */
248 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
249 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
250 (saveds) + (sljit_s32)(extra)) * (sljit_s32)sizeof(sljit_sw))
252 #define GET_SAVED_FLOAT_REGISTERS_SIZE(fscratches, fsaveds, size) \
253 (((fscratches < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS ? 0 : (fscratches - SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS)) + \
254 (fsaveds)) * (sljit_s32)(size))
256 #define ADJUST_LOCAL_OFFSET(p, i) \
257 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
258 (i) += SLJIT_LOCALS_OFFSET;
260 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
262 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
263 #include "sljitUtils.c"
265 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
267 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
269 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
270 #include "sljitProtExecAllocator.c"
271 #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR)
272 #include "sljitWXExecAllocator.c"
273 #else
274 #include "sljitExecAllocator.c"
275 #endif
277 #endif
279 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
280 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
281 #else
282 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
283 #endif
285 #ifndef SLJIT_UPDATE_WX_FLAGS
286 #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)
287 #endif
289 /* Argument checking features. */
291 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
293 /* Returns with error when an invalid argument is passed. */
295 #define CHECK_ARGUMENT(x) \
296 do { \
297 if (SLJIT_UNLIKELY(!(x))) \
298 return 1; \
299 } while (0)
301 #define CHECK_RETURN_TYPE sljit_s32
302 #define CHECK_RETURN_OK return 0
304 #define CHECK(x) \
305 do { \
306 if (SLJIT_UNLIKELY(x)) { \
307 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
308 return SLJIT_ERR_BAD_ARGUMENT; \
310 } while (0)
312 #define CHECK_PTR(x) \
313 do { \
314 if (SLJIT_UNLIKELY(x)) { \
315 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
316 return NULL; \
318 } while (0)
320 #define CHECK_REG_INDEX(x) \
321 do { \
322 if (SLJIT_UNLIKELY(x)) { \
323 return -2; \
325 } while (0)
327 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
329 /* Assertion failure occures if an invalid argument is passed. */
330 #undef SLJIT_ARGUMENT_CHECKS
331 #define SLJIT_ARGUMENT_CHECKS 1
333 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
334 #define CHECK_RETURN_TYPE void
335 #define CHECK_RETURN_OK return
336 #define CHECK(x) x
337 #define CHECK_PTR(x) x
338 #define CHECK_REG_INDEX(x) x
340 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
342 /* Arguments are not checked. */
343 #define CHECK_RETURN_TYPE void
344 #define CHECK_RETURN_OK return
345 #define CHECK(x) x
346 #define CHECK_PTR(x) x
347 #define CHECK_REG_INDEX(x) x
349 #else
351 /* Arguments are not checked. */
352 #define CHECK(x)
353 #define CHECK_PTR(x)
354 #define CHECK_REG_INDEX(x)
356 #endif /* SLJIT_ARGUMENT_CHECKS */
358 /* --------------------------------------------------------------------- */
359 /* Public functions */
360 /* --------------------------------------------------------------------- */
362 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
363 #define SLJIT_NEEDS_COMPILER_INIT 1
364 static sljit_s32 compiler_initialized = 0;
365 /* A thread safe initialization. */
366 static void init_compiler(void);
367 #endif
369 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
371 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
372 if (!compiler)
373 return NULL;
374 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
376 SLJIT_COMPILE_ASSERT(
377 sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
378 && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
379 && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
380 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
381 && sizeof(sljit_p) <= sizeof(sljit_sw)
382 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
383 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
384 invalid_integer_types);
385 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_32,
386 rewritable_jump_and_single_op_must_not_be_the_same);
387 SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_F_EQUAL & 0x1) && !(SLJIT_JUMP & 0x1),
388 conditional_flags_must_be_even_numbers);
390 /* Only the non-zero members must be set. */
391 compiler->error = SLJIT_SUCCESS;
393 compiler->allocator_data = allocator_data;
394 compiler->exec_allocator_data = exec_allocator_data;
395 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
396 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
398 if (!compiler->buf || !compiler->abuf) {
399 if (compiler->buf)
400 SLJIT_FREE(compiler->buf, allocator_data);
401 if (compiler->abuf)
402 SLJIT_FREE(compiler->abuf, allocator_data);
403 SLJIT_FREE(compiler, allocator_data);
404 return NULL;
407 compiler->buf->next = NULL;
408 compiler->buf->used_size = 0;
409 compiler->abuf->next = NULL;
410 compiler->abuf->used_size = 0;
412 compiler->scratches = -1;
413 compiler->saveds = -1;
414 compiler->fscratches = -1;
415 compiler->fsaveds = -1;
416 compiler->local_size = -1;
418 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
419 compiler->args_size = -1;
420 #endif
422 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
423 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
424 + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
425 if (!compiler->cpool) {
426 SLJIT_FREE(compiler->buf, allocator_data);
427 SLJIT_FREE(compiler->abuf, allocator_data);
428 SLJIT_FREE(compiler, allocator_data);
429 return NULL;
431 compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
432 compiler->cpool_diff = 0xffffffff;
433 #endif
435 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
436 compiler->delay_slot = UNMOVABLE_INS;
437 #endif
439 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
440 || (defined SLJIT_DEBUG && SLJIT_DEBUG)
441 compiler->last_flags = 0;
442 compiler->last_return = -1;
443 compiler->logical_local_size = 0;
444 #endif
446 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
447 if (!compiler_initialized) {
448 init_compiler();
449 compiler_initialized = 1;
451 #endif
453 return compiler;
456 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
458 struct sljit_memory_fragment *buf;
459 struct sljit_memory_fragment *curr;
460 void *allocator_data = compiler->allocator_data;
461 SLJIT_UNUSED_ARG(allocator_data);
463 buf = compiler->buf;
464 while (buf) {
465 curr = buf;
466 buf = buf->next;
467 SLJIT_FREE(curr, allocator_data);
470 buf = compiler->abuf;
471 while (buf) {
472 curr = buf;
473 buf = buf->next;
474 SLJIT_FREE(curr, allocator_data);
477 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
478 SLJIT_FREE(compiler->cpool, allocator_data);
479 #endif
480 SLJIT_FREE(compiler, allocator_data);
483 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
485 if (compiler->error == SLJIT_SUCCESS)
486 compiler->error = SLJIT_ERR_ALLOC_FAILED;
489 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
490 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
492 SLJIT_UNUSED_ARG(exec_allocator_data);
494 /* Remove thumb mode flag. */
495 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~(sljit_uw)0x1), exec_allocator_data);
497 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
498 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
500 SLJIT_UNUSED_ARG(exec_allocator_data);
502 /* Resolve indirection. */
503 code = (void*)(*(sljit_uw*)code);
504 SLJIT_FREE_EXEC(code, exec_allocator_data);
506 #else
507 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
509 SLJIT_UNUSED_ARG(exec_allocator_data);
511 SLJIT_FREE_EXEC(code, exec_allocator_data);
513 #endif
515 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
517 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
518 jump->flags &= (sljit_uw)~JUMP_ADDR;
519 jump->flags |= JUMP_LABEL;
520 jump->u.label = label;
524 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
526 if (SLJIT_LIKELY(!!jump)) {
527 jump->flags &= (sljit_uw)~JUMP_LABEL;
528 jump->flags |= JUMP_ADDR;
529 jump->u.target = target;
533 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
535 if (SLJIT_LIKELY(!!put_label))
536 put_label->label = label;
539 #define SLJIT_CURRENT_FLAGS_ALL \
540 (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE)
542 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
544 SLJIT_UNUSED_ARG(compiler);
545 SLJIT_UNUSED_ARG(current_flags);
547 #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
548 compiler->status_flags_state = current_flags;
549 #endif
551 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
552 compiler->last_flags = 0;
553 if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) {
554 compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z));
556 #endif
559 /* --------------------------------------------------------------------- */
560 /* Private functions */
561 /* --------------------------------------------------------------------- */
563 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
565 sljit_u8 *ret;
566 struct sljit_memory_fragment *new_frag;
568 SLJIT_ASSERT(size <= 256);
569 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
570 ret = compiler->buf->memory + compiler->buf->used_size;
571 compiler->buf->used_size += size;
572 return ret;
574 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
575 PTR_FAIL_IF_NULL(new_frag);
576 new_frag->next = compiler->buf;
577 compiler->buf = new_frag;
578 new_frag->used_size = size;
579 return new_frag->memory;
582 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
584 sljit_u8 *ret;
585 struct sljit_memory_fragment *new_frag;
587 SLJIT_ASSERT(size <= 256);
588 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
589 ret = compiler->abuf->memory + compiler->abuf->used_size;
590 compiler->abuf->used_size += size;
591 return ret;
593 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
594 PTR_FAIL_IF_NULL(new_frag);
595 new_frag->next = compiler->abuf;
596 compiler->abuf = new_frag;
597 new_frag->used_size = size;
598 return new_frag->memory;
601 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
603 CHECK_ERROR_PTR();
605 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
606 if (size <= 0 || size > 128)
607 return NULL;
608 size = (size + 7) & ~7;
609 #else
610 if (size <= 0 || size > 64)
611 return NULL;
612 size = (size + 3) & ~3;
613 #endif
614 return ensure_abuf(compiler, (sljit_uw)size);
617 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
619 struct sljit_memory_fragment *buf = compiler->buf;
620 struct sljit_memory_fragment *prev = NULL;
621 struct sljit_memory_fragment *tmp;
623 do {
624 tmp = buf->next;
625 buf->next = prev;
626 prev = buf;
627 buf = tmp;
628 } while (buf != NULL);
630 compiler->buf = prev;
633 /* Only used in RISC architectures where the instruction size is constant */
634 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
635 && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
637 static SLJIT_INLINE sljit_uw compute_next_addr(struct sljit_label *label, struct sljit_jump *jump,
638 struct sljit_const *const_, struct sljit_put_label *put_label)
640 sljit_uw result = ~(sljit_uw)0;
642 if (label)
643 result = label->size;
645 if (jump && jump->addr < result)
646 result = jump->addr;
648 if (const_ && const_->addr < result)
649 result = const_->addr;
651 if (put_label && put_label->addr < result)
652 result = put_label->addr;
654 return result;
657 #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X */
659 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
660 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
661 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
663 SLJIT_UNUSED_ARG(args);
664 SLJIT_UNUSED_ARG(local_size);
666 compiler->options = options;
667 compiler->scratches = scratches;
668 compiler->saveds = saveds;
669 compiler->fscratches = fscratches;
670 compiler->fsaveds = fsaveds;
671 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
672 compiler->last_return = args & SLJIT_ARG_MASK;
673 compiler->logical_local_size = local_size;
674 #endif
677 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
678 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
679 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
681 SLJIT_UNUSED_ARG(args);
682 SLJIT_UNUSED_ARG(local_size);
684 compiler->options = options;
685 compiler->scratches = scratches;
686 compiler->saveds = saveds;
687 compiler->fscratches = fscratches;
688 compiler->fsaveds = fsaveds;
689 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
690 compiler->last_return = args & SLJIT_ARG_MASK;
691 compiler->logical_local_size = local_size;
692 #endif
695 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
697 label->next = NULL;
698 label->size = compiler->size;
699 if (compiler->last_label)
700 compiler->last_label->next = label;
701 else
702 compiler->labels = label;
703 compiler->last_label = label;
706 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_u32 flags)
708 jump->next = NULL;
709 jump->flags = flags;
710 if (compiler->last_jump)
711 compiler->last_jump->next = jump;
712 else
713 compiler->jumps = jump;
714 compiler->last_jump = jump;
717 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
719 const_->next = NULL;
720 const_->addr = compiler->size;
721 if (compiler->last_const)
722 compiler->last_const->next = const_;
723 else
724 compiler->consts = const_;
725 compiler->last_const = const_;
728 static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
730 put_label->next = NULL;
731 put_label->label = NULL;
732 put_label->addr = compiler->size - offset;
733 put_label->flags = 0;
734 if (compiler->last_put_label)
735 compiler->last_put_label->next = put_label;
736 else
737 compiler->put_labels = put_label;
738 compiler->last_put_label = put_label;
741 #define ADDRESSING_DEPENDS_ON(exp, reg) \
742 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
744 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
746 static sljit_s32 function_check_arguments(sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches)
748 sljit_s32 word_arg_count, scratch_arg_end, saved_arg_count, float_arg_count, curr_type;
750 curr_type = (arg_types & SLJIT_ARG_FULL_MASK);
752 if (curr_type >= SLJIT_ARG_TYPE_F64) {
753 if (curr_type > SLJIT_ARG_TYPE_F32 || fscratches == 0)
754 return 0;
755 } else if (curr_type >= SLJIT_ARG_TYPE_W) {
756 if (scratches == 0)
757 return 0;
760 arg_types >>= SLJIT_ARG_SHIFT;
762 word_arg_count = 0;
763 scratch_arg_end = 0;
764 saved_arg_count = 0;
765 float_arg_count = 0;
766 while (arg_types != 0) {
767 if (word_arg_count + float_arg_count >= 4)
768 return 0;
770 curr_type = (arg_types & SLJIT_ARG_MASK);
772 if (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) {
773 if (saveds == -1 || curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_P)
774 return 0;
776 word_arg_count++;
777 scratch_arg_end = word_arg_count;
778 } else {
779 if (curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_F32)
780 return 0;
782 if (curr_type < SLJIT_ARG_TYPE_F64) {
783 word_arg_count++;
784 saved_arg_count++;
785 } else
786 float_arg_count++;
789 arg_types >>= SLJIT_ARG_SHIFT;
792 if (saveds == -1)
793 return (word_arg_count <= scratches && float_arg_count <= fscratches);
795 return (saved_arg_count <= saveds && scratch_arg_end <= scratches && float_arg_count <= fscratches);
798 #define FUNCTION_CHECK_IS_REG(r) \
799 (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
800 || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
802 #define FUNCTION_CHECK_IS_FREG(fr) \
803 (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
804 || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
806 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
807 #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
808 #else
809 #define CHECK_IF_VIRTUAL_REGISTER(p) 0
810 #endif
812 static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
814 if (compiler->scratches == -1 || compiler->saveds == -1)
815 return 0;
817 if (!(p & SLJIT_MEM))
818 return 0;
820 if (p == SLJIT_MEM1(SLJIT_SP))
821 return (i >= 0 && i < compiler->logical_local_size);
823 if (!(!(p & REG_MASK) || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
824 return 0;
826 if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
827 return 0;
829 if (p & OFFS_REG_MASK) {
830 if (!(p & REG_MASK))
831 return 0;
833 if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
834 return 0;
836 if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
837 return 0;
839 if ((i & ~0x3) != 0)
840 return 0;
843 return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
846 #define FUNCTION_CHECK_SRC_MEM(p, i) \
847 CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
849 static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
851 if (compiler->scratches == -1 || compiler->saveds == -1)
852 return 0;
854 if (FUNCTION_CHECK_IS_REG(p))
855 return (i == 0);
857 if (p == SLJIT_IMM)
858 return 1;
860 return function_check_src_mem(compiler, p, i);
863 #define FUNCTION_CHECK_SRC(p, i) \
864 CHECK_ARGUMENT(function_check_src(compiler, p, i));
866 static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
868 if (compiler->scratches == -1 || compiler->saveds == -1)
869 return 0;
871 if (FUNCTION_CHECK_IS_REG(p))
872 return (i == 0);
874 return function_check_src_mem(compiler, p, i);
877 #define FUNCTION_CHECK_DST(p, i) \
878 CHECK_ARGUMENT(function_check_dst(compiler, p, i));
880 static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
882 if (compiler->scratches == -1 || compiler->saveds == -1)
883 return 0;
885 if (FUNCTION_CHECK_IS_FREG(p))
886 return (i == 0);
888 return function_check_src_mem(compiler, p, i);
891 #define FUNCTION_FCHECK(p, i) \
892 CHECK_ARGUMENT(function_fcheck(compiler, p, i));
894 #endif /* SLJIT_ARGUMENT_CHECKS */
896 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
898 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
900 compiler->verbose = verbose;
903 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
904 #ifdef _WIN64
905 #ifdef __GNUC__
906 # define SLJIT_PRINT_D "ll"
907 #else
908 # define SLJIT_PRINT_D "I64"
909 #endif
910 #else
911 # define SLJIT_PRINT_D "l"
912 #endif
913 #else
914 # define SLJIT_PRINT_D ""
915 #endif
917 static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
919 if (r < (SLJIT_R0 + compiler->scratches))
920 fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
921 else if (r != SLJIT_SP)
922 fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
923 else
924 fprintf(compiler->verbose, "sp");
927 static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
929 if (r < (SLJIT_FR0 + compiler->fscratches))
930 fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
931 else
932 fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
935 static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
937 if ((p) & SLJIT_IMM)
938 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
939 else if ((p) & SLJIT_MEM) {
940 if ((p) & REG_MASK) {
941 fputc('[', compiler->verbose);
942 sljit_verbose_reg(compiler, (p) & REG_MASK);
943 if ((p) & OFFS_REG_MASK) {
944 fprintf(compiler->verbose, " + ");
945 sljit_verbose_reg(compiler, OFFS_REG(p));
946 if (i)
947 fprintf(compiler->verbose, " * %d", 1 << (i));
949 else if (i)
950 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
951 fputc(']', compiler->verbose);
953 else
954 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
955 } else
956 sljit_verbose_reg(compiler, p);
959 static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
961 if ((p) & SLJIT_MEM) {
962 if ((p) & REG_MASK) {
963 fputc('[', compiler->verbose);
964 sljit_verbose_reg(compiler, (p) & REG_MASK);
965 if ((p) & OFFS_REG_MASK) {
966 fprintf(compiler->verbose, " + ");
967 sljit_verbose_reg(compiler, OFFS_REG(p));
968 if (i)
969 fprintf(compiler->verbose, "%d", 1 << (i));
971 else if (i)
972 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
973 fputc(']', compiler->verbose);
975 else
976 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
978 else
979 sljit_verbose_freg(compiler, p);
982 static const char* op0_names[] = {
983 "breakpoint", "nop", "lmul.uw", "lmul.sw",
984 "divmod.u", "divmod.s", "div.u", "div.s",
985 "endbr", "skip_frames_before_return"
988 static const char* op1_names[] = {
989 "", ".u8", ".s8", ".u16",
990 ".s16", ".u32", ".s32", "32",
991 ".p", "not", "clz",
994 static const char* op2_names[] = {
995 "add", "addc", "sub", "subc",
996 "mul", "and", "or", "xor",
997 "shl", "lshr", "ashr",
1000 static const char* op_src_names[] = {
1001 "fast_return", "skip_frames_before_fast_return",
1002 "prefetch_l1", "prefetch_l2",
1003 "prefetch_l3", "prefetch_once",
1006 static const char* fop1_names[] = {
1007 "mov", "conv", "conv", "conv",
1008 "conv", "conv", "cmp", "neg",
1009 "abs",
1012 static const char* fop2_names[] = {
1013 "add", "sub", "mul", "div"
1016 static const char* jump_names[] = {
1017 "equal", "not_equal",
1018 "less", "greater_equal",
1019 "greater", "less_equal",
1020 "sig_less", "sig_greater_equal",
1021 "sig_greater", "sig_less_equal",
1022 "overflow", "not_overflow",
1023 "carry", "",
1024 "f_equal", "f_not_equal",
1025 "f_less", "f_greater_equal",
1026 "f_greater", "f_less_equal",
1027 "unordered", "ordered",
1028 "ordered_equal", "unordered_or_not_equal",
1029 "ordered_less", "unordered_or_greater_equal",
1030 "ordered_greater", "unordered_or_less_equal",
1031 "unordered_or_equal", "ordered_not_equal",
1032 "unordered_or_less", "ordered_greater_equal",
1033 "unordered_or_greater", "ordered_less_equal",
1034 "jump", "fast_call",
1035 "call", "call.cdecl"
1038 static const char* call_arg_names[] = {
1039 "void", "w", "32", "p", "f64", "f32"
1042 #endif /* SLJIT_VERBOSE */
1044 /* --------------------------------------------------------------------- */
1045 /* Arch dependent */
1046 /* --------------------------------------------------------------------- */
1048 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1049 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1051 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
1053 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1054 struct sljit_jump *jump;
1055 #endif
1057 SLJIT_UNUSED_ARG(compiler);
1059 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1060 CHECK_ARGUMENT(compiler->size > 0);
1061 jump = compiler->jumps;
1062 while (jump) {
1063 /* All jumps have target. */
1064 CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
1065 jump = jump->next;
1067 #endif
1068 CHECK_RETURN_OK;
1071 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
1072 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1073 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1075 SLJIT_UNUSED_ARG(compiler);
1077 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1078 CHECK_ARGUMENT(!(options & ~(SLJIT_ENTER_KEEP_S0 | SLJIT_ENTER_KEEP_S0_S1 | SLJIT_ENTER_CDECL)));
1079 CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 2 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1080 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1081 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1082 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1083 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1084 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1085 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1086 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1087 CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1088 CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, saveds - SLJIT_KEPT_SAVEDS_COUNT(options), fscratches));
1090 compiler->last_flags = 0;
1091 #endif
1092 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1093 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1094 fprintf(compiler->verbose, " enter ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1096 arg_types >>= SLJIT_ARG_SHIFT;
1097 if (arg_types) {
1098 fprintf(compiler->verbose, "], args[");
1099 do {
1100 fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1101 (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1102 arg_types >>= SLJIT_ARG_SHIFT;
1103 if (arg_types)
1104 fprintf(compiler->verbose, ",");
1105 } while (arg_types);
1108 fprintf(compiler->verbose, "],");
1110 if (options & SLJIT_ENTER_CDECL)
1111 fprintf(compiler->verbose, " enter:cdecl,");
1112 if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1113 fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1115 fprintf(compiler->verbose, "scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1116 scratches, saveds, fscratches, fsaveds, local_size);
1118 #endif
1119 CHECK_RETURN_OK;
1122 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
1123 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1124 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1126 SLJIT_UNUSED_ARG(compiler);
1128 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1129 CHECK_ARGUMENT(!(options & ~(SLJIT_ENTER_KEEP_S0 | SLJIT_ENTER_KEEP_S0_S1 | SLJIT_ENTER_CDECL)));
1130 CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 2 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1131 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1132 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1133 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1134 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1135 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1136 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1137 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1138 CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1139 CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, saveds - SLJIT_KEPT_SAVEDS_COUNT(options), fscratches));
1141 compiler->last_flags = 0;
1142 #endif
1143 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1144 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1145 fprintf(compiler->verbose, " set_context ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1147 arg_types >>= SLJIT_ARG_SHIFT;
1148 if (arg_types) {
1149 fprintf(compiler->verbose, "], args[");
1150 do {
1151 fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1152 (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1153 arg_types >>= SLJIT_ARG_SHIFT;
1154 if (arg_types)
1155 fprintf(compiler->verbose, ",");
1156 } while (arg_types);
1159 fprintf(compiler->verbose, "],");
1161 if (options & SLJIT_ENTER_CDECL)
1162 fprintf(compiler->verbose, " enter:cdecl,");
1163 if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1164 fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1166 fprintf(compiler->verbose, " scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1167 scratches, saveds, fscratches, fsaveds, local_size);
1169 #endif
1170 CHECK_RETURN_OK;
1173 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_compiler *compiler)
1175 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1176 compiler->skip_checks = 0;
1177 CHECK_RETURN_OK;
1180 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1181 CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_VOID);
1182 #endif
1184 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1185 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1186 fprintf(compiler->verbose, " return_void\n");
1188 #endif
1189 CHECK_RETURN_OK;
1192 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1194 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1195 CHECK_ARGUMENT(compiler->scratches >= 0);
1197 switch (compiler->last_return) {
1198 case SLJIT_ARG_TYPE_W:
1199 CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_S32);
1200 break;
1201 case SLJIT_ARG_TYPE_32:
1202 CHECK_ARGUMENT(op == SLJIT_MOV32 || (op >= SLJIT_MOV32_U8 && op <= SLJIT_MOV32_S16));
1203 break;
1204 case SLJIT_ARG_TYPE_P:
1205 CHECK_ARGUMENT(op == SLJIT_MOV_P);
1206 break;
1207 default:
1208 /* Context not initialized, void, etc. */
1209 CHECK_ARGUMENT(0);
1210 break;
1212 FUNCTION_CHECK_SRC(src, srcw);
1213 compiler->last_flags = 0;
1214 #endif
1215 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1216 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1217 fprintf(compiler->verbose, " return%s%s ", !(op & SLJIT_32) ? "" : "32",
1218 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1219 sljit_verbose_param(compiler, src, srcw);
1220 fprintf(compiler->verbose, "\n");
1222 #endif
1223 CHECK_RETURN_OK;
1226 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1228 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1229 FUNCTION_CHECK_DST(dst, dstw);
1230 compiler->last_flags = 0;
1231 #endif
1232 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1233 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1234 fprintf(compiler->verbose, " fast_enter ");
1235 sljit_verbose_param(compiler, dst, dstw);
1236 fprintf(compiler->verbose, "\n");
1238 #endif
1239 CHECK_RETURN_OK;
1242 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1244 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1245 CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1246 || ((op & ~SLJIT_32) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_32) <= SLJIT_DIV_SW)
1247 || (op >= SLJIT_ENDBR && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN));
1248 CHECK_ARGUMENT(GET_OPCODE(op) < SLJIT_LMUL_UW || GET_OPCODE(op) >= SLJIT_ENDBR || compiler->scratches >= 2);
1249 if ((GET_OPCODE(op) >= SLJIT_LMUL_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN)
1250 compiler->last_flags = 0;
1251 #endif
1252 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1253 if (SLJIT_UNLIKELY(!!compiler->verbose))
1255 fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1256 if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) {
1257 fprintf(compiler->verbose, (op & SLJIT_32) ? "32" : "w");
1259 fprintf(compiler->verbose, "\n");
1261 #endif
1262 CHECK_RETURN_OK;
1265 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1266 sljit_s32 dst, sljit_sw dstw,
1267 sljit_s32 src, sljit_sw srcw)
1269 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1270 compiler->skip_checks = 0;
1271 CHECK_RETURN_OK;
1274 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1275 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1277 switch (GET_OPCODE(op)) {
1278 case SLJIT_NOT:
1279 /* Only SLJIT_32 and SLJIT_SET_Z are allowed. */
1280 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1281 break;
1282 case SLJIT_MOV:
1283 case SLJIT_MOV_U32:
1284 case SLJIT_MOV_P:
1285 /* Nothing allowed */
1286 CHECK_ARGUMENT(!(op & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1287 break;
1288 default:
1289 /* Only SLJIT_32 is allowed. */
1290 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1291 break;
1294 FUNCTION_CHECK_DST(dst, dstw);
1295 FUNCTION_CHECK_SRC(src, srcw);
1297 if (GET_OPCODE(op) >= SLJIT_NOT) {
1298 CHECK_ARGUMENT(src != SLJIT_IMM);
1299 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1301 #endif
1302 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1303 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1304 if (GET_OPCODE(op) <= SLJIT_MOV_P)
1306 fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_32) ? "" : "32",
1307 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1309 else
1311 fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_32) ? "" : "32",
1312 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1313 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1316 sljit_verbose_param(compiler, dst, dstw);
1317 fprintf(compiler->verbose, ", ");
1318 sljit_verbose_param(compiler, src, srcw);
1319 fprintf(compiler->verbose, "\n");
1321 #endif
1322 CHECK_RETURN_OK;
1325 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset,
1326 sljit_s32 dst, sljit_sw dstw,
1327 sljit_s32 src1, sljit_sw src1w,
1328 sljit_s32 src2, sljit_sw src2w)
1330 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1331 compiler->skip_checks = 0;
1332 CHECK_RETURN_OK;
1335 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1336 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1338 switch (GET_OPCODE(op)) {
1339 case SLJIT_AND:
1340 case SLJIT_OR:
1341 case SLJIT_XOR:
1342 case SLJIT_SHL:
1343 case SLJIT_LSHR:
1344 case SLJIT_ASHR:
1345 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1346 break;
1347 case SLJIT_MUL:
1348 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1349 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1350 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1351 break;
1352 case SLJIT_ADD:
1353 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1354 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1355 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1356 break;
1357 case SLJIT_SUB:
1358 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1359 || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1360 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1361 break;
1362 case SLJIT_ADDC:
1363 case SLJIT_SUBC:
1364 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1365 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1366 CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1367 CHECK_ARGUMENT((op & SLJIT_32) == (compiler->last_flags & SLJIT_32));
1368 break;
1369 default:
1370 SLJIT_UNREACHABLE();
1371 break;
1374 if (unset) {
1375 CHECK_ARGUMENT(HAS_FLAGS(op));
1376 } else {
1377 FUNCTION_CHECK_DST(dst, dstw);
1379 FUNCTION_CHECK_SRC(src1, src1w);
1380 FUNCTION_CHECK_SRC(src2, src2w);
1381 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1382 #endif
1383 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1384 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1385 fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32",
1386 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1387 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1388 if (unset)
1389 fprintf(compiler->verbose, "unset");
1390 else
1391 sljit_verbose_param(compiler, dst, dstw);
1392 fprintf(compiler->verbose, ", ");
1393 sljit_verbose_param(compiler, src1, src1w);
1394 fprintf(compiler->verbose, ", ");
1395 sljit_verbose_param(compiler, src2, src2w);
1396 fprintf(compiler->verbose, "\n");
1398 #endif
1399 CHECK_RETURN_OK;
1402 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
1403 sljit_s32 src, sljit_sw srcw)
1405 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1406 CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE);
1407 FUNCTION_CHECK_SRC(src, srcw);
1409 if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN)
1411 CHECK_ARGUMENT(src != SLJIT_IMM);
1412 compiler->last_flags = 0;
1414 else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE)
1416 CHECK_ARGUMENT(src & SLJIT_MEM);
1418 #endif
1419 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1420 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1421 fprintf(compiler->verbose, " %s ", op_src_names[op - SLJIT_OP_SRC_BASE]);
1422 sljit_verbose_param(compiler, src, srcw);
1423 fprintf(compiler->verbose, "\n");
1425 #endif
1426 CHECK_RETURN_OK;
1429 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1431 SLJIT_UNUSED_ARG(reg);
1432 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1433 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1434 #endif
1435 CHECK_RETURN_OK;
1438 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1440 SLJIT_UNUSED_ARG(reg);
1441 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1442 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1443 #endif
1444 CHECK_RETURN_OK;
1447 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1448 void *instruction, sljit_u32 size)
1450 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1451 sljit_u32 i;
1452 #endif
1454 SLJIT_UNUSED_ARG(compiler);
1456 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1457 CHECK_ARGUMENT(instruction);
1459 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1460 CHECK_ARGUMENT(size > 0 && size < 16);
1461 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1462 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1463 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1464 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
1465 CHECK_ARGUMENT(size == 2 || size == 4 || size == 6);
1466 #else
1467 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1468 #endif
1470 compiler->last_flags = 0;
1471 #endif
1472 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1473 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1474 fprintf(compiler->verbose, " op_custom");
1475 for (i = 0; i < size; i++)
1476 fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1477 fprintf(compiler->verbose, "\n");
1479 #endif
1480 CHECK_RETURN_OK;
1483 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1484 sljit_s32 dst, sljit_sw dstw,
1485 sljit_s32 src, sljit_sw srcw)
1487 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1488 compiler->skip_checks = 0;
1489 CHECK_RETURN_OK;
1492 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1493 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1494 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1495 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1496 FUNCTION_FCHECK(src, srcw);
1497 FUNCTION_FCHECK(dst, dstw);
1498 #endif
1499 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1500 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1501 if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1502 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1503 (op & SLJIT_32) ? ".f32.from.f64" : ".f64.from.f32");
1504 else
1505 fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1506 (op & SLJIT_32) ? ".f32" : ".f64");
1508 sljit_verbose_fparam(compiler, dst, dstw);
1509 fprintf(compiler->verbose, ", ");
1510 sljit_verbose_fparam(compiler, src, srcw);
1511 fprintf(compiler->verbose, "\n");
1513 #endif
1514 CHECK_RETURN_OK;
1517 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1518 sljit_s32 src1, sljit_sw src1w,
1519 sljit_s32 src2, sljit_sw src2w)
1521 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1522 compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32);
1523 #endif
1525 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1526 compiler->skip_checks = 0;
1527 CHECK_RETURN_OK;
1530 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1531 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1532 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1533 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1534 CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1535 || (GET_FLAG_TYPE(op) >= SLJIT_F_EQUAL && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_LESS_EQUAL));
1536 FUNCTION_FCHECK(src1, src1w);
1537 FUNCTION_FCHECK(src2, src2w);
1538 #endif
1539 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1540 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1541 fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1542 if (op & VARIABLE_FLAG_MASK) {
1543 fprintf(compiler->verbose, ".%s", jump_names[GET_FLAG_TYPE(op)]);
1545 fprintf(compiler->verbose, " ");
1546 sljit_verbose_fparam(compiler, src1, src1w);
1547 fprintf(compiler->verbose, ", ");
1548 sljit_verbose_fparam(compiler, src2, src2w);
1549 fprintf(compiler->verbose, "\n");
1551 #endif
1552 CHECK_RETURN_OK;
1555 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1556 sljit_s32 dst, sljit_sw dstw,
1557 sljit_s32 src, sljit_sw srcw)
1559 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1560 compiler->skip_checks = 0;
1561 CHECK_RETURN_OK;
1564 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1565 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1566 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1567 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1568 FUNCTION_FCHECK(src, srcw);
1569 FUNCTION_CHECK_DST(dst, dstw);
1570 #endif
1571 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1572 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1573 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1574 (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1575 (op & SLJIT_32) ? ".f32" : ".f64");
1576 sljit_verbose_param(compiler, dst, dstw);
1577 fprintf(compiler->verbose, ", ");
1578 sljit_verbose_fparam(compiler, src, srcw);
1579 fprintf(compiler->verbose, "\n");
1581 #endif
1582 CHECK_RETURN_OK;
1585 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1586 sljit_s32 dst, sljit_sw dstw,
1587 sljit_s32 src, sljit_sw srcw)
1589 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1590 compiler->skip_checks = 0;
1591 CHECK_RETURN_OK;
1594 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1595 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1596 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1597 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1598 FUNCTION_CHECK_SRC(src, srcw);
1599 FUNCTION_FCHECK(dst, dstw);
1600 #endif
1601 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1602 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1603 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1604 (op & SLJIT_32) ? ".f32" : ".f64",
1605 (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1606 sljit_verbose_fparam(compiler, dst, dstw);
1607 fprintf(compiler->verbose, ", ");
1608 sljit_verbose_param(compiler, src, srcw);
1609 fprintf(compiler->verbose, "\n");
1611 #endif
1612 CHECK_RETURN_OK;
1615 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1616 sljit_s32 dst, sljit_sw dstw,
1617 sljit_s32 src1, sljit_sw src1w,
1618 sljit_s32 src2, sljit_sw src2w)
1620 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1621 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1622 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1623 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1624 FUNCTION_FCHECK(src1, src1w);
1625 FUNCTION_FCHECK(src2, src2w);
1626 FUNCTION_FCHECK(dst, dstw);
1627 #endif
1628 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1629 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1630 fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1631 sljit_verbose_fparam(compiler, dst, dstw);
1632 fprintf(compiler->verbose, ", ");
1633 sljit_verbose_fparam(compiler, src1, src1w);
1634 fprintf(compiler->verbose, ", ");
1635 sljit_verbose_fparam(compiler, src2, src2w);
1636 fprintf(compiler->verbose, "\n");
1638 #endif
1639 CHECK_RETURN_OK;
1642 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1644 SLJIT_UNUSED_ARG(compiler);
1646 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1647 compiler->skip_checks = 0;
1648 CHECK_RETURN_OK;
1651 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1652 compiler->last_flags = 0;
1653 #endif
1655 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1656 if (SLJIT_UNLIKELY(!!compiler->verbose))
1657 fprintf(compiler->verbose, "label:\n");
1658 #endif
1659 CHECK_RETURN_OK;
1662 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1663 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
1664 || (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1665 #define CHECK_UNORDERED(type, last_flags) \
1666 ((((type) & 0xff) == SLJIT_UNORDERED || ((type) & 0xff) == SLJIT_ORDERED) && \
1667 ((last_flags) & 0xff) >= SLJIT_UNORDERED && ((last_flags) & 0xff) <= SLJIT_ORDERED_LESS_EQUAL)
1668 #else
1669 #define CHECK_UNORDERED(type, last_flags) 0
1670 #endif
1671 #endif /* SLJIT_ARGUMENT_CHECKS */
1673 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1675 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1676 compiler->skip_checks = 0;
1677 CHECK_RETURN_OK;
1680 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1681 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1682 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
1684 if ((type & 0xff) < SLJIT_JUMP) {
1685 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1686 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1687 else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) {
1688 CHECK_ARGUMENT((type & 0xff) == SLJIT_CARRY || (type & 0xff) == SLJIT_NOT_CARRY);
1689 compiler->last_flags = 0;
1690 } else
1691 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1692 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1693 || CHECK_UNORDERED(type, compiler->last_flags));
1695 #endif
1696 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1697 if (SLJIT_UNLIKELY(!!compiler->verbose))
1698 fprintf(compiler->verbose, " jump%s %s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1699 jump_names[type & 0xff]);
1700 #endif
1701 CHECK_RETURN_OK;
1704 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
1705 sljit_s32 arg_types)
1707 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1708 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_CALL_RETURN)));
1709 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
1710 CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1712 if (type & SLJIT_CALL_RETURN) {
1713 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1715 #endif
1716 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1717 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1718 fprintf(compiler->verbose, " %s%s%s ret[%s", jump_names[type & 0xff],
1719 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1720 !(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1721 call_arg_names[arg_types & SLJIT_ARG_MASK]);
1723 arg_types >>= SLJIT_ARG_SHIFT;
1724 if (arg_types) {
1725 fprintf(compiler->verbose, "], args[");
1726 do {
1727 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1728 arg_types >>= SLJIT_ARG_SHIFT;
1729 if (arg_types)
1730 fprintf(compiler->verbose, ",");
1731 } while (arg_types);
1733 fprintf(compiler->verbose, "]\n");
1735 #endif
1736 CHECK_RETURN_OK;
1739 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1740 sljit_s32 src1, sljit_sw src1w,
1741 sljit_s32 src2, sljit_sw src2w)
1743 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1744 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1745 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1746 FUNCTION_CHECK_SRC(src1, src1w);
1747 FUNCTION_CHECK_SRC(src2, src2w);
1748 compiler->last_flags = 0;
1749 #endif
1750 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1751 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1752 fprintf(compiler->verbose, " cmp%s%s %s, ", (type & SLJIT_32) ? "32" : "",
1753 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1754 sljit_verbose_param(compiler, src1, src1w);
1755 fprintf(compiler->verbose, ", ");
1756 sljit_verbose_param(compiler, src2, src2w);
1757 fprintf(compiler->verbose, "\n");
1759 #endif
1760 CHECK_RETURN_OK;
1763 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1764 sljit_s32 src1, sljit_sw src1w,
1765 sljit_s32 src2, sljit_sw src2w)
1767 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1768 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1769 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1770 CHECK_ARGUMENT((type & 0xff) >= SLJIT_F_EQUAL && (type & 0xff) <= SLJIT_ORDERED_LESS_EQUAL
1771 && ((type & 0xff) <= SLJIT_ORDERED || sljit_cmp_info(type & 0xff)));
1772 FUNCTION_FCHECK(src1, src1w);
1773 FUNCTION_FCHECK(src2, src2w);
1774 compiler->last_flags = 0;
1775 #endif
1776 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1777 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1778 fprintf(compiler->verbose, " fcmp%s%s %s, ", (type & SLJIT_32) ? ".f32" : ".f64",
1779 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1780 sljit_verbose_fparam(compiler, src1, src1w);
1781 fprintf(compiler->verbose, ", ");
1782 sljit_verbose_fparam(compiler, src2, src2w);
1783 fprintf(compiler->verbose, "\n");
1785 #endif
1786 CHECK_RETURN_OK;
1789 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
1790 sljit_s32 src, sljit_sw srcw)
1792 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1793 compiler->skip_checks = 0;
1794 CHECK_RETURN_OK;
1797 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1798 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
1799 FUNCTION_CHECK_SRC(src, srcw);
1800 #endif
1801 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1802 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1803 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1804 sljit_verbose_param(compiler, src, srcw);
1805 fprintf(compiler->verbose, "\n");
1807 #endif
1808 CHECK_RETURN_OK;
1811 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
1812 sljit_s32 arg_types,
1813 sljit_s32 src, sljit_sw srcw)
1815 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1816 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_CALL_RETURN)));
1817 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
1818 CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1819 FUNCTION_CHECK_SRC(src, srcw);
1821 if (type & SLJIT_CALL_RETURN) {
1822 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1824 #endif
1825 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1826 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1827 fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff],
1828 !(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1829 call_arg_names[arg_types & SLJIT_ARG_MASK]);
1831 arg_types >>= SLJIT_ARG_SHIFT;
1832 if (arg_types) {
1833 fprintf(compiler->verbose, "], args[");
1834 do {
1835 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1836 arg_types >>= SLJIT_ARG_SHIFT;
1837 if (arg_types)
1838 fprintf(compiler->verbose, ",");
1839 } while (arg_types);
1841 fprintf(compiler->verbose, "], ");
1842 sljit_verbose_param(compiler, src, srcw);
1843 fprintf(compiler->verbose, "\n");
1845 #endif
1846 CHECK_RETURN_OK;
1849 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1850 sljit_s32 dst, sljit_sw dstw,
1851 sljit_s32 type)
1853 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1854 CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1855 CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1856 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1857 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1859 if (type <= SLJIT_NOT_ZERO)
1860 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1861 else
1862 CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1863 || (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1864 || (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1865 || CHECK_UNORDERED(type, compiler->last_flags));
1867 FUNCTION_CHECK_DST(dst, dstw);
1869 if (GET_OPCODE(op) >= SLJIT_ADD)
1870 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1871 #endif
1872 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1873 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1874 fprintf(compiler->verbose, " flags.%s%s%s ",
1875 GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1876 GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_32) ? "32" : ""),
1877 !(op & SLJIT_SET_Z) ? "" : ".z");
1878 sljit_verbose_param(compiler, dst, dstw);
1879 fprintf(compiler->verbose, ", %s\n", jump_names[type]);
1881 #endif
1882 CHECK_RETURN_OK;
1885 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1886 sljit_s32 dst_reg,
1887 sljit_s32 src, sljit_sw srcw)
1889 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1890 CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1892 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
1893 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_32));
1894 if (src != SLJIT_IMM) {
1895 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
1896 CHECK_ARGUMENT(srcw == 0);
1899 if (type <= SLJIT_NOT_ZERO)
1900 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1901 else
1902 CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1903 || (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1904 || (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1905 || CHECK_UNORDERED(type, compiler->last_flags));
1906 #endif
1907 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1908 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1909 fprintf(compiler->verbose, " cmov%s %s, ",
1910 !(dst_reg & SLJIT_32) ? "" : "32",
1911 jump_names[type]);
1912 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_32);
1913 fprintf(compiler->verbose, ", ");
1914 sljit_verbose_param(compiler, src, srcw);
1915 fprintf(compiler->verbose, "\n");
1917 #endif
1918 CHECK_RETURN_OK;
1921 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
1922 sljit_s32 reg,
1923 sljit_s32 mem, sljit_sw memw)
1925 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1926 sljit_s32 allowed_flags;
1928 CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
1929 CHECK_ARGUMENT(!(type & SLJIT_32) || ((type & 0xff) >= SLJIT_MOV_U8 && (type & 0xff) <= SLJIT_MOV_S16));
1931 if (type & SLJIT_MEM_UNALIGNED) {
1932 allowed_flags = SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32;
1934 switch (type & 0xff) {
1935 case SLJIT_MOV_U8:
1936 case SLJIT_MOV_S8:
1937 case SLJIT_MOV_U16:
1938 case SLJIT_MOV_S16:
1939 allowed_flags = 0;
1940 break;
1941 case SLJIT_MOV_U32:
1942 case SLJIT_MOV_S32:
1943 case SLJIT_MOV32:
1944 allowed_flags = SLJIT_MEM_ALIGNED_16;
1945 break;
1947 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_UNALIGNED | allowed_flags)) == 0);
1948 CHECK_ARGUMENT((type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32)) != (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32));
1949 } else {
1950 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1951 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1952 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1953 CHECK_ARGUMENT((mem & REG_MASK) != 0 && (mem & REG_MASK) != reg);
1956 FUNCTION_CHECK_SRC_MEM(mem, memw);
1957 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
1958 #endif
1959 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1960 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1961 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) {
1962 if (type & SLJIT_MEM_SUPP)
1963 CHECK_RETURN_OK;
1964 if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED) {
1965 fprintf(compiler->verbose, " // mem: unsupported form, no instructions are emitted");
1966 CHECK_RETURN_OK;
1970 if ((type & 0xff) == SLJIT_MOV32)
1971 fprintf(compiler->verbose, " mem32.%s",
1972 (type & SLJIT_MEM_STORE) ? "st" : "ld");
1973 else
1974 fprintf(compiler->verbose, " mem%s.%s%s",
1975 !(type & SLJIT_32) ? "" : "32",
1976 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1977 op1_names[(type & 0xff) - SLJIT_OP1_BASE]);
1979 if (type & SLJIT_MEM_UNALIGNED) {
1980 printf(".un%s%s ", (type & SLJIT_MEM_ALIGNED_16) ? ".16" : "", (type & SLJIT_MEM_ALIGNED_32) ? ".32" : "");
1981 } else
1982 printf((type & SLJIT_MEM_PRE) ? ".pre " : ".post ");
1983 sljit_verbose_reg(compiler, reg);
1984 fprintf(compiler->verbose, ", ");
1985 sljit_verbose_param(compiler, mem, memw);
1986 fprintf(compiler->verbose, "\n");
1988 #endif
1989 CHECK_RETURN_OK;
1992 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
1993 sljit_s32 freg,
1994 sljit_s32 mem, sljit_sw memw)
1996 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1997 CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
1998 if (type & SLJIT_MEM_UNALIGNED) {
1999 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_UNALIGNED | SLJIT_MEM_ALIGNED_16 | (type & SLJIT_32 ? 0 : SLJIT_MEM_ALIGNED_32))) == 0);
2000 CHECK_ARGUMENT((type & (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32)) != (SLJIT_MEM_ALIGNED_16 | SLJIT_MEM_ALIGNED_32));
2001 } else {
2002 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
2003 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
2004 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
2007 FUNCTION_CHECK_SRC_MEM(mem, memw);
2008 CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
2009 #endif
2010 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2011 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2012 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) {
2013 if (type & SLJIT_MEM_SUPP)
2014 CHECK_RETURN_OK;
2015 if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED) {
2016 fprintf(compiler->verbose, " // fmem: unsupported form, no instructions are emitted");
2017 CHECK_RETURN_OK;
2021 fprintf(compiler->verbose, " fmem.%s%s",
2022 (type & SLJIT_MEM_STORE) ? "st" : "ld",
2023 !(type & SLJIT_32) ? ".f64" : ".f32");
2025 if (type & SLJIT_MEM_UNALIGNED) {
2026 printf(".un%s%s ", (type & SLJIT_MEM_ALIGNED_16) ? ".16" : "", (type & SLJIT_MEM_ALIGNED_32) ? ".32" : "");
2027 } else
2028 printf((type & SLJIT_MEM_PRE) ? ".pre " : ".post ");
2029 sljit_verbose_freg(compiler, freg);
2030 fprintf(compiler->verbose, ", ");
2031 sljit_verbose_param(compiler, mem, memw);
2032 fprintf(compiler->verbose, "\n");
2034 #endif
2035 CHECK_RETURN_OK;
2038 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2040 /* Any offset is allowed. */
2041 SLJIT_UNUSED_ARG(offset);
2043 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2044 FUNCTION_CHECK_DST(dst, dstw);
2045 #endif
2046 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2047 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2048 fprintf(compiler->verbose, " local_base ");
2049 sljit_verbose_param(compiler, dst, dstw);
2050 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
2052 #endif
2053 CHECK_RETURN_OK;
2056 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
2058 SLJIT_UNUSED_ARG(init_value);
2060 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2061 FUNCTION_CHECK_DST(dst, dstw);
2062 #endif
2063 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2064 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2065 fprintf(compiler->verbose, " const ");
2066 sljit_verbose_param(compiler, dst, dstw);
2067 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
2069 #endif
2070 CHECK_RETURN_OK;
2073 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2075 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2076 FUNCTION_CHECK_DST(dst, dstw);
2077 #endif
2078 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2079 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2080 fprintf(compiler->verbose, " put_label ");
2081 sljit_verbose_param(compiler, dst, dstw);
2082 fprintf(compiler->verbose, "\n");
2084 #endif
2085 CHECK_RETURN_OK;
2088 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
2090 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
2091 SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
2092 invalid_float_opcodes); \
2093 if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
2094 if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
2095 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
2096 ADJUST_LOCAL_OFFSET(dst, dstw); \
2097 ADJUST_LOCAL_OFFSET(src, srcw); \
2098 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
2100 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
2101 CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
2102 ADJUST_LOCAL_OFFSET(dst, dstw); \
2103 ADJUST_LOCAL_OFFSET(src, srcw); \
2104 return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
2106 CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
2107 ADJUST_LOCAL_OFFSET(dst, dstw); \
2108 ADJUST_LOCAL_OFFSET(src, srcw); \
2109 return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
2111 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
2112 ADJUST_LOCAL_OFFSET(dst, dstw); \
2113 ADJUST_LOCAL_OFFSET(src, srcw);
2115 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2117 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2118 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
2119 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
2120 return SLJIT_SUCCESS;
2121 #else
2122 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
2123 return SLJIT_SUCCESS;
2124 #endif
2126 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2127 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2128 compiler->skip_checks = 1;
2129 #endif
2130 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
2133 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2135 CHECK_ERROR();
2136 CHECK(check_sljit_emit_return(compiler, op, src, srcw));
2138 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
2140 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2141 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2142 compiler->skip_checks = 1;
2143 #endif
2144 return sljit_emit_return_void(compiler);
2147 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2148 || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
2149 || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6)) \
2150 || (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2152 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
2153 sljit_s32 dst_reg,
2154 sljit_s32 src, sljit_sw srcw)
2156 struct sljit_label *label;
2157 struct sljit_jump *jump;
2158 sljit_s32 op = (dst_reg & SLJIT_32) ? SLJIT_MOV32 : SLJIT_MOV;
2160 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2161 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2162 compiler->skip_checks = 1;
2163 #endif
2164 jump = sljit_emit_jump(compiler, type ^ 0x1);
2165 FAIL_IF(!jump);
2167 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2168 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2169 compiler->skip_checks = 1;
2170 #endif
2171 FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_32, 0, src, srcw));
2173 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2174 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2175 compiler->skip_checks = 1;
2176 #endif
2177 label = sljit_emit_label(compiler);
2178 FAIL_IF(!label);
2179 sljit_set_label(jump, label);
2180 return SLJIT_SUCCESS;
2183 #endif
2185 #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \
2186 && !(defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2188 static sljit_s32 sljit_emit_mem_unaligned(struct sljit_compiler *compiler, sljit_s32 type,
2189 sljit_s32 reg,
2190 sljit_s32 mem, sljit_sw memw)
2192 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2193 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2194 compiler->skip_checks = 1;
2195 #endif
2197 if (type & SLJIT_MEM_STORE)
2198 return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), mem, memw, reg, 0);
2199 return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), reg, 0, mem, memw);
2202 #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM_V5 */
2204 #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \
2205 && !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
2207 static sljit_s32 sljit_emit_fmem_unaligned(struct sljit_compiler *compiler, sljit_s32 type,
2208 sljit_s32 freg,
2209 sljit_s32 mem, sljit_sw memw)
2211 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2212 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2213 compiler->skip_checks = 1;
2214 #endif
2216 if (type & SLJIT_MEM_STORE)
2217 return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), mem, memw, freg, 0);
2218 return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), freg, 0, mem, memw);
2221 #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM */
2223 /* CPU description section */
2225 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
2226 #define SLJIT_CPUINFO_PART1 " 32bit ("
2227 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2228 #define SLJIT_CPUINFO_PART1 " 64bit ("
2229 #else
2230 #error "Internal error: CPU type info missing"
2231 #endif
2233 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
2234 #define SLJIT_CPUINFO_PART2 "little endian + "
2235 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
2236 #define SLJIT_CPUINFO_PART2 "big endian + "
2237 #else
2238 #error "Internal error: CPU type info missing"
2239 #endif
2241 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
2242 #define SLJIT_CPUINFO_PART3 "unaligned)"
2243 #else
2244 #define SLJIT_CPUINFO_PART3 "aligned)"
2245 #endif
2247 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
2249 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
2250 # include "sljitNativeX86_common.c"
2251 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2252 # include "sljitNativeARM_32.c"
2253 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
2254 # include "sljitNativeARM_32.c"
2255 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
2256 # include "sljitNativeARM_T2_32.c"
2257 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2258 # include "sljitNativeARM_64.c"
2259 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2260 # include "sljitNativePPC_common.c"
2261 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2262 # include "sljitNativeMIPS_common.c"
2263 #elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2264 # include "sljitNativeRISCV_common.c"
2265 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
2266 # include "sljitNativeS390X.c"
2267 #endif
2269 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2270 && !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2272 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2273 sljit_s32 src1, sljit_sw src1w,
2274 sljit_s32 src2, sljit_sw src2w)
2276 /* Default compare for most architectures. */
2277 sljit_s32 flags, tmp_src, condition;
2278 sljit_sw tmp_srcw;
2280 CHECK_ERROR_PTR();
2281 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
2283 condition = type & 0xff;
2284 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2285 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
2286 if ((src1 & SLJIT_IMM) && !src1w) {
2287 src1 = src2;
2288 src1w = src2w;
2289 src2 = SLJIT_IMM;
2290 src2w = 0;
2292 if ((src2 & SLJIT_IMM) && !src2w)
2293 return emit_cmp_to0(compiler, type, src1, src1w);
2295 #endif
2297 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
2298 /* Immediate is preferred as second argument by most architectures. */
2299 switch (condition) {
2300 case SLJIT_LESS:
2301 condition = SLJIT_GREATER;
2302 break;
2303 case SLJIT_GREATER_EQUAL:
2304 condition = SLJIT_LESS_EQUAL;
2305 break;
2306 case SLJIT_GREATER:
2307 condition = SLJIT_LESS;
2308 break;
2309 case SLJIT_LESS_EQUAL:
2310 condition = SLJIT_GREATER_EQUAL;
2311 break;
2312 case SLJIT_SIG_LESS:
2313 condition = SLJIT_SIG_GREATER;
2314 break;
2315 case SLJIT_SIG_GREATER_EQUAL:
2316 condition = SLJIT_SIG_LESS_EQUAL;
2317 break;
2318 case SLJIT_SIG_GREATER:
2319 condition = SLJIT_SIG_LESS;
2320 break;
2321 case SLJIT_SIG_LESS_EQUAL:
2322 condition = SLJIT_SIG_GREATER_EQUAL;
2323 break;
2326 type = condition | (type & (SLJIT_32 | SLJIT_REWRITABLE_JUMP));
2327 tmp_src = src1;
2328 src1 = src2;
2329 src2 = tmp_src;
2330 tmp_srcw = src1w;
2331 src1w = src2w;
2332 src2w = tmp_srcw;
2335 if (condition <= SLJIT_NOT_ZERO)
2336 flags = SLJIT_SET_Z;
2337 else
2338 flags = condition << VARIABLE_FLAG_SHIFT;
2340 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2341 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2342 compiler->skip_checks = 1;
2343 #endif
2344 PTR_FAIL_IF(sljit_emit_op2u(compiler,
2345 SLJIT_SUB | flags | (type & SLJIT_32), src1, src1w, src2, src2w));
2346 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2347 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2348 compiler->skip_checks = 1;
2349 #endif
2350 return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_32)));
2353 #endif /* !SLJIT_CONFIG_MIPS */
2355 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
2357 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2359 if (type < SLJIT_UNORDERED || type > SLJIT_ORDERED_LESS_EQUAL)
2360 return 0;
2362 switch (type) {
2363 case SLJIT_UNORDERED_OR_EQUAL:
2364 case SLJIT_ORDERED_NOT_EQUAL:
2365 return 0;
2368 return 1;
2371 #endif /* SLJIT_CONFIG_ARM */
2373 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2374 sljit_s32 src1, sljit_sw src1w,
2375 sljit_s32 src2, sljit_sw src2w)
2377 CHECK_ERROR_PTR();
2378 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
2380 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2381 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2382 compiler->skip_checks = 1;
2383 #endif
2384 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_32), src1, src1w, src2, src2w);
2386 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2387 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2388 compiler->skip_checks = 1;
2389 #endif
2390 return sljit_emit_jump(compiler, type);
2393 #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \
2394 && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2395 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2397 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
2398 sljit_s32 reg,
2399 sljit_s32 mem, sljit_sw memw)
2401 CHECK_ERROR();
2402 CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw));
2404 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST))
2405 return SLJIT_ERR_UNSUPPORTED;
2407 return sljit_emit_mem_unaligned(compiler, type, reg, mem, memw);
2410 #endif
2412 #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \
2413 && !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2414 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2416 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2417 sljit_s32 freg,
2418 sljit_s32 mem, sljit_sw memw)
2420 CHECK_ERROR();
2421 CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
2423 if (type & (SLJIT_MEM_PRE | SLJIT_MEM_POST))
2424 return SLJIT_ERR_UNSUPPORTED;
2426 return sljit_emit_fmem_unaligned(compiler, type, freg, mem, memw);
2429 #endif
2431 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2432 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2434 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2436 CHECK_ERROR();
2437 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2439 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
2440 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2441 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2442 compiler->skip_checks = 1;
2443 #endif
2444 if (offset != 0)
2445 return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2446 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
2449 #endif
2451 #else /* SLJIT_CONFIG_UNSUPPORTED */
2453 /* Empty function bodies for those machines, which are not (yet) supported. */
2455 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2457 return "unsupported";
2460 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
2462 SLJIT_UNUSED_ARG(allocator_data);
2463 SLJIT_UNUSED_ARG(exec_allocator_data);
2464 SLJIT_UNREACHABLE();
2465 return NULL;
2468 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
2470 SLJIT_UNUSED_ARG(compiler);
2471 SLJIT_UNREACHABLE();
2474 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
2476 SLJIT_UNUSED_ARG(compiler);
2477 SLJIT_UNREACHABLE();
2480 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
2482 SLJIT_UNUSED_ARG(compiler);
2483 SLJIT_UNUSED_ARG(size);
2484 SLJIT_UNREACHABLE();
2485 return NULL;
2488 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2489 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
2491 SLJIT_UNUSED_ARG(compiler);
2492 SLJIT_UNUSED_ARG(verbose);
2493 SLJIT_UNREACHABLE();
2495 #endif
2497 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
2499 SLJIT_UNUSED_ARG(compiler);
2500 SLJIT_UNREACHABLE();
2501 return NULL;
2504 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
2506 SLJIT_UNUSED_ARG(feature_type);
2507 SLJIT_UNREACHABLE();
2508 return 0;
2511 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2513 SLJIT_UNUSED_ARG(type);
2514 SLJIT_UNREACHABLE();
2515 return 0;
2518 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
2520 SLJIT_UNUSED_ARG(code);
2521 SLJIT_UNUSED_ARG(exec_allocator_data);
2522 SLJIT_UNREACHABLE();
2525 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
2526 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2527 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2529 SLJIT_UNUSED_ARG(compiler);
2530 SLJIT_UNUSED_ARG(options);
2531 SLJIT_UNUSED_ARG(arg_types);
2532 SLJIT_UNUSED_ARG(scratches);
2533 SLJIT_UNUSED_ARG(saveds);
2534 SLJIT_UNUSED_ARG(fscratches);
2535 SLJIT_UNUSED_ARG(fsaveds);
2536 SLJIT_UNUSED_ARG(local_size);
2537 SLJIT_UNREACHABLE();
2538 return SLJIT_ERR_UNSUPPORTED;
2541 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
2542 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2543 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2545 SLJIT_UNUSED_ARG(compiler);
2546 SLJIT_UNUSED_ARG(options);
2547 SLJIT_UNUSED_ARG(arg_types);
2548 SLJIT_UNUSED_ARG(scratches);
2549 SLJIT_UNUSED_ARG(saveds);
2550 SLJIT_UNUSED_ARG(fscratches);
2551 SLJIT_UNUSED_ARG(fsaveds);
2552 SLJIT_UNUSED_ARG(local_size);
2553 SLJIT_UNREACHABLE();
2554 return SLJIT_ERR_UNSUPPORTED;
2557 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2559 SLJIT_UNUSED_ARG(compiler);
2560 SLJIT_UNUSED_ARG(op);
2561 SLJIT_UNUSED_ARG(src);
2562 SLJIT_UNUSED_ARG(srcw);
2563 SLJIT_UNREACHABLE();
2564 return SLJIT_ERR_UNSUPPORTED;
2567 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler)
2569 SLJIT_UNUSED_ARG(compiler);
2570 SLJIT_UNREACHABLE();
2571 return SLJIT_ERR_UNSUPPORTED;
2574 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2576 SLJIT_UNUSED_ARG(compiler);
2577 SLJIT_UNUSED_ARG(dst);
2578 SLJIT_UNUSED_ARG(dstw);
2579 SLJIT_UNREACHABLE();
2580 return SLJIT_ERR_UNSUPPORTED;
2583 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2585 SLJIT_UNUSED_ARG(compiler);
2586 SLJIT_UNUSED_ARG(op);
2587 SLJIT_UNREACHABLE();
2588 return SLJIT_ERR_UNSUPPORTED;
2591 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2592 sljit_s32 dst, sljit_sw dstw,
2593 sljit_s32 src, sljit_sw srcw)
2595 SLJIT_UNUSED_ARG(compiler);
2596 SLJIT_UNUSED_ARG(op);
2597 SLJIT_UNUSED_ARG(dst);
2598 SLJIT_UNUSED_ARG(dstw);
2599 SLJIT_UNUSED_ARG(src);
2600 SLJIT_UNUSED_ARG(srcw);
2601 SLJIT_UNREACHABLE();
2602 return SLJIT_ERR_UNSUPPORTED;
2605 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2606 sljit_s32 dst, sljit_sw dstw,
2607 sljit_s32 src1, sljit_sw src1w,
2608 sljit_s32 src2, sljit_sw src2w)
2610 SLJIT_UNUSED_ARG(compiler);
2611 SLJIT_UNUSED_ARG(op);
2612 SLJIT_UNUSED_ARG(dst);
2613 SLJIT_UNUSED_ARG(dstw);
2614 SLJIT_UNUSED_ARG(src1);
2615 SLJIT_UNUSED_ARG(src1w);
2616 SLJIT_UNUSED_ARG(src2);
2617 SLJIT_UNUSED_ARG(src2w);
2618 SLJIT_UNREACHABLE();
2619 return SLJIT_ERR_UNSUPPORTED;
2622 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,
2623 sljit_s32 src1, sljit_sw src1w,
2624 sljit_s32 src2, sljit_sw src2w)
2626 SLJIT_UNUSED_ARG(compiler);
2627 SLJIT_UNUSED_ARG(op);
2628 SLJIT_UNUSED_ARG(src1);
2629 SLJIT_UNUSED_ARG(src1w);
2630 SLJIT_UNUSED_ARG(src2);
2631 SLJIT_UNUSED_ARG(src2w);
2632 SLJIT_UNREACHABLE();
2633 return SLJIT_ERR_UNSUPPORTED;
2636 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
2637 sljit_s32 src, sljit_sw srcw)
2639 SLJIT_UNUSED_ARG(compiler);
2640 SLJIT_UNUSED_ARG(op);
2641 SLJIT_UNUSED_ARG(src);
2642 SLJIT_UNUSED_ARG(srcw);
2643 SLJIT_UNREACHABLE();
2644 return SLJIT_ERR_UNSUPPORTED;
2647 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2649 SLJIT_UNREACHABLE();
2650 return reg;
2653 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2654 void *instruction, sljit_u32 size)
2656 SLJIT_UNUSED_ARG(compiler);
2657 SLJIT_UNUSED_ARG(instruction);
2658 SLJIT_UNUSED_ARG(size);
2659 SLJIT_UNREACHABLE();
2660 return SLJIT_ERR_UNSUPPORTED;
2663 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2665 SLJIT_UNUSED_ARG(compiler);
2666 SLJIT_UNUSED_ARG(current_flags);
2669 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2670 sljit_s32 dst, sljit_sw dstw,
2671 sljit_s32 src, sljit_sw srcw)
2673 SLJIT_UNUSED_ARG(compiler);
2674 SLJIT_UNUSED_ARG(op);
2675 SLJIT_UNUSED_ARG(dst);
2676 SLJIT_UNUSED_ARG(dstw);
2677 SLJIT_UNUSED_ARG(src);
2678 SLJIT_UNUSED_ARG(srcw);
2679 SLJIT_UNREACHABLE();
2680 return SLJIT_ERR_UNSUPPORTED;
2683 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2684 sljit_s32 dst, sljit_sw dstw,
2685 sljit_s32 src1, sljit_sw src1w,
2686 sljit_s32 src2, sljit_sw src2w)
2688 SLJIT_UNUSED_ARG(compiler);
2689 SLJIT_UNUSED_ARG(op);
2690 SLJIT_UNUSED_ARG(dst);
2691 SLJIT_UNUSED_ARG(dstw);
2692 SLJIT_UNUSED_ARG(src1);
2693 SLJIT_UNUSED_ARG(src1w);
2694 SLJIT_UNUSED_ARG(src2);
2695 SLJIT_UNUSED_ARG(src2w);
2696 SLJIT_UNREACHABLE();
2697 return SLJIT_ERR_UNSUPPORTED;
2700 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2702 SLJIT_UNUSED_ARG(compiler);
2703 SLJIT_UNREACHABLE();
2704 return NULL;
2707 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2709 SLJIT_UNUSED_ARG(compiler);
2710 SLJIT_UNUSED_ARG(type);
2711 SLJIT_UNREACHABLE();
2712 return NULL;
2715 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
2716 sljit_s32 arg_types)
2718 SLJIT_UNUSED_ARG(compiler);
2719 SLJIT_UNUSED_ARG(type);
2720 SLJIT_UNUSED_ARG(arg_types);
2721 SLJIT_UNREACHABLE();
2722 return NULL;
2725 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2726 sljit_s32 src1, sljit_sw src1w,
2727 sljit_s32 src2, sljit_sw src2w)
2729 SLJIT_UNUSED_ARG(compiler);
2730 SLJIT_UNUSED_ARG(type);
2731 SLJIT_UNUSED_ARG(src1);
2732 SLJIT_UNUSED_ARG(src1w);
2733 SLJIT_UNUSED_ARG(src2);
2734 SLJIT_UNUSED_ARG(src2w);
2735 SLJIT_UNREACHABLE();
2736 return NULL;
2739 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2740 sljit_s32 src1, sljit_sw src1w,
2741 sljit_s32 src2, sljit_sw src2w)
2743 SLJIT_UNUSED_ARG(compiler);
2744 SLJIT_UNUSED_ARG(type);
2745 SLJIT_UNUSED_ARG(src1);
2746 SLJIT_UNUSED_ARG(src1w);
2747 SLJIT_UNUSED_ARG(src2);
2748 SLJIT_UNUSED_ARG(src2w);
2749 SLJIT_UNREACHABLE();
2750 return NULL;
2753 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2755 SLJIT_UNUSED_ARG(jump);
2756 SLJIT_UNUSED_ARG(label);
2757 SLJIT_UNREACHABLE();
2760 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2762 SLJIT_UNUSED_ARG(jump);
2763 SLJIT_UNUSED_ARG(target);
2764 SLJIT_UNREACHABLE();
2767 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
2769 SLJIT_UNUSED_ARG(put_label);
2770 SLJIT_UNUSED_ARG(label);
2771 SLJIT_UNREACHABLE();
2774 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2776 SLJIT_UNUSED_ARG(compiler);
2777 SLJIT_UNUSED_ARG(type);
2778 SLJIT_UNUSED_ARG(src);
2779 SLJIT_UNUSED_ARG(srcw);
2780 SLJIT_UNREACHABLE();
2781 return SLJIT_ERR_UNSUPPORTED;
2784 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
2785 sljit_s32 arg_types,
2786 sljit_s32 src, sljit_sw srcw)
2788 SLJIT_UNUSED_ARG(compiler);
2789 SLJIT_UNUSED_ARG(type);
2790 SLJIT_UNUSED_ARG(arg_types);
2791 SLJIT_UNUSED_ARG(src);
2792 SLJIT_UNUSED_ARG(srcw);
2793 SLJIT_UNREACHABLE();
2794 return SLJIT_ERR_UNSUPPORTED;
2797 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2798 sljit_s32 dst, sljit_sw dstw,
2799 sljit_s32 type)
2801 SLJIT_UNUSED_ARG(compiler);
2802 SLJIT_UNUSED_ARG(op);
2803 SLJIT_UNUSED_ARG(dst);
2804 SLJIT_UNUSED_ARG(dstw);
2805 SLJIT_UNUSED_ARG(type);
2806 SLJIT_UNREACHABLE();
2807 return SLJIT_ERR_UNSUPPORTED;
2810 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
2811 sljit_s32 dst_reg,
2812 sljit_s32 src, sljit_sw srcw)
2814 SLJIT_UNUSED_ARG(compiler);
2815 SLJIT_UNUSED_ARG(type);
2816 SLJIT_UNUSED_ARG(dst_reg);
2817 SLJIT_UNUSED_ARG(src);
2818 SLJIT_UNUSED_ARG(srcw);
2819 SLJIT_UNREACHABLE();
2820 return SLJIT_ERR_UNSUPPORTED;
2823 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)
2825 SLJIT_UNUSED_ARG(compiler);
2826 SLJIT_UNUSED_ARG(type);
2827 SLJIT_UNUSED_ARG(reg);
2828 SLJIT_UNUSED_ARG(mem);
2829 SLJIT_UNUSED_ARG(memw);
2830 SLJIT_UNREACHABLE();
2831 return SLJIT_ERR_UNSUPPORTED;
2834 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)
2836 SLJIT_UNUSED_ARG(compiler);
2837 SLJIT_UNUSED_ARG(type);
2838 SLJIT_UNUSED_ARG(freg);
2839 SLJIT_UNUSED_ARG(mem);
2840 SLJIT_UNUSED_ARG(memw);
2841 SLJIT_UNREACHABLE();
2842 return SLJIT_ERR_UNSUPPORTED;
2845 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2847 SLJIT_UNUSED_ARG(compiler);
2848 SLJIT_UNUSED_ARG(dst);
2849 SLJIT_UNUSED_ARG(dstw);
2850 SLJIT_UNUSED_ARG(offset);
2851 SLJIT_UNREACHABLE();
2852 return SLJIT_ERR_UNSUPPORTED;
2855 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2857 SLJIT_UNUSED_ARG(compiler);
2858 SLJIT_UNUSED_ARG(dst);
2859 SLJIT_UNUSED_ARG(dstw);
2860 SLJIT_UNUSED_ARG(initval);
2861 SLJIT_UNREACHABLE();
2862 return NULL;
2865 SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2867 SLJIT_UNUSED_ARG(compiler);
2868 SLJIT_UNUSED_ARG(dst);
2869 SLJIT_UNUSED_ARG(dstw);
2870 return NULL;
2873 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2875 SLJIT_UNUSED_ARG(addr);
2876 SLJIT_UNUSED_ARG(new_target);
2877 SLJIT_UNUSED_ARG(executable_offset);
2878 SLJIT_UNREACHABLE();
2881 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2883 SLJIT_UNUSED_ARG(addr);
2884 SLJIT_UNUSED_ARG(new_constant);
2885 SLJIT_UNUSED_ARG(executable_offset);
2886 SLJIT_UNREACHABLE();
2889 #endif /* !SLJIT_CONFIG_UNSUPPORTED */