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