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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12