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