Support unsaved registers
[sljit.git] / sljit_src / sljitLir.c
blob8b1b876eb931cd6d804dd0cd9c35699d5038bf76
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
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
158 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
159 # define CPOOL_SIZE 512
160 #endif
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
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
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
199 # define REMOVE_COND 0x100
200 #endif
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
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
229 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
230 # define IS_MOVABLE 0x04
231 # define IS_COND 0x08
232 # define IS_CALL 0x10
234 # define PATCH_B 0x20
235 # define PATCH_CALL 0x40
237 /* instruction types */
238 # define MOVABLE_INS 0
239 /* 1 - 31 last destination register */
240 /* no destination (i.e: store) */
241 # define UNMOVABLE_INS 32
243 # define DST_INS_MASK 0xff
245 /* ICC_SET is the same as SET_FLAGS. */
246 # define ICC_IS_SET (1 << 23)
247 # define FCC_IS_SET (1 << 24)
248 #endif
250 /* Stack management. */
252 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
253 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
254 (saveds) + (sljit_s32)(extra)) * (sljit_s32)sizeof(sljit_sw))
256 #define GET_SAVED_FLOAT_REGISTERS_SIZE(fscratches, fsaveds, size) \
257 (((fscratches < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS ? 0 : (fscratches - SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS)) + \
258 (fsaveds)) * (sljit_s32)(size))
260 #define ADJUST_LOCAL_OFFSET(p, i) \
261 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
262 (i) += SLJIT_LOCALS_OFFSET;
264 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
266 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
267 #include "sljitUtils.c"
269 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
271 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
273 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
274 #include "sljitProtExecAllocator.c"
275 #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR)
276 #include "sljitWXExecAllocator.c"
277 #else
278 #include "sljitExecAllocator.c"
279 #endif
281 #endif
283 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
284 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
285 #else
286 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
287 #endif
289 #ifndef SLJIT_UPDATE_WX_FLAGS
290 #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)
291 #endif
293 /* Argument checking features. */
295 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
297 /* Returns with error when an invalid argument is passed. */
299 #define CHECK_ARGUMENT(x) \
300 do { \
301 if (SLJIT_UNLIKELY(!(x))) \
302 return 1; \
303 } while (0)
305 #define CHECK_RETURN_TYPE sljit_s32
306 #define CHECK_RETURN_OK return 0
308 #define CHECK(x) \
309 do { \
310 if (SLJIT_UNLIKELY(x)) { \
311 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
312 return SLJIT_ERR_BAD_ARGUMENT; \
314 } while (0)
316 #define CHECK_PTR(x) \
317 do { \
318 if (SLJIT_UNLIKELY(x)) { \
319 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
320 return NULL; \
322 } while (0)
324 #define CHECK_REG_INDEX(x) \
325 do { \
326 if (SLJIT_UNLIKELY(x)) { \
327 return -2; \
329 } while (0)
331 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
333 /* Assertion failure occures if an invalid argument is passed. */
334 #undef SLJIT_ARGUMENT_CHECKS
335 #define SLJIT_ARGUMENT_CHECKS 1
337 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
338 #define CHECK_RETURN_TYPE void
339 #define CHECK_RETURN_OK return
340 #define CHECK(x) x
341 #define CHECK_PTR(x) x
342 #define CHECK_REG_INDEX(x) x
344 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
346 /* Arguments are not checked. */
347 #define CHECK_RETURN_TYPE void
348 #define CHECK_RETURN_OK return
349 #define CHECK(x) x
350 #define CHECK_PTR(x) x
351 #define CHECK_REG_INDEX(x) x
353 #else
355 /* Arguments are not checked. */
356 #define CHECK(x)
357 #define CHECK_PTR(x)
358 #define CHECK_REG_INDEX(x)
360 #endif /* SLJIT_ARGUMENT_CHECKS */
362 /* --------------------------------------------------------------------- */
363 /* Public functions */
364 /* --------------------------------------------------------------------- */
366 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
367 #define SLJIT_NEEDS_COMPILER_INIT 1
368 static sljit_s32 compiler_initialized = 0;
369 /* A thread safe initialization. */
370 static void init_compiler(void);
371 #endif
373 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
375 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
376 if (!compiler)
377 return NULL;
378 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
380 SLJIT_COMPILE_ASSERT(
381 sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
382 && sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
383 && sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
384 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
385 && sizeof(sljit_p) <= sizeof(sljit_sw)
386 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
387 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
388 invalid_integer_types);
389 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_32,
390 rewritable_jump_and_single_op_must_not_be_the_same);
391 SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_F_EQUAL & 0x1) && !(SLJIT_JUMP & 0x1),
392 conditional_flags_must_be_even_numbers);
394 /* Only the non-zero members must be set. */
395 compiler->error = SLJIT_SUCCESS;
397 compiler->allocator_data = allocator_data;
398 compiler->exec_allocator_data = exec_allocator_data;
399 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
400 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
402 if (!compiler->buf || !compiler->abuf) {
403 if (compiler->buf)
404 SLJIT_FREE(compiler->buf, allocator_data);
405 if (compiler->abuf)
406 SLJIT_FREE(compiler->abuf, allocator_data);
407 SLJIT_FREE(compiler, allocator_data);
408 return NULL;
411 compiler->buf->next = NULL;
412 compiler->buf->used_size = 0;
413 compiler->abuf->next = NULL;
414 compiler->abuf->used_size = 0;
416 compiler->scratches = -1;
417 compiler->saveds = -1;
418 compiler->fscratches = -1;
419 compiler->fsaveds = -1;
420 compiler->local_size = -1;
422 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
423 compiler->args_size = -1;
424 #endif
426 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
427 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
428 + CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
429 if (!compiler->cpool) {
430 SLJIT_FREE(compiler->buf, allocator_data);
431 SLJIT_FREE(compiler->abuf, allocator_data);
432 SLJIT_FREE(compiler, allocator_data);
433 return NULL;
435 compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
436 compiler->cpool_diff = 0xffffffff;
437 #endif
439 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
440 compiler->delay_slot = UNMOVABLE_INS;
441 #endif
443 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
444 compiler->delay_slot = UNMOVABLE_INS;
445 #endif
447 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
448 || (defined SLJIT_DEBUG && SLJIT_DEBUG)
449 compiler->last_flags = 0;
450 compiler->last_return = -1;
451 compiler->logical_local_size = 0;
452 #endif
454 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
455 if (!compiler_initialized) {
456 init_compiler();
457 compiler_initialized = 1;
459 #endif
461 return compiler;
464 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
466 struct sljit_memory_fragment *buf;
467 struct sljit_memory_fragment *curr;
468 void *allocator_data = compiler->allocator_data;
469 SLJIT_UNUSED_ARG(allocator_data);
471 buf = compiler->buf;
472 while (buf) {
473 curr = buf;
474 buf = buf->next;
475 SLJIT_FREE(curr, allocator_data);
478 buf = compiler->abuf;
479 while (buf) {
480 curr = buf;
481 buf = buf->next;
482 SLJIT_FREE(curr, allocator_data);
485 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
486 SLJIT_FREE(compiler->cpool, allocator_data);
487 #endif
488 SLJIT_FREE(compiler, allocator_data);
491 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
493 if (compiler->error == SLJIT_SUCCESS)
494 compiler->error = SLJIT_ERR_ALLOC_FAILED;
497 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
498 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
500 SLJIT_UNUSED_ARG(exec_allocator_data);
502 /* Remove thumb mode flag. */
503 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~(sljit_uw)0x1), exec_allocator_data);
505 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
506 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
508 SLJIT_UNUSED_ARG(exec_allocator_data);
510 /* Resolve indirection. */
511 code = (void*)(*(sljit_uw*)code);
512 SLJIT_FREE_EXEC(code, exec_allocator_data);
514 #else
515 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
517 SLJIT_UNUSED_ARG(exec_allocator_data);
519 SLJIT_FREE_EXEC(code, exec_allocator_data);
521 #endif
523 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
525 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
526 jump->flags &= (sljit_uw)~JUMP_ADDR;
527 jump->flags |= JUMP_LABEL;
528 jump->u.label = label;
532 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
534 if (SLJIT_LIKELY(!!jump)) {
535 jump->flags &= (sljit_uw)~JUMP_LABEL;
536 jump->flags |= JUMP_ADDR;
537 jump->u.target = target;
541 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
543 if (SLJIT_LIKELY(!!put_label))
544 put_label->label = label;
547 #define SLJIT_CURRENT_FLAGS_ALL \
548 (SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE)
550 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
552 SLJIT_UNUSED_ARG(compiler);
553 SLJIT_UNUSED_ARG(current_flags);
555 #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
556 compiler->status_flags_state = current_flags;
557 #endif
559 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
560 compiler->last_flags = 0;
561 if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) {
562 compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z));
564 #endif
567 /* --------------------------------------------------------------------- */
568 /* Private functions */
569 /* --------------------------------------------------------------------- */
571 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
573 sljit_u8 *ret;
574 struct sljit_memory_fragment *new_frag;
576 SLJIT_ASSERT(size <= 256);
577 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
578 ret = compiler->buf->memory + compiler->buf->used_size;
579 compiler->buf->used_size += size;
580 return ret;
582 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
583 PTR_FAIL_IF_NULL(new_frag);
584 new_frag->next = compiler->buf;
585 compiler->buf = new_frag;
586 new_frag->used_size = size;
587 return new_frag->memory;
590 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
592 sljit_u8 *ret;
593 struct sljit_memory_fragment *new_frag;
595 SLJIT_ASSERT(size <= 256);
596 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
597 ret = compiler->abuf->memory + compiler->abuf->used_size;
598 compiler->abuf->used_size += size;
599 return ret;
601 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
602 PTR_FAIL_IF_NULL(new_frag);
603 new_frag->next = compiler->abuf;
604 compiler->abuf = new_frag;
605 new_frag->used_size = size;
606 return new_frag->memory;
609 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
611 CHECK_ERROR_PTR();
613 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
614 if (size <= 0 || size > 128)
615 return NULL;
616 size = (size + 7) & ~7;
617 #else
618 if (size <= 0 || size > 64)
619 return NULL;
620 size = (size + 3) & ~3;
621 #endif
622 return ensure_abuf(compiler, (sljit_uw)size);
625 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
627 struct sljit_memory_fragment *buf = compiler->buf;
628 struct sljit_memory_fragment *prev = NULL;
629 struct sljit_memory_fragment *tmp;
631 do {
632 tmp = buf->next;
633 buf->next = prev;
634 prev = buf;
635 buf = tmp;
636 } while (buf != NULL);
638 compiler->buf = prev;
641 /* Only used in RISC architectures where the instruction size is constant */
642 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
643 && !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
645 static SLJIT_INLINE sljit_uw compute_next_addr(struct sljit_label *label, struct sljit_jump *jump,
646 struct sljit_const *const_, struct sljit_put_label *put_label)
648 sljit_uw result = ~(sljit_uw)0;
650 if (label)
651 result = label->size;
653 if (jump && jump->addr < result)
654 result = jump->addr;
656 if (const_ && const_->addr < result)
657 result = const_->addr;
659 if (put_label && put_label->addr < result)
660 result = put_label->addr;
662 return result;
665 #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X */
667 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
668 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
669 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
671 SLJIT_UNUSED_ARG(args);
672 SLJIT_UNUSED_ARG(local_size);
674 compiler->options = options;
675 compiler->scratches = scratches;
676 compiler->saveds = saveds;
677 compiler->fscratches = fscratches;
678 compiler->fsaveds = fsaveds;
679 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
680 compiler->last_return = args & SLJIT_ARG_MASK;
681 compiler->logical_local_size = local_size;
682 #endif
685 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
686 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
687 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
689 SLJIT_UNUSED_ARG(args);
690 SLJIT_UNUSED_ARG(local_size);
692 compiler->options = options;
693 compiler->scratches = scratches;
694 compiler->saveds = saveds;
695 compiler->fscratches = fscratches;
696 compiler->fsaveds = fsaveds;
697 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
698 compiler->last_return = args & SLJIT_ARG_MASK;
699 compiler->logical_local_size = local_size;
700 #endif
703 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
705 label->next = NULL;
706 label->size = compiler->size;
707 if (compiler->last_label)
708 compiler->last_label->next = label;
709 else
710 compiler->labels = label;
711 compiler->last_label = label;
714 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_u32 flags)
716 jump->next = NULL;
717 jump->flags = flags;
718 if (compiler->last_jump)
719 compiler->last_jump->next = jump;
720 else
721 compiler->jumps = jump;
722 compiler->last_jump = jump;
725 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
727 const_->next = NULL;
728 const_->addr = compiler->size;
729 if (compiler->last_const)
730 compiler->last_const->next = const_;
731 else
732 compiler->consts = const_;
733 compiler->last_const = const_;
736 static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
738 put_label->next = NULL;
739 put_label->label = NULL;
740 put_label->addr = compiler->size - offset;
741 put_label->flags = 0;
742 if (compiler->last_put_label)
743 compiler->last_put_label->next = put_label;
744 else
745 compiler->put_labels = put_label;
746 compiler->last_put_label = put_label;
749 #define ADDRESSING_DEPENDS_ON(exp, reg) \
750 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
752 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
754 static sljit_s32 function_check_arguments(sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches)
756 sljit_s32 word_arg_count, scratch_arg_end, saved_arg_count, float_arg_count, curr_type;
758 curr_type = (arg_types & SLJIT_ARG_FULL_MASK);
760 if (curr_type >= SLJIT_ARG_TYPE_F64) {
761 if (curr_type > SLJIT_ARG_TYPE_F32 || fscratches == 0)
762 return 0;
763 } else if (curr_type >= SLJIT_ARG_TYPE_W) {
764 if (scratches == 0)
765 return 0;
768 arg_types >>= SLJIT_ARG_SHIFT;
770 word_arg_count = 0;
771 scratch_arg_end = 0;
772 saved_arg_count = 0;
773 float_arg_count = 0;
774 while (arg_types != 0) {
775 if (word_arg_count + float_arg_count >= 4)
776 return 0;
778 curr_type = (arg_types & SLJIT_ARG_MASK);
780 if (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) {
781 if (saveds == -1 || curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_P)
782 return 0;
784 word_arg_count++;
785 scratch_arg_end = word_arg_count;
786 } else {
787 if (curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_F32)
788 return 0;
790 if (curr_type < SLJIT_ARG_TYPE_F64) {
791 word_arg_count++;
792 saved_arg_count++;
793 } else
794 float_arg_count++;
797 arg_types >>= SLJIT_ARG_SHIFT;
800 if (saveds == -1)
801 return (word_arg_count <= scratches && float_arg_count <= fscratches);
803 return (saved_arg_count <= saveds && scratch_arg_end <= scratches && float_arg_count <= fscratches);
806 #define FUNCTION_CHECK_IS_REG(r) \
807 (((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
808 || ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
810 #define FUNCTION_CHECK_IS_FREG(fr) \
811 (((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
812 || ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
814 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
815 #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
816 #else
817 #define CHECK_IF_VIRTUAL_REGISTER(p) 0
818 #endif
820 static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
822 if (compiler->scratches == -1 || compiler->saveds == -1)
823 return 0;
825 if (!(p & SLJIT_MEM))
826 return 0;
828 if (!(!(p & REG_MASK) || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
829 return 0;
831 if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
832 return 0;
834 if (p & OFFS_REG_MASK) {
835 if (!(p & REG_MASK))
836 return 0;
838 if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
839 return 0;
841 if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
842 return 0;
844 if ((i & ~0x3) != 0)
845 return 0;
848 return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
851 #define FUNCTION_CHECK_SRC_MEM(p, i) \
852 CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
854 static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
856 if (compiler->scratches == -1 || compiler->saveds == -1)
857 return 0;
859 if (FUNCTION_CHECK_IS_REG(p))
860 return (i == 0);
862 if (p == SLJIT_IMM)
863 return 1;
865 if (p == SLJIT_MEM1(SLJIT_SP))
866 return (i >= 0 && i < compiler->logical_local_size);
868 return function_check_src_mem(compiler, p, i);
871 #define FUNCTION_CHECK_SRC(p, i) \
872 CHECK_ARGUMENT(function_check_src(compiler, p, i));
874 static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
876 if (compiler->scratches == -1 || compiler->saveds == -1)
877 return 0;
879 if (FUNCTION_CHECK_IS_REG(p))
880 return (i == 0);
882 if (p == SLJIT_MEM1(SLJIT_SP))
883 return (i >= 0 && i < compiler->logical_local_size);
885 return function_check_src_mem(compiler, p, i);
888 #define FUNCTION_CHECK_DST(p, i) \
889 CHECK_ARGUMENT(function_check_dst(compiler, p, i));
891 static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
893 if (compiler->scratches == -1 || compiler->saveds == -1)
894 return 0;
896 if (FUNCTION_CHECK_IS_FREG(p))
897 return (i == 0);
899 if (p == SLJIT_MEM1(SLJIT_SP))
900 return (i >= 0 && i < compiler->logical_local_size);
902 return function_check_src_mem(compiler, p, i);
905 #define FUNCTION_FCHECK(p, i) \
906 CHECK_ARGUMENT(function_fcheck(compiler, p, i));
908 #endif /* SLJIT_ARGUMENT_CHECKS */
910 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
912 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
914 compiler->verbose = verbose;
917 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
918 #ifdef _WIN64
919 #ifdef __GNUC__
920 # define SLJIT_PRINT_D "ll"
921 #else
922 # define SLJIT_PRINT_D "I64"
923 #endif
924 #else
925 # define SLJIT_PRINT_D "l"
926 #endif
927 #else
928 # define SLJIT_PRINT_D ""
929 #endif
931 static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
933 if (r < (SLJIT_R0 + compiler->scratches))
934 fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
935 else if (r != SLJIT_SP)
936 fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
937 else
938 fprintf(compiler->verbose, "sp");
941 static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
943 if (r < (SLJIT_FR0 + compiler->fscratches))
944 fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
945 else
946 fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
949 static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
951 if ((p) & SLJIT_IMM)
952 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
953 else if ((p) & SLJIT_MEM) {
954 if ((p) & REG_MASK) {
955 fputc('[', compiler->verbose);
956 sljit_verbose_reg(compiler, (p) & REG_MASK);
957 if ((p) & OFFS_REG_MASK) {
958 fprintf(compiler->verbose, " + ");
959 sljit_verbose_reg(compiler, OFFS_REG(p));
960 if (i)
961 fprintf(compiler->verbose, " * %d", 1 << (i));
963 else if (i)
964 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
965 fputc(']', compiler->verbose);
967 else
968 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
969 } else
970 sljit_verbose_reg(compiler, p);
973 static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
975 if ((p) & SLJIT_MEM) {
976 if ((p) & REG_MASK) {
977 fputc('[', compiler->verbose);
978 sljit_verbose_reg(compiler, (p) & REG_MASK);
979 if ((p) & OFFS_REG_MASK) {
980 fprintf(compiler->verbose, " + ");
981 sljit_verbose_reg(compiler, OFFS_REG(p));
982 if (i)
983 fprintf(compiler->verbose, "%d", 1 << (i));
985 else if (i)
986 fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
987 fputc(']', compiler->verbose);
989 else
990 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
992 else
993 sljit_verbose_freg(compiler, p);
996 static const char* op0_names[] = {
997 "breakpoint", "nop", "lmul.uw", "lmul.sw",
998 "divmod.u", "divmod.s", "div.u", "div.s",
999 "endbr", "skip_frames_before_return"
1002 static const char* op1_names[] = {
1003 "", ".u8", ".s8", ".u16",
1004 ".s16", ".u32", ".s32", "32",
1005 ".p", "not", "clz",
1008 static const char* op2_names[] = {
1009 "add", "addc", "sub", "subc",
1010 "mul", "and", "or", "xor",
1011 "shl", "lshr", "ashr",
1014 static const char* op_src_names[] = {
1015 "fast_return", "skip_frames_before_fast_return",
1016 "prefetch_l1", "prefetch_l2",
1017 "prefetch_l3", "prefetch_once",
1020 static const char* fop1_names[] = {
1021 "mov", "conv", "conv", "conv",
1022 "conv", "conv", "cmp", "neg",
1023 "abs",
1026 static const char* fop2_names[] = {
1027 "add", "sub", "mul", "div"
1030 static const char* jump_names[] = {
1031 "equal", "not_equal",
1032 "less", "greater_equal",
1033 "greater", "less_equal",
1034 "sig_less", "sig_greater_equal",
1035 "sig_greater", "sig_less_equal",
1036 "overflow", "not_overflow",
1037 "carry", "",
1038 "f_equal", "f_not_equal",
1039 "f_less", "f_greater_equal",
1040 "f_greater", "f_less_equal",
1041 "unordered", "ordered",
1042 "ordered_equal", "unordered_or_not_equal",
1043 "ordered_less", "unordered_or_greater_equal",
1044 "ordered_greater", "unordered_or_less_equal",
1045 "unordered_or_equal", "ordered_not_equal",
1046 "unordered_or_less", "ordered_greater_equal",
1047 "unordered_or_greater", "ordered_less_equal",
1048 "jump", "fast_call",
1049 "call", "call.cdecl"
1052 static const char* call_arg_names[] = {
1053 "void", "w", "32", "p", "f64", "f32"
1056 #endif /* SLJIT_VERBOSE */
1058 /* --------------------------------------------------------------------- */
1059 /* Arch dependent */
1060 /* --------------------------------------------------------------------- */
1062 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1063 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1065 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
1067 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1068 struct sljit_jump *jump;
1069 #endif
1071 SLJIT_UNUSED_ARG(compiler);
1073 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1074 CHECK_ARGUMENT(compiler->size > 0);
1075 jump = compiler->jumps;
1076 while (jump) {
1077 /* All jumps have target. */
1078 CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
1079 jump = jump->next;
1081 #endif
1082 CHECK_RETURN_OK;
1085 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
1086 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1087 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1089 SLJIT_UNUSED_ARG(compiler);
1091 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1092 CHECK_ARGUMENT(!(options & ~(SLJIT_ENTER_KEEP_S0 | SLJIT_ENTER_KEEP_S0_S1 | SLJIT_ENTER_CDECL)));
1093 CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 2 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1094 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1095 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1096 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1097 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1098 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1099 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1100 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1101 CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1102 CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, saveds - SLJIT_KEPT_SAVEDS_COUNT(options), fscratches));
1104 compiler->last_flags = 0;
1105 #endif
1106 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1107 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1108 fprintf(compiler->verbose, " enter ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1110 arg_types >>= SLJIT_ARG_SHIFT;
1111 if (arg_types) {
1112 fprintf(compiler->verbose, "], args[");
1113 do {
1114 fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1115 (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1116 arg_types >>= SLJIT_ARG_SHIFT;
1117 if (arg_types)
1118 fprintf(compiler->verbose, ",");
1119 } while (arg_types);
1122 fprintf(compiler->verbose, "],");
1124 if (options & SLJIT_ENTER_CDECL)
1125 fprintf(compiler->verbose, " enter:cdecl,");
1126 if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1127 fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1129 fprintf(compiler->verbose, "scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1130 scratches, saveds, fscratches, fsaveds, local_size);
1132 #endif
1133 CHECK_RETURN_OK;
1136 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
1137 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1138 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1140 SLJIT_UNUSED_ARG(compiler);
1142 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1143 CHECK_ARGUMENT(!(options & ~(SLJIT_ENTER_KEEP_S0 | SLJIT_ENTER_KEEP_S0_S1 | SLJIT_ENTER_CDECL)));
1144 CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 2 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1145 CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1146 CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1147 CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1148 CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1149 CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1150 CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1151 CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1152 CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1153 CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, saveds - SLJIT_KEPT_SAVEDS_COUNT(options), fscratches));
1155 compiler->last_flags = 0;
1156 #endif
1157 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1158 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1159 fprintf(compiler->verbose, " set_context ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1161 arg_types >>= SLJIT_ARG_SHIFT;
1162 if (arg_types) {
1163 fprintf(compiler->verbose, "], args[");
1164 do {
1165 fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1166 (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1167 arg_types >>= SLJIT_ARG_SHIFT;
1168 if (arg_types)
1169 fprintf(compiler->verbose, ",");
1170 } while (arg_types);
1173 fprintf(compiler->verbose, "],");
1175 if (options & SLJIT_ENTER_CDECL)
1176 fprintf(compiler->verbose, " enter:cdecl,");
1177 if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1178 fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1180 fprintf(compiler->verbose, " scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1181 scratches, saveds, fscratches, fsaveds, local_size);
1183 #endif
1184 CHECK_RETURN_OK;
1187 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_compiler *compiler)
1189 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1190 compiler->skip_checks = 0;
1191 CHECK_RETURN_OK;
1194 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1195 CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_VOID);
1196 #endif
1198 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1199 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1200 fprintf(compiler->verbose, " return_void\n");
1202 #endif
1203 CHECK_RETURN_OK;
1206 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1208 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1209 CHECK_ARGUMENT(compiler->scratches >= 0);
1211 switch (compiler->last_return) {
1212 case SLJIT_ARG_TYPE_W:
1213 CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_S32);
1214 break;
1215 case SLJIT_ARG_TYPE_32:
1216 CHECK_ARGUMENT(op == SLJIT_MOV32 || (op >= SLJIT_MOV32_U8 && op <= SLJIT_MOV32_S16));
1217 break;
1218 case SLJIT_ARG_TYPE_P:
1219 CHECK_ARGUMENT(op == SLJIT_MOV_P);
1220 break;
1221 default:
1222 /* Context not initialized, void, etc. */
1223 CHECK_ARGUMENT(0);
1224 break;
1226 FUNCTION_CHECK_SRC(src, srcw);
1227 compiler->last_flags = 0;
1228 #endif
1229 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1230 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1231 fprintf(compiler->verbose, " return%s%s ", !(op & SLJIT_32) ? "" : "32",
1232 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1233 sljit_verbose_param(compiler, src, srcw);
1234 fprintf(compiler->verbose, "\n");
1236 #endif
1237 CHECK_RETURN_OK;
1240 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1242 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1243 FUNCTION_CHECK_DST(dst, dstw);
1244 compiler->last_flags = 0;
1245 #endif
1246 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1247 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1248 fprintf(compiler->verbose, " fast_enter ");
1249 sljit_verbose_param(compiler, dst, dstw);
1250 fprintf(compiler->verbose, "\n");
1252 #endif
1253 CHECK_RETURN_OK;
1256 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1258 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1259 CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1260 || ((op & ~SLJIT_32) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_32) <= SLJIT_DIV_SW)
1261 || (op >= SLJIT_ENDBR && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN));
1262 CHECK_ARGUMENT(GET_OPCODE(op) < SLJIT_LMUL_UW || GET_OPCODE(op) >= SLJIT_ENDBR || compiler->scratches >= 2);
1263 if ((GET_OPCODE(op) >= SLJIT_LMUL_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN)
1264 compiler->last_flags = 0;
1265 #endif
1266 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1267 if (SLJIT_UNLIKELY(!!compiler->verbose))
1269 fprintf(compiler->verbose, " %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1270 if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) {
1271 fprintf(compiler->verbose, (op & SLJIT_32) ? "32" : "w");
1273 fprintf(compiler->verbose, "\n");
1275 #endif
1276 CHECK_RETURN_OK;
1279 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1280 sljit_s32 dst, sljit_sw dstw,
1281 sljit_s32 src, sljit_sw srcw)
1283 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1284 compiler->skip_checks = 0;
1285 CHECK_RETURN_OK;
1288 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1289 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1291 switch (GET_OPCODE(op)) {
1292 case SLJIT_NOT:
1293 /* Only SLJIT_32 and SLJIT_SET_Z are allowed. */
1294 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1295 break;
1296 case SLJIT_MOV:
1297 case SLJIT_MOV_U32:
1298 case SLJIT_MOV_P:
1299 /* Nothing allowed */
1300 CHECK_ARGUMENT(!(op & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1301 break;
1302 default:
1303 /* Only SLJIT_32 is allowed. */
1304 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1305 break;
1308 FUNCTION_CHECK_DST(dst, dstw);
1309 FUNCTION_CHECK_SRC(src, srcw);
1311 if (GET_OPCODE(op) >= SLJIT_NOT) {
1312 CHECK_ARGUMENT(src != SLJIT_IMM);
1313 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1315 #endif
1316 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1317 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1318 if (GET_OPCODE(op) <= SLJIT_MOV_P)
1320 fprintf(compiler->verbose, " mov%s%s ", !(op & SLJIT_32) ? "" : "32",
1321 op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1323 else
1325 fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_32) ? "" : "32",
1326 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1327 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1330 sljit_verbose_param(compiler, dst, dstw);
1331 fprintf(compiler->verbose, ", ");
1332 sljit_verbose_param(compiler, src, srcw);
1333 fprintf(compiler->verbose, "\n");
1335 #endif
1336 CHECK_RETURN_OK;
1339 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset,
1340 sljit_s32 dst, sljit_sw dstw,
1341 sljit_s32 src1, sljit_sw src1w,
1342 sljit_s32 src2, sljit_sw src2w)
1344 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1345 compiler->skip_checks = 0;
1346 CHECK_RETURN_OK;
1349 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1350 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1352 switch (GET_OPCODE(op)) {
1353 case SLJIT_AND:
1354 case SLJIT_OR:
1355 case SLJIT_XOR:
1356 case SLJIT_SHL:
1357 case SLJIT_LSHR:
1358 case SLJIT_ASHR:
1359 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1360 break;
1361 case SLJIT_MUL:
1362 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1363 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1364 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1365 break;
1366 case SLJIT_ADD:
1367 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1368 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1369 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1370 break;
1371 case SLJIT_SUB:
1372 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1373 || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1374 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1375 break;
1376 case SLJIT_ADDC:
1377 case SLJIT_SUBC:
1378 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1379 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1380 CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1381 CHECK_ARGUMENT((op & SLJIT_32) == (compiler->last_flags & SLJIT_32));
1382 break;
1383 default:
1384 SLJIT_UNREACHABLE();
1385 break;
1388 if (unset) {
1389 CHECK_ARGUMENT(HAS_FLAGS(op));
1390 } else {
1391 FUNCTION_CHECK_DST(dst, dstw);
1393 FUNCTION_CHECK_SRC(src1, src1w);
1394 FUNCTION_CHECK_SRC(src2, src2w);
1395 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1396 #endif
1397 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1398 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1399 fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32",
1400 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1401 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1402 if (unset)
1403 fprintf(compiler->verbose, "unset");
1404 else
1405 sljit_verbose_param(compiler, dst, dstw);
1406 fprintf(compiler->verbose, ", ");
1407 sljit_verbose_param(compiler, src1, src1w);
1408 fprintf(compiler->verbose, ", ");
1409 sljit_verbose_param(compiler, src2, src2w);
1410 fprintf(compiler->verbose, "\n");
1412 #endif
1413 CHECK_RETURN_OK;
1416 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
1417 sljit_s32 src, sljit_sw srcw)
1419 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1420 CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE);
1421 FUNCTION_CHECK_SRC(src, srcw);
1423 if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN)
1425 CHECK_ARGUMENT(src != SLJIT_IMM);
1426 compiler->last_flags = 0;
1428 else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE)
1430 CHECK_ARGUMENT(src & SLJIT_MEM);
1432 #endif
1433 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1434 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1435 fprintf(compiler->verbose, " %s ", op_src_names[op - SLJIT_OP_SRC_BASE]);
1436 sljit_verbose_param(compiler, src, srcw);
1437 fprintf(compiler->verbose, "\n");
1439 #endif
1440 CHECK_RETURN_OK;
1443 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1445 SLJIT_UNUSED_ARG(reg);
1446 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1447 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1448 #endif
1449 CHECK_RETURN_OK;
1452 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1454 SLJIT_UNUSED_ARG(reg);
1455 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1456 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1457 #endif
1458 CHECK_RETURN_OK;
1461 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1462 void *instruction, sljit_u32 size)
1464 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1465 sljit_u32 i;
1466 #endif
1468 SLJIT_UNUSED_ARG(compiler);
1470 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1471 CHECK_ARGUMENT(instruction);
1473 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1474 CHECK_ARGUMENT(size > 0 && size < 16);
1475 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1476 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1477 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1478 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
1479 CHECK_ARGUMENT(size == 2 || size == 4 || size == 6);
1480 #else
1481 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1482 #endif
1484 compiler->last_flags = 0;
1485 #endif
1486 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1487 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1488 fprintf(compiler->verbose, " op_custom");
1489 for (i = 0; i < size; i++)
1490 fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1491 fprintf(compiler->verbose, "\n");
1493 #endif
1494 CHECK_RETURN_OK;
1497 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1498 sljit_s32 dst, sljit_sw dstw,
1499 sljit_s32 src, sljit_sw srcw)
1501 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1502 compiler->skip_checks = 0;
1503 CHECK_RETURN_OK;
1506 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1507 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1508 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1509 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1510 FUNCTION_FCHECK(src, srcw);
1511 FUNCTION_FCHECK(dst, dstw);
1512 #endif
1513 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1514 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1515 if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1516 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1517 (op & SLJIT_32) ? ".f32.from.f64" : ".f64.from.f32");
1518 else
1519 fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1520 (op & SLJIT_32) ? ".f32" : ".f64");
1522 sljit_verbose_fparam(compiler, dst, dstw);
1523 fprintf(compiler->verbose, ", ");
1524 sljit_verbose_fparam(compiler, src, srcw);
1525 fprintf(compiler->verbose, "\n");
1527 #endif
1528 CHECK_RETURN_OK;
1531 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1532 sljit_s32 src1, sljit_sw src1w,
1533 sljit_s32 src2, sljit_sw src2w)
1535 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1536 compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32);
1537 #endif
1539 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1540 compiler->skip_checks = 0;
1541 CHECK_RETURN_OK;
1544 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1545 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1546 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1547 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1548 CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1549 || (GET_FLAG_TYPE(op) >= SLJIT_F_EQUAL && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_LESS_EQUAL));
1550 FUNCTION_FCHECK(src1, src1w);
1551 FUNCTION_FCHECK(src2, src2w);
1552 #endif
1553 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1554 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1555 fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1556 if (op & VARIABLE_FLAG_MASK) {
1557 fprintf(compiler->verbose, ".%s", jump_names[GET_FLAG_TYPE(op)]);
1559 fprintf(compiler->verbose, " ");
1560 sljit_verbose_fparam(compiler, src1, src1w);
1561 fprintf(compiler->verbose, ", ");
1562 sljit_verbose_fparam(compiler, src2, src2w);
1563 fprintf(compiler->verbose, "\n");
1565 #endif
1566 CHECK_RETURN_OK;
1569 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1570 sljit_s32 dst, sljit_sw dstw,
1571 sljit_s32 src, sljit_sw srcw)
1573 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1574 compiler->skip_checks = 0;
1575 CHECK_RETURN_OK;
1578 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1579 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1580 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1581 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1582 FUNCTION_FCHECK(src, srcw);
1583 FUNCTION_CHECK_DST(dst, dstw);
1584 #endif
1585 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1586 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1587 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1588 (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1589 (op & SLJIT_32) ? ".f32" : ".f64");
1590 sljit_verbose_param(compiler, dst, dstw);
1591 fprintf(compiler->verbose, ", ");
1592 sljit_verbose_fparam(compiler, src, srcw);
1593 fprintf(compiler->verbose, "\n");
1595 #endif
1596 CHECK_RETURN_OK;
1599 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1600 sljit_s32 dst, sljit_sw dstw,
1601 sljit_s32 src, sljit_sw srcw)
1603 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1604 compiler->skip_checks = 0;
1605 CHECK_RETURN_OK;
1608 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1609 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1610 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1611 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1612 FUNCTION_CHECK_SRC(src, srcw);
1613 FUNCTION_FCHECK(dst, dstw);
1614 #endif
1615 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1616 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1617 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1618 (op & SLJIT_32) ? ".f32" : ".f64",
1619 (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1620 sljit_verbose_fparam(compiler, dst, dstw);
1621 fprintf(compiler->verbose, ", ");
1622 sljit_verbose_param(compiler, src, srcw);
1623 fprintf(compiler->verbose, "\n");
1625 #endif
1626 CHECK_RETURN_OK;
1629 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1630 sljit_s32 dst, sljit_sw dstw,
1631 sljit_s32 src1, sljit_sw src1w,
1632 sljit_s32 src2, sljit_sw src2w)
1634 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1635 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1636 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1637 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1638 FUNCTION_FCHECK(src1, src1w);
1639 FUNCTION_FCHECK(src2, src2w);
1640 FUNCTION_FCHECK(dst, dstw);
1641 #endif
1642 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1643 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1644 fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1645 sljit_verbose_fparam(compiler, dst, dstw);
1646 fprintf(compiler->verbose, ", ");
1647 sljit_verbose_fparam(compiler, src1, src1w);
1648 fprintf(compiler->verbose, ", ");
1649 sljit_verbose_fparam(compiler, src2, src2w);
1650 fprintf(compiler->verbose, "\n");
1652 #endif
1653 CHECK_RETURN_OK;
1656 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1658 SLJIT_UNUSED_ARG(compiler);
1660 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1661 compiler->skip_checks = 0;
1662 CHECK_RETURN_OK;
1665 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1666 compiler->last_flags = 0;
1667 #endif
1669 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1670 if (SLJIT_UNLIKELY(!!compiler->verbose))
1671 fprintf(compiler->verbose, "label:\n");
1672 #endif
1673 CHECK_RETURN_OK;
1676 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1677 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
1678 || (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1679 #define CHECK_UNORDERED(type, last_flags) \
1680 ((((type) & 0xff) == SLJIT_UNORDERED || ((type) & 0xff) == SLJIT_ORDERED) && \
1681 ((last_flags) & 0xff) >= SLJIT_UNORDERED && ((last_flags) & 0xff) <= SLJIT_ORDERED_LESS_EQUAL)
1682 #else
1683 #define CHECK_UNORDERED(type, last_flags) 0
1684 #endif
1685 #endif /* SLJIT_ARGUMENT_CHECKS */
1687 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1689 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1690 compiler->skip_checks = 0;
1691 CHECK_RETURN_OK;
1694 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1695 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1696 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
1698 if ((type & 0xff) < SLJIT_JUMP) {
1699 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1700 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1701 else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) {
1702 CHECK_ARGUMENT((type & 0xff) == SLJIT_CARRY || (type & 0xff) == SLJIT_NOT_CARRY);
1703 compiler->last_flags = 0;
1704 } else
1705 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1706 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1707 || CHECK_UNORDERED(type, compiler->last_flags));
1709 #endif
1710 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1711 if (SLJIT_UNLIKELY(!!compiler->verbose))
1712 fprintf(compiler->verbose, " jump%s %s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1713 jump_names[type & 0xff]);
1714 #endif
1715 CHECK_RETURN_OK;
1718 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
1719 sljit_s32 arg_types)
1721 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1722 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_CALL_RETURN)));
1723 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
1724 CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1726 if (type & SLJIT_CALL_RETURN) {
1727 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1729 #endif
1730 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1731 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1732 fprintf(compiler->verbose, " %s%s%s ret[%s", jump_names[type & 0xff],
1733 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1734 !(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1735 call_arg_names[arg_types & SLJIT_ARG_MASK]);
1737 arg_types >>= SLJIT_ARG_SHIFT;
1738 if (arg_types) {
1739 fprintf(compiler->verbose, "], args[");
1740 do {
1741 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1742 arg_types >>= SLJIT_ARG_SHIFT;
1743 if (arg_types)
1744 fprintf(compiler->verbose, ",");
1745 } while (arg_types);
1747 fprintf(compiler->verbose, "]\n");
1749 #endif
1750 CHECK_RETURN_OK;
1753 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1754 sljit_s32 src1, sljit_sw src1w,
1755 sljit_s32 src2, sljit_sw src2w)
1757 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1758 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1759 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1760 FUNCTION_CHECK_SRC(src1, src1w);
1761 FUNCTION_CHECK_SRC(src2, src2w);
1762 compiler->last_flags = 0;
1763 #endif
1764 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1765 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1766 fprintf(compiler->verbose, " cmp%s%s %s, ", (type & SLJIT_32) ? "32" : "",
1767 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1768 sljit_verbose_param(compiler, src1, src1w);
1769 fprintf(compiler->verbose, ", ");
1770 sljit_verbose_param(compiler, src2, src2w);
1771 fprintf(compiler->verbose, "\n");
1773 #endif
1774 CHECK_RETURN_OK;
1777 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1778 sljit_s32 src1, sljit_sw src1w,
1779 sljit_s32 src2, sljit_sw src2w)
1781 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1782 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1783 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1784 CHECK_ARGUMENT((type & 0xff) >= SLJIT_F_EQUAL && (type & 0xff) <= SLJIT_ORDERED_LESS_EQUAL
1785 && ((type & 0xff) <= SLJIT_ORDERED || sljit_cmp_info(type & 0xff)));
1786 FUNCTION_FCHECK(src1, src1w);
1787 FUNCTION_FCHECK(src2, src2w);
1788 compiler->last_flags = 0;
1789 #endif
1790 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1791 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1792 fprintf(compiler->verbose, " fcmp%s%s %s, ", (type & SLJIT_32) ? ".f32" : ".f64",
1793 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1794 sljit_verbose_fparam(compiler, src1, src1w);
1795 fprintf(compiler->verbose, ", ");
1796 sljit_verbose_fparam(compiler, src2, src2w);
1797 fprintf(compiler->verbose, "\n");
1799 #endif
1800 CHECK_RETURN_OK;
1803 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
1804 sljit_s32 src, sljit_sw srcw)
1806 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1807 compiler->skip_checks = 0;
1808 CHECK_RETURN_OK;
1811 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1812 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
1813 FUNCTION_CHECK_SRC(src, srcw);
1814 #endif
1815 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1816 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1817 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1818 sljit_verbose_param(compiler, src, srcw);
1819 fprintf(compiler->verbose, "\n");
1821 #endif
1822 CHECK_RETURN_OK;
1825 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
1826 sljit_s32 arg_types,
1827 sljit_s32 src, sljit_sw srcw)
1829 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1830 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_CALL_RETURN)));
1831 CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL || (type & 0xff) == SLJIT_CALL_CDECL);
1832 CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1833 FUNCTION_CHECK_SRC(src, srcw);
1835 if (type & SLJIT_CALL_RETURN) {
1836 CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1838 #endif
1839 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1840 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1841 fprintf(compiler->verbose, " i%s%s ret[%s", jump_names[type & 0xff],
1842 !(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1843 call_arg_names[arg_types & SLJIT_ARG_MASK]);
1845 arg_types >>= SLJIT_ARG_SHIFT;
1846 if (arg_types) {
1847 fprintf(compiler->verbose, "], args[");
1848 do {
1849 fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1850 arg_types >>= SLJIT_ARG_SHIFT;
1851 if (arg_types)
1852 fprintf(compiler->verbose, ",");
1853 } while (arg_types);
1855 fprintf(compiler->verbose, "], ");
1856 sljit_verbose_param(compiler, src, srcw);
1857 fprintf(compiler->verbose, "\n");
1859 #endif
1860 CHECK_RETURN_OK;
1863 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1864 sljit_s32 dst, sljit_sw dstw,
1865 sljit_s32 type)
1867 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1868 CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1869 CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1870 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1871 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1873 if (type <= SLJIT_NOT_ZERO)
1874 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1875 else
1876 CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1877 || (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1878 || (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1879 || CHECK_UNORDERED(type, compiler->last_flags));
1881 FUNCTION_CHECK_DST(dst, dstw);
1883 if (GET_OPCODE(op) >= SLJIT_ADD)
1884 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1885 #endif
1886 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1887 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1888 fprintf(compiler->verbose, " flags.%s%s%s ",
1889 GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1890 GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_32) ? "32" : ""),
1891 !(op & SLJIT_SET_Z) ? "" : ".z");
1892 sljit_verbose_param(compiler, dst, dstw);
1893 fprintf(compiler->verbose, ", %s\n", jump_names[type]);
1895 #endif
1896 CHECK_RETURN_OK;
1899 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1900 sljit_s32 dst_reg,
1901 sljit_s32 src, sljit_sw srcw)
1903 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1904 CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1906 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
1907 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_32));
1908 if (src != SLJIT_IMM) {
1909 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
1910 CHECK_ARGUMENT(srcw == 0);
1913 if (type <= SLJIT_NOT_ZERO)
1914 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1915 else
1916 CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1917 || (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1918 || (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1919 || CHECK_UNORDERED(type, compiler->last_flags));
1920 #endif
1921 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1922 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1923 fprintf(compiler->verbose, " cmov%s %s, ",
1924 !(dst_reg & SLJIT_32) ? "" : "32",
1925 jump_names[type]);
1926 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_32);
1927 fprintf(compiler->verbose, ", ");
1928 sljit_verbose_param(compiler, src, srcw);
1929 fprintf(compiler->verbose, "\n");
1931 #endif
1932 CHECK_RETURN_OK;
1935 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
1936 sljit_s32 reg,
1937 sljit_s32 mem, sljit_sw memw)
1939 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1940 CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
1941 CHECK_ARGUMENT(!(type & SLJIT_32) || ((type & 0xff) != SLJIT_MOV && (type & 0xff) != SLJIT_MOV_U32 && (type & 0xff) != SLJIT_MOV_P));
1942 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1943 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1944 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1946 FUNCTION_CHECK_SRC_MEM(mem, memw);
1947 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
1949 CHECK_ARGUMENT((mem & REG_MASK) != 0 && (mem & REG_MASK) != reg);
1950 #endif
1951 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1952 if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
1953 if (sljit_emit_mem(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
1954 fprintf(compiler->verbose, " //");
1956 fprintf(compiler->verbose, " mem%s.%s%s%s ",
1957 !(type & SLJIT_32) ? "" : "32",
1958 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1959 op1_names[(type & 0xff) - SLJIT_OP1_BASE],
1960 (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
1961 sljit_verbose_reg(compiler, reg);
1962 fprintf(compiler->verbose, ", ");
1963 sljit_verbose_param(compiler, mem, memw);
1964 fprintf(compiler->verbose, "\n");
1966 #endif
1967 CHECK_RETURN_OK;
1970 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
1971 sljit_s32 freg,
1972 sljit_s32 mem, sljit_sw memw)
1974 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1975 CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
1976 CHECK_ARGUMENT((type & SLJIT_MEM_PRE) || (type & SLJIT_MEM_POST));
1977 CHECK_ARGUMENT((type & (SLJIT_MEM_PRE | SLJIT_MEM_POST)) != (SLJIT_MEM_PRE | SLJIT_MEM_POST));
1978 CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_PRE | SLJIT_MEM_POST)) == 0);
1980 FUNCTION_CHECK_SRC_MEM(mem, memw);
1981 CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
1982 #endif
1983 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1984 if (!(type & SLJIT_MEM_SUPP) && SLJIT_UNLIKELY(!!compiler->verbose)) {
1985 if (sljit_emit_fmem(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED)
1986 fprintf(compiler->verbose, " //");
1988 fprintf(compiler->verbose, " fmem.%s%s%s ",
1989 (type & SLJIT_MEM_STORE) ? "st" : "ld",
1990 !(type & SLJIT_32) ? ".f64" : ".f32",
1991 (type & SLJIT_MEM_PRE) ? ".pre" : ".post");
1992 sljit_verbose_freg(compiler, freg);
1993 fprintf(compiler->verbose, ", ");
1994 sljit_verbose_param(compiler, mem, memw);
1995 fprintf(compiler->verbose, "\n");
1997 #endif
1998 CHECK_RETURN_OK;
2001 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2003 /* Any offset is allowed. */
2004 SLJIT_UNUSED_ARG(offset);
2006 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2007 FUNCTION_CHECK_DST(dst, dstw);
2008 #endif
2009 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2010 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2011 fprintf(compiler->verbose, " local_base ");
2012 sljit_verbose_param(compiler, dst, dstw);
2013 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
2015 #endif
2016 CHECK_RETURN_OK;
2019 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
2021 SLJIT_UNUSED_ARG(init_value);
2023 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2024 FUNCTION_CHECK_DST(dst, dstw);
2025 #endif
2026 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2027 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2028 fprintf(compiler->verbose, " const ");
2029 sljit_verbose_param(compiler, dst, dstw);
2030 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
2032 #endif
2033 CHECK_RETURN_OK;
2036 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2038 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2039 FUNCTION_CHECK_DST(dst, dstw);
2040 #endif
2041 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2042 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2043 fprintf(compiler->verbose, " put_label ");
2044 sljit_verbose_param(compiler, dst, dstw);
2045 fprintf(compiler->verbose, "\n");
2047 #endif
2048 CHECK_RETURN_OK;
2051 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
2053 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
2054 SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
2055 invalid_float_opcodes); \
2056 if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
2057 if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
2058 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
2059 ADJUST_LOCAL_OFFSET(dst, dstw); \
2060 ADJUST_LOCAL_OFFSET(src, srcw); \
2061 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
2063 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
2064 CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
2065 ADJUST_LOCAL_OFFSET(dst, dstw); \
2066 ADJUST_LOCAL_OFFSET(src, srcw); \
2067 return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
2069 CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
2070 ADJUST_LOCAL_OFFSET(dst, dstw); \
2071 ADJUST_LOCAL_OFFSET(src, srcw); \
2072 return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
2074 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
2075 ADJUST_LOCAL_OFFSET(dst, dstw); \
2076 ADJUST_LOCAL_OFFSET(src, srcw);
2078 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2080 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2081 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
2082 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
2083 return SLJIT_SUCCESS;
2084 #else
2085 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
2086 return SLJIT_SUCCESS;
2087 #endif
2089 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2090 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2091 compiler->skip_checks = 1;
2092 #endif
2093 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
2096 #if !(defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
2098 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2100 CHECK_ERROR();
2101 CHECK(check_sljit_emit_return(compiler, op, src, srcw));
2103 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
2105 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
2106 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2107 compiler->skip_checks = 1;
2108 #endif
2109 return sljit_emit_return_void(compiler);
2112 #endif
2114 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2115 || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
2116 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
2117 || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6))
2119 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
2120 sljit_s32 dst_reg,
2121 sljit_s32 src, sljit_sw srcw)
2123 struct sljit_label *label;
2124 struct sljit_jump *jump;
2125 sljit_s32 op = (dst_reg & SLJIT_32) ? SLJIT_MOV32 : SLJIT_MOV;
2127 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2128 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2129 compiler->skip_checks = 1;
2130 #endif
2131 jump = sljit_emit_jump(compiler, type ^ 0x1);
2132 FAIL_IF(!jump);
2134 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2135 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2136 compiler->skip_checks = 1;
2137 #endif
2138 FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_32, 0, src, srcw));
2140 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2141 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2142 compiler->skip_checks = 1;
2143 #endif
2144 label = sljit_emit_label(compiler);
2145 FAIL_IF(!label);
2146 sljit_set_label(jump, label);
2147 return SLJIT_SUCCESS;
2150 #endif
2152 /* CPU description section */
2154 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
2155 #define SLJIT_CPUINFO_PART1 " 32bit ("
2156 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2157 #define SLJIT_CPUINFO_PART1 " 64bit ("
2158 #else
2159 #error "Internal error: CPU type info missing"
2160 #endif
2162 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
2163 #define SLJIT_CPUINFO_PART2 "little endian + "
2164 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
2165 #define SLJIT_CPUINFO_PART2 "big endian + "
2166 #else
2167 #error "Internal error: CPU type info missing"
2168 #endif
2170 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
2171 #define SLJIT_CPUINFO_PART3 "unaligned)"
2172 #else
2173 #define SLJIT_CPUINFO_PART3 "aligned)"
2174 #endif
2176 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
2178 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
2179 # include "sljitNativeX86_common.c"
2180 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2181 # include "sljitNativeARM_32.c"
2182 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
2183 # include "sljitNativeARM_32.c"
2184 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
2185 # include "sljitNativeARM_T2_32.c"
2186 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2187 # include "sljitNativeARM_64.c"
2188 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2189 # include "sljitNativePPC_common.c"
2190 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2191 # include "sljitNativeMIPS_common.c"
2192 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
2193 # include "sljitNativeSPARC_common.c"
2194 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
2195 # include "sljitNativeS390X.c"
2196 #endif
2198 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2200 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2201 sljit_s32 src1, sljit_sw src1w,
2202 sljit_s32 src2, sljit_sw src2w)
2204 /* Default compare for most architectures. */
2205 sljit_s32 flags, tmp_src, condition;
2206 sljit_sw tmp_srcw;
2208 CHECK_ERROR_PTR();
2209 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
2211 condition = type & 0xff;
2212 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2213 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
2214 if ((src1 & SLJIT_IMM) && !src1w) {
2215 src1 = src2;
2216 src1w = src2w;
2217 src2 = SLJIT_IMM;
2218 src2w = 0;
2220 if ((src2 & SLJIT_IMM) && !src2w)
2221 return emit_cmp_to0(compiler, type, src1, src1w);
2223 #endif
2225 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
2226 /* Immediate is preferred as second argument by most architectures. */
2227 switch (condition) {
2228 case SLJIT_LESS:
2229 condition = SLJIT_GREATER;
2230 break;
2231 case SLJIT_GREATER_EQUAL:
2232 condition = SLJIT_LESS_EQUAL;
2233 break;
2234 case SLJIT_GREATER:
2235 condition = SLJIT_LESS;
2236 break;
2237 case SLJIT_LESS_EQUAL:
2238 condition = SLJIT_GREATER_EQUAL;
2239 break;
2240 case SLJIT_SIG_LESS:
2241 condition = SLJIT_SIG_GREATER;
2242 break;
2243 case SLJIT_SIG_GREATER_EQUAL:
2244 condition = SLJIT_SIG_LESS_EQUAL;
2245 break;
2246 case SLJIT_SIG_GREATER:
2247 condition = SLJIT_SIG_LESS;
2248 break;
2249 case SLJIT_SIG_LESS_EQUAL:
2250 condition = SLJIT_SIG_GREATER_EQUAL;
2251 break;
2254 type = condition | (type & (SLJIT_32 | SLJIT_REWRITABLE_JUMP));
2255 tmp_src = src1;
2256 src1 = src2;
2257 src2 = tmp_src;
2258 tmp_srcw = src1w;
2259 src1w = src2w;
2260 src2w = tmp_srcw;
2263 if (condition <= SLJIT_NOT_ZERO)
2264 flags = SLJIT_SET_Z;
2265 else
2266 flags = condition << VARIABLE_FLAG_SHIFT;
2268 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2269 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2270 compiler->skip_checks = 1;
2271 #endif
2272 PTR_FAIL_IF(sljit_emit_op2u(compiler,
2273 SLJIT_SUB | flags | (type & SLJIT_32), src1, src1w, src2, src2w));
2274 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2275 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2276 compiler->skip_checks = 1;
2277 #endif
2278 return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_32)));
2281 #endif /* !SLJIT_CONFIG_MIPS */
2283 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
2285 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2287 if (type < SLJIT_UNORDERED || type > SLJIT_ORDERED_LESS_EQUAL)
2288 return 0;
2290 switch (type) {
2291 case SLJIT_UNORDERED_OR_EQUAL:
2292 case SLJIT_ORDERED_NOT_EQUAL:
2293 return 0;
2296 return 1;
2299 #endif /* SLJIT_CONFIG_ARM */
2301 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2302 sljit_s32 src1, sljit_sw src1w,
2303 sljit_s32 src2, sljit_sw src2w)
2305 CHECK_ERROR_PTR();
2306 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
2308 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2309 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2310 compiler->skip_checks = 1;
2311 #endif
2312 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_32), src1, src1w, src2, src2w);
2314 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2315 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2316 compiler->skip_checks = 1;
2317 #endif
2318 return sljit_emit_jump(compiler, type);
2321 #if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \
2322 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2323 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2325 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
2326 sljit_s32 reg,
2327 sljit_s32 mem, sljit_sw memw)
2329 SLJIT_UNUSED_ARG(compiler);
2330 SLJIT_UNUSED_ARG(type);
2331 SLJIT_UNUSED_ARG(reg);
2332 SLJIT_UNUSED_ARG(mem);
2333 SLJIT_UNUSED_ARG(memw);
2335 CHECK_ERROR();
2336 CHECK(check_sljit_emit_mem(compiler, type, reg, mem, memw));
2338 return SLJIT_ERR_UNSUPPORTED;
2341 #endif
2343 #if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2344 && !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2346 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2347 sljit_s32 freg,
2348 sljit_s32 mem, sljit_sw memw)
2350 SLJIT_UNUSED_ARG(compiler);
2351 SLJIT_UNUSED_ARG(type);
2352 SLJIT_UNUSED_ARG(freg);
2353 SLJIT_UNUSED_ARG(mem);
2354 SLJIT_UNUSED_ARG(memw);
2356 CHECK_ERROR();
2357 CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
2359 return SLJIT_ERR_UNSUPPORTED;
2362 #endif
2364 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2365 && !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2367 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2369 CHECK_ERROR();
2370 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2372 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
2373 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
2374 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2375 compiler->skip_checks = 1;
2376 #endif
2377 if (offset != 0)
2378 return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2379 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
2382 #endif
2384 #else /* SLJIT_CONFIG_UNSUPPORTED */
2386 /* Empty function bodies for those machines, which are not (yet) supported. */
2388 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2390 return "unsupported";
2393 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
2395 SLJIT_UNUSED_ARG(allocator_data);
2396 SLJIT_UNUSED_ARG(exec_allocator_data);
2397 SLJIT_UNREACHABLE();
2398 return NULL;
2401 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
2403 SLJIT_UNUSED_ARG(compiler);
2404 SLJIT_UNREACHABLE();
2407 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
2409 SLJIT_UNUSED_ARG(compiler);
2410 SLJIT_UNREACHABLE();
2413 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
2415 SLJIT_UNUSED_ARG(compiler);
2416 SLJIT_UNUSED_ARG(size);
2417 SLJIT_UNREACHABLE();
2418 return NULL;
2421 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2422 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
2424 SLJIT_UNUSED_ARG(compiler);
2425 SLJIT_UNUSED_ARG(verbose);
2426 SLJIT_UNREACHABLE();
2428 #endif
2430 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
2432 SLJIT_UNUSED_ARG(compiler);
2433 SLJIT_UNREACHABLE();
2434 return NULL;
2437 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
2439 SLJIT_UNUSED_ARG(feature_type);
2440 SLJIT_UNREACHABLE();
2441 return 0;
2444 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2446 SLJIT_UNUSED_ARG(type);
2447 SLJIT_UNREACHABLE();
2448 return 0;
2451 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
2453 SLJIT_UNUSED_ARG(code);
2454 SLJIT_UNUSED_ARG(exec_allocator_data);
2455 SLJIT_UNREACHABLE();
2458 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
2459 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2460 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2462 SLJIT_UNUSED_ARG(compiler);
2463 SLJIT_UNUSED_ARG(options);
2464 SLJIT_UNUSED_ARG(arg_types);
2465 SLJIT_UNUSED_ARG(scratches);
2466 SLJIT_UNUSED_ARG(saveds);
2467 SLJIT_UNUSED_ARG(fscratches);
2468 SLJIT_UNUSED_ARG(fsaveds);
2469 SLJIT_UNUSED_ARG(local_size);
2470 SLJIT_UNREACHABLE();
2471 return SLJIT_ERR_UNSUPPORTED;
2474 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
2475 sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2476 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2478 SLJIT_UNUSED_ARG(compiler);
2479 SLJIT_UNUSED_ARG(options);
2480 SLJIT_UNUSED_ARG(arg_types);
2481 SLJIT_UNUSED_ARG(scratches);
2482 SLJIT_UNUSED_ARG(saveds);
2483 SLJIT_UNUSED_ARG(fscratches);
2484 SLJIT_UNUSED_ARG(fsaveds);
2485 SLJIT_UNUSED_ARG(local_size);
2486 SLJIT_UNREACHABLE();
2487 return SLJIT_ERR_UNSUPPORTED;
2490 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2492 SLJIT_UNUSED_ARG(compiler);
2493 SLJIT_UNUSED_ARG(op);
2494 SLJIT_UNUSED_ARG(src);
2495 SLJIT_UNUSED_ARG(srcw);
2496 SLJIT_UNREACHABLE();
2497 return SLJIT_ERR_UNSUPPORTED;
2500 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler)
2502 SLJIT_UNUSED_ARG(compiler);
2503 SLJIT_UNREACHABLE();
2504 return SLJIT_ERR_UNSUPPORTED;
2507 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2509 SLJIT_UNUSED_ARG(compiler);
2510 SLJIT_UNUSED_ARG(dst);
2511 SLJIT_UNUSED_ARG(dstw);
2512 SLJIT_UNREACHABLE();
2513 return SLJIT_ERR_UNSUPPORTED;
2516 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2518 SLJIT_UNUSED_ARG(compiler);
2519 SLJIT_UNUSED_ARG(op);
2520 SLJIT_UNREACHABLE();
2521 return SLJIT_ERR_UNSUPPORTED;
2524 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2525 sljit_s32 dst, sljit_sw dstw,
2526 sljit_s32 src, sljit_sw srcw)
2528 SLJIT_UNUSED_ARG(compiler);
2529 SLJIT_UNUSED_ARG(op);
2530 SLJIT_UNUSED_ARG(dst);
2531 SLJIT_UNUSED_ARG(dstw);
2532 SLJIT_UNUSED_ARG(src);
2533 SLJIT_UNUSED_ARG(srcw);
2534 SLJIT_UNREACHABLE();
2535 return SLJIT_ERR_UNSUPPORTED;
2538 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2539 sljit_s32 dst, sljit_sw dstw,
2540 sljit_s32 src1, sljit_sw src1w,
2541 sljit_s32 src2, sljit_sw src2w)
2543 SLJIT_UNUSED_ARG(compiler);
2544 SLJIT_UNUSED_ARG(op);
2545 SLJIT_UNUSED_ARG(dst);
2546 SLJIT_UNUSED_ARG(dstw);
2547 SLJIT_UNUSED_ARG(src1);
2548 SLJIT_UNUSED_ARG(src1w);
2549 SLJIT_UNUSED_ARG(src2);
2550 SLJIT_UNUSED_ARG(src2w);
2551 SLJIT_UNREACHABLE();
2552 return SLJIT_ERR_UNSUPPORTED;
2555 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,
2556 sljit_s32 src1, sljit_sw src1w,
2557 sljit_s32 src2, sljit_sw src2w)
2559 SLJIT_UNUSED_ARG(compiler);
2560 SLJIT_UNUSED_ARG(op);
2561 SLJIT_UNUSED_ARG(src1);
2562 SLJIT_UNUSED_ARG(src1w);
2563 SLJIT_UNUSED_ARG(src2);
2564 SLJIT_UNUSED_ARG(src2w);
2565 SLJIT_UNREACHABLE();
2566 return SLJIT_ERR_UNSUPPORTED;
2569 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
2570 sljit_s32 src, sljit_sw srcw)
2572 SLJIT_UNUSED_ARG(compiler);
2573 SLJIT_UNUSED_ARG(op);
2574 SLJIT_UNUSED_ARG(src);
2575 SLJIT_UNUSED_ARG(srcw);
2576 SLJIT_UNREACHABLE();
2577 return SLJIT_ERR_UNSUPPORTED;
2580 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2582 SLJIT_UNREACHABLE();
2583 return reg;
2586 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2587 void *instruction, sljit_u32 size)
2589 SLJIT_UNUSED_ARG(compiler);
2590 SLJIT_UNUSED_ARG(instruction);
2591 SLJIT_UNUSED_ARG(size);
2592 SLJIT_UNREACHABLE();
2593 return SLJIT_ERR_UNSUPPORTED;
2596 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2598 SLJIT_UNUSED_ARG(compiler);
2599 SLJIT_UNUSED_ARG(current_flags);
2602 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2603 sljit_s32 dst, sljit_sw dstw,
2604 sljit_s32 src, sljit_sw srcw)
2606 SLJIT_UNUSED_ARG(compiler);
2607 SLJIT_UNUSED_ARG(op);
2608 SLJIT_UNUSED_ARG(dst);
2609 SLJIT_UNUSED_ARG(dstw);
2610 SLJIT_UNUSED_ARG(src);
2611 SLJIT_UNUSED_ARG(srcw);
2612 SLJIT_UNREACHABLE();
2613 return SLJIT_ERR_UNSUPPORTED;
2616 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2617 sljit_s32 dst, sljit_sw dstw,
2618 sljit_s32 src1, sljit_sw src1w,
2619 sljit_s32 src2, sljit_sw src2w)
2621 SLJIT_UNUSED_ARG(compiler);
2622 SLJIT_UNUSED_ARG(op);
2623 SLJIT_UNUSED_ARG(dst);
2624 SLJIT_UNUSED_ARG(dstw);
2625 SLJIT_UNUSED_ARG(src1);
2626 SLJIT_UNUSED_ARG(src1w);
2627 SLJIT_UNUSED_ARG(src2);
2628 SLJIT_UNUSED_ARG(src2w);
2629 SLJIT_UNREACHABLE();
2630 return SLJIT_ERR_UNSUPPORTED;
2633 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2635 SLJIT_UNUSED_ARG(compiler);
2636 SLJIT_UNREACHABLE();
2637 return NULL;
2640 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2642 SLJIT_UNUSED_ARG(compiler);
2643 SLJIT_UNUSED_ARG(type);
2644 SLJIT_UNREACHABLE();
2645 return NULL;
2648 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
2649 sljit_s32 arg_types)
2651 SLJIT_UNUSED_ARG(compiler);
2652 SLJIT_UNUSED_ARG(type);
2653 SLJIT_UNUSED_ARG(arg_types);
2654 SLJIT_UNREACHABLE();
2655 return NULL;
2658 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2659 sljit_s32 src1, sljit_sw src1w,
2660 sljit_s32 src2, sljit_sw src2w)
2662 SLJIT_UNUSED_ARG(compiler);
2663 SLJIT_UNUSED_ARG(type);
2664 SLJIT_UNUSED_ARG(src1);
2665 SLJIT_UNUSED_ARG(src1w);
2666 SLJIT_UNUSED_ARG(src2);
2667 SLJIT_UNUSED_ARG(src2w);
2668 SLJIT_UNREACHABLE();
2669 return NULL;
2672 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2673 sljit_s32 src1, sljit_sw src1w,
2674 sljit_s32 src2, sljit_sw src2w)
2676 SLJIT_UNUSED_ARG(compiler);
2677 SLJIT_UNUSED_ARG(type);
2678 SLJIT_UNUSED_ARG(src1);
2679 SLJIT_UNUSED_ARG(src1w);
2680 SLJIT_UNUSED_ARG(src2);
2681 SLJIT_UNUSED_ARG(src2w);
2682 SLJIT_UNREACHABLE();
2683 return NULL;
2686 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2688 SLJIT_UNUSED_ARG(jump);
2689 SLJIT_UNUSED_ARG(label);
2690 SLJIT_UNREACHABLE();
2693 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2695 SLJIT_UNUSED_ARG(jump);
2696 SLJIT_UNUSED_ARG(target);
2697 SLJIT_UNREACHABLE();
2700 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
2702 SLJIT_UNUSED_ARG(put_label);
2703 SLJIT_UNUSED_ARG(label);
2704 SLJIT_UNREACHABLE();
2707 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2709 SLJIT_UNUSED_ARG(compiler);
2710 SLJIT_UNUSED_ARG(type);
2711 SLJIT_UNUSED_ARG(src);
2712 SLJIT_UNUSED_ARG(srcw);
2713 SLJIT_UNREACHABLE();
2714 return SLJIT_ERR_UNSUPPORTED;
2717 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
2718 sljit_s32 arg_types,
2719 sljit_s32 src, sljit_sw srcw)
2721 SLJIT_UNUSED_ARG(compiler);
2722 SLJIT_UNUSED_ARG(type);
2723 SLJIT_UNUSED_ARG(arg_types);
2724 SLJIT_UNUSED_ARG(src);
2725 SLJIT_UNUSED_ARG(srcw);
2726 SLJIT_UNREACHABLE();
2727 return SLJIT_ERR_UNSUPPORTED;
2730 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2731 sljit_s32 dst, sljit_sw dstw,
2732 sljit_s32 type)
2734 SLJIT_UNUSED_ARG(compiler);
2735 SLJIT_UNUSED_ARG(op);
2736 SLJIT_UNUSED_ARG(dst);
2737 SLJIT_UNUSED_ARG(dstw);
2738 SLJIT_UNUSED_ARG(type);
2739 SLJIT_UNREACHABLE();
2740 return SLJIT_ERR_UNSUPPORTED;
2743 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
2744 sljit_s32 dst_reg,
2745 sljit_s32 src, sljit_sw srcw)
2747 SLJIT_UNUSED_ARG(compiler);
2748 SLJIT_UNUSED_ARG(type);
2749 SLJIT_UNUSED_ARG(dst_reg);
2750 SLJIT_UNUSED_ARG(src);
2751 SLJIT_UNUSED_ARG(srcw);
2752 SLJIT_UNREACHABLE();
2753 return SLJIT_ERR_UNSUPPORTED;
2756 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)
2758 SLJIT_UNUSED_ARG(compiler);
2759 SLJIT_UNUSED_ARG(type);
2760 SLJIT_UNUSED_ARG(reg);
2761 SLJIT_UNUSED_ARG(mem);
2762 SLJIT_UNUSED_ARG(memw);
2763 SLJIT_UNREACHABLE();
2764 return SLJIT_ERR_UNSUPPORTED;
2767 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)
2769 SLJIT_UNUSED_ARG(compiler);
2770 SLJIT_UNUSED_ARG(type);
2771 SLJIT_UNUSED_ARG(freg);
2772 SLJIT_UNUSED_ARG(mem);
2773 SLJIT_UNUSED_ARG(memw);
2774 SLJIT_UNREACHABLE();
2775 return SLJIT_ERR_UNSUPPORTED;
2778 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2780 SLJIT_UNUSED_ARG(compiler);
2781 SLJIT_UNUSED_ARG(dst);
2782 SLJIT_UNUSED_ARG(dstw);
2783 SLJIT_UNUSED_ARG(offset);
2784 SLJIT_UNREACHABLE();
2785 return SLJIT_ERR_UNSUPPORTED;
2788 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2790 SLJIT_UNUSED_ARG(compiler);
2791 SLJIT_UNUSED_ARG(dst);
2792 SLJIT_UNUSED_ARG(dstw);
2793 SLJIT_UNUSED_ARG(initval);
2794 SLJIT_UNREACHABLE();
2795 return NULL;
2798 SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2800 SLJIT_UNUSED_ARG(compiler);
2801 SLJIT_UNUSED_ARG(dst);
2802 SLJIT_UNUSED_ARG(dstw);
2803 return NULL;
2806 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2808 SLJIT_UNUSED_ARG(addr);
2809 SLJIT_UNUSED_ARG(new_target);
2810 SLJIT_UNUSED_ARG(executable_offset);
2811 SLJIT_UNREACHABLE();
2814 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2816 SLJIT_UNUSED_ARG(addr);
2817 SLJIT_UNUSED_ARG(new_constant);
2818 SLJIT_UNUSED_ARG(executable_offset);
2819 SLJIT_UNREACHABLE();
2822 #endif /* !SLJIT_CONFIG_UNSUPPORTED */