Home | History | Annotate | Download | only in sljit

Lines Matching refs:compiler

2  *    Stack-less Just-In-Time compiler
184 static sljit_s32 push_inst16(struct sljit_compiler *compiler, sljit_ins inst)
189 ptr = (sljit_u16*)ensure_buf(compiler, sizeof(sljit_u16));
192 compiler->size++;
196 static sljit_s32 push_inst32(struct sljit_compiler *compiler, sljit_ins inst)
198 sljit_u16 *ptr = (sljit_u16*)ensure_buf(compiler, sizeof(sljit_ins));
202 compiler->size += 2;
206 static SLJIT_INLINE sljit_s32 emit_imm32_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_uw imm)
208 FAIL_IF(push_inst32(compiler, MOVW | RD4(dst) |
210 return push_inst32(compiler, MOVT | RD4(dst) |
342 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
356 CHECK_PTR(check_sljit_generate_code(compiler));
357 reverse_buf(compiler);
359 code = (sljit_u16*)SLJIT_MALLOC_EXEC(compiler->size * sizeof(sljit_u16));
361 buf = compiler->buf;
365 label = compiler->labels;
366 jump = compiler->jumps;
367 const_ = compiler->consts;
408 SLJIT_ASSERT(code_ptr - code <= (sljit_sw)compiler->size);
410 jump = compiler->jumps;
416 compiler->error = SLJIT_ERR_COMPILED;
417 compiler->executable_size = (code_ptr - code) * sizeof(sljit_u16);
477 static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst, sljit_uw imm)
484 return push_inst32(compiler, MOV_WI | RD4(dst) | tmp);
487 return push_inst32(compiler, MVN_WI | RD4(dst) | tmp);
491 FAIL_IF(push_inst32(compiler, MOVW | RD4(dst) |
496 return push_inst32(compiler, MOVT | RD4(dst) |
511 static sljit_s32 emit_op_imm(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 dst, sljit_uw arg1, sljit_uw arg2)
522 FAIL_IF(load_immediate(compiler, TMP_REG1, arg1));
537 return load_immediate(compiler, dst, imm);
540 return load_immediate(compiler, dst, ~imm);
548 return push_inst16(compiler, ADDSI3 | IMM3(imm) | RD3(dst) | RN3(reg));
550 return push_inst16(compiler, SUBSI3 | IMM3(nimm) | RD3(dst) | RN3(reg));
553 return push_inst16(compiler, ADDSI8 | IMM8(imm) | RDN3(dst));
555 return push_inst16(compiler, SUBSI8 | IMM8(nimm) | RDN3(dst));
560 return push_inst32(compiler, ADDWI | RD4(dst) | RN4(reg) | IMM12(imm));
562 return push_inst32(compiler, SUBWI | RD4(dst) | RN4(reg) | IMM12(nimm));
566 return push_inst32(compiler, ADD_WI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
571 return push_inst32(compiler, ADCI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
576 return push_inst16(compiler, RSBSI | RD3(dst) | RN3(reg));
579 return push_inst32(compiler, RSB_WI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
585 return push_inst16(compiler, SUBSI3 | IMM3(imm) | RD3(dst) | RN3(reg));
587 return push_inst16(compiler, ADDSI3 | IMM3(nimm) | RD3(dst) | RN3(reg));
590 return push_inst16(compiler, SUBSI8 | IMM8(imm) | RDN3(dst));
592 return push_inst16(compiler, ADDSI8 | IMM8(nimm) | RDN3(dst));
595 return push_inst16(compiler, CMPI | IMM8(imm) | RDN3(reg));
599 return push_inst32(compiler, SUBWI | RD4(dst) | RN4(reg) | IMM12(imm));
601 return push_inst32(compiler, ADDWI | RD4(dst) | RN4(reg) | IMM12(nimm));
605 return push_inst32(compiler, SUB_WI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
612 return push_inst32(compiler, SBCI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
617 return push_inst32(compiler, ANDI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | nimm);
620 return push_inst32(compiler, BICI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
625 return push_inst32(compiler, ORRI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | nimm);
628 return push_inst32(compiler, ORNI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
633 return push_inst32(compiler, EORI | (flags & SET_FLAGS) | RD4(dst) | RN4(reg) | imm);
643 return push_inst16(compiler, MOV | SET_REGS44(dst, reg));
645 return push_inst16(compiler, MOVS | RD3(dst) | RN3(reg));
646 return push_inst32(compiler, MOV_W | SET_FLAGS | RD4(dst) | RM4(reg));
651 return push_inst16(compiler, LSLSI | RD3(dst) | RN3(reg) | (imm << 6));
652 return push_inst32(compiler, LSL_WI | (flags & SET_FLAGS) | RD4(dst) | RM4(reg) | IMM5(imm));
655 return push_inst16(compiler, LSRSI | RD3(dst) | RN3(reg) | (imm << 6));
656 return push_inst32(compiler, LSR_WI | (flags & SET_FLAGS) | RD4(dst) | RM4(reg) | IMM5(imm));
659 return push_inst16(compiler, ASRSI | RD3(dst) | RN3(reg) | (imm << 6));
660 return push_inst32(compiler, ASR_WI | (flags & SET_FLAGS) | RD4(dst) | RM4(reg) | IMM5(imm));
668 FAIL_IF(load_immediate(compiler, TMP_REG2, arg2));
672 FAIL_IF(load_immediate(compiler, TMP_REG1, arg1));
690 return push_inst16(compiler, MOV | SET_REGS44(dst, arg2));
695 return push_inst16(compiler, UXTB | RD3(dst) | RN3(arg2));
696 return push_inst32(compiler, UXTB_W | RD4(dst) | RM4(arg2));
701 return push_inst16(compiler, SXTB | RD3(dst) | RN3(arg2));
702 return push_inst32(compiler, SXTB_W | RD4(dst) | RM4(arg2));
707 return push_inst16(compiler, UXTH | RD3(dst) | RN3(arg2));
708 return push_inst32(compiler, UXTH_W | RD4(dst) | RM4(arg2));
713 return push_inst16(compiler, SXTH | RD3(dst) | RN3(arg2));
714 return push_inst32(compiler, SXTH_W | RD4(dst) | RM4(arg2));
718 return push_inst16(compiler, MVNS | RD3(dst) | RN3(arg2));
719 return push_inst32(compiler, MVN_W | (flags & SET_FLAGS) | RD4(dst) | RM4(arg2));
722 FAIL_IF(push_inst32(compiler, CLZ | RN4(arg2) | RD4(dst) | RM4(arg2)));
725 return push_inst16(compiler, CMPI | RDN3(dst));
726 return push_inst32(compiler, ADD_WI | SET_FLAGS | RN4(dst) | RD4(dst));
731 return push_inst16(compiler, ADDS | RD3(dst) | RN3(arg1) | RM3(arg2));
733 return push_inst16(compiler, ADD | SET_REGS44(dst, arg2));
734 return push_inst32(compiler, ADD_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
737 return push_inst16(compiler, ADCS | RD3(dst) | RN3(arg2));
738 return push_inst32(compiler, ADC_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
741 return push_inst16(compiler, SUBS | RD3(dst) | RN3(arg1) | RM3(arg2));
742 return push_inst32(compiler, SUB_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
745 return push_inst16(compiler, SBCS | RD3(dst) | RN3(arg2));
746 return push_inst32(compiler, SBC_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
749 return push_inst32(compiler, MUL | RD4(dst) | RN4(arg1) | RM4(arg2));
751 FAIL_IF(push_inst32(compiler, SMULL | RT4(dst) | RD4(TMP_REG2) | RN4(arg1) | RM4(arg2)));
753 return push_inst32(compiler, CMP_W | RN4(TMP_REG2) | 0x70e0 | RM4(dst));
757 return push_inst16(compiler, ANDS | RD3(dst) | RN3(arg2));
759 return push_inst16(compiler, TST | RD3(arg1) | RN3(arg2));
761 return push_inst32(compiler, AND_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
764 return push_inst16(compiler, ORRS | RD3(dst) | RN3(arg2));
765 return push_inst32(compiler, ORR_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
768 return push_inst16(compiler, EORS | RD3(dst) | RN3(arg2));
769 return push_inst32(compiler, EOR_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
772 return push_inst16(compiler, LSLS | RD3(dst) | RN3(arg2));
773 return push_inst32(compiler, LSL_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
776 return push_inst16(compiler, LSRS | RD3(dst) | RN3(arg2));
777 return push_inst32(compiler, LSR_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
780 return push_inst16(compiler, ASRS | RD3(dst) | RN3(arg2));
781 return push_inst32(compiler, ASR_W | (flags & SET_FLAGS) | RD4(dst) | RN4(arg1) | RM4(arg2));
870 static sljit_s32 emit_set_delta(struct sljit_compiler *compiler, sljit_s32 dst, sljit_s32 reg, sljit_sw value)
874 return push_inst32(compiler, ADDWI | RD4(dst) | RN4(reg) | IMM12(value));
877 return push_inst32(compiler, ADD_WI | RD4(dst) | RN4(reg) | value);
882 return push_inst32(compiler, SUBWI | RD4(dst) | RN4(reg) | IMM12(value));
885 return push_inst32(compiler, SUB_WI | RD4(dst) | RN4(reg) | value);
891 static sljit_s32 getput_arg_fast(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw)
911 FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | MEM_IMM8 | RT4(reg) | RN4(arg) | 0x100 | argw));
926 FAIL_IF(push_inst16(compiler, sljit_mem16[flags] | RD3(reg) | RN3(arg) | RM3(other_r)));
928 FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(other_r) | (argw << 4)));
957 FAIL_IF(push_inst16(compiler, sljit_mem16_imm5[flags] | RD3(reg) | RN3(arg) | (argw << (6 - shift))));
964 FAIL_IF(push_inst16(compiler, STR_SP | ((flags & STORE) ? 0 : 0x800) | RDN3(reg) | (argw >> 2)));
969 FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(arg) | argw));
971 FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | MEM_IMM8 | RT4(reg) | RN4(arg) | -argw));
1002 static sljit_s32 getput_arg(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg,
1025 FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(arg) | argw));
1026 return push_inst32(compiler, ADDWI | RD4(arg) | RN4(arg) | IMM12(argw));
1029 if (compiler->cache_arg == SLJIT_MEM) {
1030 if (argw == compiler
1034 else if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) {
1035 FAIL_IF(compiler->error);
1036 compiler->cache_argw = argw;
1043 FAIL_IF(load_immediate(compiler, TMP_REG3, argw));
1044 compiler->cache_arg = SLJIT_MEM;
1045 compiler->cache_argw = argw;
1053 FAIL_IF(push_inst16(compiler, sljit_mem16[flags] | RD3(reg) | RN3(arg) | RM3(other_r)));
1054 return push_inst16(compiler, ADD | SET_REGS44(arg, other_r));
1056 FAIL_IF(push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(other_r) | (argw << 4)));
1057 return push_inst32(compiler, ADD_W | RD4(arg) | RN4(arg) | RM4(other_r) | (argw << 6));
1063 if (compiler->cache_arg == arg) {
1064 diff = argw - compiler->cache_argw;
1066 return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(TMP_REG3) | diff);
1067 if (!((compiler->cache_argw - argw) & ~0xff))
1068 return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM8 | RT4(reg) | RN4(TMP_REG3) | (compiler->cache_argw - argw));
1069 if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, diff) != SLJIT_ERR_UNSUPPORTED) {
1070 FAIL_IF(compiler->error);
1071 return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(TMP_REG3) | 0);
1077 if (arg && compiler->cache_arg == SLJIT_MEM) {
1078 if (compiler->cache_argw == argw)
1079 return push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(TMP_REG3));
1080 if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, argw - compiler->cache_argw) != SLJIT_ERR_UNSUPPORTED) {
1081 FAIL_IF(compiler->error);
1082 compiler->cache_argw = argw;
1083 return push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(TMP_REG3));
1087 compiler->cache_argw = argw;
1088 if (next_arg && emit_set_delta(compiler, TMP_REG3, arg, argw) != SLJIT_ERR_UNSUPPORTED) {
1089 FAIL_IF(compiler->error);
1090 compiler->cache_arg = SLJIT_MEM | arg;
1094 FAIL_IF(load_immediate(compiler, TMP_REG3, argw));
1095 compiler->cache_arg = SLJIT_MEM;
1099 FAIL_IF(push_inst16(compiler, ADD | SET_REGS44(TMP_REG3, arg)));
1100 compiler->cache_arg = SLJIT_MEM | arg;
1106 return push_inst32(compiler, sljit_mem32[flags] | RT4(reg) | RN4(arg) | RM4(TMP_REG3));
1107 return push_inst32(compiler, sljit_mem32[flags] | MEM_IMM12 | RT4(reg) | RN4(TMP_REG3) | 0);
1110 static SLJIT_INLINE sljit_s32 emit_op_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw)
1112 if (getput_arg_fast(compiler, flags, reg, arg, argw))
1113 return compiler->error;
1114 compiler->cache_arg = 0;
1115 compiler->cache_argw = 0;
1116 return getput_arg(compiler, flags, reg, arg, argw, 0, 0);
1119 static SLJIT_INLINE sljit_s32 emit_op_mem2(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg1, sljit_sw arg1w, sljit_s32 arg2, sljit_sw arg2w)
1121 if (getput_arg_fast(compiler, flags, reg, arg1, arg1w))
1122 return compiler->error;
1123 return getput_arg(compiler, flags, reg, arg1, arg1w, arg2, arg2w);
1130 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_enter(struct sljit_compiler *compiler,
1138 CHECK(check_sljit_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size));
1139 set_emit_enter(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size);
1151 ? push_inst32(compiler, PUSH_W | (1 << 14) | push)
1152 : push_inst16(compiler, PUSH | (1 << 8) | push));
1157 compiler->local_size = local_size;
1160 FAIL_IF(push_inst16(compiler, SUB_SP | (local_size >> 2)));
1162 FAIL_IF(emit_op_imm(compiler, SLJIT_SUB | ARG2_IMM, SLJIT_SP, SLJIT_SP, local_size));
1166 FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_S0, SLJIT_R0)));
1168 FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_S1, SLJIT_R1)));
1170 FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(SLJIT_S2, SLJIT_R2)));
1175 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_set_context(struct sljit_compiler *compiler,
1182 CHECK(check_sljit_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size));
1183 set_set_context(compiler, options, args, scratches, saveds, fscratches, fsaveds, local_size);
1186 compiler->local_size = ((size + local_size + 7) & ~7) - size;
1190 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_return(struct sljit_compiler *compiler, sljit_s32 op, sljit_s32 src, sljit_sw srcw)
1196 CHECK(check_sljit_emit_return(compiler, op, src, srcw));
1198 FAIL_IF(emit_mov_before_return(compiler, op, src, srcw));
1200 if (compiler->local_size > 0) {
1201 if (compiler->local_size <= (127 << 2))
1202 FAIL_IF(push_inst16(compiler, ADD_SP | (compiler->local_size >> 2)));
1204 FAIL_IF(emit_op_imm(compiler, SLJIT_ADD | ARG2_IMM, SLJIT_SP, SLJIT_SP, compiler->local_size));
1209 tmp = compiler->saveds < SLJIT_NUMBER_OF_SAVED_REGISTERS ? (SLJIT_S0 + 1 - compiler->saveds) : SLJIT_FIRST_SAVED_REG;
1213 for (i = compiler->scratches; i >= SLJIT_FIRST_SAVED_REG; i--)
1217 ? push_inst32(compiler, POP_W | (1 << 15) | pop)
1218 : push_inst16(compiler, POP | (1 << 8) | pop);
1240 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
1246 CHECK(check_sljit_emit_op0(compiler, op));
1251 return push_inst16(compiler, BKPT);
1253 return push_inst16(compiler, NOP);
1256 return push_inst32(compiler, (op == SLJIT_LMUL_UW ? UMULL : SMULL)
1269 if (compiler->scratches >= 4)
1271 if (compiler->scratches >= 3)
1277 FAIL_IF(push_inst32(compiler, 0xf84d0d00 | (saved_reg_count >= 3 ? 16 : 8)
1281 FAIL_IF(push_inst16(compiler, 0x9001 | (saved_reg_list[1] << 8) /* str rX, [sp, #4] */));
1285 FAIL_IF(push_inst16(compiler, 0x9002 | (saved_reg_list[2] << 8) /* str rX, [sp, #8] */));
1290 FAIL_IF(sljit_emit_ijump(compiler, SLJIT_FAST_CALL, SLJIT_IMM,
1299 FAIL_IF(push_inst16(compiler, 0x9802 | (saved_reg_list[2] << 8) /* ldr rX, [sp, #8] */));
1303 FAIL_IF(push_inst16(compiler, 0x9801 | (saved_reg_list[1] << 8) /* ldr rX, [sp, #4] */));
1305 return push_inst32(compiler, 0xf85d0b00 | (saved_reg_count >= 3 ? 16 : 8)
1314 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1322 CHECK(check_sljit_emit_op1(compiler, op, dst, dstw, src, srcw));
1326 compiler->cache_arg = 0;
1327 compiler->cache_argw = 0;
1393 FAIL_IF(emit_op_imm(compiler, SLJIT_MOV | ARG2_IMM, dst_r, TMP_REG1, srcw));
1395 if (getput_arg_fast(compiler, flags, dst_r, src, srcw))
1396 FAIL_IF(compiler->error);
1398 FAIL_IF(getput_arg(compiler, flags, dst_r, src, srcw, dst, dstw));
1401 return emit_op_imm(compiler, op, dst_r, TMP_REG1, src);
1406 if (getput_arg_fast(compiler, flags | STORE, dst_r, dst, dstw))
1407 return compiler->error;
1409 return getput_arg(compiler, flags | STORE, dst_r, dst, dstw, 0, 0);
1417 compiler->skip_checks = 1;
1419 return sljit_emit_op2(compiler, SLJIT_SUB | op_flags, dst, dstw, SLJIT_IMM, 0, src, srcw);
1424 if (getput_arg_fast(compiler, WORD_SIZE, TMP_REG2, src, srcw))
1425 FAIL_IF(compiler->error);
1427 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG2, src, srcw, dst, dstw));
1436 emit_op_imm(compiler, flags | op, dst_r, TMP_REG1, srcw);
1439 if (getput_arg_fast(compiler, flags | STORE, dst_r, dst, dstw))
1440 return compiler->error;
1442 return getput_arg(compiler, flags | STORE, dst_r, dst, dstw, 0, 0);
1447 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
1455 CHECK(check_sljit_emit_op2(compiler, op, dst, dstw, src1, src1w, src2, src2w));
1460 compiler->cache_arg = 0;
1461 compiler->cache_argw = 0;
1466 if ((dst & SLJIT_MEM) && !getput_arg_fast(compiler, WORD_SIZE | STORE | ARG_TEST, TMP_REG1, dst, dstw))
1470 if (getput_arg_fast(compiler, WORD_SIZE, TMP_REG1, src1, src1w))
1471 FAIL_IF(compiler->error);
1476 if (getput_arg_fast(compiler, WORD_SIZE, TMP_REG2, src2, src2w))
1477 FAIL_IF(compiler->error);
1484 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG2, src2, src2w, src1, src1w));
1485 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG1, src1, src1w, dst, dstw));
1488 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG1, src1, src1w, src2, src2w));
1489 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG2, src2, src2w, dst, dstw));
1493 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG1, src1, src1w, dst, dstw));
1495 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG2, src2, src2w, dst, dstw));
1514 emit_op_imm(compiler, flags | GET_OPCODE(op), dst_r, src1w, src2w);
1518 getput_arg_fast(compiler, WORD_SIZE | STORE, dst_r, dst, dstw);
1519 return compiler->error;
1521 return getput_arg(compiler, WORD_SIZE | STORE, TMP_REG1, dst, dstw, 0, 0);
1538 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
1542 CHECK(check_sljit_emit_op_custom(compiler, instruction, size));
1545 return push_inst16(compiler, *(sljit_u16*)instruction);
1546 return push_inst32(compiler, *(sljit_ins*)instruction);
1565 static sljit_s32 emit_fop_mem(struct sljit_compiler *compiler, sljit_s32 flags, sljit_s32 reg, sljit_s32 arg, sljit_sw argw)
1575 FAIL_IF(push_inst32(compiler, ADD_W | RD4(TMP_REG2) | RN4(arg & REG_MASK) | RM4(OFFS_REG(arg)) | ((argw & 0x3) << 6)));
1582 return push_inst32(compiler, inst | 0x800000 | RN4(arg & REG_MASK) | DD4(reg) | (argw >> 2));
1584 return push_inst32(compiler, inst | RN4(arg & REG_MASK) | DD4(reg) | (-argw >> 2));
1589 if (compiler->cache_arg == arg) {
1590 tmp = argw - compiler->cache_argw;
1592 return push_inst32(compiler, inst | 0x800000 | RN4(TMP_REG3) | DD4(reg) | (tmp >> 2));
1594 return push_inst32(compiler, inst | RN4(TMP_REG3) | DD4(reg) | (-tmp >> 2));
1595 if (emit_set_delta(compiler, TMP_REG3, TMP_REG3, tmp) != SLJIT_ERR_UNSUPPORTED) {
1596 FAIL_IF(compiler->error);
1597 compiler->cache_argw = argw;
1598 return push_inst32(compiler, inst | 0x800000 | RN4(TMP_REG3) | DD4(reg));
1603 if (emit_set_delta(compiler, TMP_REG1, arg & REG_MASK, argw) != SLJIT_ERR_UNSUPPORTED) {
1604 FAIL_IF(compiler->error);
1605 return push_inst32(compiler, inst | 0x800000 | RN4(TMP_REG1) | DD4(reg));
1609 FAIL_IF(push_inst32(compiler, ADD_WI | RD4(TMP_REG1) | RN4(arg & REG_MASK) | imm));
1610 return push_inst32(compiler, inst | 0x800000 | RN4(TMP_REG1) | DD4(reg) | ((argw & 0x3fc) >> 2));
1615 FAIL_IF(push_inst32(compiler, SUB_WI | RD4(TMP_REG1) | RN4(arg & REG_MASK) | imm));
1616 return push_inst32(compiler, inst | RN4(TMP_REG1) | DD4(reg) | ((argw & 0x3fc) >> 2));
1620 compiler->cache_arg = arg;
1621 compiler->cache_argw = argw;
1623 FAIL_IF(load_immediate(compiler, TMP_REG3, argw));
1625 FAIL_IF(push_inst16(compiler, ADD | SET_REGS44(TMP_REG3, (arg & REG_MASK))));
1626 return push_inst32(compiler, inst | 0x800000 | RN4(TMP_REG3) | DD4(reg));
1629 static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
1634 FAIL_IF(emit_fop_mem(compiler, (op & SLJIT_F32_OP) | FPU_LOAD, TMP_FREG1, src, srcw));
1638 FAIL_IF(push_inst32(compiler, VCVT_S32_F32 | (op & SLJIT_F32_OP) | DD4(TMP_FREG1) | DM4(src)));
1644 return push_inst32(compiler, VMOV | (1 << 20) | RT4(dst) | DN4(TMP_FREG1));
1647 return emit_fop_mem(compiler, 0, TMP_FREG1, dst, dstw);
1650 static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
1657 FAIL_IF(push_inst32(compiler, VMOV | RT4(src) | DN4(TMP_FREG1)));
1660 FAIL_IF(emit_fop_mem(compiler, FPU_LOAD, TMP_FREG1, src, srcw));
1663 FAIL_IF(load_immediate(compiler, TMP_REG1, srcw));
1664 FAIL_IF(push_inst32(compiler, VMOV | RT4(TMP_REG1) | DN4(TMP_FREG1)));
1667 FAIL_IF(push_inst32(compiler, VCVT_F32_S32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DM4(TMP_FREG1)));
1670 return emit_fop_mem(compiler, (op & SLJIT_F32_OP), TMP_FREG1, dst, dstw);
1674 static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
1679 emit_fop_mem(compiler, (op & SLJIT_F32_OP) | FPU_LOAD, TMP_FREG1, src1, src1w);
1684 emit_fop_mem(compiler, (op & SLJIT_F32_OP) | FPU_LOAD, TMP_FREG2, src2, src2w);
1688 FAIL_IF(push_inst32(compiler, VCMP_F32 | (op & SLJIT_F32_OP) | DD4(src1) | DM4(src2)));
1689 return push_inst32(compiler, VMRS);
1692 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
1699 compiler->cache_arg = 0;
1700 compiler->cache_argw = 0;
1705 SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw);
1710 emit_fop_mem(compiler, (op & SLJIT_F32_OP) | FPU_LOAD, dst_r, src, srcw);
1718 FAIL_IF(push_inst32(compiler, VMOV_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DM4(src)));
1724 FAIL_IF(push_inst32(compiler, VNEG_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DM4(src)));
1727 FAIL_IF(push_inst32(compiler, VABS_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DM4(src)));
1730 FAIL_IF(push_inst32(compiler, VCVT_F64_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DM4(src)));
1736 return emit_fop_mem(compiler, (op & SLJIT_F32_OP), dst_r, dst, dstw);
1740 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
1748 CHECK(check_sljit_emit_fop2(compiler, op, dst, dstw, src1, src1w, src2, src2w));
1753 compiler->cache_arg = 0;
1754 compiler->cache_argw = 0;
1759 emit_fop_mem(compiler, (op & SLJIT_F32_OP) | FPU_LOAD, TMP_FREG1, src1, src1w);
1763 emit_fop_mem(compiler, (op & SLJIT_F32_OP) | FPU_LOAD, TMP_FREG2, src2, src2w);
1769 FAIL_IF(push_inst32(compiler, VADD_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DN4(src1) | DM4(src2)));
1772 FAIL_IF(push_inst32(compiler, VSUB_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DN4(src1) | DM4(src2)));
1775 FAIL_IF(push_inst32(compiler, VMUL_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DN4(src1) | DM4(src2)));
1778 FAIL_IF(push_inst32(compiler, VDIV_F32 | (op & SLJIT_F32_OP) | DD4(dst_r) | DN4(src1) | DM4(src2)));
1784 return emit_fop_mem(compiler, (op & SLJIT_F32_OP), TMP_FREG1, dst, dstw);
1793 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_enter(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw)
1796 CHECK(check_sljit_emit_fast_enter(compiler, dst, dstw));
1804 return push_inst16(compiler, MOV | SET_REGS44(dst, TMP_REG3));
1807 if (getput_arg_fast(compiler, WORD_SIZE | STORE, TMP_REG3, dst, dstw))
1808 return compiler->error;
1810 FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG2, TMP_REG3)));
1811 compiler->cache_arg = 0;
1812 compiler->cache_argw = 0;
1813 return getput_arg(compiler, WORD_SIZE | STORE, TMP_REG2, dst, dstw, 0, 0);
1816 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fast_return(struct sljit_compiler *compiler, sljit_s32 src, sljit_sw srcw)
1819 CHECK(check_sljit_emit_fast_return(compiler, src, srcw));
1823 FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG3, src)));
1825 if (getput_arg_fast(compiler, WORD_SIZE, TMP_REG3, src, srcw))
1826 FAIL_IF(compiler->error);
1828 compiler->cache_arg = 0;
1829 compiler->cache_argw = 0;
1830 FAIL_IF(getput_arg(compiler, WORD_SIZE, TMP_REG2, src, srcw, 0, 0));
1831 FAIL_IF(push_inst16(compiler, MOV | SET_REGS44(TMP_REG3, TMP_REG2)));
1835 FAIL_IF(load_immediate(compiler, TMP_REG3, srcw));
1836 return push_inst16(compiler, BLX | RN3(TMP_REG3));
1898 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
1903 CHECK_PTR(check_sljit_emit_label(compiler));
1905 if (compiler->last_label && compiler->last_label->size == compiler->size)
1906 return compiler->last_label;
1908 label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label));
1910 set_label(label, compiler);
1914 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
1920 CHECK_PTR(check_sljit_emit_jump(compiler, type));
1922 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1924 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
1928 PTR_FAIL_IF(emit_imm32_const(compiler, TMP_REG1, 0));
1933 PTR_FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8));
1936 jump->addr = compiler->size;
1938 PTR_FAIL_IF(push_inst16(compiler, BX | RN3(TMP_REG1)));
1941 PTR_FAIL_IF(push_inst16(compiler, BLX | RN3(TMP_REG1)));
1947 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
1952 CHECK(check_sljit_emit_ijump(compiler, type, src, srcw));
1958 return push_inst16(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RN3(src));
1960 FAIL_IF(emit_op_mem(compiler, WORD_SIZE, type <= SLJIT_JUMP ? TMP_PC : TMP_REG1, src, srcw));
1962 return push_inst16(compiler, BLX | RN3(TMP_REG1));
1965 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
1967 set_jump(jump, compiler, JUMP_ADDR | ((type >= SLJIT_FAST_CALL) ? IS_BL : 0));
1970 FAIL_IF(emit_imm32_const(compiler, TMP_REG1, 0));
1971 jump->addr = compiler->size;
1972 return push_inst16(compiler, (type <= SLJIT_JUMP ? BX : BLX) | RN3(TMP_REG1));
1975 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
1984 CHECK(check_sljit_emit_op_flags(compiler, op, dst, dstw, src, srcw, type));
1996 FAIL_IF(push_inst16(compiler, IT | (cc << 4) | (((cc & 0x1) ^ 0x1) << 3) | 0x4));
1998 FAIL_IF(push_inst32(compiler, MOV_WI | RD4(dst_r) | 1));
1999 FAIL_IF(push_inst32(compiler, MOV_WI | RD4(dst_r) | 0));
2001 FAIL_IF(push_inst16(compiler, MOVSI | RDN3(dst_r) | 1));
2002 FAIL_IF(push_inst16(compiler, MOVSI | RDN3(dst_r) | 0));
2006 return emit_op_mem(compiler, WORD_SIZE | STORE, TMP_REG2, dst, dstw);
2012 FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8));
2013 FAIL_IF(push_inst32(compiler, ins | RN4(src) | RD4(dst) | 1));
2017 return push_inst16(compiler, MOVS | RD3(TMP_REG1) | RN3(dst));
2018 return push_inst32(compiler, MOV_W | SET_FLAGS | RD4(TMP_REG1) | RM4(dst));
2023 compiler->cache_arg = 0;
2024 compiler->cache_argw = 0;
2026 FAIL_IF(emit_op_mem2(compiler, WORD_SIZE, TMP_REG2, src, srcw, dst, dstw));
2030 FAIL_IF(load_immediate(compiler, TMP_REG2, srcw));
2036 FAIL_IF(push_inst16(compiler, IT | (cc << 4) | (((cc & 0x1) ^ 0x1) << 3) | 0x4));
2037 FAIL_IF(push_inst32(compiler, ins | RN4(src) | RD4(dst_r) | 1));
2038 FAIL_IF(push_inst32(compiler, ins | RN4(src) | RD4(dst_r) | 0));
2041 FAIL_IF(push_inst16(compiler, IT | (cc << 4) | 0x8));
2042 FAIL_IF(push_inst32(compiler, ins | RN4(src) | RD4(dst_r) | 1));
2046 FAIL_IF(emit_op_mem2(compiler, WORD_SIZE | STORE, TMP_REG2, dst, dstw, 0, 0));
2051 return push_inst16(compiler, MOVS | RD3(TMP_REG1) | RN3(dst_r));
2052 return push_inst32(compiler, MOV_W | SET_FLAGS | RD4(TMP_REG1) | RM4(dst_r));
2057 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
2063 CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value));
2066 const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const));
2068 set_const(const_, compiler);
2071 PTR_FAIL_IF(emit_imm32_const(compiler, dst_r, init_value));
2074 PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw));