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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5