/[pcre]/code/trunk/sljit/sljitLir.c
ViewVC logotype

Contents of /code/trunk/sljit/sljitLir.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1709 - (show annotations)
Tue Aug 1 08:29:13 2017 UTC (2 years, 1 month ago) by zherczeg
File MIME type: text/plain
File size: 71392 byte(s)
Minor JIT compiler update.
1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #include "sljitLir.h"
28
29 #if !(defined SLJIT_STD_MACROS_DEFINED && SLJIT_STD_MACROS_DEFINED)
30
31 /* These libraries are needed for the macros below. */
32 #include <stdlib.h>
33 #include <string.h>
34
35 #endif /* SLJIT_STD_MACROS_DEFINED */
36
37 #define CHECK_ERROR() \
38 do { \
39 if (SLJIT_UNLIKELY(compiler->error)) \
40 return compiler->error; \
41 } while (0)
42
43 #define CHECK_ERROR_PTR() \
44 do { \
45 if (SLJIT_UNLIKELY(compiler->error)) \
46 return NULL; \
47 } while (0)
48
49 #define FAIL_IF(expr) \
50 do { \
51 if (SLJIT_UNLIKELY(expr)) \
52 return compiler->error; \
53 } while (0)
54
55 #define PTR_FAIL_IF(expr) \
56 do { \
57 if (SLJIT_UNLIKELY(expr)) \
58 return NULL; \
59 } while (0)
60
61 #define FAIL_IF_NULL(ptr) \
62 do { \
63 if (SLJIT_UNLIKELY(!(ptr))) { \
64 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
65 return SLJIT_ERR_ALLOC_FAILED; \
66 } \
67 } while (0)
68
69 #define PTR_FAIL_IF_NULL(ptr) \
70 do { \
71 if (SLJIT_UNLIKELY(!(ptr))) { \
72 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
73 return NULL; \
74 } \
75 } while (0)
76
77 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
78 do { \
79 if (SLJIT_UNLIKELY(!(ptr))) { \
80 compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
81 return NULL; \
82 } \
83 } while (0)
84
85 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
86
87 #define VARIABLE_FLAG_SHIFT (10)
88 #define VARIABLE_FLAG_MASK (0x3f << VARIABLE_FLAG_SHIFT)
89 #define GET_FLAG_TYPE(op) ((op) >> VARIABLE_FLAG_SHIFT)
90
91 #define GET_OPCODE(op) \
92 ((op) & ~(SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
93
94 #define HAS_FLAGS(op) \
95 ((op) & (SLJIT_SET_Z | VARIABLE_FLAG_MASK))
96
97 #define GET_ALL_FLAGS(op) \
98 ((op) & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK))
99
100 #define TYPE_CAST_NEEDED(op) \
101 (((op) >= SLJIT_MOV_U8 && (op) <= SLJIT_MOV_S16) || ((op) >= SLJIT_MOVU_U8 && (op) <= SLJIT_MOVU_S16))
102
103 #define BUF_SIZE 4096
104
105 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
106 #define ABUF_SIZE 2048
107 #else
108 #define ABUF_SIZE 4096
109 #endif
110
111 /* Parameter parsing. */
112 #define REG_MASK 0x3f
113 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
114 #define OFFS_REG_MASK (REG_MASK << 8)
115 #define TO_OFFS_REG(reg) ((reg) << 8)
116 /* When reg cannot be unused. */
117 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
118 /* When reg can be unused. */
119 #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK)
120
121 /* Jump flags. */
122 #define JUMP_LABEL 0x1
123 #define JUMP_ADDR 0x2
124 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
125
126 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
127 # define PATCH_MB 0x4
128 # define PATCH_MW 0x8
129 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
130 # define PATCH_MD 0x10
131 #endif
132 #endif
133
134 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
135 # define IS_BL 0x4
136 # define PATCH_B 0x8
137 #endif
138
139 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
140 # define CPOOL_SIZE 512
141 #endif
142
143 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
144 # define IS_COND 0x04
145 # define IS_BL 0x08
146 /* conditional + imm8 */
147 # define PATCH_TYPE1 0x10
148 /* conditional + imm20 */
149 # define PATCH_TYPE2 0x20
150 /* IT + imm24 */
151 # define PATCH_TYPE3 0x30
152 /* imm11 */
153 # define PATCH_TYPE4 0x40
154 /* imm24 */
155 # define PATCH_TYPE5 0x50
156 /* BL + imm24 */
157 # define PATCH_BL 0x60
158 /* 0xf00 cc code for branches */
159 #endif
160
161 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
162 # define IS_COND 0x004
163 # define IS_CBZ 0x008
164 # define IS_BL 0x010
165 # define PATCH_B 0x020
166 # define PATCH_COND 0x040
167 # define PATCH_ABS48 0x080
168 # define PATCH_ABS64 0x100
169 #endif
170
171 #if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
172 # define IS_COND 0x004
173 # define IS_CALL 0x008
174 # define PATCH_B 0x010
175 # define PATCH_ABS_B 0x020
176 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
177 # define PATCH_ABS32 0x040
178 # define PATCH_ABS48 0x080
179 #endif
180 # define REMOVE_COND 0x100
181 #endif
182
183 #if (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
184 # define IS_MOVABLE 0x004
185 # define IS_JAL 0x008
186 # define IS_CALL 0x010
187 # define IS_BIT26_COND 0x020
188 # define IS_BIT16_COND 0x040
189
190 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
191
192 # define PATCH_B 0x080
193 # define PATCH_J 0x100
194
195 #if (defined SLJIT_CONFIG_MIPS_64 && SLJIT_CONFIG_MIPS_64)
196 # define PATCH_ABS32 0x200
197 # define PATCH_ABS48 0x400
198 #endif
199
200 /* instruction types */
201 # define MOVABLE_INS 0
202 /* 1 - 31 last destination register */
203 /* no destination (i.e: store) */
204 # define UNMOVABLE_INS 32
205 /* FPU status register */
206 # define FCSR_FCC 33
207 #endif
208
209 #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
210 # define IS_JAL 0x04
211 # define IS_COND 0x08
212
213 # define PATCH_B 0x10
214 # define PATCH_J 0x20
215 #endif
216
217 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
218 # define IS_MOVABLE 0x04
219 # define IS_COND 0x08
220 # define IS_CALL 0x10
221
222 # define PATCH_B 0x20
223 # define PATCH_CALL 0x40
224
225 /* instruction types */
226 # define MOVABLE_INS 0
227 /* 1 - 31 last destination register */
228 /* no destination (i.e: store) */
229 # define UNMOVABLE_INS 32
230
231 # define DST_INS_MASK 0xff
232
233 /* ICC_SET is the same as SET_FLAGS. */
234 # define ICC_IS_SET (1 << 23)
235 # define FCC_IS_SET (1 << 24)
236 #endif
237
238 /* Stack management. */
239
240 #define GET_SAVED_REGISTERS_SIZE(scratches, saveds, extra) \
241 (((scratches < SLJIT_NUMBER_OF_SCRATCH_REGISTERS ? 0 : (scratches - SLJIT_NUMBER_OF_SCRATCH_REGISTERS)) + \
242 (saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? saveds : SLJIT_NUMBER_OF_SAVED_REGISTERS) + \
243 extra) * sizeof(sljit_sw))
244
245 #define ADJUST_LOCAL_OFFSET(p, i) \
246 if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
247 (i) += SLJIT_LOCALS_OFFSET;
248
249 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
250
251 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
252 #include "sljitUtils.c"
253
254 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
255
256 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
257
258 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
259 #include "sljitProtExecAllocator.c"
260 #else
261 #include "sljitExecAllocator.c"
262 #endif
263
264 #endif
265
266 #if (defined SLJIT_PROT_EXECUTABLE_ALLOCATOR && SLJIT_PROT_EXECUTABLE_ALLOCATOR)
267 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr) + (exec_offset))
268 #else
269 #define SLJIT_ADD_EXEC_OFFSET(ptr, exec_offset) ((sljit_u8 *)(ptr))
270 #endif
271
272 /* Argument checking features. */
273
274 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
275
276 /* Returns with error when an invalid argument is passed. */
277
278 #define CHECK_ARGUMENT(x) \
279 do { \
280 if (SLJIT_UNLIKELY(!(x))) \
281 return 1; \
282 } while (0)
283
284 #define CHECK_RETURN_TYPE sljit_s32
285 #define CHECK_RETURN_OK return 0
286
287 #define CHECK(x) \
288 do { \
289 if (SLJIT_UNLIKELY(x)) { \
290 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
291 return SLJIT_ERR_BAD_ARGUMENT; \
292 } \
293 } while (0)
294
295 #define CHECK_PTR(x) \
296 do { \
297 if (SLJIT_UNLIKELY(x)) { \
298 compiler->error = SLJIT_ERR_BAD_ARGUMENT; \
299 return NULL; \
300 } \
301 } while (0)
302
303 #define CHECK_REG_INDEX(x) \
304 do { \
305 if (SLJIT_UNLIKELY(x)) { \
306 return -2; \
307 } \
308 } while (0)
309
310 #elif (defined SLJIT_DEBUG && SLJIT_DEBUG)
311
312 /* Assertion failure occures if an invalid argument is passed. */
313 #undef SLJIT_ARGUMENT_CHECKS
314 #define SLJIT_ARGUMENT_CHECKS 1
315
316 #define CHECK_ARGUMENT(x) SLJIT_ASSERT(x)
317 #define CHECK_RETURN_TYPE void
318 #define CHECK_RETURN_OK return
319 #define CHECK(x) x
320 #define CHECK_PTR(x) x
321 #define CHECK_REG_INDEX(x) x
322
323 #elif (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
324
325 /* Arguments are not checked. */
326 #define CHECK_RETURN_TYPE void
327 #define CHECK_RETURN_OK return
328 #define CHECK(x) x
329 #define CHECK_PTR(x) x
330 #define CHECK_REG_INDEX(x) x
331
332 #else
333
334 /* Arguments are not checked. */
335 #define CHECK(x)
336 #define CHECK_PTR(x)
337 #define CHECK_REG_INDEX(x)
338
339 #endif /* SLJIT_ARGUMENT_CHECKS */
340
341 /* --------------------------------------------------------------------- */
342 /* Public functions */
343 /* --------------------------------------------------------------------- */
344
345 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
346 #define SLJIT_NEEDS_COMPILER_INIT 1
347 static sljit_s32 compiler_initialized = 0;
348 /* A thread safe initialization. */
349 static void init_compiler(void);
350 #endif
351
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 | REG_MASK | OFFS_REG_MASK))); \
701 }
702
703 #define FUNCTION_CHECK_DST(p, i, unused) \
704 CHECK_ARGUMENT(compiler->scratches != -1 && compiler->saveds != -1); \
705 if (FUNCTION_CHECK_IS_REG(p) || ((unused) && (p) == SLJIT_UNUSED)) \
706 CHECK_ARGUMENT((i) == 0); \
707 else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
708 CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
709 else { \
710 CHECK_ARGUMENT((p) & SLJIT_MEM); \
711 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
712 CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
713 if ((p) & OFFS_REG_MASK) { \
714 CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
715 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
716 CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
717 CHECK_ARGUMENT(!((i) & ~0x3)); \
718 } \
719 CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK))); \
720 }
721
722 #define FUNCTION_FCHECK(p, i) \
723 CHECK_ARGUMENT(compiler->fscratches != -1 && compiler->fsaveds != -1); \
724 if (((p) >= SLJIT_FR0 && (p) < (SLJIT_FR0 + compiler->fscratches)) || \
725 ((p) > (SLJIT_FS0 - compiler->fsaveds) && (p) <= SLJIT_FS0)) \
726 CHECK_ARGUMENT(i == 0); \
727 else if ((p) == (SLJIT_MEM1(SLJIT_SP))) \
728 CHECK_ARGUMENT((i) >= 0 && (i) < compiler->logical_local_size); \
729 else { \
730 CHECK_ARGUMENT((p) & SLJIT_MEM); \
731 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG_OR_UNUSED((p) & REG_MASK)); \
732 CHECK_NOT_VIRTUAL_REGISTER((p) & REG_MASK); \
733 if ((p) & OFFS_REG_MASK) { \
734 CHECK_ARGUMENT(((p) & REG_MASK) != SLJIT_UNUSED); \
735 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
736 CHECK_NOT_VIRTUAL_REGISTER(OFFS_REG(p)); \
737 CHECK_ARGUMENT(((p) & OFFS_REG_MASK) != TO_OFFS_REG(SLJIT_SP) && !(i & ~0x3)); \
738 } \
739 CHECK_ARGUMENT(!((p) & ~(SLJIT_MEM | REG_MASK | OFFS_REG_MASK))); \
740 }
741
742 #endif /* SLJIT_ARGUMENT_CHECKS */
743
744 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
745
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, 0);
981 compiler->last_flags = 0;
982 #endif
983 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
984 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
985 fprintf(compiler->verbose, " fast_enter ");
986 sljit_verbose_param(compiler, dst, dstw);
987 fprintf(compiler->verbose, "\n");
988 }
989 #endif
990 CHECK_RETURN_OK;
991 }
992
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 /* Only SLJIT_I32_OP and SLJIT_SET_Z are allowed. */
1046 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1047 break;
1048 case SLJIT_NEG:
1049 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1050 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1051 break;
1052 case SLJIT_MOV:
1053 case SLJIT_MOV_U32:
1054 case SLJIT_MOV_P:
1055 case SLJIT_MOVU:
1056 case SLJIT_MOVU_U32:
1057 case SLJIT_MOVU_P:
1058 /* Nothing allowed */
1059 CHECK_ARGUMENT(!(op & (SLJIT_I32_OP | SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1060 break;
1061 default:
1062 /* Only SLJIT_I32_OP is allowed. */
1063 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1064 break;
1065 }
1066
1067 FUNCTION_CHECK_DST(dst, dstw, 1);
1068 FUNCTION_CHECK_SRC(src, srcw);
1069
1070 if (GET_OPCODE(op) >= SLJIT_NOT)
1071 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1072 else if (GET_OPCODE(op) >= SLJIT_MOVU) {
1073 CHECK_ARGUMENT(!(src & SLJIT_MEM) || (src & REG_MASK) != SLJIT_SP);
1074 CHECK_ARGUMENT(!(dst & SLJIT_MEM) || (dst & REG_MASK) != SLJIT_SP);
1075 if ((src & REG_MASK) != SLJIT_UNUSED) {
1076 CHECK_ARGUMENT((src & REG_MASK) != (dst & REG_MASK) && (src & REG_MASK) != OFFS_REG(dst));
1077 CHECK_ARGUMENT((src & OFFS_REG_MASK) == SLJIT_UNUSED || srcw == 0);
1078 }
1079 if ((dst & REG_MASK) != SLJIT_UNUSED) {
1080 CHECK_ARGUMENT((dst & REG_MASK) != OFFS_REG(src));
1081 CHECK_ARGUMENT((dst & OFFS_REG_MASK) == SLJIT_UNUSED || dstw == 0);
1082 }
1083 compiler->last_flags = 0;
1084 }
1085 #endif
1086 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1087 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1088 if (GET_OPCODE(op) <= SLJIT_MOVU_P)
1089 {
1090 fprintf(compiler->verbose, " mov%s%s%s ", (GET_OPCODE(op) >= SLJIT_MOVU) ? "u" : "",
1091 !(op & SLJIT_I32_OP) ? "" : "32", (op != SLJIT_MOV32 && op != SLJIT_MOVU32) ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : "");
1092 }
1093 else
1094 {
1095 fprintf(compiler->verbose, " %s%s%s%s%s ", op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
1096 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1097 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1098 }
1099
1100 sljit_verbose_param(compiler, dst, dstw);
1101 fprintf(compiler->verbose, ", ");
1102 sljit_verbose_param(compiler, src, srcw);
1103 fprintf(compiler->verbose, "\n");
1104 }
1105 #endif
1106 CHECK_RETURN_OK;
1107 }
1108
1109 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
1110 sljit_s32 dst, sljit_sw dstw,
1111 sljit_s32 src1, sljit_sw src1w,
1112 sljit_s32 src2, sljit_sw src2w)
1113 {
1114 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1115 compiler->skip_checks = 0;
1116 CHECK_RETURN_OK;
1117 }
1118
1119 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1120 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1121
1122 switch (GET_OPCODE(op)) {
1123 case SLJIT_AND:
1124 case SLJIT_OR:
1125 case SLJIT_XOR:
1126 case SLJIT_SHL:
1127 case SLJIT_LSHR:
1128 case SLJIT_ASHR:
1129 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1130 break;
1131 case SLJIT_MUL:
1132 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1133 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1134 || GET_FLAG_TYPE(op) == SLJIT_MUL_OVERFLOW);
1135 break;
1136 case SLJIT_ADD:
1137 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1138 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY)
1139 || GET_FLAG_TYPE(op) == SLJIT_OVERFLOW);
1140 break;
1141 case SLJIT_SUB:
1142 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1143 || (GET_FLAG_TYPE(op) >= SLJIT_LESS && GET_FLAG_TYPE(op) <= SLJIT_OVERFLOW)
1144 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1145 break;
1146 case SLJIT_ADDC:
1147 case SLJIT_SUBC:
1148 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK)
1149 || GET_FLAG_TYPE(op) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1150 CHECK_ARGUMENT((compiler->last_flags & 0xff) == GET_FLAG_TYPE(SLJIT_SET_CARRY));
1151 CHECK_ARGUMENT((op & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
1152 break;
1153 default:
1154 SLJIT_UNREACHABLE();
1155 break;
1156 }
1157
1158 FUNCTION_CHECK_DST(dst, dstw, 1);
1159 FUNCTION_CHECK_SRC(src1, src1w);
1160 FUNCTION_CHECK_SRC(src2, src2w);
1161 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1162 #endif
1163 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1164 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1165 fprintf(compiler->verbose, " %s%s%s%s%s ", op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE], !(op & SLJIT_I32_OP) ? "" : "32",
1166 !(op & SLJIT_SET_Z) ? "" : ".z", !(op & VARIABLE_FLAG_MASK) ? "" : ".",
1167 !(op & VARIABLE_FLAG_MASK) ? "" : jump_names[GET_FLAG_TYPE(op)]);
1168 sljit_verbose_param(compiler, dst, dstw);
1169 fprintf(compiler->verbose, ", ");
1170 sljit_verbose_param(compiler, src1, src1w);
1171 fprintf(compiler->verbose, ", ");
1172 sljit_verbose_param(compiler, src2, src2w);
1173 fprintf(compiler->verbose, "\n");
1174 }
1175 #endif
1176 CHECK_RETURN_OK;
1177 }
1178
1179 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_register_index(sljit_s32 reg)
1180 {
1181 SLJIT_UNUSED_ARG(reg);
1182 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1183 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_REGISTERS);
1184 #endif
1185 CHECK_RETURN_OK;
1186 }
1187
1188 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_float_register_index(sljit_s32 reg)
1189 {
1190 SLJIT_UNUSED_ARG(reg);
1191 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1192 CHECK_ARGUMENT(reg > 0 && reg <= SLJIT_NUMBER_OF_FLOAT_REGISTERS);
1193 #endif
1194 CHECK_RETURN_OK;
1195 }
1196
1197 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1198 void *instruction, sljit_s32 size)
1199 {
1200 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1201 int i;
1202 #endif
1203
1204 SLJIT_UNUSED_ARG(compiler);
1205
1206 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1207 CHECK_ARGUMENT(instruction);
1208
1209 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1210 CHECK_ARGUMENT(size > 0 && size < 16);
1211 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1212 CHECK_ARGUMENT((size == 2 && (((sljit_sw)instruction) & 0x1) == 0)
1213 || (size == 4 && (((sljit_sw)instruction) & 0x3) == 0));
1214 #else
1215 CHECK_ARGUMENT(size == 4 && (((sljit_sw)instruction) & 0x3) == 0);
1216 #endif
1217
1218 compiler->last_flags = 0;
1219 #endif
1220 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1221 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1222 fprintf(compiler->verbose, " op_custom");
1223 for (i = 0; i < size; i++)
1224 fprintf(compiler->verbose, " 0x%x", ((sljit_u8*)instruction)[i]);
1225 fprintf(compiler->verbose, "\n");
1226 }
1227 #endif
1228 CHECK_RETURN_OK;
1229 }
1230
1231 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1232 sljit_s32 dst, sljit_sw dstw,
1233 sljit_s32 src, sljit_sw srcw)
1234 {
1235 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1236 compiler->skip_checks = 0;
1237 CHECK_RETURN_OK;
1238 }
1239
1240 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1241 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1242 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_MOV_F64 && GET_OPCODE(op) <= SLJIT_ABS_F64);
1243 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1244 FUNCTION_FCHECK(src, srcw);
1245 FUNCTION_FCHECK(dst, dstw);
1246 #endif
1247 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1248 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1249 if (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_F32)
1250 fprintf(compiler->verbose, " %s%s ", fop1_names[SLJIT_CONV_F64_FROM_F32 - SLJIT_FOP1_BASE],
1251 (op & SLJIT_F32_OP) ? ".f32.from.f64" : ".f64.from.f32");
1252 else
1253 fprintf(compiler->verbose, " %s%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1254 (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1255
1256 sljit_verbose_fparam(compiler, dst, dstw);
1257 fprintf(compiler->verbose, ", ");
1258 sljit_verbose_fparam(compiler, src, srcw);
1259 fprintf(compiler->verbose, "\n");
1260 }
1261 #endif
1262 CHECK_RETURN_OK;
1263 }
1264
1265 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1266 sljit_s32 src1, sljit_sw src1w,
1267 sljit_s32 src2, sljit_sw src2w)
1268 {
1269 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1270 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1271 #endif
1272
1273 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1274 compiler->skip_checks = 0;
1275 CHECK_RETURN_OK;
1276 }
1277
1278 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1279 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1280 CHECK_ARGUMENT(GET_OPCODE(op) == SLJIT_CMP_F64);
1281 CHECK_ARGUMENT(!(op & SLJIT_SET_Z));
1282 CHECK_ARGUMENT((op & VARIABLE_FLAG_MASK)
1283 || (GET_FLAG_TYPE(op) >= SLJIT_EQUAL_F64 && GET_FLAG_TYPE(op) <= SLJIT_ORDERED_F64));
1284 FUNCTION_FCHECK(src1, src1w);
1285 FUNCTION_FCHECK(src2, src2w);
1286 #endif
1287 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1288 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1289 fprintf(compiler->verbose, " %s%s", fop1_names[SLJIT_CMP_F64 - SLJIT_FOP1_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1290 if (op & VARIABLE_FLAG_MASK) {
1291 fprintf(compiler->verbose, ".%s_f", jump_names[GET_FLAG_TYPE(op)]);
1292 }
1293 fprintf(compiler->verbose, " ");
1294 sljit_verbose_fparam(compiler, src1, src1w);
1295 fprintf(compiler->verbose, ", ");
1296 sljit_verbose_fparam(compiler, src2, src2w);
1297 fprintf(compiler->verbose, "\n");
1298 }
1299 #endif
1300 CHECK_RETURN_OK;
1301 }
1302
1303 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1304 sljit_s32 dst, sljit_sw dstw,
1305 sljit_s32 src, sljit_sw srcw)
1306 {
1307 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1308 compiler->skip_checks = 0;
1309 CHECK_RETURN_OK;
1310 }
1311
1312 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1313 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1314 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CONV_S32_FROM_F64);
1315 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1316 FUNCTION_FCHECK(src, srcw);
1317 FUNCTION_CHECK_DST(dst, dstw, 0);
1318 #endif
1319 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1320 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1321 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1322 (GET_OPCODE(op) == SLJIT_CONV_S32_FROM_F64) ? ".s32" : ".sw",
1323 (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1324 sljit_verbose_param(compiler, dst, dstw);
1325 fprintf(compiler->verbose, ", ");
1326 sljit_verbose_fparam(compiler, src, srcw);
1327 fprintf(compiler->verbose, "\n");
1328 }
1329 #endif
1330 CHECK_RETURN_OK;
1331 }
1332
1333 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1334 sljit_s32 dst, sljit_sw dstw,
1335 sljit_s32 src, sljit_sw srcw)
1336 {
1337 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1338 compiler->skip_checks = 0;
1339 CHECK_RETURN_OK;
1340 }
1341
1342 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1343 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1344 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_CONV_F64_FROM_SW && GET_OPCODE(op) <= SLJIT_CONV_F64_FROM_S32);
1345 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1346 FUNCTION_CHECK_SRC(src, srcw);
1347 FUNCTION_FCHECK(dst, dstw);
1348 #endif
1349 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1350 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1351 fprintf(compiler->verbose, " %s%s.from%s ", fop1_names[GET_OPCODE(op) - SLJIT_FOP1_BASE],
1352 (op & SLJIT_F32_OP) ? ".f32" : ".f64",
1353 (GET_OPCODE(op) == SLJIT_CONV_F64_FROM_S32) ? ".s32" : ".sw");
1354 sljit_verbose_fparam(compiler, dst, dstw);
1355 fprintf(compiler->verbose, ", ");
1356 sljit_verbose_param(compiler, src, srcw);
1357 fprintf(compiler->verbose, "\n");
1358 }
1359 #endif
1360 CHECK_RETURN_OK;
1361 }
1362
1363 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1364 sljit_s32 dst, sljit_sw dstw,
1365 sljit_s32 src1, sljit_sw src1w,
1366 sljit_s32 src2, sljit_sw src2w)
1367 {
1368 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1369 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1370 CHECK_ARGUMENT(GET_OPCODE(op) >= SLJIT_ADD_F64 && GET_OPCODE(op) <= SLJIT_DIV_F64);
1371 CHECK_ARGUMENT(!(op & (SLJIT_SET_Z | VARIABLE_FLAG_MASK)));
1372 FUNCTION_FCHECK(src1, src1w);
1373 FUNCTION_FCHECK(src2, src2w);
1374 FUNCTION_FCHECK(dst, dstw);
1375 #endif
1376 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1377 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1378 fprintf(compiler->verbose, " %s%s ", fop2_names[GET_OPCODE(op) - SLJIT_FOP2_BASE], (op & SLJIT_F32_OP) ? ".f32" : ".f64");
1379 sljit_verbose_fparam(compiler, dst, dstw);
1380 fprintf(compiler->verbose, ", ");
1381 sljit_verbose_fparam(compiler, src1, src1w);
1382 fprintf(compiler->verbose, ", ");
1383 sljit_verbose_fparam(compiler, src2, src2w);
1384 fprintf(compiler->verbose, "\n");
1385 }
1386 #endif
1387 CHECK_RETURN_OK;
1388 }
1389
1390 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_label(struct sljit_compiler *compiler)
1391 {
1392 SLJIT_UNUSED_ARG(compiler);
1393
1394 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1395 compiler->skip_checks = 0;
1396 CHECK_RETURN_OK;
1397 }
1398
1399 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1400 compiler->last_flags = 0;
1401 #endif
1402
1403 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1404 if (SLJIT_UNLIKELY(!!compiler->verbose))
1405 fprintf(compiler->verbose, "label:\n");
1406 #endif
1407 CHECK_RETURN_OK;
1408 }
1409
1410 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1411 {
1412 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1413 compiler->skip_checks = 0;
1414 CHECK_RETURN_OK;
1415 }
1416
1417 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1418 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1419 CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1420 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_CALL3);
1421 CHECK_ARGUMENT((type & 0xff) < SLJIT_JUMP || !(type & SLJIT_I32_OP));
1422 CHECK_ARGUMENT((type & 0xff) <= SLJIT_CALL0 || ((type & 0xff) - SLJIT_CALL0) <= compiler->scratches);
1423
1424 if ((type & 0xff) < SLJIT_JUMP) {
1425 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1426 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1427 else
1428 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1429 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1430 || ((type & 0xff) == SLJIT_MUL_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_MUL_OVERFLOW));
1431 CHECK_ARGUMENT((type & SLJIT_I32_OP) == (compiler->last_flags & SLJIT_I32_OP));
1432 }
1433 #endif
1434 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1435 if (SLJIT_UNLIKELY(!!compiler->verbose))
1436 fprintf(compiler->verbose, " jump%s %s%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1437 jump_names[type & 0xff], JUMP_POSTFIX(type));
1438 #endif
1439 CHECK_RETURN_OK;
1440 }
1441
1442 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1443 sljit_s32 src1, sljit_sw src1w,
1444 sljit_s32 src2, sljit_sw src2w)
1445 {
1446 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1447 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1448 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_SIG_LESS_EQUAL);
1449 FUNCTION_CHECK_SRC(src1, src1w);
1450 FUNCTION_CHECK_SRC(src2, src2w);
1451 compiler->last_flags = 0;
1452 #endif
1453 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1454 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1455 fprintf(compiler->verbose, " cmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1456 jump_names[type & 0xff], (type & SLJIT_I32_OP) ? "32" : "");
1457 sljit_verbose_param(compiler, src1, src1w);
1458 fprintf(compiler->verbose, ", ");
1459 sljit_verbose_param(compiler, src2, src2w);
1460 fprintf(compiler->verbose, "\n");
1461 }
1462 #endif
1463 CHECK_RETURN_OK;
1464 }
1465
1466 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1467 sljit_s32 src1, sljit_sw src1w,
1468 sljit_s32 src2, sljit_sw src2w)
1469 {
1470 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1471 CHECK_ARGUMENT(sljit_has_cpu_feature(SLJIT_HAS_FPU));
1472 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_F32_OP)));
1473 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL_F64 && (type & 0xff) <= SLJIT_ORDERED_F64);
1474 FUNCTION_FCHECK(src1, src1w);
1475 FUNCTION_FCHECK(src2, src2w);
1476 compiler->last_flags = 0;
1477 #endif
1478 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1479 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1480 fprintf(compiler->verbose, " fcmp%s %s%s, ", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r",
1481 jump_names[type & 0xff], (type & SLJIT_F32_OP) ? ".f32" : ".f64");
1482 sljit_verbose_fparam(compiler, src1, src1w);
1483 fprintf(compiler->verbose, ", ");
1484 sljit_verbose_fparam(compiler, src2, src2w);
1485 fprintf(compiler->verbose, "\n");
1486 }
1487 #endif
1488 CHECK_RETURN_OK;
1489 }
1490
1491 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
1492 {
1493 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1494 compiler->last_flags = 0;
1495 #endif
1496
1497 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1498 compiler->skip_checks = 0;
1499 CHECK_RETURN_OK;
1500 }
1501
1502 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1503 CHECK_ARGUMENT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1504 CHECK_ARGUMENT(type <= SLJIT_CALL0 || (type - SLJIT_CALL0) <= compiler->scratches);
1505 FUNCTION_CHECK_SRC(src, srcw);
1506 #endif
1507 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1508 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1509 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1510 sljit_verbose_param(compiler, src, srcw);
1511 fprintf(compiler->verbose, "\n");
1512 }
1513 #endif
1514 CHECK_RETURN_OK;
1515 }
1516
1517 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1518 sljit_s32 dst, sljit_sw dstw,
1519 sljit_s32 type)
1520 {
1521 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1522 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
1523 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1524 CHECK_ARGUMENT((type & 0xff) != GET_FLAG_TYPE(SLJIT_SET_CARRY) && (type & 0xff) != (GET_FLAG_TYPE(SLJIT_SET_CARRY) + 1));
1525 CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV32
1526 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1527 CHECK_ARGUMENT(!(op & VARIABLE_FLAG_MASK));
1528
1529 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1530 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1531 else
1532 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1533 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1534 || ((type & 0xff) == SLJIT_MUL_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_MUL_OVERFLOW));
1535
1536 FUNCTION_CHECK_DST(dst, dstw, 0);
1537
1538 if (GET_OPCODE(op) >= SLJIT_ADD)
1539 compiler->last_flags = GET_FLAG_TYPE(op) | (op & (SLJIT_I32_OP | SLJIT_SET_Z));
1540 #endif
1541 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1542 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1543 fprintf(compiler->verbose, " flags%s %s%s, ",
1544 !(op & SLJIT_SET_Z) ? "" : ".z",
1545 GET_OPCODE(op) < SLJIT_OP2_BASE ? "mov" : op2_names[GET_OPCODE(op) - SLJIT_OP2_BASE],
1546 GET_OPCODE(op) < SLJIT_OP2_BASE ? op1_names[GET_OPCODE(op) - SLJIT_OP1_BASE] : ((op & SLJIT_I32_OP) ? "32" : ""));
1547 sljit_verbose_param(compiler, dst, dstw);
1548 fprintf(compiler->verbose, ", %s%s\n", jump_names[type & 0xff], JUMP_POSTFIX(type));
1549 }
1550 #endif
1551 CHECK_RETURN_OK;
1552 }
1553
1554 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
1555 sljit_s32 dst_reg,
1556 sljit_s32 src, sljit_sw srcw)
1557 {
1558 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1559 CHECK_ARGUMENT(!(type & ~(0xff | SLJIT_I32_OP)));
1560 CHECK_ARGUMENT((type & 0xff) >= SLJIT_EQUAL && (type & 0xff) <= SLJIT_ORDERED_F64);
1561 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(dst_reg & ~SLJIT_I32_OP));
1562 if (src != SLJIT_IMM) {
1563 CHECK_ARGUMENT(FUNCTION_CHECK_IS_REG(src));
1564 CHECK_ARGUMENT(srcw == 0);
1565 }
1566
1567 if ((type & 0xff) <= SLJIT_NOT_ZERO)
1568 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
1569 else
1570 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff)
1571 || ((type & 0xff) == SLJIT_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_OVERFLOW)
1572 || ((type & 0xff) == SLJIT_MUL_NOT_OVERFLOW && (compiler->last_flags & 0xff) == SLJIT_MUL_OVERFLOW));
1573 #endif
1574 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1575 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1576 fprintf(compiler->verbose, " cmov%s %s%s, ",
1577 !(dst_reg & SLJIT_I32_OP) ? "" : ".i",
1578 jump_names[type & 0xff], JUMP_POSTFIX(type));
1579 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_I32_OP);
1580 fprintf(compiler->verbose, ", ");
1581 sljit_verbose_param(compiler, src, srcw);
1582 fprintf(compiler->verbose, "\n");
1583 }
1584 #endif
1585 CHECK_RETURN_OK;
1586 }
1587
1588 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
1589 {
1590 /* Any offset is allowed. */
1591 SLJIT_UNUSED_ARG(offset);
1592
1593 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1594 FUNCTION_CHECK_DST(dst, dstw, 0);
1595 #endif
1596 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1597 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1598 fprintf(compiler->verbose, " local_base ");
1599 sljit_verbose_param(compiler, dst, dstw);
1600 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1601 }
1602 #endif
1603 CHECK_RETURN_OK;
1604 }
1605
1606 static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
1607 {
1608 SLJIT_UNUSED_ARG(init_value);
1609
1610 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1611 FUNCTION_CHECK_DST(dst, dstw, 0);
1612 #endif
1613 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1614 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1615 fprintf(compiler->verbose, " const ");
1616 sljit_verbose_param(compiler, dst, dstw);
1617 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1618 }
1619 #endif
1620 CHECK_RETURN_OK;
1621 }
1622
1623 #endif /* SLJIT_ARGUMENT_CHECKS || SLJIT_VERBOSE */
1624
1625 #define SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw) \
1626 SLJIT_COMPILE_ASSERT(!(SLJIT_CONV_SW_FROM_F64 & 0x1) && !(SLJIT_CONV_F64_FROM_SW & 0x1), \
1627 invalid_float_opcodes); \
1628 if (GET_OPCODE(op) >= SLJIT_CONV_SW_FROM_F64 && GET_OPCODE(op) <= SLJIT_CMP_F64) { \
1629 if (GET_OPCODE(op) == SLJIT_CMP_F64) { \
1630 CHECK(check_sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw)); \
1631 ADJUST_LOCAL_OFFSET(dst, dstw); \
1632 ADJUST_LOCAL_OFFSET(src, srcw); \
1633 return sljit_emit_fop1_cmp(compiler, op, dst, dstw, src, srcw); \
1634 } \
1635 if ((GET_OPCODE(op) | 0x1) == SLJIT_CONV_S32_FROM_F64) { \
1636 CHECK(check_sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw)); \
1637 ADJUST_LOCAL_OFFSET(dst, dstw); \
1638 ADJUST_LOCAL_OFFSET(src, srcw); \
1639 return sljit_emit_fop1_conv_sw_from_f64(compiler, op, dst, dstw, src, srcw); \
1640 } \
1641 CHECK(check_sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw)); \
1642 ADJUST_LOCAL_OFFSET(dst, dstw); \
1643 ADJUST_LOCAL_OFFSET(src, srcw); \
1644 return sljit_emit_fop1_conv_f64_from_sw(compiler, op, dst, dstw, src, srcw); \
1645 } \
1646 CHECK(check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw)); \
1647 ADJUST_LOCAL_OFFSET(dst, dstw); \
1648 ADJUST_LOCAL_OFFSET(src, srcw);
1649
1650 static SLJIT_INLINE sljit_s32 emit_mov_before_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1651 {
1652 /* Return if don't need to do anything. */
1653 if (op == SLJIT_UNUSED)
1654 return SLJIT_SUCCESS;
1655
1656 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1657 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1658 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1659 return SLJIT_SUCCESS;
1660 #else
1661 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_U32 || op == SLJIT_MOV_S32 || op == SLJIT_MOV_P))
1662 return SLJIT_SUCCESS;
1663 #endif
1664
1665 #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) \
1666 || (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1667 compiler->skip_checks = 1;
1668 #endif
1669 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1670 }
1671
1672 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) \
1673 || (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC) \
1674 || (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32) \
1675 || ((defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS) && !(defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1))
1676
1677 static SLJIT_INLINE sljit_s32 sljit_emit_cmov_generic(struct sljit_compiler *compiler, sljit_s32 type,
1678 sljit_s32 dst_reg,
1679 sljit_s32 src, sljit_sw srcw)
1680 {
1681 struct sljit_label *label;
1682 struct sljit_jump *jump;
1683 sljit_s32 op = (dst_reg & SLJIT_I32_OP) ? SLJIT_MOV32 : SLJIT_MOV;
1684
1685 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1686 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1687 compiler->skip_checks = 1;
1688 #endif
1689 jump = sljit_emit_jump(compiler, type ^ 0x1);
1690 FAIL_IF(!jump);
1691
1692 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1693 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1694 compiler->skip_checks = 1;
1695 #endif
1696 FAIL_IF(sljit_emit_op1(compiler, op, dst_reg & ~SLJIT_I32_OP, 0, src, srcw));
1697
1698 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1699 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1700 compiler->skip_checks = 1;
1701 #endif
1702 label = sljit_emit_label(compiler);
1703 FAIL_IF(!label);
1704 sljit_set_label(jump, label);
1705 return SLJIT_SUCCESS;
1706 }
1707
1708 #endif
1709
1710 /* CPU description section */
1711
1712 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1713 #define SLJIT_CPUINFO_PART1 " 32bit ("
1714 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1715 #define SLJIT_CPUINFO_PART1 " 64bit ("
1716 #else
1717 #error "Internal error: CPU type info missing"
1718 #endif
1719
1720 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1721 #define SLJIT_CPUINFO_PART2 "little endian + "
1722 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1723 #define SLJIT_CPUINFO_PART2 "big endian + "
1724 #else
1725 #error "Internal error: CPU type info missing"
1726 #endif
1727
1728 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
1729 #define SLJIT_CPUINFO_PART3 "unaligned)"
1730 #else
1731 #define SLJIT_CPUINFO_PART3 "aligned)"
1732 #endif
1733
1734 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
1735
1736 #if (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1737 # include "sljitNativeX86_common.c"
1738 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1739 # include "sljitNativeARM_32.c"
1740 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1741 # include "sljitNativeARM_32.c"
1742 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1743 # include "sljitNativeARM_T2_32.c"
1744 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1745 # include "sljitNativeARM_64.c"
1746 #elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
1747 # include "sljitNativePPC_common.c"
1748 #elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1749 # include "sljitNativeMIPS_common.c"
1750 #elif (defined SLJIT_CONFIG_SPARC && SLJIT_CONFIG_SPARC)
1751 # include "sljitNativeSPARC_common.c"
1752 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
1753 # include "sljitNativeTILEGX_64.c"
1754 #endif
1755
1756 #if !(defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
1757
1758 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
1759 sljit_s32 src1, sljit_sw src1w,
1760 sljit_s32 src2, sljit_sw src2w)
1761 {
1762 /* Default compare for most architectures. */
1763 sljit_s32 flags, tmp_src, condition;
1764 sljit_sw tmp_srcw;
1765
1766 CHECK_ERROR_PTR();
1767 CHECK_PTR(check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w));
1768
1769 condition = type & 0xff;
1770 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1771 if ((condition == SLJIT_EQUAL || condition == SLJIT_NOT_EQUAL)) {
1772 if ((src1 & SLJIT_IMM) && !src1w) {
1773 src1 = src2;
1774 src1w = src2w;
1775 src2 = SLJIT_IMM;
1776 src2w = 0;
1777 }
1778 if ((src2 & SLJIT_IMM) && !src2w)
1779 return emit_cmp_to0(compiler, type, src1, src1w);
1780 }
1781 #endif
1782
1783 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1784 /* Immediate is prefered as second argument by most architectures. */
1785 switch (condition) {
1786 case SLJIT_LESS:
1787 condition = SLJIT_GREATER;
1788 break;
1789 case SLJIT_GREATER_EQUAL:
1790 condition = SLJIT_LESS_EQUAL;
1791 break;
1792 case SLJIT_GREATER:
1793 condition = SLJIT_LESS;
1794 break;
1795 case SLJIT_LESS_EQUAL:
1796 condition = SLJIT_GREATER_EQUAL;
1797 break;
1798 case SLJIT_SIG_LESS:
1799 condition = SLJIT_SIG_GREATER;
1800 break;
1801 case SLJIT_SIG_GREATER_EQUAL:
1802 condition = SLJIT_SIG_LESS_EQUAL;
1803 break;
1804 case SLJIT_SIG_GREATER:
1805 condition = SLJIT_SIG_LESS;
1806 break;
1807 case SLJIT_SIG_LESS_EQUAL:
1808 condition = SLJIT_SIG_GREATER_EQUAL;
1809 break;
1810 }
1811
1812 type = condition | (type & (SLJIT_I32_OP | SLJIT_REWRITABLE_JUMP));
1813 tmp_src = src1;
1814 src1 = src2;
1815 src2 = tmp_src;
1816 tmp_srcw = src1w;
1817 src1w = src2w;
1818 src2w = tmp_srcw;
1819 }
1820
1821 if (condition <= SLJIT_NOT_ZERO)
1822 flags = SLJIT_SET_Z;
1823 else
1824 flags = condition << VARIABLE_FLAG_SHIFT;
1825
1826 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1827 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1828 compiler->skip_checks = 1;
1829 #endif
1830 PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_I32_OP),
1831 SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1832 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1833 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1834 compiler->skip_checks = 1;
1835 #endif
1836 return sljit_emit_jump(compiler, condition | (type & (SLJIT_REWRITABLE_JUMP | SLJIT_I32_OP)));
1837 }
1838
1839 #endif
1840
1841 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
1842 sljit_s32 src1, sljit_sw src1w,
1843 sljit_s32 src2, sljit_sw src2w)
1844 {
1845 CHECK_ERROR_PTR();
1846 CHECK_PTR(check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w));
1847
1848 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1849 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1850 compiler->skip_checks = 1;
1851 #endif
1852 sljit_emit_fop1(compiler, SLJIT_CMP_F64 | ((type & 0xff) << VARIABLE_FLAG_SHIFT) | (type & SLJIT_I32_OP), src1, src1w, src2, src2w);
1853
1854 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1855 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1856 compiler->skip_checks = 1;
1857 #endif
1858 return sljit_emit_jump(compiler, type);
1859 }
1860
1861 #if !(defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86)
1862
1863 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
1864 {
1865 CHECK_ERROR();
1866 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
1867
1868 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_SP), offset);
1869 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) \
1870 || (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS)
1871 compiler->skip_checks = 1;
1872 #endif
1873 if (offset != 0)
1874 return sljit_emit_op2(compiler, SLJIT_ADD, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
1875 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_SP, 0);
1876 }
1877
1878 #endif
1879
1880 #else /* SLJIT_CONFIG_UNSUPPORTED */
1881
1882 /* Empty function bodies for those machines, which are not (yet) supported. */
1883
1884 SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void)
1885 {
1886 return "unsupported";
1887 }
1888
1889 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void *allocator_data)
1890 {
1891 SLJIT_UNUSED_ARG(allocator_data);
1892 SLJIT_UNREACHABLE();
1893 return NULL;
1894 }
1895
1896 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
1897 {
1898 SLJIT_UNUSED_ARG(compiler);
1899 SLJIT_UNREACHABLE();
1900 }
1901
1902 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_compiler_memory_error(struct sljit_compiler *compiler)
1903 {
1904 SLJIT_UNUSED_ARG(compiler);
1905 SLJIT_UNREACHABLE();
1906 }
1907
1908 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_s32 size)
1909 {
1910 SLJIT_UNUSED_ARG(compiler);
1911 SLJIT_UNUSED_ARG(size);
1912 SLJIT_UNREACHABLE();
1913 return NULL;
1914 }
1915
1916 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1917 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1918 {
1919 SLJIT_UNUSED_ARG(compiler);
1920 SLJIT_UNUSED_ARG(verbose);
1921 SLJIT_UNREACHABLE();
1922 }
1923 #endif
1924
1925 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
1926 {
1927 SLJIT_UNUSED_ARG(compiler);
1928 SLJIT_UNREACHABLE();
1929 return NULL;
1930 }
1931
1932 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type)
1933 {
1934 SLJIT_UNUSED_ARG(feature_type);
1935 SLJIT_UNREACHABLE();
1936 return 0;
1937 }
1938
1939 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
1940 {
1941 SLJIT_UNUSED_ARG(code);
1942 SLJIT_UNREACHABLE();
1943 }
1944
1945 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
1946 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
1947 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1948 {
1949 SLJIT_UNUSED_ARG(compiler);
1950 SLJIT_UNUSED_ARG(options);
1951 SLJIT_UNUSED_ARG(args);
1952 SLJIT_UNUSED_ARG(scratches);
1953 SLJIT_UNUSED_ARG(saveds);
1954 SLJIT_UNUSED_ARG(fscratches);
1955 SLJIT_UNUSED_ARG(fsaveds);
1956 SLJIT_UNUSED_ARG(local_size);
1957 SLJIT_UNREACHABLE();
1958 return SLJIT_ERR_UNSUPPORTED;
1959 }
1960
1961 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
1962 sljit_s32 options, sljit_s32 args, sljit_s32 scratches, sljit_s32 saveds,
1963 sljit_s32 fscratches, sljit_s32 fsaveds, sljit_s32 local_size)
1964 {
1965 SLJIT_UNUSED_ARG(compiler);
1966 SLJIT_UNUSED_ARG(options);
1967 SLJIT_UNUSED_ARG(args);
1968 SLJIT_UNUSED_ARG(scratches);
1969 SLJIT_UNUSED_ARG(saveds);
1970 SLJIT_UNUSED_ARG(fscratches);
1971 SLJIT_UNUSED_ARG(fsaveds);
1972 SLJIT_UNUSED_ARG(local_size);
1973 SLJIT_UNREACHABLE();
1974 return SLJIT_ERR_UNSUPPORTED;
1975 }
1976
1977 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1978 {
1979 SLJIT_UNUSED_ARG(compiler);
1980 SLJIT_UNUSED_ARG(op);
1981 SLJIT_UNUSED_ARG(src);
1982 SLJIT_UNUSED_ARG(srcw);
1983 SLJIT_UNREACHABLE();
1984 return SLJIT_ERR_UNSUPPORTED;
1985 }
1986
1987 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1988 {
1989 SLJIT_UNUSED_ARG(compiler);
1990 SLJIT_UNUSED_ARG(dst);
1991 SLJIT_UNUSED_ARG(dstw);
1992 SLJIT_UNREACHABLE();
1993 return SLJIT_ERR_UNSUPPORTED;
1994 }
1995
1996 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
1997 {
1998 SLJIT_UNUSED_ARG(compiler);
1999 SLJIT_UNUSED_ARG(src);
2000 SLJIT_UNUSED_ARG(srcw);
2001 SLJIT_UNREACHABLE();
2002 return SLJIT_ERR_UNSUPPORTED;
2003 }
2004
2005 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
2006 {
2007 SLJIT_UNUSED_ARG(compiler);
2008 SLJIT_UNUSED_ARG(op);
2009 SLJIT_UNREACHABLE();
2010 return SLJIT_ERR_UNSUPPORTED;
2011 }
2012
2013 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
2014 sljit_s32 dst, sljit_sw dstw,
2015 sljit_s32 src, sljit_sw srcw)
2016 {
2017 SLJIT_UNUSED_ARG(compiler);
2018 SLJIT_UNUSED_ARG(op);
2019 SLJIT_UNUSED_ARG(dst);
2020 SLJIT_UNUSED_ARG(dstw);
2021 SLJIT_UNUSED_ARG(src);
2022 SLJIT_UNUSED_ARG(srcw);
2023 SLJIT_UNREACHABLE();
2024 return SLJIT_ERR_UNSUPPORTED;
2025 }
2026
2027 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2028 sljit_s32 dst, sljit_sw dstw,
2029 sljit_s32 src1, sljit_sw src1w,
2030 sljit_s32 src2, sljit_sw src2w)
2031 {
2032 SLJIT_UNUSED_ARG(compiler);
2033 SLJIT_UNUSED_ARG(op);
2034 SLJIT_UNUSED_ARG(dst);
2035 SLJIT_UNUSED_ARG(dstw);
2036 SLJIT_UNUSED_ARG(src1);
2037 SLJIT_UNUSED_ARG(src1w);
2038 SLJIT_UNUSED_ARG(src2);
2039 SLJIT_UNUSED_ARG(src2w);
2040 SLJIT_UNREACHABLE();
2041 return SLJIT_ERR_UNSUPPORTED;
2042 }
2043
2044 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_register_index(sljit_s32 reg)
2045 {
2046 SLJIT_UNREACHABLE();
2047 return reg;
2048 }
2049
2050 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2051 void *instruction, sljit_s32 size)
2052 {
2053 SLJIT_UNUSED_ARG(compiler);
2054 SLJIT_UNUSED_ARG(instruction);
2055 SLJIT_UNUSED_ARG(size);
2056 SLJIT_UNREACHABLE();
2057 return SLJIT_ERR_UNSUPPORTED;
2058 }
2059
2060 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_current_flags(struct sljit_compiler *compiler, sljit_s32 current_flags)
2061 {
2062 SLJIT_UNUSED_ARG(compiler);
2063 SLJIT_UNUSED_ARG(current_flags);
2064 }
2065
2066 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2067 sljit_s32 dst, sljit_sw dstw,
2068 sljit_s32 src, sljit_sw srcw)
2069 {
2070 SLJIT_UNUSED_ARG(compiler);
2071 SLJIT_UNUSED_ARG(op);
2072 SLJIT_UNUSED_ARG(dst);
2073 SLJIT_UNUSED_ARG(dstw);
2074 SLJIT_UNUSED_ARG(src);
2075 SLJIT_UNUSED_ARG(srcw);
2076 SLJIT_UNREACHABLE();
2077 return SLJIT_ERR_UNSUPPORTED;
2078 }
2079
2080 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2081 sljit_s32 dst, sljit_sw dstw,
2082 sljit_s32 src1, sljit_sw src1w,
2083 sljit_s32 src2, sljit_sw src2w)
2084 {
2085 SLJIT_UNUSED_ARG(compiler);
2086 SLJIT_UNUSED_ARG(op);
2087 SLJIT_UNUSED_ARG(dst);
2088 SLJIT_UNUSED_ARG(dstw);
2089 SLJIT_UNUSED_ARG(src1);
2090 SLJIT_UNUSED_ARG(src1w);
2091 SLJIT_UNUSED_ARG(src2);
2092 SLJIT_UNUSED_ARG(src2w);
2093 SLJIT_UNREACHABLE();
2094 return SLJIT_ERR_UNSUPPORTED;
2095 }
2096
2097 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2098 {
2099 SLJIT_UNUSED_ARG(compiler);
2100 SLJIT_UNREACHABLE();
2101 return NULL;
2102 }
2103
2104 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2105 {
2106 SLJIT_UNUSED_ARG(compiler);
2107 SLJIT_UNUSED_ARG(type);
2108 SLJIT_UNREACHABLE();
2109 return NULL;
2110 }
2111
2112 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_s32 type,
2113 sljit_s32 src1, sljit_sw src1w,
2114 sljit_s32 src2, sljit_sw src2w)
2115 {
2116 SLJIT_UNUSED_ARG(compiler);
2117 SLJIT_UNUSED_ARG(type);
2118 SLJIT_UNUSED_ARG(src1);
2119 SLJIT_UNUSED_ARG(src1w);
2120 SLJIT_UNUSED_ARG(src2);
2121 SLJIT_UNUSED_ARG(src2w);
2122 SLJIT_UNREACHABLE();
2123 return NULL;
2124 }
2125
2126 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_s32 type,
2127 sljit_s32 src1, sljit_sw src1w,
2128 sljit_s32 src2, sljit_sw src2w)
2129 {
2130 SLJIT_UNUSED_ARG(compiler);
2131 SLJIT_UNUSED_ARG(type);
2132 SLJIT_UNUSED_ARG(src1);
2133 SLJIT_UNUSED_ARG(src1w);
2134 SLJIT_UNUSED_ARG(src2);
2135 SLJIT_UNUSED_ARG(src2w);
2136 SLJIT_UNREACHABLE();
2137 return NULL;
2138 }
2139
2140 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
2141 {
2142 SLJIT_UNUSED_ARG(jump);
2143 SLJIT_UNUSED_ARG(label);
2144 SLJIT_UNREACHABLE();
2145 }
2146
2147 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
2148 {
2149 SLJIT_UNUSED_ARG(jump);
2150 SLJIT_UNUSED_ARG(target);
2151 SLJIT_UNREACHABLE();
2152 }
2153
2154 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2155 {
2156 SLJIT_UNUSED_ARG(compiler);
2157 SLJIT_UNUSED_ARG(type);
2158 SLJIT_UNUSED_ARG(src);
2159 SLJIT_UNUSED_ARG(srcw);
2160 SLJIT_UNREACHABLE();
2161 return SLJIT_ERR_UNSUPPORTED;
2162 }
2163
2164 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2165 sljit_s32 dst, sljit_sw dstw,
2166 sljit_s32 type)
2167 {
2168 SLJIT_UNUSED_ARG(compiler);
2169 SLJIT_UNUSED_ARG(op);
2170 SLJIT_UNUSED_ARG(dst);
2171 SLJIT_UNUSED_ARG(dstw);
2172 SLJIT_UNUSED_ARG(type);
2173 SLJIT_UNREACHABLE();
2174 return SLJIT_ERR_UNSUPPORTED;
2175 }
2176
2177 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_cmov(struct sljit_compiler *compiler, sljit_s32 type,
2178 sljit_s32 dst_reg,
2179 sljit_s32 src, sljit_sw srcw)
2180 {
2181 SLJIT_UNUSED_ARG(compiler);
2182 SLJIT_UNUSED_ARG(type);
2183 SLJIT_UNUSED_ARG(dst_reg);
2184 SLJIT_UNUSED_ARG(src);
2185 SLJIT_UNUSED_ARG(srcw);
2186 SLJIT_UNREACHABLE();
2187 return SLJIT_ERR_UNSUPPORTED;
2188 }
2189
2190 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2191 {
2192 SLJIT_UNUSED_ARG(compiler);
2193 SLJIT_UNUSED_ARG(dst);
2194 SLJIT_UNUSED_ARG(dstw);
2195 SLJIT_UNUSED_ARG(offset);
2196 SLJIT_UNREACHABLE();
2197 return SLJIT_ERR_UNSUPPORTED;
2198 }
2199
2200 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw initval)
2201 {
2202 SLJIT_UNUSED_ARG(compiler);
2203 SLJIT_UNUSED_ARG(dst);
2204 SLJIT_UNUSED_ARG(dstw);
2205 SLJIT_UNUSED_ARG(initval);
2206 SLJIT_UNREACHABLE();
2207 return NULL;
2208 }
2209
2210 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset)
2211 {
2212 SLJIT_UNUSED_ARG(addr);
2213 SLJIT_UNUSED_ARG(new_target);
2214 SLJIT_UNUSED_ARG(executable_offset);
2215 SLJIT_UNREACHABLE();
2216 }
2217
2218 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset)
2219 {
2220 SLJIT_UNUSED_ARG(addr);
2221 SLJIT_UNUSED_ARG(new_constant);
2222 SLJIT_UNUSED_ARG(executable_offset);
2223 SLJIT_UNREACHABLE();
2224 }
2225
2226 #endif

  ViewVC Help
Powered by ViewVC 1.1.5