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