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