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