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