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