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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.5