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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 662 - (show annotations)
Mon Aug 22 14:35:22 2011 UTC (3 years, 9 months ago) by ph10
File MIME type: text/plain
File size: 43432 byte(s)
Error occurred while calculating annotation data.
JIT compiler source
1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2010 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_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))
93
94 #define BUF_SIZE 4096
95
96 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
97 #define ABUF_SIZE 2048
98 #else
99 #define ABUF_SIZE 4096
100 #endif
101
102 /* Jump flags. */
103 #define JUMP_LABEL 0x1
104 #define JUMP_ADDR 0x2
105 /* SLJIT_REWRITABLE_JUMP is 0x1000. */
106
107 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
108 #define PATCH_MB 0x4
109 #define PATCH_MW 0x8
110 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
111 #define PATCH_MD 0x10
112 #endif
113 #endif
114
115 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) || (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
116 #define IS_BL 0x4
117 #define PATCH_B 0x8
118 #endif
119
120 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
121 #define CPOOL_SIZE 512
122 #endif
123
124 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
125 #define IS_CONDITIONAL 0x04
126 #define IS_BL 0x08
127 /* cannot be encoded as branch */
128 #define B_TYPE0 0x00
129 /* conditional + imm8 */
130 #define B_TYPE1 0x10
131 /* conditional + imm20 */
132 #define B_TYPE2 0x20
133 /* IT + imm24 */
134 #define B_TYPE3 0x30
135 /* imm11 */
136 #define B_TYPE4 0x40
137 /* imm24 */
138 #define B_TYPE5 0x50
139 /* BL + imm24 */
140 #define BL_TYPE6 0x60
141 /* 0xf00 cc code for branches */
142 #endif
143
144 #if (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
145 #define UNCOND_B 0x04
146 #define PATCH_B 0x08
147 #define ABSOLUTE_B 0x10
148 #endif
149
150 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
151 #define IS_MOVABLE 0x04
152 #define IS_JAL 0x08
153 #define IS_BIT26_COND 0x10
154 #define IS_BIT16_COND 0x20
155
156 #define IS_COND (IS_BIT26_COND | IS_BIT16_COND)
157
158 #define PATCH_B 0x40
159 #define PATCH_J 0x80
160
161 /* instruction types */
162 #define UNMOVABLE_INS 0
163 /* 1 - 31 last destination register */
164 /* 32 - 39 FCSR FCC bits */
165 #define FCSR_FCC 32
166 /* no destination (i.e: store) */
167 #define MOVABLE_INS 40
168 #endif
169
170 #endif /* !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED) */
171
172 /* Utils can still be used even if SLJIT_CONFIG_UNSUPPORTED is set. */
173 #include "sljitUtils.c"
174
175 #if !(defined SLJIT_CONFIG_UNSUPPORTED && SLJIT_CONFIG_UNSUPPORTED)
176
177 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
178 #include "sljitExecAllocator.c"
179 #endif
180
181 #if (defined SLJIT_SSE2_AUTO && SLJIT_SSE2_AUTO) && !(defined SLJIT_SSE2 && SLJIT_SSE2)
182 #error SLJIT_SSE2_AUTO cannot be enabled without SLJIT_SSE2
183 #endif
184
185 /* --------------------------------------------------------------------- */
186 /* Public functions */
187 /* --------------------------------------------------------------------- */
188
189 #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)))
190 #define SLJIT_NEEDS_COMPILER_INIT 1
191 static int compiler_initialized = 0;
192 /* A thread safe initialization. */
193 static void init_compiler(void);
194 #endif
195
196 struct sljit_compiler* sljit_create_compiler(void)
197 {
198 struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler));
199 /* Compile time assert. */
200 SLJIT_CONST int minus1[sizeof(sljit_b) == 1 && sizeof(sljit_h) == 2 &&
201 sizeof(sljit_i) == 4 && (sizeof(sljit_w) == 4 || sizeof(sljit_w) == 8) ? 1 : -1] = { -1 };
202
203 if (!compiler)
204 return NULL;
205
206 compiler->error = SLJIT_SUCCESS;
207
208 compiler->labels = NULL;
209 compiler->jumps = NULL;
210 compiler->consts = NULL;
211 compiler->last_label = NULL;
212 compiler->last_jump = NULL;
213 compiler->last_const = NULL;
214
215 compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE);
216 compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE);
217
218 if (!compiler->buf || !compiler->abuf) {
219 if (compiler->buf)
220 SLJIT_FREE(compiler->buf);
221 if (compiler->abuf)
222 SLJIT_FREE(compiler->abuf);
223 SLJIT_FREE(compiler);
224 return NULL;
225 }
226
227 compiler->buf->next = NULL;
228 compiler->buf->used_size = 0;
229 compiler->abuf->next = NULL;
230 compiler->abuf->used_size = 0;
231
232 compiler->temporaries = minus1[0];
233 compiler->generals = minus1[0];
234 compiler->local_size = 0;
235 compiler->size = 0;
236
237 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
238 compiler->args = -1;
239 #endif
240
241 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) || (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
242 compiler->flags_saved = 0;
243 #endif
244
245 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
246 compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw) + CPOOL_SIZE * sizeof(sljit_ub));
247 if (!compiler->cpool) {
248 SLJIT_FREE(compiler->buf);
249 SLJIT_FREE(compiler->abuf);
250 SLJIT_FREE(compiler);
251 return NULL;
252 }
253 compiler->cpool_unique = (sljit_ub*)(compiler->cpool + CPOOL_SIZE);
254 compiler->cpool_diff = 0xffffffff;
255 compiler->cpool_fill = 0;
256 compiler->patches = 0;
257 #endif
258
259 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
260 compiler->has_locals = 0;
261 compiler->delay_slot = UNMOVABLE_INS;
262 #endif
263
264 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
265 compiler->verbose = NULL;
266 #endif
267
268 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
269 compiler->skip_checks = 0;
270 #endif
271
272 #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT)
273 if (!compiler_initialized) {
274 init_compiler();
275 compiler_initialized = 1;
276 }
277 #endif
278
279 return compiler;
280 }
281
282 void sljit_free_compiler(struct sljit_compiler *compiler)
283 {
284 struct sljit_memory_fragment *buf;
285 struct sljit_memory_fragment *curr;
286
287 buf = compiler->buf;
288 while (buf) {
289 curr = buf;
290 buf = buf->next;
291 SLJIT_FREE(curr);
292 }
293
294 buf = compiler->abuf;
295 while (buf) {
296 curr = buf;
297 buf = buf->next;
298 SLJIT_FREE(curr);
299 }
300
301 #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
302 SLJIT_FREE(compiler->cpool);
303 #endif
304 SLJIT_FREE(compiler);
305 }
306
307 #if (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
308 void sljit_free_code(void* code)
309 {
310 /* Remove thumb mode flag. */
311 SLJIT_FREE_EXEC((void*)((sljit_uw)code & ~0x1));
312 }
313 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
314 void sljit_free_code(void* code)
315 {
316 /* Resolve indirection. */
317 code = (void*)(*(sljit_uw*)code);
318 SLJIT_FREE_EXEC(code);
319 }
320 #else
321 void sljit_free_code(void* code)
322 {
323 SLJIT_FREE_EXEC(code);
324 }
325 #endif
326
327 void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
328 {
329 if (SLJIT_LIKELY(!!jump) && SLJIT_LIKELY(!!label)) {
330 jump->flags &= ~JUMP_ADDR;
331 jump->flags |= JUMP_LABEL;
332 jump->u.label = label;
333 }
334 }
335
336 void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
337 {
338 if (SLJIT_LIKELY(!!jump)) {
339 SLJIT_ASSERT(jump->flags & SLJIT_REWRITABLE_JUMP);
340
341 jump->flags &= ~JUMP_LABEL;
342 jump->flags |= JUMP_ADDR;
343 jump->u.target = target;
344 }
345 }
346
347 /* --------------------------------------------------------------------- */
348 /* Private functions */
349 /* --------------------------------------------------------------------- */
350
351 static void* ensure_buf(struct sljit_compiler *compiler, int size)
352 {
353 sljit_ub *ret;
354 struct sljit_memory_fragment *new_frag;
355
356 if (compiler->buf->used_size + size <= (int)(BUF_SIZE - sizeof(sljit_uw) - sizeof(void*))) {
357 ret = compiler->buf->memory + compiler->buf->used_size;
358 compiler->buf->used_size += size;
359 return ret;
360 }
361 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE);
362 PTR_FAIL_IF_NULL(new_frag);
363 new_frag->next = compiler->buf;
364 compiler->buf = new_frag;
365 new_frag->used_size = size;
366 return new_frag->memory;
367 }
368
369 static void* ensure_abuf(struct sljit_compiler *compiler, int size)
370 {
371 sljit_ub *ret;
372 struct sljit_memory_fragment *new_frag;
373
374 if (compiler->abuf->used_size + size <= (int)(ABUF_SIZE - sizeof(sljit_uw) - sizeof(void*))) {
375 ret = compiler->abuf->memory + compiler->abuf->used_size;
376 compiler->abuf->used_size += size;
377 return ret;
378 }
379 new_frag = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE);
380 PTR_FAIL_IF_NULL(new_frag);
381 new_frag->next = compiler->abuf;
382 compiler->abuf = new_frag;
383 new_frag->used_size = size;
384 return new_frag->memory;
385 }
386
387 void* sljit_alloc_memory(struct sljit_compiler *compiler, int size)
388 {
389 CHECK_ERROR_PTR();
390
391 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
392 if (size <= 0 || size > 128)
393 return NULL;
394 size = (size + 7) & ~7;
395 #else
396 if (size <= 0 || size > 64)
397 return NULL;
398 size = (size + 3) & ~3;
399 #endif
400 return ensure_abuf(compiler, size);
401 }
402
403 static SLJIT_INLINE void reverse_buf(struct sljit_compiler *compiler)
404 {
405 struct sljit_memory_fragment *buf = compiler->buf;
406 struct sljit_memory_fragment *prev = NULL;
407 struct sljit_memory_fragment *tmp;
408
409 do {
410 tmp = buf->next;
411 buf->next = prev;
412 prev = buf;
413 buf = tmp;
414 } while (buf != NULL);
415
416 compiler->buf = prev;
417 }
418
419 static SLJIT_INLINE void set_label(struct sljit_label *label, struct sljit_compiler *compiler)
420 {
421 label->next = NULL;
422 label->size = compiler->size;
423 if (compiler->last_label)
424 compiler->last_label->next = label;
425 else
426 compiler->labels = label;
427 compiler->last_label = label;
428 }
429
430 static SLJIT_INLINE void set_jump(struct sljit_jump *jump, struct sljit_compiler *compiler, int flags)
431 {
432 jump->next = NULL;
433 jump->flags = flags;
434 if (compiler->last_jump)
435 compiler->last_jump->next = jump;
436 else
437 compiler->jumps = jump;
438 compiler->last_jump = jump;
439 }
440
441 static SLJIT_INLINE void set_const(struct sljit_const *const_, struct sljit_compiler *compiler)
442 {
443 const_->next = NULL;
444 const_->addr = compiler->size;
445 if (compiler->last_const)
446 compiler->last_const->next = const_;
447 else
448 compiler->consts = const_;
449 compiler->last_const = const_;
450 }
451
452 #define depends_on(exp, reg) \
453 (((exp) & SLJIT_MEM) && (((exp) & 0xf) == reg || (((exp) >> 4) & 0xf) == reg))
454
455 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
456 #define FUNCTION_CHECK_OP() \
457 SLJIT_ASSERT(!GET_FLAGS(op) || !(op & SLJIT_KEEP_FLAGS)); \
458 switch (GET_OPCODE(op)) { \
459 case SLJIT_NOT: \
460 case SLJIT_CLZ: \
461 case SLJIT_AND: \
462 case SLJIT_OR: \
463 case SLJIT_XOR: \
464 case SLJIT_SHL: \
465 case SLJIT_LSHR: \
466 case SLJIT_ASHR: \
467 SLJIT_ASSERT(!(op & (SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C))); \
468 break; \
469 case SLJIT_NEG: \
470 SLJIT_ASSERT(!(op & (SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_C))); \
471 break; \
472 case SLJIT_MUL: \
473 SLJIT_ASSERT(!(op & (SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_C))); \
474 break; \
475 case SLJIT_FCMP: \
476 SLJIT_ASSERT(!(op & (SLJIT_INT_OP | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
477 SLJIT_ASSERT((op & (SLJIT_SET_E | SLJIT_SET_S))); \
478 break; \
479 case SLJIT_ADD: \
480 SLJIT_ASSERT(!(op & (SLJIT_SET_S | SLJIT_SET_U))); \
481 break; \
482 case SLJIT_SUB: \
483 break; \
484 case SLJIT_ADDC: \
485 case SLJIT_SUBC: \
486 SLJIT_ASSERT(!(op & (SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O))); \
487 break; \
488 default: \
489 /* Nothing allowed */ \
490 SLJIT_ASSERT(!(op & (SLJIT_INT_OP | SLJIT_SET_E | SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C | SLJIT_KEEP_FLAGS))); \
491 break; \
492 }
493
494 #define FUNCTION_CHECK_IS_REG(r) \
495 ((r) == SLJIT_UNUSED || (r) == SLJIT_LOCALS_REG || \
496 ((r) >= SLJIT_TEMPORARY_REG1 && (r) <= SLJIT_TEMPORARY_REG3 && (r) <= SLJIT_TEMPORARY_REG1 - 1 + compiler->temporaries) || \
497 ((r) >= SLJIT_GENERAL_REG1 && (r) <= SLJIT_GENERAL_REG3 && (r) <= SLJIT_GENERAL_REG1 - 1 + compiler->generals)) \
498
499 #define FUNCTION_CHECK_SRC(p, i) \
500 SLJIT_ASSERT(compiler->temporaries != -1 && compiler->generals != -1); \
501 if (((p) >= SLJIT_TEMPORARY_REG1 && (p) <= SLJIT_TEMPORARY_REG1 - 1 + compiler->temporaries) || \
502 ((p) >= SLJIT_GENERAL_REG1 && (p) <= SLJIT_GENERAL_REG1 - 1 + compiler->generals) || \
503 (p) == SLJIT_LOCALS_REG) \
504 SLJIT_ASSERT(i == 0); \
505 else if ((p) == SLJIT_IMM) \
506 ; \
507 else if ((p) & SLJIT_MEM) { \
508 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG((p) & 0xf)); \
509 if ((p) & 0xf0) { \
510 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG(((p) >> 4) & 0xf)); \
511 SLJIT_ASSERT(((p) & 0xf0) != (SLJIT_LOCALS_REG << 4) && !(i & ~0x3)); \
512 } else \
513 SLJIT_ASSERT((((p) >> 4) & 0xf) == 0); \
514 SLJIT_ASSERT(((p) >> 9) == 0); \
515 } \
516 else \
517 SLJIT_ASSERT_STOP();
518
519 #define FUNCTION_CHECK_DST(p, i) \
520 SLJIT_ASSERT(compiler->temporaries != -1 && compiler->generals != -1); \
521 if (((p) >= SLJIT_TEMPORARY_REG1 && (p) <= SLJIT_TEMPORARY_REG1 - 1 + compiler->temporaries) || \
522 ((p) >= SLJIT_GENERAL_REG1 && (p) <= SLJIT_GENERAL_REG1 - 1 + compiler->generals) || \
523 (p) == SLJIT_UNUSED) \
524 SLJIT_ASSERT(i == 0); \
525 else if ((p) & SLJIT_MEM) { \
526 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG((p) & 0xf)); \
527 if ((p) & 0xf0) { \
528 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG(((p) >> 4) & 0xf)); \
529 SLJIT_ASSERT(((p) & 0xf0) != (SLJIT_LOCALS_REG << 4) && !(i & ~0x3)); \
530 } else \
531 SLJIT_ASSERT((((p) >> 4) & 0xf) == 0); \
532 SLJIT_ASSERT(((p) >> 9) == 0); \
533 } \
534 else \
535 SLJIT_ASSERT_STOP();
536
537 #define FUNCTION_FCHECK(p, i) \
538 if ((p) >= SLJIT_FLOAT_REG1 && (p) <= SLJIT_FLOAT_REG4) \
539 SLJIT_ASSERT(i == 0); \
540 else if ((p) & SLJIT_MEM) { \
541 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG((p) & 0xf)); \
542 if ((p) & 0xf0) { \
543 SLJIT_ASSERT(FUNCTION_CHECK_IS_REG(((p) >> 4) & 0xf)); \
544 SLJIT_ASSERT(((p) & 0xf0) != (SLJIT_LOCALS_REG << 4) && !(i & ~0x3)); \
545 } else \
546 SLJIT_ASSERT((((p) >> 4) & 0xf) == 0); \
547 SLJIT_ASSERT(((p) >> 9) == 0); \
548 } \
549 else \
550 SLJIT_ASSERT_STOP();
551
552 #define FUNCTION_CHECK_OP1() \
553 if (GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_MOVU_SI) { \
554 SLJIT_ASSERT(!GET_ALL_FLAGS(op)); \
555 } \
556 if (GET_OPCODE(op) >= SLJIT_MOVU && GET_OPCODE(op) <= SLJIT_MOVU_SI) { \
557 SLJIT_ASSERT(!(src & SLJIT_MEM) || (src & 0xf) != SLJIT_LOCALS_REG); \
558 SLJIT_ASSERT(!(dst & SLJIT_MEM) || (dst & 0xf) != SLJIT_LOCALS_REG); \
559 if ((src & SLJIT_MEM) && (src & 0xf)) \
560 SLJIT_ASSERT((dst & 0xf) != (src & 0xf) && ((dst >> 4) & 0xf) != (src & 0xf)); \
561 }
562
563 #endif
564
565 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
566
567 void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
568 {
569 compiler->verbose = verbose;
570 }
571
572 static char* reg_names[] = {
573 (char*)"<noreg>", (char*)"tmp_r1", (char*)"tmp_r2", (char*)"tmp_r3",
574 (char*)"tmp_er1", (char*)"tmp_er2", (char*)"gen_r1", (char*)"gen_r2",
575 (char*)"gen_r3", (char*)"gen_er1", (char*)"gen_er2", (char*)"stack_r"
576 };
577
578 static char* freg_names[] = {
579 (char*)"<noreg>", (char*)"float_r1", (char*)"float_r2", (char*)"float_r3", (char*)"float_r4"
580 };
581
582 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) || (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
583 #ifdef _WIN64
584 #define SLJIT_PRINT_D "I64"
585 #else
586 #define SLJIT_PRINT_D "l"
587 #endif
588 #else
589 #define SLJIT_PRINT_D ""
590 #endif
591
592 #define sljit_verbose_param(p, i) \
593 if ((p) & SLJIT_IMM) \
594 fprintf(compiler->verbose, "#%"SLJIT_PRINT_D"d", (i)); \
595 else if ((p) & SLJIT_MEM) { \
596 if ((p) & 0xf) { \
597 if (i) { \
598 if (((p) >> 4) & 0xf) \
599 fprintf(compiler->verbose, "[%s + %s * %d]", reg_names[(p) & 0xF], reg_names[((p) >> 4)& 0xF], 1 << (i)); \
600 else \
601 fprintf(compiler->verbose, "[%s + #%"SLJIT_PRINT_D"d]", reg_names[(p) & 0xF], (i)); \
602 } \
603 else { \
604 if (((p) >> 4) & 0xf) \
605 fprintf(compiler->verbose, "[%s + %s]", reg_names[(p) & 0xF], reg_names[((p) >> 4)& 0xF]); \
606 else \
607 fprintf(compiler->verbose, "[%s]", reg_names[(p) & 0xF]); \
608 } \
609 } \
610 else \
611 fprintf(compiler->verbose, "[#%"SLJIT_PRINT_D"d]", (i)); \
612 } else \
613 fprintf(compiler->verbose, "%s", reg_names[p]);
614 #define sljit_verbose_fparam(p, i) \
615 if ((p) & SLJIT_MEM) { \
616 if ((p) & 0xf) { \
617 if (i) { \
618 if (((p) >> 4) & 0xf) \
619 fprintf(compiler->verbose, "[%s + %s * %d]", reg_names[(p) & 0xF], reg_names[((p) >> 4)& 0xF], 1 << (i)); \
620 else \
621 fprintf(compiler->verbose, "[%s + #%"SLJIT_PRINT_D"d]", reg_names[(p) & 0xF], (i)); \
622 } \
623 else { \
624 if (((p) >> 4) & 0xF) \
625 fprintf(compiler->verbose, "[%s + %s]", reg_names[(p) & 0xF], reg_names[((p) >> 4)& 0xF]); \
626 else \
627 fprintf(compiler->verbose, "[%s]", reg_names[(p) & 0xF]); \
628 } \
629 } \
630 else \
631 fprintf(compiler->verbose, "[#%"SLJIT_PRINT_D"d]", (i)); \
632 } else \
633 fprintf(compiler->verbose, "%s", freg_names[p]);
634
635 static SLJIT_CONST char* op_names[] = {
636 /* op0 */
637 (char*)"breakpoint", (char*)"nop",
638 /* op1 */
639 (char*)"mov", (char*)"mov.ub", (char*)"mov.sb", (char*)"mov.uh",
640 (char*)"mov.sh", (char*)"mov.ui", (char*)"mov.si", (char*)"movu",
641 (char*)"movu.ub", (char*)"movu.sb", (char*)"movu.uh", (char*)"movu.sh",
642 (char*)"movu.ui", (char*)"movu.si", (char*)"not", (char*)"neg",
643 (char*)"clz",
644 /* op2 */
645 (char*)"add", (char*)"addc", (char*)"sub", (char*)"subc",
646 (char*)"mul", (char*)"and", (char*)"or", (char*)"xor",
647 (char*)"shl", (char*)"lshr", (char*)"ashr",
648 /* fop1 */
649 (char*)"fcmp", (char*)"fmov", (char*)"fneg", (char*)"fabs",
650 /* fop2 */
651 (char*)"fadd", (char*)"fsub", (char*)"fmul", (char*)"fdiv"
652 };
653
654 static char* jump_names[] = {
655 (char*)"c_equal", (char*)"c_not_equal",
656 (char*)"c_less", (char*)"c_greater_equal",
657 (char*)"c_greater", (char*)"c_less_equal",
658 (char*)"c_sig_less", (char*)"c_sig_greater_equal",
659 (char*)"c_sig_greater", (char*)"c_sig_less_equal",
660 (char*)"c_overflow", (char*)"c_not_overflow",
661 (char*)"c_mul_overflow", (char*)"c_mul_not_overflow",
662 (char*)"c_float_equal", (char*)"c_float_not_equal",
663 (char*)"c_float_less", (char*)"c_float_greater_equal",
664 (char*)"c_float_greater", (char*)"c_float_less_equal",
665 (char*)"c_float_nan", (char*)"c_float_not_nan",
666 (char*)"jump",
667 (char*)"call0", (char*)"call1", (char*)"call2", (char*)"call3"
668 };
669
670 #endif
671
672 /* --------------------------------------------------------------------- */
673 /* Arch dependent */
674 /* --------------------------------------------------------------------- */
675
676 static SLJIT_INLINE void check_sljit_generate_code(struct sljit_compiler *compiler)
677 {
678 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
679 struct sljit_jump *jump;
680 #endif
681 /* If debug and verbose are disabled, all arguments are unused. */
682 SLJIT_UNUSED_ARG(compiler);
683
684 SLJIT_ASSERT(compiler->size > 0);
685 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
686 jump = compiler->jumps;
687 while (jump) {
688 /* All jumps have target. */
689 SLJIT_ASSERT(jump->flags & (JUMP_LABEL | JUMP_ADDR));
690 jump = jump->next;
691 }
692 #endif
693 }
694
695 static SLJIT_INLINE void check_sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size)
696 {
697 /* If debug and verbose are disabled, all arguments are unused. */
698 SLJIT_UNUSED_ARG(compiler);
699 SLJIT_UNUSED_ARG(args);
700 SLJIT_UNUSED_ARG(temporaries);
701 SLJIT_UNUSED_ARG(generals);
702 SLJIT_UNUSED_ARG(local_size);
703
704 SLJIT_ASSERT(args >= 0 && args <= 3);
705 SLJIT_ASSERT(temporaries >= 0 && temporaries <= SLJIT_NO_TMP_REGISTERS);
706 SLJIT_ASSERT(generals >= 0 && generals <= SLJIT_NO_GEN_REGISTERS);
707 SLJIT_ASSERT(args <= generals);
708 SLJIT_ASSERT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
709 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
710 if (SLJIT_UNLIKELY(!!compiler->verbose))
711 fprintf(compiler->verbose, " enter args=%d temporaries=%d generals=%d local_size=%d\n", args, temporaries, generals, local_size);
712 #endif
713 }
714
715 static SLJIT_INLINE void check_sljit_fake_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size)
716 {
717 /* If debug and verbose are disabled, all arguments are unused. */
718 SLJIT_UNUSED_ARG(compiler);
719 SLJIT_UNUSED_ARG(args);
720 SLJIT_UNUSED_ARG(temporaries);
721 SLJIT_UNUSED_ARG(generals);
722 SLJIT_UNUSED_ARG(local_size);
723
724 SLJIT_ASSERT(args >= 0 && args <= 3);
725 SLJIT_ASSERT(temporaries >= 0 && temporaries <= SLJIT_NO_TMP_REGISTERS);
726 SLJIT_ASSERT(generals >= 0 && generals <= SLJIT_NO_GEN_REGISTERS);
727 SLJIT_ASSERT(args <= generals);
728 SLJIT_ASSERT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
729 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
730 if (SLJIT_UNLIKELY(!!compiler->verbose))
731 fprintf(compiler->verbose, " fake_enter args=%d temporaries=%d generals=%d local_size=%d\n", args, temporaries, generals, local_size);
732 #endif
733 }
734
735 static SLJIT_INLINE void check_sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
736 {
737 /* If debug and verbose are disabled, all arguments are unused. */
738 SLJIT_UNUSED_ARG(compiler);
739 SLJIT_UNUSED_ARG(src);
740 SLJIT_UNUSED_ARG(srcw);
741
742 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
743 if (src != SLJIT_UNUSED) {
744 FUNCTION_CHECK_SRC(src, srcw);
745 }
746 else
747 SLJIT_ASSERT(srcw == 0);
748 #endif
749 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
750 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
751 fprintf(compiler->verbose, " return ");
752 sljit_verbose_param(src, srcw);
753 fprintf(compiler->verbose, "\n");
754 }
755 #endif
756 }
757
758 static SLJIT_INLINE void check_sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int generals, int local_size)
759 {
760 /* If debug and verbose are disabled, all arguments are unused. */
761 SLJIT_UNUSED_ARG(compiler);
762 SLJIT_UNUSED_ARG(dst);
763 SLJIT_UNUSED_ARG(dstw);
764 SLJIT_UNUSED_ARG(args);
765 SLJIT_UNUSED_ARG(temporaries);
766 SLJIT_UNUSED_ARG(generals);
767 SLJIT_UNUSED_ARG(local_size);
768
769 SLJIT_ASSERT(args >= 0 && args <= 3);
770 SLJIT_ASSERT(temporaries >= 0 && temporaries <= SLJIT_NO_TMP_REGISTERS);
771 SLJIT_ASSERT(generals >= 0 && generals <= SLJIT_NO_GEN_REGISTERS);
772 SLJIT_ASSERT(args <= generals);
773 SLJIT_ASSERT(local_size >= 0 && local_size <= SLJIT_MAX_LOCAL_SIZE);
774 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
775 compiler->temporaries = temporaries;
776 compiler->generals = generals;
777 FUNCTION_CHECK_DST(dst, dstw);
778 compiler->temporaries = -1;
779 compiler->generals = -1;
780 #endif
781 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
782 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
783 fprintf(compiler->verbose, " fast_enter ");
784 sljit_verbose_param(dst, dstw);
785 fprintf(compiler->verbose, " args=%d temporaries=%d generals=%d local_size=%d\n", args, temporaries, generals, local_size);
786 }
787 #endif
788 }
789
790 static SLJIT_INLINE void check_sljit_emit_fast_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
791 {
792 /* If debug and verbose are disabled, all arguments are unused. */
793 SLJIT_UNUSED_ARG(compiler);
794 SLJIT_UNUSED_ARG(src);
795 SLJIT_UNUSED_ARG(srcw);
796
797 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
798 FUNCTION_CHECK_SRC(src, srcw);
799 #endif
800 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
801 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
802 fprintf(compiler->verbose, " fast_return ");
803 sljit_verbose_param(src, srcw);
804 fprintf(compiler->verbose, "\n");
805 }
806 #endif
807 }
808
809 static SLJIT_INLINE void check_sljit_emit_op0(struct sljit_compiler *compiler, int op)
810 {
811 /* If debug and verbose are disabled, all arguments are unused. */
812 SLJIT_UNUSED_ARG(compiler);
813 SLJIT_UNUSED_ARG(op);
814
815 SLJIT_ASSERT(op >= SLJIT_BREAKPOINT && op <= SLJIT_NOP);
816 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
817 if (SLJIT_UNLIKELY(!!compiler->verbose))
818 fprintf(compiler->verbose, " %s\n", op_names[op]);
819 #endif
820 }
821
822 static SLJIT_INLINE void check_sljit_emit_op1(struct sljit_compiler *compiler, int op,
823 int dst, sljit_w dstw,
824 int src, sljit_w srcw)
825 {
826 /* If debug and verbose are disabled, all arguments are unused. */
827 SLJIT_UNUSED_ARG(compiler);
828 SLJIT_UNUSED_ARG(op);
829 SLJIT_UNUSED_ARG(dst);
830 SLJIT_UNUSED_ARG(dstw);
831 SLJIT_UNUSED_ARG(src);
832 SLJIT_UNUSED_ARG(srcw);
833
834 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_MOV && GET_OPCODE(op) <= SLJIT_CLZ);
835 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
836 FUNCTION_CHECK_OP();
837 FUNCTION_CHECK_SRC(src, srcw);
838 FUNCTION_CHECK_DST(dst, dstw);
839 FUNCTION_CHECK_OP1();
840 #endif
841 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
842 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
843 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op_names[GET_OPCODE(op)],
844 !(op & SLJIT_SET_E) ? "" : "E", !(op & SLJIT_SET_S) ? "" : "S", !(op & SLJIT_SET_U) ? "" : "U", !(op & SLJIT_SET_O) ? "" : "O", !(op & SLJIT_SET_C) ? "" : "C", !(op & SLJIT_KEEP_FLAGS) ? "" : "K");
845 sljit_verbose_param(dst, dstw);
846 fprintf(compiler->verbose, ", ");
847 sljit_verbose_param(src, srcw);
848 fprintf(compiler->verbose, "\n");
849 }
850 #endif
851 }
852
853 static SLJIT_INLINE void check_sljit_emit_op2(struct sljit_compiler *compiler, int op,
854 int dst, sljit_w dstw,
855 int src1, sljit_w src1w,
856 int src2, sljit_w src2w)
857 {
858 /* If debug and verbose are disabled, all arguments are unused. */
859 SLJIT_UNUSED_ARG(compiler);
860 SLJIT_UNUSED_ARG(op);
861 SLJIT_UNUSED_ARG(dst);
862 SLJIT_UNUSED_ARG(dstw);
863 SLJIT_UNUSED_ARG(src1);
864 SLJIT_UNUSED_ARG(src1w);
865 SLJIT_UNUSED_ARG(src2);
866 SLJIT_UNUSED_ARG(src2w);
867
868 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
869 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
870 compiler->skip_checks = 0;
871 return;
872 }
873 #endif
874
875 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
876 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
877 FUNCTION_CHECK_OP();
878 FUNCTION_CHECK_SRC(src1, src1w);
879 FUNCTION_CHECK_SRC(src2, src2w);
880 FUNCTION_CHECK_DST(dst, dstw);
881 #endif
882 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
883 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
884 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op_names[GET_OPCODE(op)],
885 !(op & SLJIT_SET_E) ? "" : "E", !(op & SLJIT_SET_S) ? "" : "S", !(op & SLJIT_SET_U) ? "" : "U", !(op & SLJIT_SET_O) ? "" : "O", !(op & SLJIT_SET_C) ? "" : "C", !(op & SLJIT_KEEP_FLAGS) ? "" : "K");
886 sljit_verbose_param(dst, dstw);
887 fprintf(compiler->verbose, ", ");
888 sljit_verbose_param(src1, src1w);
889 fprintf(compiler->verbose, ", ");
890 sljit_verbose_param(src2, src2w);
891 fprintf(compiler->verbose, "\n");
892 }
893 #endif
894 }
895
896 static SLJIT_INLINE void check_sljit_emit_fop1(struct sljit_compiler *compiler, int op,
897 int dst, sljit_w dstw,
898 int src, sljit_w srcw)
899 {
900 /* If debug and verbose are disabled, all arguments are unused. */
901 SLJIT_UNUSED_ARG(compiler);
902 SLJIT_UNUSED_ARG(op);
903 SLJIT_UNUSED_ARG(dst);
904 SLJIT_UNUSED_ARG(dstw);
905 SLJIT_UNUSED_ARG(src);
906 SLJIT_UNUSED_ARG(srcw);
907
908 SLJIT_ASSERT(sljit_is_fpu_available());
909 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_FCMP && GET_OPCODE(op) <= SLJIT_FABS);
910 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
911 FUNCTION_CHECK_OP();
912 FUNCTION_FCHECK(src, srcw);
913 FUNCTION_FCHECK(dst, dstw);
914 #endif
915 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
916 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
917 fprintf(compiler->verbose, " %s%s%s ", op_names[GET_OPCODE(op)],
918 !(op & SLJIT_SET_E) ? "" : "E", !(op & SLJIT_SET_S) ? "" : "S");
919 sljit_verbose_fparam(dst, dstw);
920 fprintf(compiler->verbose, ", ");
921 sljit_verbose_fparam(src, srcw);
922 fprintf(compiler->verbose, "\n");
923 }
924 #endif
925 }
926
927 static SLJIT_INLINE void check_sljit_emit_fop2(struct sljit_compiler *compiler, int op,
928 int dst, sljit_w dstw,
929 int src1, sljit_w src1w,
930 int src2, sljit_w src2w)
931 {
932 /* If debug and verbose are disabled, all arguments are unused. */
933 SLJIT_UNUSED_ARG(compiler);
934 SLJIT_UNUSED_ARG(op);
935 SLJIT_UNUSED_ARG(dst);
936 SLJIT_UNUSED_ARG(dstw);
937 SLJIT_UNUSED_ARG(src1);
938 SLJIT_UNUSED_ARG(src1w);
939 SLJIT_UNUSED_ARG(src2);
940 SLJIT_UNUSED_ARG(src2w);
941
942 SLJIT_ASSERT(sljit_is_fpu_available());
943 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_FADD && GET_OPCODE(op) <= SLJIT_FDIV);
944 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
945 FUNCTION_CHECK_OP();
946 FUNCTION_FCHECK(src1, src1w);
947 FUNCTION_FCHECK(src2, src2w);
948 FUNCTION_FCHECK(dst, dstw);
949 #endif
950 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
951 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
952 fprintf(compiler->verbose, " %s ", op_names[GET_OPCODE(op)]);
953 sljit_verbose_fparam(dst, dstw);
954 fprintf(compiler->verbose, ", ");
955 sljit_verbose_fparam(src1, src1w);
956 fprintf(compiler->verbose, ", ");
957 sljit_verbose_fparam(src2, src2w);
958 fprintf(compiler->verbose, "\n");
959 }
960 #endif
961 }
962
963 static SLJIT_INLINE void check_sljit_emit_label(struct sljit_compiler *compiler)
964 {
965 /* If debug and verbose are disabled, all arguments are unused. */
966 SLJIT_UNUSED_ARG(compiler);
967
968 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
969 if (SLJIT_UNLIKELY(!!compiler->verbose))
970 fprintf(compiler->verbose, "label:\n");
971 #endif
972 }
973
974 static SLJIT_INLINE void check_sljit_emit_jump(struct sljit_compiler *compiler, int type)
975 {
976 /* If debug and verbose are disabled, all arguments are unused. */
977 SLJIT_UNUSED_ARG(compiler);
978 SLJIT_UNUSED_ARG(type);
979
980 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
981 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
982 compiler->skip_checks = 0;
983 return;
984 }
985 #endif
986
987 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
988 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_EQUAL && (type & 0xff) <= SLJIT_CALL3);
989 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
990 if (SLJIT_UNLIKELY(!!compiler->verbose))
991 fprintf(compiler->verbose, " jump%s <%s>\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : "R", jump_names[type & 0xff]);
992 #endif
993 }
994
995 static SLJIT_INLINE void check_sljit_emit_cmp(struct sljit_compiler *compiler, int type,
996 int src1, sljit_w src1w,
997 int src2, sljit_w src2w)
998 {
999 SLJIT_UNUSED_ARG(compiler);
1000 SLJIT_UNUSED_ARG(type);
1001 SLJIT_UNUSED_ARG(src1);
1002 SLJIT_UNUSED_ARG(src1w);
1003 SLJIT_UNUSED_ARG(src2);
1004 SLJIT_UNUSED_ARG(src2w);
1005
1006 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_INT_OP | SLJIT_REWRITABLE_JUMP)));
1007 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_EQUAL && (type & 0xff) <= SLJIT_C_SIG_LESS_EQUAL);
1008 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1009 FUNCTION_CHECK_SRC(src1, src1w);
1010 FUNCTION_CHECK_SRC(src2, src2w);
1011 #endif
1012 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1013 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1014 fprintf(compiler->verbose, " %scmp%s <%s> ", !(type & SLJIT_INT_OP) ? "" : "i", !(type & SLJIT_REWRITABLE_JUMP) ? "" : "R", jump_names[type & 0xff]);
1015 sljit_verbose_param(src1, src1w);
1016 fprintf(compiler->verbose, ", ");
1017 sljit_verbose_param(src2, src2w);
1018 fprintf(compiler->verbose, "\n");
1019 }
1020 #endif
1021 }
1022
1023 static SLJIT_INLINE void check_sljit_emit_ijump(struct sljit_compiler *compiler, int type, int src, sljit_w srcw)
1024 {
1025 /* If debug and verbose are disabled, all arguments are unused. */
1026 SLJIT_UNUSED_ARG(compiler);
1027 SLJIT_UNUSED_ARG(type);
1028 SLJIT_UNUSED_ARG(src);
1029 SLJIT_UNUSED_ARG(srcw);
1030
1031 SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1032 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1033 FUNCTION_CHECK_SRC(src, srcw);
1034 #endif
1035 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1036 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1037 fprintf(compiler->verbose, " ijump <%s> ", jump_names[type]);
1038 sljit_verbose_param(src, srcw);
1039 fprintf(compiler->verbose, "\n");
1040 }
1041 #endif
1042 }
1043
1044 static SLJIT_INLINE void check_sljit_emit_cond_value(struct sljit_compiler *compiler, int op, int dst, sljit_w dstw, int type)
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(type);
1052
1053 SLJIT_ASSERT(type >= SLJIT_C_EQUAL && type < SLJIT_JUMP);
1054 SLJIT_ASSERT(op == SLJIT_MOV || GET_OPCODE(op) == SLJIT_OR);
1055 SLJIT_ASSERT(GET_ALL_FLAGS(op) == 0 || GET_ALL_FLAGS(op) == SLJIT_SET_E || GET_ALL_FLAGS(op) == SLJIT_KEEP_FLAGS);
1056 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1057 FUNCTION_CHECK_DST(dst, dstw);
1058 #endif
1059 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1060 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1061 fprintf(compiler->verbose, " cond_set%s%s <%s> ", !(op & SLJIT_SET_E) ? "" : "E",
1062 !(op & SLJIT_KEEP_FLAGS) ? "" : "K", op_names[GET_OPCODE(op)]);
1063 sljit_verbose_param(dst, dstw);
1064 fprintf(compiler->verbose, ", <%s>\n", jump_names[type]);
1065 }
1066 #endif
1067 }
1068
1069 static SLJIT_INLINE void check_sljit_emit_const(struct sljit_compiler *compiler, int dst, sljit_w dstw, sljit_w init_value)
1070 {
1071 /* If debug and verbose are disabled, all arguments are unused. */
1072 SLJIT_UNUSED_ARG(compiler);
1073 SLJIT_UNUSED_ARG(dst);
1074 SLJIT_UNUSED_ARG(dstw);
1075 SLJIT_UNUSED_ARG(init_value);
1076
1077 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1078 FUNCTION_CHECK_DST(dst, dstw);
1079 #endif
1080 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1081 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1082 fprintf(compiler->verbose, " const ");
1083 sljit_verbose_param(dst, dstw);
1084 fprintf(compiler->verbose, ", #%"SLJIT_PRINT_D"d\n", init_value);
1085 }
1086 #endif
1087 }
1088
1089 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
1090 #include "sljitNativeX86_common.c"
1091 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1092 #include "sljitNativeX86_common.c"
1093 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1094 #include "sljitNativeARM_v5.c"
1095 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1096 #include "sljitNativeARM_v5.c"
1097 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1098 #include "sljitNativeARM_Thumb2.c"
1099 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
1100 #include "sljitNativePPC_common.c"
1101 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
1102 #include "sljitNativePPC_common.c"
1103 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1104 #include "sljitNativeMIPS_common.c"
1105 #endif
1106
1107 #if !(defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1108 struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, int type,
1109 int src1, sljit_w src1w,
1110 int src2, sljit_w src2w)
1111 {
1112 /* Default compare for most architectures. */
1113 int flags, tmp_src, condition;
1114 sljit_w tmp_srcw;
1115
1116 CHECK_ERROR_PTR();
1117 check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
1118
1119 condition = type & 0xff;
1120 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1121 /* Immediate is prefered as second argument by most architectures. */
1122 switch (condition) {
1123 case SLJIT_C_LESS:
1124 condition = SLJIT_C_GREATER;
1125 break;
1126 case SLJIT_C_GREATER_EQUAL:
1127 condition = SLJIT_C_LESS_EQUAL;
1128 break;
1129 case SLJIT_C_GREATER:
1130 condition = SLJIT_C_LESS;
1131 break;
1132 case SLJIT_C_LESS_EQUAL:
1133 condition = SLJIT_C_GREATER_EQUAL;
1134 break;
1135 case SLJIT_C_SIG_LESS:
1136 condition = SLJIT_C_SIG_GREATER;
1137 break;
1138 case SLJIT_C_SIG_GREATER_EQUAL:
1139 condition = SLJIT_C_SIG_LESS_EQUAL;
1140 break;
1141 case SLJIT_C_SIG_GREATER:
1142 condition = SLJIT_C_SIG_LESS;
1143 break;
1144 case SLJIT_C_SIG_LESS_EQUAL:
1145 condition = SLJIT_C_SIG_GREATER_EQUAL;
1146 break;
1147 }
1148 type = condition | (type & (SLJIT_INT_OP | SLJIT_REWRITABLE_JUMP));
1149 tmp_src = src1;
1150 src1 = src2;
1151 src2 = tmp_src;
1152 tmp_srcw = src1w;
1153 src1w = src2w;
1154 src2w = tmp_srcw;
1155 }
1156
1157 if (condition <= SLJIT_C_NOT_ZERO)
1158 flags = SLJIT_SET_E;
1159 else if (condition <= SLJIT_C_LESS_EQUAL)
1160 flags = SLJIT_SET_U;
1161 else
1162 flags = SLJIT_SET_S;
1163
1164 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1165 compiler->skip_checks = 1;
1166 #endif
1167 PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_INT_OP),
1168 SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1169 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1170 compiler->skip_checks = 1;
1171 #endif
1172 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1173 }
1174 #endif
1175
1176 #else /* SLJIT_CONFIG_UNSUPPORTED */
1177
1178 /* Empty function bodies for those machines, which are not (yet) supported. */
1179
1180 SLJIT_CONST char* sljit_get_platform_name()
1181 {
1182 return "unsupported";
1183 }
1184
1185 struct sljit_compiler* sljit_create_compiler(void)
1186 {
1187 SLJIT_ASSERT_STOP();
1188 return NULL;
1189 }
1190
1191 void sljit_free_compiler(struct sljit_compiler *compiler)
1192 {
1193 SLJIT_UNUSED_ARG(compiler);
1194 SLJIT_ASSERT_STOP();
1195 }
1196
1197 void* sljit_alloc_memory(struct sljit_compiler *compiler, int size)
1198 {
1199 SLJIT_UNUSED_ARG(compiler);
1200 SLJIT_UNUSED_ARG(size);
1201 SLJIT_ASSERT_STOP();
1202 return NULL;
1203 }
1204
1205 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1206 void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1207 {
1208 SLJIT_UNUSED_ARG(compiler);
1209 SLJIT_UNUSED_ARG(verbose);
1210 SLJIT_ASSERT_STOP();
1211 }
1212 #endif
1213
1214 void* sljit_generate_code(struct sljit_compiler *compiler)
1215 {
1216 SLJIT_UNUSED_ARG(compiler);
1217 SLJIT_ASSERT_STOP();
1218 return NULL;
1219 }
1220
1221 void sljit_free_code(void* code)
1222 {
1223 SLJIT_UNUSED_ARG(code);
1224 SLJIT_ASSERT_STOP();
1225 }
1226
1227 int sljit_emit_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size)
1228 {
1229 SLJIT_UNUSED_ARG(compiler);
1230 SLJIT_UNUSED_ARG(args);
1231 SLJIT_UNUSED_ARG(temporaries);
1232 SLJIT_UNUSED_ARG(generals);
1233 SLJIT_UNUSED_ARG(local_size);
1234 SLJIT_ASSERT_STOP();
1235 return SLJIT_ERR_UNSUPPORTED;
1236 }
1237
1238 void sljit_fake_enter(struct sljit_compiler *compiler, int args, int temporaries, int generals, int local_size)
1239 {
1240 SLJIT_UNUSED_ARG(compiler);
1241 SLJIT_UNUSED_ARG(args);
1242 SLJIT_UNUSED_ARG(temporaries);
1243 SLJIT_UNUSED_ARG(generals);
1244 SLJIT_UNUSED_ARG(local_size);
1245 SLJIT_ASSERT_STOP();
1246 }
1247
1248 int sljit_emit_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
1249 {
1250 SLJIT_UNUSED_ARG(compiler);
1251 SLJIT_UNUSED_ARG(src);
1252 SLJIT_UNUSED_ARG(srcw);
1253 SLJIT_ASSERT_STOP();
1254 return SLJIT_ERR_UNSUPPORTED;
1255 }
1256
1257 int sljit_emit_fast_enter(struct sljit_compiler *compiler, int dst, sljit_w dstw, int args, int temporaries, int generals, int local_size)
1258 {
1259 SLJIT_UNUSED_ARG(compiler);
1260 SLJIT_UNUSED_ARG(dst);
1261 SLJIT_UNUSED_ARG(dstw);
1262 SLJIT_UNUSED_ARG(args);
1263 SLJIT_UNUSED_ARG(temporaries);
1264 SLJIT_UNUSED_ARG(generals);
1265 SLJIT_UNUSED_ARG(local_size);
1266 SLJIT_ASSERT_STOP();
1267 return SLJIT_ERR_UNSUPPORTED;
1268 }
1269
1270 int sljit_emit_fast_return(struct sljit_compiler *compiler, int src, sljit_w srcw)
1271 {
1272 SLJIT_UNUSED_ARG(compiler);
1273 SLJIT_UNUSED_ARG(src);
1274 SLJIT_UNUSED_ARG(srcw);
1275 SLJIT_ASSERT_STOP();
1276 return SLJIT_ERR_UNSUPPORTED;
1277 }
1278
1279 int sljit_emit_op0(struct sljit_compiler *compiler, int op)
1280 {
1281 SLJIT_UNUSED_ARG(compiler);
1282 SLJIT_UNUSED_ARG(op);
1283 SLJIT_ASSERT_STOP();
1284 return SLJIT_ERR_UNSUPPORTED;
1285 }
1286
1287 int sljit_emit_op1(struct sljit_compiler *compiler, int op,
1288 int dst, sljit_w dstw,
1289 int src, sljit_w srcw)
1290 {
1291 SLJIT_UNUSED_ARG(compiler);
1292 SLJIT_UNUSED_ARG(op);
1293 SLJIT_UNUSED_ARG(dst);
1294 SLJIT_UNUSED_ARG(dstw);
1295 SLJIT_UNUSED_ARG(src);
1296 SLJIT_UNUSED_ARG(srcw);
1297 SLJIT_ASSERT_STOP();
1298 return SLJIT_ERR_UNSUPPORTED;
1299 }
1300
1301 int sljit_emit_op2(struct sljit_compiler *compiler, int op,
1302 int dst, sljit_w dstw,
1303 int src1, sljit_w src1w,
1304 int src2, sljit_w src2w)
1305 {
1306 SLJIT_UNUSED_ARG(compiler);
1307 SLJIT_UNUSED_ARG(op);
1308 SLJIT_UNUSED_ARG(dst);
1309 SLJIT_UNUSED_ARG(dstw);
1310 SLJIT_UNUSED_ARG(src1);
1311 SLJIT_UNUSED_ARG(src1w);
1312 SLJIT_UNUSED_ARG(src2);
1313 SLJIT_UNUSED_ARG(src2w);
1314 SLJIT_ASSERT_STOP();
1315 return SLJIT_ERR_UNSUPPORTED;
1316 }
1317
1318 int sljit_is_fpu_available(void)
1319 {
1320 SLJIT_ASSERT_STOP();
1321 return 0;
1322 }
1323
1324 int sljit_emit_fop1(struct sljit_compiler *compiler, int op,
1325 int dst, sljit_w dstw,
1326 int src, sljit_w srcw)
1327 {
1328 SLJIT_UNUSED_ARG(compiler);
1329 SLJIT_UNUSED_ARG(op);
1330 SLJIT_UNUSED_ARG(dst);
1331 SLJIT_UNUSED_ARG(dstw);
1332 SLJIT_UNUSED_ARG(src);
1333 SLJIT_UNUSED_ARG(srcw);
1334 SLJIT_ASSERT_STOP();
1335 return SLJIT_ERR_UNSUPPORTED;
1336 }
1337
1338 int sljit_emit_fop2(struct sljit_compiler *compiler, int op,
1339 int dst, sljit_w dstw,
1340 int src1, sljit_w src1w,
1341 int src2, sljit_w src2w)
1342 {
1343 SLJIT_UNUSED_ARG(compiler);
1344 SLJIT_UNUSED_ARG(op);
1345 SLJIT_UNUSED_ARG(dst);
1346 SLJIT_UNUSED_ARG(dstw);
1347 SLJIT_UNUSED_ARG(src1);
1348 SLJIT_UNUSED_ARG(src1w);
1349 SLJIT_UNUSED_ARG(src2);
1350 SLJIT_UNUSED_ARG(src2w);
1351 SLJIT_ASSERT_STOP();
1352 return SLJIT_ERR_UNSUPPORTED;
1353 }
1354
1355 struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1356 {
1357 SLJIT_UNUSED_ARG(compiler);
1358 SLJIT_ASSERT_STOP();
1359 return NULL;
1360 }
1361
1362 struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, int type)
1363 {
1364 SLJIT_UNUSED_ARG(compiler);
1365 SLJIT_UNUSED_ARG(type);
1366 SLJIT_ASSERT_STOP();
1367 return NULL;
1368 }
1369
1370 struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, int type,
1371 int src1, sljit_w src1w,
1372 int src2, sljit_w src2w)
1373 {
1374 SLJIT_UNUSED_ARG(compiler);
1375 SLJIT_UNUSED_ARG(type);
1376 SLJIT_UNUSED_ARG(src1);
1377 SLJIT_UNUSED_ARG(src1w);
1378 SLJIT_UNUSED_ARG(src2);
1379 SLJIT_UNUSED_ARG(src2w);
1380 SLJIT_ASSERT_STOP();
1381 return NULL;
1382 }
1383
1384 void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
1385 {
1386 SLJIT_UNUSED_ARG(jump);
1387 SLJIT_UNUSED_ARG(label);
1388 SLJIT_ASSERT_STOP();
1389 }
1390
1391 void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
1392 {
1393 SLJIT_UNUSED_ARG(jump);
1394 SLJIT_UNUSED_ARG(target);
1395 SLJIT_ASSERT_STOP();
1396 }
1397
1398 int sljit_emit_ijump(struct sljit_compiler *compiler, int type, int src, sljit_w srcw)
1399 {
1400 SLJIT_UNUSED_ARG(compiler);
1401 SLJIT_UNUSED_ARG(type);
1402 SLJIT_UNUSED_ARG(src);
1403 SLJIT_UNUSED_ARG(srcw);
1404 SLJIT_ASSERT_STOP();
1405 return SLJIT_ERR_UNSUPPORTED;
1406 }
1407
1408 int sljit_emit_cond_value(struct sljit_compiler *compiler, int op, int dst, sljit_w dstw, int type)
1409 {
1410 SLJIT_UNUSED_ARG(compiler);
1411 SLJIT_UNUSED_ARG(op);
1412 SLJIT_UNUSED_ARG(dst);
1413 SLJIT_UNUSED_ARG(dstw);
1414 SLJIT_UNUSED_ARG(type);
1415 SLJIT_ASSERT_STOP();
1416 return SLJIT_ERR_UNSUPPORTED;
1417 }
1418
1419 struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, int dst, sljit_w dstw, sljit_w initval)
1420 {
1421 SLJIT_UNUSED_ARG(compiler);
1422 SLJIT_UNUSED_ARG(dst);
1423 SLJIT_UNUSED_ARG(dstw);
1424 SLJIT_UNUSED_ARG(initval);
1425 SLJIT_ASSERT_STOP();
1426 return NULL;
1427 }
1428
1429 void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
1430 {
1431 SLJIT_UNUSED_ARG(addr);
1432 SLJIT_UNUSED_ARG(new_addr);
1433 SLJIT_ASSERT_STOP();
1434 }
1435
1436 void sljit_set_const(sljit_uw addr, sljit_w new_constant)
1437 {
1438 SLJIT_UNUSED_ARG(addr);
1439 SLJIT_UNUSED_ARG(new_constant);
1440 SLJIT_ASSERT_STOP();
1441 }
1442
1443 #endif

  ViewVC Help
Powered by ViewVC 1.1.5