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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1457 - (show annotations)
Sun Mar 2 14:49:27 2014 UTC (5 years, 6 months ago) by zherczeg
File MIME type: text/plain
File size: 56049 byte(s)
Error occurred while calculating annotation data.
JIT compiler update.
1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2012 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 #define CHECK_ERROR() \
30 do { \
31 if (SLJIT_UNLIKELY(compiler->error)) \
32 return compiler->error; \
33 } while (0)
34
35 #define CHECK_ERROR_PTR() \
36 do { \
37 if (SLJIT_UNLIKELY(compiler->error)) \
38 return NULL; \
39 } while (0)
40
41 #define CHECK_ERROR_VOID() \
42 do { \
43 if (SLJIT_UNLIKELY(compiler->error)) \
44 return; \
45 } while (0)
46
47 #define FAIL_IF(expr) \
48 do { \
49 if (SLJIT_UNLIKELY(expr)) \
50 return compiler->error; \
51 } while (0)
52
53 #define PTR_FAIL_IF(expr) \
54 do { \
55 if (SLJIT_UNLIKELY(expr)) \
56 return NULL; \
57 } while (0)
58
59 #define FAIL_IF_NULL(ptr) \
60 do { \
61 if (SLJIT_UNLIKELY(!(ptr))) { \
62 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
63 return SLJIT_ERR_ALLOC_FAILED; \
64 } \
65 } while (0)
66
67 #define PTR_FAIL_IF_NULL(ptr) \
68 do { \
69 if (SLJIT_UNLIKELY(!(ptr))) { \
70 compiler->error = SLJIT_ERR_ALLOC_FAILED; \
71 return NULL; \
72 } \
73 } while (0)
74
75 #define PTR_FAIL_WITH_EXEC_IF(ptr) \
76 do { \
77 if (SLJIT_UNLIKELY(!(ptr))) { \
78 compiler->error = SLJIT_ERR_EX_ALLOC_FAILED; \
79 return NULL; \
80 } \
81 } while (0)
82
83 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
84
85 #define GET_OPCODE(op) \
86 ((op) & ~(SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
87
88 #define GET_FLAGS(op) \
89 ((op) & (SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C))
90
91 #define GET_ALL_FLAGS(op) \
92 ((op) & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
93
94 #define TYPE_CAST_NEEDED(op) \
95 (((op) >= SLJIT_MOV_UB && (op) <= SLJIT_MOV_SH) || ((op) >= SLJIT_MOVU_UB && (op) <= SLJIT_MOVU_SH))
96
97 #define BUF_SIZE 4096
98
99 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
100 #define ABUF_SIZE 2048
101 #else
102 #define ABUF_SIZE 4096
103 #endif
104
105 /* Parameter parsing. */
106 #define REG_MASK 0x3f
107 #define OFFS_REG(reg) (((reg) >> 8) & REG_MASK)
108 #define OFFS_REG_MASK (REG_MASK << 8)
109 #define TO_OFFS_REG(reg) ((reg) << 8)
110 /* When reg cannot be unused. */
111 #define FAST_IS_REG(reg) ((reg) <= REG_MASK)
112 /* When reg can be unused. */
113 #define SLOW_IS_REG(reg) ((reg) > 0 && (reg) <= REG_MASK)
114
115 /* Jump flags. */
116 #define JUMP_LABEL 0x1
117 #define JUMP_ADDR 0x2
118 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
119
120 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
121 # define PATCH_MB 0x4
122 # define PATCH_MW 0x8
123 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
124 # define PATCH_MD 0x10
125 #endif
126 #endif
127
128 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
129 # define IS_BL 0x4
130 # define PATCH_B 0x8
131 #endif
132
133 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
134 # define CPOOL_SIZE 512
135 #endif
136
137 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
138 # define IS_COND 0x04
139 # define IS_BL 0x08
140 /* conditional + imm8 */
141 # define PATCH_TYPE1 0x10
142 /* conditional + imm20 */
143 # define PATCH_TYPE2 0x20
144 /* IT + imm24 */
145 # define PATCH_TYPE3 0x30
146 /* imm11 */
147 # define PATCH_TYPE4 0x40
148 /* imm24 */
149 # define PATCH_TYPE5 0x50
150 /* BL + imm24 */
151 # define PATCH_BL 0x60
152 /* 0xf00 cc code for branches */
153 #endif
154
155 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
156 # define IS_COND 0x04
157 # define IS_CBZ 0x08
158 # define IS_BL 0x10
159 # define PATCH_B 0x20
160 # define PATCH_COND 0x40
161 #endif
162
163 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
164 # define COND_B 0x04
165 # define PATCH_B 0x08
166 # define ABSOLUTE_B 0x10
167 # define REMOVE_COND 0x20
168 #endif
169
170 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
171 # define IS_MOVABLE 0x04
172 # define IS_JAL 0x08
173 # define IS_BIT26_COND 0x10
174 # define IS_BIT16_COND 0x20
175
176 # define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
177
178 # define PATCH_B 0x40
179 # define PATCH_J 0x80
180
181 /* instruction types */
182 # define MOVABLE_INS 0
183 /* 1 - 31 last destination register */
184 /* no destination (i.e: store) */
185 # define UNMOVABLE_INS 32
186 /* FPU status register */
187 # define FCSR_FCC 33
188 #endif
189
190 #if (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
191 # define IS_JAL 0x04
192 # define IS_COND 0x08
193
194 # define PATCH_B 0x10
195 # define PATCH_J 0x20
196 #endif
197
198 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
199 # define IS_MOVABLE 0x04
200 # define IS_COND 0x08
201 # define IS_CALL 0x10
202
203 # define PATCH_B 0x20
204 # define PATCH_CALL 0x40
205
206 /* instruction types */
207 # define MOVABLE_INS 0
208 /* 1 - 31 last destination register */
209 /* no destination (i.e: store) */
210 # define UNMOVABLE_INS 32
211
212 # define DST_INS_MASK 0xff
213
214 /* ICC_SET is the same as SET_FLAGS. */
215 # define ICC_IS_SET (1 << 23)
216 # define FCC_IS_SET (1 << 24)
217 #endif
218
219 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
220 #define SLJIT_HAS_VARIABLE_LOCALS_OFFSET 1
221 #if !(defined SLJIT_X86_32_FASTCALL && SLJIT_X86_32_FASTCALL)
222 #define FIXED_LOCALS_OFFSET (3 * sizeof(sljit_sw))
223 #endif
224 #endif
225
226 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
227 #define SLJIT_HAS_FIXED_LOCALS_OFFSET 1
228 #ifdef _WIN64
229 #define FIXED_LOCALS_OFFSET ((4 + 2) * sizeof(sljit_sw))
230 #else
231 #define FIXED_LOCALS_OFFSET (sizeof(sljit_sw))
232 #endif
233 #endif
234
235 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
236 #define SLJIT_HAS_VARIABLE_LOCALS_OFFSET 1
237 #endif
238
239 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
240 #define SLJIT_HAS_FIXED_LOCALS_OFFSET 1
241 #ifdef _AIX
242 #define FIXED_LOCALS_OFFSET ((6 + 8) * sizeof(sljit_sw))
243 #else
244 #define FIXED_LOCALS_OFFSET (2 * sizeof(sljit_sw))
245 #endif
246 #endif
247
248 #if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
249 #define SLJIT_HAS_FIXED_LOCALS_OFFSET 1
250 #define FIXED_LOCALS_OFFSET ((6 + 8) * sizeof(sljit_sw))
251 #endif
252
253 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
254 #define SLJIT_HAS_FIXED_LOCALS_OFFSET 1
255 #define FIXED_LOCALS_OFFSET (4 * sizeof(sljit_sw))
256 #endif
257
258 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
259 #define SLJIT_HAS_FIXED_LOCALS_OFFSET 1
260 #define FIXED_LOCALS_OFFSET (23 * sizeof(sljit_sw))
261 #endif
262
263 #if (defined SLJIT_HAS_VARIABLE_LOCALS_OFFSET && SLJIT_HAS_VARIABLE_LOCALS_OFFSET)
264
265 #define ADJUST_LOCAL_OFFSET(p, i) \
266 if ((p) == (SLJIT_MEM1(SLJIT_LOCALS_REG))) \
267 (i) += compiler->locals_offset;
268
269 #elif (defined SLJIT_HAS_FIXED_LOCALS_OFFSET && SLJIT_HAS_FIXED_LOCALS_OFFSET)
270
271 #define ADJUST_LOCAL_OFFSET(p, i) \
272 if ((p) == (SLJIT_MEM1(SLJIT_LOCALS_REG))) \
273 (i) += FIXED_LOCALS_OFFSET;
274
275 #else
276
277 #define ADJUST_LOCAL_OFFSET(p, i)
278
279 #endif
280
281 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
282
283 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
284 #include "sljitUtils.c"
285
286 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
287
288 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
289 #include "sljitExecAllocator.c"
290 #endif
291
292 #if (defined SLJIT_SSE2_AUTO && SLJIT_SSE2_AUTO) && !(defined SLJIT_SSE2 && SLJIT_SSE2)
293 #error SLJIT_SSE2_AUTO cannot be enabled without SLJIT_SSE2
294 #endif
295
296 /* --------------------------------------------------------------------- */
297 /* Public functions */
298 /* --------------------------------------------------------------------- */
299
300 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || ((defined SLJIT_SSE2 && SLJIT_SSE2) && ((defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)))
301 #define SLJIT_NEEDS_COMPILER_INIT 1
302 static sljit_si compiler_initialized = 0;
303 /* A thread safe initialization. */
304 static void init_compiler(void);
305 #endif
306
307 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
308 {
309 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler));
310 if (!compiler)
311 return NULL;
312 SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler));
313
314 SLJIT_COMPILE_ASSERT(
315 sizeof(sljit_sb) == 1 && sizeof(sljit_ub) == 1
316 && sizeof(sljit_sh) == 2 && sizeof(sljit_uh) == 2
317 && sizeof(sljit_si) == 4 && sizeof(sljit_ui) == 4
318 && (sizeof(sljit_p) == 4 || sizeof(sljit_p) == 8)
319 && sizeof(sljit_p) <= sizeof(sljit_sw)
320 && (sizeof(sljit_sw) == 4 || sizeof(sljit_sw) == 8)
321 && (sizeof(sljit_uw) == 4 || sizeof(sljit_uw) == 8),
322 invalid_integer_types);
323 SLJIT_COMPILE_ASSERT(SLJIT_INT_OP == SLJIT_SINGLE_OP,
324 int_op_and_single_op_must_be_the_same);
325 SLJIT_COMPILE_ASSERT(SLJIT_REWRITABLE_JUMP != SLJIT_SINGLE_OP,
326 rewritable_jump_and_single_op_must_not_be_the_same);
327
328 /* Only the non-zero members must be set. */
329 compiler->error = SLJIT_SUCCESS;
330
331 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE);
332 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE);
333
334 if (!compiler->buf || !compiler->abuf) {
335 if (compiler->buf)
336 SLJIT_FREE(compiler->buf);
337 if (compiler->abuf)
338 SLJIT_FREE(compiler->abuf);
339 SLJIT_FREE(compiler);
340 return NULL;
341 }
342
343 compiler->buf->next = NULL;
344 compiler->buf->used_size = 0;
345 compiler->abuf->next = NULL;
346 compiler->abuf->used_size = 0;
347
348 compiler->scratches = -1;
349 compiler->saveds = -1;
350
351 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
352 compiler->args = -1;
353 #endif
354
355 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
356 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw) + CPOOL_SIZE * sizeof(sljit_ub));
357 if (!compiler->cpool) {
358 SLJIT_FREE(compiler->buf);
359 SLJIT_FREE(compiler->abuf);
360 SLJIT_FREE(compiler);
361 return NULL;
362 }
363 compiler->cpool_unique = (sljit_ub*)(compiler->cpool + CPOOL_SIZE);
364 compiler->cpool_diff = 0xffffffff;
365 #endif
366
367 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
368 compiler->delay_slot = UNMOVABLE_INS;
369 #endif
370
371 #if (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
372 compiler->delay_slot = UNMOVABLE_INS;
373 #endif
374
375 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
376 if (!compiler_initialized) {
377 init_compiler();
378 compiler_initialized = 1;
379 }
380 #endif
381
382 return compiler;
383 }
384
385 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
386 {
387 struct sljit_memory_fragment *buf;
388 struct sljit_memory_fragment *curr;
389
390 buf = compiler->buf;
391 while (buf) {
392 curr = buf;
393 buf = buf->next;
394 SLJIT_FREE(curr);
395 }
396
397 buf = compiler->abuf;
398 while (buf) {
399 curr = buf;
400 buf = buf->next;
401 SLJIT_FREE(curr);
402 }
403
404 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
405 SLJIT_FREE(compiler->cpool);
406 #endif
407 SLJIT_FREE(compiler);
408 }
409
410 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
411 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
412 {
413 /* Remove thumb mode flag. */
414 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1));
415 }
416 #elif (defined SLJIT_INDIRECT_CALL && SLJIT_INDIRECT_CALL)
417 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
418 {
419 /* Resolve indirection. */
420 code = (void*)(*(sljit_uw*)code);
421 SLJIT_FREE_EXEC(code);
422 }
423 #else
424 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
425 {
426 SLJIT_FREE_EXEC(code);
427 }
428 #endif
429
430 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
431 {
432 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
433 jump->flags &= ~JUMP_ADDR;
434 jump->flags |= JUMP_LABEL;
435 jump->u.label = label;
436 }
437 }
438
439 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
440 {
441 if (SLJIT_LIKELY(!!jump)) {
442 SLJIT_ASSERT(jump->flags & SLJIT_REWRITABLE_JUMP);
443
444 jump->flags &= ~JUMP_LABEL;
445 jump->flags |= JUMP_ADDR;
446 jump->u.target = target;
447 }
448 }
449
450 /* --------------------------------------------------------------------- */
451 /* Private functions */
452 /* --------------------------------------------------------------------- */
453
454 static void* ensure_buf(struct sljit_compiler *compiler, sljit_uw size)
455 {
456 sljit_ub *ret;
457 struct sljit_memory_fragment *new_frag;
458
459 SLJIT_ASSERT(size <= 256);
460 if (compiler->buf->used_size + size <= (BUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
461 ret = compiler->buf->memory + compiler->buf->used_size;
462 compiler->buf->used_size += size;
463 return ret;
464 }
465 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE);
466 PTR_FAIL_IF_NULL(new_frag);
467 new_frag->next = compiler->buf;
468 compiler->buf = new_frag;
469 new_frag->used_size = size;
470 return new_frag->memory;
471 }
472
473 static void* ensure_abuf(struct sljit_compiler *compiler, sljit_uw size)
474 {
475 sljit_ub *ret;
476 struct sljit_memory_fragment *new_frag;
477
478 SLJIT_ASSERT(size <= 256);
479 if (compiler->abuf->used_size + size <= (ABUF_SIZE - (sljit_uw)SLJIT_OFFSETOF(struct sljit_memory_fragment, memory))) {
480 ret = compiler->abuf->memory + compiler->abuf->used_size;
481 compiler->abuf->used_size += size;
482 return ret;
483 }
484 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE);
485 PTR_FAIL_IF_NULL(new_frag);
486 new_frag->next = compiler->abuf;
487 compiler->abuf = new_frag;
488 new_frag->used_size = size;
489 return new_frag->memory;
490 }
491
492 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
493 {
494 CHECK_ERROR_PTR();
495
496 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
497 if (size <= 0 || size > 128)
498 return NULL;
499 size = (size + 7) & ~7;
500 #else
501 if (size <= 0 || size > 64)
502 return NULL;
503 size = (size + 3) & ~3;
504 #endif
505 return ensure_abuf(compiler, size);
506 }
507
508 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
509 {
510 struct sljit_memory_fragment *buf = compiler->buf;
511 struct sljit_memory_fragment *prev = NULL;
512 struct sljit_memory_fragment *tmp;
513
514 do {
515 tmp = buf->next;
516 buf->next = prev;
517 prev = buf;
518 buf = tmp;
519 } while (buf != NULL);
520
521 compiler->buf = prev;
522 }
523
524 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
525 {
526 label->next = NULL;
527 label->size = compiler->size;
528 if (compiler->last_label)
529 compiler->last_label->next = label;
530 else
531 compiler->labels = label;
532 compiler->last_label = label;
533 }
534
535 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, sljit_si flags)
536 {
537 jump->next = NULL;
538 jump->flags = flags;
539 if (compiler->last_jump)
540 compiler->last_jump->next = jump;
541 else
542 compiler->jumps = jump;
543 compiler->last_jump = jump;
544 }
545
546 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
547 {
548 const_->next = NULL;
549 const_->addr = compiler->size;
550 if (compiler->last_const)
551 compiler->last_const->next = const_;
552 else
553 compiler->consts = const_;
554 compiler->last_const = const_;
555 }
556
557 #define ADDRESSING_DEPENDS_ON(exp, reg) \
558 (((exp) & SLJIT_MEM) && (((exp) & REG_MASK) == reg || OFFS_REG(exp) == reg))
559
560 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
561 #define FUNCTION_CHECK_OP() \
562 SLJIT_ASSERT(!GET_FLAGS(op) || !(op & SLJIT_KEEP_FLAGS)); \
563 switch (GET_OPCODE(op)) { \
564 case SLJIT_NOT: \
565 case SLJIT_CLZ: \
566 case SLJIT_AND: \
567 case SLJIT_OR: \
568 case SLJIT_XOR: \
569 case SLJIT_SHL: \
570 case SLJIT_LSHR: \
571 case SLJIT_ASHR: \
572 SLJIT_ASSERT(!(op & (SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C))); \
573 break; \
574 case SLJIT_NEG: \
575 SLJIT_ASSERT(!(op & (SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_C))); \
576 break; \
577 case SLJIT_MUL: \
578 SLJIT_ASSERT(!(op & (SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_C))); \
579 break; \
580 case SLJIT_CMPD: \
581 SLJIT_ASSERT(!(op & (SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
582 SLJIT_ASSERT((op & (SLJIT_SET_E | SLJIT_SET_S))); \
583 break; \
584 case SLJIT_ADD: \
585 SLJIT_ASSERT(!(op & (SLJIT_SET_S | SLJIT_SET_U))); \
586 break; \
587 case SLJIT_SUB: \
588 break; \
589 case SLJIT_ADDC: \
590 case SLJIT_SUBC: \
591 SLJIT_ASSERT(!(op & (SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O))); \
592 break; \
593 case SLJIT_BREAKPOINT: \
594 case SLJIT_NOP: \
595 case SLJIT_UMUL: \
596 case SLJIT_SMUL: \
597 case SLJIT_MOV: \
598 case SLJIT_MOV_P: \
599 case SLJIT_MOVU: \
600 case SLJIT_MOVU_P: \
601 /* Nothing allowed */ \
602 SLJIT_ASSERT(!(op & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
603 break; \
604 default: \
605 /* Only SLJIT_INT_OP or SLJIT_SINGLE_OP is allowed. */ \
606 SLJIT_ASSERT(!(op & (SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
607 break; \
608 }
609
610 #define FUNCTION_CHECK_IS_REG(r) \
611 ((r) == SLJIT_UNUSED || \
612 ((r) >= SLJIT_SCRATCH_REG1 && (r) <= SLJIT_SCRATCH_REG1 - 1 + compiler->scratches) || \
613 ((r) >= SLJIT_SAVED_REG1 && (r) <= SLJIT_SAVED_REG1 - 1 + compiler->saveds))
614
615 #define FUNCTION_CHECK_SRC(p, i) \
616 SLJIT_ASSERT(compiler->scratches != -1 && compiler->saveds != -1); \
617 if (FUNCTION_CHECK_IS_REG(p)) \
618 SLJIT_ASSERT((i) == 0 && (p) != SLJIT_UNUSED); \
619 else if ((p) == SLJIT_IMM) \
620 ; \
621 else if ((p) == (SLJIT_MEM1(SLJIT_LOCALS_REG))) \
622 SLJIT_ASSERT((i) >= 0 && (i) < compiler->logical_local_size); \
623 else if ((p) & SLJIT_MEM) { \
624 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG((p) & REG_MASK)); \
625 if ((p) & OFFS_REG_MASK) { \
626 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
627 SLJIT_ASSERT(!((i) & ~0x3)); \
628 } \
629 SLJIT_ASSERT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
630 } \
631 else \
632 SLJIT_ASSERT_STOP();
633
634 #define FUNCTION_CHECK_DST(p, i) \
635 SLJIT_ASSERT(compiler->scratches != -1 && compiler->saveds != -1); \
636 if (FUNCTION_CHECK_IS_REG(p)) \
637 SLJIT_ASSERT((i) == 0); \
638 else if ((p) == (SLJIT_MEM1(SLJIT_LOCALS_REG))) \
639 SLJIT_ASSERT((i) >= 0 && (i) < compiler->logical_local_size); \
640 else if ((p) & SLJIT_MEM) { \
641 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG((p) & REG_MASK)); \
642 if ((p) & OFFS_REG_MASK) { \
643 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
644 SLJIT_ASSERT(!((i) & ~0x3)); \
645 } \
646 SLJIT_ASSERT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
647 } \
648 else \
649 SLJIT_ASSERT_STOP();
650
651 #define FUNCTION_FCHECK(p, i) \
652 if ((p) >= SLJIT_FLOAT_REG1 && (p) <= SLJIT_FLOAT_REG6) \
653 SLJIT_ASSERT(i == 0); \
654 else if ((p) & SLJIT_MEM) { \
655 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG((p) & REG_MASK)); \
656 if ((p) & OFFS_REG_MASK) { \
657 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG(OFFS_REG(p))); \
658 SLJIT_ASSERT(((p) & OFFS_REG_MASK) != TO_OFFS_REG(SLJIT_LOCALS_REG) && !(i & ~0x3)); \
659 } else \
660 SLJIT_ASSERT(OFFS_REG(p) == 0); \
661 SLJIT_ASSERT(!((p) & ~(SLJIT_MEM | SLJIT_IMM | REG_MASK | OFFS_REG_MASK))); \
662 } \
663 else \
664 SLJIT_ASSERT_STOP();
665
666 #define FUNCTION_CHECK_OP1() \
667 if (GET_OPCODE(op) >= SLJIT_MOVU && GET_OPCODE(op) <= SLJIT_MOVU_P) { \
668 SLJIT_ASSERT(!(src & SLJIT_MEM) || (src & REG_MASK) != SLJIT_LOCALS_REG); \
669 SLJIT_ASSERT(!(dst & SLJIT_MEM) || (dst & REG_MASK) != SLJIT_LOCALS_REG); \
670 if ((src & SLJIT_MEM) && (src & REG_MASK)) \
671 SLJIT_ASSERT((dst & REG_MASK) != (src & REG_MASK) && OFFS_REG(dst) != (src & REG_MASK)); \
672 }
673
674 #endif
675
676 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
677
678 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
679 {
680 compiler->verbose = verbose;
681 }
682
683 static char* reg_names[] = {
684 (char*)"unused", (char*)"s1", (char*)"s2", (char*)"s3",
685 (char*)"se1", (char*)"se2", (char*)"p1", (char*)"p2",
686 (char*)"p3", (char*)"pe1", (char*)"pe2", (char*)"lc"
687 };
688
689 static char* freg_names[] = {
690 (char*)"unused", (char*)"f1", (char*)"f2", (char*)"f3",
691 (char*)"f4", (char*)"f5", (char*)"f6"
692 };
693
694 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) \
695 || (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64) \
696 || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
697 #ifdef _WIN64
698 # define SLJIT_PRINT_D "I64"
699 #else
700 # define SLJIT_PRINT_D "l"
701 #endif
702 #else
703 # define SLJIT_PRINT_D ""
704 #endif
705
706 #define sljit_verbose_param(p, i) \
707 if ((p) & SLJIT_IMM) \
708 fprintf(compiler->verbose, "#%" SLJIT_PRINT_D "d", (i)); \
709 else if ((p) & SLJIT_MEM) { \
710 if ((p) & REG_MASK) { \
711 if (i) { \
712 if ((p) & OFFS_REG_MASK) \
713 fprintf(compiler->verbose, "[%s + %s * %d]", reg_names[(p) & REG_MASK], reg_names[OFFS_REG(p)], 1 << (i)); \
714 else \
715 fprintf(compiler->verbose, "[%s + #%" SLJIT_PRINT_D "d]", reg_names[(p) & REG_MASK], (i)); \
716 } \
717 else { \
718 if ((p) & OFFS_REG_MASK) \
719 fprintf(compiler->verbose, "[%s + %s]", reg_names[(p) & REG_MASK], reg_names[OFFS_REG(p)]); \
720 else \
721 fprintf(compiler->verbose, "[%s]", reg_names[(p) & REG_MASK]); \
722 } \
723 } \
724 else \
725 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
726 } else \
727 fprintf(compiler->verbose, "%s", reg_names[p]);
728 #define sljit_verbose_fparam(p, i) \
729 if ((p) & SLJIT_MEM) { \
730 if ((p) & REG_MASK) { \
731 if (i) { \
732 if ((p) & OFFS_REG_MASK) \
733 fprintf(compiler->verbose, "[%s + %s * %d]", reg_names[(p) & REG_MASK], reg_names[OFFS_REG(p)], 1 << (i)); \
734 else \
735 fprintf(compiler->verbose, "[%s + #%" SLJIT_PRINT_D "d]", reg_names[(p) & REG_MASK], (i)); \
736 } \
737 else { \
738 if ((p) & OFFS_REG_MASK) \
739 fprintf(compiler->verbose, "[%s + %s]", reg_names[(p) & REG_MASK], reg_names[OFFS_REG(p)]); \
740 else \
741 fprintf(compiler->verbose, "[%s]", reg_names[(p) & REG_MASK]); \
742 } \
743 } \
744 else \
745 fprintf(compiler->verbose, "[#%" SLJIT_PRINT_D "d]", (i)); \
746 } else \
747 fprintf(compiler->verbose, "%s", freg_names[p]);
748
749 static SLJIT_CONST char* op_names[] = {
750 /* op0 */
751 (char*)"breakpoint", (char*)"nop",
752 (char*)"umul", (char*)"smul", (char*)"udiv", (char*)"sdiv",
753 /* op1 */
754 (char*)"mov", (char*)"mov.ub", (char*)"mov.sb", (char*)"mov.uh",
755 (char*)"mov.sh", (char*)"mov.ui", (char*)"mov.si", (char*)"mov.p",
756 (char*)"movu", (char*)"movu.ub", (char*)"movu.sb", (char*)"movu.uh",
757 (char*)"movu.sh", (char*)"movu.ui", (char*)"movu.si", (char*)"movu.p",
758 (char*)"not", (char*)"neg", (char*)"clz",
759 /* op2 */
760 (char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
761 (char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
762 (char*)"shl", (char*)"lshr", (char*)"ashr",
763 /* fop1 */
764 (char*)"cmp", (char*)"mov", (char*)"neg", (char*)"abs",
765 /* fop2 */
766 (char*)"add", (char*)"sub", (char*)"mul", (char*)"div"
767 };
768
769 static char* jump_names[] = {
770 (char*)"equal", (char*)"not_equal",
771 (char*)"less", (char*)"greater_equal",
772 (char*)"greater", (char*)"less_equal",
773 (char*)"sig_less", (char*)"sig_greater_equal",
774 (char*)"sig_greater", (char*)"sig_less_equal",
775 (char*)"overflow", (char*)"not_overflow",
776 (char*)"mul_overflow", (char*)"mul_not_overflow",
777 (char*)"float_equal", (char*)"float_not_equal",
778 (char*)"float_less", (char*)"float_greater_equal",
779 (char*)"float_greater", (char*)"float_less_equal",
780 (char*)"float_unordered", (char*)"float_ordered",
781 (char*)"jump", (char*)"fast_call",
782 (char*)"call0", (char*)"call1", (char*)"call2", (char*)"call3"
783 };
784
785 #endif
786
787 /* --------------------------------------------------------------------- */
788 /* Arch dependent */
789 /* --------------------------------------------------------------------- */
790
791 static SLJIT_INLINE void check_sljit_generate_code(struct sljit_compiler *compiler)
792 {
793 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
794 struct sljit_jump *jump;
795 #endif
796 /* If debug and verbose are disabled, all arguments are unused. */
797 SLJIT_UNUSED_ARG(compiler);
798
799 SLJIT_ASSERT(compiler->size > 0);
800 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
801 jump = compiler->jumps;
802 while (jump) {
803 /* All jumps have target. */
804 SLJIT_ASSERT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
805 jump = jump->next;
806 }
807 #endif
808 }
809
810 static SLJIT_INLINE void check_sljit_emit_enter(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
811 {
812 /* If debug and verbose are disabled, all arguments are unused. */
813 SLJIT_UNUSED_ARG(compiler);
814 SLJIT_UNUSED_ARG(args);
815 SLJIT_UNUSED_ARG(scratches);
816 SLJIT_UNUSED_ARG(saveds);
817 SLJIT_UNUSED_ARG(local_size);
818
819 SLJIT_ASSERT(args >= 0 && args <= 3);
820 SLJIT_ASSERT(scratches >= 0 && scratches <= SLJIT_NO_TMP_REGISTERS);
821 SLJIT_ASSERT(saveds >= 0 && saveds <= SLJIT_NO_GEN_REGISTERS);
822 SLJIT_ASSERT(args <= saveds);
823 SLJIT_ASSERT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
824 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
825 if (SLJIT_UNLIKELY(!!compiler->verbose))
826 fprintf(compiler->verbose, " enter args=%d scratches=%d saveds=%d local_size=%d\n", args, scratches, saveds, local_size);
827 #endif
828 }
829
830 static SLJIT_INLINE void check_sljit_set_context(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
831 {
832 /* If debug and verbose are disabled, all arguments are unused. */
833 SLJIT_UNUSED_ARG(compiler);
834 SLJIT_UNUSED_ARG(args);
835 SLJIT_UNUSED_ARG(scratches);
836 SLJIT_UNUSED_ARG(saveds);
837 SLJIT_UNUSED_ARG(local_size);
838
839 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
840 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
841 compiler->skip_checks = 0;
842 return;
843 }
844 #endif
845
846 SLJIT_ASSERT(args >= 0 && args <= 3);
847 SLJIT_ASSERT(scratches >= 0 && scratches <= SLJIT_NO_TMP_REGISTERS);
848 SLJIT_ASSERT(saveds >= 0 && saveds <= SLJIT_NO_GEN_REGISTERS);
849 SLJIT_ASSERT(args <= saveds);
850 SLJIT_ASSERT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
851 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
852 if (SLJIT_UNLIKELY(!!compiler->verbose))
853 fprintf(compiler->verbose, " set_context args=%d scratches=%d saveds=%d local_size=%d\n", args, scratches, saveds, local_size);
854 #endif
855 }
856
857 static SLJIT_INLINE void check_sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
858 {
859 /* If debug and verbose are disabled, all arguments are unused. */
860 SLJIT_UNUSED_ARG(compiler);
861 SLJIT_UNUSED_ARG(op);
862 SLJIT_UNUSED_ARG(src);
863 SLJIT_UNUSED_ARG(srcw);
864
865 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
866 if (op != SLJIT_UNUSED) {
867 SLJIT_ASSERT(op >= SLJIT_MOV && op <= SLJIT_MOV_P);
868 FUNCTION_CHECK_SRC(src, srcw);
869 }
870 else
871 SLJIT_ASSERT(src == 0 && srcw == 0);
872 #endif
873 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
874 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
875 if (op == SLJIT_UNUSED)
876 fprintf(compiler->verbose, " return\n");
877 else {
878 fprintf(compiler->verbose, " return %s ", op_names[op]);
879 sljit_verbose_param(src, srcw);
880 fprintf(compiler->verbose, "\n");
881 }
882 }
883 #endif
884 }
885
886 static SLJIT_INLINE void check_sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
887 {
888 /* If debug and verbose are disabled, all arguments are unused. */
889 SLJIT_UNUSED_ARG(compiler);
890 SLJIT_UNUSED_ARG(dst);
891 SLJIT_UNUSED_ARG(dstw);
892
893 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
894 FUNCTION_CHECK_DST(dst, dstw);
895 #endif
896 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
897 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
898 fprintf(compiler->verbose, " fast_enter ");
899 sljit_verbose_param(dst, dstw);
900 fprintf(compiler->verbose, "\n");
901 }
902 #endif
903 }
904
905 static SLJIT_INLINE void check_sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
906 {
907 /* If debug and verbose are disabled, all arguments are unused. */
908 SLJIT_UNUSED_ARG(compiler);
909 SLJIT_UNUSED_ARG(src);
910 SLJIT_UNUSED_ARG(srcw);
911
912 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
913 FUNCTION_CHECK_SRC(src, srcw);
914 #endif
915 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
916 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
917 fprintf(compiler->verbose, " fast_return ");
918 sljit_verbose_param(src, srcw);
919 fprintf(compiler->verbose, "\n");
920 }
921 #endif
922 }
923
924 static SLJIT_INLINE void check_sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
925 {
926 /* If debug and verbose are disabled, all arguments are unused. */
927 SLJIT_UNUSED_ARG(compiler);
928 SLJIT_UNUSED_ARG(op);
929
930 SLJIT_ASSERT((op >= SLJIT_BREAKPOINT && op <= SLJIT_SMUL)
931 || ((op & ~SLJIT_INT_OP) >= SLJIT_UDIV && (op & ~SLJIT_INT_OP) <= SLJIT_SDIV));
932 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
933 if (SLJIT_UNLIKELY(!!compiler->verbose))
934 fprintf(compiler->verbose, " %s%s\n", !(op & SLJIT_INT_OP) ? "" : "i", op_names[GET_OPCODE(op)]);
935 #endif
936 }
937
938 static SLJIT_INLINE void check_sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
939 sljit_si dst, sljit_sw dstw,
940 sljit_si src, sljit_sw srcw)
941 {
942 /* If debug and verbose are disabled, all arguments are unused. */
943 SLJIT_UNUSED_ARG(compiler);
944 SLJIT_UNUSED_ARG(op);
945 SLJIT_UNUSED_ARG(dst);
946 SLJIT_UNUSED_ARG(dstw);
947 SLJIT_UNUSED_ARG(src);
948 SLJIT_UNUSED_ARG(srcw);
949
950 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
951 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
952 compiler->skip_checks = 0;
953 return;
954 }
955 #endif
956
957 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
958 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
959 FUNCTION_CHECK_OP();
960 FUNCTION_CHECK_SRC(src, srcw);
961 FUNCTION_CHECK_DST(dst, dstw);
962 FUNCTION_CHECK_OP1();
963 #endif
964 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
965 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
966 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op_names[GET_OPCODE(op)],
967 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_S) ? "" : ".s", !(op & SLJIT_SET_U) ? "" : ".u",
968 !(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
969 sljit_verbose_param(dst, dstw);
970 fprintf(compiler->verbose, ", ");
971 sljit_verbose_param(src, srcw);
972 fprintf(compiler->verbose, "\n");
973 }
974 #endif
975 }
976
977 static SLJIT_INLINE void check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
978 sljit_si dst, sljit_sw dstw,
979 sljit_si src1, sljit_sw src1w,
980 sljit_si src2, sljit_sw src2w)
981 {
982 /* If debug and verbose are disabled, all arguments are unused. */
983 SLJIT_UNUSED_ARG(compiler);
984 SLJIT_UNUSED_ARG(op);
985 SLJIT_UNUSED_ARG(dst);
986 SLJIT_UNUSED_ARG(dstw);
987 SLJIT_UNUSED_ARG(src1);
988 SLJIT_UNUSED_ARG(src1w);
989 SLJIT_UNUSED_ARG(src2);
990 SLJIT_UNUSED_ARG(src2w);
991
992 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
993 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
994 compiler->skip_checks = 0;
995 return;
996 }
997 #endif
998
999 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
1000 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1001 FUNCTION_CHECK_OP();
1002 FUNCTION_CHECK_SRC(src1, src1w);
1003 FUNCTION_CHECK_SRC(src2, src2w);
1004 FUNCTION_CHECK_DST(dst, dstw);
1005 #endif
1006 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1007 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1008 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op_names[GET_OPCODE(op)],
1009 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_S) ? "" : ".s", !(op & SLJIT_SET_U) ? "" : ".u",
1010 !(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1011 sljit_verbose_param(dst, dstw);
1012 fprintf(compiler->verbose, ", ");
1013 sljit_verbose_param(src1, src1w);
1014 fprintf(compiler->verbose, ", ");
1015 sljit_verbose_param(src2, src2w);
1016 fprintf(compiler->verbose, "\n");
1017 }
1018 #endif
1019 }
1020
1021 static SLJIT_INLINE void check_sljit_get_register_index(sljit_si reg)
1022 {
1023 SLJIT_UNUSED_ARG(reg);
1024 SLJIT_ASSERT(reg > 0 && reg <= SLJIT_NO_REGISTERS);
1025 }
1026
1027 static SLJIT_INLINE void check_sljit_get_float_register_index(sljit_si reg)
1028 {
1029 SLJIT_UNUSED_ARG(reg);
1030 SLJIT_ASSERT(reg > 0 && reg <= SLJIT_NO_FLOAT_REGISTERS);
1031 }
1032
1033 static SLJIT_INLINE void check_sljit_emit_op_custom(struct sljit_compiler *compiler,
1034 void *instruction, sljit_si size)
1035 {
1036 SLJIT_UNUSED_ARG(compiler);
1037 SLJIT_UNUSED_ARG(instruction);
1038 SLJIT_UNUSED_ARG(size);
1039 SLJIT_ASSERT(instruction);
1040 }
1041
1042 static SLJIT_INLINE void check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1043 sljit_si dst, sljit_sw dstw,
1044 sljit_si src, sljit_sw srcw)
1045 {
1046 /* If debug and verbose are disabled, all arguments are unused. */
1047 SLJIT_UNUSED_ARG(compiler);
1048 SLJIT_UNUSED_ARG(op);
1049 SLJIT_UNUSED_ARG(dst);
1050 SLJIT_UNUSED_ARG(dstw);
1051 SLJIT_UNUSED_ARG(src);
1052 SLJIT_UNUSED_ARG(srcw);
1053
1054 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1055 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1056 compiler->skip_checks = 0;
1057 return;
1058 }
1059 #endif
1060
1061 SLJIT_ASSERT(sljit_is_fpu_available());
1062 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_CMPD && GET_OPCODE(op) <= SLJIT_ABSD);
1063 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1064 FUNCTION_CHECK_OP();
1065 FUNCTION_FCHECK(src, srcw);
1066 FUNCTION_FCHECK(dst, dstw);
1067 #endif
1068 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1069 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1070 fprintf(compiler->verbose, " %s%s%s%s ", op_names[GET_OPCODE(op)], (op & SLJIT_SINGLE_OP) ? "s" : "d",
1071 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_S) ? "" : ".s");
1072 sljit_verbose_fparam(dst, dstw);
1073 fprintf(compiler->verbose, ", ");
1074 sljit_verbose_fparam(src, srcw);
1075 fprintf(compiler->verbose, "\n");
1076 }
1077 #endif
1078 }
1079
1080 static SLJIT_INLINE void check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1081 sljit_si dst, sljit_sw dstw,
1082 sljit_si src1, sljit_sw src1w,
1083 sljit_si src2, sljit_sw src2w)
1084 {
1085 /* If debug and verbose are disabled, all arguments are unused. */
1086 SLJIT_UNUSED_ARG(compiler);
1087 SLJIT_UNUSED_ARG(op);
1088 SLJIT_UNUSED_ARG(dst);
1089 SLJIT_UNUSED_ARG(dstw);
1090 SLJIT_UNUSED_ARG(src1);
1091 SLJIT_UNUSED_ARG(src1w);
1092 SLJIT_UNUSED_ARG(src2);
1093 SLJIT_UNUSED_ARG(src2w);
1094
1095 SLJIT_ASSERT(sljit_is_fpu_available());
1096 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_ADDD && GET_OPCODE(op) <= SLJIT_DIVD);
1097 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1098 FUNCTION_CHECK_OP();
1099 FUNCTION_FCHECK(src1, src1w);
1100 FUNCTION_FCHECK(src2, src2w);
1101 FUNCTION_FCHECK(dst, dstw);
1102 #endif
1103 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1104 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1105 fprintf(compiler->verbose, " %s%s ", op_names[GET_OPCODE(op)], (op & SLJIT_SINGLE_OP) ? "s" : "d");
1106 sljit_verbose_fparam(dst, dstw);
1107 fprintf(compiler->verbose, ", ");
1108 sljit_verbose_fparam(src1, src1w);
1109 fprintf(compiler->verbose, ", ");
1110 sljit_verbose_fparam(src2, src2w);
1111 fprintf(compiler->verbose, "\n");
1112 }
1113 #endif
1114 }
1115
1116 static SLJIT_INLINE void check_sljit_emit_label(struct sljit_compiler *compiler)
1117 {
1118 /* If debug and verbose are disabled, all arguments are unused. */
1119 SLJIT_UNUSED_ARG(compiler);
1120
1121 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1122 if (SLJIT_UNLIKELY(!!compiler->verbose))
1123 fprintf(compiler->verbose, "label:\n");
1124 #endif
1125 }
1126
1127 static SLJIT_INLINE void check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1128 {
1129 /* If debug and verbose are disabled, all arguments are unused. */
1130 SLJIT_UNUSED_ARG(compiler);
1131 SLJIT_UNUSED_ARG(type);
1132
1133 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1134 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1135 compiler->skip_checks = 0;
1136 return;
1137 }
1138 #endif
1139
1140 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1141 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_EQUAL && (type & 0xff) <= SLJIT_CALL3);
1142 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1143 if (SLJIT_UNLIKELY(!!compiler->verbose))
1144 fprintf(compiler->verbose, " jump%s.%s\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1145 #endif
1146 }
1147
1148 static SLJIT_INLINE void check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1149 sljit_si src1, sljit_sw src1w,
1150 sljit_si src2, sljit_sw src2w)
1151 {
1152 SLJIT_UNUSED_ARG(compiler);
1153 SLJIT_UNUSED_ARG(type);
1154 SLJIT_UNUSED_ARG(src1);
1155 SLJIT_UNUSED_ARG(src1w);
1156 SLJIT_UNUSED_ARG(src2);
1157 SLJIT_UNUSED_ARG(src2w);
1158
1159 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_INT_OP)));
1160 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_EQUAL && (type & 0xff) <= SLJIT_C_SIG_LESS_EQUAL);
1161 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1162 FUNCTION_CHECK_SRC(src1, src1w);
1163 FUNCTION_CHECK_SRC(src2, src2w);
1164 #endif
1165 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1166 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1167 fprintf(compiler->verbose, " %scmp%s.%s ", !(type & SLJIT_INT_OP) ? "" : "i", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1168 sljit_verbose_param(src1, src1w);
1169 fprintf(compiler->verbose, ", ");
1170 sljit_verbose_param(src2, src2w);
1171 fprintf(compiler->verbose, "\n");
1172 }
1173 #endif
1174 }
1175
1176 static SLJIT_INLINE void check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1177 sljit_si src1, sljit_sw src1w,
1178 sljit_si src2, sljit_sw src2w)
1179 {
1180 SLJIT_UNUSED_ARG(compiler);
1181 SLJIT_UNUSED_ARG(type);
1182 SLJIT_UNUSED_ARG(src1);
1183 SLJIT_UNUSED_ARG(src1w);
1184 SLJIT_UNUSED_ARG(src2);
1185 SLJIT_UNUSED_ARG(src2w);
1186
1187 SLJIT_ASSERT(sljit_is_fpu_available());
1188 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_SINGLE_OP)));
1189 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_FLOAT_EQUAL && (type & 0xff) <= SLJIT_C_FLOAT_ORDERED);
1190 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1191 FUNCTION_FCHECK(src1, src1w);
1192 FUNCTION_FCHECK(src2, src2w);
1193 #endif
1194 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1195 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1196 fprintf(compiler->verbose, " %scmp%s.%s ", (type & SLJIT_SINGLE_OP) ? "s" : "d",
1197 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1198 sljit_verbose_fparam(src1, src1w);
1199 fprintf(compiler->verbose, ", ");
1200 sljit_verbose_fparam(src2, src2w);
1201 fprintf(compiler->verbose, "\n");
1202 }
1203 #endif
1204 }
1205
1206 static SLJIT_INLINE void check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1207 {
1208 /* If debug and verbose are disabled, all arguments are unused. */
1209 SLJIT_UNUSED_ARG(compiler);
1210 SLJIT_UNUSED_ARG(type);
1211 SLJIT_UNUSED_ARG(src);
1212 SLJIT_UNUSED_ARG(srcw);
1213
1214 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1215 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1216 compiler->skip_checks = 0;
1217 return;
1218 }
1219 #endif
1220
1221 SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1222 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1223 FUNCTION_CHECK_SRC(src, srcw);
1224 #endif
1225 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1226 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1227 fprintf(compiler->verbose, " ijump.%s ", jump_names[type]);
1228 sljit_verbose_param(src, srcw);
1229 fprintf(compiler->verbose, "\n");
1230 }
1231 #endif
1232 }
1233
1234 static SLJIT_INLINE void check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1235 sljit_si dst, sljit_sw dstw,
1236 sljit_si src, sljit_sw srcw,
1237 sljit_si type)
1238 {
1239 /* If debug and verbose are disabled, all arguments are unused. */
1240 SLJIT_UNUSED_ARG(compiler);
1241 SLJIT_UNUSED_ARG(op);
1242 SLJIT_UNUSED_ARG(dst);
1243 SLJIT_UNUSED_ARG(dstw);
1244 SLJIT_UNUSED_ARG(src);
1245 SLJIT_UNUSED_ARG(srcw);
1246 SLJIT_UNUSED_ARG(type);
1247
1248 SLJIT_ASSERT(type >= SLJIT_C_EQUAL && type < SLJIT_JUMP);
1249 SLJIT_ASSERT(op == SLJIT_MOV || GET_OPCODE(op) == SLJIT_MOV_UI || GET_OPCODE(op) == SLJIT_MOV_SI
1250 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1251 SLJIT_ASSERT((op & (SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C)) == 0);
1252 SLJIT_ASSERT((op & (SLJIT_SET_E | SLJIT_KEEP_FLAGS)) != (SLJIT_SET_E | SLJIT_KEEP_FLAGS));
1253 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1254 if (GET_OPCODE(op) < SLJIT_ADD) {
1255 SLJIT_ASSERT(src == SLJIT_UNUSED && srcw == 0);
1256 } else {
1257 SLJIT_ASSERT(src == dst && srcw == dstw);
1258 }
1259 FUNCTION_CHECK_DST(dst, dstw);
1260 #endif
1261 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1262 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1263 fprintf(compiler->verbose, " %sflags.%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i",
1264 op_names[GET_OPCODE(op)], !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1265 sljit_verbose_param(dst, dstw);
1266 if (src != SLJIT_UNUSED) {
1267 fprintf(compiler->verbose, ", ");
1268 sljit_verbose_param(src, srcw);
1269 }
1270 fprintf(compiler->verbose, ", %s\n", jump_names[type]);
1271 }
1272 #endif
1273 }
1274
1275 static SLJIT_INLINE void check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1276 {
1277 SLJIT_UNUSED_ARG(compiler);
1278 SLJIT_UNUSED_ARG(dst);
1279 SLJIT_UNUSED_ARG(dstw);
1280 SLJIT_UNUSED_ARG(offset);
1281
1282 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1283 FUNCTION_CHECK_DST(dst, dstw);
1284 #endif
1285 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1286 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1287 fprintf(compiler->verbose, " local_base ");
1288 sljit_verbose_param(dst, dstw);
1289 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1290 }
1291 #endif
1292 }
1293
1294 static SLJIT_INLINE void check_sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value)
1295 {
1296 /* If debug and verbose are disabled, all arguments are unused. */
1297 SLJIT_UNUSED_ARG(compiler);
1298 SLJIT_UNUSED_ARG(dst);
1299 SLJIT_UNUSED_ARG(dstw);
1300 SLJIT_UNUSED_ARG(init_value);
1301
1302 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1303 FUNCTION_CHECK_DST(dst, dstw);
1304 #endif
1305 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1306 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1307 fprintf(compiler->verbose, " const ");
1308 sljit_verbose_param(dst, dstw);
1309 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1310 }
1311 #endif
1312 }
1313
1314 static SLJIT_INLINE sljit_si emit_mov_before_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1315 {
1316 /* Return if don't need to do anything. */
1317 if (op == SLJIT_UNUSED)
1318 return SLJIT_SUCCESS;
1319
1320 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1321 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1322 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1323 return SLJIT_SUCCESS;
1324 #else
1325 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_UI || op == SLJIT_MOV_SI || op == SLJIT_MOV_P))
1326 return SLJIT_SUCCESS;
1327 #endif
1328
1329 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1330 compiler->skip_checks = 1;
1331 #endif
1332 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1333 }
1334
1335 /* CPU description section */
1336
1337 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1338 #define SLJIT_CPUINFO_PART1 " 32bit ("
1339 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1340 #define SLJIT_CPUINFO_PART1 " 64bit ("
1341 #else
1342 #error "Internal error: CPU type info missing"
1343 #endif
1344
1345 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1346 #define SLJIT_CPUINFO_PART2 "little endian + "
1347 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1348 #define SLJIT_CPUINFO_PART2 "big endian + "
1349 #else
1350 #error "Internal error: CPU type info missing"
1351 #endif
1352
1353 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
1354 #define SLJIT_CPUINFO_PART3 "unaligned)"
1355 #else
1356 #define SLJIT_CPUINFO_PART3 "aligned)"
1357 #endif
1358
1359 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
1360
1361 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
1362 # include "sljitNativeX86_common.c"
1363 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1364 # include "sljitNativeX86_common.c"
1365 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1366 # include "sljitNativeARM_32.c"
1367 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1368 # include "sljitNativeARM_32.c"
1369 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1370 # include "sljitNativeARM_T2_32.c"
1371 #elif (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1372 # include "sljitNativeARM_64.c"
1373 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
1374 # include "sljitNativePPC_common.c"
1375 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
1376 # include "sljitNativePPC_common.c"
1377 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1378 # include "sljitNativeMIPS_common.c"
1379 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1380 # include "sljitNativeSPARC_common.c"
1381 #elif (defined SLJIT_CONFIG_TILEGX && SLJIT_CONFIG_TILEGX)
1382 # include "sljitNativeTILEGX_64.c"
1383 #endif
1384
1385 #if !(defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1386
1387 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1388 sljit_si src1, sljit_sw src1w,
1389 sljit_si src2, sljit_sw src2w)
1390 {
1391 /* Default compare for most architectures. */
1392 sljit_si flags, tmp_src, condition;
1393 sljit_sw tmp_srcw;
1394
1395 CHECK_ERROR_PTR();
1396 check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
1397
1398 condition = type & 0xff;
1399 #if (defined SLJIT_CONFIG_ARM_64 && SLJIT_CONFIG_ARM_64)
1400 if ((condition == SLJIT_C_EQUAL || condition == SLJIT_C_NOT_EQUAL)) {
1401 if ((src1 & SLJIT_IMM) && !src1w) {
1402 src1 = src2;
1403 src1w = src2w;
1404 src2 = SLJIT_IMM;
1405 src2w = 0;
1406 }
1407 if ((src2 & SLJIT_IMM) && !src2w)
1408 return emit_cmp_to0(compiler, type, src1, src1w);
1409 }
1410 #endif
1411
1412 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1413 /* Immediate is prefered as second argument by most architectures. */
1414 switch (condition) {
1415 case SLJIT_C_LESS:
1416 condition = SLJIT_C_GREATER;
1417 break;
1418 case SLJIT_C_GREATER_EQUAL:
1419 condition = SLJIT_C_LESS_EQUAL;
1420 break;
1421 case SLJIT_C_GREATER:
1422 condition = SLJIT_C_LESS;
1423 break;
1424 case SLJIT_C_LESS_EQUAL:
1425 condition = SLJIT_C_GREATER_EQUAL;
1426 break;
1427 case SLJIT_C_SIG_LESS:
1428 condition = SLJIT_C_SIG_GREATER;
1429 break;
1430 case SLJIT_C_SIG_GREATER_EQUAL:
1431 condition = SLJIT_C_SIG_LESS_EQUAL;
1432 break;
1433 case SLJIT_C_SIG_GREATER:
1434 condition = SLJIT_C_SIG_LESS;
1435 break;
1436 case SLJIT_C_SIG_LESS_EQUAL:
1437 condition = SLJIT_C_SIG_GREATER_EQUAL;
1438 break;
1439 }
1440 type = condition | (type & (SLJIT_INT_OP | SLJIT_REWRITABLE_JUMP));
1441 tmp_src = src1;
1442 src1 = src2;
1443 src2 = tmp_src;
1444 tmp_srcw = src1w;
1445 src1w = src2w;
1446 src2w = tmp_srcw;
1447 }
1448
1449 if (condition <= SLJIT_C_NOT_ZERO)
1450 flags = SLJIT_SET_E;
1451 else if (condition <= SLJIT_C_LESS_EQUAL)
1452 flags = SLJIT_SET_U;
1453 else
1454 flags = SLJIT_SET_S;
1455
1456 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1457 compiler->skip_checks = 1;
1458 #endif
1459 PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_INT_OP),
1460 SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1461 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1462 compiler->skip_checks = 1;
1463 #endif
1464 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1465 }
1466
1467 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1468 sljit_si src1, sljit_sw src1w,
1469 sljit_si src2, sljit_sw src2w)
1470 {
1471 sljit_si flags, condition;
1472
1473 check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w);
1474
1475 condition = type & 0xff;
1476 flags = (condition <= SLJIT_C_FLOAT_NOT_EQUAL) ? SLJIT_SET_E : SLJIT_SET_S;
1477 if (type & SLJIT_SINGLE_OP)
1478 flags |= SLJIT_SINGLE_OP;
1479
1480 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1481 compiler->skip_checks = 1;
1482 #endif
1483 sljit_emit_fop1(compiler, SLJIT_CMPD | flags, src1, src1w, src2, src2w);
1484
1485 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1486 compiler->skip_checks = 1;
1487 #endif
1488 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1489 }
1490
1491 #endif
1492
1493 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) && !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1494
1495 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1496 {
1497 CHECK_ERROR();
1498 check_sljit_get_local_base(compiler, dst, dstw, offset);
1499
1500 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_LOCALS_REG), offset);
1501 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1502 compiler->skip_checks = 1;
1503 #endif
1504 if (offset != 0)
1505 return sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, SLJIT_LOCALS_REG, 0, SLJIT_IMM, offset);
1506 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_LOCALS_REG, 0);
1507 }
1508
1509 #endif
1510
1511 #else /* SLJIT_CONFIG_UNSUPPORTED */
1512
1513 /* Empty function bodies for those machines, which are not (yet) supported. */
1514
1515 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
1516 {
1517 return "unsupported";
1518 }
1519
1520 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
1521 {
1522 SLJIT_ASSERT_STOP();
1523 return NULL;
1524 }
1525
1526 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
1527 {
1528 SLJIT_UNUSED_ARG(compiler);
1529 SLJIT_ASSERT_STOP();
1530 }
1531
1532 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
1533 {
1534 SLJIT_UNUSED_ARG(compiler);
1535 SLJIT_UNUSED_ARG(size);
1536 SLJIT_ASSERT_STOP();
1537 return NULL;
1538 }
1539
1540 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1541 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1542 {
1543 SLJIT_UNUSED_ARG(compiler);
1544 SLJIT_UNUSED_ARG(verbose);
1545 SLJIT_ASSERT_STOP();
1546 }
1547 #endif
1548
1549 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
1550 {
1551 SLJIT_UNUSED_ARG(compiler);
1552 SLJIT_ASSERT_STOP();
1553 return NULL;
1554 }
1555
1556 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
1557 {
1558 SLJIT_UNUSED_ARG(code);
1559 SLJIT_ASSERT_STOP();
1560 }
1561
1562 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_enter(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
1563 {
1564 SLJIT_UNUSED_ARG(compiler);
1565 SLJIT_UNUSED_ARG(args);
1566 SLJIT_UNUSED_ARG(scratches);
1567 SLJIT_UNUSED_ARG(saveds);
1568 SLJIT_UNUSED_ARG(local_size);
1569 SLJIT_ASSERT_STOP();
1570 return SLJIT_ERR_UNSUPPORTED;
1571 }
1572
1573 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
1574 {
1575 SLJIT_UNUSED_ARG(compiler);
1576 SLJIT_UNUSED_ARG(args);
1577 SLJIT_UNUSED_ARG(scratches);
1578 SLJIT_UNUSED_ARG(saveds);
1579 SLJIT_UNUSED_ARG(local_size);
1580 SLJIT_ASSERT_STOP();
1581 }
1582
1583 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1584 {
1585 SLJIT_UNUSED_ARG(compiler);
1586 SLJIT_UNUSED_ARG(op);
1587 SLJIT_UNUSED_ARG(src);
1588 SLJIT_UNUSED_ARG(srcw);
1589 SLJIT_ASSERT_STOP();
1590 return SLJIT_ERR_UNSUPPORTED;
1591 }
1592
1593 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1594 {
1595 SLJIT_UNUSED_ARG(compiler);
1596 SLJIT_UNUSED_ARG(dst);
1597 SLJIT_UNUSED_ARG(dstw);
1598 SLJIT_ASSERT_STOP();
1599 return SLJIT_ERR_UNSUPPORTED;
1600 }
1601
1602 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1603 {
1604 SLJIT_UNUSED_ARG(compiler);
1605 SLJIT_UNUSED_ARG(src);
1606 SLJIT_UNUSED_ARG(srcw);
1607 SLJIT_ASSERT_STOP();
1608 return SLJIT_ERR_UNSUPPORTED;
1609 }
1610
1611 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1612 {
1613 SLJIT_UNUSED_ARG(compiler);
1614 SLJIT_UNUSED_ARG(op);
1615 SLJIT_ASSERT_STOP();
1616 return SLJIT_ERR_UNSUPPORTED;
1617 }
1618
1619 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1620 sljit_si dst, sljit_sw dstw,
1621 sljit_si src, sljit_sw srcw)
1622 {
1623 SLJIT_UNUSED_ARG(compiler);
1624 SLJIT_UNUSED_ARG(op);
1625 SLJIT_UNUSED_ARG(dst);
1626 SLJIT_UNUSED_ARG(dstw);
1627 SLJIT_UNUSED_ARG(src);
1628 SLJIT_UNUSED_ARG(srcw);
1629 SLJIT_ASSERT_STOP();
1630 return SLJIT_ERR_UNSUPPORTED;
1631 }
1632
1633 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1634 sljit_si dst, sljit_sw dstw,
1635 sljit_si src1, sljit_sw src1w,
1636 sljit_si src2, sljit_sw src2w)
1637 {
1638 SLJIT_UNUSED_ARG(compiler);
1639 SLJIT_UNUSED_ARG(op);
1640 SLJIT_UNUSED_ARG(dst);
1641 SLJIT_UNUSED_ARG(dstw);
1642 SLJIT_UNUSED_ARG(src1);
1643 SLJIT_UNUSED_ARG(src1w);
1644 SLJIT_UNUSED_ARG(src2);
1645 SLJIT_UNUSED_ARG(src2w);
1646 SLJIT_ASSERT_STOP();
1647 return SLJIT_ERR_UNSUPPORTED;
1648 }
1649
1650 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg)
1651 {
1652 SLJIT_ASSERT_STOP();
1653 return reg;
1654 }
1655
1656 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
1657 void *instruction, sljit_si size)
1658 {
1659 SLJIT_UNUSED_ARG(compiler);
1660 SLJIT_UNUSED_ARG(instruction);
1661 SLJIT_UNUSED_ARG(size);
1662 SLJIT_ASSERT_STOP();
1663 return SLJIT_ERR_UNSUPPORTED;
1664 }
1665
1666 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void)
1667 {
1668 SLJIT_ASSERT_STOP();
1669 return 0;
1670 }
1671
1672 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1673 sljit_si dst, sljit_sw dstw,
1674 sljit_si src, sljit_sw srcw)
1675 {
1676 SLJIT_UNUSED_ARG(compiler);
1677 SLJIT_UNUSED_ARG(op);
1678 SLJIT_UNUSED_ARG(dst);
1679 SLJIT_UNUSED_ARG(dstw);
1680 SLJIT_UNUSED_ARG(src);
1681 SLJIT_UNUSED_ARG(srcw);
1682 SLJIT_ASSERT_STOP();
1683 return SLJIT_ERR_UNSUPPORTED;
1684 }
1685
1686 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1687 sljit_si dst, sljit_sw dstw,
1688 sljit_si src1, sljit_sw src1w,
1689 sljit_si src2, sljit_sw src2w)
1690 {
1691 SLJIT_UNUSED_ARG(compiler);
1692 SLJIT_UNUSED_ARG(op);
1693 SLJIT_UNUSED_ARG(dst);
1694 SLJIT_UNUSED_ARG(dstw);
1695 SLJIT_UNUSED_ARG(src1);
1696 SLJIT_UNUSED_ARG(src1w);
1697 SLJIT_UNUSED_ARG(src2);
1698 SLJIT_UNUSED_ARG(src2w);
1699 SLJIT_ASSERT_STOP();
1700 return SLJIT_ERR_UNSUPPORTED;
1701 }
1702
1703 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1704 {
1705 SLJIT_UNUSED_ARG(compiler);
1706 SLJIT_ASSERT_STOP();
1707 return NULL;
1708 }
1709
1710 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1711 {
1712 SLJIT_UNUSED_ARG(compiler);
1713 SLJIT_UNUSED_ARG(type);
1714 SLJIT_ASSERT_STOP();
1715 return NULL;
1716 }
1717
1718 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1719 sljit_si src1, sljit_sw src1w,
1720 sljit_si src2, sljit_sw src2w)
1721 {
1722 SLJIT_UNUSED_ARG(compiler);
1723 SLJIT_UNUSED_ARG(type);
1724 SLJIT_UNUSED_ARG(src1);
1725 SLJIT_UNUSED_ARG(src1w);
1726 SLJIT_UNUSED_ARG(src2);
1727 SLJIT_UNUSED_ARG(src2w);
1728 SLJIT_ASSERT_STOP();
1729 return NULL;
1730 }
1731
1732 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1733 sljit_si src1, sljit_sw src1w,
1734 sljit_si src2, sljit_sw src2w)
1735 {
1736 SLJIT_UNUSED_ARG(compiler);
1737 SLJIT_UNUSED_ARG(type);
1738 SLJIT_UNUSED_ARG(src1);
1739 SLJIT_UNUSED_ARG(src1w);
1740 SLJIT_UNUSED_ARG(src2);
1741 SLJIT_UNUSED_ARG(src2w);
1742 SLJIT_ASSERT_STOP();
1743 return NULL;
1744 }
1745
1746 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
1747 {
1748 SLJIT_UNUSED_ARG(jump);
1749 SLJIT_UNUSED_ARG(label);
1750 SLJIT_ASSERT_STOP();
1751 }
1752
1753 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
1754 {
1755 SLJIT_UNUSED_ARG(jump);
1756 SLJIT_UNUSED_ARG(target);
1757 SLJIT_ASSERT_STOP();
1758 }
1759
1760 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1761 {
1762 SLJIT_UNUSED_ARG(compiler);
1763 SLJIT_UNUSED_ARG(type);
1764 SLJIT_UNUSED_ARG(src);
1765 SLJIT_UNUSED_ARG(srcw);
1766 SLJIT_ASSERT_STOP();
1767 return SLJIT_ERR_UNSUPPORTED;
1768 }
1769
1770 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1771 sljit_si dst, sljit_sw dstw,
1772 sljit_si src, sljit_sw srcw,
1773 sljit_si type)
1774 {
1775 SLJIT_UNUSED_ARG(compiler);
1776 SLJIT_UNUSED_ARG(op);
1777 SLJIT_UNUSED_ARG(dst);
1778 SLJIT_UNUSED_ARG(dstw);
1779 SLJIT_UNUSED_ARG(src);
1780 SLJIT_UNUSED_ARG(srcw);
1781 SLJIT_UNUSED_ARG(type);
1782 SLJIT_ASSERT_STOP();
1783 return SLJIT_ERR_UNSUPPORTED;
1784 }
1785
1786 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1787 {
1788 SLJIT_UNUSED_ARG(compiler);
1789 SLJIT_UNUSED_ARG(dst);
1790 SLJIT_UNUSED_ARG(dstw);
1791 SLJIT_UNUSED_ARG(offset);
1792 SLJIT_ASSERT_STOP();
1793 return SLJIT_ERR_UNSUPPORTED;
1794 }
1795
1796 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw initval)
1797 {
1798 SLJIT_UNUSED_ARG(compiler);
1799 SLJIT_UNUSED_ARG(dst);
1800 SLJIT_UNUSED_ARG(dstw);
1801 SLJIT_UNUSED_ARG(initval);
1802 SLJIT_ASSERT_STOP();
1803 return NULL;
1804 }
1805
1806 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
1807 {
1808 SLJIT_UNUSED_ARG(addr);
1809 SLJIT_UNUSED_ARG(new_addr);
1810 SLJIT_ASSERT_STOP();
1811 }
1812
1813 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant)
1814 {
1815 SLJIT_UNUSED_ARG(addr);
1816 SLJIT_UNUSED_ARG(new_constant);
1817 SLJIT_ASSERT_STOP();
1818 }
1819
1820 #endif

  ViewVC Help
Powered by ViewVC 1.1.5