Home | History | Annotate | Download | only in sljit_src

Lines Matching refs:compiler

4  *    Stack-less Just-In-Time compiler
77 if (p <= compiler->scratches) \
78 w = compiler->saveds_offset - ((p) - SLJIT_R2) * (sljit_sw)sizeof(sljit_sw); \
80 w = compiler->locals_offset + ((p) - SLJIT_S2) * (sljit_sw)sizeof(sljit_sw); \
264 #define INC_SIZE(s) (*inst++ = (s), compiler->size += (s))
477 SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler)
493 CHECK_PTR(check_sljit_generate_code(compiler));
494 reverse_buf(compiler);
497 code = (sljit_u8*)SLJIT_MALLOC_EXEC(compiler->size);
499 buf = compiler->buf;
502 label = compiler->labels;
503 jump = compiler->jumps;
504 const_ = compiler->consts;
552 jump = compiler->jumps;
586 SLJIT_ASSERT(code_ptr <= code + compiler->size);
587 compiler->error = SLJIT_ERR_COMPILED;
588 compiler->executable_offset = executable_offset;
589 compiler->executable_size = code_ptr - code;
597 static sljit_s32 emit_cum_binary(struct sljit_compiler *compiler,
603 static sljit_s32 emit_non_cum_binary(struct sljit_compiler *compiler,
609 static sljit_s32 emit_mov(struct sljit_compiler *compiler,
613 #define EMIT_MOV(compiler, dst, dstw, src, srcw) \
614 FAIL_IF(emit_mov(compiler, dst, dstw, src, srcw));
639 static sljit_s32 emit_mov(struct sljit_compiler *compiler,
648 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src, srcw);
655 inst = emit_x86_instruction(compiler, 1, src, 0, dst, dstw);
663 return emit_do_imm(compiler, MOV_r_i32 + reg_map[dst], srcw);
665 if (!compiler->mode32) {
667 return emit_load_imm64(compiler, dst, srcw);
670 return emit_do_imm32(compiler, (reg_map[dst] >= 8) ? REX_B : 0, MOV_r_i32 + reg_lmap[dst], srcw);
674 if (!compiler->mode32 && NOT_HALFWORD(srcw)) {
675 FAIL_IF(emit_load_imm64(compiler, TMP_REG2, srcw));
676 inst = emit_x86_instruction(compiler, 1, TMP_REG2, 0, dst, dstw);
682 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, srcw, dst, dstw);
688 inst = emit_x86_instruction(compiler, 1, dst, 0, src, srcw);
695 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src, srcw);
698 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, dst, dstw);
704 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op0(struct sljit_compiler *compiler, sljit_s32 op)
712 CHECK(check_sljit_emit_op0(compiler, op));
716 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1);
722 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1);
745 compiler->mode32 = op & SLJIT_I32_OP;
752 EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_R1, 0);
753 inst = emit_x86_instruction(compiler, 1, SLJIT_R1, 0, SLJIT_R1, 0);
755 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, TMP_REG1, 0);
763 EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_R1, 0);
767 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1);
772 if (compiler->mode32) {
773 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1);
778 inst = (sljit_u8*)ensure_buf(compiler, 1 + 2);
788 inst = (sljit_u8*)ensure_buf(compiler, 1 + 2);
795 size = (!compiler->mode32 || op >= SLJIT_DIVMOD_UW) ? 3 : 2;
797 size = (!compiler->mode32) ? 3 : 2;
799 inst = (sljit_u8*)ensure_buf(compiler, 1 + size);
803 if (!compiler->mode32)
810 if (!compiler->mode32)
834 EMIT_MOV(compiler, SLJIT_R1, 0, TMP_REG1, 0);
837 EMIT_MOV(compiler, SLJIT_R1, 0, TMP_REG1, 0);
847 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1); \
853 static sljit_s32 emit_mov_byte(struct sljit_compiler *compiler, sljit_s32 sign,
864 compiler->mode32 = 0;
873 return emit_do_imm(compiler, MOV_r_i32 + reg_map[dst], srcw);
875 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, srcw, dst, 0);
881 inst = emit_x86_instruction(compiler, 1 | EX86_BYTE_ARG | EX86_NO_REXW, SLJIT_IMM, srcw, dst, dstw);
893 EMIT_MOV(compiler, TMP_REG1, 0, src, 0);
906 EMIT_MOV(compiler, dst, 0, src, 0);
907 inst = emit_x86_instruction(compiler, 2, dst, 0, dst, 0);
914 EMIT_MOV(compiler, dst, 0, src, 0);
917 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, 24, dst, 0);
921 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, 24, dst, 0);
926 inst = emit_x86_instruction(compiler, 1 | EX86_BIN_INS, SLJIT_IMM, 0xff, dst, 0);
936 inst = emit_x86_instruction(compiler, 2, dst_r, 0, src, srcw);
965 inst = emit_x86_instruction(compiler, 1, work_r, 0, dst_r, 0);
970 inst = emit_x86_instruction(compiler, 1, work_r, 0, dst, dstw);
978 inst = emit_x86_instruction(compiler, 1, work_r, 0, dst_r, 0);
984 inst = emit_x86_instruction(compiler, 1, dst_r, 0, dst, dstw);
989 inst = emit_x86_instruction(compiler, 1 | EX86_REX | EX86_NO_REXW, dst_r, 0, dst, dstw);
998 static sljit_s32 emit_mov_half(struct sljit_compiler *compiler, sljit_s32 sign,
1006 compiler->mode32 = 0;
1015 return emit_do_imm(compiler, MOV_r_i32 + reg_map[dst], srcw);
1017 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, srcw, dst, 0);
1023 inst = emit_x86_instruction(compiler, 1 | EX86_HALF_ARG | EX86_NO_REXW | EX86_PREF_66, SLJIT_IMM, srcw, dst, dstw);
1034 inst = emit_x86_instruction(compiler, 2, dst_r, 0, src, srcw);
1041 inst = emit_x86_instruction(compiler, 1 | EX86_NO_REXW | EX86_PREF_66, dst_r, 0, dst, dstw);
1049 static sljit_s32 emit_unary(struct sljit_compiler *compiler, sljit_u8 opcode,
1056 EMIT_MOV(compiler, TMP_REG1, 0, src, srcw);
1057 inst = emit_x86_instruction(compiler, 1, 0, 0, TMP_REG1, 0);
1065 inst = emit_x86_instruction(compiler, 1, 0, 0, dst, dstw);
1072 EMIT_MOV(compiler, dst, 0, src, srcw);
1073 inst = emit_x86_instruction(compiler, 1, 0, 0, dst, dstw);
1079 EMIT_MOV(compiler, TMP_REG1, 0, src, srcw);
1080 inst = emit_x86_instruction(compiler, 1, 0, 0, TMP_REG1, 0);
1084 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
1088 static sljit_s32 emit_not_with_flags(struct sljit_compiler *compiler,
1095 EMIT_MOV(compiler, TMP_REG1, 0, src, srcw);
1096 inst = emit_x86_instruction(compiler, 1, 0, 0, TMP_REG1, 0);
1100 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, TMP_REG1, 0);
1106 EMIT_MOV(compiler, dst, 0, src, srcw);
1107 inst = emit_x86_instruction(compiler, 1, 0, 0, dst, dstw);
1111 inst = emit_x86_instruction(compiler, 1, dst, 0, dst, 0);
1116 EMIT_MOV(compiler, TMP_REG1, 0, src, srcw);
1117 inst = emit_x86_instruction(compiler, 1, 0, 0, TMP_REG1, 0);
1121 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, TMP_REG1, 0);
1124 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
1128 static sljit_s32 emit_clz(struct sljit_compiler *compiler, sljit_s32 op_flags,
1138 EMIT_MOV(compiler, TMP_REG1, 0, src, srcw);
1139 inst = emit_x86_instruction(compiler, 1, 0, 0, TMP_REG1, 0);
1144 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, 31, TMP_REG1, 0);
1146 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_IMM, !(op_flags & SLJIT_I32_OP) ? 63 : 31, TMP_REG1, 0);
1154 EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_IMM, srcw);
1159 inst = emit_x86_instruction(compiler, 2, TMP_REG1, 0, src, srcw);
1175 EMIT_MOV(compiler, dst, dstw, dst_r, 0);
1177 EMIT_MOV(compiler, dst_r, 0, SLJIT_IMM, 32 + 31);
1180 compiler->mode32 = 0;
1181 EMIT_MOV(compiler, dst_r, 0, SLJIT_IMM, !(op_flags & SLJIT_I32_OP) ? 64 + 63 : 32 + 31);
1182 compiler->mode32 = op_flags & SLJIT_I32_OP;
1189 inst = emit_x86_instruction(compiler, 2, dst_r, 0, TMP_REG1, 0);
1195 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4);
1204 inst = (sljit_u8*)ensure_buf(compiler, 1 + 5);
1217 inst = emit_x86_instruction(compiler, 1 | EX86_BIN_INS, SLJIT_IMM, 31, dst_r, 0);
1219 inst = emit_x86_instruction(compiler, 1 | EX86_BIN_INS, SLJIT_IMM, !(op_flags & SLJIT_I32_OP) ? 63 : 31, dst_r, 0);
1226 inst = emit_x86_instruction(compiler, 1, dst_r, 0, dst, dstw);
1232 EMIT_MOV(compiler, dst, dstw, TMP_REG2, 0);
1237 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op1(struct sljit_compiler *compiler, sljit_s32 op,
1251 CHECK(check_sljit_emit_op1(compiler, op, dst, dstw, src, srcw));
1258 compiler->mode32 = op_flags & SLJIT_I32_OP;
1264 compiler->mode32 = 0;
1315 return emit_mov(compiler, dst, dstw, src, srcw);
1333 FAIL_IF(emit_mov(compiler, dst, dstw, src, srcw));
1336 FAIL_IF(emit_mov_byte(compiler, 0, dst, dstw, src, srcw));
1339 FAIL_IF(emit_mov_byte(compiler, 1, dst, dstw, src, srcw));
1342 FAIL_IF(emit_mov_half(compiler, 0, dst, dstw, src, srcw));
1345 FAIL_IF(emit_mov_half(compiler, 1, dst, dstw, src, srcw));
1349 FAIL_IF(emit_mov_int(compiler, 0, dst, dstw, src, srcw));
1352 FAIL_IF(emit_mov_int(compiler, 1, dst, dstw, src, srcw));
1359 return emit_mov(compiler, SLJIT_MEM1(SLJIT_SP), dstw, TMP_REG1, 0);
1364 FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32,
1368 FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32,
1375 FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32,
1379 FAIL_IF(emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32,
1389 return emit_not_with_flags(compiler, dst, dstw, src, srcw);
1390 return emit_unary(compiler, NOT_rm, dst, dstw, src, srcw);
1393 return emit_unary(compiler, NEG_rm, dst, dstw, src, srcw);
1396 return emit_clz(compiler, op_flags, dst, dstw, src, srcw);
1409 if (IS_HALFWORD(immw) || compiler->mode32) { \
1410 inst = emit_x86_instruction(compiler, 1 | EX86_BIN_INS, SLJIT_IMM, immw, arg, argw); \
1415 FAIL_IF(emit_load_imm64(compiler, TMP_REG2, immw)); \
1416 inst = emit_x86_instruction(compiler, 1, TMP_REG2, 0, arg, argw); \
1422 FAIL_IF(emit_do_imm32(compiler, (!compiler->mode32) ? REX_W : 0, (op_eax_imm), immw))
1427 inst = emit_x86_instruction(compiler, 1 | EX86_BIN_INS, SLJIT_IMM, immw, arg, argw); \
1432 FAIL_IF(emit_do_imm(compiler, (op_eax_imm), immw))
1436 static sljit_s32 emit_cum_binary(struct sljit_compiler *compiler,
1445 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1450 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src2, src2w);
1460 if ((dst == SLJIT_R0) && (src2w > 127 || src2w < -128) && (compiler->mode32 || IS_HALFWORD(src2w))) {
1471 inst = emit_x86_instruction(compiler, 1, dst, dstw, src2, src2w);
1477 inst = emit_x86_instruction(compiler, 1, src2, src2w, dst, dstw);
1482 EMIT_MOV(compiler, TMP_REG1, 0, src2, src2w);
1483 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, dst, dstw);
1494 if ((dst == SLJIT_R0) && (src1w > 127 || src1w < -128) && (compiler->mode32 || IS_HALFWORD(src1w))) {
1505 inst = emit_x86_instruction(compiler, 1, dst, dstw, src1, src1w);
1510 inst = emit_x86_instruction(compiler, 1, src1, src1w, dst, dstw);
1515 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1516 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, dst, dstw);
1525 EMIT_MOV(compiler, dst, 0, src1, src1w);
1530 inst = emit_x86_instruction(compiler, 1, dst, 0, src2, src2w);
1537 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1542 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src2, src2w);
1546 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
1552 static sljit_s32 emit_non_cum_binary(struct sljit_compiler *compiler,
1561 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1566 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src2, src2w);
1576 if ((dst == SLJIT_R0) && (src2w > 127 || src2w < -128) && (compiler->mode32 || IS_HALFWORD(src2w))) {
1587 inst = emit_x86_instruction(compiler, 1, dst, dstw, src2, src2w);
1592 inst = emit_x86_instruction(compiler, 1, src2, src2w, dst, dstw);
1597 EMIT_MOV(compiler, TMP_REG1, 0, src2, src2w);
1598 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, dst, dstw);
1607 EMIT_MOV(compiler, dst, 0, src1, src1w);
1612 inst = emit_x86_instruction(compiler, 1, dst, 0, src2, src2w);
1619 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1624 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src2, src2w);
1628 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
1634 static sljit_s32 emit_mul(struct sljit_compiler *compiler,
1646 inst = emit_x86_instruction(compiler, 2, dst_r, 0, src2, src2w);
1652 inst = emit_x86_instruction(compiler, 2, dst_r, 0, src1, src1w);
1659 EMIT_MOV(compiler, dst_r, 0, SLJIT_IMM, src2w);
1665 inst = emit_x86_instruction(compiler, 1, dst_r, 0, src2, src2w);
1668 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1);
1675 inst = emit_x86_instruction(compiler, 1, dst_r, 0, src2, src2w);
1678 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4);
1685 inst = emit_x86_instruction(compiler, 1, dst_r, 0, src2, src2w);
1688 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4);
1694 EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_IMM, src1w);
1696 EMIT_MOV(compiler, dst_r, 0, src2, src2w);
1697 inst = emit_x86_instruction(compiler, 2, dst_r, 0, TMP_REG2, 0);
1708 inst = emit_x86_instruction(compiler, 1, dst_r, 0, src1, src1w);
1711 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1);
1718 inst = emit_x86_instruction(compiler, 1, dst_r, 0, src1, src1w);
1721 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4);
1728 inst = emit_x86_instruction(compiler, 1, dst_r, 0, src1, src1w);
1731 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4);
1737 EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_IMM, src2w);
1739 EMIT_MOV(compiler, dst_r, 0, src1, src1w);
1740 inst = emit_x86_instruction(compiler, 2, dst_r, 0, TMP_REG2, 0);
1751 EMIT_MOV(compiler, dst_r, 0, src1, src1w);
1752 inst = emit_x86_instruction(compiler, 2, dst_r, 0, src2, src2w);
1759 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
1764 compiler,
1782 inst = emit_x86_instruction(compiler, 1, dst_r, 0, SLJIT_MEM2(src1, src2), 0);
1788 if ((src2 & SLJIT_IMM) && (compiler->mode32 || IS_HALFWORD(src2w))) {
1789 inst = emit_x86_instruction(compiler, 1, dst_r, 0, SLJIT_MEM1(src1), (sljit_s32)src2w);
1792 inst = emit_x86_instruction(compiler, 1, dst_r, 0, SLJIT_MEM1(src1), src2w);
1801 if ((src1 & SLJIT_IMM) && (compiler->mode32 || IS_HALFWORD(src1w))) {
1802 inst = emit_x86_instruction(compiler, 1, dst_r, 0, SLJIT_MEM1(src2), (sljit_s32)src1w);
1805 inst = emit_x86_instruction(compiler, 1, dst_r, 0, SLJIT_MEM1(src2), src1w);
1815 return emit_mov(compiler, dst, dstw, TMP_REG1, 0);
1821 static sljit_s32 emit_cmp_binary(struct sljit_compiler *compiler,
1828 if (src1 == SLJIT_R0 && (src2 & SLJIT_IMM) && (src2w > 127 || src2w < -128) && (compiler->mode32 || IS_HALFWORD(src2w))) {
1841 inst = emit_x86_instruction(compiler, 1, src1, 0, src2, src2w);
1849 inst = emit_x86_instruction(compiler, 1, src2, 0, src1, src1w);
1857 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1864 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1865 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src2, src2w);
1872 static sljit_s32 emit_test_binary(struct sljit_compiler *compiler,
1879 if (src1 == SLJIT_R0 && (src2 & SLJIT_IMM) && (src2w > 127 || src2w < -128) && (compiler->mode32 || IS_HALFWORD(src2w))) {
1888 if (src2 == SLJIT_R0 && (src1 & SLJIT_IMM) && (src1w > 127 || src1w < -128) && (compiler->mode32 || IS_HALFWORD(src1w))) {
1899 if (IS_HALFWORD(src2w) || compiler->mode32) {
1900 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, src2w, src1, src1w);
1905 FAIL_IF(emit_load_imm64(compiler, TMP_REG2, src2w));
1906 inst = emit_x86_instruction(compiler, 1, TMP_REG2, 0, src1, src1w);
1911 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, src2w, src1, src1w);
1918 inst = emit_x86_instruction(compiler, 1, src1, 0, src2, src2w);
1928 if (IS_HALFWORD(src1w) || compiler->mode32) {
1929 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, src1w, src2, src2w);
1934 FAIL_IF(emit_load_imm64(compiler, TMP_REG2, src1w));
1935 inst = emit_x86_instruction(compiler, 1, TMP_REG2, 0, src2, src2w);
1940 inst = emit_x86_instruction(compiler, 1, src1, src1w, src2, src2w);
1947 inst = emit_x86_instruction(compiler, 1, src2, 0, src1, src1w);
1954 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1957 if (IS_HALFWORD(src2w) || compiler->mode32) {
1958 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, src2w, TMP_REG1, 0);
1963 FAIL_IF(emit_load_imm64(compiler, TMP_REG2, src2w));
1964 inst = emit_x86_instruction(compiler, 1, TMP_REG2, 0, TMP_REG1, 0);
1969 inst = emit_x86_instruction(compiler, 1, SLJIT_IMM, src2w, TMP_REG1, 0);
1975 inst = emit_x86_instruction(compiler, 1, TMP_REG1, 0, src2, src2w);
1982 static sljit_s32 emit_shift(struct sljit_compiler *compiler,
1992 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, src2, src2w, dst, dstw);
1998 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
1999 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, src2, src2w, TMP_REG1, 0);
2005 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
2006 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0);
2009 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0);
2013 EMIT_MOV(compiler, dst, 0, src1, src1w);
2014 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, src2, src2w, dst, 0);
2020 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
2021 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, src2, src2w, TMP_REG1, 0);
2024 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
2029 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
2030 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, src2, src2w);
2031 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0);
2034 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0);
2038 EMIT_MOV(compiler, dst, 0, src1, src1w);
2039 EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_PREF_SHIFT_REG, 0);
2040 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, src2, src2w);
2041 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_PREF_SHIFT_REG, 0, dst, 0);
2044 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0);
2049 EMIT_MOV(compiler, TMP_REG1, 0, src1, src1w);
2051 EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_PREF_SHIFT_REG, 0);
2053 EMIT_MOV(compiler, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_PREF_SHIFT_REG, 0);
2055 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, src2, src2w);
2056 inst = emit_x86_instruction(compiler, 1 | EX86_SHIFT_INS, SLJIT_PREF_SHIFT_REG, 0, TMP_REG1, 0);
2060 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, TMP_REG2, 0);
2062 EMIT_MOV(compiler, SLJIT_PREF_SHIFT_REG, 0, SLJIT_MEM1(SLJIT_SP), 0);
2064 EMIT_MOV(compiler, dst, dstw, TMP_REG1, 0);
2070 static sljit_s32 emit_shift_with_flags(struct sljit_compiler *compiler,
2079 if ((src2w & 0x3f) != 0 || (compiler->mode32 && (src2w & 0x1f) != 0))
2080 return emit_shift(compiler, mode, dst, dstw, src1, src1w, src2, src2w);
2083 return emit_shift(compiler, mode, dst, dstw, src1, src1w, src2, src2w);
2086 return emit_mov(compiler, dst, dstw, src1, src1w);
2088 return emit_cum_binary(compiler, OR_r_rm, OR_rm_r, OR, OR_EAX_i32,
2093 return emit_shift(compiler, mode, dst, dstw, src1, src1w, src2, src2w);
2096 FAIL_IF(emit_cmp_binary(compiler, src1, src1w, SLJIT_IMM, 0));
2098 FAIL_IF(emit_shift(compiler,mode, dst, dstw, src1, src1w, src2, src2w));
2101 return emit_cmp_binary(compiler, dst, dstw, SLJIT_IMM, 0);
2105 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op2(struct sljit_compiler *compiler, sljit_s32 op,
2111 CHECK(check_sljit_emit_op2(compiler, op, dst, dstw, src1, src1w, src2, src2w));
2120 compiler->mode32 = op & SLJIT_I32_OP;
2126 if (emit_lea_binary(compiler, dst, dstw, src1, src1w, src2, src2w) != SLJIT_ERR_UNSUPPORTED)
2127 return compiler->error;
2129 return emit_cum_binary(compiler, ADD_r_rm, ADD_rm_r, ADD, ADD_EAX_i32,
2132 return emit_cum_binary(compiler, ADC_r_rm, ADC_rm_r, ADC, ADC_EAX_i32,
2136 if ((src2 & SLJIT_IMM) && emit_lea_binary(compiler, dst, dstw, src1, src1w, SLJIT_IMM, -src2w) != SLJIT_ERR_UNSUPPORTED)
2137 return compiler->error;
2141 return emit_cmp_binary(compiler, src1, src1w, src2, src2w);
2142 return emit_non_cum_binary(compiler, SUB_r_rm, SUB_rm_r, SUB, SUB_EAX_i32,
2145 return emit_non_cum_binary(compiler, SBB_r_rm, SBB_rm_r, SBB, SBB_EAX_i32,
2148 return emit_mul(compiler, dst, dstw, src1, src1w, src2, src2w);
2151 return emit_test_binary(compiler, src1, src1w, src2, src2w);
2152 return emit_cum_binary(compiler, AND_r_rm, AND_rm_r, AND, AND_EAX_i32,
2155 return emit_cum_binary(compiler, OR_r_rm, OR_rm_r, OR, OR_EAX_i32,
2158 return emit_cum_binary(compiler, XOR_r_rm, XOR_rm_r, XOR, XOR_EAX_i32,
2161 return emit_shift_with_flags(compiler, SHL, HAS_FLAGS(op),
2164 return emit_shift_with_flags(compiler, SHR, HAS_FLAGS(op),
2167 return emit_shift_with_flags(compiler, SAR, HAS_FLAGS(op),
2190 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_custom(struct sljit_compiler *compiler,
2196 CHECK(check_sljit_emit_op_custom(compiler, instruction, size));
2198 inst = (sljit_u8*)ensure_buf(compiler, 1 + size);
2239 static sljit_s32 emit_sse2(struct sljit_compiler *compiler, sljit_u8 opcode,
2244 inst = emit_x86_instruction(compiler, 2 | (single ? EX86_PREF_F3 : EX86_PREF_F2) | EX86_SSE2, xmm1, 0, xmm2, xmm2w);
2251 static sljit_s32 emit_sse2_logic(struct sljit_compiler *compiler, sljit_u8 opcode,
2256 inst = emit_x86_instruction(compiler, 2 | (pref66 ? EX86_PREF_66 : 0) | EX86_SSE2, xmm1, 0, xmm2, xmm2w);
2263 static SLJIT_INLINE sljit_s32 emit_sse2_load(struct sljit_compiler *compiler,
2266 return emit_sse2(compiler, MOVSD_x_xm, single, dst, src, srcw);
2269 static SLJIT_INLINE sljit_s32 emit_sse2_store(struct sljit_compiler *compiler,
2272 return emit_sse2(compiler, MOVSD_xm_x, single, src, dst, dstw);
2275 static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_sw_from_f64(struct sljit_compiler *compiler, sljit_s32 op,
2284 compiler->mode32 = 0;
2287 inst = emit_x86_instruction(compiler
2293 return emit_mov(compiler, dst, dstw, TMP_REG1, 0);
2297 static SLJIT_INLINE sljit_s32 sljit_emit_fop1_conv_f64_from_sw(struct sljit_compiler *compiler, sljit_s32 op,
2306 compiler->mode32 = 0;
2314 EMIT_MOV(compiler, TMP_REG1, 0, src, srcw);
2319 inst = emit_x86_instruction(compiler, 2 | ((op & SLJIT_F32_OP) ? EX86_PREF_F3 : EX86_PREF_F2) | EX86_SSE2_OP1, dst_r, 0, src, srcw);
2325 compiler->mode32 = 1;
2328 return emit_sse2_store(compiler, op & SLJIT_F32_OP, dst, dstw, TMP_FREG);
2332 static SLJIT_INLINE sljit_s32 sljit_emit_fop1_cmp(struct sljit_compiler *compiler, sljit_s32 op,
2337 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, TMP_FREG, src1, src1w));
2340 return emit_sse2_logic(compiler, UCOMISD_x_xm, !(op & SLJIT_F32_OP), src1, src2, src2w);
2343 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop1(struct sljit_compiler *compiler, sljit_s32 op,
2350 compiler->mode32 = 1;
2354 SELECT_FOP1_OPERATION_WITH_CHECKS(compiler, op, dst, dstw, src, srcw);
2358 return emit_sse2_load(compiler, op & SLJIT_F32_OP, dst, src, srcw);
2360 return emit_sse2_store(compiler, op & SLJIT_F32_OP, dst, dstw, src);
2361 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, TMP_FREG, src, srcw));
2362 return emit_sse2_store(compiler, op & SLJIT_F32_OP, dst, dstw, TMP_FREG);
2371 FAIL_IF(emit_sse2_logic(compiler, UNPCKLPD_x_xm, op & SLJIT_F32_OP, src, src, 0));
2374 FAIL_IF(emit_sse2_load(compiler, !(op & SLJIT_F32_OP), TMP_FREG, src, srcw));
2378 FAIL_IF(emit_sse2_logic(compiler, CVTPD2PS_x_xm, op & SLJIT_F32_OP, dst_r, src, 0));
2380 return emit_sse2_store(compiler, op & SLJIT_F32_OP, dst, dstw, TMP_FREG);
2387 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, dst_r, src, srcw));
2391 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, dst_r, src, srcw));
2396 FAIL_IF(emit_sse2_logic(compiler, XORPD_x_xm, 1, dst_r, SLJIT_MEM0(), (sljit_sw)(op & SLJIT_F32_OP ? sse2_buffer : sse2_buffer + 8)));
2400 FAIL_IF(emit_sse2_logic(compiler, ANDPD_x_xm, 1, dst_r, SLJIT_MEM0(), (sljit_sw)(op & SLJIT_F32_OP ? sse2_buffer + 4 : sse2_buffer + 12)));
2405 return emit_sse2_store(compiler, op & SLJIT_F32_OP, dst, dstw, TMP_FREG);
2409 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_fop2(struct sljit_compiler *compiler, sljit_s32 op,
2417 CHECK(check_sljit_emit_fop2(compiler, op, dst, dstw, src1, src1w, src2, src2w));
2423 compiler->mode32 = 1;
2436 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, dst_r, src1, src1w));
2439 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, TMP_FREG, src1, src1w));
2444 FAIL_IF(emit_sse2_load(compiler, op & SLJIT_F32_OP, TMP_FREG, src1, src1w));
2449 FAIL_IF(emit_sse2(compiler, ADDSD_x_xm, op & SLJIT_F32_OP, dst_r, src2, src2w));
2453 FAIL_IF(emit_sse2(compiler, SUBSD_x_xm, op & SLJIT_F32_OP, dst_r, src2, src2w));
2457 FAIL_IF(emit_sse2(compiler, MULSD_x_xm, op & SLJIT_F32_OP, dst_r, src2, src2w));
2461 FAIL_IF(emit_sse2(compiler, DIVSD_x_xm, op & SLJIT_F32_OP, dst_r, src2, src2w));
2466 return emit_sse2_store(compiler, op & SLJIT_F32_OP, dst, dstw, TMP_FREG);
2474 SLJIT_API_FUNC_ATTRIBUTE struct sljit_label* sljit_emit_label(struct sljit_compiler *compiler)
2480 CHECK_PTR(check_sljit_emit_label(compiler));
2482 if (compiler->last_label && compiler->last_label->size == compiler->size)
2483 return compiler->last_label;
2485 label = (struct sljit_label*)ensure_abuf(compiler, sizeof(struct sljit_label));
2487 set_label(label, compiler);
2489 inst = (sljit_u8*)ensure_buf(compiler, 2);
2498 SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_jump(struct sljit_compiler *compiler, sljit_s32 type)
2504 CHECK_PTR(check_sljit_emit_jump(compiler, type));
2506 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
2508 set_jump(jump, compiler, type & SLJIT_REWRITABLE_JUMP);
2512 PTR_FAIL_IF(call_with_args(compiler, type));
2516 compiler->size += (type >= SLJIT_JUMP) ? 5 : 6;
2518 compiler->size += (type >= SLJIT_JUMP) ? (10 + 3) : (2 + 10 + 3);
2521 inst = (sljit_u8*)ensure_buf(compiler, 2);
2529 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_ijump(struct sljit_compiler *compiler, sljit_s32 type, sljit_s32 src, sljit_sw srcw)
2535 CHECK(check_sljit_emit_ijump(compiler, type, src, srcw));
2544 EMIT_MOV(compiler, TMP_REG1, 0, src, 0);
2553 EMIT_MOV(compiler, TMP_REG1, 0, src, 0);
2557 FAIL_IF(call_with_args(compiler, type));
2561 jump = (struct sljit_jump*)ensure_abuf(compiler, sizeof(struct sljit_jump));
2563 set_jump(jump, compiler, JUMP_ADDR);
2568 compiler->size += 5;
2570 compiler->size += 10 + 3;
2573 inst = (sljit_u8*)ensure_buf(compiler, 2);
2582 compiler->mode32 = 1;
2584 inst = emit_x86_instruction(compiler, 1, 0, 0, src, srcw);
2592 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_op_flags(struct sljit_compiler *compiler, sljit_s32 op,
2607 CHECK(check_sljit_emit_op_flags(compiler, op, dst, dstw, src, srcw, type));
2622 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4 + 3);
2638 inst = (sljit_u8*)ensure_buf(compiler, 1 + 4 + 4);
2656 compiler->mode32 = GET_OPCODE(op) != SLJIT_MOV;
2657 return emit_mov(compiler, dst, dstw, TMP_REG1, 0);
2661 compiler->skip_checks = 1;
2663 return sljit_emit_op2(compiler, op, dst_save, dstw_save, dst_save, dstw_save, TMP_REG1, 0);
2670 inst = (sljit_u8*)ensure_buf(compiler, 1 + 3 + 3);
2689 EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_IMM, 1);
2691 EMIT_MOV(compiler, dst, 0, SLJIT_IMM, 0);
2693 inst = (sljit_u8*)ensure_buf(compiler, 1 + 3);
2704 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1 + 3 + 3 + 1);
2724 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1 + 3 + 2 + 1);
2737 inst = (sljit_u8*)ensure_buf(compiler, 1 + 2 + 3 + 2 + 2);
2755 inst = (sljit_u8*)ensure_buf(compiler, 1 + 1 + 3 + 3 + 1);
2771 return emit_mov(compiler, dst, dstw, TMP_REG1, 0);
2775 compiler->skip_checks = 1;
2777 return sljit_emit_op2(compiler, op, dst_save, dstw_save, dst_save, dstw_save, TMP_REG1, 0);
2781 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset)
2784 CHECK(check_sljit_get_local_base(compiler, dst, dstw, offset));
2790 compiler->mode32 = 0;
2797 FAIL_IF(emit_load_imm64(compiler, TMP_REG1, offset));
2799 SLJIT_ASSERT(emit_lea_binary(compiler, dst, dstw, SLJIT_SP, 0, TMP_REG1, 0) != SLJIT_ERR_UNSUPPORTED);
2800 return compiler->error;
2802 return emit_lea_binary(compiler, dst, dstw, SLJIT_SP, 0, TMP_REG1, 0);
2808 return emit_lea_binary(compiler, dst, dstw, SLJIT_SP, 0, SLJIT_IMM, offset);
2809 return emit_mov(compiler, dst, dstw, SLJIT_SP, 0);
2812 SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value)
2821 CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value));
2826 const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const));
2828 set_const(const_, compiler);
2831 compiler->mode32 = 0;
2834 if (emit_load_imm64(compiler, reg, init_value))
2840 if (emit_mov(compiler, dst, dstw, SLJIT_IMM, init_value))
2844 inst = (sljit_u8*)ensure_buf(compiler, 2);
2852 if (emit_mov(compiler, dst, dstw, TMP_REG1, 0))
2893 SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_x86_emit_cmov(struct sljit_compiler *compiler,
2909 CHECK_ARGUMENT(compiler->last_flags & SLJIT_SET_Z);
2911 CHECK_ARGUMENT((type & 0xff) == (compiler->last_flags & 0xff));
2914 if (SLJIT_UNLIKELY(!!compiler->verbose)) {
2915 fprintf(compiler->verbose, " x86_cmov%s %s%s, ",
2918 sljit_verbose_reg(compiler, dst_reg & ~SLJIT_I32_OP);
2919 fprintf(compiler->verbose, ", ");
2920 sljit_verbose_param(compiler, src, srcw);
2921 fprintf(compiler->verbose, "\n");
2929 compiler->mode32 = dst_reg & SLJIT_I32_OP;
2934 EMIT_MOV(compiler, TMP_REG1, 0, SLJIT_IMM, srcw);
2939 inst = emit_x86_instruction(compiler, 2, dst_reg, 0, src, srcw);