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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1506 - (show annotations)
Sat Sep 27 06:25:26 2014 UTC (4 years, 10 months ago) by zherczeg
File MIME type: text/plain
File size: 62228 byte(s)
Major 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 SLJIT_API_FUNC_ATTRIBUTE SLJIT_CONST char* sljit_get_platform_name(void)
28 {
29 return "ARM-64" SLJIT_CPUINFO;
30 }
31
32 /* Length of an instruction word */
33 typedef sljit_ui sljit_ins;
34
35 #define TMP_ZERO (0)
36
37 #define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2)
38 #define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3)
39 #define TMP_REG3 (SLJIT_NUMBER_OF_REGISTERS + 4)
40 #define TMP_LR (SLJIT_NUMBER_OF_REGISTERS + 5)
41 #define TMP_SP (SLJIT_NUMBER_OF_REGISTERS + 6)
42
43 #define TMP_FREG1 (0)
44 #define TMP_FREG2 (SLJIT_NUMBER_OF_FLOAT_REGISTERS + 1)
45
46 static SLJIT_CONST sljit_ub reg_map[SLJIT_NUMBER_OF_REGISTERS + 8] = {
47 31, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, 8, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 29, 9, 10, 11, 30, 31
48 };
49
50 #define W_OP (1 << 31)
51 #define RD(rd) (reg_map[rd])
52 #define RT(rt) (reg_map[rt])
53 #define RN(rn) (reg_map[rn] << 5)
54 #define RT2(rt2) (reg_map[rt2] << 10)
55 #define RM(rm) (reg_map[rm] << 16)
56 #define VD(vd) (vd)
57 #define VT(vt) (vt)
58 #define VN(vn) ((vn) << 5)
59 #define VM(vm) ((vm) << 16)
60
61 /* --------------------------------------------------------------------- */
62 /* Instrucion forms */
63 /* --------------------------------------------------------------------- */
64
65 #define ADC 0x9a000000
66 #define ADD 0x8b000000
67 #define ADDI 0x91000000
68 #define AND 0x8a000000
69 #define ANDI 0x92000000
70 #define ASRV 0x9ac02800
71 #define B 0x14000000
72 #define B_CC 0x54000000
73 #define BL 0x94000000
74 #define BLR 0xd63f0000
75 #define BR 0xd61f0000
76 #define BRK 0xd4200000
77 #define CBZ 0xb4000000
78 #define CLZ 0xdac01000
79 #define CSINC 0x9a800400
80 #define EOR 0xca000000
81 #define EORI 0xd2000000
82 #define FABS 0x1e60c000
83 #define FADD 0x1e602800
84 #define FCMP 0x1e602000
85 #define FCVT 0x1e224000
86 #define FCVTZS 0x9e780000
87 #define FDIV 0x1e601800
88 #define FMOV 0x1e604000
89 #define FMUL 0x1e600800
90 #define FNEG 0x1e614000
91 #define FSUB 0x1e603800
92 #define LDRI 0xf9400000
93 #define LDP 0xa9400000
94 #define LDP_PST 0xa8c00000
95 #define LSLV 0x9ac02000
96 #define LSRV 0x9ac02400
97 #define MADD 0x9b000000
98 #define MOVK 0xf2800000
99 #define MOVN 0x92800000
100 #define MOVZ 0xd2800000
101 #define NOP 0xd503201f
102 #define ORN 0xaa200000
103 #define ORR 0xaa000000
104 #define ORRI 0xb2000000
105 #define RET 0xd65f0000
106 #define SBC 0xda000000
107 #define SBFM 0x93000000
108 #define SCVTF 0x9e620000
109 #define SDIV 0x9ac00c00
110 #define SMADDL 0x9b200000
111 #define SMULH 0x9b403c00
112 #define STP 0xa9000000
113 #define STP_PRE 0xa9800000
114 #define STRI 0xf9000000
115 #define STR_FI 0x3d000000
116 #define STR_FR 0x3c206800
117 #define STUR_FI 0x3c000000
118 #define SUB 0xcb000000
119 #define SUBI 0xd1000000
120 #define SUBS 0xeb000000
121 #define UBFM 0xd3000000
122 #define UDIV 0x9ac00800
123 #define UMULH 0x9bc03c00
124
125 /* dest_reg is the absolute name of the register
126 Useful for reordering instructions in the delay slot. */
127 static sljit_si push_inst(struct sljit_compiler *compiler, sljit_ins ins)
128 {
129 sljit_ins *ptr = (sljit_ins*)ensure_buf(compiler, sizeof(sljit_ins));
130 FAIL_IF(!ptr);
131 *ptr = ins;
132 compiler->size++;
133 return SLJIT_SUCCESS;
134 }
135
136 static SLJIT_INLINE sljit_si emit_imm64_const(struct sljit_compiler *compiler, sljit_si dst, sljit_uw imm)
137 {
138 FAIL_IF(push_inst(compiler, MOVZ | RD(dst) | ((imm & 0xffff) << 5)));
139 FAIL_IF(push_inst(compiler, MOVK | RD(dst) | (((imm >> 16) & 0xffff) << 5) | (1 << 21)));
140 FAIL_IF(push_inst(compiler, MOVK | RD(dst) | (((imm >> 32) & 0xffff) << 5) | (2 << 21)));
141 return push_inst(compiler, MOVK | RD(dst) | ((imm >> 48) << 5) | (3 << 21));
142 }
143
144 static SLJIT_INLINE void modify_imm64_const(sljit_ins* inst, sljit_uw new_imm)
145 {
146 sljit_si dst = inst[0] & 0x1f;
147 SLJIT_ASSERT((inst[0] & 0xffe00000) == MOVZ && (inst[1] & 0xffe00000) == (MOVK | (1 << 21)));
148 inst[0] = MOVZ | dst | ((new_imm & 0xffff) << 5);
149 inst[1] = MOVK | dst | (((new_imm >> 16) & 0xffff) << 5) | (1 << 21);
150 inst[2] = MOVK | dst | (((new_imm >> 32) & 0xffff) << 5) | (2 << 21);
151 inst[3] = MOVK | dst | ((new_imm >> 48) << 5) | (3 << 21);
152 }
153
154 static SLJIT_INLINE sljit_si detect_jump_type(struct sljit_jump *jump, sljit_ins *code_ptr, sljit_ins *code)
155 {
156 sljit_sw diff;
157 sljit_uw target_addr;
158
159 if (jump->flags & SLJIT_REWRITABLE_JUMP) {
160 jump->flags |= PATCH_ABS64;
161 return 0;
162 }
163
164 if (jump->flags & JUMP_ADDR)
165 target_addr = jump->u.target;
166 else {
167 SLJIT_ASSERT(jump->flags & JUMP_LABEL);
168 target_addr = (sljit_uw)(code + jump->u.label->size);
169 }
170 diff = (sljit_sw)target_addr - (sljit_sw)(code_ptr + 4);
171
172 if (jump->flags & IS_COND) {
173 diff += sizeof(sljit_ins);
174 if (diff <= 0xfffff && diff >= -0x100000) {
175 code_ptr[-5] ^= (jump->flags & IS_CBZ) ? (0x1 << 24) : 0x1;
176 jump->addr -= sizeof(sljit_ins);
177 jump->flags |= PATCH_COND;
178 return 5;
179 }
180 diff -= sizeof(sljit_ins);
181 }
182
183 if (diff <= 0x7ffffff && diff >= -0x8000000) {
184 jump->flags |= PATCH_B;
185 return 4;
186 }
187
188 if (target_addr <= 0xffffffffl) {
189 if (jump->flags & IS_COND)
190 code_ptr[-5] -= (2 << 5);
191 code_ptr[-2] = code_ptr[0];
192 return 2;
193 }
194 if (target_addr <= 0xffffffffffffl) {
195 if (jump->flags & IS_COND)
196 code_ptr[-5] -= (1 << 5);
197 jump->flags |= PATCH_ABS48;
198 code_ptr[-1] = code_ptr[0];
199 return 1;
200 }
201
202 jump->flags |= PATCH_ABS64;
203 return 0;
204 }
205
206 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
207 {
208 struct sljit_memory_fragment *buf;
209 sljit_ins *code;
210 sljit_ins *code_ptr;
211 sljit_ins *buf_ptr;
212 sljit_ins *buf_end;
213 sljit_uw word_count;
214 sljit_uw addr;
215 sljit_si dst;
216
217 struct sljit_label *label;
218 struct sljit_jump *jump;
219 struct sljit_const *const_;
220
221 CHECK_ERROR_PTR();
222 CHECK_PTR(check_sljit_generate_code(compiler));
223 reverse_buf(compiler);
224
225 code = (sljit_ins*)SLJIT_MALLOC_EXEC(compiler->size * sizeof(sljit_ins));
226 PTR_FAIL_WITH_EXEC_IF(code);
227 buf = compiler->buf;
228
229 code_ptr = code;
230 word_count = 0;
231 label = compiler->labels;
232 jump = compiler->jumps;
233 const_ = compiler->consts;
234
235 do {
236 buf_ptr = (sljit_ins*)buf->memory;
237 buf_end = buf_ptr + (buf->used_size >> 2);
238 do {
239 *code_ptr = *buf_ptr++;
240 /* These structures are ordered by their address. */
241 SLJIT_ASSERT(!label || label->size >= word_count);
242 SLJIT_ASSERT(!jump || jump->addr >= word_count);
243 SLJIT_ASSERT(!const_ || const_->addr >= word_count);
244 if (label && label->size == word_count) {
245 label->addr = (sljit_uw)code_ptr;
246 label->size = code_ptr - code;
247 label = label->next;
248 }
249 if (jump && jump->addr == word_count) {
250 jump->addr = (sljit_uw)(code_ptr - 4);
251 code_ptr -= detect_jump_type(jump, code_ptr, code);
252 jump = jump->next;
253 }
254 if (const_ && const_->addr == word_count) {
255 const_->addr = (sljit_uw)code_ptr;
256 const_ = const_->next;
257 }
258 code_ptr ++;
259 word_count ++;
260 } while (buf_ptr < buf_end);
261
262 buf = buf->next;
263 } while (buf);
264
265 if (label && label->size == word_count) {
266 label->addr = (sljit_uw)code_ptr;
267 label->size = code_ptr - code;
268 label = label->next;
269 }
270
271 SLJIT_ASSERT(!label);
272 SLJIT_ASSERT(!jump);
273 SLJIT_ASSERT(!const_);
274 SLJIT_ASSERT(code_ptr - code <= (sljit_sw)compiler->size);
275
276 jump = compiler->jumps;
277 while (jump) {
278 do {
279 addr = (jump->flags & JUMP_LABEL) ? jump->u.label->addr : jump->u.target;
280 buf_ptr = (sljit_ins*)jump->addr;
281 if (jump->flags & PATCH_B) {
282 addr = (sljit_sw)(addr - jump->addr) >> 2;
283 SLJIT_ASSERT((sljit_sw)addr <= 0x1ffffff && (sljit_sw)addr >= -0x2000000);
284 buf_ptr[0] = ((jump->flags & IS_BL) ? BL : B) | (addr & 0x3ffffff);
285 if (jump->flags & IS_COND)
286 buf_ptr[-1] -= (4 << 5);
287 break;
288 }
289 if (jump->flags & PATCH_COND) {
290 addr = (sljit_sw)(addr - jump->addr) >> 2;
291 SLJIT_ASSERT((sljit_sw)addr <= 0x3ffff && (sljit_sw)addr >= -0x40000);
292 buf_ptr[0] = (buf_ptr[0] & ~0xffffe0) | ((addr & 0x7ffff) << 5);
293 break;
294 }
295
296 SLJIT_ASSERT((jump->flags & (PATCH_ABS48 | PATCH_ABS64)) || addr <= 0xffffffffl);
297 SLJIT_ASSERT((jump->flags & PATCH_ABS64) || addr <= 0xffffffffffffl);
298
299 dst = buf_ptr[0] & 0x1f;
300 buf_ptr[0] = MOVZ | dst | ((addr & 0xffff) << 5);
301 buf_ptr[1] = MOVK | dst | (((addr >> 16) & 0xffff) << 5) | (1 << 21);
302 if (jump->flags & (PATCH_ABS48 | PATCH_ABS64))
303 buf_ptr[2] = MOVK | dst | (((addr >> 32) & 0xffff) << 5) | (2 << 21);
304 if (jump->flags & PATCH_ABS64)
305 buf_ptr[3] = MOVK | dst | (((addr >> 48) & 0xffff) << 5) | (3 << 21);
306 } while (0);
307 jump = jump->next;
308 }
309
310 compiler->error = SLJIT_ERR_COMPILED;
311 compiler->executable_size = (code_ptr - code) * sizeof(sljit_ins);
312 SLJIT_CACHE_FLUSH(code, code_ptr);
313 return code;
314 }
315
316 /* --------------------------------------------------------------------- */
317 /* Core code generator functions. */
318 /* --------------------------------------------------------------------- */
319
320 #define COUNT_TRAILING_ZERO(value, result) \
321 result = 0; \
322 if (!(value & 0xffffffff)) { \
323 result += 32; \
324 value >>= 32; \
325 } \
326 if (!(value & 0xffff)) { \
327 result += 16; \
328 value >>= 16; \
329 } \
330 if (!(value & 0xff)) { \
331 result += 8; \
332 value >>= 8; \
333 } \
334 if (!(value & 0xf)) { \
335 result += 4; \
336 value >>= 4; \
337 } \
338 if (!(value & 0x3)) { \
339 result += 2; \
340 value >>= 2; \
341 } \
342 if (!(value & 0x1)) { \
343 result += 1; \
344 value >>= 1; \
345 }
346
347 #define LOGICAL_IMM_CHECK 0x100
348
349 static sljit_ins logical_imm(sljit_sw imm, sljit_si len)
350 {
351 sljit_si negated, ones, right;
352 sljit_uw mask, uimm;
353 sljit_ins ins;
354
355 if (len & LOGICAL_IMM_CHECK) {
356 len &= ~LOGICAL_IMM_CHECK;
357 if (len == 32 && (imm == 0 || imm == -1))
358 return 0;
359 if (len == 16 && ((sljit_si)imm == 0 || (sljit_si)imm == -1))
360 return 0;
361 }
362
363 SLJIT_ASSERT((len == 32 && imm != 0 && imm != -1)
364 || (len == 16 && (sljit_si)imm != 0 && (sljit_si)imm != -1));
365 uimm = (sljit_uw)imm;
366 while (1) {
367 if (len <= 0) {
368 SLJIT_ASSERT_STOP();
369 return 0;
370 }
371 mask = ((sljit_uw)1 << len) - 1;
372 if ((uimm & mask) != ((uimm >> len) & mask))
373 break;
374 len >>= 1;
375 }
376
377 len <<= 1;
378
379 negated = 0;
380 if (uimm & 0x1) {
381 negated = 1;
382 uimm = ~uimm;
383 }
384
385 if (len < 64)
386 uimm &= ((sljit_uw)1 << len) - 1;
387
388 /* Unsigned right shift. */
389 COUNT_TRAILING_ZERO(uimm, right);
390
391 /* Signed shift. We also know that the highest bit is set. */
392 imm = (sljit_sw)~uimm;
393 SLJIT_ASSERT(imm < 0);
394
395 COUNT_TRAILING_ZERO(imm, ones);
396
397 if (~imm)
398 return 0;
399
400 if (len == 64)
401 ins = 1 << 22;
402 else
403 ins = (0x3f - ((len << 1) - 1)) << 10;
404
405 if (negated)
406 return ins | ((len - ones - 1) << 10) | ((len - ones - right) << 16);
407
408 return ins | ((ones - 1) << 10) | ((len - right) << 16);
409 }
410
411 #undef COUNT_TRAILING_ZERO
412
413 static sljit_si load_immediate(struct sljit_compiler *compiler, sljit_si dst, sljit_sw simm)
414 {
415 sljit_uw imm = (sljit_uw)simm;
416 sljit_si i, zeros, ones, first;
417 sljit_ins bitmask;
418
419 if (imm <= 0xffff)
420 return push_inst(compiler, MOVZ | RD(dst) | (imm << 5));
421
422 if (simm >= -0x10000 && simm < 0)
423 return push_inst(compiler, MOVN | RD(dst) | ((~imm & 0xffff) << 5));
424
425 if (imm <= 0xffffffffl) {
426 if ((imm & 0xffff0000l) == 0xffff0000)
427 return push_inst(compiler, (MOVN ^ W_OP) | RD(dst) | ((~imm & 0xffff) << 5));
428 if ((imm & 0xffff) == 0xffff)
429 return push_inst(compiler, (MOVN ^ W_OP) | RD(dst) | ((~imm & 0xffff0000l) >> (16 - 5)) | (1 << 21));
430 bitmask = logical_imm(simm, 16);
431 if (bitmask != 0)
432 return push_inst(compiler, (ORRI ^ W_OP) | RD(dst) | RN(TMP_ZERO) | bitmask);
433 }
434 else {
435 bitmask = logical_imm(simm, 32);
436 if (bitmask != 0)
437 return push_inst(compiler, ORRI | RD(dst) | RN(TMP_ZERO) | bitmask);
438 }
439
440 if (imm <= 0xffffffffl) {
441 FAIL_IF(push_inst(compiler, MOVZ | RD(dst) | ((imm & 0xffff) << 5)));
442 return push_inst(compiler, MOVK | RD(dst) | ((imm & 0xffff0000l) >> (16 - 5)) | (1 << 21));
443 }
444
445 if (simm >= -0x100000000l && simm < 0) {
446 FAIL_IF(push_inst(compiler, MOVN | RD(dst) | ((~imm & 0xffff) << 5)));
447 return push_inst(compiler, MOVK | RD(dst) | ((imm & 0xffff0000l) >> (16 - 5)) | (1 << 21));
448 }
449
450 /* A large amount of number can be constructed from ORR and MOVx,
451 but computing them is costly. We don't */
452
453 zeros = 0;
454 ones = 0;
455 for (i = 4; i > 0; i--) {
456 if ((simm & 0xffff) == 0)
457 zeros++;
458 if ((simm & 0xffff) == 0xffff)
459 ones++;
460 simm >>= 16;
461 }
462
463 simm = (sljit_sw)imm;
464 first = 1;
465 if (ones > zeros) {
466 simm = ~simm;
467 for (i = 0; i < 4; i++) {
468 if (!(simm & 0xffff)) {
469 simm >>= 16;
470 continue;
471 }
472 if (first) {
473 first = 0;
474 FAIL_IF(push_inst(compiler, MOVN | RD(dst) | ((simm & 0xffff) << 5) | (i << 21)));
475 }
476 else
477 FAIL_IF(push_inst(compiler, MOVK | RD(dst) | ((~simm & 0xffff) << 5) | (i << 21)));
478 simm >>= 16;
479 }
480 return SLJIT_SUCCESS;
481 }
482
483 for (i = 0; i < 4; i++) {
484 if (!(simm & 0xffff)) {
485 simm >>= 16;
486 continue;
487 }
488 if (first) {
489 first = 0;
490 FAIL_IF(push_inst(compiler, MOVZ | RD(dst) | ((simm & 0xffff) << 5) | (i << 21)));
491 }
492 else
493 FAIL_IF(push_inst(compiler, MOVK | RD(dst) | ((simm & 0xffff) << 5) | (i << 21)));
494 simm >>= 16;
495 }
496 return SLJIT_SUCCESS;
497 }
498
499 #define ARG1_IMM 0x0010000
500 #define ARG2_IMM 0x0020000
501 #define INT_OP 0x0040000
502 #define SET_FLAGS 0x0080000
503 #define UNUSED_RETURN 0x0100000
504 #define SLOW_DEST 0x0200000
505 #define SLOW_SRC1 0x0400000
506 #define SLOW_SRC2 0x0800000
507
508 #define CHECK_FLAGS(flag_bits) \
509 if (flags & SET_FLAGS) { \
510 inv_bits |= flag_bits; \
511 if (flags & UNUSED_RETURN) \
512 dst = TMP_ZERO; \
513 }
514
515 static sljit_si emit_op_imm(struct sljit_compiler *compiler, sljit_si flags, sljit_si dst, sljit_sw arg1, sljit_sw arg2)
516 {
517 /* dst must be register, TMP_REG1
518 arg1 must be register, TMP_REG1, imm
519 arg2 must be register, TMP_REG2, imm */
520 sljit_ins inv_bits = (flags & INT_OP) ? (1 << 31) : 0;
521 sljit_ins inst_bits;
522 sljit_si op = (flags & 0xffff);
523 sljit_si reg;
524 sljit_sw imm, nimm;
525
526 if (SLJIT_UNLIKELY((flags & (ARG1_IMM | ARG2_IMM)) == (ARG1_IMM | ARG2_IMM))) {
527 /* Both are immediates. */
528 flags &= ~ARG1_IMM;
529 if (arg1 == 0 && op != SLJIT_ADD && op != SLJIT_SUB)
530 arg1 = TMP_ZERO;
531 else {
532 FAIL_IF(load_immediate(compiler, TMP_REG1, arg1));
533 arg1 = TMP_REG1;
534 }
535 }
536
537 if (flags & (ARG1_IMM | ARG2_IMM)) {
538 reg = (flags & ARG2_IMM) ? arg1 : arg2;
539 imm = (flags & ARG2_IMM) ? arg2 : arg1;
540
541 switch (op) {
542 case SLJIT_MUL:
543 case SLJIT_NEG:
544 case SLJIT_CLZ:
545 case SLJIT_ADDC:
546 case SLJIT_SUBC:
547 /* No form with immediate operand (except imm 0, which
548 is represented by a ZERO register). */
549 break;
550 case SLJIT_MOV:
551 SLJIT_ASSERT(!(flags & SET_FLAGS) && (flags & ARG2_IMM) && arg1 == TMP_REG1);
552 return load_immediate(compiler, dst, imm);
553 case SLJIT_NOT:
554 SLJIT_ASSERT(flags & ARG2_IMM);
555 FAIL_IF(load_immediate(compiler, dst, (flags & INT_OP) ? (~imm & 0xffffffff) : ~imm));
556 goto set_flags;
557 case SLJIT_SUB:
558 if (flags & ARG1_IMM)
559 break;
560 imm = -imm;
561 /* Fall through. */
562 case SLJIT_ADD:
563 if (imm == 0) {
564 CHECK_FLAGS(1 << 29);
565 return push_inst(compiler, ((op == SLJIT_ADD ? ADDI : SUBI) ^ inv_bits) | RD(dst) | RN(reg));
566 }
567 if (imm > 0 && imm <= 0xfff) {
568 CHECK_FLAGS(1 << 29);
569 return push_inst(compiler, (ADDI ^ inv_bits) | RD(dst) | RN(reg) | (imm << 10));
570 }
571 nimm = -imm;
572 if (nimm > 0 && nimm <= 0xfff) {
573 CHECK_FLAGS(1 << 29);
574 return push_inst(compiler, (SUBI ^ inv_bits) | RD(dst) | RN(reg) | (nimm << 10));
575 }
576 if (imm > 0 && imm <= 0xffffff && !(imm & 0xfff)) {
577 CHECK_FLAGS(1 << 29);
578 return push_inst(compiler, (ADDI ^ inv_bits) | RD(dst) | RN(reg) | ((imm >> 12) << 10) | (1 << 22));
579 }
580 if (nimm > 0 && nimm <= 0xffffff && !(nimm & 0xfff)) {
581 CHECK_FLAGS(1 << 29);
582 return push_inst(compiler, (SUBI ^ inv_bits) | RD(dst) | RN(reg) | ((nimm >> 12) << 10) | (1 << 22));
583 }
584 if (imm > 0 && imm <= 0xffffff && !(flags & SET_FLAGS)) {
585 FAIL_IF(push_inst(compiler, (ADDI ^ inv_bits) | RD(dst) | RN(reg) | ((imm >> 12) << 10) | (1 << 22)));
586 return push_inst(compiler, (ADDI ^ inv_bits) | RD(dst) | RN(dst) | ((imm & 0xfff) << 10));
587 }
588 if (nimm > 0 && nimm <= 0xffffff && !(flags & SET_FLAGS)) {
589 FAIL_IF(push_inst(compiler, (SUBI ^ inv_bits) | RD(dst) | RN(reg) | ((nimm >> 12) << 10) | (1 << 22)));
590 return push_inst(compiler, (SUBI ^ inv_bits) | RD(dst) | RN(dst) | ((nimm & 0xfff) << 10));
591 }
592 break;
593 case SLJIT_AND:
594 inst_bits = logical_imm(imm, LOGICAL_IMM_CHECK | ((flags & INT_OP) ? 16 : 32));
595 if (!inst_bits)
596 break;
597 CHECK_FLAGS(3 << 29);
598 return push_inst(compiler, (ANDI ^ inv_bits) | RD(dst) | RN(reg) | inst_bits);
599 case SLJIT_OR:
600 case SLJIT_XOR:
601 inst_bits = logical_imm(imm, LOGICAL_IMM_CHECK | ((flags & INT_OP) ? 16 : 32));
602 if (!inst_bits)
603 break;
604 if (op == SLJIT_OR)
605 inst_bits |= ORRI;
606 else
607 inst_bits |= EORI;
608 FAIL_IF(push_inst(compiler, (inst_bits ^ inv_bits) | RD(dst) | RN(reg)));
609 goto set_flags;
610 case SLJIT_SHL:
611 if (flags & ARG1_IMM)
612 break;
613 if (flags & INT_OP) {
614 imm &= 0x1f;
615 FAIL_IF(push_inst(compiler, (UBFM ^ inv_bits) | RD(dst) | RN(arg1) | ((-imm & 0x1f) << 16) | ((31 - imm) << 10)));
616 }
617 else {
618 imm &= 0x3f;
619 FAIL_IF(push_inst(compiler, (UBFM ^ inv_bits) | RD(dst) | RN(arg1) | (1 << 22) | ((-imm & 0x3f) << 16) | ((63 - imm) << 10)));
620 }
621 goto set_flags;
622 case SLJIT_LSHR:
623 case SLJIT_ASHR:
624 if (flags & ARG1_IMM)
625 break;
626 if (op == SLJIT_ASHR)
627 inv_bits |= 1 << 30;
628 if (flags & INT_OP) {
629 imm &= 0x1f;
630 FAIL_IF(push_inst(compiler, (UBFM ^ inv_bits) | RD(dst) | RN(arg1) | (imm << 16) | (31 << 10)));
631 }
632 else {
633 imm &= 0x3f;
634 FAIL_IF(push_inst(compiler, (UBFM ^ inv_bits) | RD(dst) | RN(arg1) | (1 << 22) | (imm << 16) | (63 << 10)));
635 }
636 goto set_flags;
637 default:
638 SLJIT_ASSERT_STOP();
639 break;
640 }
641
642 if (flags & ARG2_IMM) {
643 if (arg2 == 0)
644 arg2 = TMP_ZERO;
645 else {
646 FAIL_IF(load_immediate(compiler, TMP_REG2, arg2));
647 arg2 = TMP_REG2;
648 }
649 }
650 else {
651 if (arg1 == 0)
652 arg1 = TMP_ZERO;
653 else {
654 FAIL_IF(load_immediate(compiler, TMP_REG1, arg1));
655 arg1 = TMP_REG1;
656 }
657 }
658 }
659
660 /* Both arguments are registers. */
661 switch (op) {
662 case SLJIT_MOV:
663 case SLJIT_MOV_P:
664 case SLJIT_MOVU:
665 case SLJIT_MOVU_P:
666 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
667 if (dst == arg2)
668 return SLJIT_SUCCESS;
669 return push_inst(compiler, ORR | RD(dst) | RN(TMP_ZERO) | RM(arg2));
670 case SLJIT_MOV_UB:
671 case SLJIT_MOVU_UB:
672 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
673 return push_inst(compiler, (UBFM ^ (1 << 31)) | RD(dst) | RN(arg2) | (7 << 10));
674 case SLJIT_MOV_SB:
675 case SLJIT_MOVU_SB:
676 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
677 if (!(flags & INT_OP))
678 inv_bits |= 1 << 22;
679 return push_inst(compiler, (SBFM ^ inv_bits) | RD(dst) | RN(arg2) | (7 << 10));
680 case SLJIT_MOV_UH:
681 case SLJIT_MOVU_UH:
682 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
683 return push_inst(compiler, (UBFM ^ (1 << 31)) | RD(dst) | RN(arg2) | (15 << 10));
684 case SLJIT_MOV_SH:
685 case SLJIT_MOVU_SH:
686 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
687 if (!(flags & INT_OP))
688 inv_bits |= 1 << 22;
689 return push_inst(compiler, (SBFM ^ inv_bits) | RD(dst) | RN(arg2) | (15 << 10));
690 case SLJIT_MOV_UI:
691 case SLJIT_MOVU_UI:
692 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
693 if ((flags & INT_OP) && dst == arg2)
694 return SLJIT_SUCCESS;
695 return push_inst(compiler, (ORR ^ (1 << 31)) | RD(dst) | RN(TMP_ZERO) | RM(arg2));
696 case SLJIT_MOV_SI:
697 case SLJIT_MOVU_SI:
698 SLJIT_ASSERT(!(flags & SET_FLAGS) && arg1 == TMP_REG1);
699 if ((flags & INT_OP) && dst == arg2)
700 return SLJIT_SUCCESS;
701 return push_inst(compiler, SBFM | (1 << 22) | RD(dst) | RN(arg2) | (31 << 10));
702 case SLJIT_NOT:
703 SLJIT_ASSERT(arg1 == TMP_REG1);
704 FAIL_IF(push_inst(compiler, (ORN ^ inv_bits) | RD(dst) | RN(TMP_ZERO) | RM(arg2)));
705 goto set_flags;
706 case SLJIT_NEG:
707 SLJIT_ASSERT(arg1 == TMP_REG1);
708 if (flags & SET_FLAGS)
709 inv_bits |= 1 << 29;
710 return push_inst(compiler, (SUB ^ inv_bits) | RD(dst) | RN(TMP_ZERO) | RM(arg2));
711 case SLJIT_CLZ:
712 SLJIT_ASSERT(arg1 == TMP_REG1);
713 FAIL_IF(push_inst(compiler, (CLZ ^ inv_bits) | RD(dst) | RN(arg2)));
714 goto set_flags;
715 case SLJIT_ADD:
716 CHECK_FLAGS(1 << 29);
717 return push_inst(compiler, (ADD ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2));
718 case SLJIT_ADDC:
719 CHECK_FLAGS(1 << 29);
720 return push_inst(compiler, (ADC ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2));
721 case SLJIT_SUB:
722 CHECK_FLAGS(1 << 29);
723 return push_inst(compiler, (SUB ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2));
724 case SLJIT_SUBC:
725 CHECK_FLAGS(1 << 29);
726 return push_inst(compiler, (SBC ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2));
727 case SLJIT_MUL:
728 if (!(flags & SET_FLAGS))
729 return push_inst(compiler, (MADD ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2) | RT2(TMP_ZERO));
730 if (flags & INT_OP) {
731 FAIL_IF(push_inst(compiler, SMADDL | RD(dst) | RN(arg1) | RM(arg2) | (31 << 10)));
732 FAIL_IF(push_inst(compiler, ADD | RD(TMP_LR) | RN(TMP_ZERO) | RM(dst) | (2 << 22) | (31 << 10)));
733 return push_inst(compiler, SUBS | RD(TMP_ZERO) | RN(TMP_LR) | RM(dst) | (2 << 22) | (63 << 10));
734 }
735 FAIL_IF(push_inst(compiler, SMULH | RD(TMP_LR) | RN(arg1) | RM(arg2)));
736 FAIL_IF(push_inst(compiler, MADD | RD(dst) | RN(arg1) | RM(arg2) | RT2(TMP_ZERO)));
737 return push_inst(compiler, SUBS | RD(TMP_ZERO) | RN(TMP_LR) | RM(dst) | (2 << 22) | (63 << 10));
738 case SLJIT_AND:
739 CHECK_FLAGS(3 << 29);
740 return push_inst(compiler, (AND ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2));
741 case SLJIT_OR:
742 FAIL_IF(push_inst(compiler, (ORR ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2)));
743 goto set_flags;
744 case SLJIT_XOR:
745 FAIL_IF(push_inst(compiler, (EOR ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2)));
746 goto set_flags;
747 case SLJIT_SHL:
748 FAIL_IF(push_inst(compiler, (LSLV ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2)));
749 goto set_flags;
750 case SLJIT_LSHR:
751 FAIL_IF(push_inst(compiler, (LSRV ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2)));
752 goto set_flags;
753 case SLJIT_ASHR:
754 FAIL_IF(push_inst(compiler, (ASRV ^ inv_bits) | RD(dst) | RN(arg1) | RM(arg2)));
755 goto set_flags;
756 }
757
758 SLJIT_ASSERT_STOP();
759 return SLJIT_SUCCESS;
760
761 set_flags:
762 if (flags & SET_FLAGS)
763 return push_inst(compiler, (SUBS ^ inv_bits) | RD(TMP_ZERO) | RN(dst) | RM(TMP_ZERO));
764 return SLJIT_SUCCESS;
765 }
766
767 #define STORE 0x01
768 #define SIGNED 0x02
769
770 #define UPDATE 0x04
771 #define ARG_TEST 0x08
772
773 #define BYTE_SIZE 0x000
774 #define HALF_SIZE 0x100
775 #define INT_SIZE 0x200
776 #define WORD_SIZE 0x300
777
778 #define MEM_SIZE_SHIFT(flags) ((flags) >> 8)
779
780 static SLJIT_CONST sljit_ins sljit_mem_imm[4] = {
781 /* u l */ 0x39400000 /* ldrb [reg,imm] */,
782 /* u s */ 0x39000000 /* strb [reg,imm] */,
783 /* s l */ 0x39800000 /* ldrsb [reg,imm] */,
784 /* s s */ 0x39000000 /* strb [reg,imm] */,
785 };
786
787 static SLJIT_CONST sljit_ins sljit_mem_simm[4] = {
788 /* u l */ 0x38400000 /* ldurb [reg,imm] */,
789 /* u s */ 0x38000000 /* sturb [reg,imm] */,
790 /* s l */ 0x38800000 /* ldursb [reg,imm] */,
791 /* s s */ 0x38000000 /* sturb [reg,imm] */,
792 };
793
794 static SLJIT_CONST sljit_ins sljit_mem_pre_simm[4] = {
795 /* u l */ 0x38400c00 /* ldrb [reg,imm]! */,
796 /* u s */ 0x38000c00 /* strb [reg,imm]! */,
797 /* s l */ 0x38800c00 /* ldrsb [reg,imm]! */,
798 /* s s */ 0x38000c00 /* strb [reg,imm]! */,
799 };
800
801 static SLJIT_CONST sljit_ins sljit_mem_reg[4] = {
802 /* u l */ 0x38606800 /* ldrb [reg,reg] */,
803 /* u s */ 0x38206800 /* strb [reg,reg] */,
804 /* s l */ 0x38a06800 /* ldrsb [reg,reg] */,
805 /* s s */ 0x38206800 /* strb [reg,reg] */,
806 };
807
808 /* Helper function. Dst should be reg + value, using at most 1 instruction, flags does not set. */
809 static sljit_si emit_set_delta(struct sljit_compiler *compiler, sljit_si dst, sljit_si reg, sljit_sw value)
810 {
811 if (value >= 0) {
812 if (value <= 0xfff)
813 return push_inst(compiler, ADDI | RD(dst) | RN(reg) | (value << 10));
814 if (value <= 0xffffff && !(value & 0xfff))
815 return push_inst(compiler, ADDI | (1 << 22) | RD(dst) | RN(reg) | (value >> 2));
816 }
817 else {
818 value = -value;
819 if (value <= 0xfff)
820 return push_inst(compiler, SUBI | RD(dst) | RN(reg) | (value << 10));
821 if (value <= 0xffffff && !(value & 0xfff))
822 return push_inst(compiler, SUBI | (1 << 22) | RD(dst) | RN(reg) | (value >> 2));
823 }
824 return SLJIT_ERR_UNSUPPORTED;
825 }
826
827 /* Can perform an operation using at most 1 instruction. */
828 static sljit_si getput_arg_fast(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg, sljit_si arg, sljit_sw argw)
829 {
830 sljit_ui shift = MEM_SIZE_SHIFT(flags);
831
832 SLJIT_ASSERT(arg & SLJIT_MEM);
833
834 if (SLJIT_UNLIKELY(flags & UPDATE)) {
835 if ((arg & REG_MASK) && !(arg & OFFS_REG_MASK) && argw <= 255 && argw >= -256) {
836 if (SLJIT_UNLIKELY(flags & ARG_TEST))
837 return 1;
838
839 arg &= REG_MASK;
840 argw &= 0x1ff;
841 FAIL_IF(push_inst(compiler, sljit_mem_pre_simm[flags & 0x3]
842 | (shift << 30) | RT(reg) | RN(arg) | (argw << 12)));
843 return -1;
844 }
845 return 0;
846 }
847
848 if (SLJIT_UNLIKELY(arg & OFFS_REG_MASK)) {
849 argw &= 0x3;
850 if (argw && argw != shift)
851 return 0;
852
853 if (SLJIT_UNLIKELY(flags & ARG_TEST))
854 return 1;
855
856 FAIL_IF(push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg)
857 | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw ? (1 << 12) : 0)));
858 return -1;
859 }
860
861 arg &= REG_MASK;
862 if (argw >= 0 && (argw >> shift) <= 0xfff && (argw & ((1 << shift) - 1)) == 0) {
863 if (SLJIT_UNLIKELY(flags & ARG_TEST))
864 return 1;
865
866 FAIL_IF(push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30)
867 | RT(reg) | RN(arg) | (argw << (10 - shift))));
868 return -1;
869 }
870
871 if (argw > 255 || argw < -256)
872 return 0;
873
874 if (SLJIT_UNLIKELY(flags & ARG_TEST))
875 return 1;
876
877 FAIL_IF(push_inst(compiler, sljit_mem_simm[flags & 0x3] | (shift << 30)
878 | RT(reg) | RN(arg) | ((argw & 0x1ff) << 12)));
879 return -1;
880 }
881
882 /* see getput_arg below.
883 Note: can_cache is called only for binary operators. Those
884 operators always uses word arguments without write back. */
885 static sljit_si can_cache(sljit_si arg, sljit_sw argw, sljit_si next_arg, sljit_sw next_argw)
886 {
887 sljit_sw diff;
888 if ((arg & OFFS_REG_MASK) || !(next_arg & SLJIT_MEM))
889 return 0;
890
891 if (!(arg & REG_MASK)) {
892 diff = argw - next_argw;
893 if (diff <= 0xfff && diff >= -0xfff)
894 return 1;
895 return 0;
896 }
897
898 if (argw == next_argw)
899 return 1;
900
901 diff = argw - next_argw;
902 if (arg == next_arg && diff <= 0xfff && diff >= -0xfff)
903 return 1;
904
905 return 0;
906 }
907
908 /* Emit the necessary instructions. See can_cache above. */
909 static sljit_si getput_arg(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg,
910 sljit_si arg, sljit_sw argw, sljit_si next_arg, sljit_sw next_argw)
911 {
912 sljit_ui shift = MEM_SIZE_SHIFT(flags);
913 sljit_si tmp_r, other_r;
914 sljit_sw diff;
915
916 SLJIT_ASSERT(arg & SLJIT_MEM);
917 if (!(next_arg & SLJIT_MEM)) {
918 next_arg = 0;
919 next_argw = 0;
920 }
921
922 tmp_r = (flags & STORE) ? TMP_REG3 : reg;
923
924 if (SLJIT_UNLIKELY((flags & UPDATE) && (arg & REG_MASK))) {
925 /* Update only applies if a base register exists. */
926 other_r = OFFS_REG(arg);
927 if (!other_r) {
928 other_r = arg & REG_MASK;
929 if (other_r != reg && argw >= 0 && argw <= 0xffffff) {
930 if ((argw & 0xfff) != 0)
931 FAIL_IF(push_inst(compiler, ADDI | RD(other_r) | RN(other_r) | ((argw & 0xfff) << 10)));
932 if (argw >> 12)
933 FAIL_IF(push_inst(compiler, ADDI | (1 << 22) | RD(other_r) | RN(other_r) | ((argw >> 12) << 10)));
934 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(other_r));
935 }
936 else if (other_r != reg && argw < 0 && argw >= -0xffffff) {
937 argw = -argw;
938 if ((argw & 0xfff) != 0)
939 FAIL_IF(push_inst(compiler, SUBI | RD(other_r) | RN(other_r) | ((argw & 0xfff) << 10)));
940 if (argw >> 12)
941 FAIL_IF(push_inst(compiler, SUBI | (1 << 22) | RD(other_r) | RN(other_r) | ((argw >> 12) << 10)));
942 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(other_r));
943 }
944
945 if (compiler->cache_arg == SLJIT_MEM) {
946 if (argw == compiler->cache_argw) {
947 other_r = TMP_REG3;
948 argw = 0;
949 }
950 else if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) {
951 FAIL_IF(compiler->error);
952 compiler->cache_argw = argw;
953 other_r = TMP_REG3;
954 argw = 0;
955 }
956 }
957
958 if (argw) {
959 FAIL_IF(load_immediate(compiler, TMP_REG3, argw));
960 compiler->cache_arg = SLJIT_MEM;
961 compiler->cache_argw = argw;
962 other_r = TMP_REG3;
963 argw = 0;
964 }
965 }
966
967 /* No caching here. */
968 arg &= REG_MASK;
969 argw &= 0x3;
970 if (!argw || argw == shift) {
971 FAIL_IF(push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(other_r) | (argw ? (1 << 12) : 0)));
972 return push_inst(compiler, ADD | RD(arg) | RN(arg) | RM(other_r) | (argw << 10));
973 }
974 if (arg != reg) {
975 FAIL_IF(push_inst(compiler, ADD | RD(arg) | RN(arg) | RM(other_r) | (argw << 10)));
976 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg));
977 }
978 FAIL_IF(push_inst(compiler, ADD | RD(TMP_LR) | RN(arg) | RM(other_r) | (argw << 10)));
979 FAIL_IF(push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(TMP_LR)));
980 return push_inst(compiler, ORR | RD(arg) | RN(TMP_ZERO) | RM(TMP_LR));
981 }
982
983 if (arg & OFFS_REG_MASK) {
984 other_r = OFFS_REG(arg);
985 arg &= REG_MASK;
986 FAIL_IF(push_inst(compiler, ADD | RD(tmp_r) | RN(arg) | RM(other_r) | ((argw & 0x3) << 10)));
987 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(tmp_r));
988 }
989
990 if (compiler->cache_arg == arg) {
991 diff = argw - compiler->cache_argw;
992 if (diff <= 255 && diff >= -256)
993 return push_inst(compiler, sljit_mem_simm[flags & 0x3] | (shift << 30)
994 | RT(reg) | RN(TMP_REG3) | ((diff & 0x1ff) << 12));
995 if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, diff) != SLJIT_ERR_UNSUPPORTED) {
996 FAIL_IF(compiler->error);
997 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg));
998 }
999 }
1000
1001 if (argw >= 0 && argw <= 0xffffff && (argw & ((1 << shift) - 1)) == 0) {
1002 FAIL_IF(push_inst(compiler, ADDI | (1 << 22) | RD(tmp_r) | RN(arg & REG_MASK) | ((argw >> 12) << 10)));
1003 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30)
1004 | RT(reg) | RN(tmp_r) | ((argw & 0xfff) << (10 - shift)));
1005 }
1006
1007 diff = argw - next_argw;
1008 next_arg = (arg & REG_MASK) && (arg == next_arg) && diff <= 0xfff && diff >= -0xfff && diff != 0;
1009 arg &= REG_MASK;
1010
1011 if (arg && compiler->cache_arg == SLJIT_MEM) {
1012 if (compiler->cache_argw == argw)
1013 return push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(TMP_REG3));
1014 if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) {
1015 FAIL_IF(compiler->error);
1016 compiler->cache_argw = argw;
1017 return push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(TMP_REG3));
1018 }
1019 }
1020
1021 compiler->cache_argw = argw;
1022 if (next_arg && emit_set_delta(compiler, TMP_REG3, arg, argw) != SLJIT_ERR_UNSUPPORTED) {
1023 FAIL_IF(compiler->error);
1024 compiler->cache_arg = SLJIT_MEM | arg;
1025 arg = 0;
1026 }
1027 else {
1028 FAIL_IF(load_immediate(compiler, TMP_REG3, argw));
1029 compiler->cache_arg = SLJIT_MEM;
1030
1031 if (next_arg) {
1032 FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG3) | RN(TMP_REG3) | RM(arg)));
1033 compiler->cache_arg = SLJIT_MEM | arg;
1034 arg = 0;
1035 }
1036 }
1037
1038 if (arg)
1039 return push_inst(compiler, sljit_mem_reg[flags & 0x3] | (shift << 30) | RT(reg) | RN(arg) | RM(TMP_REG3));
1040 return push_inst(compiler, sljit_mem_imm[flags & 0x3] | (shift << 30) | RT(reg) | RN(TMP_REG3));
1041 }
1042
1043 static SLJIT_INLINE sljit_si emit_op_mem(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg, sljit_si arg, sljit_sw argw)
1044 {
1045 if (getput_arg_fast(compiler, flags, reg, arg, argw))
1046 return compiler->error;
1047 compiler->cache_arg = 0;
1048 compiler->cache_argw = 0;
1049 return getput_arg(compiler, flags, reg, arg, argw, 0, 0);
1050 }
1051
1052 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)
1053 {
1054 if (getput_arg_fast(compiler, flags, reg, arg1, arg1w))
1055 return compiler->error;
1056 return getput_arg(compiler, flags, reg, arg1, arg1w, arg2, arg2w);
1057 }
1058
1059 /* --------------------------------------------------------------------- */
1060 /* Entry, exit */
1061 /* --------------------------------------------------------------------- */
1062
1063 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_enter(struct sljit_compiler *compiler,
1064 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
1065 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
1066 {
1067 sljit_si i, tmp, offs, prev, saved_regs_size;
1068
1069 CHECK_ERROR();
1070 CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size));
1071 set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size);
1072
1073 saved_regs_size = GET_SAVED_REGISTERS_SIZE(scratches, saveds, 0);
1074 local_size += saved_regs_size + SLJIT_LOCALS_OFFSET;
1075 local_size = (local_size + 15) & ~0xf;
1076 compiler->local_size = local_size;
1077
1078 if (local_size <= (63 * sizeof(sljit_sw))) {
1079 FAIL_IF(push_inst(compiler, STP_PRE | 29 | RT2(TMP_LR)
1080 | RN(TMP_SP) | ((-(local_size >> 3) & 0x7f) << 15)));
1081 FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(TMP_SP) | (0 << 10)));
1082 offs = (local_size - saved_regs_size) << (15 - 3);
1083 } else {
1084 compiler->local_size += 2 * sizeof(sljit_sw);
1085 local_size -= saved_regs_size;
1086 saved_regs_size += 2 * sizeof(sljit_sw);
1087 FAIL_IF(push_inst(compiler, STP_PRE | 29 | RT2(TMP_LR)
1088 | RN(TMP_SP) | ((-(saved_regs_size >> 3) & 0x7f) << 15)));
1089 offs = 2 << 15;
1090 }
1091
1092 tmp = saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - saveds) : SLJIT_FIRST_SAVED_REG;
1093 prev = -1;
1094 for (i = SLJIT_S0; i >= tmp; i--) {
1095 if (prev == -1) {
1096 prev = i;
1097 continue;
1098 }
1099 FAIL_IF(push_inst(compiler, STP | RT(prev) | RT2(i) | RN(TMP_SP) | offs));
1100 offs += 2 << 15;
1101 prev = -1;
1102 }
1103
1104 for (i = scratches; i >= SLJIT_FIRST_SAVED_REG; i--) {
1105 if (prev == -1) {
1106 prev = i;
1107 continue;
1108 }
1109 FAIL_IF(push_inst(compiler, STP | RT(prev) | RT2(i) | RN(TMP_SP) | offs));
1110 offs += 2 << 15;
1111 prev = -1;
1112 }
1113
1114 if (prev != -1)
1115 FAIL_IF(push_inst(compiler, STRI | RT(prev) | RN(TMP_SP) | (offs >> 5)));
1116
1117 if (compiler->local_size > (63 * sizeof(sljit_sw))) {
1118 /* The local_size is already adjusted by the saved registers. */
1119 if (local_size > 0xfff) {
1120 FAIL_IF(push_inst(compiler, SUBI | RD(TMP_SP) | RN(TMP_SP) | ((local_size >> 12) << 10) | (1 << 22)));
1121 local_size &= 0xfff;
1122 }
1123 if (local_size)
1124 FAIL_IF(push_inst(compiler, SUBI | RD(TMP_SP) | RN(TMP_SP) | (local_size << 10)));
1125 FAIL_IF(push_inst(compiler, ADDI | RD(SLJIT_SP) | RN(TMP_SP) | (0 << 10)));
1126 }
1127
1128 if (args >= 1)
1129 FAIL_IF(push_inst(compiler, ORR | RD(SLJIT_S0) | RN(TMP_ZERO) | RM(SLJIT_R0)));
1130 if (args >= 2)
1131 FAIL_IF(push_inst(compiler, ORR | RD(SLJIT_S1) | RN(TMP_ZERO) | RM(SLJIT_R1)));
1132 if (args >= 3)
1133 FAIL_IF(push_inst(compiler, ORR | RD(SLJIT_S2) | RN(TMP_ZERO) | RM(SLJIT_R2)));
1134
1135 return SLJIT_SUCCESS;
1136 }
1137
1138 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_set_context(struct sljit_compiler *compiler,
1139 sljit_si options, sljit_si args, sljit_si scratches, sljit_si saveds,
1140 sljit_si fscratches, sljit_si fsaveds, sljit_si local_size)
1141 {
1142 CHECK_ERROR();
1143 CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size));
1144 set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size);
1145
1146 local_size += GET_SAVED_REGISTERS_SIZE(scratches, saveds, 0) + SLJIT_LOCALS_OFFSET;
1147 local_size = (local_size + 15) & ~0xf;
1148 if (local_size > (63 * sizeof(sljit_sw)))
1149 local_size += 2 * sizeof(sljit_sw);
1150 compiler->local_size = local_size;
1151 return SLJIT_SUCCESS;
1152 }
1153
1154 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_return(struct sljit_compiler *compiler, sljit_si op, sljit_si src, sljit_sw srcw)
1155 {
1156 sljit_si local_size;
1157 sljit_si i, tmp, offs, prev, saved_regs_size;
1158
1159 CHECK_ERROR();
1160 CHECK(check_sljit_emit_return(compiler, op, src, srcw));
1161
1162 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
1163
1164 local_size = compiler->local_size;
1165
1166 saved_regs_size = GET_SAVED_REGISTERS_SIZE(compiler->scratches, compiler->saveds, 0);
1167 if (local_size <= (63 * sizeof(sljit_sw)))
1168 offs = (local_size - saved_regs_size) << (15 - 3);
1169 else {
1170 saved_regs_size += 2 * sizeof(sljit_sw);
1171 local_size -= saved_regs_size;
1172 if (local_size > 0xfff) {
1173 FAIL_IF(push_inst(compiler, ADDI | RD(TMP_SP) | RN(TMP_SP) | ((local_size >> 12) << 10) | (1 << 22)));
1174 local_size &= 0xfff;
1175 }
1176 if (local_size)
1177 FAIL_IF(push_inst(compiler, ADDI | RD(TMP_SP) | RN(TMP_SP) | (local_size << 10)));
1178 local_size = saved_regs_size;
1179 offs = 2 << 15;
1180 }
1181
1182 tmp = compiler->saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - compiler->saveds) : SLJIT_FIRST_SAVED_REG;
1183 prev = -1;
1184 for (i = SLJIT_S0; i >= tmp; i--) {
1185 if (prev == -1) {
1186 prev = i;
1187 continue;
1188 }
1189 FAIL_IF(push_inst(compiler, LDP | RT(prev) | RT2(i) | RN(TMP_SP) | offs));
1190 offs += 2 << 15;
1191 prev = -1;
1192 }
1193
1194 for (i = compiler->scratches; i >= SLJIT_FIRST_SAVED_REG; i--) {
1195 if (prev == -1) {
1196 prev = i;
1197 continue;
1198 }
1199 FAIL_IF(push_inst(compiler, LDP | RT(prev) | RT2(i) | RN(TMP_SP) | offs));
1200 offs += 2 << 15;
1201 prev = -1;
1202 }
1203
1204 if (prev != -1)
1205 FAIL_IF(push_inst(compiler, LDRI | RT(prev) | RN(TMP_SP) | (offs >> 5)));
1206
1207 FAIL_IF(push_inst(compiler, LDP_PST | 29 | RT2(TMP_LR)
1208 | RN(TMP_SP) | (((local_size >> 3) & 0x7f) << 15)));
1209
1210 FAIL_IF(push_inst(compiler, RET | RN(TMP_LR)));
1211 return SLJIT_SUCCESS;
1212 }
1213
1214 /* --------------------------------------------------------------------- */
1215 /* Operators */
1216 /* --------------------------------------------------------------------- */
1217
1218 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op0(struct sljit_compiler *compiler, sljit_si op)
1219 {
1220 sljit_ins inv_bits = (op & SLJIT_INT_OP) ? (1 << 31) : 0;
1221
1222 CHECK_ERROR();
1223 CHECK(check_sljit_emit_op0(compiler, op));
1224
1225 op = GET_OPCODE(op);
1226 switch (op) {
1227 case SLJIT_BREAKPOINT:
1228 return push_inst(compiler, BRK);
1229 case SLJIT_NOP:
1230 return push_inst(compiler, NOP);
1231 case SLJIT_LUMUL:
1232 case SLJIT_LSMUL:
1233 FAIL_IF(push_inst(compiler, ORR | RD(TMP_REG1) | RN(TMP_ZERO) | RM(SLJIT_R0)));
1234 FAIL_IF(push_inst(compiler, MADD | RD(SLJIT_R0) | RN(SLJIT_R0) | RM(SLJIT_R1) | RT2(TMP_ZERO)));
1235 return push_inst(compiler, (op == SLJIT_LUMUL ? UMULH : SMULH) | RD(SLJIT_R1) | RN(TMP_REG1) | RM(SLJIT_R1));
1236 case SLJIT_LUDIV:
1237 case SLJIT_LSDIV:
1238 FAIL_IF(push_inst(compiler, (ORR ^ inv_bits) | RD(TMP_REG1) | RN(TMP_ZERO) | RM(SLJIT_R0)));
1239 FAIL_IF(push_inst(compiler, ((op == SLJIT_LUDIV ? UDIV : SDIV) ^ inv_bits) | RD(SLJIT_R0) | RN(SLJIT_R0) | RM(SLJIT_R1)));
1240 FAIL_IF(push_inst(compiler, (MADD ^ inv_bits) | RD(SLJIT_R1) | RN(SLJIT_R0) | RM(SLJIT_R1) | RT2(TMP_ZERO)));
1241 return push_inst(compiler, (SUB ^ inv_bits) | RD(SLJIT_R1) | RN(TMP_REG1) | RM(SLJIT_R1));
1242 }
1243
1244 return SLJIT_SUCCESS;
1245 }
1246
1247 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op1(struct sljit_compiler *compiler, sljit_si op,
1248 sljit_si dst, sljit_sw dstw,
1249 sljit_si src, sljit_sw srcw)
1250 {
1251 sljit_si dst_r, flags, mem_flags;
1252 sljit_si op_flags = GET_ALL_FLAGS(op);
1253
1254 CHECK_ERROR();
1255 CHECK(check_sljit_emit_op1(compiler, op, dst, dstw, src, srcw));
1256 ADJUST_LOCAL_OFFSET(dst, dstw);
1257 ADJUST_LOCAL_OFFSET(src, srcw);
1258
1259 compiler->cache_arg = 0;
1260 compiler->cache_argw = 0;
1261
1262 dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1;
1263
1264 op = GET_OPCODE(op);
1265 if (op >= SLJIT_MOV && op <= SLJIT_MOVU_P) {
1266 switch (op) {
1267 case SLJIT_MOV:
1268 case SLJIT_MOV_P:
1269 flags = WORD_SIZE;
1270 break;
1271 case SLJIT_MOV_UB:
1272 flags = BYTE_SIZE;
1273 if (src & SLJIT_IMM)
1274 srcw = (sljit_ub)srcw;
1275 break;
1276 case SLJIT_MOV_SB:
1277 flags = BYTE_SIZE | SIGNED;
1278 if (src & SLJIT_IMM)
1279 srcw = (sljit_sb)srcw;
1280 break;
1281 case SLJIT_MOV_UH:
1282 flags = HALF_SIZE;
1283 if (src & SLJIT_IMM)
1284 srcw = (sljit_uh)srcw;
1285 break;
1286 case SLJIT_MOV_SH:
1287 flags = HALF_SIZE | SIGNED;
1288 if (src & SLJIT_IMM)
1289 srcw = (sljit_sh)srcw;
1290 break;
1291 case SLJIT_MOV_UI:
1292 flags = INT_SIZE;
1293 if (src & SLJIT_IMM)
1294 srcw = (sljit_ui)srcw;
1295 break;
1296 case SLJIT_MOV_SI:
1297 flags = INT_SIZE | SIGNED;
1298 if (src & SLJIT_IMM)
1299 srcw = (sljit_si)srcw;
1300 break;
1301 case SLJIT_MOVU:
1302 case SLJIT_MOVU_P:
1303 flags = WORD_SIZE | UPDATE;
1304 break;
1305 case SLJIT_MOVU_UB:
1306 flags = BYTE_SIZE | UPDATE;
1307 if (src & SLJIT_IMM)
1308 srcw = (sljit_ub)srcw;
1309 break;
1310 case SLJIT_MOVU_SB:
1311 flags = BYTE_SIZE | SIGNED | UPDATE;
1312 if (src & SLJIT_IMM)
1313 srcw = (sljit_sb)srcw;
1314 break;
1315 case SLJIT_MOVU_UH:
1316 flags = HALF_SIZE | UPDATE;
1317 if (src & SLJIT_IMM)
1318 srcw = (sljit_uh)srcw;
1319 break;
1320 case SLJIT_MOVU_SH:
1321 flags = HALF_SIZE | SIGNED | UPDATE;
1322 if (src & SLJIT_IMM)
1323 srcw = (sljit_sh)srcw;
1324 break;
1325 case SLJIT_MOVU_UI:
1326 flags = INT_SIZE | UPDATE;
1327 if (src & SLJIT_IMM)
1328 srcw = (sljit_ui)srcw;
1329 break;
1330 case SLJIT_MOVU_SI:
1331 flags = INT_SIZE | SIGNED | UPDATE;
1332 if (src & SLJIT_IMM)
1333 srcw = (sljit_si)srcw;
1334 break;
1335 default:
1336 SLJIT_ASSERT_STOP();
1337 flags = 0;
1338 break;
1339 }
1340
1341 if (src & SLJIT_IMM)
1342 FAIL_IF(emit_op_imm(compiler, SLJIT_MOV | ARG2_IMM, dst_r, TMP_REG1, srcw));
1343 else if (src & SLJIT_MEM) {
1344 if (getput_arg_fast(compiler, flags, dst_r, src, srcw))
1345 FAIL_IF(compiler->error);
1346 else
1347 FAIL_IF(getput_arg(compiler, flags, dst_r, src, srcw, dst, dstw));
1348 } else {
1349 if (dst_r != TMP_REG1)
1350 return emit_op_imm(compiler, op | ((op_flags & SLJIT_INT_OP) ? INT_OP : 0), dst_r, TMP_REG1, src);
1351 dst_r = src;
1352 }
1353
1354 if (dst & SLJIT_MEM) {
1355 if (getput_arg_fast(compiler, flags | STORE, dst_r, dst, dstw))
1356 return compiler->error;
1357 else
1358 return getput_arg(compiler, flags | STORE, dst_r, dst, dstw, 0, 0);
1359 }
1360 return SLJIT_SUCCESS;
1361 }
1362
1363 flags = GET_FLAGS(op_flags) ? SET_FLAGS : 0;
1364 mem_flags = WORD_SIZE;
1365 if (op_flags & SLJIT_INT_OP) {
1366 flags |= INT_OP;
1367 mem_flags = INT_SIZE;
1368 }
1369
1370 if (dst == SLJIT_UNUSED)
1371 flags |= UNUSED_RETURN;
1372
1373 if (src & SLJIT_MEM) {
1374 if (getput_arg_fast(compiler, mem_flags, TMP_REG2, src, srcw))
1375 FAIL_IF(compiler->error);
1376 else
1377 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src, srcw, dst, dstw));
1378 src = TMP_REG2;
1379 }
1380
1381 if (src & SLJIT_IMM) {
1382 flags |= ARG2_IMM;
1383 if (op_flags & SLJIT_INT_OP)
1384 srcw = (sljit_si)srcw;
1385 } else
1386 srcw = src;
1387
1388 emit_op_imm(compiler, flags | op, dst_r, TMP_REG1, srcw);
1389
1390 if (dst & SLJIT_MEM) {
1391 if (getput_arg_fast(compiler, mem_flags | STORE, dst_r, dst, dstw))
1392 return compiler->error;
1393 else
1394 return getput_arg(compiler, mem_flags | STORE, dst_r, dst, dstw, 0, 0);
1395 }
1396 return SLJIT_SUCCESS;
1397 }
1398
1399 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op2(struct sljit_compiler *compiler, sljit_si op,
1400 sljit_si dst, sljit_sw dstw,
1401 sljit_si src1, sljit_sw src1w,
1402 sljit_si src2, sljit_sw src2w)
1403 {
1404 sljit_si dst_r, flags, mem_flags;
1405
1406 CHECK_ERROR();
1407 CHECK(check_sljit_emit_op2(compiler, op, dst, dstw, src1, src1w, src2, src2w));
1408 ADJUST_LOCAL_OFFSET(dst, dstw);
1409 ADJUST_LOCAL_OFFSET(src1, src1w);
1410 ADJUST_LOCAL_OFFSET(src2, src2w);
1411
1412 compiler->cache_arg = 0;
1413 compiler->cache_argw = 0;
1414
1415 dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1;
1416 flags = GET_FLAGS(op) ? SET_FLAGS : 0;
1417 mem_flags = WORD_SIZE;
1418 if (op & SLJIT_INT_OP) {
1419 flags |= INT_OP;
1420 mem_flags = INT_SIZE;
1421 }
1422
1423 if (dst == SLJIT_UNUSED)
1424 flags |= UNUSED_RETURN;
1425
1426 if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, mem_flags | STORE | ARG_TEST, TMP_REG1, dst, dstw))
1427 flags |= SLOW_DEST;
1428
1429 if (src1 & SLJIT_MEM) {
1430 if (getput_arg_fast(compiler, mem_flags, TMP_REG1, src1, src1w))
1431 FAIL_IF(compiler->error);
1432 else
1433 flags |= SLOW_SRC1;
1434 }
1435 if (src2 & SLJIT_MEM) {
1436 if (getput_arg_fast(compiler, mem_flags, TMP_REG2, src2, src2w))
1437 FAIL_IF(compiler->error);
1438 else
1439 flags |= SLOW_SRC2;
1440 }
1441
1442 if ((flags & (SLOW_SRC1 | SLOW_SRC2)) == (SLOW_SRC1 | SLOW_SRC2)) {
1443 if (!can_cache(src1, src1w, src2, src2w) && can_cache(src1, src1w, dst, dstw)) {
1444 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src2, src2w, src1, src1w));
1445 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG1, src1, src1w, dst, dstw));
1446 }
1447 else {
1448 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG1, src1, src1w, src2, src2w));
1449 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src2, src2w, dst, dstw));
1450 }
1451 }
1452 else if (flags & SLOW_SRC1)
1453 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG1, src1, src1w, dst, dstw));
1454 else if (flags & SLOW_SRC2)
1455 FAIL_IF(getput_arg(compiler, mem_flags, TMP_REG2, src2, src2w, dst, dstw));
1456
1457 if (src1 & SLJIT_MEM)
1458 src1 = TMP_REG1;
1459 if (src2 & SLJIT_MEM)
1460 src2 = TMP_REG2;
1461
1462 if (src1 & SLJIT_IMM)
1463 flags |= ARG1_IMM;
1464 else
1465 src1w = src1;
1466 if (src2 & SLJIT_IMM)
1467 flags |= ARG2_IMM;
1468 else
1469 src2w = src2;
1470
1471 emit_op_imm(compiler, flags | GET_OPCODE(op), dst_r, src1w, src2w);
1472
1473 if (dst & SLJIT_MEM) {
1474 if (!(flags & SLOW_DEST)) {
1475 getput_arg_fast(compiler, mem_flags | STORE, dst_r, dst, dstw);
1476 return compiler->error;
1477 }
1478 return getput_arg(compiler, mem_flags | STORE, TMP_REG1, dst, dstw, 0, 0);
1479 }
1480
1481 return SLJIT_SUCCESS;
1482 }
1483
1484 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_register_index(sljit_si reg)
1485 {
1486 CHECK_REG_INDEX(check_sljit_get_register_index(reg));
1487 return reg_map[reg];
1488 }
1489
1490 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_get_float_register_index(sljit_si reg)
1491 {
1492 CHECK_REG_INDEX(check_sljit_get_float_register_index(reg));
1493 return reg;
1494 }
1495
1496 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_custom(struct sljit_compiler *compiler,
1497 void *instruction, sljit_si size)
1498 {
1499 CHECK_ERROR();
1500 CHECK(check_sljit_emit_op_custom(compiler, instruction, size));
1501
1502 return push_inst(compiler, *(sljit_ins*)instruction);
1503 }
1504
1505 /* --------------------------------------------------------------------- */
1506 /* Floating point operators */
1507 /* --------------------------------------------------------------------- */
1508
1509 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_is_fpu_available(void)
1510 {
1511 #ifdef SLJIT_IS_FPU_AVAILABLE
1512 return SLJIT_IS_FPU_AVAILABLE;
1513 #else
1514 /* Available by default. */
1515 return 1;
1516 #endif
1517 }
1518
1519 static sljit_si emit_fop_mem(struct sljit_compiler *compiler, sljit_si flags, sljit_si reg, sljit_si arg, sljit_sw argw)
1520 {
1521 sljit_ui shift = MEM_SIZE_SHIFT(flags);
1522 sljit_ins ins_bits = (shift << 30);
1523 sljit_si other_r;
1524 sljit_sw diff;
1525
1526 SLJIT_ASSERT(arg & SLJIT_MEM);
1527
1528 if (!(flags & STORE))
1529 ins_bits |= 1 << 22;
1530
1531 if (arg & OFFS_REG_MASK) {
1532 argw &= 3;
1533 if (!argw || argw == shift)
1534 return push_inst(compiler, STR_FR | ins_bits | VT(reg)
1535 | RN(arg & REG_MASK) | RM(OFFS_REG(arg)) | (argw ? (1 << 12) : 0));
1536 other_r = OFFS_REG(arg);
1537 arg &= REG_MASK;
1538 FAIL_IF(push_inst(compiler, ADD | RD(TMP_REG1) | RN(arg) | RM(other_r) | (argw << 10)));
1539 arg = TMP_REG1;
1540 argw = 0;
1541 }
1542
1543 arg &= REG_MASK;
1544 if (arg && argw >= 0 && ((argw >> shift) <= 0xfff) && (argw & ((1 << shift) - 1)) == 0)
1545 return push_inst(compiler, STR_FI | ins_bits | VT(reg) | RN(arg) | (argw << (10 - shift)));
1546
1547 if (arg && argw <= 255 && argw >= -256)
1548 return push_inst(compiler, STUR_FI | ins_bits | VT(reg) | RN(arg) | ((argw & 0x1ff) << 12));
1549
1550 /* Slow cases */
1551 if (compiler->cache_arg == SLJIT_MEM && argw != compiler->cache_argw) {
1552 diff = argw - compiler->cache_argw;
1553 if (!arg && diff <= 255 && diff >= -256)
1554 return push_inst(compiler, STUR_FI | ins_bits | VT(reg) | RN(TMP_REG3) | ((diff & 0x1ff) << 12));
1555 if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) {
1556 FAIL_IF(compiler->error);
1557 compiler->cache_argw = argw;
1558 }
1559 }
1560
1561 if (compiler->cache_arg != SLJIT_MEM || argw != compiler->cache_argw) {
1562 compiler->cache_arg = SLJIT_MEM;
1563 compiler->cache_argw = argw;
1564 FAIL_IF(load_immediate(compiler, TMP_REG3, argw));
1565 }
1566
1567 if (arg & REG_MASK)
1568 return push_inst(compiler, STR_FR | ins_bits | VT(reg) | RN(arg) | RM(TMP_REG3));
1569 return push_inst(compiler, STR_FI | ins_bits | VT(reg) | RN(TMP_REG3));
1570 }
1571
1572 static SLJIT_INLINE sljit_si sljit_emit_fop1_convw_fromd(struct sljit_compiler *compiler, sljit_si op,
1573 sljit_si dst, sljit_sw dstw,
1574 sljit_si src, sljit_sw srcw)
1575 {
1576 sljit_si dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1;
1577 sljit_ins inv_bits = (op & SLJIT_SINGLE_OP) ? (1 << 22) : 0;
1578
1579 if (GET_OPCODE(op) == SLJIT_CONVI_FROMD)
1580 inv_bits |= (1 << 31);
1581
1582 if (src & SLJIT_MEM) {
1583 emit_fop_mem(compiler, (op & SLJIT_SINGLE_OP) ? INT_SIZE : WORD_SIZE, TMP_FREG1, src, srcw);
1584 src = TMP_FREG1;
1585 }
1586
1587 FAIL_IF(push_inst(compiler, (FCVTZS ^ inv_bits) | RD(dst_r) | VN(src)));
1588
1589 if (dst_r == TMP_REG1 && dst != SLJIT_UNUSED)
1590 return emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONVI_FROMD) ? INT_SIZE : WORD_SIZE) | STORE, TMP_REG1, dst, dstw);
1591 return SLJIT_SUCCESS;
1592 }
1593
1594 static SLJIT_INLINE sljit_si sljit_emit_fop1_convd_fromw(struct sljit_compiler *compiler, sljit_si op,
1595 sljit_si dst, sljit_sw dstw,
1596 sljit_si src, sljit_sw srcw)
1597 {
1598 sljit_si dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1;
1599 sljit_ins inv_bits = (op & SLJIT_SINGLE_OP) ? (1 << 22) : 0;
1600
1601 if (GET_OPCODE(op) == SLJIT_CONVD_FROMI)
1602 inv_bits |= (1 << 31);
1603
1604 if (src & SLJIT_MEM) {
1605 emit_op_mem(compiler, ((GET_OPCODE(op) == SLJIT_CONVD_FROMI) ? INT_SIZE : WORD_SIZE), TMP_REG1, src, srcw);
1606 src = TMP_REG1;
1607 } else if (src & SLJIT_IMM) {
1608 #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64)
1609 if (GET_OPCODE(op) == SLJIT_CONVD_FROMI)
1610 srcw = (sljit_si)srcw;
1611 #endif
1612 FAIL_IF(load_immediate(compiler, TMP_REG1, srcw));
1613 src = TMP_REG1;
1614 }
1615
1616 FAIL_IF(push_inst(compiler, (SCVTF ^ inv_bits) | VD(dst_r) | RN(src)));
1617
1618 if (dst & SLJIT_MEM)
1619 return emit_fop_mem(compiler, ((op & SLJIT_SINGLE_OP) ? INT_SIZE : WORD_SIZE) | STORE, TMP_FREG1, dst, dstw);
1620 return SLJIT_SUCCESS;
1621 }
1622
1623 static SLJIT_INLINE sljit_si sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_si op,
1624 sljit_si src1, sljit_sw src1w,
1625 sljit_si src2, sljit_sw src2w)
1626 {
1627 sljit_si mem_flags = (op & SLJIT_SINGLE_OP) ? INT_SIZE : WORD_SIZE;
1628 sljit_ins inv_bits = (op & SLJIT_SINGLE_OP) ? (1 << 22) : 0;
1629
1630 if (src1 & SLJIT_MEM) {
1631 emit_fop_mem(compiler, mem_flags, TMP_FREG1, src1, src1w);
1632 src1 = TMP_FREG1;
1633 }
1634
1635 if (src2 & SLJIT_MEM) {
1636 emit_fop_mem(compiler, mem_flags, TMP_FREG2, src2, src2w);
1637 src2 = TMP_FREG2;
1638 }
1639
1640 return push_inst(compiler, (FCMP ^ inv_bits) | VN(src1) | VM(src2));
1641 }
1642
1643 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop1(struct sljit_compiler *compiler, sljit_si op,
1644 sljit_si dst, sljit_sw dstw,
1645 sljit_si src, sljit_sw srcw)
1646 {
1647 sljit_si dst_r, mem_flags = (op & SLJIT_SINGLE_OP) ? INT_SIZE : WORD_SIZE;
1648 sljit_ins inv_bits;
1649
1650 CHECK_ERROR();
1651 compiler->cache_arg = 0;
1652 compiler->cache_argw = 0;
1653
1654 SLJIT_COMPILE_ASSERT((INT_SIZE ^ 0x100) == WORD_SIZE, must_be_one_bit_difference);
1655 SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw);
1656
1657 inv_bits = (op & SLJIT_SINGLE_OP) ? (1 << 22) : 0;
1658 dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1;
1659
1660 if (src & SLJIT_MEM) {
1661 emit_fop_mem(compiler, (GET_OPCODE(op) == SLJIT_CONVD_FROMS) ? (mem_flags ^ 0x100) : mem_flags, dst_r, src, srcw);
1662 src = dst_r;
1663 }
1664
1665 switch (GET_OPCODE(op)) {
1666 case SLJIT_DMOV:
1667 if (src != dst_r) {
1668 if (dst_r != TMP_FREG1)
1669 FAIL_IF(push_inst(compiler, (FMOV ^ inv_bits) | VD(dst_r) | VN(src)));
1670 else
1671 dst_r = src;
1672 }
1673 break;
1674 case SLJIT_DNEG:
1675 FAIL_IF(push_inst(compiler, (FNEG ^ inv_bits) | VD(dst_r) | VN(src)));
1676 break;
1677 case SLJIT_DABS:
1678 FAIL_IF(push_inst(compiler, (FABS ^ inv_bits) | VD(dst_r) | VN(src)));
1679 break;
1680 case SLJIT_CONVD_FROMS:
1681 FAIL_IF(push_inst(compiler, FCVT | ((op & SLJIT_SINGLE_OP) ? (1 << 22) : (1 << 15)) | VD(dst_r) | VN(src)));
1682 break;
1683 }
1684
1685 if (dst & SLJIT_MEM)
1686 return emit_fop_mem(compiler, mem_flags | STORE, dst_r, dst, dstw);
1687 return SLJIT_SUCCESS;
1688 }
1689
1690 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fop2(struct sljit_compiler *compiler, sljit_si op,
1691 sljit_si dst, sljit_sw dstw,
1692 sljit_si src1, sljit_sw src1w,
1693 sljit_si src2, sljit_sw src2w)
1694 {
1695 sljit_si dst_r, mem_flags = (op & SLJIT_SINGLE_OP) ? INT_SIZE : WORD_SIZE;
1696 sljit_ins inv_bits = (op & SLJIT_SINGLE_OP) ? (1 << 22) : 0;
1697
1698 CHECK_ERROR();
1699 CHECK(check_sljit_emit_fop2(compiler, op, dst, dstw, src1, src1w, src2, src2w));
1700 ADJUST_LOCAL_OFFSET(dst, dstw);
1701 ADJUST_LOCAL_OFFSET(src1, src1w);
1702 ADJUST_LOCAL_OFFSET(src2, src2w);
1703
1704 compiler->cache_arg = 0;
1705 compiler->cache_argw = 0;
1706
1707 dst_r = FAST_IS_REG(dst) ? dst : TMP_FREG1;
1708 if (src1 & SLJIT_MEM) {
1709 emit_fop_mem(compiler, mem_flags, TMP_FREG1, src1, src1w);
1710 src1 = TMP_FREG1;
1711 }
1712 if (src2 & SLJIT_MEM) {
1713 emit_fop_mem(compiler, mem_flags, TMP_FREG2, src2, src2w);
1714 src2 = TMP_FREG2;
1715 }
1716
1717 switch (GET_OPCODE(op)) {
1718 case SLJIT_DADD:
1719 FAIL_IF(push_inst(compiler, (FADD ^ inv_bits) | VD(dst_r) | VN(src1) | VM(src2)));
1720 break;
1721 case SLJIT_DSUB:
1722 FAIL_IF(push_inst(compiler, (FSUB ^ inv_bits) | VD(dst_r) | VN(src1) | VM(src2)));
1723 break;
1724 case SLJIT_DMUL:
1725 FAIL_IF(push_inst(compiler, (FMUL ^ inv_bits) | VD(dst_r) | VN(src1) | VM(src2)));
1726 break;
1727 case SLJIT_DDIV:
1728 FAIL_IF(push_inst(compiler, (FDIV ^ inv_bits) | VD(dst_r) | VN(src1) | VM(src2)));
1729 break;
1730 }
1731
1732 if (!(dst & SLJIT_MEM))
1733 return SLJIT_SUCCESS;
1734 return emit_fop_mem(compiler, mem_flags | STORE, TMP_FREG1, dst, dstw);
1735 }
1736
1737 /* --------------------------------------------------------------------- */
1738 /* Other instructions */
1739 /* --------------------------------------------------------------------- */
1740
1741 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw)
1742 {
1743 CHECK_ERROR();
1744 CHECK(check_sljit_emit_fast_enter(compiler, dst, dstw));
1745 ADJUST_LOCAL_OFFSET(dst, dstw);
1746
1747 /* For UNUSED dst. Uncommon, but possible. */
1748 if (dst == SLJIT_UNUSED)
1749 return SLJIT_SUCCESS;
1750
1751 if (FAST_IS_REG(dst))
1752 return push_inst(compiler, ORR | RD(dst) | RN(TMP_ZERO) | RM(TMP_LR));
1753
1754 /* Memory. */
1755 return emit_op_mem(compiler, WORD_SIZE | STORE, TMP_LR, dst, dstw);
1756 }
1757
1758 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_si src, sljit_sw srcw)
1759 {
1760 CHECK_ERROR();
1761 CHECK(check_sljit_emit_fast_return(compiler, src, srcw));
1762 ADJUST_LOCAL_OFFSET(src, srcw);
1763
1764 if (FAST_IS_REG(src))
1765 FAIL_IF(push_inst(compiler, ORR | RD(TMP_LR) | RN(TMP_ZERO) | RM(src)));
1766 else if (src & SLJIT_MEM)
1767 FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_LR, src, srcw));
1768 else if (src & SLJIT_IMM)
1769 FAIL_IF(load_immediate(compiler, TMP_LR, srcw));
1770
1771 return push_inst(compiler, RET | RN(TMP_LR));
1772 }
1773
1774 /* --------------------------------------------------------------------- */
1775 /* Conditional instructions */
1776 /* --------------------------------------------------------------------- */
1777
1778 static sljit_uw get_cc(sljit_si type)
1779 {
1780 switch (type) {
1781 case SLJIT_EQUAL:
1782 case SLJIT_MUL_NOT_OVERFLOW:
1783 case SLJIT_D_EQUAL:
1784 return 0x1;
1785
1786 case SLJIT_NOT_EQUAL:
1787 case SLJIT_MUL_OVERFLOW:
1788 case SLJIT_D_NOT_EQUAL:
1789 return 0x0;
1790
1791 case SLJIT_LESS:
1792 case SLJIT_D_LESS:
1793 return 0x2;
1794
1795 case SLJIT_GREATER_EQUAL:
1796 case SLJIT_D_GREATER_EQUAL:
1797 return 0x3;
1798
1799 case SLJIT_GREATER:
1800 case SLJIT_D_GREATER:
1801 return 0x9;
1802
1803 case SLJIT_LESS_EQUAL:
1804 case SLJIT_D_LESS_EQUAL:
1805 return 0x8;
1806
1807 case SLJIT_SIG_LESS:
1808 return 0xa;
1809
1810 case SLJIT_SIG_GREATER_EQUAL:
1811 return 0xb;
1812
1813 case SLJIT_SIG_GREATER:
1814 return 0xd;
1815
1816 case SLJIT_SIG_LESS_EQUAL:
1817 return 0xc;
1818
1819 case SLJIT_OVERFLOW:
1820 case SLJIT_D_UNORDERED:
1821 return 0x7;
1822
1823 case SLJIT_NOT_OVERFLOW:
1824 case SLJIT_D_ORDERED:
1825 return 0x6;
1826
1827 default:
1828 SLJIT_ASSERT_STOP();
1829 return 0xe;
1830 }
1831 }
1832
1833 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1834 {
1835 struct sljit_label *label;
1836
1837 CHECK_ERROR_PTR();
1838 CHECK_PTR(check_sljit_emit_label(compiler));
1839
1840 if (compiler->last_label && compiler->last_label->size == compiler->size)
1841 return compiler->last_label;
1842
1843 label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label));
1844 PTR_FAIL_IF(!label);
1845 set_label(label, compiler);
1846 return label;
1847 }
1848
1849 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_si type)
1850 {
1851 struct sljit_jump *jump;
1852
1853 CHECK_ERROR_PTR();
1854 CHECK_PTR(check_sljit_emit_jump(compiler, type));
1855
1856 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1857 PTR_FAIL_IF(!jump);
1858 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
1859 type &= 0xff;
1860
1861 if (type < SLJIT_JUMP) {
1862 jump->flags |= IS_COND;
1863 PTR_FAIL_IF(push_inst(compiler, B_CC | (6 << 5) | get_cc(type)));
1864 }
1865 else if (type >= SLJIT_FAST_CALL)
1866 jump->flags |= IS_BL;
1867
1868 PTR_FAIL_IF(emit_imm64_const(compiler, TMP_REG1, 0));
1869 jump->addr = compiler->size;
1870 PTR_FAIL_IF(push_inst(compiler, ((type >= SLJIT_FAST_CALL) ? BLR : BR) | RN(TMP_REG1)));
1871
1872 return jump;
1873 }
1874
1875 static SLJIT_INLINE struct sljit_jump* emit_cmp_to0(struct sljit_compiler *compiler, sljit_si type,
1876 sljit_si src, sljit_sw srcw)
1877 {
1878 struct sljit_jump *jump;
1879 sljit_ins inv_bits = (type & SLJIT_INT_OP) ? (1 << 31) : 0;
1880
1881 SLJIT_ASSERT((type & 0xff) == SLJIT_EQUAL || (type & 0xff) == SLJIT_NOT_EQUAL);
1882 ADJUST_LOCAL_OFFSET(src, srcw);
1883
1884 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1885 PTR_FAIL_IF(!jump);
1886 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
1887 jump->flags |= IS_CBZ | IS_COND;
1888
1889 if (src & SLJIT_MEM) {
1890 PTR_FAIL_IF(emit_op_mem(compiler, inv_bits ? INT_SIZE : WORD_SIZE, TMP_REG1, src, srcw));
1891 src = TMP_REG1;
1892 }
1893 else if (src & SLJIT_IMM) {
1894 PTR_FAIL_IF(load_immediate(compiler, TMP_REG1, srcw));
1895 src = TMP_REG1;
1896 }
1897 SLJIT_ASSERT(FAST_IS_REG(src));
1898
1899 if ((type & 0xff) == SLJIT_EQUAL)
1900 inv_bits |= 1 << 24;
1901
1902 PTR_FAIL_IF(push_inst(compiler, (CBZ ^ inv_bits) | (6 << 5) | RT(src)));
1903 PTR_FAIL_IF(emit_imm64_const(compiler, TMP_REG1, 0));
1904 jump->addr = compiler->size;
1905 PTR_FAIL_IF(push_inst(compiler, BR | RN(TMP_REG1)));
1906 return jump;
1907 }
1908
1909 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_ijump(struct sljit_compiler *compiler, sljit_si type, sljit_si src, sljit_sw srcw)
1910 {
1911 struct sljit_jump *jump;
1912
1913 CHECK_ERROR();
1914 CHECK(check_sljit_emit_ijump(compiler, type, src, srcw));
1915 ADJUST_LOCAL_OFFSET(src, srcw);
1916
1917 /* In ARM, we don't need to touch the arguments. */
1918 if (!(src & SLJIT_IMM)) {
1919 if (src & SLJIT_MEM) {
1920 FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG1, src, srcw));
1921 src = TMP_REG1;
1922 }
1923 return push_inst(compiler, ((type >= SLJIT_FAST_CALL) ? BLR : BR) | RN(src));
1924 }
1925
1926 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1927 FAIL_IF(!jump);
1928 set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_BL : 0));
1929 jump->u.target = srcw;
1930
1931 FAIL_IF(emit_imm64_const(compiler, TMP_REG1, 0));
1932 jump->addr = compiler->size;
1933 return push_inst(compiler, ((type >= SLJIT_FAST_CALL) ? BLR : BR) | RN(TMP_REG1));
1934 }
1935
1936 SLJIT_API_FUNC_ATTRIBUTE sljit_si sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_si op,
1937 sljit_si dst, sljit_sw dstw,
1938 sljit_si src, sljit_sw srcw,
1939 sljit_si type)
1940 {
1941 sljit_si dst_r, flags, mem_flags;
1942 sljit_ins cc;
1943
1944 CHECK_ERROR();
1945 CHECK(check_sljit_emit_op_flags(compiler, op, dst, dstw, src, srcw, type));
1946 ADJUST_LOCAL_OFFSET(dst, dstw);
1947 ADJUST_LOCAL_OFFSET(src, srcw);
1948
1949 if (dst == SLJIT_UNUSED)
1950 return SLJIT_SUCCESS;
1951
1952 cc = get_cc(type & 0xff);
1953 dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1;
1954
1955 if (GET_OPCODE(op) < SLJIT_ADD) {
1956 FAIL_IF(push_inst(compiler, CSINC | (cc << 12) | RD(dst_r) | RN(TMP_ZERO) | RM(TMP_ZERO)));
1957 if (dst_r != TMP_REG1)
1958 return SLJIT_SUCCESS;
1959 return emit_op_mem(compiler, (GET_OPCODE(op) == SLJIT_MOV ? WORD_SIZE : INT_SIZE) | STORE, TMP_REG1, dst, dstw);
1960 }
1961
1962 compiler->cache_arg = 0;
1963 compiler->cache_argw = 0;
1964 flags = GET_FLAGS(op) ? SET_FLAGS : 0;
1965 mem_flags = WORD_SIZE;
1966 if (op & SLJIT_INT_OP) {
1967 flags |= INT_OP;
1968 mem_flags = INT_SIZE;
1969 }
1970
1971 if (src & SLJIT_MEM) {
1972 FAIL_IF(emit_op_mem2(compiler, mem_flags, TMP_REG1, src, srcw, dst, dstw));
1973 src = TMP_REG1;
1974 srcw = 0;
1975 } else if (src & SLJIT_IMM)
1976 flags |= ARG1_IMM;
1977
1978 FAIL_IF(push_inst(compiler, CSINC | (cc << 12) | RD(TMP_REG2) | RN(TMP_ZERO) | RM(TMP_ZERO)));
1979 emit_op_imm(compiler, flags | GET_OPCODE(op), dst_r, src, TMP_REG2);
1980
1981 if (dst_r != TMP_REG1)
1982 return SLJIT_SUCCESS;
1983 return emit_op_mem2(compiler, mem_flags | STORE, TMP_REG1, dst, dstw, 0, 0);
1984 }
1985
1986 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_si dst, sljit_sw dstw, sljit_sw init_value)
1987 {
1988 struct sljit_const *const_;
1989 sljit_si dst_r;
1990
1991 CHECK_ERROR_PTR();
1992 CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value));
1993 ADJUST_LOCAL_OFFSET(dst, dstw);
1994
1995 const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const));
1996 PTR_FAIL_IF(!const_);
1997 set_const(const_, compiler);
1998
1999 dst_r = SLOW_IS_REG(dst) ? dst : TMP_REG1;
2000 PTR_FAIL_IF(emit_imm64_const(compiler, dst_r, init_value));
2001
2002 if (dst & SLJIT_MEM)
2003 PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw));
2004 return const_;
2005 }
2006
2007 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_addr)
2008 {
2009 sljit_ins* inst = (sljit_ins*)addr;
2010 modify_imm64_const(inst, new_addr);
2011 SLJIT_CACHE_FLUSH(inst, inst + 4);
2012 }
2013
2014 SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant)
2015 {
2016 sljit_ins* inst = (sljit_ins*)addr;
2017 modify_imm64_const(inst, new_constant);
2018 SLJIT_CACHE_FLUSH(inst, inst + 4);
2019 }

  ViewVC Help
Powered by ViewVC 1.1.5