• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Stack-less Just-In-Time compiler
3  *
4  *    Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without modification, are
7  * permitted provided that the following conditions are met:
8  *
9  *   1. Redistributions of source code must retain the above copyright notice, this list of
10  *      conditions and the following disclaimer.
11  *
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.
15  *
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.
25  */
26 
27 #include "sljitLir.h"
28 
29 #ifdef _WIN32
30 
31 #include <windows.h>
32 
33 #endif /* _WIN32 */
34 
35 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
36 
37 /* These libraries are needed for the macros below. */
38 #include <stdlib.h>
39 #include <string.h>
40 
41 #endif /* SLJIT_STD_MACROS_DEFINED */
42 
43 #define CHECK_ERROR() \
44 	do { \
45 		if (SLJIT_UNLIKELY(compiler->error)) \
46 			return compiler->error; \
47 	} while (0)
48 
49 #define CHECK_ERROR_PTR() \
50 	do { \
51 		if (SLJIT_UNLIKELY(compiler->error)) \
52 			return NULL; \
53 	} while (0)
54 
55 #define FAIL_IF(expr) \
56 	do { \
57 		if (SLJIT_UNLIKELY(expr)) \
58 			return compiler->error; \
59 	} while (0)
60 
61 #define PTR_FAIL_IF(expr) \
62 	do { \
63 		if (SLJIT_UNLIKELY(expr)) \
64 			return NULL; \
65 	} while (0)
66 
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)
74 
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)
82 
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)
90 
91 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
92 
93 #define SSIZE_OF(type) ((sljit_s32)sizeof(sljit_ ## type))
94 
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)
98 
99 #define GET_OPCODE(op) \
100 	((op) & ~(SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
101 
102 #define HAS_FLAGS(op) \
103 	((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
104 
105 #define GET_ALL_FLAGS(op) \
106 	((op) & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
107 
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 */
115 
116 #define BUF_SIZE	4096
117 
118 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
119 #define ABUF_SIZE	2048
120 #else
121 #define ABUF_SIZE	4096
122 #endif
123 
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)
131 
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)
135 
136 /* Mask for sljit_emit_mem. */
137 #define REG_PAIR_MASK		0xff00
138 #define REG_PAIR_FIRST(reg)	((reg) & 0xff)
139 #define REG_PAIR_SECOND(reg)	((reg) >> 8)
140 
141 /* Mask for sljit_emit_enter. */
142 #define SLJIT_KEPT_SAVEDS_COUNT(options) ((options) & 0x3)
143 
144 /* Jump flags. */
145 #define JUMP_LABEL	0x1
146 #define JUMP_ADDR	0x2
147 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
148 
149 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
150 #	define PATCH_MB		0x4
151 #	define PATCH_MW		0x8
152 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
153 #	define PATCH_MD		0x10
154 #endif
155 #	define TYPE_SHIFT	13
156 #endif /* SLJIT_CONFIG_X86 */
157 
158 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
159 #	define IS_BL		0x4
160 #	define PATCH_B		0x8
161 #endif /* SLJIT_CONFIG_ARM_V5 || SLJIT_CONFIG_ARM_V7 */
162 
163 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
164 #	define CPOOL_SIZE	512
165 #endif /* SLJIT_CONFIG_ARM_V5 */
166 
167 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
168 #	define IS_COND		0x04
169 #	define IS_BL		0x08
170 	/* conditional + imm8 */
171 #	define PATCH_TYPE1	0x10
172 	/* conditional + imm20 */
173 #	define PATCH_TYPE2	0x20
174 	/* IT + imm24 */
175 #	define PATCH_TYPE3	0x30
176 	/* imm11 */
177 #	define PATCH_TYPE4	0x40
178 	/* imm24 */
179 #	define PATCH_TYPE5	0x50
180 	/* BL + imm24 */
181 #	define PATCH_BL		0x60
182 	/* 0xf00 cc code for branches */
183 #endif /* SLJIT_CONFIG_ARM_THUMB2 */
184 
185 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
186 #	define IS_COND		0x004
187 #	define IS_CBZ		0x008
188 #	define IS_BL		0x010
189 #	define PATCH_B		0x020
190 #	define PATCH_COND	0x040
191 #	define PATCH_ABS48	0x080
192 #	define PATCH_ABS64	0x100
193 #endif /* SLJIT_CONFIG_ARM_64 */
194 
195 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
196 #	define IS_COND		0x004
197 #	define IS_CALL		0x008
198 #	define PATCH_B		0x010
199 #	define PATCH_ABS_B	0x020
200 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
201 #	define PATCH_ABS32	0x040
202 #	define PATCH_ABS48	0x080
203 #endif /* SLJIT_CONFIG_PPC_64 */
204 #	define REMOVE_COND	0x100
205 #endif /* SLJIT_CONFIG_PPC */
206 
207 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
208 #	define IS_MOVABLE	0x004
209 #	define IS_JAL		0x008
210 #	define IS_CALL		0x010
211 #	define IS_BIT26_COND	0x020
212 #	define IS_BIT16_COND	0x040
213 #	define IS_BIT23_COND	0x080
214 
215 #	define IS_COND		(IS_BIT26_COND | IS_BIT16_COND | IS_BIT23_COND)
216 
217 #	define PATCH_B		0x100
218 #	define PATCH_J		0x200
219 
220 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
221 #	define PATCH_ABS32	0x400
222 #	define PATCH_ABS48	0x800
223 #endif /* SLJIT_CONFIG_MIPS_64 */
224 
225 	/* instruction types */
226 #	define MOVABLE_INS	0
227 	/* 1 - 31 last destination register */
228 	/* no destination (i.e: store) */
229 #	define UNMOVABLE_INS	32
230 	/* FPU status register */
231 #	define FCSR_FCC		33
232 #endif /* SLJIT_CONFIG_MIPS */
233 
234 #if (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
235 #	define IS_COND		0x004
236 #	define IS_CALL		0x008
237 
238 #	define PATCH_B		0x010
239 #	define PATCH_J		0x020
240 
241 #if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64)
242 #	define PATCH_REL32	0x040
243 #	define PATCH_ABS32	0x080
244 #	define PATCH_ABS44	0x100
245 #	define PATCH_ABS52	0x200
246 #else /* !SLJIT_CONFIG_RISCV_64 */
247 #	define PATCH_REL32	0x0
248 #endif /* SLJIT_CONFIG_RISCV_64 */
249 #endif /* SLJIT_CONFIG_RISCV */
250 
251 /* Stack management. */
252 
253 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
254 	(((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
255 		(saveds) + (sljit_s32)(extra)) * (sljit_s32)sizeof(sljit_sw))
256 
257 #define GET_SAVED_FLOAT_REGISTERS_SIZE(fscratches, fsaveds, size) \
258 	(((fscratches < SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS ? 0 : (fscratches - SLJIT_NUMBER_OF_SCRATCH_FLOAT_REGISTERS)) + \
259 		(fsaveds)) * (sljit_s32)(size))
260 
261 #define ADJUST_LOCAL_OFFSET(p, i) \
262 	if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
263 		(i) += SLJIT_LOCALS_OFFSET;
264 
265 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
266 
267 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
268 #include "sljitUtils.c"
269 
270 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
271 
272 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
273 
274 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
275 #include "sljitProtExecAllocator.c"
276 #elif (defined SLJIT_WX_EXECUTABLE_ALLOCATOR && SLJIT_WX_EXECUTABLE_ALLOCATOR)
277 #include "sljitWXExecAllocator.c"
278 #else
279 #include "sljitExecAllocator.c"
280 #endif
281 
282 #endif
283 
284 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
285 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
286 #else
287 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
288 #endif
289 
290 #ifndef SLJIT_UPDATE_WX_FLAGS
291 #define SLJIT_UPDATE_WX_FLAGS(from, to, enable_exec)
292 #endif
293 
294 /* Argument checking features. */
295 
296 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
297 
298 /* Returns with error when an invalid argument is passed. */
299 
300 #define CHECK_ARGUMENT(x) \
301 	do { \
302 		if (SLJIT_UNLIKELY(!(x))) \
303 			return 1; \
304 	} while (0)
305 
306 #define CHECK_RETURN_TYPE sljit_s32
307 #define CHECK_RETURN_OK return 0
308 
309 #define CHECK(x) \
310 	do { \
311 		if (SLJIT_UNLIKELY(x)) { \
312 			compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
313 			return SLJIT_ERR_BAD_ARGUMENT; \
314 		} \
315 	} while (0)
316 
317 #define CHECK_PTR(x) \
318 	do { \
319 		if (SLJIT_UNLIKELY(x)) { \
320 			compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
321 			return NULL; \
322 		} \
323 	} while (0)
324 
325 #define CHECK_REG_INDEX(x) \
326 	do { \
327 		if (SLJIT_UNLIKELY(x)) { \
328 			return -2; \
329 		} \
330 	} while (0)
331 
332 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
333 
334 /* Assertion failure occures if an invalid argument is passed. */
335 #undef SLJIT_ARGUMENT_CHECKS
336 #define SLJIT_ARGUMENT_CHECKS 1
337 
338 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
339 #define CHECK_RETURN_TYPE void
340 #define CHECK_RETURN_OK return
341 #define CHECK(x) x
342 #define CHECK_PTR(x) x
343 #define CHECK_REG_INDEX(x) x
344 
345 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
346 
347 /* Arguments are not checked. */
348 #define CHECK_RETURN_TYPE void
349 #define CHECK_RETURN_OK return
350 #define CHECK(x) x
351 #define CHECK_PTR(x) x
352 #define CHECK_REG_INDEX(x) x
353 
354 #else
355 
356 /* Arguments are not checked. */
357 #define CHECK(x)
358 #define CHECK_PTR(x)
359 #define CHECK_REG_INDEX(x)
360 
361 #endif /* SLJIT_ARGUMENT_CHECKS */
362 
363 /* --------------------------------------------------------------------- */
364 /*  Public functions                                                     */
365 /* --------------------------------------------------------------------- */
366 
367 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
368 #define SLJIT_NEEDS_COMPILER_INIT 1
369 static sljit_s32 compiler_initialized = 0;
370 /* A thread safe initialization. */
371 static void init_compiler(void);
372 #endif
373 
sljit_create_compiler(void * allocator_data,void * exec_allocator_data)374 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
375 {
376 	struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
377 	if (!compiler)
378 		return NULL;
379 	SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
380 
381 	SLJIT_COMPILE_ASSERT(
382 		sizeof(sljit_s8) == 1 && sizeof(sljit_u8) == 1
383 		&& sizeof(sljit_s16) == 2 && sizeof(sljit_u16) == 2
384 		&& sizeof(sljit_s32) == 4 && sizeof(sljit_u32) == 4
385 		&& (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
386 		&& sizeof(sljit_p) <= sizeof(sljit_sw)
387 		&& (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
388 		&& (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
389 		invalid_integer_types);
390 	SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_32,
391 		rewritable_jump_and_single_op_must_not_be_the_same);
392 	SLJIT_COMPILE_ASSERT(!(SLJIT_EQUAL & 0x1) && !(SLJIT_LESS & 0x1) && !(SLJIT_F_EQUAL & 0x1) && !(SLJIT_JUMP & 0x1),
393 		conditional_flags_must_be_even_numbers);
394 
395 	/* Only the non-zero members must be set. */
396 	compiler->error = SLJIT_SUCCESS;
397 
398 	compiler->allocator_data = allocator_data;
399 	compiler->exec_allocator_data = exec_allocator_data;
400 	compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
401 	compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
402 
403 	if (!compiler->buf || !compiler->abuf) {
404 		if (compiler->buf)
405 			SLJIT_FREE(compiler->buf, allocator_data);
406 		if (compiler->abuf)
407 			SLJIT_FREE(compiler->abuf, allocator_data);
408 		SLJIT_FREE(compiler, allocator_data);
409 		return NULL;
410 	}
411 
412 	compiler->buf->next = NULL;
413 	compiler->buf->used_size = 0;
414 	compiler->abuf->next = NULL;
415 	compiler->abuf->used_size = 0;
416 
417 	compiler->scratches = -1;
418 	compiler->saveds = -1;
419 	compiler->fscratches = -1;
420 	compiler->fsaveds = -1;
421 	compiler->local_size = -1;
422 
423 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
424 	compiler->args_size = -1;
425 #endif
426 
427 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
428 	compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
429 		+ CPOOL_SIZE * sizeof(sljit_u8), allocator_data);
430 	if (!compiler->cpool) {
431 		SLJIT_FREE(compiler->buf, allocator_data);
432 		SLJIT_FREE(compiler->abuf, allocator_data);
433 		SLJIT_FREE(compiler, allocator_data);
434 		return NULL;
435 	}
436 	compiler->cpool_unique = (sljit_u8*)(compiler->cpool + CPOOL_SIZE);
437 	compiler->cpool_diff = 0xffffffff;
438 #endif
439 
440 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
441 	compiler->delay_slot = UNMOVABLE_INS;
442 #endif
443 
444 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
445 		|| (defined SLJIT_DEBUG && SLJIT_DEBUG)
446 	compiler->last_flags = 0;
447 	compiler->last_return = -1;
448 	compiler->logical_local_size = 0;
449 #endif
450 
451 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
452 	if (!compiler_initialized) {
453 		init_compiler();
454 		compiler_initialized = 1;
455 	}
456 #endif
457 
458 	return compiler;
459 }
460 
sljit_free_compiler(struct sljit_compiler * compiler)461 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
462 {
463 	struct sljit_memory_fragment *buf;
464 	struct sljit_memory_fragment *curr;
465 	void *allocator_data = compiler->allocator_data;
466 	SLJIT_UNUSED_ARG(allocator_data);
467 
468 	buf = compiler->buf;
469 	while (buf) {
470 		curr = buf;
471 		buf = buf->next;
472 		SLJIT_FREE(curr, allocator_data);
473 	}
474 
475 	buf = compiler->abuf;
476 	while (buf) {
477 		curr = buf;
478 		buf = buf->next;
479 		SLJIT_FREE(curr, allocator_data);
480 	}
481 
482 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
483 	SLJIT_FREE(compiler->cpool, allocator_data);
484 #endif
485 	SLJIT_FREE(compiler, allocator_data);
486 }
487 
sljit_set_compiler_memory_error(struct sljit_compiler * compiler)488 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
489 {
490 	if (compiler->error == SLJIT_SUCCESS)
491 		compiler->error = SLJIT_ERR_ALLOC_FAILED;
492 }
493 
494 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
sljit_free_code(void * code,void * exec_allocator_data)495 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
496 {
497 	SLJIT_UNUSED_ARG(exec_allocator_data);
498 
499 	/* Remove thumb mode flag. */
500 	SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~(sljit_uw)0x1), exec_allocator_data);
501 }
502 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
sljit_free_code(void * code,void * exec_allocator_data)503 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
504 {
505 	SLJIT_UNUSED_ARG(exec_allocator_data);
506 
507 	/* Resolve indirection. */
508 	code = (void*)(*(sljit_uw*)code);
509 	SLJIT_FREE_EXEC(code, exec_allocator_data);
510 }
511 #else
sljit_free_code(void * code,void * exec_allocator_data)512 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
513 {
514 	SLJIT_UNUSED_ARG(exec_allocator_data);
515 
516 	SLJIT_FREE_EXEC(code, exec_allocator_data);
517 }
518 #endif
519 
sljit_set_label(struct sljit_jump * jump,struct sljit_label * label)520 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
521 {
522 	if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
523 		jump->flags &= (sljit_uw)~JUMP_ADDR;
524 		jump->flags |= JUMP_LABEL;
525 		jump->u.label = label;
526 	}
527 }
528 
sljit_set_target(struct sljit_jump * jump,sljit_uw target)529 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
530 {
531 	if (SLJIT_LIKELY(!!jump)) {
532 		jump->flags &= (sljit_uw)~JUMP_LABEL;
533 		jump->flags |= JUMP_ADDR;
534 		jump->u.target = target;
535 	}
536 }
537 
sljit_set_put_label(struct sljit_put_label * put_label,struct sljit_label * label)538 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
539 {
540 	if (SLJIT_LIKELY(!!put_label))
541 		put_label->label = label;
542 }
543 
544 #define SLJIT_CURRENT_FLAGS_ALL \
545 	(SLJIT_CURRENT_FLAGS_32 | SLJIT_CURRENT_FLAGS_ADD | SLJIT_CURRENT_FLAGS_SUB | SLJIT_CURRENT_FLAGS_COMPARE)
546 
sljit_set_current_flags(struct sljit_compiler * compiler,sljit_s32 current_flags)547 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
548 {
549 	SLJIT_UNUSED_ARG(compiler);
550 	SLJIT_UNUSED_ARG(current_flags);
551 
552 #if (defined SLJIT_HAS_STATUS_FLAGS_STATE && SLJIT_HAS_STATUS_FLAGS_STATE)
553 	compiler->status_flags_state = current_flags;
554 #endif
555 
556 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
557 	compiler->last_flags = 0;
558 	if ((current_flags & ~(VARIABLE_FLAG_MASK | SLJIT_SET_Z | SLJIT_CURRENT_FLAGS_ALL)) == 0) {
559 		compiler->last_flags = GET_FLAG_TYPE(current_flags) | (current_flags & (SLJIT_32 | SLJIT_SET_Z));
560 	}
561 #endif
562 }
563 
564 /* --------------------------------------------------------------------- */
565 /*  Private functions                                                    */
566 /* --------------------------------------------------------------------- */
567 
ensure_buf(struct sljit_compiler * compiler,sljit_uw size)568 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
569 {
570 	sljit_u8 *ret;
571 	struct sljit_memory_fragment *new_frag;
572 
573 	SLJIT_ASSERT(size <= 256);
574 	if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
575 		ret = compiler->buf->memory + compiler->buf->used_size;
576 		compiler->buf->used_size += size;
577 		return ret;
578 	}
579 	new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
580 	PTR_FAIL_IF_NULL(new_frag);
581 	new_frag->next = compiler->buf;
582 	compiler->buf = new_frag;
583 	new_frag->used_size = size;
584 	return new_frag->memory;
585 }
586 
ensure_abuf(struct sljit_compiler * compiler,sljit_uw size)587 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
588 {
589 	sljit_u8 *ret;
590 	struct sljit_memory_fragment *new_frag;
591 
592 	SLJIT_ASSERT(size <= 256);
593 	if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
594 		ret = compiler->abuf->memory + compiler->abuf->used_size;
595 		compiler->abuf->used_size += size;
596 		return ret;
597 	}
598 	new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
599 	PTR_FAIL_IF_NULL(new_frag);
600 	new_frag->next = compiler->abuf;
601 	compiler->abuf = new_frag;
602 	new_frag->used_size = size;
603 	return new_frag->memory;
604 }
605 
sljit_alloc_memory(struct sljit_compiler * compiler,sljit_s32 size)606 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
607 {
608 	CHECK_ERROR_PTR();
609 
610 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
611 	if (size <= 0 || size > 128)
612 		return NULL;
613 	size = (size + 7) & ~7;
614 #else
615 	if (size <= 0 || size > 64)
616 		return NULL;
617 	size = (size + 3) & ~3;
618 #endif
619 	return ensure_abuf(compiler, (sljit_uw)size);
620 }
621 
reverse_buf(struct sljit_compiler * compiler)622 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
623 {
624 	struct sljit_memory_fragment *buf = compiler->buf;
625 	struct sljit_memory_fragment *prev = NULL;
626 	struct sljit_memory_fragment *tmp;
627 
628 	do {
629 		tmp = buf->next;
630 		buf->next = prev;
631 		prev = buf;
632 		buf = tmp;
633 	} while (buf != NULL);
634 
635 	compiler->buf = prev;
636 }
637 
638 /* Only used in RISC architectures where the instruction size is constant */
639 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
640 	&& !(defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
641 
compute_next_addr(struct sljit_label * label,struct sljit_jump * jump,struct sljit_const * const_,struct sljit_put_label * put_label)642 static SLJIT_INLINE sljit_uw compute_next_addr(struct sljit_label *label, struct sljit_jump *jump,
643 	struct sljit_const *const_, struct sljit_put_label *put_label)
644 {
645 	sljit_uw result = ~(sljit_uw)0;
646 
647 	if (label)
648 		result = label->size;
649 
650 	if (jump && jump->addr < result)
651 		result = jump->addr;
652 
653 	if (const_ && const_->addr < result)
654 		result = const_->addr;
655 
656 	if (put_label && put_label->addr < result)
657 		result = put_label->addr;
658 
659 	return result;
660 }
661 
662 #endif /* !SLJIT_CONFIG_X86 && !SLJIT_CONFIG_S390X */
663 
set_emit_enter(struct sljit_compiler * compiler,sljit_s32 options,sljit_s32 args,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches,sljit_s32 fsaveds,sljit_s32 local_size)664 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
665 	sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
666 	sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
667 {
668 	SLJIT_UNUSED_ARG(args);
669 	SLJIT_UNUSED_ARG(local_size);
670 
671 	compiler->options = options;
672 	compiler->scratches = scratches;
673 	compiler->saveds = saveds;
674 	compiler->fscratches = fscratches;
675 	compiler->fsaveds = fsaveds;
676 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
677 	compiler->last_return = args & SLJIT_ARG_MASK;
678 	compiler->logical_local_size = local_size;
679 #endif
680 }
681 
set_set_context(struct sljit_compiler * compiler,sljit_s32 options,sljit_s32 args,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches,sljit_s32 fsaveds,sljit_s32 local_size)682 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
683 	sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
684 	sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
685 {
686 	SLJIT_UNUSED_ARG(args);
687 	SLJIT_UNUSED_ARG(local_size);
688 
689 	compiler->options = options;
690 	compiler->scratches = scratches;
691 	compiler->saveds = saveds;
692 	compiler->fscratches = fscratches;
693 	compiler->fsaveds = fsaveds;
694 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
695 	compiler->last_return = args & SLJIT_ARG_MASK;
696 	compiler->logical_local_size = local_size;
697 #endif
698 }
699 
set_label(struct sljit_label * label,struct sljit_compiler * compiler)700 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
701 {
702 	label->next = NULL;
703 	label->size = compiler->size;
704 	if (compiler->last_label)
705 		compiler->last_label->next = label;
706 	else
707 		compiler->labels = label;
708 	compiler->last_label = label;
709 }
710 
set_jump(struct sljit_jump * jump,struct sljit_compiler * compiler,sljit_u32 flags)711 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_u32 flags)
712 {
713 	jump->next = NULL;
714 	jump->flags = flags;
715 	if (compiler->last_jump)
716 		compiler->last_jump->next = jump;
717 	else
718 		compiler->jumps = jump;
719 	compiler->last_jump = jump;
720 }
721 
set_const(struct sljit_const * const_,struct sljit_compiler * compiler)722 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
723 {
724 	const_->next = NULL;
725 	const_->addr = compiler->size;
726 	if (compiler->last_const)
727 		compiler->last_const->next = const_;
728 	else
729 		compiler->consts = const_;
730 	compiler->last_const = const_;
731 }
732 
set_put_label(struct sljit_put_label * put_label,struct sljit_compiler * compiler,sljit_uw offset)733 static SLJIT_INLINE void set_put_label(struct sljit_put_label *put_label, struct sljit_compiler *compiler, sljit_uw offset)
734 {
735 	put_label->next = NULL;
736 	put_label->label = NULL;
737 	put_label->addr = compiler->size - offset;
738 	put_label->flags = 0;
739 	if (compiler->last_put_label)
740 		compiler->last_put_label->next = put_label;
741 	else
742 		compiler->put_labels = put_label;
743 	compiler->last_put_label = put_label;
744 }
745 
746 #define ADDRESSING_DEPENDS_ON(exp, reg) \
747 	(((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
748 
749 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
750 
function_check_arguments(sljit_s32 arg_types,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches)751 static sljit_s32 function_check_arguments(sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds, sljit_s32 fscratches)
752 {
753 	sljit_s32 word_arg_count, scratch_arg_end, saved_arg_count, float_arg_count, curr_type;
754 
755 	curr_type = (arg_types & SLJIT_ARG_FULL_MASK);
756 
757 	if (curr_type >= SLJIT_ARG_TYPE_F64) {
758 		if (curr_type > SLJIT_ARG_TYPE_F32 || fscratches == 0)
759 			return 0;
760 	} else if (curr_type >= SLJIT_ARG_TYPE_W) {
761 		if (scratches == 0)
762 			return 0;
763 	}
764 
765 	arg_types >>= SLJIT_ARG_SHIFT;
766 
767 	word_arg_count = 0;
768 	scratch_arg_end = 0;
769 	saved_arg_count = 0;
770 	float_arg_count = 0;
771 	while (arg_types != 0) {
772 		if (word_arg_count + float_arg_count >= 4)
773 			return 0;
774 
775 		curr_type = (arg_types & SLJIT_ARG_MASK);
776 
777 		if (arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) {
778 			if (saveds == -1 || curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_P)
779 				return 0;
780 
781 			word_arg_count++;
782 			scratch_arg_end = word_arg_count;
783 		} else {
784 			if (curr_type < SLJIT_ARG_TYPE_W || curr_type > SLJIT_ARG_TYPE_F32)
785 				return 0;
786 
787 			if (curr_type < SLJIT_ARG_TYPE_F64) {
788 				word_arg_count++;
789 				saved_arg_count++;
790 			} else
791 				float_arg_count++;
792 		}
793 
794 		arg_types >>= SLJIT_ARG_SHIFT;
795 	}
796 
797 	if (saveds == -1)
798 		return (word_arg_count <= scratches && float_arg_count <= fscratches);
799 
800 	return (saved_arg_count <= saveds && scratch_arg_end <= scratches && float_arg_count <= fscratches);
801 }
802 
803 #define FUNCTION_CHECK_IS_REG(r) \
804 	(((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) \
805 	|| ((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
806 
807 #define FUNCTION_CHECK_IS_FREG(fr) \
808 	(((fr) >= SLJIT_FR0 && (fr) < (SLJIT_FR0 + compiler->fscratches)) \
809 	|| ((fr) > (SLJIT_FS0 - compiler->fsaveds) && (fr) <= SLJIT_FS0))
810 
811 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
812 #define CHECK_IF_VIRTUAL_REGISTER(p) ((p) <= SLJIT_S3 && (p) >= SLJIT_S8)
813 #else
814 #define CHECK_IF_VIRTUAL_REGISTER(p) 0
815 #endif
816 
function_check_src_mem(struct sljit_compiler * compiler,sljit_s32 p,sljit_sw i)817 static sljit_s32 function_check_src_mem(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
818 {
819 	if (compiler->scratches == -1 || compiler->saveds == -1)
820 		return 0;
821 
822 	if (!(p & SLJIT_MEM))
823 		return 0;
824 
825 	if (p == SLJIT_MEM1(SLJIT_SP))
826 		return (i >= 0 && i < compiler->logical_local_size);
827 
828 	if (!(!(p & REG_MASK) || FUNCTION_CHECK_IS_REG(p & REG_MASK)))
829 		return 0;
830 
831 	if (CHECK_IF_VIRTUAL_REGISTER(p & REG_MASK))
832 		return 0;
833 
834 	if (p & OFFS_REG_MASK) {
835 		if (!(p & REG_MASK))
836 			return 0;
837 
838 		if (!(FUNCTION_CHECK_IS_REG(OFFS_REG(p))))
839 			return 0;
840 
841 		if (CHECK_IF_VIRTUAL_REGISTER(OFFS_REG(p)))
842 			return 0;
843 
844 		if ((i & ~0x3) != 0)
845 			return 0;
846 	}
847 
848 	return (p & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK)) == 0;
849 }
850 
851 #define FUNCTION_CHECK_SRC_MEM(p, i) \
852 	CHECK_ARGUMENT(function_check_src_mem(compiler, p, i));
853 
function_check_src(struct sljit_compiler * compiler,sljit_s32 p,sljit_sw i)854 static sljit_s32 function_check_src(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
855 {
856 	if (compiler->scratches == -1 || compiler->saveds == -1)
857 		return 0;
858 
859 	if (FUNCTION_CHECK_IS_REG(p))
860 		return (i == 0);
861 
862 	if (p == SLJIT_IMM)
863 		return 1;
864 
865 	return function_check_src_mem(compiler, p, i);
866 }
867 
868 #define FUNCTION_CHECK_SRC(p, i) \
869 	CHECK_ARGUMENT(function_check_src(compiler, p, i));
870 
function_check_dst(struct sljit_compiler * compiler,sljit_s32 p,sljit_sw i)871 static sljit_s32 function_check_dst(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
872 {
873 	if (compiler->scratches == -1 || compiler->saveds == -1)
874 		return 0;
875 
876 	if (FUNCTION_CHECK_IS_REG(p))
877 		return (i == 0);
878 
879 	return function_check_src_mem(compiler, p, i);
880 }
881 
882 #define FUNCTION_CHECK_DST(p, i) \
883 	CHECK_ARGUMENT(function_check_dst(compiler, p, i));
884 
function_fcheck(struct sljit_compiler * compiler,sljit_s32 p,sljit_sw i)885 static sljit_s32 function_fcheck(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
886 {
887 	if (compiler->scratches == -1 || compiler->saveds == -1)
888 		return 0;
889 
890 	if (FUNCTION_CHECK_IS_FREG(p))
891 		return (i == 0);
892 
893 	return function_check_src_mem(compiler, p, i);
894 }
895 
896 #define FUNCTION_FCHECK(p, i) \
897 	CHECK_ARGUMENT(function_fcheck(compiler, p, i));
898 
899 #endif /* SLJIT_ARGUMENT_CHECKS */
900 
901 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
902 
sljit_compiler_verbose(struct sljit_compiler * compiler,FILE * verbose)903 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
904 {
905 	compiler->verbose = verbose;
906 }
907 
908 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
909 #ifdef _WIN64
910 #ifdef __GNUC__
911 #	define SLJIT_PRINT_D	"ll"
912 #else
913 #	define SLJIT_PRINT_D	"I64"
914 #endif
915 #else
916 #	define SLJIT_PRINT_D	"l"
917 #endif
918 #else
919 #	define SLJIT_PRINT_D	""
920 #endif
921 
sljit_verbose_reg(struct sljit_compiler * compiler,sljit_s32 r)922 static void sljit_verbose_reg(struct sljit_compiler *compiler, sljit_s32 r)
923 {
924 	if (r < (SLJIT_R0 + compiler->scratches))
925 		fprintf(compiler->verbose, "r%d", r - SLJIT_R0);
926 	else if (r != SLJIT_SP)
927 		fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - r);
928 	else
929 		fprintf(compiler->verbose, "sp");
930 }
931 
sljit_verbose_freg(struct sljit_compiler * compiler,sljit_s32 r)932 static void sljit_verbose_freg(struct sljit_compiler *compiler, sljit_s32 r)
933 {
934 	if (r < (SLJIT_FR0 + compiler->fscratches))
935 		fprintf(compiler->verbose, "fr%d", r - SLJIT_FR0);
936 	else
937 		fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - r);
938 }
939 
sljit_verbose_param(struct sljit_compiler * compiler,sljit_s32 p,sljit_sw i)940 static void sljit_verbose_param(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
941 {
942 	if ((p) & SLJIT_IMM)
943 		fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i));
944 	else if ((p) & SLJIT_MEM) {
945 		if ((p) & REG_MASK) {
946 			fputc('[', compiler->verbose);
947 			sljit_verbose_reg(compiler, (p) & REG_MASK);
948 			if ((p) & OFFS_REG_MASK) {
949 				fprintf(compiler->verbose, " + ");
950 				sljit_verbose_reg(compiler, OFFS_REG(p));
951 				if (i)
952 					fprintf(compiler->verbose, " * %d", 1 << (i));
953 			}
954 			else if (i)
955 				fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
956 			fputc(']', compiler->verbose);
957 		}
958 		else
959 			fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
960 	} else
961 		sljit_verbose_reg(compiler, p);
962 }
963 
sljit_verbose_fparam(struct sljit_compiler * compiler,sljit_s32 p,sljit_sw i)964 static void sljit_verbose_fparam(struct sljit_compiler *compiler, sljit_s32 p, sljit_sw i)
965 {
966 	if ((p) & SLJIT_MEM) {
967 		if ((p) & REG_MASK) {
968 			fputc('[', compiler->verbose);
969 			sljit_verbose_reg(compiler, (p) & REG_MASK);
970 			if ((p) & OFFS_REG_MASK) {
971 				fprintf(compiler->verbose, " + ");
972 				sljit_verbose_reg(compiler, OFFS_REG(p));
973 				if (i)
974 					fprintf(compiler->verbose, "%d", 1 << (i));
975 			}
976 			else if (i)
977 				fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i));
978 			fputc(']', compiler->verbose);
979 		}
980 		else
981 			fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i));
982 	}
983 	else
984 		sljit_verbose_freg(compiler, p);
985 }
986 
987 static const char* op0_names[] = {
988 	"breakpoint", "nop", "lmul.uw", "lmul.sw",
989 	"divmod.u", "divmod.s", "div.u", "div.s",
990 	"endbr", "skip_frames_before_return"
991 };
992 
993 static const char* op1_names[] = {
994 	"", ".u8", ".s8", ".u16",
995 	".s16", ".u32", ".s32", "32",
996 	".p", "not", "clz", "ctz"
997 };
998 
999 static const char* op2_names[] = {
1000 	"add", "addc", "sub", "subc",
1001 	"mul", "and", "or", "xor",
1002 	"shl", "mshl", "lshr", "mlshr",
1003 	"ashr", "mashr", "rotl", "rotr"
1004 };
1005 
1006 static const char* op_src_names[] = {
1007 	"fast_return", "skip_frames_before_fast_return",
1008 	"prefetch_l1", "prefetch_l2",
1009 	"prefetch_l3", "prefetch_once",
1010 };
1011 
1012 static const char* fop1_names[] = {
1013 	"mov", "conv", "conv", "conv",
1014 	"conv", "conv", "cmp", "neg",
1015 	"abs",
1016 };
1017 
1018 static const char* fop2_names[] = {
1019 	"add", "sub", "mul", "div"
1020 };
1021 
1022 static const char* jump_names[] = {
1023 	"equal", "not_equal",
1024 	"less", "greater_equal",
1025 	"greater", "less_equal",
1026 	"sig_less", "sig_greater_equal",
1027 	"sig_greater", "sig_less_equal",
1028 	"overflow", "not_overflow",
1029 	"carry", "",
1030 	"f_equal", "f_not_equal",
1031 	"f_less", "f_greater_equal",
1032 	"f_greater", "f_less_equal",
1033 	"unordered", "ordered",
1034 	"ordered_equal", "unordered_or_not_equal",
1035 	"ordered_less", "unordered_or_greater_equal",
1036 	"ordered_greater", "unordered_or_less_equal",
1037 	"unordered_or_equal", "ordered_not_equal",
1038 	"unordered_or_less", "ordered_greater_equal",
1039 	"unordered_or_greater", "ordered_less_equal",
1040 	"jump", "fast_call",
1041 	"call", "call_reg_arg"
1042 };
1043 
1044 static const char* call_arg_names[] = {
1045 	"void", "w", "32", "p", "f64", "f32"
1046 };
1047 
1048 #endif /* SLJIT_VERBOSE */
1049 
1050 /* --------------------------------------------------------------------- */
1051 /*  Arch dependent                                                       */
1052 /* --------------------------------------------------------------------- */
1053 
1054 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1055 	|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1056 
1057 #define SLJIT_SKIP_CHECKS(compiler) (compiler)->skip_checks = 1
1058 
check_sljit_generate_code(struct sljit_compiler * compiler)1059 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
1060 {
1061 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1062 	struct sljit_jump *jump;
1063 #endif
1064 
1065 	SLJIT_UNUSED_ARG(compiler);
1066 
1067 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1068 	CHECK_ARGUMENT(compiler->size > 0);
1069 	jump = compiler->jumps;
1070 	while (jump) {
1071 		/* All jumps have target. */
1072 		CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
1073 		jump = jump->next;
1074 	}
1075 #endif
1076 	CHECK_RETURN_OK;
1077 }
1078 
check_sljit_emit_enter(struct sljit_compiler * compiler,sljit_s32 options,sljit_s32 arg_types,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches,sljit_s32 fsaveds,sljit_s32 local_size)1079 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
1080 	sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
1081 	sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1082 {
1083 	SLJIT_UNUSED_ARG(compiler);
1084 
1085 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1086 	if (options & SLJIT_ENTER_REG_ARG) {
1087 		CHECK_ARGUMENT(!(options & ~(0x3 | SLJIT_ENTER_REG_ARG)));
1088 	} else {
1089 		CHECK_ARGUMENT(options == 0);
1090 	}
1091 	CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 3 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1092 	CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1093 	CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1094 	CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1095 	CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1096 	CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1097 	CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1098 	CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1099 	CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) <= SLJIT_ARG_TYPE_F32);
1100 	CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, (options & SLJIT_ENTER_REG_ARG) ? 0 : saveds, fscratches));
1101 
1102 	compiler->last_flags = 0;
1103 #endif
1104 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1105 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1106 		fprintf(compiler->verbose, "  enter ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1107 
1108 		arg_types >>= SLJIT_ARG_SHIFT;
1109 		if (arg_types) {
1110 			fprintf(compiler->verbose, "], args[");
1111 			do {
1112 				fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1113 					(arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1114 				arg_types >>= SLJIT_ARG_SHIFT;
1115 				if (arg_types)
1116 					fprintf(compiler->verbose, ",");
1117 			} while (arg_types);
1118 		}
1119 
1120 		fprintf(compiler->verbose, "],");
1121 
1122 		if (options & SLJIT_ENTER_REG_ARG) {
1123 			fprintf(compiler->verbose, " enter:reg_arg,");
1124 
1125 			if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1126 				fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1127 		}
1128 
1129 		fprintf(compiler->verbose, "scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1130 			scratches, saveds, fscratches, fsaveds, local_size);
1131 	}
1132 #endif
1133 	CHECK_RETURN_OK;
1134 }
1135 
check_sljit_set_context(struct sljit_compiler * compiler,sljit_s32 options,sljit_s32 arg_types,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches,sljit_s32 fsaveds,sljit_s32 local_size)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)
1139 {
1140 	SLJIT_UNUSED_ARG(compiler);
1141 
1142 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1143 	if (options & SLJIT_ENTER_REG_ARG) {
1144 		CHECK_ARGUMENT(!(options & ~(0x3 | SLJIT_ENTER_REG_ARG)));
1145 	} else {
1146 		CHECK_ARGUMENT(options == 0);
1147 	}
1148 	CHECK_ARGUMENT(SLJIT_KEPT_SAVEDS_COUNT(options) <= 3 && SLJIT_KEPT_SAVEDS_COUNT(options) <= saveds);
1149 	CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
1150 	CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_SAVED_REGISTERS);
1151 	CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
1152 	CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1153 	CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_SAVED_FLOAT_REGISTERS);
1154 	CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1155 	CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
1156 	CHECK_ARGUMENT((arg_types & SLJIT_ARG_FULL_MASK) < SLJIT_ARG_TYPE_F64);
1157 	CHECK_ARGUMENT(function_check_arguments(arg_types, scratches, (options & SLJIT_ENTER_REG_ARG) ? 0 : saveds, fscratches));
1158 
1159 	compiler->last_flags = 0;
1160 #endif
1161 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1162 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1163 		fprintf(compiler->verbose, "  set_context ret[%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1164 
1165 		arg_types >>= SLJIT_ARG_SHIFT;
1166 		if (arg_types) {
1167 			fprintf(compiler->verbose, "], args[");
1168 			do {
1169 				fprintf(compiler->verbose, "%s%s", call_arg_names[arg_types & SLJIT_ARG_MASK],
1170 					(arg_types & SLJIT_ARG_TYPE_SCRATCH_REG) ? "_r" : "");
1171 				arg_types >>= SLJIT_ARG_SHIFT;
1172 				if (arg_types)
1173 					fprintf(compiler->verbose, ",");
1174 			} while (arg_types);
1175 		}
1176 
1177 		fprintf(compiler->verbose, "],");
1178 
1179 		if (options & SLJIT_ENTER_REG_ARG) {
1180 			fprintf(compiler->verbose, " enter:reg_arg,");
1181 
1182 			if (SLJIT_KEPT_SAVEDS_COUNT(options) > 0)
1183 				fprintf(compiler->verbose, " keep:%d,", SLJIT_KEPT_SAVEDS_COUNT(options));
1184 		}
1185 
1186 		fprintf(compiler->verbose, " scratches:%d, saveds:%d, fscratches:%d, fsaveds:%d, local_size:%d\n",
1187 			scratches, saveds, fscratches, fsaveds, local_size);
1188 	}
1189 #endif
1190 	CHECK_RETURN_OK;
1191 }
1192 
check_sljit_emit_return_void(struct sljit_compiler * compiler)1193 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_void(struct sljit_compiler *compiler)
1194 {
1195 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1196 		compiler->skip_checks = 0;
1197 		CHECK_RETURN_OK;
1198 	}
1199 
1200 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1201 	CHECK_ARGUMENT(compiler->last_return == SLJIT_ARG_TYPE_VOID);
1202 #endif
1203 
1204 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1205 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1206 		fprintf(compiler->verbose, "  return_void\n");
1207 	}
1208 #endif
1209 	CHECK_RETURN_OK;
1210 }
1211 
check_sljit_emit_return(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)1212 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1213 {
1214 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1215 	CHECK_ARGUMENT(compiler->scratches >= 0);
1216 
1217 	switch (compiler->last_return) {
1218 	case SLJIT_ARG_TYPE_W:
1219 		CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_S32);
1220 		break;
1221 	case SLJIT_ARG_TYPE_32:
1222 		CHECK_ARGUMENT(op == SLJIT_MOV32 || (op >= SLJIT_MOV32_U8 && op <= SLJIT_MOV32_S16));
1223 		break;
1224 	case SLJIT_ARG_TYPE_P:
1225 		CHECK_ARGUMENT(op == SLJIT_MOV_P);
1226 		break;
1227 	case SLJIT_ARG_TYPE_F64:
1228 		CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1229 		CHECK_ARGUMENT(op == SLJIT_MOV_F64);
1230 		break;
1231 	case SLJIT_ARG_TYPE_F32:
1232 		CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1233 		CHECK_ARGUMENT(op == SLJIT_MOV_F32);
1234 		break;
1235 	default:
1236 		/* Context not initialized, void, etc. */
1237 		CHECK_ARGUMENT(0);
1238 		break;
1239 	}
1240 
1241 	if (GET_OPCODE(op) < SLJIT_MOV_F64) {
1242 		FUNCTION_CHECK_SRC(src, srcw);
1243 	} else {
1244 		FUNCTION_FCHECK(src, srcw);
1245 	}
1246 	compiler->last_flags = 0;
1247 #endif
1248 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1249 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1250 		if (GET_OPCODE(op) < SLJIT_MOV_F64) {
1251 			fprintf(compiler->verbose, "  return%s%s ", !(op & SLJIT_32) ? "" : "32",
1252 				op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1253 			sljit_verbose_param(compiler, src, srcw);
1254 		} else {
1255 			fprintf(compiler->verbose, "  return%s ", !(op & SLJIT_32) ? ".f64" : ".f32");
1256 			sljit_verbose_fparam(compiler, src, srcw);
1257 		}
1258 		fprintf(compiler->verbose, "\n");
1259 	}
1260 #endif
1261 	CHECK_RETURN_OK;
1262 }
1263 
check_sljit_emit_return_to(struct sljit_compiler * compiler,sljit_s32 src,sljit_sw srcw)1264 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return_to(struct sljit_compiler *compiler,
1265 	sljit_s32 src, sljit_sw srcw)
1266 {
1267 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1268 	FUNCTION_CHECK_SRC(src, srcw);
1269 #endif
1270 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1271 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1272 		fprintf(compiler->verbose, "  return_to ");
1273 		sljit_verbose_param(compiler, src, srcw);
1274 		fprintf(compiler->verbose, "\n");
1275 	}
1276 #endif
1277 	CHECK_RETURN_OK;
1278 }
1279 
check_sljit_emit_fast_enter(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw)1280 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1281 {
1282 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1283 	FUNCTION_CHECK_DST(dst, dstw);
1284 	compiler->last_flags = 0;
1285 #endif
1286 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1287 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1288 		fprintf(compiler->verbose, "  fast_enter ");
1289 		sljit_verbose_param(compiler, dst, dstw);
1290 		fprintf(compiler->verbose, "\n");
1291 	}
1292 #endif
1293 	CHECK_RETURN_OK;
1294 }
1295 
check_sljit_emit_op0(struct sljit_compiler * compiler,sljit_s32 op)1296 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1297 {
1298 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1299 	CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LMUL_SW)
1300 		|| ((op & ~SLJIT_32) >= SLJIT_DIVMOD_UW && (op & ~SLJIT_32) <= SLJIT_DIV_SW)
1301 		|| (op >= SLJIT_ENDBR && op <= SLJIT_SKIP_FRAMES_BEFORE_RETURN));
1302 	CHECK_ARGUMENT(GET_OPCODE(op) < SLJIT_LMUL_UW || GET_OPCODE(op) >= SLJIT_ENDBR || compiler->scratches >= 2);
1303 	if ((GET_OPCODE(op) >= SLJIT_LMUL_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) || op == SLJIT_SKIP_FRAMES_BEFORE_RETURN)
1304 		compiler->last_flags = 0;
1305 #endif
1306 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1307 	if (SLJIT_UNLIKELY(!!compiler->verbose))
1308 	{
1309 		fprintf(compiler->verbose, "  %s", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1310 		if (GET_OPCODE(op) >= SLJIT_DIVMOD_UW && GET_OPCODE(op) <= SLJIT_DIV_SW) {
1311 			fprintf(compiler->verbose, (op & SLJIT_32) ? "32" : "w");
1312 		}
1313 		fprintf(compiler->verbose, "\n");
1314 	}
1315 #endif
1316 	CHECK_RETURN_OK;
1317 }
1318 
check_sljit_emit_op1(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src,sljit_sw srcw)1319 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1320 	sljit_s32 dst, sljit_sw dstw,
1321 	sljit_s32 src, sljit_sw srcw)
1322 {
1323 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1324 		compiler->skip_checks = 0;
1325 		CHECK_RETURN_OK;
1326 	}
1327 
1328 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1329 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CTZ);
1330 
1331 	switch (GET_OPCODE(op)) {
1332 	case SLJIT_NOT:
1333 		/* Only SLJIT_32 and SLJIT_SET_Z are allowed. */
1334 		CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1335 		break;
1336 	case SLJIT_MOV:
1337 	case SLJIT_MOV_U32:
1338 	case SLJIT_MOV_P:
1339 		/* Nothing allowed */
1340 		CHECK_ARGUMENT(!(op & (SLJIT_32 | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1341 		break;
1342 	default:
1343 		/* Only SLJIT_32 is allowed. */
1344 		CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1345 		break;
1346 	}
1347 
1348 	FUNCTION_CHECK_DST(dst, dstw);
1349 	FUNCTION_CHECK_SRC(src, srcw);
1350 
1351 	if (GET_OPCODE(op) >= SLJIT_NOT) {
1352 		CHECK_ARGUMENT(src != SLJIT_IMM);
1353 		compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1354 	}
1355 #endif
1356 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1357 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1358 		if (GET_OPCODE(op) <= SLJIT_MOV_P)
1359 		{
1360 			fprintf(compiler->verbose, "  mov%s%s ", !(op & SLJIT_32) ? "" : "32",
1361 				op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE]);
1362 		}
1363 		else
1364 		{
1365 			fprintf(compiler->verbose, "  %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_32) ? "" : "32",
1366 				!(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1367 				!(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1368 		}
1369 
1370 		sljit_verbose_param(compiler, dst, dstw);
1371 		fprintf(compiler->verbose, ", ");
1372 		sljit_verbose_param(compiler, src, srcw);
1373 		fprintf(compiler->verbose, "\n");
1374 	}
1375 #endif
1376 	CHECK_RETURN_OK;
1377 }
1378 
check_sljit_emit_op2(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 unset,sljit_s32 dst,sljit_sw dstw,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)1379 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 unset,
1380 	sljit_s32 dst, sljit_sw dstw,
1381 	sljit_s32 src1, sljit_sw src1w,
1382 	sljit_s32 src2, sljit_sw src2w)
1383 {
1384 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1385 		compiler->skip_checks = 0;
1386 		CHECK_RETURN_OK;
1387 	}
1388 
1389 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1390 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ROTR);
1391 
1392 	switch (GET_OPCODE(op)) {
1393 	case SLJIT_AND:
1394 	case SLJIT_OR:
1395 	case SLJIT_XOR:
1396 	case SLJIT_SHL:
1397 	case SLJIT_MSHL:
1398 	case SLJIT_LSHR:
1399 	case SLJIT_MLSHR:
1400 	case SLJIT_ASHR:
1401 	case SLJIT_MASHR:
1402 		CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1403 		break;
1404 	case SLJIT_MUL:
1405 		CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1406 		CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1407 			|| GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1408 		break;
1409 	case SLJIT_ADD:
1410 		CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1411 			|| GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1412 			|| GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1413 		break;
1414 	case SLJIT_SUB:
1415 		CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1416 			|| (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1417 			|| GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1418 		break;
1419 	case SLJIT_ADDC:
1420 	case SLJIT_SUBC:
1421 		CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1422 			|| GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1423 		CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1424 		CHECK_ARGUMENT((op & SLJIT_32) == (compiler->last_flags & SLJIT_32));
1425 		break;
1426 	case SLJIT_ROTL:
1427 	case SLJIT_ROTR:
1428 		CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1429 		break;
1430 	default:
1431 		SLJIT_UNREACHABLE();
1432 		break;
1433 	}
1434 
1435 	if (unset) {
1436 		CHECK_ARGUMENT(HAS_FLAGS(op));
1437 	} else {
1438 		FUNCTION_CHECK_DST(dst, dstw);
1439 	}
1440 	FUNCTION_CHECK_SRC(src1, src1w);
1441 	FUNCTION_CHECK_SRC(src2, src2w);
1442 	compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1443 #endif
1444 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1445 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1446 		fprintf(compiler->verbose, "  %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32",
1447 			!(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1448 			!(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1449 		if (unset)
1450 			fprintf(compiler->verbose, "unset");
1451 		else
1452 			sljit_verbose_param(compiler, dst, dstw);
1453 		fprintf(compiler->verbose, ", ");
1454 		sljit_verbose_param(compiler, src1, src1w);
1455 		fprintf(compiler->verbose, ", ");
1456 		sljit_verbose_param(compiler, src2, src2w);
1457 		fprintf(compiler->verbose, "\n");
1458 	}
1459 #endif
1460 	CHECK_RETURN_OK;
1461 }
1462 
check_sljit_emit_shift_into(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src_dst,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)1463 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_shift_into(struct sljit_compiler *compiler, sljit_s32 op,
1464 	sljit_s32 src_dst,
1465 	sljit_s32 src1, sljit_sw src1w,
1466 	sljit_s32 src2, sljit_sw src2w)
1467 {
1468 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1469 	CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_SHL || GET_OPCODE(op) == SLJIT_LSHR
1470 		|| GET_OPCODE(op) == SLJIT_MSHL || GET_OPCODE(op) == SLJIT_MLSHR);
1471 	CHECK_ARGUMENT((op & ~(0xff | SLJIT_32 | SLJIT_SHIFT_INTO_NON_ZERO)) == 0);
1472 	CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src_dst));
1473 	FUNCTION_CHECK_SRC(src1, src1w);
1474 	FUNCTION_CHECK_SRC(src2, src2w);
1475 #endif
1476 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1477 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1478 		fprintf(compiler->verbose, "  %s%s.into%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_32) ? "" : "32",
1479 			(op & SLJIT_SHIFT_INTO_NON_ZERO) ? ".nz" : "");
1480 
1481 		sljit_verbose_reg(compiler, src_dst);
1482 		fprintf(compiler->verbose, ", ");
1483 		sljit_verbose_param(compiler, src1, src1w);
1484 		fprintf(compiler->verbose, ", ");
1485 		sljit_verbose_param(compiler, src2, src2w);
1486 		fprintf(compiler->verbose, "\n");
1487 	}
1488 #endif
1489 	CHECK_RETURN_OK;
1490 }
1491 
check_sljit_emit_op_src(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)1492 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
1493 	sljit_s32 src, sljit_sw srcw)
1494 {
1495 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1496 	CHECK_ARGUMENT(op >= SLJIT_FAST_RETURN && op <= SLJIT_PREFETCH_ONCE);
1497 	FUNCTION_CHECK_SRC(src, srcw);
1498 
1499 	if (op == SLJIT_FAST_RETURN || op == SLJIT_SKIP_FRAMES_BEFORE_FAST_RETURN)
1500 	{
1501 		CHECK_ARGUMENT(src != SLJIT_IMM);
1502 		compiler->last_flags = 0;
1503 	}
1504 	else if (op >= SLJIT_PREFETCH_L1 && op <= SLJIT_PREFETCH_ONCE)
1505 	{
1506 		CHECK_ARGUMENT(src & SLJIT_MEM);
1507 	}
1508 #endif
1509 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1510 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1511 		fprintf(compiler->verbose, "  %s ", op_src_names[op - SLJIT_OP_SRC_BASE]);
1512 		sljit_verbose_param(compiler, src, srcw);
1513 		fprintf(compiler->verbose, "\n");
1514 	}
1515 #endif
1516 	CHECK_RETURN_OK;
1517 }
1518 
check_sljit_get_register_index(sljit_s32 reg)1519 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1520 {
1521 	SLJIT_UNUSED_ARG(reg);
1522 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1523 	CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1524 #endif
1525 	CHECK_RETURN_OK;
1526 }
1527 
check_sljit_get_float_register_index(sljit_s32 reg)1528 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1529 {
1530 	SLJIT_UNUSED_ARG(reg);
1531 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1532 	CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1533 #endif
1534 	CHECK_RETURN_OK;
1535 }
1536 
check_sljit_emit_op_custom(struct sljit_compiler * compiler,void * instruction,sljit_u32 size)1537 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1538 	void *instruction, sljit_u32 size)
1539 {
1540 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1541 	sljit_u32 i;
1542 #endif
1543 
1544 	SLJIT_UNUSED_ARG(compiler);
1545 
1546 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1547 	CHECK_ARGUMENT(instruction);
1548 
1549 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1550 	CHECK_ARGUMENT(size > 0 && size < 16);
1551 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1552 	CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1553 		|| (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1554 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
1555 	CHECK_ARGUMENT(size == 2 || size == 4 || size == 6);
1556 #else
1557 	CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1558 #endif
1559 
1560 	compiler->last_flags = 0;
1561 #endif
1562 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1563 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1564 		fprintf(compiler->verbose, "  op_custom");
1565 		for (i = 0; i < size; i++)
1566 			fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1567 		fprintf(compiler->verbose, "\n");
1568 	}
1569 #endif
1570 	CHECK_RETURN_OK;
1571 }
1572 
check_sljit_emit_fop1(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src,sljit_sw srcw)1573 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1574 	sljit_s32 dst, sljit_sw dstw,
1575 	sljit_s32 src, sljit_sw srcw)
1576 {
1577 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1578 		compiler->skip_checks = 0;
1579 		CHECK_RETURN_OK;
1580 	}
1581 
1582 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1583 	CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1584 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1585 	CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1586 	FUNCTION_FCHECK(src, srcw);
1587 	FUNCTION_FCHECK(dst, dstw);
1588 #endif
1589 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1590 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1591 		if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1592 			fprintf(compiler->verbose, "  %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1593 				(op & SLJIT_32) ? ".f32.from.f64" : ".f64.from.f32");
1594 		else
1595 			fprintf(compiler->verbose, "  %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1596 				(op & SLJIT_32) ? ".f32" : ".f64");
1597 
1598 		sljit_verbose_fparam(compiler, dst, dstw);
1599 		fprintf(compiler->verbose, ", ");
1600 		sljit_verbose_fparam(compiler, src, srcw);
1601 		fprintf(compiler->verbose, "\n");
1602 	}
1603 #endif
1604 	CHECK_RETURN_OK;
1605 }
1606 
check_sljit_emit_fop1_cmp(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)1607 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1608 	sljit_s32 src1, sljit_sw src1w,
1609 	sljit_s32 src2, sljit_sw src2w)
1610 {
1611 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1612 	compiler->last_flags = GET_FLAG_TYPE(op) | (op & SLJIT_32);
1613 #endif
1614 
1615 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1616 		compiler->skip_checks = 0;
1617 		CHECK_RETURN_OK;
1618 	}
1619 
1620 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1621 	CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1622 	CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1623 	CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1624 	CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1625 		|| (GET_FLAG_TYPE(op) >= SLJIT_F_EQUAL && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_LESS_EQUAL));
1626 	FUNCTION_FCHECK(src1, src1w);
1627 	FUNCTION_FCHECK(src2, src2w);
1628 #endif
1629 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1630 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1631 		fprintf(compiler->verbose, "  %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1632 		if (op & VARIABLE_FLAG_MASK) {
1633 			fprintf(compiler->verbose, ".%s", jump_names[GET_FLAG_TYPE(op)]);
1634 		}
1635 		fprintf(compiler->verbose, " ");
1636 		sljit_verbose_fparam(compiler, src1, src1w);
1637 		fprintf(compiler->verbose, ", ");
1638 		sljit_verbose_fparam(compiler, src2, src2w);
1639 		fprintf(compiler->verbose, "\n");
1640 	}
1641 #endif
1642 	CHECK_RETURN_OK;
1643 }
1644 
check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src,sljit_sw srcw)1645 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1646 	sljit_s32 dst, sljit_sw dstw,
1647 	sljit_s32 src, sljit_sw srcw)
1648 {
1649 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1650 		compiler->skip_checks = 0;
1651 		CHECK_RETURN_OK;
1652 	}
1653 
1654 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1655 	CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1656 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1657 	CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1658 	FUNCTION_FCHECK(src, srcw);
1659 	FUNCTION_CHECK_DST(dst, dstw);
1660 #endif
1661 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1662 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1663 		fprintf(compiler->verbose, "  %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1664 			(GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1665 			(op & SLJIT_32) ? ".f32" : ".f64");
1666 		sljit_verbose_param(compiler, dst, dstw);
1667 		fprintf(compiler->verbose, ", ");
1668 		sljit_verbose_fparam(compiler, src, srcw);
1669 		fprintf(compiler->verbose, "\n");
1670 	}
1671 #endif
1672 	CHECK_RETURN_OK;
1673 }
1674 
check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src,sljit_sw srcw)1675 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1676 	sljit_s32 dst, sljit_sw dstw,
1677 	sljit_s32 src, sljit_sw srcw)
1678 {
1679 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1680 		compiler->skip_checks = 0;
1681 		CHECK_RETURN_OK;
1682 	}
1683 
1684 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1685 	CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1686 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1687 	CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1688 	FUNCTION_CHECK_SRC(src, srcw);
1689 	FUNCTION_FCHECK(dst, dstw);
1690 #endif
1691 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1692 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1693 		fprintf(compiler->verbose, "  %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1694 			(op & SLJIT_32) ? ".f32" : ".f64",
1695 			(GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1696 		sljit_verbose_fparam(compiler, dst, dstw);
1697 		fprintf(compiler->verbose, ", ");
1698 		sljit_verbose_param(compiler, src, srcw);
1699 		fprintf(compiler->verbose, "\n");
1700 	}
1701 #endif
1702 	CHECK_RETURN_OK;
1703 }
1704 
check_sljit_emit_fop2(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)1705 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1706 	sljit_s32 dst, sljit_sw dstw,
1707 	sljit_s32 src1, sljit_sw src1w,
1708 	sljit_s32 src2, sljit_sw src2w)
1709 {
1710 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1711 	CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1712 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1713 	CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1714 	FUNCTION_FCHECK(src1, src1w);
1715 	FUNCTION_FCHECK(src2, src2w);
1716 	FUNCTION_FCHECK(dst, dstw);
1717 #endif
1718 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1719 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1720 		fprintf(compiler->verbose, "  %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_32) ? ".f32" : ".f64");
1721 		sljit_verbose_fparam(compiler, dst, dstw);
1722 		fprintf(compiler->verbose, ", ");
1723 		sljit_verbose_fparam(compiler, src1, src1w);
1724 		fprintf(compiler->verbose, ", ");
1725 		sljit_verbose_fparam(compiler, src2, src2w);
1726 		fprintf(compiler->verbose, "\n");
1727 	}
1728 #endif
1729 	CHECK_RETURN_OK;
1730 }
1731 
check_sljit_emit_label(struct sljit_compiler * compiler)1732 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1733 {
1734 	SLJIT_UNUSED_ARG(compiler);
1735 
1736 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1737 		compiler->skip_checks = 0;
1738 		CHECK_RETURN_OK;
1739 	}
1740 
1741 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1742 	compiler->last_flags = 0;
1743 #endif
1744 
1745 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1746 	if (SLJIT_UNLIKELY(!!compiler->verbose))
1747 		fprintf(compiler->verbose, "label:\n");
1748 #endif
1749 	CHECK_RETURN_OK;
1750 }
1751 
1752 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1753 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
1754 	|| (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
1755 #define CHECK_UNORDERED(type, last_flags) \
1756 	((((type) & 0xff) == SLJIT_UNORDERED || ((type) & 0xff) == SLJIT_ORDERED) && \
1757 		((last_flags) & 0xff) >= SLJIT_UNORDERED && ((last_flags) & 0xff) <= SLJIT_ORDERED_LESS_EQUAL)
1758 #else
1759 #define CHECK_UNORDERED(type, last_flags) 0
1760 #endif
1761 #endif /* SLJIT_ARGUMENT_CHECKS */
1762 
check_sljit_emit_jump(struct sljit_compiler * compiler,sljit_s32 type)1763 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1764 {
1765 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1766 		compiler->skip_checks = 0;
1767 		CHECK_RETURN_OK;
1768 	}
1769 
1770 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1771 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1772 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_FAST_CALL);
1773 
1774 	if ((type & 0xff) < SLJIT_JUMP) {
1775 		if ((type & 0xff) <= SLJIT_NOT_ZERO)
1776 			CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1777 		else if ((compiler->last_flags & 0xff) == SLJIT_CARRY) {
1778 			CHECK_ARGUMENT((type & 0xff) == SLJIT_CARRY || (type & 0xff) == SLJIT_NOT_CARRY);
1779 			compiler->last_flags = 0;
1780 		} else
1781 			CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1782 				|| ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1783 				|| CHECK_UNORDERED(type, compiler->last_flags));
1784 	}
1785 #endif
1786 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1787 	if (SLJIT_UNLIKELY(!!compiler->verbose))
1788 		fprintf(compiler->verbose, "  jump%s %s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1789 			jump_names[type & 0xff]);
1790 #endif
1791 	CHECK_RETURN_OK;
1792 }
1793 
check_sljit_emit_call(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 arg_types)1794 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
1795 	sljit_s32 arg_types)
1796 {
1797 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1798 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_CALL_RETURN)));
1799 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_CALL && (type & 0xff) <= SLJIT_CALL_REG_ARG);
1800 	CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1801 
1802 	if (type & SLJIT_CALL_RETURN) {
1803 		CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1804 
1805 		if (compiler->options & SLJIT_ENTER_REG_ARG) {
1806 			CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL_REG_ARG);
1807 		} else {
1808 			CHECK_ARGUMENT((type & 0xff) != SLJIT_CALL_REG_ARG);
1809 		}
1810 	}
1811 #endif
1812 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1813 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1814 		fprintf(compiler->verbose, "  %s%s%s ret[%s", jump_names[type & 0xff],
1815 			!(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1816 			!(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1817 			call_arg_names[arg_types & SLJIT_ARG_MASK]);
1818 
1819 		arg_types >>= SLJIT_ARG_SHIFT;
1820 		if (arg_types) {
1821 			fprintf(compiler->verbose, "], args[");
1822 			do {
1823 				fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1824 				arg_types >>= SLJIT_ARG_SHIFT;
1825 				if (arg_types)
1826 					fprintf(compiler->verbose, ",");
1827 			} while (arg_types);
1828 		}
1829 		fprintf(compiler->verbose, "]\n");
1830 	}
1831 #endif
1832 	CHECK_RETURN_OK;
1833 }
1834 
check_sljit_emit_cmp(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)1835 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1836 	sljit_s32 src1, sljit_sw src1w,
1837 	sljit_s32 src2, sljit_sw src2w)
1838 {
1839 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1840 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1841 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1842 	FUNCTION_CHECK_SRC(src1, src1w);
1843 	FUNCTION_CHECK_SRC(src2, src2w);
1844 	compiler->last_flags = 0;
1845 #endif
1846 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1847 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1848 		fprintf(compiler->verbose, "  cmp%s%s %s, ", (type & SLJIT_32) ? "32" : "",
1849 			!(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1850 		sljit_verbose_param(compiler, src1, src1w);
1851 		fprintf(compiler->verbose, ", ");
1852 		sljit_verbose_param(compiler, src2, src2w);
1853 		fprintf(compiler->verbose, "\n");
1854 	}
1855 #endif
1856 	CHECK_RETURN_OK;
1857 }
1858 
check_sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)1859 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1860 	sljit_s32 src1, sljit_sw src1w,
1861 	sljit_s32 src2, sljit_sw src2w)
1862 {
1863 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1864 	CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1865 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_32)));
1866 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_F_EQUAL && (type & 0xff) <= SLJIT_ORDERED_LESS_EQUAL
1867 				&& ((type & 0xff) <= SLJIT_ORDERED || sljit_cmp_info(type & 0xff)));
1868 	FUNCTION_FCHECK(src1, src1w);
1869 	FUNCTION_FCHECK(src2, src2w);
1870 	compiler->last_flags = 0;
1871 #endif
1872 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1873 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1874 		fprintf(compiler->verbose, "  fcmp%s%s %s, ", (type & SLJIT_32) ? ".f32" : ".f64",
1875 			!(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1876 		sljit_verbose_fparam(compiler, src1, src1w);
1877 		fprintf(compiler->verbose, ", ");
1878 		sljit_verbose_fparam(compiler, src2, src2w);
1879 		fprintf(compiler->verbose, "\n");
1880 	}
1881 #endif
1882 	CHECK_RETURN_OK;
1883 }
1884 
check_sljit_emit_ijump(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src,sljit_sw srcw)1885 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type,
1886 	sljit_s32 src, sljit_sw srcw)
1887 {
1888 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1889 		compiler->skip_checks = 0;
1890 		CHECK_RETURN_OK;
1891 	}
1892 
1893 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1894 	CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_FAST_CALL);
1895 	FUNCTION_CHECK_SRC(src, srcw);
1896 #endif
1897 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1898 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1899 		fprintf(compiler->verbose, "  ijump.%s ", jump_names[type]);
1900 		sljit_verbose_param(compiler, src, srcw);
1901 		fprintf(compiler->verbose, "\n");
1902 	}
1903 #endif
1904 	CHECK_RETURN_OK;
1905 }
1906 
check_sljit_emit_icall(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 arg_types,sljit_s32 src,sljit_sw srcw)1907 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
1908 	sljit_s32 arg_types,
1909 	sljit_s32 src, sljit_sw srcw)
1910 {
1911 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1912 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_CALL_RETURN)));
1913 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_CALL && (type & 0xff) <= SLJIT_CALL_REG_ARG);
1914 	CHECK_ARGUMENT(function_check_arguments(arg_types, compiler->scratches, -1, compiler->fscratches));
1915 	FUNCTION_CHECK_SRC(src, srcw);
1916 
1917 	if (type & SLJIT_CALL_RETURN) {
1918 		CHECK_ARGUMENT((arg_types & SLJIT_ARG_MASK) == compiler->last_return);
1919 
1920 		if (compiler->options & SLJIT_ENTER_REG_ARG) {
1921 			CHECK_ARGUMENT((type & 0xff) == SLJIT_CALL_REG_ARG);
1922 		} else {
1923 			CHECK_ARGUMENT((type & 0xff) != SLJIT_CALL_REG_ARG);
1924 		}
1925 	}
1926 #endif
1927 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1928 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1929 		fprintf(compiler->verbose, "  i%s%s ret[%s", jump_names[type & 0xff],
1930 			!(type & SLJIT_CALL_RETURN) ? "" : ".ret",
1931 			call_arg_names[arg_types & SLJIT_ARG_MASK]);
1932 
1933 		arg_types >>= SLJIT_ARG_SHIFT;
1934 		if (arg_types) {
1935 			fprintf(compiler->verbose, "], args[");
1936 			do {
1937 				fprintf(compiler->verbose, "%s", call_arg_names[arg_types & SLJIT_ARG_MASK]);
1938 				arg_types >>= SLJIT_ARG_SHIFT;
1939 				if (arg_types)
1940 					fprintf(compiler->verbose, ",");
1941 			} while (arg_types);
1942 		}
1943 		fprintf(compiler->verbose, "], ");
1944 		sljit_verbose_param(compiler, src, srcw);
1945 		fprintf(compiler->verbose, "\n");
1946 	}
1947 #endif
1948 	CHECK_RETURN_OK;
1949 }
1950 
check_sljit_emit_op_flags(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 type)1951 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1952 	sljit_s32 dst, sljit_sw dstw,
1953 	sljit_s32 type)
1954 {
1955 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1956 	CHECK_ARGUMENT(type >= SLJIT_EQUAL && type <= SLJIT_ORDERED_LESS_EQUAL);
1957 	CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1958 		|| (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1959 	CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1960 
1961 	if (type <= SLJIT_NOT_ZERO)
1962 		CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1963 	else
1964 		CHECK_ARGUMENT(type == (compiler->last_flags & 0xff)
1965 			|| (type == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
1966 			|| (type == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1967 			|| CHECK_UNORDERED(type, compiler->last_flags));
1968 
1969 	FUNCTION_CHECK_DST(dst, dstw);
1970 
1971 	if (GET_OPCODE(op) >= SLJIT_ADD)
1972 		compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_32 | SLJIT_SET_Z));
1973 #endif
1974 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1975 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1976 		fprintf(compiler->verbose, "  flags.%s%s%s ",
1977 			GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1978 			GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_32) ? "32" : ""),
1979 			!(op & SLJIT_SET_Z) ? "" : ".z");
1980 		sljit_verbose_param(compiler, dst, dstw);
1981 		fprintf(compiler->verbose, ", %s\n", jump_names[type]);
1982 	}
1983 #endif
1984 	CHECK_RETURN_OK;
1985 }
1986 
check_sljit_emit_cmov(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 dst_reg,sljit_s32 src,sljit_sw srcw)1987 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1988 	sljit_s32 dst_reg,
1989 	sljit_s32 src, sljit_sw srcw)
1990 {
1991 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1992 	sljit_s32 cond = type & ~SLJIT_32;
1993 
1994 	CHECK_ARGUMENT(cond >= SLJIT_EQUAL && cond <= SLJIT_ORDERED_LESS_EQUAL);
1995 
1996 	CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1);
1997 	CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg));
1998 	if (src != SLJIT_IMM) {
1999 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
2000 		CHECK_ARGUMENT(srcw == 0);
2001 	}
2002 
2003 	if (cond <= SLJIT_NOT_ZERO)
2004 		CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
2005 	else
2006 		CHECK_ARGUMENT(cond == (compiler->last_flags & 0xff)
2007 			|| (cond == SLJIT_NOT_CARRY && (compiler->last_flags & 0xff) == SLJIT_CARRY)
2008 			|| (cond == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
2009 			|| CHECK_UNORDERED(cond, compiler->last_flags));
2010 #endif
2011 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2012 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2013 		fprintf(compiler->verbose, "  cmov%s %s, ",
2014 			!(type & SLJIT_32) ? "" : "32",
2015 			jump_names[type & ~SLJIT_32]);
2016 		sljit_verbose_reg(compiler, dst_reg);
2017 		fprintf(compiler->verbose, ", ");
2018 		sljit_verbose_param(compiler, src, srcw);
2019 		fprintf(compiler->verbose, "\n");
2020 	}
2021 #endif
2022 	CHECK_RETURN_OK;
2023 }
2024 
check_sljit_emit_mem(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 reg,sljit_s32 mem,sljit_sw memw)2025 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem(struct sljit_compiler *compiler, sljit_s32 type,
2026 	sljit_s32 reg,
2027 	sljit_s32 mem, sljit_sw memw)
2028 {
2029 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
2030 		compiler->skip_checks = 0;
2031 		CHECK_RETURN_OK;
2032 	}
2033 
2034 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2035 	sljit_s32 allowed_flags;
2036 
2037 	if (type & SLJIT_MEM_UNALIGNED) {
2038 		CHECK_ARGUMENT(!(type & (SLJIT_MEM_UNALIGNED_16 | SLJIT_MEM_UNALIGNED_32)));
2039 	} else if (type & SLJIT_MEM_UNALIGNED_16) {
2040 		CHECK_ARGUMENT(!(type & SLJIT_MEM_UNALIGNED_32));
2041 	} else {
2042 		CHECK_ARGUMENT((reg & REG_PAIR_MASK) || (type & SLJIT_MEM_UNALIGNED_32));
2043 	}
2044 
2045 	allowed_flags = SLJIT_MEM_UNALIGNED;
2046 
2047 	switch (type & 0xff) {
2048 	case SLJIT_MOV_U32:
2049 	case SLJIT_MOV_S32:
2050 	case SLJIT_MOV32:
2051 		allowed_flags = SLJIT_MEM_UNALIGNED | SLJIT_MEM_UNALIGNED_16;
2052 		break;
2053 	case SLJIT_MOV:
2054 	case SLJIT_MOV_P:
2055 		allowed_flags = SLJIT_MEM_UNALIGNED | SLJIT_MEM_UNALIGNED_16 | SLJIT_MEM_UNALIGNED_32;
2056 		break;
2057 	}
2058 
2059 	CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | allowed_flags)) == 0);
2060 
2061 	if (reg & REG_PAIR_MASK) {
2062 		CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV);
2063 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(REG_PAIR_FIRST(reg)));
2064 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(REG_PAIR_SECOND(reg)));
2065 		CHECK_ARGUMENT(REG_PAIR_FIRST(reg) != REG_PAIR_SECOND(reg));
2066 	} else {
2067 		CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
2068 		CHECK_ARGUMENT(!(type & SLJIT_32) || ((type & 0xff) >= SLJIT_MOV_U8 && (type & 0xff) <= SLJIT_MOV_S16));
2069 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(reg));
2070 	}
2071 
2072 	FUNCTION_CHECK_SRC_MEM(mem, memw);
2073 #endif
2074 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2075 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2076 		if ((type & 0xff) == SLJIT_MOV32)
2077 			fprintf(compiler->verbose, "  %s32",
2078 				(type & SLJIT_MEM_STORE) ? "store" : "load");
2079 		else
2080 			fprintf(compiler->verbose, "  %s%s%s",
2081 				(type & SLJIT_MEM_STORE) ? "store" : "load",
2082 				!(type & SLJIT_32) ? "" : "32",
2083 				op1_names[(type & 0xff) - SLJIT_OP1_BASE]);
2084 
2085 		if (type & SLJIT_MEM_UNALIGNED)
2086 			printf(".un");
2087 		else if (type & SLJIT_MEM_UNALIGNED_16)
2088 			printf(".un16");
2089 		else if (type & SLJIT_MEM_UNALIGNED_32)
2090 			printf(".un32");
2091 
2092 		if (reg & REG_PAIR_MASK) {
2093 			fprintf(compiler->verbose, " {");
2094 			sljit_verbose_reg(compiler, REG_PAIR_FIRST(reg));
2095 			fprintf(compiler->verbose, ", ");
2096 			sljit_verbose_reg(compiler, REG_PAIR_SECOND(reg));
2097 			fprintf(compiler->verbose, "}, ");
2098 		} else {
2099 			fprintf(compiler->verbose, " ");
2100 			sljit_verbose_reg(compiler, reg);
2101 			fprintf(compiler->verbose, ", ");
2102 		}
2103 		sljit_verbose_param(compiler, mem, memw);
2104 		fprintf(compiler->verbose, "\n");
2105 	}
2106 #endif
2107 	CHECK_RETURN_OK;
2108 }
2109 
check_sljit_emit_mem_update(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 reg,sljit_s32 mem,sljit_sw memw)2110 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type,
2111 	sljit_s32 reg,
2112 	sljit_s32 mem, sljit_sw memw)
2113 {
2114 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
2115 		compiler->skip_checks = 0;
2116 		CHECK_RETURN_OK;
2117 	}
2118 
2119 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2120 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_MOV && (type & 0xff) <= SLJIT_MOV_P);
2121 	CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_POST)) == 0);
2122 	CHECK_ARGUMENT((mem & REG_MASK) != 0 && (mem & REG_MASK) != reg);
2123 
2124 	FUNCTION_CHECK_SRC_MEM(mem, memw);
2125 #endif
2126 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2127 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2128 		if (type & SLJIT_MEM_SUPP)
2129 			CHECK_RETURN_OK;
2130 		if (sljit_emit_mem_update(compiler, type | SLJIT_MEM_SUPP, reg, mem, memw) == SLJIT_ERR_UNSUPPORTED) {
2131 			fprintf(compiler->verbose, "    # mem: unsupported form, no instructions are emitted\n");
2132 			CHECK_RETURN_OK;
2133 		}
2134 
2135 		if ((type & 0xff) == SLJIT_MOV32)
2136 			fprintf(compiler->verbose, "  %s32.%s ",
2137 				(type & SLJIT_MEM_STORE) ? "store" : "load",
2138 				(type & SLJIT_MEM_POST) ? "post" : "pre");
2139 		else
2140 			fprintf(compiler->verbose, "  %s%s%s.%s ",
2141 				(type & SLJIT_MEM_STORE) ? "store" : "load",
2142 				!(type & SLJIT_32) ? "" : "32",
2143 				op1_names[(type & 0xff) - SLJIT_OP1_BASE],
2144 				(type & SLJIT_MEM_POST) ? "post" : "pre");
2145 
2146 		sljit_verbose_reg(compiler, reg);
2147 		fprintf(compiler->verbose, ", ");
2148 		sljit_verbose_param(compiler, mem, memw);
2149 		fprintf(compiler->verbose, "\n");
2150 	}
2151 #endif
2152 	CHECK_RETURN_OK;
2153 }
2154 
check_sljit_emit_fmem(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)2155 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2156 	sljit_s32 freg,
2157 	sljit_s32 mem, sljit_sw memw)
2158 {
2159 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2160 	CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
2161 
2162 	if (type & SLJIT_MEM_UNALIGNED) {
2163 		CHECK_ARGUMENT(!(type & (SLJIT_MEM_UNALIGNED_16 | SLJIT_MEM_UNALIGNED_32)));
2164 	} else if (type & SLJIT_MEM_UNALIGNED_16) {
2165 		CHECK_ARGUMENT(!(type & SLJIT_MEM_UNALIGNED_32));
2166 	} else {
2167 		CHECK_ARGUMENT(type & SLJIT_MEM_UNALIGNED_32);
2168 		CHECK_ARGUMENT(!(type & SLJIT_32));
2169 	}
2170 
2171 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_UNALIGNED | SLJIT_MEM_UNALIGNED_16 | SLJIT_MEM_UNALIGNED_32)));
2172 	CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
2173 	FUNCTION_CHECK_SRC_MEM(mem, memw);
2174 #endif
2175 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2176 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2177 		fprintf(compiler->verbose, "  %s.%s",
2178 			(type & SLJIT_MEM_STORE) ? "store" : "load",
2179 			!(type & SLJIT_32) ? "f64" : "f32");
2180 
2181 		if (type & SLJIT_MEM_UNALIGNED)
2182 			printf(".un");
2183 		else if (type & SLJIT_MEM_UNALIGNED_16)
2184 			printf(".un16");
2185 		else if (type & SLJIT_MEM_UNALIGNED_32)
2186 			printf(".un32");
2187 
2188 		fprintf(compiler->verbose, " ");
2189 		sljit_verbose_freg(compiler, freg);
2190 		fprintf(compiler->verbose, ", ");
2191 		sljit_verbose_param(compiler, mem, memw);
2192 		fprintf(compiler->verbose, "\n");
2193 	}
2194 #endif
2195 	CHECK_RETURN_OK;
2196 }
2197 
check_sljit_emit_fmem_update(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)2198 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type,
2199 	sljit_s32 freg,
2200 	sljit_s32 mem, sljit_sw memw)
2201 {
2202 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2203 	CHECK_ARGUMENT((type & 0xff) == SLJIT_MOV_F64);
2204 	CHECK_ARGUMENT((type & ~(0xff | SLJIT_32 | SLJIT_MEM_STORE | SLJIT_MEM_SUPP | SLJIT_MEM_POST)) == 0);
2205 	FUNCTION_CHECK_SRC_MEM(mem, memw);
2206 	CHECK_ARGUMENT(FUNCTION_CHECK_IS_FREG(freg));
2207 #endif
2208 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2209 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2210 		if (type & SLJIT_MEM_SUPP)
2211 			CHECK_RETURN_OK;
2212 		if (sljit_emit_fmem_update(compiler, type | SLJIT_MEM_SUPP, freg, mem, memw) == SLJIT_ERR_UNSUPPORTED) {
2213 			fprintf(compiler->verbose, "    # fmem: unsupported form, no instructions are emitted\n");
2214 			CHECK_RETURN_OK;
2215 		}
2216 
2217 		fprintf(compiler->verbose, "  %s.%s.%s ",
2218 			(type & SLJIT_MEM_STORE) ? "store" : "load",
2219 			!(type & SLJIT_32) ? "f64" : "f32",
2220 			(type & SLJIT_MEM_POST) ? "post" : "pre");
2221 
2222 		sljit_verbose_freg(compiler, freg);
2223 		fprintf(compiler->verbose, ", ");
2224 		sljit_verbose_param(compiler, mem, memw);
2225 		fprintf(compiler->verbose, "\n");
2226 	}
2227 #endif
2228 	CHECK_RETURN_OK;
2229 
2230 }
2231 
check_sljit_get_local_base(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw,sljit_sw offset)2232 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2233 {
2234 	/* Any offset is allowed. */
2235 	SLJIT_UNUSED_ARG(offset);
2236 
2237 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2238 	FUNCTION_CHECK_DST(dst, dstw);
2239 #endif
2240 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2241 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2242 		fprintf(compiler->verbose, "  local_base ");
2243 		sljit_verbose_param(compiler, dst, dstw);
2244 		fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
2245 	}
2246 #endif
2247 	CHECK_RETURN_OK;
2248 }
2249 
check_sljit_emit_const(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw,sljit_sw init_value)2250 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
2251 {
2252 	SLJIT_UNUSED_ARG(init_value);
2253 
2254 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2255 	FUNCTION_CHECK_DST(dst, dstw);
2256 #endif
2257 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2258 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2259 		fprintf(compiler->verbose, "  const ");
2260 		sljit_verbose_param(compiler, dst, dstw);
2261 		fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
2262 	}
2263 #endif
2264 	CHECK_RETURN_OK;
2265 }
2266 
check_sljit_emit_put_label(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw)2267 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2268 {
2269 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
2270 	FUNCTION_CHECK_DST(dst, dstw);
2271 #endif
2272 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
2273 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2274 		fprintf(compiler->verbose, "  put_label ");
2275 		sljit_verbose_param(compiler, dst, dstw);
2276 		fprintf(compiler->verbose, "\n");
2277 	}
2278 #endif
2279 	CHECK_RETURN_OK;
2280 }
2281 
2282 #else /* !SLJIT_ARGUMENT_CHECKS && !SLJIT_VERBOSE */
2283 
2284 #define SLJIT_SKIP_CHECKS(compiler)
2285 
2286 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
2287 
2288 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
2289 	SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
2290 		invalid_float_opcodes); \
2291 	if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
2292 		if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
2293 			CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
2294 			ADJUST_LOCAL_OFFSET(dst, dstw); \
2295 			ADJUST_LOCAL_OFFSET(src, srcw); \
2296 			return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
2297 		} \
2298 		if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
2299 			CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
2300 			ADJUST_LOCAL_OFFSET(dst, dstw); \
2301 			ADJUST_LOCAL_OFFSET(src, srcw); \
2302 			return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
2303 		} \
2304 		CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
2305 		ADJUST_LOCAL_OFFSET(dst, dstw); \
2306 		ADJUST_LOCAL_OFFSET(src, srcw); \
2307 		return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
2308 	} \
2309 	CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
2310 	ADJUST_LOCAL_OFFSET(dst, dstw); \
2311 	ADJUST_LOCAL_OFFSET(src, srcw);
2312 
2313 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2314 		|| (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
2315 		|| ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 1 && SLJIT_MIPS_REV < 6)) \
2316 		|| (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV) \
2317 		|| (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
2318 
sljit_emit_cmov_generic(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 dst_reg,sljit_s32 src,sljit_sw srcw)2319 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
2320 	sljit_s32 dst_reg,
2321 	sljit_s32 src, sljit_sw srcw)
2322 {
2323 	struct sljit_label *label;
2324 	struct sljit_jump *jump;
2325 	sljit_s32 op = (type & SLJIT_32) ? SLJIT_MOV32 : SLJIT_MOV;
2326 
2327 	SLJIT_SKIP_CHECKS(compiler);
2328 	jump = sljit_emit_jump(compiler, (type & ~SLJIT_32) ^ 0x1);
2329 	FAIL_IF(!jump);
2330 
2331 	SLJIT_SKIP_CHECKS(compiler);
2332 	FAIL_IF(sljit_emit_op1(compiler, op, dst_reg, 0, src, srcw));
2333 
2334 	SLJIT_SKIP_CHECKS(compiler);
2335 	label = sljit_emit_label(compiler);
2336 	FAIL_IF(!label);
2337 
2338 	sljit_set_label(jump, label);
2339 	return SLJIT_SUCCESS;
2340 }
2341 
2342 #endif
2343 
2344 #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \
2345 	&& !(defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2346 
sljit_emit_mem_unaligned(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 reg,sljit_s32 mem,sljit_sw memw)2347 static sljit_s32 sljit_emit_mem_unaligned(struct sljit_compiler *compiler, sljit_s32 type,
2348 	sljit_s32 reg,
2349 	sljit_s32 mem, sljit_sw memw)
2350 {
2351 	SLJIT_SKIP_CHECKS(compiler);
2352 
2353 	if (type & SLJIT_MEM_STORE)
2354 		return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), mem, memw, reg, 0);
2355 	return sljit_emit_op1(compiler, type & (0xff | SLJIT_32), reg, 0, mem, memw);
2356 }
2357 
2358 #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM_V5 */
2359 
2360 #if (!(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) || (defined SLJIT_MIPS_REV && SLJIT_MIPS_REV >= 6)) \
2361 	&& !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32)
2362 
sljit_emit_fmem_unaligned(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)2363 static sljit_s32 sljit_emit_fmem_unaligned(struct sljit_compiler *compiler, sljit_s32 type,
2364 	sljit_s32 freg,
2365 	sljit_s32 mem, sljit_sw memw)
2366 {
2367 	SLJIT_SKIP_CHECKS(compiler);
2368 
2369 	if (type & SLJIT_MEM_STORE)
2370 		return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), mem, memw, freg, 0);
2371 	return sljit_emit_fop1(compiler, type & (0xff | SLJIT_32), freg, 0, mem, memw);
2372 }
2373 
2374 #endif /* (!SLJIT_CONFIG_MIPS || SLJIT_MIPS_REV >= 6) && !SLJIT_CONFIG_ARM */
2375 
2376 /* CPU description section */
2377 
2378 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
2379 #define SLJIT_CPUINFO_PART1 " 32bit ("
2380 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2381 #define SLJIT_CPUINFO_PART1 " 64bit ("
2382 #else
2383 #error "Internal error: CPU type info missing"
2384 #endif
2385 
2386 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
2387 #define SLJIT_CPUINFO_PART2 "little endian + "
2388 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
2389 #define SLJIT_CPUINFO_PART2 "big endian + "
2390 #else
2391 #error "Internal error: CPU type info missing"
2392 #endif
2393 
2394 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
2395 #define SLJIT_CPUINFO_PART3 "unaligned)"
2396 #else
2397 #define SLJIT_CPUINFO_PART3 "aligned)"
2398 #endif
2399 
2400 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
2401 
2402 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
2403 #	include "sljitNativeX86_common.c"
2404 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
2405 #	include "sljitNativeARM_32.c"
2406 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
2407 #	include "sljitNativeARM_32.c"
2408 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
2409 #	include "sljitNativeARM_T2_32.c"
2410 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2411 #	include "sljitNativeARM_64.c"
2412 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2413 #	include "sljitNativePPC_common.c"
2414 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2415 #	include "sljitNativeMIPS_common.c"
2416 #elif (defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2417 #	include "sljitNativeRISCV_common.c"
2418 #elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
2419 #	include "sljitNativeS390X.c"
2420 #endif
2421 
emit_mov_before_return(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)2422 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2423 {
2424 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
2425 	/* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
2426 	if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
2427 		return SLJIT_SUCCESS;
2428 #else
2429 	if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
2430 		return SLJIT_SUCCESS;
2431 #endif
2432 
2433 	SLJIT_SKIP_CHECKS(compiler);
2434 	return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
2435 }
2436 
2437 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) \
2438 	&& !((defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) && defined __SOFTFP__)
2439 
emit_fmov_before_return(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)2440 static SLJIT_INLINE sljit_s32 emit_fmov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2441 {
2442 	if (src == SLJIT_FR0)
2443 		return SLJIT_SUCCESS;
2444 
2445 	SLJIT_SKIP_CHECKS(compiler);
2446 	return sljit_emit_fop1(compiler, op, SLJIT_RETURN_FREG, 0, src, srcw);
2447 }
2448 
2449 #endif /* !SLJIT_CONFIG_X86_32 && !(SLJIT_CONFIG_ARM_32 && __SOFTFP__) */
2450 
sljit_emit_return(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)2451 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2452 {
2453 	CHECK_ERROR();
2454 	CHECK(check_sljit_emit_return(compiler, op, src, srcw));
2455 
2456 	if (GET_OPCODE(op) < SLJIT_MOV_F64) {
2457 		FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
2458 	} else {
2459 		FAIL_IF(emit_fmov_before_return(compiler, op, src, srcw));
2460 	}
2461 
2462 	SLJIT_SKIP_CHECKS(compiler);
2463 	return sljit_emit_return_void(compiler);
2464 }
2465 
2466 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) \
2467 	&& !(defined SLJIT_CONFIG_RISCV && SLJIT_CONFIG_RISCV)
2468 
sljit_emit_cmp(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2469 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2470 	sljit_s32 src1, sljit_sw src1w,
2471 	sljit_s32 src2, sljit_sw src2w)
2472 {
2473 	/* Default compare for most architectures. */
2474 	sljit_s32 flags, tmp_src, condition;
2475 	sljit_sw tmp_srcw;
2476 
2477 	CHECK_ERROR_PTR();
2478 	CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
2479 
2480 	condition = type & 0xff;
2481 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2482 	if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
2483 		if ((src1 & SLJIT_IMM) && !src1w) {
2484 			src1 = src2;
2485 			src1w = src2w;
2486 			src2 = SLJIT_IMM;
2487 			src2w = 0;
2488 		}
2489 		if ((src2 & SLJIT_IMM) && !src2w)
2490 			return emit_cmp_to0(compiler, type, src1, src1w);
2491 	}
2492 #endif
2493 
2494 	if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
2495 		/* Immediate is preferred as second argument by most architectures. */
2496 		switch (condition) {
2497 		case SLJIT_LESS:
2498 			condition = SLJIT_GREATER;
2499 			break;
2500 		case SLJIT_GREATER_EQUAL:
2501 			condition = SLJIT_LESS_EQUAL;
2502 			break;
2503 		case SLJIT_GREATER:
2504 			condition = SLJIT_LESS;
2505 			break;
2506 		case SLJIT_LESS_EQUAL:
2507 			condition = SLJIT_GREATER_EQUAL;
2508 			break;
2509 		case SLJIT_SIG_LESS:
2510 			condition = SLJIT_SIG_GREATER;
2511 			break;
2512 		case SLJIT_SIG_GREATER_EQUAL:
2513 			condition = SLJIT_SIG_LESS_EQUAL;
2514 			break;
2515 		case SLJIT_SIG_GREATER:
2516 			condition = SLJIT_SIG_LESS;
2517 			break;
2518 		case SLJIT_SIG_LESS_EQUAL:
2519 			condition = SLJIT_SIG_GREATER_EQUAL;
2520 			break;
2521 		}
2522 
2523 		type = condition | (type & (SLJIT_32 | SLJIT_REWRITABLE_JUMP));
2524 		tmp_src = src1;
2525 		src1 = src2;
2526 		src2 = tmp_src;
2527 		tmp_srcw = src1w;
2528 		src1w = src2w;
2529 		src2w = tmp_srcw;
2530 	}
2531 
2532 	if (condition <= SLJIT_NOT_ZERO)
2533 		flags = SLJIT_SET_Z;
2534 	else
2535 		flags = condition << VARIABLE_FLAG_SHIFT;
2536 
2537 	SLJIT_SKIP_CHECKS(compiler);
2538 	PTR_FAIL_IF(sljit_emit_op2u(compiler,
2539 		SLJIT_SUB | flags | (type & SLJIT_32), src1, src1w, src2, src2w));
2540 
2541 	SLJIT_SKIP_CHECKS(compiler);
2542 	return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_32)));
2543 }
2544 
2545 #endif /* !SLJIT_CONFIG_MIPS */
2546 
2547 #if (defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM)
2548 
sljit_cmp_info(sljit_s32 type)2549 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2550 {
2551 	if (type < SLJIT_UNORDERED || type > SLJIT_ORDERED_LESS_EQUAL)
2552 		return 0;
2553 
2554 	switch (type) {
2555 	case SLJIT_UNORDERED_OR_EQUAL:
2556 	case SLJIT_ORDERED_NOT_EQUAL:
2557 		return 0;
2558 	}
2559 
2560 	return 1;
2561 }
2562 
2563 #endif /* SLJIT_CONFIG_ARM */
2564 
sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2565 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2566 	sljit_s32 src1, sljit_sw src1w,
2567 	sljit_s32 src2, sljit_sw src2w)
2568 {
2569 	CHECK_ERROR_PTR();
2570 	CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
2571 
2572 	SLJIT_SKIP_CHECKS(compiler);
2573 	sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_32), src1, src1w, src2, src2w);
2574 
2575 	SLJIT_SKIP_CHECKS(compiler);
2576 	return sljit_emit_jump(compiler, type);
2577 }
2578 
2579 #if !(defined SLJIT_CONFIG_ARM && SLJIT_CONFIG_ARM) \
2580 	&& !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2581 
sljit_emit_mem_update(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 reg,sljit_s32 mem,sljit_sw memw)2582 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type,
2583 	sljit_s32 reg,
2584 	sljit_s32 mem, sljit_sw memw)
2585 {
2586 	CHECK_ERROR();
2587 	CHECK(check_sljit_emit_mem_update(compiler, type, reg, mem, memw));
2588 	SLJIT_UNUSED_ARG(type);
2589 	SLJIT_UNUSED_ARG(reg);
2590 	SLJIT_UNUSED_ARG(mem);
2591 	SLJIT_UNUSED_ARG(memw);
2592 
2593 	return SLJIT_ERR_UNSUPPORTED;
2594 }
2595 
2596 #endif /* !SLJIT_CONFIG_ARM && !SLJIT_CONFIG_PPC */
2597 
2598 #if !(defined SLJIT_CONFIG_ARM_32 && SLJIT_CONFIG_ARM_32) \
2599 	&& !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
2600 
sljit_emit_fmem(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)2601 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem(struct sljit_compiler *compiler, sljit_s32 type,
2602 	sljit_s32 freg,
2603 	sljit_s32 mem, sljit_sw memw)
2604 {
2605 	CHECK_ERROR();
2606 	CHECK(check_sljit_emit_fmem(compiler, type, freg, mem, memw));
2607 
2608 	return sljit_emit_fmem_unaligned(compiler, type, freg, mem, memw);
2609 }
2610 
2611 #endif /* !SLJIT_CONFIG_ARM_32 && !SLJIT_CONFIG_MIPS */
2612 
2613 #if !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
2614 	&& !(defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
2615 
sljit_emit_fmem_update(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)2616 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type,
2617 	sljit_s32 freg,
2618 	sljit_s32 mem, sljit_sw memw)
2619 {
2620 	CHECK_ERROR();
2621 	CHECK(check_sljit_emit_fmem_update(compiler, type, freg, mem, memw));
2622 	SLJIT_UNUSED_ARG(type);
2623 	SLJIT_UNUSED_ARG(freg);
2624 	SLJIT_UNUSED_ARG(mem);
2625 	SLJIT_UNUSED_ARG(memw);
2626 
2627 	return SLJIT_ERR_UNSUPPORTED;
2628 }
2629 
2630 #endif /* !SLJIT_CONFIG_ARM_64 && !SLJIT_CONFIG_PPC */
2631 
2632 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
2633 	&& !(defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
2634 
sljit_get_local_base(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw,sljit_sw offset)2635 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2636 {
2637 	CHECK_ERROR();
2638 	CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2639 
2640 	ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
2641 
2642 	SLJIT_SKIP_CHECKS(compiler);
2643 
2644 	if (offset != 0)
2645 		return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2646 	return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
2647 }
2648 
2649 #endif
2650 
2651 #else /* SLJIT_CONFIG_UNSUPPORTED */
2652 
2653 /* Empty function bodies for those machines, which are not (yet) supported. */
2654 
sljit_get_platform_name(void)2655 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
2656 {
2657 	return "unsupported";
2658 }
2659 
sljit_create_compiler(void * allocator_data,void * exec_allocator_data)2660 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data, void *exec_allocator_data)
2661 {
2662 	SLJIT_UNUSED_ARG(allocator_data);
2663 	SLJIT_UNUSED_ARG(exec_allocator_data);
2664 	SLJIT_UNREACHABLE();
2665 	return NULL;
2666 }
2667 
sljit_free_compiler(struct sljit_compiler * compiler)2668 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
2669 {
2670 	SLJIT_UNUSED_ARG(compiler);
2671 	SLJIT_UNREACHABLE();
2672 }
2673 
sljit_set_compiler_memory_error(struct sljit_compiler * compiler)2674 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
2675 {
2676 	SLJIT_UNUSED_ARG(compiler);
2677 	SLJIT_UNREACHABLE();
2678 }
2679 
sljit_alloc_memory(struct sljit_compiler * compiler,sljit_s32 size)2680 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
2681 {
2682 	SLJIT_UNUSED_ARG(compiler);
2683 	SLJIT_UNUSED_ARG(size);
2684 	SLJIT_UNREACHABLE();
2685 	return NULL;
2686 }
2687 
2688 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
sljit_compiler_verbose(struct sljit_compiler * compiler,FILE * verbose)2689 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
2690 {
2691 	SLJIT_UNUSED_ARG(compiler);
2692 	SLJIT_UNUSED_ARG(verbose);
2693 	SLJIT_UNREACHABLE();
2694 }
2695 #endif
2696 
sljit_generate_code(struct sljit_compiler * compiler)2697 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
2698 {
2699 	SLJIT_UNUSED_ARG(compiler);
2700 	SLJIT_UNREACHABLE();
2701 	return NULL;
2702 }
2703 
sljit_has_cpu_feature(sljit_s32 feature_type)2704 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
2705 {
2706 	SLJIT_UNUSED_ARG(feature_type);
2707 	SLJIT_UNREACHABLE();
2708 	return 0;
2709 }
2710 
sljit_cmp_info(sljit_s32 type)2711 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_cmp_info(sljit_s32 type)
2712 {
2713 	SLJIT_UNUSED_ARG(type);
2714 	SLJIT_UNREACHABLE();
2715 	return 0;
2716 }
2717 
sljit_free_code(void * code,void * exec_allocator_data)2718 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code, void *exec_allocator_data)
2719 {
2720 	SLJIT_UNUSED_ARG(code);
2721 	SLJIT_UNUSED_ARG(exec_allocator_data);
2722 	SLJIT_UNREACHABLE();
2723 }
2724 
sljit_emit_enter(struct sljit_compiler * compiler,sljit_s32 options,sljit_s32 arg_types,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches,sljit_s32 fsaveds,sljit_s32 local_size)2725 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
2726 	sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2727 	sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2728 {
2729 	SLJIT_UNUSED_ARG(compiler);
2730 	SLJIT_UNUSED_ARG(options);
2731 	SLJIT_UNUSED_ARG(arg_types);
2732 	SLJIT_UNUSED_ARG(scratches);
2733 	SLJIT_UNUSED_ARG(saveds);
2734 	SLJIT_UNUSED_ARG(fscratches);
2735 	SLJIT_UNUSED_ARG(fsaveds);
2736 	SLJIT_UNUSED_ARG(local_size);
2737 	SLJIT_UNREACHABLE();
2738 	return SLJIT_ERR_UNSUPPORTED;
2739 }
2740 
sljit_set_context(struct sljit_compiler * compiler,sljit_s32 options,sljit_s32 arg_types,sljit_s32 scratches,sljit_s32 saveds,sljit_s32 fscratches,sljit_s32 fsaveds,sljit_s32 local_size)2741 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
2742 	sljit_s32 options, sljit_s32 arg_types, sljit_s32 scratches, sljit_s32 saveds,
2743 	sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
2744 {
2745 	SLJIT_UNUSED_ARG(compiler);
2746 	SLJIT_UNUSED_ARG(options);
2747 	SLJIT_UNUSED_ARG(arg_types);
2748 	SLJIT_UNUSED_ARG(scratches);
2749 	SLJIT_UNUSED_ARG(saveds);
2750 	SLJIT_UNUSED_ARG(fscratches);
2751 	SLJIT_UNUSED_ARG(fsaveds);
2752 	SLJIT_UNUSED_ARG(local_size);
2753 	SLJIT_UNREACHABLE();
2754 	return SLJIT_ERR_UNSUPPORTED;
2755 }
2756 
sljit_emit_return_void(struct sljit_compiler * compiler)2757 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_void(struct sljit_compiler *compiler)
2758 {
2759 	SLJIT_UNUSED_ARG(compiler);
2760 	SLJIT_UNREACHABLE();
2761 	return SLJIT_ERR_UNSUPPORTED;
2762 }
2763 
sljit_emit_return(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)2764 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
2765 {
2766 	SLJIT_UNUSED_ARG(compiler);
2767 	SLJIT_UNUSED_ARG(op);
2768 	SLJIT_UNUSED_ARG(src);
2769 	SLJIT_UNUSED_ARG(srcw);
2770 	SLJIT_UNREACHABLE();
2771 	return SLJIT_ERR_UNSUPPORTED;
2772 }
2773 
sljit_emit_return_to(struct sljit_compiler * compiler,sljit_s32 src,sljit_sw srcw)2774 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return_to(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
2775 {
2776 	SLJIT_UNUSED_ARG(compiler);
2777 	SLJIT_UNUSED_ARG(src);
2778 	SLJIT_UNUSED_ARG(srcw);
2779 	SLJIT_UNREACHABLE();
2780 	return SLJIT_ERR_UNSUPPORTED;
2781 }
2782 
sljit_emit_fast_enter(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw)2783 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
2784 {
2785 	SLJIT_UNUSED_ARG(compiler);
2786 	SLJIT_UNUSED_ARG(dst);
2787 	SLJIT_UNUSED_ARG(dstw);
2788 	SLJIT_UNREACHABLE();
2789 	return SLJIT_ERR_UNSUPPORTED;
2790 }
2791 
sljit_emit_op0(struct sljit_compiler * compiler,sljit_s32 op)2792 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2793 {
2794 	SLJIT_UNUSED_ARG(compiler);
2795 	SLJIT_UNUSED_ARG(op);
2796 	SLJIT_UNREACHABLE();
2797 	return SLJIT_ERR_UNSUPPORTED;
2798 }
2799 
sljit_emit_op1(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src,sljit_sw srcw)2800 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2801 	sljit_s32 dst, sljit_sw dstw,
2802 	sljit_s32 src, sljit_sw srcw)
2803 {
2804 	SLJIT_UNUSED_ARG(compiler);
2805 	SLJIT_UNUSED_ARG(op);
2806 	SLJIT_UNUSED_ARG(dst);
2807 	SLJIT_UNUSED_ARG(dstw);
2808 	SLJIT_UNUSED_ARG(src);
2809 	SLJIT_UNUSED_ARG(srcw);
2810 	SLJIT_UNREACHABLE();
2811 	return SLJIT_ERR_UNSUPPORTED;
2812 }
2813 
sljit_emit_op2(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2814 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2815 	sljit_s32 dst, sljit_sw dstw,
2816 	sljit_s32 src1, sljit_sw src1w,
2817 	sljit_s32 src2, sljit_sw src2w)
2818 {
2819 	SLJIT_UNUSED_ARG(compiler);
2820 	SLJIT_UNUSED_ARG(op);
2821 	SLJIT_UNUSED_ARG(dst);
2822 	SLJIT_UNUSED_ARG(dstw);
2823 	SLJIT_UNUSED_ARG(src1);
2824 	SLJIT_UNUSED_ARG(src1w);
2825 	SLJIT_UNUSED_ARG(src2);
2826 	SLJIT_UNUSED_ARG(src2w);
2827 	SLJIT_UNREACHABLE();
2828 	return SLJIT_ERR_UNSUPPORTED;
2829 }
2830 
sljit_emit_op2u(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2831 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2u(struct sljit_compiler *compiler, sljit_s32 op,
2832 	sljit_s32 src1, sljit_sw src1w,
2833 	sljit_s32 src2, sljit_sw src2w)
2834 {
2835 	SLJIT_UNUSED_ARG(compiler);
2836 	SLJIT_UNUSED_ARG(op);
2837 	SLJIT_UNUSED_ARG(src1);
2838 	SLJIT_UNUSED_ARG(src1w);
2839 	SLJIT_UNUSED_ARG(src2);
2840 	SLJIT_UNUSED_ARG(src2w);
2841 	SLJIT_UNREACHABLE();
2842 	return SLJIT_ERR_UNSUPPORTED;
2843 }
2844 
sljit_emit_shift_into(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src_dst,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2845 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_shift_into(struct sljit_compiler *compiler, sljit_s32 op,
2846 	sljit_s32 src_dst,
2847 	sljit_s32 src1, sljit_sw src1w,
2848 	sljit_s32 src2, sljit_sw src2w)
2849 {
2850 	SLJIT_UNUSED_ARG(compiler);
2851 	SLJIT_UNUSED_ARG(op);
2852 	SLJIT_UNUSED_ARG(src_dst);
2853 	SLJIT_UNUSED_ARG(src1);
2854 	SLJIT_UNUSED_ARG(src1w);
2855 	SLJIT_UNUSED_ARG(src2);
2856 	SLJIT_UNUSED_ARG(src2w);
2857 	SLJIT_UNREACHABLE();
2858 	return SLJIT_ERR_UNSUPPORTED;
2859 }
2860 
sljit_emit_op_src(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 src,sljit_sw srcw)2861 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_src(struct sljit_compiler *compiler, sljit_s32 op,
2862 	sljit_s32 src, sljit_sw srcw)
2863 {
2864 	SLJIT_UNUSED_ARG(compiler);
2865 	SLJIT_UNUSED_ARG(op);
2866 	SLJIT_UNUSED_ARG(src);
2867 	SLJIT_UNUSED_ARG(srcw);
2868 	SLJIT_UNREACHABLE();
2869 	return SLJIT_ERR_UNSUPPORTED;
2870 }
2871 
sljit_get_register_index(sljit_s32 reg)2872 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2873 {
2874 	SLJIT_UNREACHABLE();
2875 	return reg;
2876 }
2877 
sljit_emit_op_custom(struct sljit_compiler * compiler,void * instruction,sljit_u32 size)2878 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2879 	void *instruction, sljit_u32 size)
2880 {
2881 	SLJIT_UNUSED_ARG(compiler);
2882 	SLJIT_UNUSED_ARG(instruction);
2883 	SLJIT_UNUSED_ARG(size);
2884 	SLJIT_UNREACHABLE();
2885 	return SLJIT_ERR_UNSUPPORTED;
2886 }
2887 
sljit_set_current_flags(struct sljit_compiler * compiler,sljit_s32 current_flags)2888 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2889 {
2890 	SLJIT_UNUSED_ARG(compiler);
2891 	SLJIT_UNUSED_ARG(current_flags);
2892 }
2893 
sljit_emit_fop1(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src,sljit_sw srcw)2894 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2895 	sljit_s32 dst, sljit_sw dstw,
2896 	sljit_s32 src, sljit_sw srcw)
2897 {
2898 	SLJIT_UNUSED_ARG(compiler);
2899 	SLJIT_UNUSED_ARG(op);
2900 	SLJIT_UNUSED_ARG(dst);
2901 	SLJIT_UNUSED_ARG(dstw);
2902 	SLJIT_UNUSED_ARG(src);
2903 	SLJIT_UNUSED_ARG(srcw);
2904 	SLJIT_UNREACHABLE();
2905 	return SLJIT_ERR_UNSUPPORTED;
2906 }
2907 
sljit_emit_fop2(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2908 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2909 	sljit_s32 dst, sljit_sw dstw,
2910 	sljit_s32 src1, sljit_sw src1w,
2911 	sljit_s32 src2, sljit_sw src2w)
2912 {
2913 	SLJIT_UNUSED_ARG(compiler);
2914 	SLJIT_UNUSED_ARG(op);
2915 	SLJIT_UNUSED_ARG(dst);
2916 	SLJIT_UNUSED_ARG(dstw);
2917 	SLJIT_UNUSED_ARG(src1);
2918 	SLJIT_UNUSED_ARG(src1w);
2919 	SLJIT_UNUSED_ARG(src2);
2920 	SLJIT_UNUSED_ARG(src2w);
2921 	SLJIT_UNREACHABLE();
2922 	return SLJIT_ERR_UNSUPPORTED;
2923 }
2924 
sljit_emit_label(struct sljit_compiler * compiler)2925 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2926 {
2927 	SLJIT_UNUSED_ARG(compiler);
2928 	SLJIT_UNREACHABLE();
2929 	return NULL;
2930 }
2931 
sljit_emit_jump(struct sljit_compiler * compiler,sljit_s32 type)2932 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2933 {
2934 	SLJIT_UNUSED_ARG(compiler);
2935 	SLJIT_UNUSED_ARG(type);
2936 	SLJIT_UNREACHABLE();
2937 	return NULL;
2938 }
2939 
sljit_emit_call(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 arg_types)2940 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_call(struct sljit_compiler *compiler, sljit_s32 type,
2941 	sljit_s32 arg_types)
2942 {
2943 	SLJIT_UNUSED_ARG(compiler);
2944 	SLJIT_UNUSED_ARG(type);
2945 	SLJIT_UNUSED_ARG(arg_types);
2946 	SLJIT_UNREACHABLE();
2947 	return NULL;
2948 }
2949 
sljit_emit_cmp(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2950 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2951 	sljit_s32 src1, sljit_sw src1w,
2952 	sljit_s32 src2, sljit_sw src2w)
2953 {
2954 	SLJIT_UNUSED_ARG(compiler);
2955 	SLJIT_UNUSED_ARG(type);
2956 	SLJIT_UNUSED_ARG(src1);
2957 	SLJIT_UNUSED_ARG(src1w);
2958 	SLJIT_UNUSED_ARG(src2);
2959 	SLJIT_UNUSED_ARG(src2w);
2960 	SLJIT_UNREACHABLE();
2961 	return NULL;
2962 }
2963 
sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src1,sljit_sw src1w,sljit_s32 src2,sljit_sw src2w)2964 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2965 	sljit_s32 src1, sljit_sw src1w,
2966 	sljit_s32 src2, sljit_sw src2w)
2967 {
2968 	SLJIT_UNUSED_ARG(compiler);
2969 	SLJIT_UNUSED_ARG(type);
2970 	SLJIT_UNUSED_ARG(src1);
2971 	SLJIT_UNUSED_ARG(src1w);
2972 	SLJIT_UNUSED_ARG(src2);
2973 	SLJIT_UNUSED_ARG(src2w);
2974 	SLJIT_UNREACHABLE();
2975 	return NULL;
2976 }
2977 
sljit_set_label(struct sljit_jump * jump,struct sljit_label * label)2978 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2979 {
2980 	SLJIT_UNUSED_ARG(jump);
2981 	SLJIT_UNUSED_ARG(label);
2982 	SLJIT_UNREACHABLE();
2983 }
2984 
sljit_set_target(struct sljit_jump * jump,sljit_uw target)2985 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2986 {
2987 	SLJIT_UNUSED_ARG(jump);
2988 	SLJIT_UNUSED_ARG(target);
2989 	SLJIT_UNREACHABLE();
2990 }
2991 
sljit_set_put_label(struct sljit_put_label * put_label,struct sljit_label * label)2992 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_put_label(struct sljit_put_label *put_label, struct sljit_label *label)
2993 {
2994 	SLJIT_UNUSED_ARG(put_label);
2995 	SLJIT_UNUSED_ARG(label);
2996 	SLJIT_UNREACHABLE();
2997 }
2998 
sljit_emit_ijump(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 src,sljit_sw srcw)2999 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
3000 {
3001 	SLJIT_UNUSED_ARG(compiler);
3002 	SLJIT_UNUSED_ARG(type);
3003 	SLJIT_UNUSED_ARG(src);
3004 	SLJIT_UNUSED_ARG(srcw);
3005 	SLJIT_UNREACHABLE();
3006 	return SLJIT_ERR_UNSUPPORTED;
3007 }
3008 
sljit_emit_icall(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 arg_types,sljit_s32 src,sljit_sw srcw)3009 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_icall(struct sljit_compiler *compiler, sljit_s32 type,
3010 	sljit_s32 arg_types,
3011 	sljit_s32 src, sljit_sw srcw)
3012 {
3013 	SLJIT_UNUSED_ARG(compiler);
3014 	SLJIT_UNUSED_ARG(type);
3015 	SLJIT_UNUSED_ARG(arg_types);
3016 	SLJIT_UNUSED_ARG(src);
3017 	SLJIT_UNUSED_ARG(srcw);
3018 	SLJIT_UNREACHABLE();
3019 	return SLJIT_ERR_UNSUPPORTED;
3020 }
3021 
sljit_emit_op_flags(struct sljit_compiler * compiler,sljit_s32 op,sljit_s32 dst,sljit_sw dstw,sljit_s32 type)3022 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
3023 	sljit_s32 dst, sljit_sw dstw,
3024 	sljit_s32 type)
3025 {
3026 	SLJIT_UNUSED_ARG(compiler);
3027 	SLJIT_UNUSED_ARG(op);
3028 	SLJIT_UNUSED_ARG(dst);
3029 	SLJIT_UNUSED_ARG(dstw);
3030 	SLJIT_UNUSED_ARG(type);
3031 	SLJIT_UNREACHABLE();
3032 	return SLJIT_ERR_UNSUPPORTED;
3033 }
3034 
sljit_emit_cmov(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 dst_reg,sljit_s32 src,sljit_sw srcw)3035 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
3036 	sljit_s32 dst_reg,
3037 	sljit_s32 src, sljit_sw srcw)
3038 {
3039 	SLJIT_UNUSED_ARG(compiler);
3040 	SLJIT_UNUSED_ARG(type);
3041 	SLJIT_UNUSED_ARG(dst_reg);
3042 	SLJIT_UNUSED_ARG(src);
3043 	SLJIT_UNUSED_ARG(srcw);
3044 	SLJIT_UNREACHABLE();
3045 	return SLJIT_ERR_UNSUPPORTED;
3046 }
3047 
sljit_emit_mem(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 reg,sljit_s32 mem,sljit_sw memw)3048 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)
3049 {
3050 	SLJIT_UNUSED_ARG(compiler);
3051 	SLJIT_UNUSED_ARG(type);
3052 	SLJIT_UNUSED_ARG(reg);
3053 	SLJIT_UNUSED_ARG(mem);
3054 	SLJIT_UNUSED_ARG(memw);
3055 	SLJIT_UNREACHABLE();
3056 	return SLJIT_ERR_UNSUPPORTED;
3057 }
3058 
sljit_emit_mem_update(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 reg,sljit_s32 mem,sljit_sw memw)3059 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_mem_update(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 reg, sljit_s32 mem, sljit_sw memw)
3060 {
3061 	SLJIT_UNUSED_ARG(compiler);
3062 	SLJIT_UNUSED_ARG(type);
3063 	SLJIT_UNUSED_ARG(reg);
3064 	SLJIT_UNUSED_ARG(mem);
3065 	SLJIT_UNUSED_ARG(memw);
3066 	SLJIT_UNREACHABLE();
3067 	return SLJIT_ERR_UNSUPPORTED;
3068 }
3069 
sljit_emit_fmem(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)3070 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)
3071 {
3072 	SLJIT_UNUSED_ARG(compiler);
3073 	SLJIT_UNUSED_ARG(type);
3074 	SLJIT_UNUSED_ARG(freg);
3075 	SLJIT_UNUSED_ARG(mem);
3076 	SLJIT_UNUSED_ARG(memw);
3077 	SLJIT_UNREACHABLE();
3078 	return SLJIT_ERR_UNSUPPORTED;
3079 }
3080 
sljit_emit_fmem_update(struct sljit_compiler * compiler,sljit_s32 type,sljit_s32 freg,sljit_s32 mem,sljit_sw memw)3081 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fmem_update(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 freg, sljit_s32 mem, sljit_sw memw)
3082 {
3083 	SLJIT_UNUSED_ARG(compiler);
3084 	SLJIT_UNUSED_ARG(type);
3085 	SLJIT_UNUSED_ARG(freg);
3086 	SLJIT_UNUSED_ARG(mem);
3087 	SLJIT_UNUSED_ARG(memw);
3088 	SLJIT_UNREACHABLE();
3089 	return SLJIT_ERR_UNSUPPORTED;
3090 }
3091 
sljit_get_local_base(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw,sljit_sw offset)3092 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
3093 {
3094 	SLJIT_UNUSED_ARG(compiler);
3095 	SLJIT_UNUSED_ARG(dst);
3096 	SLJIT_UNUSED_ARG(dstw);
3097 	SLJIT_UNUSED_ARG(offset);
3098 	SLJIT_UNREACHABLE();
3099 	return SLJIT_ERR_UNSUPPORTED;
3100 }
3101 
sljit_emit_const(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw,sljit_sw initval)3102 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
3103 {
3104 	SLJIT_UNUSED_ARG(compiler);
3105 	SLJIT_UNUSED_ARG(dst);
3106 	SLJIT_UNUSED_ARG(dstw);
3107 	SLJIT_UNUSED_ARG(initval);
3108 	SLJIT_UNREACHABLE();
3109 	return NULL;
3110 }
3111 
sljit_emit_put_label(struct sljit_compiler * compiler,sljit_s32 dst,sljit_sw dstw)3112 SLJIT_API_FUNC_ATTRIBUTE struct sljit_put_label* sljit_emit_put_label(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
3113 {
3114 	SLJIT_UNUSED_ARG(compiler);
3115 	SLJIT_UNUSED_ARG(dst);
3116 	SLJIT_UNUSED_ARG(dstw);
3117 	return NULL;
3118 }
3119 
sljit_set_jump_addr(sljit_uw addr,sljit_uw new_target,sljit_sw executable_offset)3120 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
3121 {
3122 	SLJIT_UNUSED_ARG(addr);
3123 	SLJIT_UNUSED_ARG(new_target);
3124 	SLJIT_UNUSED_ARG(executable_offset);
3125 	SLJIT_UNREACHABLE();
3126 }
3127 
sljit_set_const(sljit_uw addr,sljit_sw new_constant,sljit_sw executable_offset)3128 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
3129 {
3130 	SLJIT_UNUSED_ARG(addr);
3131 	SLJIT_UNUSED_ARG(new_constant);
3132 	SLJIT_UNUSED_ARG(executable_offset);
3133 	SLJIT_UNREACHABLE();
3134 }
3135 
3136 #endif /* !SLJIT_CONFIG_UNSUPPORTED */
3137