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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1243 - (show annotations)
Tue Jan 29 08:11:36 2013 UTC (6 years, 11 months ago) by zherczeg
File MIME type: text/plain
File size: 60898 byte(s)
JIT compiler update.
1 /*
2 * Stack-less Just-In-Time compiler
3 *
4 * Copyright 2009-2012 Zoltan Herczeg (hzmester@freemail.hu). All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification, are
7 * permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice, this list of
10 * conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 * of conditions and the following disclaimer in the documentation and/or other materials
14 * provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE COPYRIGHT HOLDER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 /* Latest MIPS architecture. */
28 /* Automatically detect SLJIT_MIPS_32_64 */
29
30 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
31 {
32 #if (defined SLJIT_MIPS_32_64 && SLJIT_MIPS_32_64)
33 return "MIPS(32)" SLJIT_CPUINFO;
34 #else
35 return "MIPS III" SLJIT_CPUINFO;
36 #endif
37 }
38
39 /* Length of an instruction word
40 Both for mips-32 and mips-64 */
41 typedef sljit_ui sljit_ins;
42
43 #define TMP_REG1 (SLJIT_NO_REGISTERS + 1)
44 #define TMP_REG2 (SLJIT_NO_REGISTERS + 2)
45 #define TMP_REG3 (SLJIT_NO_REGISTERS + 3)
46
47 /* For position independent code, t9 must contain the function address. */
48 #define PIC_ADDR_REG TMP_REG2
49
50 /* TMP_EREG1 is used mainly for literal encoding on 64 bit. */
51 #define TMP_EREG1 15
52 #define TMP_EREG2 24
53 /* Floating point status register. */
54 #define FCSR_REG 31
55 /* Return address register. */
56 #define RETURN_ADDR_REG 31
57
58 /* Flags are keept in volatile registers. */
59 #define EQUAL_FLAG 7
60 /* And carry flag as well. */
61 #define ULESS_FLAG 10
62 #define UGREATER_FLAG 11
63 #define LESS_FLAG 12
64 #define GREATER_FLAG 13
65 #define OVERFLOW_FLAG 14
66
67 #define TMP_FREG1 (0)
68 #define TMP_FREG2 ((SLJIT_FLOAT_REG6 + 1) << 1)
69
70 static SLJIT_CONST sljit_ub reg_map[SLJIT_NO_REGISTERS + 4] = {
71 0, 2, 5, 6, 3, 8, 16, 17, 18, 19, 20, 29, 4, 25, 9
72 };
73
74 /* --------------------------------------------------------------------- */
75 /* Instrucion forms */
76 /* --------------------------------------------------------------------- */
77
78 #define S(s) (reg_map[s] << 21)
79 #define T(t) (reg_map[t] << 16)
80 #define D(d) (reg_map[d] << 11)
81 /* Absolute registers. */
82 #define SA(s) ((s) << 21)
83 #define TA(t) ((t) << 16)
84 #define DA(d) ((d) << 11)
85 #define FT(t) ((t) << 16)
86 #define FS(s) ((s) << 11)
87 #define FD(d) ((d) << 6)
88 #define IMM(imm) ((imm) & 0xffff)
89 #define SH_IMM(imm) ((imm & 0x1f) << 6)
90
91 #define DR(dr) (reg_map[dr])
92 #define HI(opcode) ((opcode) << 26)
93 #define LO(opcode) (opcode)
94 /* S = (16 << 21) D = (17 << 21) */
95 #define FMT_SD (16 << 21)
96
97 #define ABS_fmt (HI(17) | FMT_SD | LO(5))
98 #define ADD_fmt (HI(17) | FMT_SD | LO(0))
99 #define ADDU (HI(0) | LO(33))
100 #define ADDIU (HI(9))
101 #define AND (HI(0) | LO(36))
102 #define ANDI (HI(12))
103 #define B (HI(4))
104 #define BAL (HI(1) | (17 << 16))
105 #define BC1F (HI(17) | (8 << 21))
106 #define BC1T (HI(17) | (8 << 21) | (1 << 16))
107 #define BEQ (HI(4))
108 #define BGEZ (HI(1) | (1 << 16))
109 #define BGTZ (HI(7))
110 #define BLEZ (HI(6))
111 #define BLTZ (HI(1) | (0 << 16))
112 #define BNE (HI(5))
113 #define BREAK (HI(0) | LO(13))
114 #define CFC1 (HI(17) | (2 << 21))
115 #define C_UN_fmt (HI(17) | FMT_SD | LO(49))
116 #define C_UEQ_fmt (HI(17) | FMT_SD | LO(51))
117 #define C_ULE_fmt (HI(17) | FMT_SD | LO(55))
118 #define C_ULT_fmt (HI(17) | FMT_SD | LO(53))
119 #define DIV (HI(0) | LO(26))
120 #define DIVU (HI(0) | LO(27))
121 #define DIV_fmt (HI(17) | FMT_SD | LO(3))
122 #define J (HI(2))
123 #define JAL (HI(3))
124 #define JALR (HI(0) | LO(9))
125 #define JR (HI(0) | LO(8))
126 #define LD (HI(55))
127 #define LUI (HI(15))
128 #define LW (HI(35))
129 #define MFHI (HI(0) | LO(16))
130 #define MFLO (HI(0) | LO(18))
131 #define MOV_fmt (HI(17) | FMT_SD | LO(6))
132 #define MOVN (HI(0) | LO(11))
133 #define MOVZ (HI(0) | LO(10))
134 #define MUL_fmt (HI(17) | FMT_SD | LO(2))
135 #define MULT (HI(0) | LO(24))
136 #define MULTU (HI(0) | LO(25))
137 #define NEG_fmt (HI(17) | FMT_SD | LO(7))
138 #define NOP (HI(0) | LO(0))
139 #define NOR (HI(0) | LO(39))
140 #define OR (HI(0) | LO(37))
141 #define ORI (HI(13))
142 #define SD (HI(63))
143 #define SLT (HI(0) | LO(42))
144 #define SLTI (HI(10))
145 #define SLTIU (HI(11))
146 #define SLTU (HI(0) | LO(43))
147 #define SLL (HI(0) | LO(0))
148 #define SLLV (HI(0) | LO(4))
149 #define SRL (HI(0) | LO(2))
150 #define SRLV (HI(0) | LO(6))
151 #define SRA (HI(0) | LO(3))
152 #define SRAV (HI(0) | LO(7))
153 #define SUB_fmt (HI(17) | FMT_SD | LO(1))
154 #define SUBU (HI(0) | LO(35))
155 #define SW (HI(43))
156 #define XOR (HI(0) | LO(38))
157 #define XORI (HI(14))
158
159 #if (defined SLJIT_MIPS_32_64 && SLJIT_MIPS_32_64)
160 #define CLZ (HI(28) | LO(32))
161 #define MUL (HI(28) | LO(2))
162 #define SEB (HI(31) | (16 << 6) | LO(32))
163 #define SEH (HI(31) | (24 << 6) | LO(32))
164 #endif
165
166 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
167 #define ADDU_W ADDU
168 #define ADDIU_W ADDIU
169 #define SLL_W SLL
170 #define SUBU_W SUBU
171 #else
172 #define ADDU_W DADDU
173 #define ADDIU_W DADDIU
174 #define SLL_W DSLL
175 #define SUBU_W DSUBU
176 #endif
177
178 #define SIMM_MAX (0x7fff)
179 #define SIMM_MIN (-0x8000)
180 #define UIMM_MAX (0xffff)
181
182 /* dest_reg is the absolute name of the register
183 Useful for reordering instructions in the delay slot. */
184 static sljit_si push_inst(struct sljit_compiler *compiler, sljit_ins ins, sljit_si delay_slot)
185 {
186 SLJIT_ASSERT(delay_slot == MOVABLE_INS || delay_slot >= UNMOVABLE_INS
187 || delay_slot == ((ins >> 11) & 0x1f) || delay_slot == ((ins >> 16) & 0x1f));
188 sljit_ins *ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins));
189 FAIL_IF(!ptr);
190 *ptr = ins;
191 compiler->size++;
192 compiler->delay_slot = delay_slot;
193 return SLJIT_SUCCESS;
194 }
195
196 static SLJIT_INLINE sljit_ins invert_branch(sljit_si flags)
197 {
198 return (flags & IS_BIT26_COND) ? (1 << 26) : (1 << 16);
199 }
200
201 static SLJIT_INLINE sljit_ins* optimize_jump(struct sljit_jump *jump, sljit_ins *code_ptr, sljit_ins *code)
202 {
203 sljit_sw diff;
204 sljit_uw target_addr;
205 sljit_ins *inst;
206 sljit_ins saved_inst;
207
208 if (jump->flags & SLJIT_REWRITABLE_JUMP)
209 return code_ptr;
210
211 if (jump->flags & JUMP_ADDR)
212 target_addr = jump->u.target;
213 else {
214 SLJIT_ASSERT(jump->flags & JUMP_LABEL);
215 target_addr = (sljit_uw)(code + jump->u.label->size);
216 }
217 inst = (sljit_ins*)jump->addr;
218 if (jump->flags & IS_COND)
219 inst--;
220
221 /* B instructions. */
222 if (jump->flags & IS_MOVABLE) {
223 diff = ((sljit_sw)target_addr - (sljit_sw)(inst)) >> 2;
224 if (diff <= SIMM_MAX && diff >= SIMM_MIN) {
225 jump->flags |= PATCH_B;
226
227 if (!(jump->flags & IS_COND)) {
228 inst[0] = inst[-1];
229 inst[-1] = (jump->flags & IS_JAL) ? BAL : B;
230 jump->addr -= sizeof(sljit_ins);
231 return inst;
232 }
233 saved_inst = inst[0];
234 inst[0] = inst[-1];
235 inst[-1] = saved_inst ^ invert_branch(jump->flags);
236 jump->addr -= 2 * sizeof(sljit_ins);
237 return inst;
238 }
239 }
240
241 diff = ((sljit_sw)target_addr - (sljit_sw)(inst + 1)) >> 2;
242 if (diff <= SIMM_MAX && diff >= SIMM_MIN) {
243 jump->flags |= PATCH_B;
244
245 if (!(jump->flags & IS_COND)) {
246 inst[0] = (jump->flags & IS_JAL) ? BAL : B;
247 inst[1] = NOP;
248 return inst + 1;
249 }
250 inst[0] = inst[0] ^ invert_branch(jump->flags);
251 inst[1] = NOP;
252 jump->addr -= sizeof(sljit_ins);
253 return inst + 1;
254 }
255
256 if (jump->flags & IS_COND) {
257 if ((target_addr & ~0xfffffff) == ((jump->addr + 3 * sizeof(sljit_ins)) & ~0xfffffff)) {
258 jump->flags |= PATCH_J;
259 inst[0] = (inst[0] & 0xffff0000) | 3;
260 inst[1] = NOP;
261 inst[2] = J;
262 inst[3] = NOP;
263 jump->addr += sizeof(sljit_ins);
264 return inst + 3;
265 }
266 return code_ptr;
267 }
268
269 /* J instuctions. */
270 if (jump->flags & IS_MOVABLE) {
271 if ((target_addr & ~0xfffffff) == (jump->addr & ~0xfffffff)) {
272 jump->flags |= PATCH_J;
273 inst[0] = inst[-1];
274 inst[-1] = (jump->flags & IS_JAL) ? JAL : J;
275 jump->addr -= sizeof(sljit_ins);
276 return inst;
277 }
278 }
279
280 if ((target_addr & ~0xfffffff) == ((jump->addr + sizeof(sljit_ins)) & ~0xfffffff)) {
281 jump->flags |= PATCH_J;
282 inst[0] = (jump->flags & IS_JAL) ? JAL : J;
283 inst[1] = NOP;
284 return inst + 1;
285 }
286
287 return code_ptr;
288 }
289
290 #ifdef __GNUC__
291 static __attribute__ ((noinline)) void sljit_cache_flush(void* code, void* code_ptr)
292 {
293 SLJIT_CACHE_FLUSH(code, code_ptr);
294 }
295 #endif
296
297 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
298 {
299 struct sljit_memory_fragment *buf;
300 sljit_ins *code;
301 sljit_ins *code_ptr;
302 sljit_ins *buf_ptr;
303 sljit_ins *buf_end;
304 sljit_uw word_count;
305 sljit_uw addr;
306
307 struct sljit_label *label;
308 struct sljit_jump *jump;
309 struct sljit_const *const_;
310
311 CHECK_ERROR_PTR();
312 check_sljit_generate_code(compiler);
313 reverse_buf(compiler);
314
315 code = (sljit_ins*)SLJIT_MALLOC_EXEC(compiler->size * sizeof(sljit_ins));
316 PTR_FAIL_WITH_EXEC_IF(code);
317 buf = compiler->buf;
318
319 code_ptr = code;
320 word_count = 0;
321 label = compiler->labels;
322 jump = compiler->jumps;
323 const_ = compiler->consts;
324 do {
325 buf_ptr = (sljit_ins*)buf->memory;
326 buf_end = buf_ptr + (buf->used_size >> 2);
327 do {
328 *code_ptr = *buf_ptr++;
329 SLJIT_ASSERT(!label || label->size >= word_count);
330 SLJIT_ASSERT(!jump || jump->addr >= word_count);
331 SLJIT_ASSERT(!const_ || const_->addr >= word_count);
332 /* These structures are ordered by their address. */
333 if (label && label->size == word_count) {
334 /* Just recording the address. */
335 label->addr = (sljit_uw)code_ptr;
336 label->size = code_ptr - code;
337 label = label->next;
338 }
339 if (jump && jump->addr == word_count) {
340 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
341 jump->addr = (sljit_uw)(code_ptr - 3);
342 #else
343 #error "Implementation required"
344 #endif
345 code_ptr = optimize_jump(jump, code_ptr, code);
346 jump = jump->next;
347 }
348 if (const_ && const_->addr == word_count) {
349 /* Just recording the address. */
350 const_->addr = (sljit_uw)code_ptr;
351 const_ = const_->next;
352 }
353 code_ptr ++;
354 word_count ++;
355 } while (buf_ptr < buf_end);
356
357 buf = buf->next;
358 } while (buf);
359
360 if (label && label->size == word_count) {
361 label->addr = (sljit_uw)code_ptr;
362 label->size = code_ptr - code;
363 label = label->next;
364 }
365
366 SLJIT_ASSERT(!label);
367 SLJIT_ASSERT(!jump);
368 SLJIT_ASSERT(!const_);
369 SLJIT_ASSERT(code_ptr - code <= (sljit_sw)compiler->size);
370
371 jump = compiler->jumps;
372 while (jump) {
373 do {
374 addr = (jump->flags & JUMP_LABEL) ? jump->u.label->addr : jump->u.target;
375 buf_ptr = (sljit_ins*)jump->addr;
376
377 if (jump->flags & PATCH_B) {
378 addr = (sljit_sw)(addr - (jump->addr + sizeof(sljit_ins))) >> 2;
379 SLJIT_ASSERT((sljit_sw)addr <= SIMM_MAX && (sljit_sw)addr >= SIMM_MIN);
380 buf_ptr[0] = (buf_ptr[0] & 0xffff0000) | (addr & 0xffff);
381 break;
382 }
383 if (jump->flags & PATCH_J) {
384 SLJIT_ASSERT((addr & ~0xfffffff) == ((jump->addr + sizeof(sljit_ins)) & ~0xfffffff));
385 buf_ptr[0] |= (addr >> 2) & 0x03ffffff;
386 break;
387 }
388
389 /* Set the fields of immediate loads. */
390 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
391 buf_ptr[0] = (buf_ptr[0] & 0xffff0000) | ((addr >> 16) & 0xffff);
392 buf_ptr[1] = (buf_ptr[1] & 0xffff0000) | (addr & 0xffff);
393 #else
394 #error "Implementation required"
395 #endif
396 } while (0);
397 jump = jump->next;
398 }
399
400 compiler->error = SLJIT_ERR_COMPILED;
401 compiler->executable_size = (code_ptr - code) * sizeof(sljit_ins);
402 #ifndef __GNUC__
403 SLJIT_CACHE_FLUSH(code, code_ptr);
404 #else
405 /* GCC workaround for invalid code generation with -O2. */
406 sljit_cache_flush(code, code_ptr);
407 #endif
408 return code;
409 }
410
411 /* --------------------------------------------------------------------- */
412 /* Entry, exit */
413 /* --------------------------------------------------------------------- */
414
415 /* Creates an index in data_transfer_insts array. */
416 #define LOAD_DATA 0x01
417 #define WORD_DATA 0x00
418 #define BYTE_DATA 0x02
419 #define HALF_DATA 0x04
420 #define INT_DATA 0x06
421 #define SIGNED_DATA 0x08
422 /* Separates integer and floating point registers */
423 #define GPR_REG 0x0f
424 #define DOUBLE_DATA 0x10
425
426 #define MEM_MASK 0x1f
427
428 #define WRITE_BACK 0x00020
429 #define ARG_TEST 0x00040
430 #define ALT_KEEP_CACHE 0x00080
431 #define CUMULATIVE_OP 0x00100
432 #define LOGICAL_OP 0x00200
433 #define IMM_OP 0x00400
434 #define SRC2_IMM 0x00800
435
436 #define UNUSED_DEST 0x01000
437 #define REG_DEST 0x02000
438 #define REG1_SOURCE 0x04000
439 #define REG2_SOURCE 0x08000
440 #define SLOW_SRC1 0x10000
441 #define SLOW_SRC2 0x20000
442 #define SLOW_DEST 0x40000
443
444 /* Only these flags are set. UNUSED_DEST is not set when no flags should be set. */
445 #define CHECK_FLAGS(list) \
446 (!(flags & UNUSED_DEST) || (op & GET_FLAGS(~(list))))
447
448 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
449 #define STACK_STORE SW
450 #define STACK_LOAD LW
451 #else
452 #define STACK_STORE SD
453 #define STACK_LOAD LD
454 #endif
455
456 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
457 #include "sljitNativeMIPS_32.c"
458 #else
459 #include "sljitNativeMIPS_64.c"
460 #endif
461
462 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)
463 {
464 sljit_ins base;
465
466 CHECK_ERROR();
467 check_sljit_emit_enter(compiler, args, scratches, saveds, local_size);
468
469 compiler->scratches = scratches;
470 compiler->saveds = saveds;
471 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
472 compiler->logical_local_size = local_size;
473 #endif
474
475 local_size += (saveds + 1 + 4) * sizeof(sljit_sw);
476 local_size = (local_size + 15) & ~0xf;
477 compiler->local_size = local_size;
478
479 if (local_size <= SIMM_MAX) {
480 /* Frequent case. */
481 FAIL_IF(push_inst(compiler, ADDIU_W | S(SLJIT_LOCALS_REG) | T(SLJIT_LOCALS_REG) | IMM(-local_size), DR(SLJIT_LOCALS_REG)));
482 base = S(SLJIT_LOCALS_REG);
483 }
484 else {
485 FAIL_IF(load_immediate(compiler, DR(TMP_REG1), local_size));
486 FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_LOCALS_REG) | TA(0) | D(TMP_REG2), DR(TMP_REG2)));
487 FAIL_IF(push_inst(compiler, SUBU_W | S(SLJIT_LOCALS_REG) | T(TMP_REG1) | D(SLJIT_LOCALS_REG), DR(SLJIT_LOCALS_REG)));
488 base = S(TMP_REG2);
489 local_size = 0;
490 }
491
492 FAIL_IF(push_inst(compiler, STACK_STORE | base | TA(RETURN_ADDR_REG) | IMM(local_size - 1 * (sljit_si)sizeof(sljit_sw)), MOVABLE_INS));
493 if (saveds >= 1)
494 FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_REG1) | IMM(local_size - 2 * (sljit_si)sizeof(sljit_sw)), MOVABLE_INS));
495 if (saveds >= 2)
496 FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_REG2) | IMM(local_size - 3 * (sljit_si)sizeof(sljit_sw)), MOVABLE_INS));
497 if (saveds >= 3)
498 FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_REG3) | IMM(local_size - 4 * (sljit_si)sizeof(sljit_sw)), MOVABLE_INS));
499 if (saveds >= 4)
500 FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_EREG1) | IMM(local_size - 5 * (sljit_si)sizeof(sljit_sw)), MOVABLE_INS));
501 if (saveds >= 5)
502 FAIL_IF(push_inst(compiler, STACK_STORE | base | T(SLJIT_SAVED_EREG2) | IMM(local_size - 6 * (sljit_si)sizeof(sljit_sw)), MOVABLE_INS));
503
504 if (args >= 1)
505 FAIL_IF(push_inst(compiler, ADDU_W | SA(4) | TA(0) | D(SLJIT_SAVED_REG1), DR(SLJIT_SAVED_REG1)));
506 if (args >= 2)
507 FAIL_IF(push_inst(compiler, ADDU_W | SA(5) | TA(0) | D(SLJIT_SAVED_REG2), DR(SLJIT_SAVED_REG2)));
508 if (args >= 3)
509 FAIL_IF(push_inst(compiler, ADDU_W | SA(6) | TA(0) | D(SLJIT_SAVED_REG3), DR(SLJIT_SAVED_REG3)));
510
511 return SLJIT_SUCCESS;
512 }
513
514 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)
515 {
516 CHECK_ERROR_VOID();
517 check_sljit_set_context(compiler, args, scratches, saveds, local_size);
518
519 compiler->scratches = scratches;
520 compiler->saveds = saveds;
521 #if (defined SLJIT_DEBUG && SLJIT_DEBUG)
522 compiler->logical_local_size = local_size;
523 #endif
524
525 local_size += (saveds + 1 + 4) * sizeof(sljit_sw);
526 compiler->local_size = (local_size + 15) & ~0xf;
527 }
528
529 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
530 {
531 sljit_si local_size;
532 sljit_ins base;
533
534 CHECK_ERROR();
535 check_sljit_emit_return(compiler, op, src, srcw);
536
537 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
538
539 local_size = compiler->local_size;
540 if (local_size <= SIMM_MAX)
541 base = S(SLJIT_LOCALS_REG);
542 else {
543 FAIL_IF(load_immediate(compiler, DR(TMP_REG1), local_size));
544 FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_LOCALS_REG) | T(TMP_REG1) | D(TMP_REG1), DR(TMP_REG1)));
545 base = S(TMP_REG1);
546 local_size = 0;
547 }
548
549 FAIL_IF(push_inst(compiler, STACK_LOAD | base | TA(RETURN_ADDR_REG) | IMM(local_size - 1 * (sljit_si)sizeof(sljit_sw)), RETURN_ADDR_REG));
550 if (compiler->saveds >= 5)
551 FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_EREG2) | IMM(local_size - 6 * (sljit_si)sizeof(sljit_sw)), DR(SLJIT_SAVED_EREG2)));
552 if (compiler->saveds >= 4)
553 FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_EREG1) | IMM(local_size - 5 * (sljit_si)sizeof(sljit_sw)), DR(SLJIT_SAVED_EREG1)));
554 if (compiler->saveds >= 3)
555 FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_REG3) | IMM(local_size - 4 * (sljit_si)sizeof(sljit_sw)), DR(SLJIT_SAVED_REG3)));
556 if (compiler->saveds >= 2)
557 FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_REG2) | IMM(local_size - 3 * (sljit_si)sizeof(sljit_sw)), DR(SLJIT_SAVED_REG2)));
558 if (compiler->saveds >= 1)
559 FAIL_IF(push_inst(compiler, STACK_LOAD | base | T(SLJIT_SAVED_REG1) | IMM(local_size - 2 * (sljit_si)sizeof(sljit_sw)), DR(SLJIT_SAVED_REG1)));
560
561 FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS));
562 if (compiler->local_size <= SIMM_MAX)
563 return push_inst(compiler, ADDIU_W | S(SLJIT_LOCALS_REG) | T(SLJIT_LOCALS_REG) | IMM(compiler->local_size), UNMOVABLE_INS);
564 else
565 return push_inst(compiler, ADDU_W | S(TMP_REG1) | TA(0) | D(SLJIT_LOCALS_REG), UNMOVABLE_INS);
566 }
567
568 #undef STACK_STORE
569 #undef STACK_LOAD
570
571 /* --------------------------------------------------------------------- */
572 /* Operators */
573 /* --------------------------------------------------------------------- */
574
575 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
576 #define ARCH_32_64(a, b) a
577 #else
578 #define ARCH_32_64(a, b) b
579 #endif
580
581 static SLJIT_CONST sljit_ins data_transfer_insts[16 + 4] = {
582 /* u w s */ ARCH_32_64(HI(43) /* sw */, HI(63) /* sd */),
583 /* u w l */ ARCH_32_64(HI(35) /* lw */, HI(55) /* ld */),
584 /* u b s */ HI(40) /* sb */,
585 /* u b l */ HI(36) /* lbu */,
586 /* u h s */ HI(41) /* sh */,
587 /* u h l */ HI(37) /* lhu */,
588 /* u i s */ HI(43) /* sw */,
589 /* u i l */ ARCH_32_64(HI(35) /* lw */, HI(39) /* lwu */),
590
591 /* s w s */ ARCH_32_64(HI(43) /* sw */, HI(63) /* sd */),
592 /* s w l */ ARCH_32_64(HI(35) /* lw */, HI(55) /* ld */),
593 /* s b s */ HI(40) /* sb */,
594 /* s b l */ HI(32) /* lb */,
595 /* s h s */ HI(41) /* sh */,
596 /* s h l */ HI(33) /* lh */,
597 /* s i s */ HI(43) /* sw */,
598 /* s i l */ HI(35) /* lw */,
599
600 /* d s */ HI(61) /* sdc1 */,
601 /* d l */ HI(53) /* ldc1 */,
602 /* s s */ HI(57) /* swc1 */,
603 /* s l */ HI(49) /* lwc1 */,
604 };
605
606 #undef ARCH_32_64
607
608 /* reg_ar is an absoulute register! */
609
610 /* Can perform an operation using at most 1 instruction. */
611 static sljit_si getput_arg_fast(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg_ar, sljit_si arg, sljit_sw argw)
612 {
613 SLJIT_ASSERT(arg & SLJIT_MEM);
614
615 if ((!(flags & WRITE_BACK) || !(arg & 0xf)) && !(arg & 0xf0) && argw <= SIMM_MAX && argw >= SIMM_MIN) {
616 /* Works for both absoulte and relative addresses. */
617 if (SLJIT_UNLIKELY(flags & ARG_TEST))
618 return 1;
619 FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(arg & 0xf)
620 | TA(reg_ar) | IMM(argw), ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) ? reg_ar : MOVABLE_INS));
621 return -1;
622 }
623 return 0;
624 }
625
626 /* See getput_arg below.
627 Note: can_cache is called only for binary operators. Those
628 operators always uses word arguments without write back. */
629 static sljit_si can_cache(sljit_si arg, sljit_sw argw, sljit_si next_arg, sljit_sw next_argw)
630 {
631 SLJIT_ASSERT((arg & SLJIT_MEM) && (next_arg & SLJIT_MEM));
632
633 /* Simple operation except for updates. */
634 if (arg & 0xf0) {
635 argw &= 0x3;
636 next_argw &= 0x3;
637 if (argw && argw == next_argw && (arg == next_arg || (arg & 0xf0) == (next_arg & 0xf0)))
638 return 1;
639 return 0;
640 }
641
642 if (arg == next_arg) {
643 if (((next_argw - argw) <= SIMM_MAX && (next_argw - argw) >= SIMM_MIN))
644 return 1;
645 return 0;
646 }
647
648 return 0;
649 }
650
651 /* Emit the necessary instructions. See can_cache above. */
652 static sljit_si getput_arg(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg_ar, sljit_si arg, sljit_sw argw, sljit_si next_arg, sljit_sw next_argw)
653 {
654 sljit_si tmp_ar, base, delay_slot;
655
656 SLJIT_ASSERT(arg & SLJIT_MEM);
657 if (!(next_arg & SLJIT_MEM)) {
658 next_arg = 0;
659 next_argw = 0;
660 }
661
662 if ((flags & MEM_MASK) <= GPR_REG && (flags & LOAD_DATA)) {
663 tmp_ar = reg_ar;
664 delay_slot = reg_ar;
665 } else {
666 tmp_ar = DR(TMP_REG1);
667 delay_slot = MOVABLE_INS;
668 }
669 base = arg & 0xf;
670
671 if (SLJIT_UNLIKELY(arg & 0xf0)) {
672 argw &= 0x3;
673 if ((flags & WRITE_BACK) && reg_ar == DR(base)) {
674 SLJIT_ASSERT(!(flags & LOAD_DATA) && DR(TMP_REG1) != reg_ar);
675 FAIL_IF(push_inst(compiler, ADDU_W | SA(reg_ar) | TA(0) | D(TMP_REG1), DR(TMP_REG1)));
676 reg_ar = DR(TMP_REG1);
677 }
678
679 /* Using the cache. */
680 if (argw == compiler->cache_argw) {
681 if (!(flags & WRITE_BACK)) {
682 if (arg == compiler->cache_arg)
683 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), delay_slot);
684 if ((SLJIT_MEM | (arg & 0xf0)) == compiler->cache_arg) {
685 if (arg == next_arg && argw == (next_argw & 0x3)) {
686 compiler->cache_arg = arg;
687 compiler->cache_argw = argw;
688 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(TMP_REG3), DR(TMP_REG3)));
689 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), delay_slot);
690 }
691 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | DA(tmp_ar), tmp_ar));
692 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), delay_slot);
693 }
694 }
695 else {
696 if ((SLJIT_MEM | (arg & 0xf0)) == compiler->cache_arg) {
697 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base)));
698 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), delay_slot);
699 }
700 }
701 }
702
703 if (SLJIT_UNLIKELY(argw)) {
704 compiler->cache_arg = SLJIT_MEM | (arg & 0xf0);
705 compiler->cache_argw = argw;
706 FAIL_IF(push_inst(compiler, SLL_W | T((arg >> 4) & 0xf) | D(TMP_REG3) | SH_IMM(argw), DR(TMP_REG3)));
707 }
708
709 if (!(flags & WRITE_BACK)) {
710 if (arg == next_arg && argw == (next_argw & 0x3)) {
711 compiler->cache_arg = arg;
712 compiler->cache_argw = argw;
713 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(!argw ? ((arg >> 4) & 0xf) : TMP_REG3) | D(TMP_REG3), DR(TMP_REG3)));
714 tmp_ar = DR(TMP_REG3);
715 }
716 else
717 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(!argw ? ((arg >> 4) & 0xf) : TMP_REG3) | DA(tmp_ar), tmp_ar));
718 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), delay_slot);
719 }
720 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(!argw ? ((arg >> 4) & 0xf) : TMP_REG3) | D(base), DR(base)));
721 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), delay_slot);
722 }
723
724 if (SLJIT_UNLIKELY(flags & WRITE_BACK) && base) {
725 /* Update only applies if a base register exists. */
726 if (reg_ar == DR(base)) {
727 SLJIT_ASSERT(!(flags & LOAD_DATA) && DR(TMP_REG1) != reg_ar);
728 if (argw <= SIMM_MAX && argw >= SIMM_MIN) {
729 FAIL_IF(push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar) | IMM(argw), MOVABLE_INS));
730 if (argw)
731 return push_inst(compiler, ADDIU_W | S(base) | T(base) | IMM(argw), DR(base));
732 return SLJIT_SUCCESS;
733 }
734 FAIL_IF(push_inst(compiler, ADDU_W | SA(reg_ar) | TA(0) | D(TMP_REG1), DR(TMP_REG1)));
735 reg_ar = DR(TMP_REG1);
736 }
737
738 if (argw <= SIMM_MAX && argw >= SIMM_MIN) {
739 if (argw)
740 FAIL_IF(push_inst(compiler, ADDIU_W | S(base) | T(base) | IMM(argw), DR(base)));
741 }
742 else {
743 if (compiler->cache_arg == SLJIT_MEM && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) {
744 if (argw != compiler->cache_argw) {
745 FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3)));
746 compiler->cache_argw = argw;
747 }
748 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base)));
749 }
750 else {
751 compiler->cache_arg = SLJIT_MEM;
752 compiler->cache_argw = argw;
753 FAIL_IF(load_immediate(compiler, DR(TMP_REG3), argw));
754 FAIL_IF(push_inst(compiler, ADDU_W | S(base) | T(TMP_REG3) | D(base), DR(base)));
755 }
756 }
757 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(base) | TA(reg_ar), delay_slot);
758 }
759
760 if (compiler->cache_arg == arg && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) {
761 if (argw != compiler->cache_argw) {
762 FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3)));
763 compiler->cache_argw = argw;
764 }
765 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), delay_slot);
766 }
767
768 if (compiler->cache_arg == SLJIT_MEM && argw - compiler->cache_argw <= SIMM_MAX && argw - compiler->cache_argw >= SIMM_MIN) {
769 if (argw != compiler->cache_argw)
770 FAIL_IF(push_inst(compiler, ADDIU_W | S(TMP_REG3) | T(TMP_REG3) | IMM(argw - compiler->cache_argw), DR(TMP_REG3)));
771 }
772 else {
773 compiler->cache_arg = SLJIT_MEM;
774 FAIL_IF(load_immediate(compiler, DR(TMP_REG3), argw));
775 }
776 compiler->cache_argw = argw;
777
778 if (!base)
779 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), delay_slot);
780
781 if (arg == next_arg && next_argw - argw <= SIMM_MAX && next_argw - argw >= SIMM_MIN) {
782 compiler->cache_arg = arg;
783 FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | T(base) | D(TMP_REG3), DR(TMP_REG3)));
784 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | S(TMP_REG3) | TA(reg_ar), delay_slot);
785 }
786
787 FAIL_IF(push_inst(compiler, ADDU_W | S(TMP_REG3) | T(base) | DA(tmp_ar), tmp_ar));
788 return push_inst(compiler, data_transfer_insts[flags & MEM_MASK] | SA(tmp_ar) | TA(reg_ar), delay_slot);
789 }
790
791 static SLJIT_INLINE sljit_si emit_op_mem(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg_ar, sljit_si arg, sljit_sw argw)
792 {
793 if (getput_arg_fast(compiler, flags, reg_ar, arg, argw))
794 return compiler->error;
795 compiler->cache_arg = 0;
796 compiler->cache_argw = 0;
797 return getput_arg(compiler, flags, reg_ar, arg, argw, 0, 0);
798 }
799
800 static SLJIT_INLINE sljit_si emit_op_mem2(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg, sljit_si arg1, sljit_sw arg1w, sljit_si arg2, sljit_sw arg2w)
801 {
802 if (getput_arg_fast(compiler, flags, reg, arg1, arg1w))
803 return compiler->error;
804 return getput_arg(compiler, flags, reg, arg1, arg1w, arg2, arg2w);
805 }
806
807 static sljit_si emit_op(struct sljit_compiler *compiler, sljit_si op, sljit_si flags,
808 sljit_si dst, sljit_sw dstw,
809 sljit_si src1, sljit_sw src1w,
810 sljit_si src2, sljit_sw src2w)
811 {
812 /* arg1 goes to TMP_REG1 or src reg
813 arg2 goes to TMP_REG2, imm or src reg
814 TMP_REG3 can be used for caching
815 result goes to TMP_REG2, so put result can use TMP_REG1 and TMP_REG3. */
816 sljit_si dst_r = TMP_REG2;
817 sljit_si src1_r;
818 sljit_sw src2_r = 0;
819 sljit_si sugg_src2_r = TMP_REG2;
820
821 if (!(flags & ALT_KEEP_CACHE)) {
822 compiler->cache_arg = 0;
823 compiler->cache_argw = 0;
824 }
825
826 if (SLJIT_UNLIKELY(dst == SLJIT_UNUSED)) {
827 if (op >= SLJIT_MOV && op <= SLJIT_MOVU_SI && !(src2 & SLJIT_MEM))
828 return SLJIT_SUCCESS;
829 if (GET_FLAGS(op))
830 flags |= UNUSED_DEST;
831 }
832 else if (dst <= TMP_REG3) {
833 dst_r = dst;
834 flags |= REG_DEST;
835 if (op >= SLJIT_MOV && op <= SLJIT_MOVU_SI)
836 sugg_src2_r = dst_r;
837 }
838 else if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, flags | ARG_TEST, DR(TMP_REG1), dst, dstw))
839 flags |= SLOW_DEST;
840
841 if (flags & IMM_OP) {
842 if ((src2 & SLJIT_IMM) && src2w) {
843 if ((!(flags & LOGICAL_OP) && (src2w <= SIMM_MAX && src2w >= SIMM_MIN))
844 || ((flags & LOGICAL_OP) && !(src2w & ~UIMM_MAX))) {
845 flags |= SRC2_IMM;
846 src2_r = src2w;
847 }
848 }
849 if (!(flags & SRC2_IMM) && (flags & CUMULATIVE_OP) && (src1 & SLJIT_IMM) && src1w) {
850 if ((!(flags & LOGICAL_OP) && (src1w <= SIMM_MAX && src1w >= SIMM_MIN))
851 || ((flags & LOGICAL_OP) && !(src1w & ~UIMM_MAX))) {
852 flags |= SRC2_IMM;
853 src2_r = src1w;
854
855 /* And swap arguments. */
856 src1 = src2;
857 src1w = src2w;
858 src2 = SLJIT_IMM;
859 /* src2w = src2_r unneeded. */
860 }
861 }
862 }
863
864 /* Source 1. */
865 if (src1 <= TMP_REG3) {
866 src1_r = src1;
867 flags |= REG1_SOURCE;
868 }
869 else if (src1 & SLJIT_IMM) {
870 if (src1w) {
871 FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w));
872 src1_r = TMP_REG1;
873 }
874 else
875 src1_r = 0;
876 }
877 else {
878 if (getput_arg_fast(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w))
879 FAIL_IF(compiler->error);
880 else
881 flags |= SLOW_SRC1;
882 src1_r = TMP_REG1;
883 }
884
885 /* Source 2. */
886 if (src2 <= TMP_REG3) {
887 src2_r = src2;
888 flags |= REG2_SOURCE;
889 if (!(flags & REG_DEST) && op >= SLJIT_MOV && op <= SLJIT_MOVU_SI)
890 dst_r = src2_r;
891 }
892 else if (src2 & SLJIT_IMM) {
893 if (!(flags & SRC2_IMM)) {
894 if (src2w) {
895 FAIL_IF(load_immediate(compiler, DR(sugg_src2_r), src2w));
896 src2_r = sugg_src2_r;
897 }
898 else {
899 src2_r = 0;
900 if ((op >= SLJIT_MOV && op <= SLJIT_MOVU_SI) && (dst & SLJIT_MEM))
901 dst_r = 0;
902 }
903 }
904 }
905 else {
906 if (getput_arg_fast(compiler, flags | LOAD_DATA, DR(sugg_src2_r), src2, src2w))
907 FAIL_IF(compiler->error);
908 else
909 flags |= SLOW_SRC2;
910 src2_r = sugg_src2_r;
911 }
912
913 if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) {
914 SLJIT_ASSERT(src2_r == TMP_REG2);
915 if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) {
916 FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG2), src2, src2w, src1, src1w));
917 FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w, dst, dstw));
918 }
919 else {
920 FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w, src2, src2w));
921 FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG2), src2, src2w, dst, dstw));
922 }
923 }
924 else if (flags & SLOW_SRC1)
925 FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(TMP_REG1), src1, src1w, dst, dstw));
926 else if (flags & SLOW_SRC2)
927 FAIL_IF(getput_arg(compiler, flags | LOAD_DATA, DR(sugg_src2_r), src2, src2w, dst, dstw));
928
929 FAIL_IF(emit_single_op(compiler, op, flags, dst_r, src1_r, src2_r));
930
931 if (dst & SLJIT_MEM) {
932 if (!(flags & SLOW_DEST)) {
933 getput_arg_fast(compiler, flags, DR(dst_r), dst, dstw);
934 return compiler->error;
935 }
936 return getput_arg(compiler, flags, DR(dst_r), dst, dstw, 0, 0);
937 }
938
939 return SLJIT_SUCCESS;
940 }
941
942 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
943 {
944 CHECK_ERROR();
945 check_sljit_emit_op0(compiler, op);
946
947 op = GET_OPCODE(op);
948 switch (op) {
949 case SLJIT_BREAKPOINT:
950 return push_inst(compiler, BREAK, UNMOVABLE_INS);
951 case SLJIT_NOP:
952 return push_inst(compiler, NOP, UNMOVABLE_INS);
953 case SLJIT_UMUL:
954 case SLJIT_SMUL:
955 FAIL_IF(push_inst(compiler, (op == SLJIT_UMUL ? MULTU : MULT) | S(SLJIT_SCRATCH_REG1) | T(SLJIT_SCRATCH_REG2), MOVABLE_INS));
956 FAIL_IF(push_inst(compiler, MFLO | D(SLJIT_SCRATCH_REG1), DR(SLJIT_SCRATCH_REG1)));
957 return push_inst(compiler, MFHI | D(SLJIT_SCRATCH_REG2), DR(SLJIT_SCRATCH_REG2));
958 case SLJIT_UDIV:
959 case SLJIT_SDIV:
960 #if !(defined SLJIT_MIPS_32_64 && SLJIT_MIPS_32_64)
961 FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
962 FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
963 #endif
964 FAIL_IF(push_inst(compiler, (op == SLJIT_UDIV ? DIVU : DIV) | S(SLJIT_SCRATCH_REG1) | T(SLJIT_SCRATCH_REG2), MOVABLE_INS));
965 FAIL_IF(push_inst(compiler, MFLO | D(SLJIT_SCRATCH_REG1), DR(SLJIT_SCRATCH_REG1)));
966 return push_inst(compiler, MFHI | D(SLJIT_SCRATCH_REG2), DR(SLJIT_SCRATCH_REG2));
967 }
968
969 return SLJIT_SUCCESS;
970 }
971
972 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
973 sljit_si dst, sljit_sw dstw,
974 sljit_si src, sljit_sw srcw)
975 {
976 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
977 # define flags 0
978 #endif
979
980 CHECK_ERROR();
981 check_sljit_emit_op1(compiler, op, dst, dstw, src, srcw);
982 ADJUST_LOCAL_OFFSET(dst, dstw);
983 ADJUST_LOCAL_OFFSET(src, srcw);
984
985 switch (GET_OPCODE(op)) {
986 case SLJIT_MOV:
987 case SLJIT_MOV_P:
988 return emit_op(compiler, SLJIT_MOV, flags | WORD_DATA, dst, dstw, TMP_REG1, 0, src, srcw);
989
990 case SLJIT_MOV_UI:
991 return emit_op(compiler, SLJIT_MOV_UI, flags | INT_DATA, dst, dstw, TMP_REG1, 0, src, srcw);
992
993 case SLJIT_MOV_SI:
994 return emit_op(compiler, SLJIT_MOV_SI, flags | INT_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, srcw);
995
996 case SLJIT_MOV_UB:
997 return emit_op(compiler, SLJIT_MOV_UB, flags | BYTE_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_ub)srcw : srcw);
998
999 case SLJIT_MOV_SB:
1000 return emit_op(compiler, SLJIT_MOV_SB, flags | BYTE_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_sb)srcw : srcw);
1001
1002 case SLJIT_MOV_UH:
1003 return emit_op(compiler, SLJIT_MOV_UH, flags | HALF_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_uh)srcw : srcw);
1004
1005 case SLJIT_MOV_SH:
1006 return emit_op(compiler, SLJIT_MOV_SH, flags | HALF_DATA | SIGNED_DATA, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_sh)srcw : srcw);
1007
1008 case SLJIT_MOVU:
1009 case SLJIT_MOVU_P:
1010 return emit_op(compiler, SLJIT_MOV, flags | WORD_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw);
1011
1012 case SLJIT_MOVU_UI:
1013 return emit_op(compiler, SLJIT_MOV_UI, flags | INT_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw);
1014
1015 case SLJIT_MOVU_SI:
1016 return emit_op(compiler, SLJIT_MOV_SI, flags | INT_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, srcw);
1017
1018 case SLJIT_MOVU_UB:
1019 return emit_op(compiler, SLJIT_MOV_UB, flags | BYTE_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_ub)srcw : srcw);
1020
1021 case SLJIT_MOVU_SB:
1022 return emit_op(compiler, SLJIT_MOV_SB, flags | BYTE_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_sb)srcw : srcw);
1023
1024 case SLJIT_MOVU_UH:
1025 return emit_op(compiler, SLJIT_MOV_UH, flags | HALF_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_uh)srcw : srcw);
1026
1027 case SLJIT_MOVU_SH:
1028 return emit_op(compiler, SLJIT_MOV_SH, flags | HALF_DATA | SIGNED_DATA | WRITE_BACK, dst, dstw, TMP_REG1, 0, src, (src & SLJIT_IMM) ? (sljit_sh)srcw : srcw);
1029
1030 case SLJIT_NOT:
1031 return emit_op(compiler, op, flags, dst, dstw, TMP_REG1, 0, src, srcw);
1032
1033 case SLJIT_NEG:
1034 return emit_op(compiler, SLJIT_SUB | GET_ALL_FLAGS(op), flags | IMM_OP, dst, dstw, SLJIT_IMM, 0, src, srcw);
1035
1036 case SLJIT_CLZ:
1037 return emit_op(compiler, op, flags, dst, dstw, TMP_REG1, 0, src, srcw);
1038 }
1039
1040 return SLJIT_SUCCESS;
1041 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1042 # undef flags
1043 #endif
1044 }
1045
1046 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1047 sljit_si dst, sljit_sw dstw,
1048 sljit_si src1, sljit_sw src1w,
1049 sljit_si src2, sljit_sw src2w)
1050 {
1051 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1052 # define flags 0
1053 #endif
1054
1055 CHECK_ERROR();
1056 check_sljit_emit_op2(compiler, op, dst, dstw, src1, src1w, src2, src2w);
1057 ADJUST_LOCAL_OFFSET(dst, dstw);
1058 ADJUST_LOCAL_OFFSET(src1, src1w);
1059 ADJUST_LOCAL_OFFSET(src2, src2w);
1060
1061 switch (GET_OPCODE(op)) {
1062 case SLJIT_ADD:
1063 case SLJIT_ADDC:
1064 return emit_op(compiler, op, flags | CUMULATIVE_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
1065
1066 case SLJIT_SUB:
1067 case SLJIT_SUBC:
1068 return emit_op(compiler, op, flags | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
1069
1070 case SLJIT_MUL:
1071 return emit_op(compiler, op, flags | CUMULATIVE_OP, dst, dstw, src1, src1w, src2, src2w);
1072
1073 case SLJIT_AND:
1074 case SLJIT_OR:
1075 case SLJIT_XOR:
1076 return emit_op(compiler, op, flags | CUMULATIVE_OP | LOGICAL_OP | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
1077
1078 case SLJIT_SHL:
1079 case SLJIT_LSHR:
1080 case SLJIT_ASHR:
1081 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1082 if (src2 & SLJIT_IMM)
1083 src2w &= 0x1f;
1084 #else
1085 SLJIT_ASSERT_STOP();
1086 #endif
1087 return emit_op(compiler, op, flags | IMM_OP, dst, dstw, src1, src1w, src2, src2w);
1088 }
1089
1090 return SLJIT_SUCCESS;
1091 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1092 # undef flags
1093 #endif
1094 }
1095
1096 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg)
1097 {
1098 check_sljit_get_register_index(reg);
1099 return reg_map[reg];
1100 }
1101
1102 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
1103 void *instruction, sljit_si size)
1104 {
1105 CHECK_ERROR();
1106 check_sljit_emit_op_custom(compiler, instruction, size);
1107 SLJIT_ASSERT(size == 4);
1108
1109 return push_inst(compiler, *(sljit_ins*)instruction, UNMOVABLE_INS);
1110 }
1111
1112 /* --------------------------------------------------------------------- */
1113 /* Floating point operators */
1114 /* --------------------------------------------------------------------- */
1115
1116 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void)
1117 {
1118 #if (defined SLJIT_QEMU && SLJIT_QEMU)
1119 /* Qemu says fir is 0 by default. */
1120 return 1;
1121 #elif defined(__GNUC__)
1122 sljit_sw fir;
1123 asm ("cfc1 %0, $0" : "=r"(fir));
1124 return (fir >> 22) & 0x1;
1125 #else
1126 #error "FIR check is not implemented for this architecture"
1127 #endif
1128 }
1129
1130 #define FLOAT_DATA(op) (DOUBLE_DATA | ((op & SLJIT_SINGLE_OP) >> 7))
1131 #define FMT(op) (((op & SLJIT_SINGLE_OP) ^ SLJIT_SINGLE_OP) << (21 - 8))
1132
1133 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1134 sljit_si dst, sljit_sw dstw,
1135 sljit_si src, sljit_sw srcw)
1136 {
1137 sljit_si dst_fr;
1138
1139 CHECK_ERROR();
1140 check_sljit_emit_fop1(compiler, op, dst, dstw, src, srcw);
1141 SLJIT_COMPILE_ASSERT((SLJIT_SINGLE_OP == 0x100) && !(DOUBLE_DATA & 0x2), float_transfer_bit_error);
1142
1143 compiler->cache_arg = 0;
1144 compiler->cache_argw = 0;
1145
1146 if (GET_OPCODE(op) == SLJIT_CMPD) {
1147 if (dst > SLJIT_FLOAT_REG6) {
1148 FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, dst, dstw, src, srcw));
1149 dst = TMP_FREG1;
1150 }
1151 else
1152 dst <<= 1;
1153
1154 if (src > SLJIT_FLOAT_REG6) {
1155 FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src, srcw, 0, 0));
1156 src = TMP_FREG2;
1157 }
1158 else
1159 src <<= 1;
1160
1161 /* src and dst are swapped. */
1162 if (op & SLJIT_SET_E) {
1163 FAIL_IF(push_inst(compiler, C_UEQ_fmt | FMT(op) | FT(src) | FS(dst), UNMOVABLE_INS));
1164 FAIL_IF(push_inst(compiler, CFC1 | TA(EQUAL_FLAG) | DA(FCSR_REG), EQUAL_FLAG));
1165 FAIL_IF(push_inst(compiler, SRL | TA(EQUAL_FLAG) | DA(EQUAL_FLAG) | SH_IMM(23), EQUAL_FLAG));
1166 FAIL_IF(push_inst(compiler, ANDI | SA(EQUAL_FLAG) | TA(EQUAL_FLAG) | IMM(1), EQUAL_FLAG));
1167 }
1168 if (op & SLJIT_SET_S) {
1169 /* Mixing the instructions for the two checks. */
1170 FAIL_IF(push_inst(compiler, C_ULT_fmt | FMT(op) | FT(src) | FS(dst), UNMOVABLE_INS));
1171 FAIL_IF(push_inst(compiler, CFC1 | TA(ULESS_FLAG) | DA(FCSR_REG), ULESS_FLAG));
1172 FAIL_IF(push_inst(compiler, C_ULT_fmt | FMT(op) | FT(dst) | FS(src), UNMOVABLE_INS));
1173 FAIL_IF(push_inst(compiler, SRL | TA(ULESS_FLAG) | DA(ULESS_FLAG) | SH_IMM(23), ULESS_FLAG));
1174 FAIL_IF(push_inst(compiler, ANDI | SA(ULESS_FLAG) | TA(ULESS_FLAG) | IMM(1), ULESS_FLAG));
1175 FAIL_IF(push_inst(compiler, CFC1 | TA(UGREATER_FLAG) | DA(FCSR_REG), UGREATER_FLAG));
1176 FAIL_IF(push_inst(compiler, SRL | TA(UGREATER_FLAG) | DA(UGREATER_FLAG) | SH_IMM(23), UGREATER_FLAG));
1177 FAIL_IF(push_inst(compiler, ANDI | SA(UGREATER_FLAG) | TA(UGREATER_FLAG) | IMM(1), UGREATER_FLAG));
1178 }
1179 return push_inst(compiler, C_UN_fmt | FMT(op) | FT(src) | FS(dst), FCSR_FCC);
1180 }
1181
1182 dst_fr = (dst > SLJIT_FLOAT_REG6) ? TMP_FREG1 : (dst << 1);
1183
1184 if (src > SLJIT_FLOAT_REG6) {
1185 FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op) | LOAD_DATA, dst_fr, src, srcw, dst, dstw));
1186 src = dst_fr;
1187 }
1188 else
1189 src <<= 1;
1190
1191 switch (GET_OPCODE(op)) {
1192 case SLJIT_MOVD:
1193 if (src != dst_fr && dst_fr != TMP_FREG1)
1194 FAIL_IF(push_inst(compiler, MOV_fmt | FMT(op) | FS(src) | FD(dst_fr), MOVABLE_INS));
1195 break;
1196 case SLJIT_NEGD:
1197 FAIL_IF(push_inst(compiler, NEG_fmt | FMT(op) | FS(src) | FD(dst_fr), MOVABLE_INS));
1198 break;
1199 case SLJIT_ABSD:
1200 FAIL_IF(push_inst(compiler, ABS_fmt | FMT(op) | FS(src) | FD(dst_fr), MOVABLE_INS));
1201 break;
1202 }
1203
1204 if (dst_fr == TMP_FREG1) {
1205 if (GET_OPCODE(op) == SLJIT_MOVD)
1206 dst_fr = src;
1207 FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op), dst_fr, dst, dstw, 0, 0));
1208 }
1209
1210 return SLJIT_SUCCESS;
1211 }
1212
1213 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1214 sljit_si dst, sljit_sw dstw,
1215 sljit_si src1, sljit_sw src1w,
1216 sljit_si src2, sljit_sw src2w)
1217 {
1218 sljit_si dst_fr, flags = 0;
1219
1220 CHECK_ERROR();
1221 check_sljit_emit_fop2(compiler, op, dst, dstw, src1, src1w, src2, src2w);
1222
1223 compiler->cache_arg = 0;
1224 compiler->cache_argw = 0;
1225
1226 dst_fr = (dst > SLJIT_FLOAT_REG6) ? TMP_FREG2 : (dst << 1);
1227
1228 if (src1 > SLJIT_FLOAT_REG6) {
1229 if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w)) {
1230 FAIL_IF(compiler->error);
1231 src1 = TMP_FREG1;
1232 } else
1233 flags |= SLOW_SRC1;
1234 }
1235 else
1236 src1 <<= 1;
1237
1238 if (src2 > SLJIT_FLOAT_REG6) {
1239 if (getput_arg_fast(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w)) {
1240 FAIL_IF(compiler->error);
1241 src2 = TMP_FREG2;
1242 } else
1243 flags |= SLOW_SRC2;
1244 }
1245 else
1246 src2 <<= 1;
1247
1248 if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) {
1249 if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) {
1250 FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, src1, src1w));
1251 FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, dst, dstw));
1252 }
1253 else {
1254 FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w));
1255 FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, dst, dstw));
1256 }
1257 }
1258 else if (flags & SLOW_SRC1)
1259 FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG1, src1, src1w, dst, dstw));
1260 else if (flags & SLOW_SRC2)
1261 FAIL_IF(getput_arg(compiler, FLOAT_DATA(op) | LOAD_DATA, TMP_FREG2, src2, src2w, dst, dstw));
1262
1263 if (flags & SLOW_SRC1)
1264 src1 = TMP_FREG1;
1265 if (flags & SLOW_SRC2)
1266 src2 = TMP_FREG2;
1267
1268 switch (GET_OPCODE(op)) {
1269 case SLJIT_ADDD:
1270 FAIL_IF(push_inst(compiler, ADD_fmt | FMT(op) | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
1271 break;
1272
1273 case SLJIT_SUBD:
1274 FAIL_IF(push_inst(compiler, SUB_fmt | FMT(op) | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
1275 break;
1276
1277 case SLJIT_MULD:
1278 FAIL_IF(push_inst(compiler, MUL_fmt | FMT(op) | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
1279 break;
1280
1281 case SLJIT_DIVD:
1282 FAIL_IF(push_inst(compiler, DIV_fmt | FMT(op) | FT(src2) | FS(src1) | FD(dst_fr), MOVABLE_INS));
1283 break;
1284 }
1285
1286 if (dst_fr == TMP_FREG2)
1287 FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(op), TMP_FREG2, dst, dstw, 0, 0));
1288
1289 return SLJIT_SUCCESS;
1290 }
1291
1292 /* --------------------------------------------------------------------- */
1293 /* Other instructions */
1294 /* --------------------------------------------------------------------- */
1295
1296 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1297 {
1298 CHECK_ERROR();
1299 check_sljit_emit_fast_enter(compiler, dst, dstw);
1300 ADJUST_LOCAL_OFFSET(dst, dstw);
1301
1302 /* For UNUSED dst. Uncommon, but possible. */
1303 if (dst == SLJIT_UNUSED)
1304 return SLJIT_SUCCESS;
1305
1306 if (dst <= TMP_REG3)
1307 return push_inst(compiler, ADDU_W | SA(RETURN_ADDR_REG) | TA(0) | D(dst), DR(dst));
1308
1309 /* Memory. */
1310 return emit_op_mem(compiler, WORD_DATA, RETURN_ADDR_REG, dst, dstw);
1311 }
1312
1313 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1314 {
1315 CHECK_ERROR();
1316 check_sljit_emit_fast_return(compiler, src, srcw);
1317 ADJUST_LOCAL_OFFSET(src, srcw);
1318
1319 if (src <= TMP_REG3)
1320 FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | DA(RETURN_ADDR_REG), RETURN_ADDR_REG));
1321 else if (src & SLJIT_MEM)
1322 FAIL_IF(emit_op_mem(compiler, WORD_DATA | LOAD_DATA, RETURN_ADDR_REG, src, srcw));
1323 else if (src & SLJIT_IMM)
1324 FAIL_IF(load_immediate(compiler, RETURN_ADDR_REG, srcw));
1325
1326 FAIL_IF(push_inst(compiler, JR | SA(RETURN_ADDR_REG), UNMOVABLE_INS));
1327 return push_inst(compiler, NOP, UNMOVABLE_INS);
1328 }
1329
1330 /* --------------------------------------------------------------------- */
1331 /* Conditional instructions */
1332 /* --------------------------------------------------------------------- */
1333
1334 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1335 {
1336 struct sljit_label *label;
1337
1338 CHECK_ERROR_PTR();
1339 check_sljit_emit_label(compiler);
1340
1341 if (compiler->last_label && compiler->last_label->size == compiler->size)
1342 return compiler->last_label;
1343
1344 label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label));
1345 PTR_FAIL_IF(!label);
1346 set_label(label, compiler);
1347 compiler->delay_slot = UNMOVABLE_INS;
1348 return label;
1349 }
1350
1351 #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32)
1352 #define JUMP_LENGTH 4
1353 #else
1354 #error "Implementation required"
1355 #endif
1356
1357 #define BR_Z(src) \
1358 inst = BEQ | SA(src) | TA(0) | JUMP_LENGTH; \
1359 flags = IS_BIT26_COND; \
1360 delay_check = src;
1361
1362 #define BR_NZ(src) \
1363 inst = BNE | SA(src) | TA(0) | JUMP_LENGTH; \
1364 flags = IS_BIT26_COND; \
1365 delay_check = src;
1366
1367 #define BR_T() \
1368 inst = BC1T | JUMP_LENGTH; \
1369 flags = IS_BIT16_COND; \
1370 delay_check = FCSR_FCC;
1371
1372 #define BR_F() \
1373 inst = BC1F | JUMP_LENGTH; \
1374 flags = IS_BIT16_COND; \
1375 delay_check = FCSR_FCC;
1376
1377 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1378 {
1379 struct sljit_jump *jump;
1380 sljit_ins inst;
1381 sljit_si flags = 0;
1382 sljit_si delay_check = UNMOVABLE_INS;
1383
1384 CHECK_ERROR_PTR();
1385 check_sljit_emit_jump(compiler, type);
1386
1387 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1388 PTR_FAIL_IF(!jump);
1389 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
1390 type &= 0xff;
1391
1392 switch (type) {
1393 case SLJIT_C_EQUAL:
1394 case SLJIT_C_FLOAT_NOT_EQUAL:
1395 BR_NZ(EQUAL_FLAG);
1396 break;
1397 case SLJIT_C_NOT_EQUAL:
1398 case SLJIT_C_FLOAT_EQUAL:
1399 BR_Z(EQUAL_FLAG);
1400 break;
1401 case SLJIT_C_LESS:
1402 case SLJIT_C_FLOAT_LESS:
1403 BR_Z(ULESS_FLAG);
1404 break;
1405 case SLJIT_C_GREATER_EQUAL:
1406 case SLJIT_C_FLOAT_GREATER_EQUAL:
1407 BR_NZ(ULESS_FLAG);
1408 break;
1409 case SLJIT_C_GREATER:
1410 case SLJIT_C_FLOAT_GREATER:
1411 BR_Z(UGREATER_FLAG);
1412 break;
1413 case SLJIT_C_LESS_EQUAL:
1414 case SLJIT_C_FLOAT_LESS_EQUAL:
1415 BR_NZ(UGREATER_FLAG);
1416 break;
1417 case SLJIT_C_SIG_LESS:
1418 BR_Z(LESS_FLAG);
1419 break;
1420 case SLJIT_C_SIG_GREATER_EQUAL:
1421 BR_NZ(LESS_FLAG);
1422 break;
1423 case SLJIT_C_SIG_GREATER:
1424 BR_Z(GREATER_FLAG);
1425 break;
1426 case SLJIT_C_SIG_LESS_EQUAL:
1427 BR_NZ(GREATER_FLAG);
1428 break;
1429 case SLJIT_C_OVERFLOW:
1430 case SLJIT_C_MUL_OVERFLOW:
1431 BR_Z(OVERFLOW_FLAG);
1432 break;
1433 case SLJIT_C_NOT_OVERFLOW:
1434 case SLJIT_C_MUL_NOT_OVERFLOW:
1435 BR_NZ(OVERFLOW_FLAG);
1436 break;
1437 case SLJIT_C_FLOAT_UNORDERED:
1438 BR_F();
1439 break;
1440 case SLJIT_C_FLOAT_ORDERED:
1441 BR_T();
1442 break;
1443 default:
1444 /* Not conditional branch. */
1445 inst = 0;
1446 break;
1447 }
1448
1449 jump->flags |= flags;
1450 if (compiler->delay_slot == MOVABLE_INS || (compiler->delay_slot != UNMOVABLE_INS && compiler->delay_slot != delay_check))
1451 jump->flags |= IS_MOVABLE;
1452
1453 if (inst)
1454 PTR_FAIL_IF(push_inst(compiler, inst, UNMOVABLE_INS));
1455
1456 PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0));
1457 if (type <= SLJIT_JUMP) {
1458 PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS));
1459 jump->addr = compiler->size;
1460 PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
1461 } else {
1462 SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2);
1463 /* Cannot be optimized out if type is >= CALL0. */
1464 jump->flags |= IS_JAL | (type >= SLJIT_CALL0 ? SLJIT_REWRITABLE_JUMP : 0);
1465 PTR_FAIL_IF(push_inst(compiler, JALR | S(TMP_REG2) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
1466 jump->addr = compiler->size;
1467 /* A NOP if type < CALL1. */
1468 PTR_FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_SCRATCH_REG1) | TA(0) | DA(4), UNMOVABLE_INS));
1469 }
1470 return jump;
1471 }
1472
1473 #define RESOLVE_IMM1() \
1474 if (src1 & SLJIT_IMM) { \
1475 if (src1w) { \
1476 PTR_FAIL_IF(load_immediate(compiler, DR(TMP_REG1), src1w)); \
1477 src1 = TMP_REG1; \
1478 } \
1479 else \
1480 src1 = 0; \
1481 }
1482
1483 #define RESOLVE_IMM2() \
1484 if (src2 & SLJIT_IMM) { \
1485 if (src2w) { \
1486 PTR_FAIL_IF(load_immediate(compiler, DR(TMP_REG2), src2w)); \
1487 src2 = TMP_REG2; \
1488 } \
1489 else \
1490 src2 = 0; \
1491 }
1492
1493 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_cmp(struct sljit_compiler *compiler, sljit_si type,
1494 sljit_si src1, sljit_sw src1w,
1495 sljit_si src2, sljit_sw src2w)
1496 {
1497 struct sljit_jump *jump;
1498 sljit_si flags;
1499 sljit_ins inst;
1500
1501 CHECK_ERROR_PTR();
1502 check_sljit_emit_cmp(compiler, type, src1, src1w, src2, src2w);
1503 ADJUST_LOCAL_OFFSET(src1, src1w);
1504 ADJUST_LOCAL_OFFSET(src2, src2w);
1505
1506 compiler->cache_arg = 0;
1507 compiler->cache_argw = 0;
1508 flags = ((type & SLJIT_INT_OP) ? INT_DATA : WORD_DATA) | LOAD_DATA;
1509 if (src1 & SLJIT_MEM) {
1510 PTR_FAIL_IF(emit_op_mem2(compiler, flags, DR(TMP_REG1), src1, src1w, src2, src2w));
1511 src1 = TMP_REG1;
1512 }
1513 if (src2 & SLJIT_MEM) {
1514 PTR_FAIL_IF(emit_op_mem2(compiler, flags, DR(TMP_REG2), src2, src2w, 0, 0));
1515 src2 = TMP_REG2;
1516 }
1517
1518 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1519 PTR_FAIL_IF(!jump);
1520 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
1521 type &= 0xff;
1522
1523 if (type <= SLJIT_C_NOT_EQUAL) {
1524 RESOLVE_IMM1();
1525 RESOLVE_IMM2();
1526 jump->flags |= IS_BIT26_COND;
1527 if (compiler->delay_slot == MOVABLE_INS || (compiler->delay_slot != UNMOVABLE_INS && compiler->delay_slot != DR(src1) && compiler->delay_slot != DR(src2)))
1528 jump->flags |= IS_MOVABLE;
1529 PTR_FAIL_IF(push_inst(compiler, (type == SLJIT_C_EQUAL ? BNE : BEQ) | S(src1) | T(src2) | JUMP_LENGTH, UNMOVABLE_INS));
1530 }
1531 else if (type >= SLJIT_C_SIG_LESS && (((src1 & SLJIT_IMM) && (src1w == 0)) || ((src2 & SLJIT_IMM) && (src2w == 0)))) {
1532 inst = NOP;
1533 if ((src1 & SLJIT_IMM) && (src1w == 0)) {
1534 RESOLVE_IMM2();
1535 switch (type) {
1536 case SLJIT_C_SIG_LESS:
1537 inst = BLEZ;
1538 jump->flags |= IS_BIT26_COND;
1539 break;
1540 case SLJIT_C_SIG_GREATER_EQUAL:
1541 inst = BGTZ;
1542 jump->flags |= IS_BIT26_COND;
1543 break;
1544 case SLJIT_C_SIG_GREATER:
1545 inst = BGEZ;
1546 jump->flags |= IS_BIT16_COND;
1547 break;
1548 case SLJIT_C_SIG_LESS_EQUAL:
1549 inst = BLTZ;
1550 jump->flags |= IS_BIT16_COND;
1551 break;
1552 }
1553 src1 = src2;
1554 }
1555 else {
1556 RESOLVE_IMM1();
1557 switch (type) {
1558 case SLJIT_C_SIG_LESS:
1559 inst = BGEZ;
1560 jump->flags |= IS_BIT16_COND;
1561 break;
1562 case SLJIT_C_SIG_GREATER_EQUAL:
1563 inst = BLTZ;
1564 jump->flags |= IS_BIT16_COND;
1565 break;
1566 case SLJIT_C_SIG_GREATER:
1567 inst = BLEZ;
1568 jump->flags |= IS_BIT26_COND;
1569 break;
1570 case SLJIT_C_SIG_LESS_EQUAL:
1571 inst = BGTZ;
1572 jump->flags |= IS_BIT26_COND;
1573 break;
1574 }
1575 }
1576 PTR_FAIL_IF(push_inst(compiler, inst | S(src1) | JUMP_LENGTH, UNMOVABLE_INS));
1577 }
1578 else {
1579 if (type == SLJIT_C_LESS || type == SLJIT_C_GREATER_EQUAL || type == SLJIT_C_SIG_LESS || type == SLJIT_C_SIG_GREATER_EQUAL) {
1580 RESOLVE_IMM1();
1581 if ((src2 & SLJIT_IMM) && src2w <= SIMM_MAX && src2w >= SIMM_MIN)
1582 PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTIU : SLTI) | S(src1) | T(TMP_REG1) | IMM(src2w), DR(TMP_REG1)));
1583 else {
1584 RESOLVE_IMM2();
1585 PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTU : SLT) | S(src1) | T(src2) | D(TMP_REG1), DR(TMP_REG1)));
1586 }
1587 type = (type == SLJIT_C_LESS || type == SLJIT_C_SIG_LESS) ? SLJIT_C_NOT_EQUAL : SLJIT_C_EQUAL;
1588 }
1589 else {
1590 RESOLVE_IMM2();
1591 if ((src1 & SLJIT_IMM) && src1w <= SIMM_MAX && src1w >= SIMM_MIN)
1592 PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTIU : SLTI) | S(src2) | T(TMP_REG1) | IMM(src1w), DR(TMP_REG1)));
1593 else {
1594 RESOLVE_IMM1();
1595 PTR_FAIL_IF(push_inst(compiler, (type <= SLJIT_C_LESS_EQUAL ? SLTU : SLT) | S(src2) | T(src1) | D(TMP_REG1), DR(TMP_REG1)));
1596 }
1597 type = (type == SLJIT_C_GREATER || type == SLJIT_C_SIG_GREATER) ? SLJIT_C_NOT_EQUAL : SLJIT_C_EQUAL;
1598 }
1599
1600 jump->flags |= IS_BIT26_COND;
1601 PTR_FAIL_IF(push_inst(compiler, (type == SLJIT_C_EQUAL ? BNE : BEQ) | S(TMP_REG1) | TA(0) | JUMP_LENGTH, UNMOVABLE_INS));
1602 }
1603
1604 PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0));
1605 PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS));
1606 jump->addr = compiler->size;
1607 PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
1608 return jump;
1609 }
1610
1611 #undef RESOLVE_IMM1
1612 #undef RESOLVE_IMM2
1613
1614 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_fcmp(struct sljit_compiler *compiler, sljit_si type,
1615 sljit_si src1, sljit_sw src1w,
1616 sljit_si src2, sljit_sw src2w)
1617 {
1618 struct sljit_jump *jump;
1619 sljit_ins inst;
1620 sljit_si if_true;
1621
1622 CHECK_ERROR_PTR();
1623 check_sljit_emit_fcmp(compiler, type, src1, src1w, src2, src2w);
1624
1625 compiler->cache_arg = 0;
1626 compiler->cache_argw = 0;
1627
1628 if (src1 > SLJIT_FLOAT_REG6) {
1629 PTR_FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(type) | LOAD_DATA, TMP_FREG1, src1, src1w, src2, src2w));
1630 src1 = TMP_FREG1;
1631 }
1632 else
1633 src1 <<= 1;
1634
1635 if (src2 > SLJIT_FLOAT_REG6) {
1636 PTR_FAIL_IF(emit_op_mem2(compiler, FLOAT_DATA(type) | LOAD_DATA, TMP_FREG2, src2, src2w, 0, 0));
1637 src2 = TMP_FREG2;
1638 }
1639 else
1640 src2 <<= 1;
1641
1642 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1643 PTR_FAIL_IF(!jump);
1644 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
1645 jump->flags |= IS_BIT16_COND;
1646
1647 switch (type & 0xff) {
1648 case SLJIT_C_FLOAT_EQUAL:
1649 inst = C_UEQ_fmt;
1650 if_true = 1;
1651 break;
1652 case SLJIT_C_FLOAT_NOT_EQUAL:
1653 inst = C_UEQ_fmt;
1654 if_true = 0;
1655 break;
1656 case SLJIT_C_FLOAT_LESS:
1657 inst = C_ULT_fmt;
1658 if_true = 1;
1659 break;
1660 case SLJIT_C_FLOAT_GREATER_EQUAL:
1661 inst = C_ULT_fmt;
1662 if_true = 0;
1663 break;
1664 case SLJIT_C_FLOAT_GREATER:
1665 inst = C_ULE_fmt;
1666 if_true = 0;
1667 break;
1668 case SLJIT_C_FLOAT_LESS_EQUAL:
1669 inst = C_ULE_fmt;
1670 if_true = 1;
1671 break;
1672 case SLJIT_C_FLOAT_UNORDERED:
1673 inst = C_UN_fmt;
1674 if_true = 1;
1675 break;
1676 case SLJIT_C_FLOAT_ORDERED:
1677 default: /* Make compilers happy. */
1678 inst = C_UN_fmt;
1679 if_true = 0;
1680 break;
1681 }
1682
1683 PTR_FAIL_IF(push_inst(compiler, inst | FMT(type) | FT(src2) | FS(src1), UNMOVABLE_INS));
1684 /* Intentionally the other opcode. */
1685 PTR_FAIL_IF(push_inst(compiler, (if_true ? BC1F : BC1T) | JUMP_LENGTH, UNMOVABLE_INS));
1686 PTR_FAIL_IF(emit_const(compiler, TMP_REG2, 0));
1687 PTR_FAIL_IF(push_inst(compiler, JR | S(TMP_REG2), UNMOVABLE_INS));
1688 jump->addr = compiler->size;
1689 PTR_FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
1690 return jump;
1691 }
1692
1693 #undef JUMP_LENGTH
1694 #undef BR_Z
1695 #undef BR_NZ
1696 #undef BR_T
1697 #undef BR_F
1698
1699 #undef FLOAT_DATA
1700 #undef FMT
1701
1702 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1703 {
1704 sljit_si src_r = TMP_REG2;
1705 struct sljit_jump *jump = NULL;
1706
1707 CHECK_ERROR();
1708 check_sljit_emit_ijump(compiler, type, src, srcw);
1709 ADJUST_LOCAL_OFFSET(src, srcw);
1710
1711 if (src <= TMP_REG3) {
1712 if (DR(src) != 4)
1713 src_r = src;
1714 else
1715 FAIL_IF(push_inst(compiler, ADDU_W | S(src) | TA(0) | D(TMP_REG2), DR(TMP_REG2)));
1716 }
1717
1718 if (type >= SLJIT_CALL0) {
1719 SLJIT_ASSERT(DR(PIC_ADDR_REG) == 25 && PIC_ADDR_REG == TMP_REG2);
1720 if (src & (SLJIT_IMM | SLJIT_MEM)) {
1721 if (src & SLJIT_IMM)
1722 FAIL_IF(load_immediate(compiler, DR(PIC_ADDR_REG), srcw));
1723 else {
1724 SLJIT_ASSERT(src_r == TMP_REG2 && (src & SLJIT_MEM));
1725 FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw));
1726 }
1727 FAIL_IF(push_inst(compiler, JALR | S(PIC_ADDR_REG) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
1728 /* We need an extra instruction in any case. */
1729 return push_inst(compiler, ADDU_W | S(SLJIT_SCRATCH_REG1) | TA(0) | DA(4), UNMOVABLE_INS);
1730 }
1731
1732 /* Register input. */
1733 if (type >= SLJIT_CALL1)
1734 FAIL_IF(push_inst(compiler, ADDU_W | S(SLJIT_SCRATCH_REG1) | TA(0) | DA(4), 4));
1735 FAIL_IF(push_inst(compiler, JALR | S(src_r) | DA(RETURN_ADDR_REG), UNMOVABLE_INS));
1736 return push_inst(compiler, ADDU_W | S(src_r) | TA(0) | D(PIC_ADDR_REG), UNMOVABLE_INS);
1737 }
1738
1739 if (src & SLJIT_IMM) {
1740 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1741 FAIL_IF(!jump);
1742 set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_JAL : 0));
1743 jump->u.target = srcw;
1744
1745 if (compiler->delay_slot != UNMOVABLE_INS)
1746 jump->flags |= IS_MOVABLE;
1747
1748 FAIL_IF(emit_const(compiler, TMP_REG2, 0));
1749 }
1750 else if (src & SLJIT_MEM)
1751 FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, TMP_REG2, 0, TMP_REG1, 0, src, srcw));
1752
1753 FAIL_IF(push_inst(compiler, JR | S(src_r), UNMOVABLE_INS));
1754 if (jump)
1755 jump->addr = compiler->size;
1756 FAIL_IF(push_inst(compiler, NOP, UNMOVABLE_INS));
1757 return SLJIT_SUCCESS;
1758 }
1759
1760 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1761 sljit_si dst, sljit_sw dstw,
1762 sljit_si src, sljit_sw srcw,
1763 sljit_si type)
1764 {
1765 sljit_si sugg_dst_ar, dst_ar;
1766 sljit_si flags = GET_ALL_FLAGS(op);
1767
1768 CHECK_ERROR();
1769 check_sljit_emit_op_flags(compiler, op, dst, dstw, src, srcw, type);
1770 ADJUST_LOCAL_OFFSET(dst, dstw);
1771
1772 if (dst == SLJIT_UNUSED)
1773 return SLJIT_SUCCESS;
1774
1775 op = GET_OPCODE(op);
1776 sugg_dst_ar = DR((op < SLJIT_ADD && dst <= TMP_REG3) ? dst : TMP_REG2);
1777
1778 compiler->cache_arg = 0;
1779 compiler->cache_argw = 0;
1780 if (op >= SLJIT_ADD && (src & SLJIT_MEM)) {
1781 ADJUST_LOCAL_OFFSET(src, srcw);
1782 FAIL_IF(emit_op_mem2(compiler, WORD_DATA | LOAD_DATA, DR(TMP_REG1), src, srcw, dst, dstw));
1783 src = TMP_REG1;
1784 srcw = 0;
1785 }
1786
1787 switch (type) {
1788 case SLJIT_C_EQUAL:
1789 case SLJIT_C_NOT_EQUAL:
1790 FAIL_IF(push_inst(compiler, SLTIU | SA(EQUAL_FLAG) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
1791 dst_ar = sugg_dst_ar;
1792 break;
1793 case SLJIT_C_LESS:
1794 case SLJIT_C_GREATER_EQUAL:
1795 case SLJIT_C_FLOAT_LESS:
1796 case SLJIT_C_FLOAT_GREATER_EQUAL:
1797 dst_ar = ULESS_FLAG;
1798 break;
1799 case SLJIT_C_GREATER:
1800 case SLJIT_C_LESS_EQUAL:
1801 case SLJIT_C_FLOAT_GREATER:
1802 case SLJIT_C_FLOAT_LESS_EQUAL:
1803 dst_ar = UGREATER_FLAG;
1804 break;
1805 case SLJIT_C_SIG_LESS:
1806 case SLJIT_C_SIG_GREATER_EQUAL:
1807 dst_ar = LESS_FLAG;
1808 break;
1809 case SLJIT_C_SIG_GREATER:
1810 case SLJIT_C_SIG_LESS_EQUAL:
1811 dst_ar = GREATER_FLAG;
1812 break;
1813 case SLJIT_C_OVERFLOW:
1814 case SLJIT_C_NOT_OVERFLOW:
1815 dst_ar = OVERFLOW_FLAG;
1816 break;
1817 case SLJIT_C_MUL_OVERFLOW:
1818 case SLJIT_C_MUL_NOT_OVERFLOW:
1819 FAIL_IF(push_inst(compiler, SLTIU | SA(OVERFLOW_FLAG) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
1820 dst_ar = sugg_dst_ar;
1821 type ^= 0x1; /* Flip type bit for the XORI below. */
1822 break;
1823 case SLJIT_C_FLOAT_EQUAL:
1824 case SLJIT_C_FLOAT_NOT_EQUAL:
1825 dst_ar = EQUAL_FLAG;
1826 break;
1827
1828 case SLJIT_C_FLOAT_UNORDERED:
1829 case SLJIT_C_FLOAT_ORDERED:
1830 FAIL_IF(push_inst(compiler, CFC1 | TA(sugg_dst_ar) | DA(FCSR_REG), sugg_dst_ar));
1831 FAIL_IF(push_inst(compiler, SRL | TA(sugg_dst_ar) | DA(sugg_dst_ar) | SH_IMM(23), sugg_dst_ar));
1832 FAIL_IF(push_inst(compiler, ANDI | SA(sugg_dst_ar) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
1833 dst_ar = sugg_dst_ar;
1834 break;
1835
1836 default:
1837 SLJIT_ASSERT_STOP();
1838 dst_ar = sugg_dst_ar;
1839 break;
1840 }
1841
1842 if (type & 0x1) {
1843 FAIL_IF(push_inst(compiler, XORI | SA(dst_ar) | TA(sugg_dst_ar) | IMM(1), sugg_dst_ar));
1844 dst_ar = sugg_dst_ar;
1845 }
1846
1847 if (op >= SLJIT_ADD) {
1848 if (DR(TMP_REG2) != dst_ar)
1849 FAIL_IF(push_inst(compiler, ADDU_W | SA(dst_ar) | TA(0) | D(TMP_REG2), DR(TMP_REG2)));
1850 return emit_op(compiler, op | flags, CUMULATIVE_OP | LOGICAL_OP | IMM_OP | ALT_KEEP_CACHE, dst, dstw, src, srcw, TMP_REG2, 0);
1851 }
1852
1853 if (dst & SLJIT_MEM)
1854 return emit_op_mem(compiler, WORD_DATA, dst_ar, dst, dstw);
1855
1856 if (sugg_dst_ar != dst_ar)
1857 return push_inst(compiler, ADDU_W | SA(dst_ar) | TA(0) | DA(sugg_dst_ar), sugg_dst_ar);
1858 return SLJIT_SUCCESS;
1859 }
1860
1861 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value)
1862 {
1863 struct sljit_const *const_;
1864 sljit_si reg;
1865
1866 CHECK_ERROR_PTR();
1867 check_sljit_emit_const(compiler, dst, dstw, init_value);
1868 ADJUST_LOCAL_OFFSET(dst, dstw);
1869
1870 const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const));
1871 PTR_FAIL_IF(!const_);
1872 set_const(const_, compiler);
1873
1874 reg = (dst <= TMP_REG3) ? dst : TMP_REG2;
1875
1876 PTR_FAIL_IF(emit_const(compiler, reg, init_value));
1877
1878 if (dst & SLJIT_MEM)
1879 PTR_FAIL_IF(emit_op(compiler, SLJIT_MOV, WORD_DATA, dst, dstw, TMP_REG1, 0, TMP_REG2, 0));
1880 return const_;
1881 }

  ViewVC Help
Powered by ViewVC 1.1.5