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