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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5