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