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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1215 - (show annotations)
Fri Nov 9 08:13:13 2012 UTC (7 years ago) by zherczeg
File MIME type: text/plain
File size: 54310 byte(s)
Large JIT compiler update again.
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->scratches = -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_SCRATCH_REG1 && (r) <= SLJIT_SCRATCH_REG1 - 1 + compiler->scratches) || \
581 ((r) >= SLJIT_SAVED_REG1 && (r) <= SLJIT_SAVED_REG1 - 1 + compiler->saveds))
582
583 #define FUNCTION_CHECK_SRC(p, i) \
584 SLJIT_ASSERT(compiler->scratches != -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->scratches != -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_unordered", (char*)"c_float_ordered",
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 scratches, 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(scratches);
782 SLJIT_UNUSED_ARG(saveds);
783 SLJIT_UNUSED_ARG(local_size);
784
785 SLJIT_ASSERT(args >= 0 && args <= 3);
786 SLJIT_ASSERT(scratches >= 0 && scratches <= 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 scratches=%d saveds=%d local_size=%d\n", args, scratches, 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 scratches, 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(scratches);
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(scratches >= 0 && scratches <= 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 scratches=%d saveds=%d local_size=%d\n", args, scratches, 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",
934 !(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
935 sljit_verbose_param(dst, dstw);
936 fprintf(compiler->verbose, ", ");
937 sljit_verbose_param(src, srcw);
938 fprintf(compiler->verbose, "\n");
939 }
940 #endif
941 }
942
943 static SLJIT_INLINE void check_sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
944 sljit_si dst, sljit_sw dstw,
945 sljit_si src1, sljit_sw src1w,
946 sljit_si src2, sljit_sw src2w)
947 {
948 /* If debug and verbose are disabled, all arguments are unused. */
949 SLJIT_UNUSED_ARG(compiler);
950 SLJIT_UNUSED_ARG(op);
951 SLJIT_UNUSED_ARG(dst);
952 SLJIT_UNUSED_ARG(dstw);
953 SLJIT_UNUSED_ARG(src1);
954 SLJIT_UNUSED_ARG(src1w);
955 SLJIT_UNUSED_ARG(src2);
956 SLJIT_UNUSED_ARG(src2w);
957
958 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
959 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
960 compiler->skip_checks = 0;
961 return;
962 }
963 #endif
964
965 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_ADD && GET_OPCODE(op) <= SLJIT_ASHR);
966 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
967 FUNCTION_CHECK_OP();
968 FUNCTION_CHECK_SRC(src1, src1w);
969 FUNCTION_CHECK_SRC(src2, src2w);
970 FUNCTION_CHECK_DST(dst, dstw);
971 #endif
972 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
973 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
974 fprintf(compiler->verbose, " %s%s%s%s%s%s%s%s ", !(op & SLJIT_INT_OP) ? "" : "i", op_names[GET_OPCODE(op)],
975 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_S) ? "" : ".s", !(op & SLJIT_SET_U) ? "" : ".u",
976 !(op & SLJIT_SET_O) ? "" : ".o", !(op & SLJIT_SET_C) ? "" : ".c", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
977 sljit_verbose_param(dst, dstw);
978 fprintf(compiler->verbose, ", ");
979 sljit_verbose_param(src1, src1w);
980 fprintf(compiler->verbose, ", ");
981 sljit_verbose_param(src2, src2w);
982 fprintf(compiler->verbose, "\n");
983 }
984 #endif
985 }
986
987 static SLJIT_INLINE void check_sljit_get_register_index(sljit_si reg)
988 {
989 SLJIT_UNUSED_ARG(reg);
990 SLJIT_ASSERT(reg > 0 && reg <= SLJIT_NO_REGISTERS);
991 }
992
993 static SLJIT_INLINE void check_sljit_emit_op_custom(struct sljit_compiler *compiler,
994 void *instruction, sljit_si size)
995 {
996 SLJIT_UNUSED_ARG(compiler);
997 SLJIT_UNUSED_ARG(instruction);
998 SLJIT_UNUSED_ARG(size);
999 SLJIT_ASSERT(instruction);
1000 }
1001
1002 static SLJIT_INLINE void check_sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1003 sljit_si dst, sljit_sw dstw,
1004 sljit_si src, sljit_sw srcw)
1005 {
1006 /* If debug and verbose are disabled, all arguments are unused. */
1007 SLJIT_UNUSED_ARG(compiler);
1008 SLJIT_UNUSED_ARG(op);
1009 SLJIT_UNUSED_ARG(dst);
1010 SLJIT_UNUSED_ARG(dstw);
1011 SLJIT_UNUSED_ARG(src);
1012 SLJIT_UNUSED_ARG(srcw);
1013
1014 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1015 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1016 compiler->skip_checks = 0;
1017 return;
1018 }
1019 #endif
1020
1021 SLJIT_ASSERT(sljit_is_fpu_available());
1022 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_CMPD && GET_OPCODE(op) <= SLJIT_ABSD);
1023 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1024 FUNCTION_CHECK_OP();
1025 FUNCTION_FCHECK(src, srcw);
1026 FUNCTION_FCHECK(dst, dstw);
1027 #endif
1028 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1029 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1030 fprintf(compiler->verbose, " %s%s%s%s ", op_names[GET_OPCODE(op)], (op & SLJIT_SINGLE_OP) ? "s" : "d",
1031 !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_SET_S) ? "" : ".s");
1032 sljit_verbose_fparam(dst, dstw);
1033 fprintf(compiler->verbose, ", ");
1034 sljit_verbose_fparam(src, srcw);
1035 fprintf(compiler->verbose, "\n");
1036 }
1037 #endif
1038 }
1039
1040 static SLJIT_INLINE void check_sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1041 sljit_si dst, sljit_sw dstw,
1042 sljit_si src1, sljit_sw src1w,
1043 sljit_si src2, sljit_sw src2w)
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(src1);
1051 SLJIT_UNUSED_ARG(src1w);
1052 SLJIT_UNUSED_ARG(src2);
1053 SLJIT_UNUSED_ARG(src2w);
1054
1055 SLJIT_ASSERT(sljit_is_fpu_available());
1056 SLJIT_ASSERT(GET_OPCODE(op) >= SLJIT_ADDD && GET_OPCODE(op) <= SLJIT_DIVD);
1057 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1058 FUNCTION_CHECK_OP();
1059 FUNCTION_FCHECK(src1, src1w);
1060 FUNCTION_FCHECK(src2, src2w);
1061 FUNCTION_FCHECK(dst, dstw);
1062 #endif
1063 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1064 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1065 fprintf(compiler->verbose, " %s%s ", op_names[GET_OPCODE(op)], (op & SLJIT_SINGLE_OP) ? "s" : "d");
1066 sljit_verbose_fparam(dst, dstw);
1067 fprintf(compiler->verbose, ", ");
1068 sljit_verbose_fparam(src1, src1w);
1069 fprintf(compiler->verbose, ", ");
1070 sljit_verbose_fparam(src2, src2w);
1071 fprintf(compiler->verbose, "\n");
1072 }
1073 #endif
1074 }
1075
1076 static SLJIT_INLINE void check_sljit_emit_label(struct sljit_compiler *compiler)
1077 {
1078 /* If debug and verbose are disabled, all arguments are unused. */
1079 SLJIT_UNUSED_ARG(compiler);
1080
1081 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1082 if (SLJIT_UNLIKELY(!!compiler->verbose))
1083 fprintf(compiler->verbose, "label:\n");
1084 #endif
1085 }
1086
1087 static SLJIT_INLINE void check_sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1088 {
1089 /* If debug and verbose are disabled, all arguments are unused. */
1090 SLJIT_UNUSED_ARG(compiler);
1091 SLJIT_UNUSED_ARG(type);
1092
1093 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1094 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1095 compiler->skip_checks = 0;
1096 return;
1097 }
1098 #endif
1099
1100 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP)));
1101 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_EQUAL && (type & 0xff) <= SLJIT_CALL3);
1102 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1103 if (SLJIT_UNLIKELY(!!compiler->verbose))
1104 fprintf(compiler->verbose, " jump%s<%s>\n", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1105 #endif
1106 }
1107
1108 static SLJIT_INLINE void check_sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1109 sljit_si src1, sljit_sw src1w,
1110 sljit_si src2, sljit_sw src2w)
1111 {
1112 SLJIT_UNUSED_ARG(compiler);
1113 SLJIT_UNUSED_ARG(type);
1114 SLJIT_UNUSED_ARG(src1);
1115 SLJIT_UNUSED_ARG(src1w);
1116 SLJIT_UNUSED_ARG(src2);
1117 SLJIT_UNUSED_ARG(src2w);
1118
1119 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_INT_OP)));
1120 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_EQUAL && (type & 0xff) <= SLJIT_C_SIG_LESS_EQUAL);
1121 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1122 FUNCTION_CHECK_SRC(src1, src1w);
1123 FUNCTION_CHECK_SRC(src2, src2w);
1124 #endif
1125 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1126 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1127 fprintf(compiler->verbose, " %scmp%s<%s> ", !(type & SLJIT_INT_OP) ? "" : "i", !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1128 sljit_verbose_param(src1, src1w);
1129 fprintf(compiler->verbose, ", ");
1130 sljit_verbose_param(src2, src2w);
1131 fprintf(compiler->verbose, "\n");
1132 }
1133 #endif
1134 }
1135
1136 static SLJIT_INLINE void check_sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1137 sljit_si src1, sljit_sw src1w,
1138 sljit_si src2, sljit_sw src2w)
1139 {
1140 SLJIT_UNUSED_ARG(compiler);
1141 SLJIT_UNUSED_ARG(type);
1142 SLJIT_UNUSED_ARG(src1);
1143 SLJIT_UNUSED_ARG(src1w);
1144 SLJIT_UNUSED_ARG(src2);
1145 SLJIT_UNUSED_ARG(src2w);
1146
1147 SLJIT_ASSERT(sljit_is_fpu_available());
1148 SLJIT_ASSERT(!(type & ~(0xff | SLJIT_REWRITABLE_JUMP | SLJIT_SINGLE_OP)));
1149 SLJIT_ASSERT((type & 0xff) >= SLJIT_C_FLOAT_EQUAL && (type & 0xff) <= SLJIT_C_FLOAT_ORDERED);
1150 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1151 FUNCTION_FCHECK(src1, src1w);
1152 FUNCTION_FCHECK(src2, src2w);
1153 #endif
1154 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1155 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1156 fprintf(compiler->verbose, " %scmp%s<%s> ", (type & SLJIT_SINGLE_OP) ? "s" : "d",
1157 !(type & SLJIT_REWRITABLE_JUMP) ? "" : ".r", jump_names[type & 0xff]);
1158 sljit_verbose_fparam(src1, src1w);
1159 fprintf(compiler->verbose, ", ");
1160 sljit_verbose_fparam(src2, src2w);
1161 fprintf(compiler->verbose, "\n");
1162 }
1163 #endif
1164 }
1165
1166 static SLJIT_INLINE void check_sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1167 {
1168 /* If debug and verbose are disabled, all arguments are unused. */
1169 SLJIT_UNUSED_ARG(compiler);
1170 SLJIT_UNUSED_ARG(type);
1171 SLJIT_UNUSED_ARG(src);
1172 SLJIT_UNUSED_ARG(srcw);
1173
1174 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1175 if (SLJIT_UNLIKELY(compiler->skip_checks)) {
1176 compiler->skip_checks = 0;
1177 return;
1178 }
1179 #endif
1180
1181 SLJIT_ASSERT(type >= SLJIT_JUMP && type <= SLJIT_CALL3);
1182 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1183 FUNCTION_CHECK_SRC(src, srcw);
1184 #endif
1185 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1186 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1187 fprintf(compiler->verbose, " ijump<%s> ", jump_names[type]);
1188 sljit_verbose_param(src, srcw);
1189 fprintf(compiler->verbose, "\n");
1190 }
1191 #endif
1192 }
1193
1194 static SLJIT_INLINE void check_sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1195 sljit_si dst, sljit_sw dstw,
1196 sljit_si src, sljit_sw srcw,
1197 sljit_si type)
1198 {
1199 /* If debug and verbose are disabled, all arguments are unused. */
1200 SLJIT_UNUSED_ARG(compiler);
1201 SLJIT_UNUSED_ARG(op);
1202 SLJIT_UNUSED_ARG(dst);
1203 SLJIT_UNUSED_ARG(dstw);
1204 SLJIT_UNUSED_ARG(src);
1205 SLJIT_UNUSED_ARG(srcw);
1206 SLJIT_UNUSED_ARG(type);
1207
1208 SLJIT_ASSERT(type >= SLJIT_C_EQUAL && type < SLJIT_JUMP);
1209 SLJIT_ASSERT(op == SLJIT_MOV || GET_OPCODE(op) == SLJIT_MOV_UI || GET_OPCODE(op) == SLJIT_MOV_SI
1210 || (GET_OPCODE(op) >= SLJIT_AND && GET_OPCODE(op) <= SLJIT_XOR));
1211 SLJIT_ASSERT((op & (SLJIT_SET_S | SLJIT_SET_U | SLJIT_SET_O | SLJIT_SET_C)) == 0);
1212 SLJIT_ASSERT((op & (SLJIT_SET_E | SLJIT_KEEP_FLAGS)) != (SLJIT_SET_E | SLJIT_KEEP_FLAGS));
1213 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1214 if (GET_OPCODE(op) < SLJIT_ADD) {
1215 SLJIT_ASSERT(src == SLJIT_UNUSED && srcw == 0);
1216 } else {
1217 SLJIT_ASSERT(src == dst && srcw == dstw);
1218 }
1219 FUNCTION_CHECK_DST(dst, dstw);
1220 #endif
1221 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1222 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1223 fprintf(compiler->verbose, " op_flags<%s%s%s%s> ", !(op & SLJIT_INT_OP) ? "" : "i",
1224 op_names[GET_OPCODE(op)], !(op & SLJIT_SET_E) ? "" : ".e", !(op & SLJIT_KEEP_FLAGS) ? "" : ".k");
1225 sljit_verbose_param(dst, dstw);
1226 if (src != SLJIT_UNUSED) {
1227 fprintf(compiler->verbose, ", ");
1228 sljit_verbose_param(src, srcw);
1229 }
1230 fprintf(compiler->verbose, ", <%s>\n", jump_names[type]);
1231 }
1232 #endif
1233 }
1234
1235 static SLJIT_INLINE void check_sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1236 {
1237 SLJIT_UNUSED_ARG(compiler);
1238 SLJIT_UNUSED_ARG(dst);
1239 SLJIT_UNUSED_ARG(dstw);
1240 SLJIT_UNUSED_ARG(offset);
1241
1242 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1243 FUNCTION_CHECK_DST(dst, dstw);
1244 #endif
1245 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1246 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1247 fprintf(compiler->verbose, " local_base ");
1248 sljit_verbose_param(dst, dstw);
1249 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", offset);
1250 }
1251 #endif
1252 }
1253
1254 static SLJIT_INLINE void check_sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value)
1255 {
1256 /* If debug and verbose are disabled, all arguments are unused. */
1257 SLJIT_UNUSED_ARG(compiler);
1258 SLJIT_UNUSED_ARG(dst);
1259 SLJIT_UNUSED_ARG(dstw);
1260 SLJIT_UNUSED_ARG(init_value);
1261
1262 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
1263 FUNCTION_CHECK_DST(dst, dstw);
1264 #endif
1265 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1266 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
1267 fprintf(compiler->verbose, " const ");
1268 sljit_verbose_param(dst, dstw);
1269 fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value);
1270 }
1271 #endif
1272 }
1273
1274 static SLJIT_INLINE sljit_si emit_mov_before_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1275 {
1276 /* Return if don't need to do anything. */
1277 if (op == SLJIT_UNUSED)
1278 return SLJIT_SUCCESS;
1279
1280 #if (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1281 /* At the moment the pointer size is always equal to sljit_sw. May be changed in the future. */
1282 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_P))
1283 return SLJIT_SUCCESS;
1284 #else
1285 if (src == SLJIT_RETURN_REG && (op == SLJIT_MOV || op == SLJIT_MOV_UI || op == SLJIT_MOV_SI || op == SLJIT_MOV_P))
1286 return SLJIT_SUCCESS;
1287 #endif
1288
1289 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1290 compiler->skip_checks = 1;
1291 #endif
1292 return sljit_emit_op1(compiler, op, SLJIT_RETURN_REG, 0, src, srcw);
1293 }
1294
1295 /* CPU description section */
1296
1297 #if (defined SLJIT_32BIT_ARCHITECTURE && SLJIT_32BIT_ARCHITECTURE)
1298 #define SLJIT_CPUINFO_PART1 " 32bit ("
1299 #elif (defined SLJIT_64BIT_ARCHITECTURE && SLJIT_64BIT_ARCHITECTURE)
1300 #define SLJIT_CPUINFO_PART1 " 64bit ("
1301 #else
1302 #error "Internal error: CPU type info missing"
1303 #endif
1304
1305 #if (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
1306 #define SLJIT_CPUINFO_PART2 "little endian + "
1307 #elif (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN)
1308 #define SLJIT_CPUINFO_PART2 "big endian + "
1309 #else
1310 #error "Internal error: CPU type info missing"
1311 #endif
1312
1313 #if (defined SLJIT_UNALIGNED && SLJIT_UNALIGNED)
1314 #define SLJIT_CPUINFO_PART3 "unaligned)"
1315 #else
1316 #define SLJIT_CPUINFO_PART3 "aligned)"
1317 #endif
1318
1319 #define SLJIT_CPUINFO SLJIT_CPUINFO_PART1 SLJIT_CPUINFO_PART2 SLJIT_CPUINFO_PART3
1320
1321 #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
1322 # include "sljitNativeX86_common.c"
1323 #elif (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1324 # include "sljitNativeX86_common.c"
1325 #elif (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5)
1326 # include "sljitNativeARM_v5.c"
1327 #elif (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7)
1328 # include "sljitNativeARM_v5.c"
1329 #elif (defined SLJIT_CONFIG_ARM_THUMB2 && SLJIT_CONFIG_ARM_THUMB2)
1330 # include "sljitNativeARM_Thumb2.c"
1331 #elif (defined SLJIT_CONFIG_PPC_32 && SLJIT_CONFIG_PPC_32)
1332 # include "sljitNativePPC_common.c"
1333 #elif (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
1334 # include "sljitNativePPC_common.c"
1335 #elif (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1336 # include "sljitNativeMIPS_common.c"
1337 #elif (defined SLJIT_CONFIG_SPARC_32 && SLJIT_CONFIG_SPARC_32)
1338 # include "sljitNativeSPARC_common.c"
1339 #endif
1340
1341 #if !(defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1342
1343 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1344 sljit_si src1, sljit_sw src1w,
1345 sljit_si src2, sljit_sw src2w)
1346 {
1347 /* Default compare for most architectures. */
1348 sljit_si flags, tmp_src, condition;
1349 sljit_sw tmp_srcw;
1350
1351 CHECK_ERROR_PTR();
1352 check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
1353
1354 condition = type & 0xff;
1355 if (SLJIT_UNLIKELY((src1 & SLJIT_IMM) && !(src2 & SLJIT_IMM))) {
1356 /* Immediate is prefered as second argument by most architectures. */
1357 switch (condition) {
1358 case SLJIT_C_LESS:
1359 condition = SLJIT_C_GREATER;
1360 break;
1361 case SLJIT_C_GREATER_EQUAL:
1362 condition = SLJIT_C_LESS_EQUAL;
1363 break;
1364 case SLJIT_C_GREATER:
1365 condition = SLJIT_C_LESS;
1366 break;
1367 case SLJIT_C_LESS_EQUAL:
1368 condition = SLJIT_C_GREATER_EQUAL;
1369 break;
1370 case SLJIT_C_SIG_LESS:
1371 condition = SLJIT_C_SIG_GREATER;
1372 break;
1373 case SLJIT_C_SIG_GREATER_EQUAL:
1374 condition = SLJIT_C_SIG_LESS_EQUAL;
1375 break;
1376 case SLJIT_C_SIG_GREATER:
1377 condition = SLJIT_C_SIG_LESS;
1378 break;
1379 case SLJIT_C_SIG_LESS_EQUAL:
1380 condition = SLJIT_C_SIG_GREATER_EQUAL;
1381 break;
1382 }
1383 type = condition | (type & (SLJIT_INT_OP | SLJIT_REWRITABLE_JUMP));
1384 tmp_src = src1;
1385 src1 = src2;
1386 src2 = tmp_src;
1387 tmp_srcw = src1w;
1388 src1w = src2w;
1389 src2w = tmp_srcw;
1390 }
1391
1392 if (condition <= SLJIT_C_NOT_ZERO)
1393 flags = SLJIT_SET_E;
1394 else if (condition <= SLJIT_C_LESS_EQUAL)
1395 flags = SLJIT_SET_U;
1396 else
1397 flags = SLJIT_SET_S;
1398
1399 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1400 compiler->skip_checks = 1;
1401 #endif
1402 PTR_FAIL_IF(sljit_emit_op2(compiler, SLJIT_SUB | flags | (type & SLJIT_INT_OP),
1403 SLJIT_UNUSED, 0, src1, src1w, src2, src2w));
1404 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1405 compiler->skip_checks = 1;
1406 #endif
1407 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1408 }
1409
1410 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1411 sljit_si src1, sljit_sw src1w,
1412 sljit_si src2, sljit_sw src2w)
1413 {
1414 sljit_si flags, condition;
1415
1416 check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w);
1417
1418 condition = type & 0xff;
1419 flags = (condition <= SLJIT_C_FLOAT_NOT_EQUAL) ? SLJIT_SET_E : SLJIT_SET_S;
1420 if (type & SLJIT_SINGLE_OP)
1421 flags |= SLJIT_SINGLE_OP;
1422
1423 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1424 compiler->skip_checks = 1;
1425 #endif
1426 sljit_emit_fop1(compiler, SLJIT_CMPD | flags, src1, src1w, src2, src2w);
1427
1428 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1429 compiler->skip_checks = 1;
1430 #endif
1431 return sljit_emit_jump(compiler, condition | (type & SLJIT_REWRITABLE_JUMP));
1432 }
1433
1434 #endif
1435
1436 #if !(defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) && !(defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1437
1438 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1439 {
1440 CHECK_ERROR();
1441 check_sljit_get_local_base(compiler, dst, dstw, offset);
1442
1443 ADJUST_LOCAL_OFFSET(SLJIT_MEM1(SLJIT_LOCALS_REG), offset);
1444 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) || (defined SLJIT_DEBUG && SLJIT_DEBUG)
1445 compiler->skip_checks = 1;
1446 #endif
1447 if (offset != 0)
1448 return sljit_emit_op2(compiler, SLJIT_ADD | SLJIT_KEEP_FLAGS, dst, dstw, SLJIT_LOCALS_REG, 0, SLJIT_IMM, offset);
1449 return sljit_emit_op1(compiler, SLJIT_MOV, dst, dstw, SLJIT_LOCALS_REG, 0);
1450 }
1451
1452 #endif
1453
1454 #else /* SLJIT_CONFIG_UNSUPPORTED */
1455
1456 /* Empty function bodies for those machines, which are not (yet) supported. */
1457
1458 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
1459 {
1460 return "unsupported";
1461 }
1462
1463 SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void)
1464 {
1465 SLJIT_ASSERT_STOP();
1466 return NULL;
1467 }
1468
1469 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_compiler(struct sljit_compiler *compiler)
1470 {
1471 SLJIT_UNUSED_ARG(compiler);
1472 SLJIT_ASSERT_STOP();
1473 }
1474
1475 SLJIT_API_FUNC_ATTRIBUTE void* sljit_alloc_memory(struct sljit_compiler *compiler, sljit_si size)
1476 {
1477 SLJIT_UNUSED_ARG(compiler);
1478 SLJIT_UNUSED_ARG(size);
1479 SLJIT_ASSERT_STOP();
1480 return NULL;
1481 }
1482
1483 #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE)
1484 SLJIT_API_FUNC_ATTRIBUTE void sljit_compiler_verbose(struct sljit_compiler *compiler, FILE* verbose)
1485 {
1486 SLJIT_UNUSED_ARG(compiler);
1487 SLJIT_UNUSED_ARG(verbose);
1488 SLJIT_ASSERT_STOP();
1489 }
1490 #endif
1491
1492 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
1493 {
1494 SLJIT_UNUSED_ARG(compiler);
1495 SLJIT_ASSERT_STOP();
1496 return NULL;
1497 }
1498
1499 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code)
1500 {
1501 SLJIT_UNUSED_ARG(code);
1502 SLJIT_ASSERT_STOP();
1503 }
1504
1505 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_enter(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
1506 {
1507 SLJIT_UNUSED_ARG(compiler);
1508 SLJIT_UNUSED_ARG(args);
1509 SLJIT_UNUSED_ARG(scratches);
1510 SLJIT_UNUSED_ARG(saveds);
1511 SLJIT_UNUSED_ARG(local_size);
1512 SLJIT_ASSERT_STOP();
1513 return SLJIT_ERR_UNSUPPORTED;
1514 }
1515
1516 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_context(struct sljit_compiler *compiler, sljit_si args, sljit_si scratches, sljit_si saveds, sljit_si local_size)
1517 {
1518 SLJIT_UNUSED_ARG(compiler);
1519 SLJIT_UNUSED_ARG(args);
1520 SLJIT_UNUSED_ARG(scratches);
1521 SLJIT_UNUSED_ARG(saveds);
1522 SLJIT_UNUSED_ARG(local_size);
1523 SLJIT_ASSERT_STOP();
1524 }
1525
1526 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1527 {
1528 SLJIT_UNUSED_ARG(compiler);
1529 SLJIT_UNUSED_ARG(op);
1530 SLJIT_UNUSED_ARG(src);
1531 SLJIT_UNUSED_ARG(srcw);
1532 SLJIT_ASSERT_STOP();
1533 return SLJIT_ERR_UNSUPPORTED;
1534 }
1535
1536 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1537 {
1538 SLJIT_UNUSED_ARG(compiler);
1539 SLJIT_UNUSED_ARG(dst);
1540 SLJIT_UNUSED_ARG(dstw);
1541 SLJIT_ASSERT_STOP();
1542 return SLJIT_ERR_UNSUPPORTED;
1543 }
1544
1545 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1546 {
1547 SLJIT_UNUSED_ARG(compiler);
1548 SLJIT_UNUSED_ARG(src);
1549 SLJIT_UNUSED_ARG(srcw);
1550 SLJIT_ASSERT_STOP();
1551 return SLJIT_ERR_UNSUPPORTED;
1552 }
1553
1554 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1555 {
1556 SLJIT_UNUSED_ARG(compiler);
1557 SLJIT_UNUSED_ARG(op);
1558 SLJIT_ASSERT_STOP();
1559 return SLJIT_ERR_UNSUPPORTED;
1560 }
1561
1562 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1563 sljit_si dst, sljit_sw dstw,
1564 sljit_si src, sljit_sw srcw)
1565 {
1566 SLJIT_UNUSED_ARG(compiler);
1567 SLJIT_UNUSED_ARG(op);
1568 SLJIT_UNUSED_ARG(dst);
1569 SLJIT_UNUSED_ARG(dstw);
1570 SLJIT_UNUSED_ARG(src);
1571 SLJIT_UNUSED_ARG(srcw);
1572 SLJIT_ASSERT_STOP();
1573 return SLJIT_ERR_UNSUPPORTED;
1574 }
1575
1576 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1577 sljit_si dst, sljit_sw dstw,
1578 sljit_si src1, sljit_sw src1w,
1579 sljit_si src2, sljit_sw src2w)
1580 {
1581 SLJIT_UNUSED_ARG(compiler);
1582 SLJIT_UNUSED_ARG(op);
1583 SLJIT_UNUSED_ARG(dst);
1584 SLJIT_UNUSED_ARG(dstw);
1585 SLJIT_UNUSED_ARG(src1);
1586 SLJIT_UNUSED_ARG(src1w);
1587 SLJIT_UNUSED_ARG(src2);
1588 SLJIT_UNUSED_ARG(src2w);
1589 SLJIT_ASSERT_STOP();
1590 return SLJIT_ERR_UNSUPPORTED;
1591 }
1592
1593 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg)
1594 {
1595 SLJIT_ASSERT_STOP();
1596 return reg;
1597 }
1598
1599 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
1600 void *instruction, sljit_si size)
1601 {
1602 SLJIT_UNUSED_ARG(compiler);
1603 SLJIT_UNUSED_ARG(instruction);
1604 SLJIT_UNUSED_ARG(size);
1605 SLJIT_ASSERT_STOP();
1606 return SLJIT_ERR_UNSUPPORTED;
1607 }
1608
1609 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void)
1610 {
1611 SLJIT_ASSERT_STOP();
1612 return 0;
1613 }
1614
1615 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1616 sljit_si dst, sljit_sw dstw,
1617 sljit_si src, sljit_sw srcw)
1618 {
1619 SLJIT_UNUSED_ARG(compiler);
1620 SLJIT_UNUSED_ARG(op);
1621 SLJIT_UNUSED_ARG(dst);
1622 SLJIT_UNUSED_ARG(dstw);
1623 SLJIT_UNUSED_ARG(src);
1624 SLJIT_UNUSED_ARG(srcw);
1625 SLJIT_ASSERT_STOP();
1626 return SLJIT_ERR_UNSUPPORTED;
1627 }
1628
1629 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1630 sljit_si dst, sljit_sw dstw,
1631 sljit_si src1, sljit_sw src1w,
1632 sljit_si src2, sljit_sw src2w)
1633 {
1634 SLJIT_UNUSED_ARG(compiler);
1635 SLJIT_UNUSED_ARG(op);
1636 SLJIT_UNUSED_ARG(dst);
1637 SLJIT_UNUSED_ARG(dstw);
1638 SLJIT_UNUSED_ARG(src1);
1639 SLJIT_UNUSED_ARG(src1w);
1640 SLJIT_UNUSED_ARG(src2);
1641 SLJIT_UNUSED_ARG(src2w);
1642 SLJIT_ASSERT_STOP();
1643 return SLJIT_ERR_UNSUPPORTED;
1644 }
1645
1646 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1647 {
1648 SLJIT_UNUSED_ARG(compiler);
1649 SLJIT_ASSERT_STOP();
1650 return NULL;
1651 }
1652
1653 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1654 {
1655 SLJIT_UNUSED_ARG(compiler);
1656 SLJIT_UNUSED_ARG(type);
1657 SLJIT_ASSERT_STOP();
1658 return NULL;
1659 }
1660
1661 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1662 sljit_si src1, sljit_sw src1w,
1663 sljit_si src2, sljit_sw src2w)
1664 {
1665 SLJIT_UNUSED_ARG(compiler);
1666 SLJIT_UNUSED_ARG(type);
1667 SLJIT_UNUSED_ARG(src1);
1668 SLJIT_UNUSED_ARG(src1w);
1669 SLJIT_UNUSED_ARG(src2);
1670 SLJIT_UNUSED_ARG(src2w);
1671 SLJIT_ASSERT_STOP();
1672 return NULL;
1673 }
1674
1675 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1676 sljit_si src1, sljit_sw src1w,
1677 sljit_si src2, sljit_sw src2w)
1678 {
1679 SLJIT_UNUSED_ARG(compiler);
1680 SLJIT_UNUSED_ARG(type);
1681 SLJIT_UNUSED_ARG(src1);
1682 SLJIT_UNUSED_ARG(src1w);
1683 SLJIT_UNUSED_ARG(src2);
1684 SLJIT_UNUSED_ARG(src2w);
1685 SLJIT_ASSERT_STOP();
1686 return NULL;
1687 }
1688
1689 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_label(struct sljit_jump *jump, struct sljit_label* label)
1690 {
1691 SLJIT_UNUSED_ARG(jump);
1692 SLJIT_UNUSED_ARG(label);
1693 SLJIT_ASSERT_STOP();
1694 }
1695
1696 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_target(struct sljit_jump *jump, sljit_uw target)
1697 {
1698 SLJIT_UNUSED_ARG(jump);
1699 SLJIT_UNUSED_ARG(target);
1700 SLJIT_ASSERT_STOP();
1701 }
1702
1703 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1704 {
1705 SLJIT_UNUSED_ARG(compiler);
1706 SLJIT_UNUSED_ARG(type);
1707 SLJIT_UNUSED_ARG(src);
1708 SLJIT_UNUSED_ARG(srcw);
1709 SLJIT_ASSERT_STOP();
1710 return SLJIT_ERR_UNSUPPORTED;
1711 }
1712
1713 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1714 sljit_si dst, sljit_sw dstw,
1715 sljit_si src, sljit_sw srcw,
1716 sljit_si type)
1717 {
1718 SLJIT_UNUSED_ARG(compiler);
1719 SLJIT_UNUSED_ARG(op);
1720 SLJIT_UNUSED_ARG(dst);
1721 SLJIT_UNUSED_ARG(dstw);
1722 SLJIT_UNUSED_ARG(src);
1723 SLJIT_UNUSED_ARG(srcw);
1724 SLJIT_UNUSED_ARG(type);
1725 SLJIT_ASSERT_STOP();
1726 return SLJIT_ERR_UNSUPPORTED;
1727 }
1728
1729 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_local_base(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw offset)
1730 {
1731 SLJIT_UNUSED_ARG(compiler);
1732 SLJIT_UNUSED_ARG(dst);
1733 SLJIT_UNUSED_ARG(dstw);
1734 SLJIT_UNUSED_ARG(offset);
1735 SLJIT_ASSERT_STOP();
1736 return SLJIT_ERR_UNSUPPORTED;
1737 }
1738
1739 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw initval)
1740 {
1741 SLJIT_UNUSED_ARG(compiler);
1742 SLJIT_UNUSED_ARG(dst);
1743 SLJIT_UNUSED_ARG(dstw);
1744 SLJIT_UNUSED_ARG(initval);
1745 SLJIT_ASSERT_STOP();
1746 return NULL;
1747 }
1748
1749 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
1750 {
1751 SLJIT_UNUSED_ARG(addr);
1752 SLJIT_UNUSED_ARG(new_addr);
1753 SLJIT_ASSERT_STOP();
1754 }
1755
1756 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant)
1757 {
1758 SLJIT_UNUSED_ARG(addr);
1759 SLJIT_UNUSED_ARG(new_constant);
1760 SLJIT_ASSERT_STOP();
1761 }
1762
1763 #endif

  ViewVC Help
Powered by ViewVC 1.1.5