• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *    Stack-less Just-In-Time compiler
3  *
4  *    Copyright 2009-2012 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 #define CHECK_ERROR() \
30 	do { \
31 		if (SLJIT_UNLIKELY(compiler->error)) \
32 			return compiler->error; \
33 	} while (0)
34 
35 #define CHECK_ERROR_PTR() \
36 	do { \
37 		if (SLJIT_UNLIKELY(compiler->error)) \
38 			return NULL; \
39 	} while (0)
40 
41 #define FAIL_IF(expr) \
42 	do { \
43 		if (SLJIT_UNLIKELY(expr)) \
44 			return compiler->error; \
45 	} while (0)
46 
47 #define PTR_FAIL_IF(expr) \
48 	do { \
49 		if (SLJIT_UNLIKELY(expr)) \
50 			return NULL; \
51 	} while (0)
52 
53 #define FAIL_IF_NULL(ptr) \
54 	do { \
55 		if (SLJIT_UNLIKELY(!(ptr))) { \
56 			compiler->error = SLJIT_ERR_ALLOC_FAILED; \
57 			return SLJIT_ERR_ALLOC_FAILED; \
58 		} \
59 	} while (0)
60 
61 #define PTR_FAIL_IF_NULL(ptr) \
62 	do { \
63 		if (SLJIT_UNLIKELY(!(ptr))) { \
64 			compiler->error = SLJIT_ERR_ALLOC_FAILED; \
65 			return NULL; \
66 		} \
67 	} while (0)
68 
69 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
70 	do { \
71 		if (SLJIT_UNLIKELY(!(ptr))) { \
72 			compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
73 			return NULL; \
74 		} \
75 	} while (0)
76 
77 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
78 
79 #define GET_OPCODE(op) \
80 	((op) & ~(SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
81 
82 #define GET_FLAGS(op) \
83 	((op) & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C))
84 
85 #define GET_ALL_FLAGS(op) \
86 	((op) & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
87 
88 #define TYPE_CAST_NEEDED(op) \
89 	(((op) >= SLJIT_MOV_UB && (op) <= SLJIT_MOV_SH) || ((op) >= SLJIT_MOVU_UB && (op) <= SLJIT_MOVU_SH))
90 
91 #define BUF_SIZE	4096
92 
93 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
94 #define ABUF_SIZE	2048
95 #else
96 #define ABUF_SIZE	4096
97 #endif
98 
99 /* Parameter parsing. */
100 #define REG_MASK		0x3f
101 #define OFFS_REG(reg)		(((reg) >> 8) & REG_MASK)
102 #define OFFS_REG_MASK		(REG_MASK << 8)
103 #define TO_OFFS_REG(reg)	((reg) << 8)
104 /* When reg cannot be unused. */
105 #define FAST_IS_REG(reg)	((reg) <= REG_MASK)
106 /* When reg can be unused. */
107 #define SLOW_IS_REG(reg)	((reg) > 0 && (reg) <= REG_MASK)
108 
109 /* Jump flags. */
110 #define JUMP_LABEL	0x1
111 #define JUMP_ADDR	0x2
112 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
113 
114 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
115 #	define PATCH_MB	0x4
116 #	define PATCH_MW	0x8
117 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
118 #	define PATCH_MD	0x10
119 #endif
120 #endif
121 
122 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
123 #	define IS_BL		0x4
124 #	define PATCH_B		0x8
125 #endif
126 
127 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
128 #	define CPOOL_SIZE	512
129 #endif
130 
131 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
132 #	define IS_COND		0x04
133 #	define IS_BL		0x08
134 	/* conditional + imm8 */
135 #	define PATCH_TYPE1	0x10
136 	/* conditional + imm20 */
137 #	define PATCH_TYPE2	0x20
138 	/* IT + imm24 */
139 #	define PATCH_TYPE3	0x30
140 	/* imm11 */
141 #	define PATCH_TYPE4	0x40
142 	/* imm24 */
143 #	define PATCH_TYPE5	0x50
144 	/* BL + imm24 */
145 #	define PATCH_BL		0x60
146 	/* 0xf00 cc code for branches */
147 #endif
148 
149 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
150 #	define IS_COND		0x004
151 #	define IS_CBZ		0x008
152 #	define IS_BL		0x010
153 #	define PATCH_B		0x020
154 #	define PATCH_COND	0x040
155 #	define PATCH_ABS48	0x080
156 #	define PATCH_ABS64	0x100
157 #endif
158 
159 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
160 #	define IS_COND		0x004
161 #	define IS_CALL		0x008
162 #	define PATCH_B		0x010
163 #	define PATCH_ABS_B	0x020
164 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
165 #	define PATCH_ABS32	0x040
166 #	define PATCH_ABS48	0x080
167 #endif
168 #	define REMOVE_COND	0x100
169 #endif
170 
171 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
172 #	define IS_MOVABLE	0x004
173 #	define IS_JAL		0x008
174 #	define IS_CALL		0x010
175 #	define IS_BIT26_COND	0x020
176 #	define IS_BIT16_COND	0x040
177 
178 #	define IS_COND		(IS_BIT26_COND | IS_BIT16_COND)
179 
180 #	define PATCH_B		0x080
181 #	define PATCH_J		0x100
182 
183 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
184 #	define PATCH_ABS32	0x200
185 #	define PATCH_ABS48	0x400
186 #endif
187 
188 	/* instruction types */
189 #	define MOVABLE_INS	0
190 	/* 1 - 31 last destination register */
191 	/* no destination (i.e: store) */
192 #	define UNMOVABLE_INS	32
193 	/* FPU status register */
194 #	define FCSR_FCC		33
195 #endif
196 
197 #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
198 #	define IS_JAL		0x04
199 #	define IS_COND		0x08
200 
201 #	define PATCH_B		0x10
202 #	define PATCH_J		0x20
203 #endif
204 
205 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
206 #	define IS_MOVABLE	0x04
207 #	define IS_COND		0x08
208 #	define IS_CALL		0x10
209 
210 #	define PATCH_B		0x20
211 #	define PATCH_CALL	0x40
212 
213 	/* instruction types */
214 #	define MOVABLE_INS	0
215 	/* 1 - 31 last destination register */
216 	/* no destination (i.e: store) */
217 #	define UNMOVABLE_INS	32
218 
219 #	define DST_INS_MASK	0xff
220 
221 	/* ICC_SET is the same as SET_FLAGS. */
222 #	define ICC_IS_SET	(1 << 23)
223 #	define FCC_IS_SET	(1 << 24)
224 #endif
225 
226 /* Stack management. */
227 
228 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
229 	(((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
230 		(saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
231 		extra) * sizeof(sljit_sw))
232 
233 #define ADJUST_LOCAL_OFFSET(p, i) \
234 	if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
235 		(i) += SLJIT_LOCALS_OFFSET;
236 
237 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
238 
239 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
240 #include "sljitUtils.c"
241 
242 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
243 
244 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
245 #include "sljitExecAllocator.c"
246 #endif
247 
248 /* Argument checking features. */
249 
250 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
251 
252 /* Returns with error when an invalid argument is passed. */
253 
254 #define CHECK_ARGUMENT(x) \
255 	do { \
256 		if (SLJIT_UNLIKELY(!(x))) \
257 			return 1; \
258 	} while (0)
259 
260 #define CHECK_RETURN_TYPE sljit_si
261 #define CHECK_RETURN_OK return 0
262 
263 #define CHECK(x) \
264 	do { \
265 		if (SLJIT_UNLIKELY(x)) { \
266 			compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
267 			return SLJIT_ERR_BAD_ARGUMENT; \
268 		} \
269 	} while (0)
270 
271 #define CHECK_PTR(x) \
272 	do { \
273 		if (SLJIT_UNLIKELY(x)) { \
274 			compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
275 			return NULL; \
276 		} \
277 	} while (0)
278 
279 #define CHECK_REG_INDEX(x) \
280 	do { \
281 		if (SLJIT_UNLIKELY(x)) { \
282 			return -2; \
283 		} \
284 	} while (0)
285 
286 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
287 
288 /* Assertion failure occures if an invalid argument is passed. */
289 #undef SLJIT_ARGUMENT_CHECKS
290 #define SLJIT_ARGUMENT_CHECKS 1
291 
292 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
293 #define CHECK_RETURN_TYPE void
294 #define CHECK_RETURN_OK return
295 #define CHECK(x) x
296 #define CHECK_PTR(x) x
297 #define CHECK_REG_INDEX(x) x
298 
299 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
300 
301 /* Arguments are not checked. */
302 #define CHECK_RETURN_TYPE void
303 #define CHECK_RETURN_OK return
304 #define CHECK(x) x
305 #define CHECK_PTR(x) x
306 #define CHECK_REG_INDEX(x) x
307 
308 #else
309 
310 /* Arguments are not checked. */
311 #define CHECK(x)
312 #define CHECK_PTR(x)
313 #define CHECK_REG_INDEX(x)
314 
315 #endif /* SLJIT_ARGUMENT_CHECKS */
316 
317 /* --------------------------------------------------------------------- */
318 /*  Public functions                                                     */
319 /* --------------------------------------------------------------------- */
320 
321 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
322 #define SLJIT_NEEDS_COMPILER_INIT 1
323 static sljit_si compiler_initialized = 0;
324 /* A thread safe initialization. */
325 static void init_compiler(void);
326 #endif
327 
sljit_create_compiler(void * allocator_data)328 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
329 {
330 	struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler), allocator_data);
331 	if (!compiler)
332 		return NULL;
333 	SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
334 
335 	SLJIT_COMPILE_ASSERT(
336 		sizeof(sljit_sb) == 1 && sizeof(sljit_ub) == 1
337 		&& sizeof(sljit_sh) == 2 && sizeof(sljit_uh) == 2
338 		&& sizeof(sljit_si) == 4 && sizeof(sljit_ui) == 4
339 		&& (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
340 		&& sizeof(sljit_p) <= sizeof(sljit_sw)
341 		&& (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
342 		&& (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
343 		invalid_integer_types);
344 	SLJIT_COMPILE_ASSERT(SLJIT_INT_OP == SLJIT_SINGLE_OP,
345 		int_op_and_single_op_must_be_the_same);
346 	SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_SINGLE_OP,
347 		rewritable_jump_and_single_op_must_not_be_the_same);
348 
349 	/* Only the non-zero members must be set. */
350 	compiler->error = SLJIT_SUCCESS;
351 
352 	compiler->allocator_data = allocator_data;
353 	compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, allocator_data);
354 	compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, allocator_data);
355 
356 	if (!compiler->buf || !compiler->abuf) {
357 		if (compiler->buf)
358 			SLJIT_FREE(compiler->buf, allocator_data);
359 		if (compiler->abuf)
360 			SLJIT_FREE(compiler->abuf, allocator_data);
361 		SLJIT_FREE(compiler, allocator_data);
362 		return NULL;
363 	}
364 
365 	compiler->buf->next = NULL;
366 	compiler->buf->used_size = 0;
367 	compiler->abuf->next = NULL;
368 	compiler->abuf->used_size = 0;
369 
370 	compiler->scratches = -1;
371 	compiler->saveds = -1;
372 	compiler->fscratches = -1;
373 	compiler->fsaveds = -1;
374 	compiler->local_size = -1;
375 
376 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
377 	compiler->args = -1;
378 #endif
379 
380 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
381 	compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw)
382 		+ CPOOL_SIZE * sizeof(sljit_ub), allocator_data);
383 	if (!compiler->cpool) {
384 		SLJIT_FREE(compiler->buf, allocator_data);
385 		SLJIT_FREE(compiler->abuf, allocator_data);
386 		SLJIT_FREE(compiler, allocator_data);
387 		return NULL;
388 	}
389 	compiler->cpool_unique = (sljit_ub*)(compiler->cpool + CPOOL_SIZE);
390 	compiler->cpool_diff = 0xffffffff;
391 #endif
392 
393 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
394 	compiler->delay_slot = UNMOVABLE_INS;
395 #endif
396 
397 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
398 	compiler->delay_slot = UNMOVABLE_INS;
399 #endif
400 
401 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
402 	if (!compiler_initialized) {
403 		init_compiler();
404 		compiler_initialized = 1;
405 	}
406 #endif
407 
408 	return compiler;
409 }
410 
sljit_free_compiler(struct sljit_compiler * compiler)411 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
412 {
413 	struct sljit_memory_fragment *buf;
414 	struct sljit_memory_fragment *curr;
415 	void *allocator_data = compiler->allocator_data;
416 	SLJIT_UNUSED_ARG(allocator_data);
417 
418 	buf = compiler->buf;
419 	while (buf) {
420 		curr = buf;
421 		buf = buf->next;
422 		SLJIT_FREE(curr, allocator_data);
423 	}
424 
425 	buf = compiler->abuf;
426 	while (buf) {
427 		curr = buf;
428 		buf = buf->next;
429 		SLJIT_FREE(curr, allocator_data);
430 	}
431 
432 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
433 	SLJIT_FREE(compiler->cpool, allocator_data);
434 #endif
435 	SLJIT_FREE(compiler, allocator_data);
436 }
437 
sljit_set_compiler_memory_error(struct sljit_compiler * compiler)438 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
439 {
440 	if (compiler->error == SLJIT_SUCCESS)
441 		compiler->error = SLJIT_ERR_ALLOC_FAILED;
442 }
443 
444 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
sljit_free_code(void * code)445 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
446 {
447 	/* Remove thumb mode flag. */
448 	SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1));
449 }
450 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
sljit_free_code(void * code)451 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
452 {
453 	/* Resolve indirection. */
454 	code = (void*)(*(sljit_uw*)code);
455 	SLJIT_FREE_EXEC(code);
456 }
457 #else
sljit_free_code(void * code)458 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
459 {
460 	SLJIT_FREE_EXEC(code);
461 }
462 #endif
463 
sljit_set_label(struct sljit_jump * jump,struct sljit_label * label)464 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
465 {
466 	if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
467 		jump->flags &= ~JUMP_ADDR;
468 		jump->flags |= JUMP_LABEL;
469 		jump->u.label = label;
470 	}
471 }
472 
sljit_set_target(struct sljit_jump * jump,sljit_uw target)473 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
474 {
475 	if (SLJIT_LIKELY(!!jump)) {
476 		jump->flags &= ~JUMP_LABEL;
477 		jump->flags |= JUMP_ADDR;
478 		jump->u.target = target;
479 	}
480 }
481 
482 /* --------------------------------------------------------------------- */
483 /*  Private functions                                                    */
484 /* --------------------------------------------------------------------- */
485 
ensure_buf(struct sljit_compiler * compiler,sljit_uw size)486 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
487 {
488 	sljit_ub *ret;
489 	struct sljit_memory_fragment *new_frag;
490 
491 	SLJIT_ASSERT(size <= 256);
492 	if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
493 		ret = compiler->buf->memory + compiler->buf->used_size;
494 		compiler->buf->used_size += size;
495 		return ret;
496 	}
497 	new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE, compiler->allocator_data);
498 	PTR_FAIL_IF_NULL(new_frag);
499 	new_frag->next = compiler->buf;
500 	compiler->buf = new_frag;
501 	new_frag->used_size = size;
502 	return new_frag->memory;
503 }
504 
ensure_abuf(struct sljit_compiler * compiler,sljit_uw size)505 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
506 {
507 	sljit_ub *ret;
508 	struct sljit_memory_fragment *new_frag;
509 
510 	SLJIT_ASSERT(size <= 256);
511 	if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
512 		ret = compiler->abuf->memory + compiler->abuf->used_size;
513 		compiler->abuf->used_size += size;
514 		return ret;
515 	}
516 	new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE, compiler->allocator_data);
517 	PTR_FAIL_IF_NULL(new_frag);
518 	new_frag->next = compiler->abuf;
519 	compiler->abuf = new_frag;
520 	new_frag->used_size = size;
521 	return new_frag->memory;
522 }
523 
sljit_alloc_memory(struct sljit_compiler * compiler,sljit_si size)524 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
525 {
526 	CHECK_ERROR_PTR();
527 
528 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
529 	if (size <= 0 || size > 128)
530 		return NULL;
531 	size = (size + 7) & ~7;
532 #else
533 	if (size <= 0 || size > 64)
534 		return NULL;
535 	size = (size + 3) & ~3;
536 #endif
537 	return ensure_abuf(compiler, size);
538 }
539 
reverse_buf(struct sljit_compiler * compiler)540 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
541 {
542 	struct sljit_memory_fragment *buf = compiler->buf;
543 	struct sljit_memory_fragment *prev = NULL;
544 	struct sljit_memory_fragment *tmp;
545 
546 	do {
547 		tmp = buf->next;
548 		buf->next = prev;
549 		prev = buf;
550 		buf = tmp;
551 	} while (buf != NULL);
552 
553 	compiler->buf = prev;
554 }
555 
set_emit_enter(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)556 static SLJIT_INLINE void set_emit_enter(struct sljit_compiler *compiler,
557 	sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
558 	sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
559 {
560 	SLJIT_UNUSED_ARG(args);
561 	SLJIT_UNUSED_ARG(local_size);
562 
563 	compiler->options = options;
564 	compiler->scratches = scratches;
565 	compiler->saveds = saveds;
566 	compiler->fscratches = fscratches;
567 	compiler->fsaveds = fsaveds;
568 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
569 	compiler->logical_local_size = local_size;
570 #endif
571 }
572 
set_set_context(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)573 static SLJIT_INLINE void set_set_context(struct sljit_compiler *compiler,
574 	sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
575 	sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
576 {
577 	SLJIT_UNUSED_ARG(args);
578 	SLJIT_UNUSED_ARG(local_size);
579 
580 	compiler->options = options;
581 	compiler->scratches = scratches;
582 	compiler->saveds = saveds;
583 	compiler->fscratches = fscratches;
584 	compiler->fsaveds = fsaveds;
585 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
586 	compiler->logical_local_size = local_size;
587 #endif
588 }
589 
set_label(struct sljit_label * label,struct sljit_compiler * compiler)590 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
591 {
592 	label->next = NULL;
593 	label->size = compiler->size;
594 	if (compiler->last_label)
595 		compiler->last_label->next = label;
596 	else
597 		compiler->labels = label;
598 	compiler->last_label = label;
599 }
600 
set_jump(struct sljit_jump * jump,struct sljit_compiler * compiler,sljit_si flags)601 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_si flags)
602 {
603 	jump->next = NULL;
604 	jump->flags = flags;
605 	if (compiler->last_jump)
606 		compiler->last_jump->next = jump;
607 	else
608 		compiler->jumps = jump;
609 	compiler->last_jump = jump;
610 }
611 
set_const(struct sljit_const * const_,struct sljit_compiler * compiler)612 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
613 {
614 	const_->next = NULL;
615 	const_->addr = compiler->size;
616 	if (compiler->last_const)
617 		compiler->last_const->next = const_;
618 	else
619 		compiler->consts = const_;
620 	compiler->last_const = const_;
621 }
622 
623 #define ADDRESSING_DEPENDS_ON(exp, reg) \
624 	(((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
625 
626 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
627 #define FUNCTION_CHECK_OP() \
628 	CHECK_ARGUMENT(!GET_FLAGS(op) || !(op & SLJIT_KEEP_FLAGS)); \
629 	switch (GET_OPCODE(op)) { \
630 	case SLJIT_NOT: \
631 	case SLJIT_CLZ: \
632 	case SLJIT_AND: \
633 	case SLJIT_OR: \
634 	case SLJIT_XOR: \
635 	case SLJIT_SHL: \
636 	case SLJIT_LSHR: \
637 	case SLJIT_ASHR: \
638 		CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C))); \
639 		break; \
640 	case SLJIT_NEG: \
641 		CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_C))); \
642 		break; \
643 	case SLJIT_MUL: \
644 		CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_C))); \
645 		break; \
646 	case SLJIT_ADD: \
647 		CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_S))); \
648 		break; \
649 	case SLJIT_SUB: \
650 		break; \
651 	case SLJIT_ADDC: \
652 	case SLJIT_SUBC: \
653 		CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O))); \
654 		break; \
655 	case SLJIT_BREAKPOINT: \
656 	case SLJIT_NOP: \
657 	case SLJIT_LUMUL: \
658 	case SLJIT_LSMUL: \
659 	case SLJIT_MOV: \
660 	case SLJIT_MOV_UI: \
661 	case SLJIT_MOV_P: \
662 	case SLJIT_MOVU: \
663 	case SLJIT_MOVU_UI: \
664 	case SLJIT_MOVU_P: \
665 		/* Nothing allowed */ \
666 		CHECK_ARGUMENT(!(op & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
667 		break; \
668 	default: \
669 		/* Only SLJIT_INT_OP or SLJIT_SINGLE_OP is allowed. */ \
670 		CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
671 		break; \
672 	}
673 
674 #define FUNCTION_CHECK_FOP() \
675 	CHECK_ARGUMENT(!GET_FLAGS(op) || !(op & SLJIT_KEEP_FLAGS)); \
676 	switch (GET_OPCODE(op)) { \
677 	case SLJIT_DCMP: \
678 		CHECK_ARGUMENT(!(op & (SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
679 		CHECK_ARGUMENT((op & (SLJIT_SET_E | SLJIT_SET_S))); \
680 		break; \
681 	default: \
682 		/* Only SLJIT_INT_OP or SLJIT_SINGLE_OP is allowed. */ \
683 		CHECK_ARGUMENT(!(op & (SLJIT_SET_E | SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
684 		break; \
685 	}
686 
687 #define FUNCTION_CHECK_IS_REG(r) \
688 	(((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \
689 	((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
690 
691 #define FUNCTION_CHECK_IS_REG_OR_UNUSED(r) \
692 	((r) == SLJIT_UNUSED || \
693 	((r) >= SLJIT_R0 && (r) < (SLJIT_R0 + compiler->scratches)) || \
694 	((r) > (SLJIT_S0 - compiler->saveds) && (r) <= SLJIT_S0))
695 
696 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
697 #define CHECK_NOT_VIRTUAL_REGISTER(p) \
698 	CHECK_ARGUMENT((p) < SLJIT_R3 || (p) > SLJIT_R6);
699 #else
700 #define CHECK_NOT_VIRTUAL_REGISTER(p)
701 #endif
702 
703 #define FUNCTION_CHECK_SRC(p, i) \
704 	CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
705 	if (FUNCTION_CHECK_IS_REG(p)) \
706 		CHECK_ARGUMENT((i) == 0); \
707 	else if ((p) == SLJIT_IMM) \
708 		; \
709 	else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
710 		CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
711 	else { \
712 		CHECK_ARGUMENT((p) & SLJIT_MEM); \
713 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
714 		CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
715 		if ((p) & OFFS_REG_MASK) { \
716 			CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
717 			CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
718 			CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
719 			CHECK_ARGUMENT(!((i) & ~0x3)); \
720 		} \
721 		CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
722 	}
723 
724 #define FUNCTION_CHECK_DST(p, i) \
725 	CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
726 	if (FUNCTION_CHECK_IS_REG_OR_UNUSED(p)) \
727 		CHECK_ARGUMENT((i) == 0); \
728 	else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
729 		CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
730 	else { \
731 		CHECK_ARGUMENT((p) & SLJIT_MEM); \
732 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
733 		CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
734 		if ((p) & OFFS_REG_MASK) { \
735 			CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
736 			CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
737 			CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
738 			CHECK_ARGUMENT(!((i) & ~0x3)); \
739 		} \
740 		CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
741 	}
742 
743 #define FUNCTION_FCHECK(p, i) \
744 	CHECK_ARGUMENT(compiler->fscratches != -1 && compiler->fsaveds != -1); \
745 	if (((p) >= SLJIT_FR0 && (p) < (SLJIT_FR0 + compiler->fscratches)) || \
746 			((p) > (SLJIT_FS0 - compiler->fsaveds) && (p) <= SLJIT_FS0)) \
747 		CHECK_ARGUMENT(i == 0); \
748 	else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
749 		CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
750 	else { \
751 		CHECK_ARGUMENT((p) & SLJIT_MEM); \
752 		CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
753 		CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
754 		if ((p) & OFFS_REG_MASK) { \
755 			CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
756 			CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
757 			CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
758 			CHECK_ARGUMENT(((p) & OFFS_REG_MASK) != TO_OFFS_REG(SLJIT_SP) && !(i & ~0x3)); \
759 		} \
760 		CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
761 	}
762 
763 #define FUNCTION_CHECK_OP1() \
764 	if (GET_OPCODE(op) >= SLJIT_MOVU && GET_OPCODE(op) <= SLJIT_MOVU_P) { \
765 		CHECK_ARGUMENT(!(src & SLJIT_MEM) || (src & REG_MASK) != SLJIT_SP); \
766 		CHECK_ARGUMENT(!(dst & SLJIT_MEM) || (dst & REG_MASK) != SLJIT_SP); \
767 		if ((src & SLJIT_MEM) && (src & REG_MASK)) \
768 			CHECK_ARGUMENT((dst & REG_MASK) != (src & REG_MASK) && OFFS_REG(dst) != (src & REG_MASK)); \
769 	}
770 
771 #endif /* SLJIT_ARGUMENT_CHECKS */
772 
773 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
774 
sljit_compiler_verbose(struct sljit_compiler * compiler,FILE * verbose)775 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
776 {
777 	compiler->verbose = verbose;
778 }
779 
780 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
781 #ifdef _WIN64
782 #	define SLJIT_PRINT_D	"I64"
783 #else
784 #	define SLJIT_PRINT_D	"l"
785 #endif
786 #else
787 #	define SLJIT_PRINT_D	""
788 #endif
789 
790 #define sljit_verbose_reg(compiler, r) \
791 	do { \
792 		if ((r) < (SLJIT_R0 + compiler->scratches)) \
793 			fprintf(compiler->verbose, "r%d", (r) - SLJIT_R0); \
794 		else \
795 			fprintf(compiler->verbose, "s%d", SLJIT_NUMBER_OF_REGISTERS - (r)); \
796 	} while (0)
797 
798 #define sljit_verbose_param(compiler, p, i) \
799 	if ((p) & SLJIT_IMM) \
800 		fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i)); \
801 	else if ((p) & SLJIT_MEM) { \
802 		if ((p) & REG_MASK) { \
803 			fputc('[', compiler->verbose); \
804 			sljit_verbose_reg(compiler, (p) & REG_MASK); \
805 			if ((p) & OFFS_REG_MASK) { \
806 				fprintf(compiler->verbose, " + "); \
807 				sljit_verbose_reg(compiler, OFFS_REG(p)); \
808 				if (i) \
809 					fprintf(compiler->verbose, " * %d", 1 << (i)); \
810 			} \
811 			else if (i) \
812 				fprintf(compiler->verbose, " + %" SLJIT_PRINT_D "d", (i)); \
813 			fputc(']', compiler->verbose); \
814 		} \
815 		else \
816 			fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
817 	} else if (p) \
818 		sljit_verbose_reg(compiler, p); \
819 	else \
820 		fprintf(compiler->verbose, "unused");
821 
822 #define sljit_verbose_fparam(compiler, p, i) \
823 	if ((p) & SLJIT_MEM) { \
824 		if ((p) & REG_MASK) { \
825 			fputc('[', compiler->verbose); \
826 			sljit_verbose_reg(compiler, (p) & REG_MASK); \
827 			if ((p) & OFFS_REG_MASK) { \
828 				fprintf(compiler->verbose, " + "); \
829 				sljit_verbose_reg(compiler, OFFS_REG(p)); \
830 				if (i) \
831 					fprintf(compiler->verbose, "%d", 1 << (i)); \
832 			} \
833 			else if (i) \
834 				fprintf(compiler->verbose, "%" SLJIT_PRINT_D "d", (i)); \
835 			fputc(']', compiler->verbose); \
836 		} \
837 		else \
838 			fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
839 	} \
840 	else { \
841 		if ((p) < (SLJIT_FR0 + compiler->fscratches)) \
842 			fprintf(compiler->verbose, "fr%d", (p) - SLJIT_FR0); \
843 		else \
844 			fprintf(compiler->verbose, "fs%d", SLJIT_NUMBER_OF_FLOAT_REGISTERS - (p)); \
845 	}
846 
847 static SLJIT_CONST char* op0_names[] = {
848 	(char*)"breakpoint", (char*)"nop", (char*)"lumul", (char*)"lsmul",
849 	(char*)"udivmod", (char*)"sdivmod", (char*)"udivi", (char*)"sdivi"
850 };
851 
852 static SLJIT_CONST char* op1_names[] = {
853 	(char*)"mov", (char*)"mov_ub", (char*)"mov_sb", (char*)"mov_uh",
854 	(char*)"mov_sh", (char*)"mov_ui", (char*)"mov_si", (char*)"mov_p",
855 	(char*)"movu", (char*)"movu_ub", (char*)"movu_sb", (char*)"movu_uh",
856 	(char*)"movu_sh", (char*)"movu_ui", (char*)"movu_si", (char*)"movu_p",
857 	(char*)"not", (char*)"neg", (char*)"clz",
858 };
859 
860 static SLJIT_CONST char* op2_names[] = {
861 	(char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
862 	(char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
863 	(char*)"shl", (char*)"lshr", (char*)"ashr",
864 };
865 
866 static SLJIT_CONST char* fop1_names[] = {
867 	(char*)"mov", (char*)"conv", (char*)"conv", (char*)"conv",
868 	(char*)"conv", (char*)"conv", (char*)"cmp", (char*)"neg",
869 	(char*)"abs",
870 };
871 
872 static SLJIT_CONST char* fop2_names[] = {
873 	(char*)"add", (char*)"sub", (char*)"mul", (char*)"div"
874 };
875 
876 #define JUMP_PREFIX(type) \
877 	((type & 0xff) <= SLJIT_MUL_NOT_OVERFLOW ? ((type & SLJIT_INT_OP) ? "i_" : "") \
878 	: ((type & 0xff) <= SLJIT_D_ORDERED ? ((type & SLJIT_SINGLE_OP) ? "s_" : "d_") : ""))
879 
880 static char* jump_names[] = {
881 	(char*)"equal", (char*)"not_equal",
882 	(char*)"less", (char*)"greater_equal",
883 	(char*)"greater", (char*)"less_equal",
884 	(char*)"sig_less", (char*)"sig_greater_equal",
885 	(char*)"sig_greater", (char*)"sig_less_equal",
886 	(char*)"overflow", (char*)"not_overflow",
887 	(char*)"mul_overflow", (char*)"mul_not_overflow",
888 	(char*)"equal", (char*)"not_equal",
889 	(char*)"less", (char*)"greater_equal",
890 	(char*)"greater", (char*)"less_equal",
891 	(char*)"unordered", (char*)"ordered",
892 	(char*)"jump", (char*)"fast_call",
893 	(char*)"call0", (char*)"call1", (char*)"call2", (char*)"call3"
894 };
895 
896 #endif /* SLJIT_VERBOSE */
897 
898 /* --------------------------------------------------------------------- */
899 /*  Arch dependent                                                       */
900 /* --------------------------------------------------------------------- */
901 
902 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
903 	|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
904 
check_sljit_generate_code(struct sljit_compiler * compiler)905 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_generate_code(struct sljit_compiler *compiler)
906 {
907 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
908 	struct sljit_jump *jump;
909 #endif
910 
911 	SLJIT_UNUSED_ARG(compiler);
912 
913 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
914 	CHECK_ARGUMENT(compiler->size > 0);
915 	jump = compiler->jumps;
916 	while (jump) {
917 		/* All jumps have target. */
918 		CHECK_ARGUMENT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
919 		jump = jump->next;
920 	}
921 #endif
922 	CHECK_RETURN_OK;
923 }
924 
check_sljit_emit_enter(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)925 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_enter(struct sljit_compiler *compiler,
926 	sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
927 	sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
928 {
929 	SLJIT_UNUSED_ARG(compiler);
930 
931 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
932 	CHECK_ARGUMENT(!(options & ~SLJIT_DOUBLE_ALIGNMENT));
933 	CHECK_ARGUMENT(args >= 0 && args <= 3);
934 	CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
935 	CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
936 	CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
937 	CHECK_ARGUMENT(args <= saveds);
938 	CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
939 	CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
940 	CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
941 	CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
942 #endif
943 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
944 	if (SLJIT_UNLIKELY(!!compiler->verbose))
945 		fprintf(compiler->verbose, "  enter options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
946 			args, scratches, saveds, fscratches, fsaveds, local_size);
947 #endif
948 	CHECK_RETURN_OK;
949 }
950 
check_sljit_set_context(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)951 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_set_context(struct sljit_compiler *compiler,
952 	sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
953 	sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
954 {
955 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
956 		compiler->skip_checks = 0;
957 		CHECK_RETURN_OK;
958 	}
959 
960 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
961 	CHECK_ARGUMENT(!(options & ~SLJIT_DOUBLE_ALIGNMENT));
962 	CHECK_ARGUMENT(args >= 0 && args <= 3);
963 	CHECK_ARGUMENT(scratches >= 0 && scratches <= SLJIT_NUMBER_OF_REGISTERS);
964 	CHECK_ARGUMENT(saveds >= 0 && saveds <= SLJIT_NUMBER_OF_REGISTERS);
965 	CHECK_ARGUMENT(scratches + saveds <= SLJIT_NUMBER_OF_REGISTERS);
966 	CHECK_ARGUMENT(args <= saveds);
967 	CHECK_ARGUMENT(fscratches >= 0 && fscratches <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
968 	CHECK_ARGUMENT(fsaveds >= 0 && fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
969 	CHECK_ARGUMENT(fscratches + fsaveds <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
970 	CHECK_ARGUMENT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
971 #endif
972 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
973 	if (SLJIT_UNLIKELY(!!compiler->verbose))
974 		fprintf(compiler->verbose, "  set_context options:none args:%d scratches:%d saveds:%d fscratches:%d fsaveds:%d local_size:%d\n",
975 			args, scratches, saveds, fscratches, fsaveds, local_size);
976 #endif
977 	CHECK_RETURN_OK;
978 }
979 
check_sljit_emit_return(struct sljit_compiler * compiler,sljit_si op,sljit_si src,sljit_sw srcw)980 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
981 {
982 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
983 	CHECK_ARGUMENT(compiler->scratches >= 0);
984 	if (op != SLJIT_UNUSED) {
985 		CHECK_ARGUMENT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
986 		FUNCTION_CHECK_SRC(src, srcw);
987 	}
988 	else
989 		CHECK_ARGUMENT(src == 0 && srcw == 0);
990 #endif
991 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
992 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
993 		if (op == SLJIT_UNUSED)
994 			fprintf(compiler->verbose, "  return\n");
995 		else {
996 			fprintf(compiler->verbose, "  return.%s ", op1_names[op - SLJIT_OP1_BASE]);
997 			sljit_verbose_param(compiler, src, srcw);
998 			fprintf(compiler->verbose, "\n");
999 		}
1000 	}
1001 #endif
1002 	CHECK_RETURN_OK;
1003 }
1004 
check_sljit_emit_fast_enter(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw)1005 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1006 {
1007 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1008 	FUNCTION_CHECK_DST(dst, dstw);
1009 #endif
1010 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1011 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1012 		fprintf(compiler->verbose, "  fast_enter ");
1013 		sljit_verbose_param(compiler, dst, dstw);
1014 		fprintf(compiler->verbose, "\n");
1015 	}
1016 #endif
1017 	CHECK_RETURN_OK;
1018 }
1019 
check_sljit_emit_fast_return(struct sljit_compiler * compiler,sljit_si src,sljit_sw srcw)1020 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1021 {
1022 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1023 	FUNCTION_CHECK_SRC(src, srcw);
1024 #endif
1025 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1026 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1027 		fprintf(compiler->verbose, "  fast_return ");
1028 		sljit_verbose_param(compiler, src, srcw);
1029 		fprintf(compiler->verbose, "\n");
1030 	}
1031 #endif
1032 	CHECK_RETURN_OK;
1033 }
1034 
check_sljit_emit_op0(struct sljit_compiler * compiler,sljit_si op)1035 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1036 {
1037 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1038 	CHECK_ARGUMENT((op >= SLJIT_BREAKPOINT && op <= SLJIT_LSMUL)
1039 		|| ((op & ~SLJIT_INT_OP) >= SLJIT_UDIVMOD && (op & ~SLJIT_INT_OP) <= SLJIT_SDIVI));
1040 	CHECK_ARGUMENT(op < SLJIT_LUMUL || compiler->scratches >= 2);
1041 #endif
1042 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1043 	if (SLJIT_UNLIKELY(!!compiler->verbose))
1044 		fprintf(compiler->verbose, "  %s%s\n", !(op & SLJIT_INT_OP) ? "" : "i", op0_names[GET_OPCODE(op) - SLJIT_OP0_BASE]);
1045 #endif
1046 	CHECK_RETURN_OK;
1047 }
1048 
check_sljit_emit_op1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1049 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1050 	sljit_si dst, sljit_sw dstw,
1051 	sljit_si src, sljit_sw srcw)
1052 {
1053 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1054 		compiler->skip_checks = 0;
1055 		CHECK_RETURN_OK;
1056 	}
1057 
1058 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1059 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
1060 	FUNCTION_CHECK_OP();
1061 	FUNCTION_CHECK_SRC(src, srcw);
1062 	FUNCTION_CHECK_DST(dst, dstw);
1063 	FUNCTION_CHECK_OP1();
1064 #endif
1065 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1066 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1067 		fprintf(compiler->verbose, "  %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE],
1068 			!(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_U) ? "" : ".u", !(op & SLJIT_SET_S) ? "" : ".s",
1069 			!(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1070 		sljit_verbose_param(compiler, dst, dstw);
1071 		fprintf(compiler->verbose, ", ");
1072 		sljit_verbose_param(compiler, src, srcw);
1073 		fprintf(compiler->verbose, "\n");
1074 	}
1075 #endif
1076 	CHECK_RETURN_OK;
1077 }
1078 
check_sljit_emit_op2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1079 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1080 	sljit_si dst, sljit_sw dstw,
1081 	sljit_si src1, sljit_sw src1w,
1082 	sljit_si src2, sljit_sw src2w)
1083 {
1084 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1085 		compiler->skip_checks = 0;
1086 		CHECK_RETURN_OK;
1087 	}
1088 
1089 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1090 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1091 	FUNCTION_CHECK_OP();
1092 	FUNCTION_CHECK_SRC(src1, src1w);
1093 	FUNCTION_CHECK_SRC(src2, src2w);
1094 	FUNCTION_CHECK_DST(dst, dstw);
1095 #endif
1096 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1097 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1098 		fprintf(compiler->verbose, "  %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1099 			!(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_U) ? "" : ".u", !(op & SLJIT_SET_S) ? "" : ".s",
1100 			!(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1101 		sljit_verbose_param(compiler, dst, dstw);
1102 		fprintf(compiler->verbose, ", ");
1103 		sljit_verbose_param(compiler, src1, src1w);
1104 		fprintf(compiler->verbose, ", ");
1105 		sljit_verbose_param(compiler, src2, src2w);
1106 		fprintf(compiler->verbose, "\n");
1107 	}
1108 #endif
1109 	CHECK_RETURN_OK;
1110 }
1111 
check_sljit_get_register_index(sljit_si reg)1112 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_si reg)
1113 {
1114 	SLJIT_UNUSED_ARG(reg);
1115 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1116 	CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1117 #endif
1118 	CHECK_RETURN_OK;
1119 }
1120 
check_sljit_get_float_register_index(sljit_si reg)1121 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_si reg)
1122 {
1123 	SLJIT_UNUSED_ARG(reg);
1124 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1125 	CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1126 #endif
1127 	CHECK_RETURN_OK;
1128 }
1129 
check_sljit_emit_op_custom(struct sljit_compiler * compiler,void * instruction,sljit_si size)1130 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1131 	void *instruction, sljit_si size)
1132 {
1133 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1134 	int i;
1135 #endif
1136 
1137 	SLJIT_UNUSED_ARG(compiler);
1138 
1139 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1140 	CHECK_ARGUMENT(instruction);
1141 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1142 	CHECK_ARGUMENT(size > 0 && size < 16);
1143 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1144 	CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1145 		|| (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1146 #else
1147 	CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1148 #endif
1149 
1150 #endif
1151 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1152 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1153 		fprintf(compiler->verbose, "  op_custom");
1154 		for (i = 0; i < size; i++)
1155 			fprintf(compiler->verbose, " 0x%x", ((sljit_ub*)instruction)[i]);
1156 		fprintf(compiler->verbose, "\n");
1157 	}
1158 #endif
1159 	CHECK_RETURN_OK;
1160 }
1161 
check_sljit_emit_fop1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1162 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1163 	sljit_si dst, sljit_sw dstw,
1164 	sljit_si src, sljit_sw srcw)
1165 {
1166 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1167 		compiler->skip_checks = 0;
1168 		CHECK_RETURN_OK;
1169 	}
1170 
1171 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1172 	CHECK_ARGUMENT(sljit_is_fpu_available());
1173 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_DMOV && GET_OPCODE(op) <= SLJIT_DABS);
1174 	FUNCTION_CHECK_FOP();
1175 	FUNCTION_FCHECK(src, srcw);
1176 	FUNCTION_FCHECK(dst, dstw);
1177 #endif
1178 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1179 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1180 		if (GET_OPCODE(op) == SLJIT_CONVD_FROMS)
1181 			fprintf(compiler->verbose, "  %s%s ", fop1_names[SLJIT_CONVD_FROMS - SLJIT_FOP1_BASE],
1182 				(op & SLJIT_SINGLE_OP) ? "s.fromd" : "d.froms");
1183 		else
1184 			fprintf(compiler->verbose, "  %s%s ", (op & SLJIT_SINGLE_OP) ? "s" : "d",
1185 				fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE]);
1186 
1187 		sljit_verbose_fparam(compiler, dst, dstw);
1188 		fprintf(compiler->verbose, ", ");
1189 		sljit_verbose_fparam(compiler, src, srcw);
1190 		fprintf(compiler->verbose, "\n");
1191 	}
1192 #endif
1193 	CHECK_RETURN_OK;
1194 }
1195 
check_sljit_emit_fop1_cmp(struct sljit_compiler * compiler,sljit_si op,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1196 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_si op,
1197 	sljit_si src1, sljit_sw src1w,
1198 	sljit_si src2, sljit_sw src2w)
1199 {
1200 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1201 		compiler->skip_checks = 0;
1202 		CHECK_RETURN_OK;
1203 	}
1204 
1205 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1206 	CHECK_ARGUMENT(sljit_is_fpu_available());
1207 	CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_DCMP);
1208 	FUNCTION_CHECK_FOP();
1209 	FUNCTION_FCHECK(src1, src1w);
1210 	FUNCTION_FCHECK(src2, src2w);
1211 #endif
1212 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1213 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1214 		fprintf(compiler->verbose, "  %s%s%s%s ", (op & SLJIT_SINGLE_OP) ? "s" : "d", fop1_names[SLJIT_DCMP - SLJIT_FOP1_BASE],
1215 			(op & SLJIT_SET_E) ? ".e" : "", (op & SLJIT_SET_S) ? ".s" : "");
1216 		sljit_verbose_fparam(compiler, src1, src1w);
1217 		fprintf(compiler->verbose, ", ");
1218 		sljit_verbose_fparam(compiler, src2, src2w);
1219 		fprintf(compiler->verbose, "\n");
1220 	}
1221 #endif
1222 	CHECK_RETURN_OK;
1223 }
1224 
check_sljit_emit_fop1_convw_fromd(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1225 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_convw_fromd(struct sljit_compiler *compiler, sljit_si op,
1226 	sljit_si dst, sljit_sw dstw,
1227 	sljit_si src, sljit_sw srcw)
1228 {
1229 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1230 		compiler->skip_checks = 0;
1231 		CHECK_RETURN_OK;
1232 	}
1233 
1234 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1235 	CHECK_ARGUMENT(sljit_is_fpu_available());
1236 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONVW_FROMD && GET_OPCODE(op) <= SLJIT_CONVI_FROMD);
1237 	FUNCTION_CHECK_FOP();
1238 	FUNCTION_FCHECK(src, srcw);
1239 	FUNCTION_CHECK_DST(dst, dstw);
1240 #endif
1241 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1242 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1243 		fprintf(compiler->verbose, "  %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1244 			(GET_OPCODE(op) == SLJIT_CONVI_FROMD) ? "i" : "w",
1245 			(op & SLJIT_SINGLE_OP) ? "s" : "d");
1246 		sljit_verbose_param(compiler, dst, dstw);
1247 		fprintf(compiler->verbose, ", ");
1248 		sljit_verbose_fparam(compiler, src, srcw);
1249 		fprintf(compiler->verbose, "\n");
1250 	}
1251 #endif
1252 	CHECK_RETURN_OK;
1253 }
1254 
check_sljit_emit_fop1_convd_fromw(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1255 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_convd_fromw(struct sljit_compiler *compiler, sljit_si op,
1256 	sljit_si dst, sljit_sw dstw,
1257 	sljit_si src, sljit_sw srcw)
1258 {
1259 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1260 		compiler->skip_checks = 0;
1261 		CHECK_RETURN_OK;
1262 	}
1263 
1264 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1265 	CHECK_ARGUMENT(sljit_is_fpu_available());
1266 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONVD_FROMW && GET_OPCODE(op) <= SLJIT_CONVD_FROMI);
1267 	FUNCTION_CHECK_FOP();
1268 	FUNCTION_CHECK_SRC(src, srcw);
1269 	FUNCTION_FCHECK(dst, dstw);
1270 #endif
1271 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1272 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1273 		fprintf(compiler->verbose, "  %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1274 			(op & SLJIT_SINGLE_OP) ? "s" : "d",
1275 			(GET_OPCODE(op) == SLJIT_CONVD_FROMI) ? "i" : "w");
1276 		sljit_verbose_fparam(compiler, dst, dstw);
1277 		fprintf(compiler->verbose, ", ");
1278 		sljit_verbose_param(compiler, src, srcw);
1279 		fprintf(compiler->verbose, "\n");
1280 	}
1281 #endif
1282 	CHECK_RETURN_OK;
1283 }
1284 
check_sljit_emit_fop2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1285 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1286 	sljit_si dst, sljit_sw dstw,
1287 	sljit_si src1, sljit_sw src1w,
1288 	sljit_si src2, sljit_sw src2w)
1289 {
1290 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1291 	CHECK_ARGUMENT(sljit_is_fpu_available());
1292 	CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_DADD && GET_OPCODE(op) <= SLJIT_DDIV);
1293 	FUNCTION_CHECK_FOP();
1294 	FUNCTION_FCHECK(src1, src1w);
1295 	FUNCTION_FCHECK(src2, src2w);
1296 	FUNCTION_FCHECK(dst, dstw);
1297 #endif
1298 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1299 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1300 		fprintf(compiler->verbose, "  %s%s ", (op & SLJIT_SINGLE_OP) ? "s" : "d", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE]);
1301 		sljit_verbose_fparam(compiler, dst, dstw);
1302 		fprintf(compiler->verbose, ", ");
1303 		sljit_verbose_fparam(compiler, src1, src1w);
1304 		fprintf(compiler->verbose, ", ");
1305 		sljit_verbose_fparam(compiler, src2, src2w);
1306 		fprintf(compiler->verbose, "\n");
1307 	}
1308 #endif
1309 	CHECK_RETURN_OK;
1310 }
1311 
check_sljit_emit_label(struct sljit_compiler * compiler)1312 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1313 {
1314 	SLJIT_UNUSED_ARG(compiler);
1315 
1316 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1317 	if (SLJIT_UNLIKELY(!!compiler->verbose))
1318 		fprintf(compiler->verbose, "label:\n");
1319 #endif
1320 	CHECK_RETURN_OK;
1321 }
1322 
check_sljit_emit_jump(struct sljit_compiler * compiler,sljit_si type)1323 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1324 {
1325 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1326 		compiler->skip_checks = 0;
1327 		CHECK_RETURN_OK;
1328 	}
1329 
1330 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1331 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_INT_OP)));
1332 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_CALL3);
1333 	CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_INT_OP));
1334 	CHECK_ARGUMENT((type & 0xff) <= SLJIT_CALL0 || ((type & 0xff) - SLJIT_CALL0) <= compiler->scratches);
1335 #endif
1336 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1337 	if (SLJIT_UNLIKELY(!!compiler->verbose))
1338 		fprintf(compiler->verbose, "  jump%s.%s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1339 			JUMP_PREFIX(type), jump_names[type & 0xff]);
1340 #endif
1341 	CHECK_RETURN_OK;
1342 }
1343 
check_sljit_emit_cmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1344 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1345 	sljit_si src1, sljit_sw src1w,
1346 	sljit_si src2, sljit_sw src2w)
1347 {
1348 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1349 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_INT_OP)));
1350 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1351 	FUNCTION_CHECK_SRC(src1, src1w);
1352 	FUNCTION_CHECK_SRC(src2, src2w);
1353 #endif
1354 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1355 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1356 		fprintf(compiler->verbose, "  cmp%s.%s%s ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1357 			(type & SLJIT_INT_OP) ? "i_" : "", jump_names[type & 0xff]);
1358 		sljit_verbose_param(compiler, src1, src1w);
1359 		fprintf(compiler->verbose, ", ");
1360 		sljit_verbose_param(compiler, src2, src2w);
1361 		fprintf(compiler->verbose, "\n");
1362 	}
1363 #endif
1364 	CHECK_RETURN_OK;
1365 }
1366 
check_sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1367 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1368 	sljit_si src1, sljit_sw src1w,
1369 	sljit_si src2, sljit_sw src2w)
1370 {
1371 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1372 	CHECK_ARGUMENT(sljit_is_fpu_available());
1373 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_SINGLE_OP)));
1374 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_D_EQUAL && (type & 0xff) <= SLJIT_D_ORDERED);
1375 	FUNCTION_FCHECK(src1, src1w);
1376 	FUNCTION_FCHECK(src2, src2w);
1377 #endif
1378 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1379 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1380 		fprintf(compiler->verbose, "  fcmp%s.%s%s ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1381 			(type & SLJIT_SINGLE_OP) ? "s_" : "d_", jump_names[type & 0xff]);
1382 		sljit_verbose_fparam(compiler, src1, src1w);
1383 		fprintf(compiler->verbose, ", ");
1384 		sljit_verbose_fparam(compiler, src2, src2w);
1385 		fprintf(compiler->verbose, "\n");
1386 	}
1387 #endif
1388 	CHECK_RETURN_OK;
1389 }
1390 
check_sljit_emit_ijump(struct sljit_compiler * compiler,sljit_si type,sljit_si src,sljit_sw srcw)1391 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1392 {
1393 	if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1394 		compiler->skip_checks = 0;
1395 		CHECK_RETURN_OK;
1396 	}
1397 
1398 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1399 	CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1400 	CHECK_ARGUMENT(type <= SLJIT_CALL0 || (type - SLJIT_CALL0) <= compiler->scratches);
1401 	FUNCTION_CHECK_SRC(src, srcw);
1402 #endif
1403 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1404 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1405 		fprintf(compiler->verbose, "  ijump.%s ", jump_names[type]);
1406 		sljit_verbose_param(compiler, src, srcw);
1407 		fprintf(compiler->verbose, "\n");
1408 	}
1409 #endif
1410 	CHECK_RETURN_OK;
1411 }
1412 
check_sljit_emit_op_flags(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw,sljit_si type)1413 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1414 	sljit_si dst, sljit_sw dstw,
1415 	sljit_si src, sljit_sw srcw,
1416 	sljit_si type)
1417 {
1418 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1419 	CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_INT_OP)));
1420 	CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_D_ORDERED);
1421 	CHECK_ARGUMENT(op == SLJIT_MOV || GET_OPCODE(op) == SLJIT_MOV_UI || GET_OPCODE(op) == SLJIT_MOV_SI
1422 		|| (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1423 	CHECK_ARGUMENT((op & (SLJIT_SET_U | SLJIT_SET_S | SLJIT_SET_O | SLJIT_SET_C)) == 0);
1424 	CHECK_ARGUMENT((op & (SLJIT_SET_E | SLJIT_KEEP_FLAGS)) != (SLJIT_SET_E | SLJIT_KEEP_FLAGS));
1425 	if (GET_OPCODE(op) < SLJIT_ADD) {
1426 		CHECK_ARGUMENT(src == SLJIT_UNUSED && srcw == 0);
1427 	} else {
1428 		CHECK_ARGUMENT(src == dst && srcw == dstw);
1429 	}
1430 	FUNCTION_CHECK_DST(dst, dstw);
1431 #endif
1432 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1433 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1434 		fprintf(compiler->verbose, "  flags.%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i",
1435 			GET_OPCODE(op) >= SLJIT_OP2_BASE ? op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE] : op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE],
1436 			!(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1437 		sljit_verbose_param(compiler, dst, dstw);
1438 		if (src != SLJIT_UNUSED) {
1439 			fprintf(compiler->verbose, ", ");
1440 			sljit_verbose_param(compiler, src, srcw);
1441 		}
1442 		fprintf(compiler->verbose, ", %s%s\n", JUMP_PREFIX(type), jump_names[type & 0xff]);
1443 	}
1444 #endif
1445 	CHECK_RETURN_OK;
1446 }
1447 
check_sljit_get_local_base(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw offset)1448 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1449 {
1450 	SLJIT_UNUSED_ARG(offset);
1451 
1452 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1453 	FUNCTION_CHECK_DST(dst, dstw);
1454 #endif
1455 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1456 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1457 		fprintf(compiler->verbose, "  local_base ");
1458 		sljit_verbose_param(compiler, dst, dstw);
1459 		fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1460 	}
1461 #endif
1462 	CHECK_RETURN_OK;
1463 }
1464 
check_sljit_emit_const(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw init_value)1465 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value)
1466 {
1467 	SLJIT_UNUSED_ARG(init_value);
1468 
1469 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1470 	FUNCTION_CHECK_DST(dst, dstw);
1471 #endif
1472 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1473 	if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1474 		fprintf(compiler->verbose, "  const ");
1475 		sljit_verbose_param(compiler, dst, dstw);
1476 		fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1477 	}
1478 #endif
1479 	CHECK_RETURN_OK;
1480 }
1481 
1482 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
1483 
1484 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
1485 	SLJIT_COMPILE_ASSERT(!(SLJIT_CONVW_FROMD & 0x1) && !(SLJIT_CONVD_FROMW & 0x1), \
1486 		invalid_float_opcodes); \
1487 	if (GET_OPCODE(op) >= SLJIT_CONVW_FROMD && GET_OPCODE(op) <= SLJIT_DCMP) { \
1488 		if (GET_OPCODE(op) == SLJIT_DCMP) { \
1489 			CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
1490 			ADJUST_LOCAL_OFFSET(dst, dstw); \
1491 			ADJUST_LOCAL_OFFSET(src, srcw); \
1492 			return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
1493 		} \
1494 		if ((GET_OPCODE(op) | 0x1) == SLJIT_CONVI_FROMD) { \
1495 			CHECK(check_sljit_emit_fop1_convw_fromd(compiler, op, dst, dstw, src, srcw)); \
1496 			ADJUST_LOCAL_OFFSET(dst, dstw); \
1497 			ADJUST_LOCAL_OFFSET(src, srcw); \
1498 			return sljit_emit_fop1_convw_fromd(compiler, op, dst, dstw, src, srcw); \
1499 		} \
1500 		CHECK(check_sljit_emit_fop1_convd_fromw(compiler, op, dst, dstw, src, srcw)); \
1501 		ADJUST_LOCAL_OFFSET(dst, dstw); \
1502 		ADJUST_LOCAL_OFFSET(src, srcw); \
1503 		return sljit_emit_fop1_convd_fromw(compiler, op, dst, dstw, src, srcw); \
1504 	} \
1505 	CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
1506 	ADJUST_LOCAL_OFFSET(dst, dstw); \
1507 	ADJUST_LOCAL_OFFSET(src, srcw);
1508 
emit_mov_before_return(struct sljit_compiler * compiler,sljit_si op,sljit_si src,sljit_sw srcw)1509 static SLJIT_INLINE sljit_si emit_mov_before_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1510 {
1511 	/* Return if don't need to do anything. */
1512 	if (op == SLJIT_UNUSED)
1513 		return SLJIT_SUCCESS;
1514 
1515 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1516 	/* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1517 	if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1518 		return SLJIT_SUCCESS;
1519 #else
1520 	if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_UI || op == SLJIT_MOV_SI || op == SLJIT_MOV_P))
1521 		return SLJIT_SUCCESS;
1522 #endif
1523 
1524 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1525 		|| (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1526 	compiler->skip_checks = 1;
1527 #endif
1528 	return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1529 }
1530 
1531 /* CPU description section */
1532 
1533 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1534 #define SLJIT_CPUINFO_PART1 " 32bit ("
1535 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1536 #define SLJIT_CPUINFO_PART1 " 64bit ("
1537 #else
1538 #error "Internal error: CPU type info missing"
1539 #endif
1540 
1541 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1542 #define SLJIT_CPUINFO_PART2 "little endian + "
1543 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1544 #define SLJIT_CPUINFO_PART2 "big endian + "
1545 #else
1546 #error "Internal error: CPU type info missing"
1547 #endif
1548 
1549 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
1550 #define SLJIT_CPUINFO_PART3 "unaligned)"
1551 #else
1552 #define SLJIT_CPUINFO_PART3 "aligned)"
1553 #endif
1554 
1555 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
1556 
1557 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1558 #	include "sljitNativeX86_common.c"
1559 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1560 #	include "sljitNativeARM_32.c"
1561 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1562 #	include "sljitNativeARM_32.c"
1563 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1564 #	include "sljitNativeARM_T2_32.c"
1565 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1566 #	include "sljitNativeARM_64.c"
1567 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
1568 #	include "sljitNativePPC_common.c"
1569 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1570 #	include "sljitNativeMIPS_common.c"
1571 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
1572 #	include "sljitNativeSPARC_common.c"
1573 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
1574 #	include "sljitNativeTILEGX_64.c"
1575 #endif
1576 
1577 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1578 
sljit_emit_cmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1579 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1580 	sljit_si src1, sljit_sw src1w,
1581 	sljit_si src2, sljit_sw src2w)
1582 {
1583 	/* Default compare for most architectures. */
1584 	sljit_si flags, tmp_src, condition;
1585 	sljit_sw tmp_srcw;
1586 
1587 	CHECK_ERROR_PTR();
1588 	CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
1589 
1590 	condition = type & 0xff;
1591 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1592 	if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
1593 		if ((src1 & SLJIT_IMM) && !src1w) {
1594 			src1 = src2;
1595 			src1w = src2w;
1596 			src2 = SLJIT_IMM;
1597 			src2w = 0;
1598 		}
1599 		if ((src2 & SLJIT_IMM) && !src2w)
1600 			return emit_cmp_to0(compiler, type, src1, src1w);
1601 	}
1602 #endif
1603 
1604 	if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1605 		/* Immediate is prefered as second argument by most architectures. */
1606 		switch (condition) {
1607 		case SLJIT_LESS:
1608 			condition = SLJIT_GREATER;
1609 			break;
1610 		case SLJIT_GREATER_EQUAL:
1611 			condition = SLJIT_LESS_EQUAL;
1612 			break;
1613 		case SLJIT_GREATER:
1614 			condition = SLJIT_LESS;
1615 			break;
1616 		case SLJIT_LESS_EQUAL:
1617 			condition = SLJIT_GREATER_EQUAL;
1618 			break;
1619 		case SLJIT_SIG_LESS:
1620 			condition = SLJIT_SIG_GREATER;
1621 			break;
1622 		case SLJIT_SIG_GREATER_EQUAL:
1623 			condition = SLJIT_SIG_LESS_EQUAL;
1624 			break;
1625 		case SLJIT_SIG_GREATER:
1626 			condition = SLJIT_SIG_LESS;
1627 			break;
1628 		case SLJIT_SIG_LESS_EQUAL:
1629 			condition = SLJIT_SIG_GREATER_EQUAL;
1630 			break;
1631 		}
1632 		type = condition | (type & (SLJIT_INT_OP | SLJIT_REWRITABLE_JUMP));
1633 		tmp_src = src1;
1634 		src1 = src2;
1635 		src2 = tmp_src;
1636 		tmp_srcw = src1w;
1637 		src1w = src2w;
1638 		src2w = tmp_srcw;
1639 	}
1640 
1641 	if (condition <= SLJIT_NOT_ZERO)
1642 		flags = SLJIT_SET_E;
1643 	else if (condition <= SLJIT_LESS_EQUAL)
1644 		flags = SLJIT_SET_U;
1645 	else
1646 		flags = SLJIT_SET_S;
1647 
1648 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1649 		|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1650 	compiler->skip_checks = 1;
1651 #endif
1652 	PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_INT_OP),
1653 		SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1654 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1655 		|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1656 	compiler->skip_checks = 1;
1657 #endif
1658 	return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1659 }
1660 
sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1661 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1662 	sljit_si src1, sljit_sw src1w,
1663 	sljit_si src2, sljit_sw src2w)
1664 {
1665 	sljit_si flags, condition;
1666 
1667 	CHECK_ERROR_PTR();
1668 	CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
1669 
1670 	condition = type & 0xff;
1671 	flags = (condition <= SLJIT_D_NOT_EQUAL) ? SLJIT_SET_E : SLJIT_SET_S;
1672 	if (type & SLJIT_SINGLE_OP)
1673 		flags |= SLJIT_SINGLE_OP;
1674 
1675 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1676 		|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1677 	compiler->skip_checks = 1;
1678 #endif
1679 	sljit_emit_fop1(compiler, SLJIT_DCMP | flags, src1, src1w, src2, src2w);
1680 
1681 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1682 		|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1683 	compiler->skip_checks = 1;
1684 #endif
1685 	return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1686 }
1687 
1688 #endif
1689 
1690 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1691 
sljit_get_local_base(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw offset)1692 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1693 {
1694 	CHECK_ERROR();
1695 	CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
1696 
1697 	ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
1698 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1699 		|| (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1700 	compiler->skip_checks = 1;
1701 #endif
1702 	if (offset != 0)
1703 		return sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
1704 	return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
1705 }
1706 
1707 #endif
1708 
1709 #else /* SLJIT_CONFIG_UNSUPPORTED */
1710 
1711 /* Empty function bodies for those machines, which are not (yet) supported. */
1712 
sljit_get_platform_name(void)1713 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
1714 {
1715 	return "unsupported";
1716 }
1717 
sljit_create_compiler(void)1718 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
1719 {
1720 	SLJIT_ASSERT_STOP();
1721 	return NULL;
1722 }
1723 
sljit_free_compiler(struct sljit_compiler * compiler)1724 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
1725 {
1726 	SLJIT_UNUSED_ARG(compiler);
1727 	SLJIT_ASSERT_STOP();
1728 }
1729 
sljit_alloc_memory(struct sljit_compiler * compiler,sljit_si size)1730 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
1731 {
1732 	SLJIT_UNUSED_ARG(compiler);
1733 	SLJIT_UNUSED_ARG(size);
1734 	SLJIT_ASSERT_STOP();
1735 	return NULL;
1736 }
1737 
1738 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
sljit_compiler_verbose(struct sljit_compiler * compiler,FILE * verbose)1739 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1740 {
1741 	SLJIT_UNUSED_ARG(compiler);
1742 	SLJIT_UNUSED_ARG(verbose);
1743 	SLJIT_ASSERT_STOP();
1744 }
1745 #endif
1746 
sljit_generate_code(struct sljit_compiler * compiler)1747 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
1748 {
1749 	SLJIT_UNUSED_ARG(compiler);
1750 	SLJIT_ASSERT_STOP();
1751 	return NULL;
1752 }
1753 
sljit_free_code(void * code)1754 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
1755 {
1756 	SLJIT_UNUSED_ARG(code);
1757 	SLJIT_ASSERT_STOP();
1758 }
1759 
sljit_emit_enter(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)1760 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_enter(struct sljit_compiler *compiler,
1761 	sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
1762 	sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
1763 {
1764 	SLJIT_UNUSED_ARG(compiler);
1765 	SLJIT_UNUSED_ARG(options);
1766 	SLJIT_UNUSED_ARG(args);
1767 	SLJIT_UNUSED_ARG(scratches);
1768 	SLJIT_UNUSED_ARG(saveds);
1769 	SLJIT_UNUSED_ARG(fscratches);
1770 	SLJIT_UNUSED_ARG(fsaveds);
1771 	SLJIT_UNUSED_ARG(local_size);
1772 	SLJIT_ASSERT_STOP();
1773 	return SLJIT_ERR_UNSUPPORTED;
1774 }
1775 
sljit_set_context(struct sljit_compiler * compiler,sljit_si options,sljit_si args,sljit_si scratches,sljit_si saveds,sljit_si fscratches,sljit_si fsaveds,sljit_si local_size)1776 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_set_context(struct sljit_compiler *compiler,
1777 	sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
1778 	sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
1779 {
1780 	SLJIT_UNUSED_ARG(compiler);
1781 	SLJIT_UNUSED_ARG(options);
1782 	SLJIT_UNUSED_ARG(args);
1783 	SLJIT_UNUSED_ARG(scratches);
1784 	SLJIT_UNUSED_ARG(saveds);
1785 	SLJIT_UNUSED_ARG(fscratches);
1786 	SLJIT_UNUSED_ARG(fsaveds);
1787 	SLJIT_UNUSED_ARG(local_size);
1788 	SLJIT_ASSERT_STOP();
1789 	return SLJIT_ERR_UNSUPPORTED;
1790 }
1791 
sljit_emit_return(struct sljit_compiler * compiler,sljit_si op,sljit_si src,sljit_sw srcw)1792 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1793 {
1794 	SLJIT_UNUSED_ARG(compiler);
1795 	SLJIT_UNUSED_ARG(op);
1796 	SLJIT_UNUSED_ARG(src);
1797 	SLJIT_UNUSED_ARG(srcw);
1798 	SLJIT_ASSERT_STOP();
1799 	return SLJIT_ERR_UNSUPPORTED;
1800 }
1801 
sljit_emit_fast_enter(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw)1802 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1803 {
1804 	SLJIT_UNUSED_ARG(compiler);
1805 	SLJIT_UNUSED_ARG(dst);
1806 	SLJIT_UNUSED_ARG(dstw);
1807 	SLJIT_ASSERT_STOP();
1808 	return SLJIT_ERR_UNSUPPORTED;
1809 }
1810 
sljit_emit_fast_return(struct sljit_compiler * compiler,sljit_si src,sljit_sw srcw)1811 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1812 {
1813 	SLJIT_UNUSED_ARG(compiler);
1814 	SLJIT_UNUSED_ARG(src);
1815 	SLJIT_UNUSED_ARG(srcw);
1816 	SLJIT_ASSERT_STOP();
1817 	return SLJIT_ERR_UNSUPPORTED;
1818 }
1819 
sljit_emit_op0(struct sljit_compiler * compiler,sljit_si op)1820 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1821 {
1822 	SLJIT_UNUSED_ARG(compiler);
1823 	SLJIT_UNUSED_ARG(op);
1824 	SLJIT_ASSERT_STOP();
1825 	return SLJIT_ERR_UNSUPPORTED;
1826 }
1827 
sljit_emit_op1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1828 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1829 	sljit_si dst, sljit_sw dstw,
1830 	sljit_si src, sljit_sw srcw)
1831 {
1832 	SLJIT_UNUSED_ARG(compiler);
1833 	SLJIT_UNUSED_ARG(op);
1834 	SLJIT_UNUSED_ARG(dst);
1835 	SLJIT_UNUSED_ARG(dstw);
1836 	SLJIT_UNUSED_ARG(src);
1837 	SLJIT_UNUSED_ARG(srcw);
1838 	SLJIT_ASSERT_STOP();
1839 	return SLJIT_ERR_UNSUPPORTED;
1840 }
1841 
sljit_emit_op2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1842 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1843 	sljit_si dst, sljit_sw dstw,
1844 	sljit_si src1, sljit_sw src1w,
1845 	sljit_si src2, sljit_sw src2w)
1846 {
1847 	SLJIT_UNUSED_ARG(compiler);
1848 	SLJIT_UNUSED_ARG(op);
1849 	SLJIT_UNUSED_ARG(dst);
1850 	SLJIT_UNUSED_ARG(dstw);
1851 	SLJIT_UNUSED_ARG(src1);
1852 	SLJIT_UNUSED_ARG(src1w);
1853 	SLJIT_UNUSED_ARG(src2);
1854 	SLJIT_UNUSED_ARG(src2w);
1855 	SLJIT_ASSERT_STOP();
1856 	return SLJIT_ERR_UNSUPPORTED;
1857 }
1858 
sljit_get_register_index(sljit_si reg)1859 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg)
1860 {
1861 	SLJIT_ASSERT_STOP();
1862 	return reg;
1863 }
1864 
sljit_emit_op_custom(struct sljit_compiler * compiler,void * instruction,sljit_si size)1865 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
1866 	void *instruction, sljit_si size)
1867 {
1868 	SLJIT_UNUSED_ARG(compiler);
1869 	SLJIT_UNUSED_ARG(instruction);
1870 	SLJIT_UNUSED_ARG(size);
1871 	SLJIT_ASSERT_STOP();
1872 	return SLJIT_ERR_UNSUPPORTED;
1873 }
1874 
sljit_is_fpu_available(void)1875 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void)
1876 {
1877 	SLJIT_ASSERT_STOP();
1878 	return 0;
1879 }
1880 
sljit_emit_fop1(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw)1881 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1882 	sljit_si dst, sljit_sw dstw,
1883 	sljit_si src, sljit_sw srcw)
1884 {
1885 	SLJIT_UNUSED_ARG(compiler);
1886 	SLJIT_UNUSED_ARG(op);
1887 	SLJIT_UNUSED_ARG(dst);
1888 	SLJIT_UNUSED_ARG(dstw);
1889 	SLJIT_UNUSED_ARG(src);
1890 	SLJIT_UNUSED_ARG(srcw);
1891 	SLJIT_ASSERT_STOP();
1892 	return SLJIT_ERR_UNSUPPORTED;
1893 }
1894 
sljit_emit_fop2(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1895 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1896 	sljit_si dst, sljit_sw dstw,
1897 	sljit_si src1, sljit_sw src1w,
1898 	sljit_si src2, sljit_sw src2w)
1899 {
1900 	SLJIT_UNUSED_ARG(compiler);
1901 	SLJIT_UNUSED_ARG(op);
1902 	SLJIT_UNUSED_ARG(dst);
1903 	SLJIT_UNUSED_ARG(dstw);
1904 	SLJIT_UNUSED_ARG(src1);
1905 	SLJIT_UNUSED_ARG(src1w);
1906 	SLJIT_UNUSED_ARG(src2);
1907 	SLJIT_UNUSED_ARG(src2w);
1908 	SLJIT_ASSERT_STOP();
1909 	return SLJIT_ERR_UNSUPPORTED;
1910 }
1911 
sljit_emit_label(struct sljit_compiler * compiler)1912 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1913 {
1914 	SLJIT_UNUSED_ARG(compiler);
1915 	SLJIT_ASSERT_STOP();
1916 	return NULL;
1917 }
1918 
sljit_emit_jump(struct sljit_compiler * compiler,sljit_si type)1919 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1920 {
1921 	SLJIT_UNUSED_ARG(compiler);
1922 	SLJIT_UNUSED_ARG(type);
1923 	SLJIT_ASSERT_STOP();
1924 	return NULL;
1925 }
1926 
sljit_emit_cmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1927 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1928 	sljit_si src1, sljit_sw src1w,
1929 	sljit_si src2, sljit_sw src2w)
1930 {
1931 	SLJIT_UNUSED_ARG(compiler);
1932 	SLJIT_UNUSED_ARG(type);
1933 	SLJIT_UNUSED_ARG(src1);
1934 	SLJIT_UNUSED_ARG(src1w);
1935 	SLJIT_UNUSED_ARG(src2);
1936 	SLJIT_UNUSED_ARG(src2w);
1937 	SLJIT_ASSERT_STOP();
1938 	return NULL;
1939 }
1940 
sljit_emit_fcmp(struct sljit_compiler * compiler,sljit_si type,sljit_si src1,sljit_sw src1w,sljit_si src2,sljit_sw src2w)1941 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1942 	sljit_si src1, sljit_sw src1w,
1943 	sljit_si src2, sljit_sw src2w)
1944 {
1945 	SLJIT_UNUSED_ARG(compiler);
1946 	SLJIT_UNUSED_ARG(type);
1947 	SLJIT_UNUSED_ARG(src1);
1948 	SLJIT_UNUSED_ARG(src1w);
1949 	SLJIT_UNUSED_ARG(src2);
1950 	SLJIT_UNUSED_ARG(src2w);
1951 	SLJIT_ASSERT_STOP();
1952 	return NULL;
1953 }
1954 
sljit_set_label(struct sljit_jump * jump,struct sljit_label * label)1955 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
1956 {
1957 	SLJIT_UNUSED_ARG(jump);
1958 	SLJIT_UNUSED_ARG(label);
1959 	SLJIT_ASSERT_STOP();
1960 }
1961 
sljit_set_target(struct sljit_jump * jump,sljit_uw target)1962 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
1963 {
1964 	SLJIT_UNUSED_ARG(jump);
1965 	SLJIT_UNUSED_ARG(target);
1966 	SLJIT_ASSERT_STOP();
1967 }
1968 
sljit_emit_ijump(struct sljit_compiler * compiler,sljit_si type,sljit_si src,sljit_sw srcw)1969 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1970 {
1971 	SLJIT_UNUSED_ARG(compiler);
1972 	SLJIT_UNUSED_ARG(type);
1973 	SLJIT_UNUSED_ARG(src);
1974 	SLJIT_UNUSED_ARG(srcw);
1975 	SLJIT_ASSERT_STOP();
1976 	return SLJIT_ERR_UNSUPPORTED;
1977 }
1978 
sljit_emit_op_flags(struct sljit_compiler * compiler,sljit_si op,sljit_si dst,sljit_sw dstw,sljit_si src,sljit_sw srcw,sljit_si type)1979 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1980 	sljit_si dst, sljit_sw dstw,
1981 	sljit_si src, sljit_sw srcw,
1982 	sljit_si type)
1983 {
1984 	SLJIT_UNUSED_ARG(compiler);
1985 	SLJIT_UNUSED_ARG(op);
1986 	SLJIT_UNUSED_ARG(dst);
1987 	SLJIT_UNUSED_ARG(dstw);
1988 	SLJIT_UNUSED_ARG(src);
1989 	SLJIT_UNUSED_ARG(srcw);
1990 	SLJIT_UNUSED_ARG(type);
1991 	SLJIT_ASSERT_STOP();
1992 	return SLJIT_ERR_UNSUPPORTED;
1993 }
1994 
sljit_get_local_base(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw offset)1995 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1996 {
1997 	SLJIT_UNUSED_ARG(compiler);
1998 	SLJIT_UNUSED_ARG(dst);
1999 	SLJIT_UNUSED_ARG(dstw);
2000 	SLJIT_UNUSED_ARG(offset);
2001 	SLJIT_ASSERT_STOP();
2002 	return SLJIT_ERR_UNSUPPORTED;
2003 }
2004 
sljit_emit_const(struct sljit_compiler * compiler,sljit_si dst,sljit_sw dstw,sljit_sw initval)2005 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw initval)
2006 {
2007 	SLJIT_UNUSED_ARG(compiler);
2008 	SLJIT_UNUSED_ARG(dst);
2009 	SLJIT_UNUSED_ARG(dstw);
2010 	SLJIT_UNUSED_ARG(initval);
2011 	SLJIT_ASSERT_STOP();
2012 	return NULL;
2013 }
2014 
sljit_set_jump_addr(sljit_uw addr,sljit_uw new_addr)2015 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
2016 {
2017 	SLJIT_UNUSED_ARG(addr);
2018 	SLJIT_UNUSED_ARG(new_addr);
2019 	SLJIT_ASSERT_STOP();
2020 }
2021 
sljit_set_const(sljit_uw addr,sljit_sw new_constant)2022 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant)
2023 {
2024 	SLJIT_UNUSED_ARG(addr);
2025 	SLJIT_UNUSED_ARG(new_constant);
2026 	SLJIT_ASSERT_STOP();
2027 }
2028 
2029 #endif
2030