diff --git a/API_CHANGES b/API_CHANGES index 07a935bc..8f304b96 100644 --- a/API_CHANGES +++ b/API_CHANGES @@ -1,5 +1,9 @@ This file is the short summary of the API changes: +31.01.2025 - Non-backward compatible + The sljit_emit_const and sljit_set_const + functions can specify the operation type. + 17.07.2024 - Non-backward compatible Passing float scratch or saved register count to emit_enter / set_context is reworked. diff --git a/sljit_src/sljitLir.c b/sljit_src/sljitLir.c index 627a23ae..6dc203de 100644 --- a/sljit_src/sljitLir.c +++ b/sljit_src/sljitLir.c @@ -3231,16 +3231,21 @@ static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_get_local_base(struct sljit_co CHECK_RETURN_OK; } -static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +static SLJIT_INLINE CHECK_RETURN_TYPE check_sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { SLJIT_UNUSED_ARG(init_value); #if (defined SLJIT_ARGUMENT_CHECKS && SLJIT_ARGUMENT_CHECKS) + CHECK_ARGUMENT(op == SLJIT_MOV || op == SLJIT_MOV_S32 + || op == SLJIT_MOV32 || (op | SLJIT_32) == SLJIT_MOV32_U8); FUNCTION_CHECK_DST(dst, dstw); #endif /* SLJIT_ARGUMENT_CHECKS */ #if (defined SLJIT_VERBOSE && SLJIT_VERBOSE) if (SLJIT_UNLIKELY(!!compiler->verbose)) { - fprintf(compiler->verbose, " const "); + fprintf(compiler->verbose, " const%s%s ", + !(op & SLJIT_32) ? "" : "32", op1_types[GET_OPCODE(op) - SLJIT_OP1_BASE]); sljit_verbose_param(compiler, dst, dstw); fprintf(compiler->verbose, ", #%" SLJIT_PRINT_D "d\n", init_value); } diff --git a/sljit_src/sljitLir.h b/sljit_src/sljitLir.h index 7008fcc1..0e755966 100644 --- a/sljit_src/sljitLir.h +++ b/sljit_src/sljitLir.h @@ -2326,9 +2326,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler Flags: - (may destroy flags) */ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw offset); -/* Store a value that can be changed runtime (see: sljit_get_const_addr / sljit_set_const) +/* Store a value that can be changed at runtime. The constant + can be managed by sljit_get_const_addr and sljit_set_const. + + op must be SLJIT_MOV, SLJIT_MOV32, SLJIT_MOV_S32, + SLJIT_MOV_U8, SLJIT_MOV32_U8 + + Note: when SLJIT_MOV_U8 is used, and dst is a register, + init_value supports a 9 bit signed value between [-256..255] + Flags: - (does not modify flags) */ -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value); +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value); /* Store the value of a label (see: sljit_set_label / sljit_set_target) Flags: - (does not modify flags) */ @@ -2345,7 +2355,8 @@ static SLJIT_INLINE sljit_uw sljit_get_const_addr(struct sljit_const *const_) { /* Only the address and executable offset are required to perform dynamic code modifications. See sljit_get_executable_offset function. */ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_target, sljit_sw executable_offset); -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset); +/* The op opcode must be set to the same value that was passed to sljit_emit_const. */ +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset); /* --------------------------------------------------------------------- */ /* CPU specific functions */ diff --git a/sljit_src/sljitNativeARM_32.c b/sljit_src/sljitNativeARM_32.c index 327dc824..0913247c 100644 --- a/sljit_src/sljitNativeARM_32.c +++ b/sljit_src/sljitNativeARM_32.c @@ -1111,17 +1111,23 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil const_ = compiler->consts; while (const_) { buf_ptr = (sljit_ins*)const_->addr; - const_->addr = (sljit_uw)code_ptr; - code_ptr[0] = (sljit_ins)buf_ptr; - code_ptr[1] = *buf_ptr; - if (*buf_ptr & (1 << 23)) - buf_ptr += ((*buf_ptr & 0xfff) >> 2) + 2; - else - buf_ptr += 1; - /* Set the value again (can be a simple constant). */ - set_const_value((sljit_uw)code_ptr, executable_offset, *buf_ptr, 0); - code_ptr += 2; + /* Note: MVN = (MOV ^ 0x400000) */ + SLJIT_ASSERT((*buf_ptr & 0xfdb00000) == MOV || (*buf_ptr & 0xfd100000) == LDR); + + if ((*buf_ptr & 0x4000000) != 0) { + const_->addr = (sljit_uw)code_ptr; + + code_ptr[0] = (sljit_ins)buf_ptr; + code_ptr[1] = *buf_ptr; + if (*buf_ptr & (1 << 23)) + buf_ptr += ((*buf_ptr & 0xfff) >> 2) + 2; + else + buf_ptr += 1; + /* Set the value again (can be a simple constant). */ + set_const_value((sljit_uw)code_ptr, executable_offset, *buf_ptr, 0); + code_ptr += 2; + } const_ = const_->next; } @@ -4688,13 +4694,19 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +#define SLJIT_EMIT_CONST_U8(c) \ + (((c) & 0x100) != 0 ? (MVN | SRC2_IMM | (~(c) & 0xff)) : (MOV | SRC2_IMM | ((c) & 0xff))) + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_SIZE; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4703,16 +4715,22 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; + if (GET_OPCODE(op) == SLJIT_MOV_U8) { + PTR_FAIL_IF(push_inst(compiler, SLJIT_EMIT_CONST_U8(init_value) | RD(dst_r))); + mem_flags = BYTE_SIZE; + } else { #if (defined SLJIT_CONFIG_ARM_V6 && SLJIT_CONFIG_ARM_V6) - PTR_FAIL_IF(push_inst_with_unique_literal(compiler, - EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, dst_r, TMP_PC, 0), (sljit_ins)init_value)); - compiler->patches++; + PTR_FAIL_IF(push_inst_with_unique_literal(compiler, + EMIT_DATA_TRANSFER(WORD_SIZE | LOAD_DATA, 1, dst_r, TMP_PC, 0), (sljit_ins)init_value)); + compiler->patches++; #else /* !SLJIT_CONFIG_ARM_V6 */ - PTR_FAIL_IF(emit_imm(compiler, dst_r, init_value)); + PTR_FAIL_IF(emit_imm(compiler, dst_r, init_value)); #endif /* SLJIT_CONFIG_ARM_V6 */ + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE, TMP_REG2, dst, dstw, TMP_REG1)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, dst, dstw, TMP_REG1)); + return const_; } @@ -4752,7 +4770,21 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta set_jump_addr(addr, executable_offset, new_target, 1); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - set_const_value(addr, executable_offset, (sljit_uw)new_constant, 1); + sljit_ins *inst; + + if (GET_OPCODE(op) != SLJIT_MOV_U8) { + set_const_value(addr, executable_offset, (sljit_uw)new_constant, 1); + return; + } + + inst = (sljit_ins*)addr; + SLJIT_ASSERT((inst[0] & 0xfff00000) == (MOV | SRC2_IMM) || (inst[0] & 0xfff00000) == (MVN | SRC2_IMM)); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + *inst = SLJIT_EMIT_CONST_U8(new_constant) | (*inst & 0xf000); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins*)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); } diff --git a/sljit_src/sljitNativeARM_64.c b/sljit_src/sljitNativeARM_64.c index f1ae3d9e..fb431ed5 100644 --- a/sljit_src/sljitNativeARM_64.c +++ b/sljit_src/sljitNativeARM_64.c @@ -3501,13 +3501,21 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +#define SLJIT_EMIT_CONST_U8(c) \ + (((c) & 0x100) != 0 ? (MOVN | (sljit_ins)((~(c) & 0xff) << 5)) : (MOVZ | (sljit_ins)(((c) & 0xff) << 5))) +#define SLJIT_EMIT_CONST_S32(c) \ + (((c) < 0) ? (MOVN | (sljit_ins)((~(c) & 0xffff) << 5)) : (MOVZ | (sljit_ins)(((c) & 0xffff) << 5))) + +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_SIZE | STORE; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -3515,10 +3523,32 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; - PTR_FAIL_IF(emit_imm64_const(compiler, dst_r, (sljit_uw)init_value)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + PTR_FAIL_IF(push_inst(compiler, SLJIT_EMIT_CONST_U8(init_value) | RD(dst_r))); + mem_flags = BYTE_SIZE | STORE; + break; + + case SLJIT_MOV32: + case SLJIT_MOV_S32: + if (GET_OPCODE(op) == SLJIT_MOV32) { + init_value = (sljit_u32)init_value; + mem_flags = INT_SIZE | STORE; + } else + init_value = (sljit_s32)init_value; + + PTR_FAIL_IF(push_inst(compiler, SLJIT_EMIT_CONST_S32(init_value) | RD(dst_r))); + PTR_FAIL_IF(push_inst(compiler, MOVK | (1 << 21) | (sljit_ins)((init_value >> 11) & 0x1fffe0) | RD(dst_r))); + break; + + default: + PTR_FAIL_IF(emit_imm64_const(compiler, dst_r, (sljit_uw)init_value)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, dst, dstw, TMP_REG2)); return const_; } @@ -3566,7 +3596,42 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_CACHE_FLUSH(inst, inst + 4); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_ins* inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins*)addr; + SLJIT_ASSERT((inst[0] & 0xffe00000) == MOVZ || (inst[0] & 0xffe00000) == MOVN); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = SLJIT_EMIT_CONST_U8(new_constant) | (inst[0] & 0x1f); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); + return; + + case SLJIT_MOV32: + case SLJIT_MOV_S32: + if (GET_OPCODE(op) == SLJIT_MOV32) + new_constant = (sljit_u32)new_constant; + else + new_constant = (sljit_s32)new_constant; + + inst = (sljit_ins*)addr; + SLJIT_ASSERT(((inst[0] & 0xffe00000) == MOVZ || (inst[0] & 0xffe00000) == MOVN) && (inst[1] & 0xffe00000) == (MOVK | (1 << 21))); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = SLJIT_EMIT_CONST_S32(new_constant) | (inst[0] & 0x1f); + inst[1] = MOVK | (1 << 21) | (sljit_ins)((new_constant >> 11) & 0x1fffe0) | (inst[1] & 0x1f); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/sljit_src/sljitNativeARM_T2_32.c b/sljit_src/sljitNativeARM_T2_32.c index d8058ab6..2441ab9c 100644 --- a/sljit_src/sljitNativeARM_T2_32.c +++ b/sljit_src/sljitNativeARM_T2_32.c @@ -4357,13 +4357,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return SLJIT_SUCCESS; } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_SIZE | STORE; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4371,10 +4374,16 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG1; - PTR_FAIL_IF(emit_imm32_const(compiler, dst_r, (sljit_uw)init_value)); + + if (GET_OPCODE(op) == SLJIT_MOV_U8) { + PTR_FAIL_IF(push_inst32(compiler, + ((init_value & 0x100) != 0 ? (MVN_WI | (~init_value & 0xff)) : (MOV_WI | (init_value & 0xff))) | RD4(dst_r))); + mem_flags = BYTE_SIZE | STORE; + } else + PTR_FAIL_IF(emit_imm32_const(compiler, dst_r, (sljit_uw)init_value)); if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_SIZE | STORE, dst_r, dst, dstw, TMP_REG2)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, dst, dstw, TMP_REG2)); return const_; } @@ -4412,7 +4421,28 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_CACHE_FLUSH(inst, inst + 4); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_u16 *inst; + + if (GET_OPCODE(op) != SLJIT_MOV_U8) { + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } + + inst = (sljit_u16*)addr; + SLJIT_ASSERT(inst[0] == (MOV_WI >> 16) || inst[0] == (MVN_WI >> 16)); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + + if ((new_constant & 0x100) != 0) { + inst[0] = (sljit_u16)(MVN_WI >> 16); + new_constant = ~new_constant; + } else + inst[0] = (sljit_u16)(MOV_WI >> 16); + + inst[1] = (sljit_u16)((new_constant & 0xff) | (inst[1] & 0xf00)); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst + 1, inst + 2); } diff --git a/sljit_src/sljitNativeMIPS_32.c b/sljit_src/sljitNativeMIPS_32.c index 91153e5f..83979617 100644 --- a/sljit_src/sljitNativeMIPS_32.c +++ b/sljit_src/sljitNativeMIPS_32.c @@ -196,18 +196,13 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); SLJIT_ASSERT((inst[0] & 0xffe00000) == LUI && (inst[1] & 0xfc000000) == ORI); - inst[0] = (inst[0] & 0xffff0000) | ((new_target >> 16) & 0xffff); - inst[1] = (inst[1] & 0xffff0000) | (new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_target >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 2); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) -{ - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); -} - static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr, sljit_u32 *extra_space) { sljit_u32 is_tail_call = *extra_space & SLJIT_CALL_RETURN; diff --git a/sljit_src/sljitNativeMIPS_64.c b/sljit_src/sljitNativeMIPS_64.c index b9f03a7b..965931b8 100644 --- a/sljit_src/sljitNativeMIPS_64.c +++ b/sljit_src/sljitNativeMIPS_64.c @@ -202,20 +202,15 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UNUSED_ARG(executable_offset); SLJIT_UPDATE_WX_FLAGS(inst, inst + 6, 0); - inst[0] = (inst[0] & 0xffff0000) | ((sljit_ins)(new_target >> 48) & 0xffff); - inst[1] = (inst[1] & 0xffff0000) | ((sljit_ins)(new_target >> 32) & 0xffff); - inst[3] = (inst[3] & 0xffff0000) | ((sljit_ins)(new_target >> 16) & 0xffff); - inst[5] = (inst[5] & 0xffff0000) | ((sljit_ins)new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_target >> 48); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_target >> 32); + inst[3] = (inst[3] & 0xffff0000) | IMM(new_target >> 16); + inst[5] = (inst[5] & 0xffff0000) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 6, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 6); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) -{ - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); -} - static sljit_s32 call_with_args(struct sljit_compiler *compiler, sljit_s32 arg_types, sljit_ins *ins_ptr) { sljit_s32 arg_count = 0; diff --git a/sljit_src/sljitNativeMIPS_common.c b/sljit_src/sljitNativeMIPS_common.c index 1b951fe1..f926db83 100644 --- a/sljit_src/sljitNativeMIPS_common.c +++ b/sljit_src/sljitNativeMIPS_common.c @@ -4319,13 +4319,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return push_inst(compiler, ins | TA(OTHER_FLAG) | S(mem_reg), OTHER_FLAG); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4333,10 +4336,35 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xff00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDIU | SA(0) | T(dst_r) | IMM(init_value), DR(dst_r))); + mem_flags = BYTE_DATA; + break; + +#if (defined(SLJIT_CONFIG_MIPS_64) && SLJIT_CONFIG_MIPS_64) + case SLJIT_MOV32: + mem_flags = INT_DATA; + /* fallthrough */ + case SLJIT_MOV_S32: + PTR_FAIL_IF(push_inst(compiler, LUI | T(dst_r) | IMM(init_value >> 16), DR(dst_r))); + PTR_FAIL_IF(push_inst(compiler, ORI | S(dst_r) | T(dst_r) | IMM(init_value), DR(dst_r))); + break; +#endif /* SLJIT_CONFIG_MIPS_64 */ + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, DR(TMP_REG2), dst, dstw)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, DR(TMP_REG2), dst, dstw)); return const_; } @@ -4367,3 +4395,45 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com return jump; } + +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) +{ + sljit_ins *inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xfc000000) == ADDIU); + + if (new_constant & 0x100) + new_constant |= 0xff00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 1); + return; + +#if (defined(SLJIT_CONFIG_MIPS_64) && SLJIT_CONFIG_MIPS_64) + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xffe00000) == LUI && (inst[1] & 0xfc000000) == ORI); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; +#endif /* SLJIT_CONFIG_MIPS_64 */ + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } +} diff --git a/sljit_src/sljitNativePPC_32.c b/sljit_src/sljitNativePPC_32.c index 2352fad5..c07f4b48 100644 --- a/sljit_src/sljitNativePPC_32.c +++ b/sljit_src/sljitNativePPC_32.c @@ -477,8 +477,8 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); SLJIT_ASSERT((inst[0] & 0xfc1f0000) == ADDIS && (inst[1] & 0xfc000000) == ORI); - inst[0] = (inst[0] & 0xffff0000) | ((new_target >> 16) & 0xffff); - inst[1] = (inst[1] & 0xffff0000) | (new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_target >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 2); diff --git a/sljit_src/sljitNativePPC_64.c b/sljit_src/sljitNativePPC_64.c index b3cf9d07..2b07fcba 100644 --- a/sljit_src/sljitNativePPC_64.c +++ b/sljit_src/sljitNativePPC_64.c @@ -709,10 +709,10 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UNUSED_ARG(executable_offset); SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 0); - inst[0] = (inst[0] & 0xffff0000u) | ((sljit_ins)(new_target >> 48) & 0xffff); - inst[1] = (inst[1] & 0xffff0000u) | ((sljit_ins)(new_target >> 32) & 0xffff); - inst[3] = (inst[3] & 0xffff0000u) | ((sljit_ins)(new_target >> 16) & 0xffff); - inst[4] = (inst[4] & 0xffff0000u) | ((sljit_ins)new_target & 0xffff); + inst[0] = (inst[0] & 0xffff0000u) | IMM(new_target >> 48); + inst[1] = (inst[1] & 0xffff0000u) | IMM(new_target >> 32); + inst[3] = (inst[3] & 0xffff0000u) | IMM(new_target >> 16); + inst[4] = (inst[4] & 0xffff0000u) | IMM(new_target); SLJIT_UPDATE_WX_FLAGS(inst, inst + 5, 1); inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); SLJIT_CACHE_FLUSH(inst, inst + 5); diff --git a/sljit_src/sljitNativePPC_common.c b/sljit_src/sljitNativePPC_common.c index 3d2268e8..290d6e27 100644 --- a/sljit_src/sljitNativePPC_common.c +++ b/sljit_src/sljitNativePPC_common.c @@ -3216,13 +3216,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_atomic_store(struct sljit_compiler return push_inst(compiler, ins | D(src_reg) | B(mem_reg)); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -3230,10 +3233,35 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xff00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDI | D(dst_r) | A(0) | IMM(init_value))); + mem_flags = BYTE_DATA; + break; + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + case SLJIT_MOV32: + mem_flags = INT_DATA; + /* fallthrough */ + case SLJIT_MOV_S32: + PTR_FAIL_IF(push_inst(compiler, ADDIS | D(dst_r) | A(0) | IMM(init_value >> 16))); + PTR_FAIL_IF(push_inst(compiler, ORI | S(dst_r) | A(dst_r) | IMM(init_value))); + break; +#endif /* SLJIT_CONFIG_PPC_64 */ + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value)); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, dst_r, dst, dstw, TMP_REG1)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, dst_r, dst, dstw, TMP_REG1)); return const_; } @@ -3265,7 +3293,44 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com return jump; } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_ins *inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xfc1f0000) == ADDI); + + if (new_constant & 0x100) + new_constant |= 0xff00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 1, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + +#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64) + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_ins *)addr; + SLJIT_ASSERT((inst[0] & 0xfc1f0000) == ADDIS && (inst[1] & 0xfc000000) == ORI); + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[0] = (inst[0] & 0xffff0000) | IMM(new_constant >> 16); + inst[1] = (inst[1] & 0xffff0000) | IMM(new_constant); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_ins *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; +#endif /* SLJIT_CONFIG_PPC_64 */ + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/sljit_src/sljitNativeRISCV_32.c b/sljit_src/sljitNativeRISCV_32.c index 44b95568..e2dfb01c 100644 --- a/sljit_src/sljitNativeRISCV_32.c +++ b/sljit_src/sljitNativeRISCV_32.c @@ -40,7 +40,7 @@ static sljit_s32 load_immediate(struct sljit_compiler *compiler, sljit_s32 dst_r if (RISCV_HAS_COMPRESSED(200) && imm <= 0x1ffff && imm >= -0x20000) FAIL_IF(push_inst16(compiler, C_LUI | C_RD(dst_r) | ((sljit_u16)(((imm) & 0x1f000) >> 10) | ((imm) & 0x20000) >> 5))); else - FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~0xfff))); + FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(imm & ~(sljit_sw)0xfff))); imm &= 0xfff; @@ -143,7 +143,7 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 0); SLJIT_ASSERT((inst[0] & 0x7f) == LUI); - inst[0] = (sljit_u16)((inst[0] & 0xfff) | (new_target & ~(sljit_uw)0xfff)); + inst[0] = (sljit_u16)((inst[0] & 0xfff) | (new_target & 0xf000)); inst[1] = (sljit_u16)(new_target >> 16); SLJIT_ASSERT((inst[2] & 0x707f) == ADDI || (inst[2] & 0x707f) == JALR); inst[3] = (sljit_u16)((inst[3] & 0xf) | (new_target << 4)); diff --git a/sljit_src/sljitNativeRISCV_64.c b/sljit_src/sljitNativeRISCV_64.c index 64a0a694..113d1f88 100644 --- a/sljit_src/sljitNativeRISCV_64.c +++ b/sljit_src/sljitNativeRISCV_64.c @@ -275,12 +275,12 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS(inst, inst + 12, 0); SLJIT_ASSERT((inst[0] & 0x7f) == LUI); - inst[0] = (sljit_u16)((inst[0] & 0xfff) | (high & ~(sljit_sw)0xfff)); + inst[0] = (sljit_u16)((inst[0] & 0xfff) | (high & 0xf000)); inst[1] = (sljit_u16)(high >> 16); SLJIT_ASSERT((inst[2] & 0x707f) == ADDI); inst[3] = (sljit_u16)((inst[3] & 0xf) | (high << 4)); SLJIT_ASSERT((inst[4] & 0x7f) == LUI); - inst[4] = (sljit_u16)((inst[4] & 0xfff) | (new_target & ~(sljit_uw)0xfff)); + inst[4] = (sljit_u16)((inst[4] & 0xfff) | (new_target & 0xf000)); inst[5] = (sljit_u16)(new_target >> 16); SLJIT_ASSERT((inst[10] & 0x707f) == ADDI || (inst[10] & 0x707f) == JALR); inst[11] = (sljit_u16)((inst[11] & 0xf) | (new_target << 4)); diff --git a/sljit_src/sljitNativeRISCV_common.c b/sljit_src/sljitNativeRISCV_common.c index cb50827a..07ebec25 100644 --- a/sljit_src/sljitNativeRISCV_common.c +++ b/sljit_src/sljitNativeRISCV_common.c @@ -256,7 +256,7 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define C_FSWSP (C_OPC(0x2, 0x7)) #define C_J (C_OPC(0x1, 0x5)) #define C_JR (C_OPC(0x2, 0x4)) -#if defined SLJIT_CONFIG_RISCV_32 +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) #define C_JAL (C_OPC(0x1, 0x1)) #endif #define C_JALR (C_OPC(0x2, 0x4) | (sljit_u16)(1 << 12)) @@ -318,9 +318,9 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define REM (F7(0x1) | F3(0x6) | OPC(0x33)) #define REMU (F7(0x1) | F3(0x7) | OPC(0x33)) /* REV8 / ROL / ROR / RORI: zbb */ -#if defined SLJIT_CONFIG_RISCV_32 +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) #define REV8 (F12(0x698) | F3(0x5) | OPC(0x13)) -#elif defined SLJIT_CONFIG_RISCV_64 +#elif (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) #define REV8 (F12(0x6b8) | F3(0x5) | OPC(0x13)) #endif /* SLJIT_CONFIG_RISCV_32 */ #define ROL (F7(0x30) | F3(0x1) | OPC(0x33)) @@ -378,9 +378,9 @@ static const sljit_u8 vreg_map[SLJIT_NUMBER_OF_VECTOR_REGISTERS + 3] = { #define XOR (F7(0x0) | F3(0x4) | OPC(0x33)) #define XORI (F3(0x4) | OPC(0x13)) /* ZEXTH: zbb */ -#if defined SLJIT_CONFIG_RISCV_32 +#if (defined SLJIT_CONFIG_RISCV_32 && SLJIT_CONFIG_RISCV_32) #define ZEXTH (F7(0x4) | F3(0x4) | OPC(0x33)) -#elif defined SLJIT_CONFIG_RISCV_64 +#else /* SLJIT_CONFIG_RISCV_64 */ #define ZEXTH (F7(0x4) | F3(0x4) | OPC(0x3B)) #endif /* SLJIT_CONFIG_RISCV_32 */ @@ -1809,7 +1809,6 @@ static sljit_s32 emit_rev(struct sljit_compiler *compiler, sljit_s32 op, sljit_s } #endif /* SLJIT_CONFIG_RISCV_64 */ - FAIL_IF(push_inst(compiler, SRLI | WORD_32 | RD(TMP_REG1) | RS1(src) | IMM_I(16))); FAIL_IF(push_inst(compiler, LUI | RD(OTHER_FLAG) | 0xff0000)); FAIL_IF(push_inst(compiler, SLLI | WORD_32 | RD(dst) | RS1(src) | IMM_I(16))); @@ -4391,13 +4390,16 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_emit_simd_op2(struct sljit_compiler *co return push_inst(compiler, ins | VRD(dst_vreg) | VRS1(src2) | VRS2(src1_vreg)); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { struct sljit_const *const_; sljit_s32 dst_r; + sljit_s32 mem_flags = WORD_DATA; CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); @@ -4405,10 +4407,38 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compi set_const(const_, compiler); dst_r = FAST_IS_REG(dst) ? dst : TMP_REG2; - PTR_FAIL_IF(emit_const(compiler, dst_r, init_value, ADDI | RD(dst_r))); + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + if (init_value & 0x100) + init_value |= 0xf00; + else + init_value &= 0xff; + + PTR_FAIL_IF(push_inst(compiler, ADDI | RD(dst_r) | IMM_I(init_value))); + mem_flags = BYTE_DATA; + break; + +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + case SLJIT_MOV32: + mem_flags = INT_DATA; + /* fallthrough */ + case SLJIT_MOV_S32: + if ((init_value & 0x800) != 0) + init_value ^= ~(sljit_sw)0xfff; + + PTR_FAIL_IF(push_inst(compiler, LUI | RD(dst_r) | (sljit_ins)(init_value & ~(sljit_sw)0xfff))); + PTR_FAIL_IF(push_inst(compiler, XORI | RD(dst_r) | RS1(dst_r) | IMM_I(init_value))); + break; +#endif /* SLJIT_CONFIG_RISCV_64 */ + + default: + PTR_FAIL_IF(emit_const(compiler, dst_r, init_value, ADDI | RD(dst_r))); + break; + } if (dst & SLJIT_MEM) - PTR_FAIL_IF(emit_op_mem(compiler, WORD_DATA, TMP_REG2, dst, dstw)); + PTR_FAIL_IF(emit_op_mem(compiler, mem_flags, TMP_REG2, dst, dstw)); return const_; } @@ -4436,7 +4466,48 @@ SLJIT_API_FUNC_ATTRIBUTE struct sljit_jump* sljit_emit_mov_addr(struct sljit_com return jump; } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { - sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + sljit_u16 *inst; + + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: + inst = (sljit_u16*)addr; + SLJIT_ASSERT((inst[0] & 0x707f) == ADDI); + + if (new_constant & 0x100) + new_constant |= 0xf00; + else + new_constant &= 0xff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 0); + inst[1] = (sljit_u16)(new_constant << 4) | (inst[1] & 0xf); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 2, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 2); + return; + +#if (defined SLJIT_CONFIG_RISCV_64 && SLJIT_CONFIG_RISCV_64) + case SLJIT_MOV32: + case SLJIT_MOV_S32: + inst = (sljit_u16*)addr; + SLJIT_ASSERT((inst[0] & 0x7f) == LUI && (inst[2] & 0x707f) == XORI); + + if ((new_constant & 0x800) != 0) + new_constant ^= ~(sljit_sw)0xfff; + + SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 0); + inst[0] = (sljit_u16)((inst[0] & 0xfff) | (new_constant & 0xf000)); + inst[1] = (sljit_u16)(new_constant >> 16); + inst[3] = (sljit_u16)(new_constant << 4) | (inst[3] & 0xf); + SLJIT_UPDATE_WX_FLAGS(inst, inst + 4, 1); + inst = (sljit_u16 *)SLJIT_ADD_EXEC_OFFSET(inst, executable_offset); + SLJIT_CACHE_FLUSH(inst, inst + 4); + return; +#endif /* SLJIT_CONFIG_RISCV_64 */ + + default: + sljit_set_jump_addr(addr, (sljit_uw)new_constant, executable_offset); + return; + } } diff --git a/sljit_src/sljitNativeX86_common.c b/sljit_src/sljitNativeX86_common.c index 4a465923..ae113f9b 100644 --- a/sljit_src/sljitNativeX86_common.c +++ b/sljit_src/sljitNativeX86_common.c @@ -974,7 +974,7 @@ SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compil break; default: SLJIT_ASSERT(len == SLJIT_INST_CONST); - const_->addr = ((sljit_uw)code_ptr) - sizeof(sljit_sw); + const_->addr = (sljit_uw)code_ptr; const_ = const_->next; break; } @@ -5027,46 +5027,90 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_get_local_base(struct sljit_compiler *c return emit_mov(compiler, dst, dstw, SLJIT_SP, 0); } -SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 dst, sljit_sw dstw, sljit_sw init_value) +SLJIT_API_FUNC_ATTRIBUTE struct sljit_const* sljit_emit_const(struct sljit_compiler *compiler, sljit_s32 op, + sljit_s32 dst, sljit_sw dstw, + sljit_sw init_value) { sljit_u8 *inst; struct sljit_const *const_; -#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) sljit_s32 reg; -#endif +#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) + sljit_s32 dst_is_ereg = 0; +#endif /* !SLJIT_CONFIG_X86_32 */ CHECK_ERROR_PTR(); - CHECK_PTR(check_sljit_emit_const(compiler, dst, dstw, init_value)); + CHECK_PTR(check_sljit_emit_const(compiler, op, dst, dstw, init_value)); ADJUST_LOCAL_OFFSET(dst, dstw); - CHECK_EXTRA_REGS(dst, dstw, (void)0); + CHECK_EXTRA_REGS(dst, dstw, dst_is_ereg = 1); const_ = (struct sljit_const*)ensure_abuf(compiler, sizeof(struct sljit_const)); PTR_FAIL_IF(!const_); set_const(const_, compiler); + switch (GET_OPCODE(op)) { + case SLJIT_MOV_U8: #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - compiler->mode32 = 0; - reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + compiler->mode32 = (op & SLJIT_32); +#endif /* SLJIT_CONFIG_X86_64 */ - if (emit_load_imm64(compiler, reg, init_value)) - return NULL; -#else - if (emit_mov(compiler, dst, dstw, SLJIT_IMM, init_value)) - return NULL; -#endif + if ((init_value & 0x100) != 0) + init_value = init_value | -(sljit_sw)0x100; + else + init_value = (sljit_u8)init_value; + +#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) + if (dst_is_ereg) { + if (emit_mov(compiler, dst, dstw, SLJIT_IMM, (sljit_s32)init_value)) + return NULL; + dst = 0; + break; + } +#endif /* !SLJIT_CONFIG_X86_32 */ + + reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + + if (emit_mov(compiler, reg, 0, SLJIT_IMM, init_value)) + return NULL; + break; +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + case SLJIT_MOV: + compiler->mode32 = 0; + reg = FAST_IS_REG(dst) ? dst : TMP_REG1; + + if (emit_load_imm64(compiler, reg, init_value)) + return NULL; + break; +#endif /* SLJIT_CONFIG_X86_64 */ + default: +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + compiler->mode32 = (op == SLJIT_MOV32); +#endif /* SLJIT_CONFIG_X86_64 */ + + if (emit_mov(compiler, dst, dstw, SLJIT_IMM, (sljit_s32)init_value)) + return NULL; + dst = 0; + break; + } inst = (sljit_u8*)ensure_buf(compiler, 1); PTR_FAIL_IF(!inst); inst[0] = SLJIT_INST_CONST; + if (dst & SLJIT_MEM) { #if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) - if (dst & SLJIT_MEM) - if (emit_mov(compiler, dst, dstw, TMP_REG1, 0)) - return NULL; + if (op == SLJIT_MOV) { + if (emit_mov(compiler, dst, dstw, TMP_REG1, 0)) + return NULL; + return const_; + } #endif + if (emit_mov_byte(compiler, 0, dst, dstw, TMP_REG1, 0)) + return NULL; + } + return const_; } @@ -5127,11 +5171,31 @@ SLJIT_API_FUNC_ATTRIBUTE void sljit_set_jump_addr(sljit_uw addr, sljit_uw new_ta SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + sizeof(sljit_uw)), 1); } -SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_sw new_constant, sljit_sw executable_offset) +SLJIT_API_FUNC_ATTRIBUTE void sljit_set_const(sljit_uw addr, sljit_s32 op, sljit_sw new_constant, sljit_sw executable_offset) { + void *start_addr; SLJIT_UNUSED_ARG(executable_offset); - SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + sizeof(sljit_sw)), 0); - sljit_unaligned_store_sw((void*)addr, new_constant); - SLJIT_UPDATE_WX_FLAGS((void*)addr, (void*)(addr + sizeof(sljit_sw)), 1); +#if (defined SLJIT_CONFIG_X86_64 && SLJIT_CONFIG_X86_64) + if (op == SLJIT_MOV) { + start_addr = (void*)(addr - sizeof(sljit_sw)); + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 0); + sljit_unaligned_store_sw(start_addr, new_constant); + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 1); + return; + } +#endif + + start_addr = (void*)(addr - sizeof(sljit_s32)); + + if ((op | SLJIT_32) == SLJIT_MOV32_U8) { + if ((new_constant & 0x100) != 0) + new_constant = new_constant | -(sljit_sw)0x100; + else + new_constant = (sljit_u8)new_constant; + } + + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 0); + sljit_unaligned_store_s32(start_addr, (sljit_s32)new_constant); + SLJIT_UPDATE_WX_FLAGS(start_addr, (void*)addr, 1); } diff --git a/test_src/sljitTest.c b/test_src/sljitTest.c index 5b3aea88..764b1ffe 100644 --- a/test_src/sljitTest.c +++ b/test_src/sljitTest.c @@ -1191,7 +1191,7 @@ static void test11(void) SLJIT_ASSERT(!sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw) + 1)); /* buf[0] */ - const1 = sljit_emit_const(compiler, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9); + const1 = sljit_emit_const(compiler, SLJIT_MOV, SLJIT_MEM0(), (sljit_sw)&buf[0], -0x81b9); value = sljit_alloc_memory(compiler, 16 * sizeof(sljit_sw)); if (value != NULL) @@ -1202,10 +1202,10 @@ static void test11(void) /* buf[1] */ sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, 2); - const2 = sljit_emit_const(compiler, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535); + const2 = sljit_emit_const(compiler, SLJIT_MOV, SLJIT_MEM2(SLJIT_S0, SLJIT_R0), SLJIT_WORD_SHIFT - 1, -65535); /* buf[2] */ sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R0, 0, SLJIT_R0, 0, SLJIT_IMM, (sljit_sw)&buf[0] + 2 * (sljit_sw)sizeof(sljit_sw) - 2); - const3 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_R0), 0, word_value1); + const3 = sljit_emit_const(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_R0), 0, word_value1); value = sljit_alloc_memory(compiler, 17); if (value != NULL) @@ -1215,7 +1215,7 @@ static void test11(void) } /* Return value */ - const4 = sljit_emit_const(compiler, SLJIT_RETURN_REG, 0, (sljit_sw)0xf7afcdb7); + const4 = sljit_emit_const(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0, (sljit_sw)0xf7afcdb7); sljit_emit_return(compiler, SLJIT_MOV, SLJIT_RETURN_REG, 0); @@ -1234,13 +1234,13 @@ static void test11(void) FAILED(buf[2] != word_value1, "test11 case 4 failed\n"); /* buf[0] */ - sljit_set_const(const1_addr, -1, executable_offset); + sljit_set_const(const1_addr, SLJIT_MOV, -1, executable_offset); /* buf[1] */ - sljit_set_const(const2_addr, word_value2, executable_offset); + sljit_set_const(const2_addr, SLJIT_MOV, word_value2, executable_offset); /* buf[2] */ - sljit_set_const(const3_addr, (sljit_sw)0xbab0fea1, executable_offset); + sljit_set_const(const3_addr, SLJIT_MOV, (sljit_sw)0xbab0fea1, executable_offset); /* Return vaue */ - sljit_set_const(const4_addr, -60089, executable_offset); + sljit_set_const(const4_addr, SLJIT_MOV, -60089, executable_offset); FAILED(code.func1((sljit_sw)&buf) != -60089, "test11 case 5 failed\n"); FAILED(buf[0] != -1, "test11 case 6 failed\n"); @@ -1374,7 +1374,7 @@ static void test13(void) mov_addr = sljit_emit_mov_addr(compiler, SLJIT_R2, 0); /* buf[0] */ - const1 = sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_S0), 0, -1234); + const1 = sljit_emit_const(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, -1234); sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_R2, 0); sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, -1234); @@ -1401,7 +1401,7 @@ static void test13(void) label_addr = sljit_get_label_addr(label); sljit_free_compiler(compiler); - sljit_set_const(const_addr, 87654, executable_offset); + sljit_set_const(const_addr, SLJIT_MOV, 87654, executable_offset); sljit_set_jump_addr(jump_addr, label_addr, executable_offset); code.func1((sljit_sw)&buf); @@ -2645,7 +2645,7 @@ static void test25(void) if (sljit_has_cpu_feature(SLJIT_HAS_MEMORY_BARRIER) != 0) SLJIT_ASSERT(sljit_emit_op0(compiler, SLJIT_MEMORY_BARRIER) != SLJIT_ERR_UNSUPPORTED); - const1 = sljit_emit_const(compiler, SLJIT_S3, 0, 0); + const1 = sljit_emit_const(compiler, SLJIT_MOV, SLJIT_S3, 0, 0); sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_S3, 0); sljit_emit_op2(compiler, SLJIT_SUB, SLJIT_S3, 0, SLJIT_S3, 0, SLJIT_IMM, 100); label = sljit_emit_label(compiler); @@ -2659,7 +2659,7 @@ static void test25(void) CHECK(compiler); label_addr = sljit_get_label_addr(label); - sljit_set_const(sljit_get_const_addr(const1), (sljit_sw)label_addr, sljit_get_executable_offset(compiler)); + sljit_set_const(sljit_get_const_addr(const1), SLJIT_MOV, (sljit_sw)label_addr, sljit_get_executable_offset(compiler)); sljit_free_compiler(compiler); @@ -3658,7 +3658,7 @@ static void test35(void) SLJIT_ASSERT(!jump); SLJIT_ASSERT(sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_MEM1(SLJIT_R0), 8) == -3967); SLJIT_ASSERT(sljit_emit_op_flags(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_OVERFLOW) == -3967); - SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_R0, 0, 99)); + SLJIT_ASSERT(!sljit_emit_const(compiler, SLJIT_MOV, SLJIT_R0, 0, 99)); SLJIT_ASSERT(!compiler->labels && !compiler->jumps && !compiler->consts); SLJIT_ASSERT(!compiler->last_label && !compiler->last_jump && !compiler->last_const); @@ -9498,6 +9498,136 @@ static void test77(void) successful_tests++; } +static void test78(void) +{ + /* Test op2cmp operation. */ + executable_code code; + struct sljit_compiler *compiler = sljit_create_compiler(NULL); + sljit_sw executable_offset; + sljit_s32 i; + struct sljit_const *consts[11]; + sljit_uw const_addr[11]; + sljit_sw buf[11]; + + if (verbose) + printf("Run test78\n"); + + for (i = 0; i < 11; i++) + buf[i] = -1; + +#if IS_64BIT + buf[10] = (sljit_sw)SLJIT_W(0xaaaaaaaaaaaaaaaa); +#endif /* IS_64BIT */ + + FAILED(!compiler, "cannot create compiler\n"); + + sljit_emit_enter(compiler, 0, SLJIT_ARGS1V(P), 5, 5, 2 * sizeof(sljit_sw)); + + consts[0] = sljit_emit_const(compiler, SLJIT_MOV_S32, SLJIT_S1, 0, WCONST(0xffff123456, 0xff123456)); + /* buf[0] */ + sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_S1, 0); + + /* buf[1] */ + consts[1] = sljit_emit_const(compiler, SLJIT_MOV_S32, SLJIT_MEM1(SLJIT_S0), sizeof(sljit_sw), WCONST(0xffabcdef01, 0xabcdef01)); + + consts[2] = sljit_emit_const(compiler, SLJIT_MOV32, SLJIT_R1, 0, WCONST(0xff1234567f, 0x1234567f)); + /* buf[2] */ + sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 2 * sizeof(sljit_sw), SLJIT_R1, 0); + + consts[3] = sljit_emit_const(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_SP), sizeof(sljit_s32), WCONST(0xffedcba987, 0xedcba987)); + /* buf[3] */ + sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 3 * sizeof(sljit_sw), SLJIT_MEM1(SLJIT_SP), sizeof(sljit_s32)); + + consts[4] = sljit_emit_const(compiler, SLJIT_MOV_U8, SLJIT_TMP_DEST_REG, 0, 0xaaaafe); + /* buf[4] */ + sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 4 * sizeof(sljit_sw), SLJIT_TMP_DEST_REG, 0); + + consts[5] = sljit_emit_const(compiler, SLJIT_MOV32_U8, SLJIT_S4, 0, 0xaaab14); + /* buf[5] */ + sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 5 * sizeof(sljit_sw), SLJIT_S4, 0); + + sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R1, 0, SLJIT_S0, 0); + sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R0, 0, SLJIT_IMM, (6 * sizeof(sljit_sw)) >> 1); + + /* buf[6] */ + consts[6] = sljit_emit_const(compiler, SLJIT_MOV_U8, SLJIT_MEM2(SLJIT_R1, SLJIT_R0), (1), 0xaaaac2); + + consts[7] = sljit_emit_const(compiler, SLJIT_MOV_U8, SLJIT_R4, 0, 0xaaaaff); + /* buf[7] */ + sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 7 * sizeof(sljit_sw), SLJIT_R4, 0); + + consts[8] = sljit_emit_const(compiler, SLJIT_MOV32_U8, SLJIT_R0, 0, 0xaaab00); + /* buf[8] */ + sljit_emit_op1(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 8 * sizeof(sljit_sw), SLJIT_R0, 0); + + /* buf[9] */ + consts[9] = sljit_emit_const(compiler, SLJIT_MOV32_U8, SLJIT_MEM0(), (sljit_sw)(buf + 9), 0xaaaaa0); + + /* buf[10] */ + consts[10] = sljit_emit_const(compiler, SLJIT_MOV32, SLJIT_MEM1(SLJIT_S0), 10 * sizeof(sljit_sw), WCONST(0xcc12345678, 0x12345678)); + + sljit_emit_return_void(compiler); + + code.code = sljit_generate_code(compiler, 0, NULL); + CHECK(compiler); + executable_offset = sljit_get_executable_offset(compiler); + for (i = 0; i < 11; i++) + const_addr[i] = sljit_get_const_addr(consts[i]); + + sljit_free_compiler(compiler); + + code.func1((sljit_sw)&buf); + + FAILED(buf[0] != (sljit_s32)0xff123456, "test78 case 1 failed\n"); + FAILED(buf[1] != (sljit_s32)0xabcdef01, "test78 case 2 failed\n"); + FAILED(*(sljit_s32*)(buf + 2) != (sljit_s32)0x1234567f, "test78 case 3 failed\n"); + FAILED(*(sljit_s32*)(buf + 3) != (sljit_s32)0xedcba987, "test78 case 4 failed\n"); + FAILED(buf[4] != 0xfe, "test78 case 5 failed\n"); + FAILED(*(sljit_s32*)(buf + 5) != -0xec, "test78 case 6 failed\n"); + FAILED(*(sljit_u16*)(buf + 6) != LITTLE_BIG(0xffc2, 0xc2ff), "test78 case 7 failed\n"); + FAILED(buf[7] != 0xff, "test78 case 8 failed\n"); + FAILED(*(sljit_s32*)(buf + 8) != -0x100, "test78 case 9 failed\n"); + FAILED(*(sljit_u16*)(buf + 9) != LITTLE_BIG(0xffa0, 0xa0ff), "test78 case 10 failed\n"); +#if IS_64BIT + FAILED(buf[10] != (sljit_sw)LITTLE_BIG(SLJIT_W(0xaaaaaaaa12345678), SLJIT_W(0x12345678aaaaaaaa)), "test78 case 11 failed\n"); +#else /* !IS_64BIT */ + FAILED(buf[10] != (sljit_sw)0x12345678, "test78 case 11 failed\n"); +#endif /* IS_64BIT */ + + sljit_set_const(const_addr[0], SLJIT_MOV_S32, WCONST(0xffff654321, 0xff654321), executable_offset); + sljit_set_const(const_addr[1], SLJIT_MOV_S32, WCONST(0xff01fedcba, 0x01fedcba), executable_offset); + sljit_set_const(const_addr[2], SLJIT_MOV32, WCONST(0xfff7654321, 0xf7654321), executable_offset); + sljit_set_const(const_addr[3], SLJIT_MOV32, WCONST(0xff789abcde, 0x789abcde), executable_offset); + sljit_set_const(const_addr[4], SLJIT_MOV_U8, 0xbbbeff, executable_offset); + sljit_set_const(const_addr[5], SLJIT_MOV32_U8, 0xbbb100, executable_offset); + sljit_set_const(const_addr[6], SLJIT_MOV_U8, 0xaaaa93, executable_offset); + sljit_set_const(const_addr[7], SLJIT_MOV_U8, 0xbbbf39, executable_offset); + sljit_set_const(const_addr[8], SLJIT_MOV32_U8, 0xaaaa6c, executable_offset); + sljit_set_const(const_addr[9], SLJIT_MOV32_U8, 0xaaaa53, executable_offset); + sljit_set_const(const_addr[10], SLJIT_MOV32, WCONST(0xee87654321, 0x87654321), executable_offset); + + code.func1((sljit_sw)&buf); + + FAILED(buf[0] != (sljit_s32)0xff654321, "test78 case 12 failed\n"); + FAILED(buf[1] != (sljit_s32)0x01fedcba, "test78 case 13 failed\n"); + FAILED(*(sljit_s32*)(buf + 2) != (sljit_s32)0xf7654321, "test78 case 14 failed\n"); + FAILED(*(sljit_s32*)(buf + 3) != (sljit_s32)0x789abcde, "test78 case 15 failed\n"); + FAILED(buf[4] != 0xff, "test78 case 16 failed\n"); + FAILED(*(sljit_s32*)(buf + 5) != -0x100, "test78 case 17 failed\n"); + FAILED(*(sljit_u16*)(buf + 6) != LITTLE_BIG(0xff93, 0x93ff), "test78 case 18 failed\n"); + FAILED(buf[7] != -0xc7, "test78 case 19 failed\n"); + FAILED(*(sljit_s32*)(buf + 8) != 0x6c, "test78 case 20 failed\n"); + FAILED(*(sljit_u16*)(buf + 9) != LITTLE_BIG(0xff53, 0x53ff), "test78 case 21 failed\n"); +#if IS_64BIT + FAILED(buf[10] != (sljit_sw)LITTLE_BIG(SLJIT_W(0xaaaaaaaa87654321), SLJIT_W(0x87654321aaaaaaaa)), "test78 case 22 failed\n"); +#else /* !IS_64BIT */ + FAILED(buf[10] != (sljit_sw)0x87654321, "test78 case 22 failed\n"); +#endif /* IS_64BIT */ + + sljit_free_code(code.code, NULL); + successful_tests++; +} + #include "sljitTestCall.h" #include "sljitTestFloat.h" #include "sljitTestSimd.h" @@ -9593,6 +9723,7 @@ int sljit_test(int argc, char* argv[]) test75(); test76(); test77(); + test78(); if (verbose) printf("---- Call tests ----\n"); @@ -9674,7 +9805,7 @@ int sljit_test(int argc, char* argv[]) sljit_free_unused_memory_exec(); #endif /* SLJIT_EXECUTABLE_ALLOCATOR */ -# define TEST_COUNT 127 +# define TEST_COUNT 128 printf("SLJIT tests: "); if (successful_tests == TEST_COUNT) diff --git a/test_src/sljitTestSerialize.h b/test_src/sljitTestSerialize.h index 5bb9f61a..3d2e42d0 100644 --- a/test_src/sljitTestSerialize.h +++ b/test_src/sljitTestSerialize.h @@ -61,7 +61,7 @@ static void test_serialize1(void) mov_addr = sljit_emit_mov_addr(compiler, SLJIT_R2, 0); /* buf[0] */ - sljit_emit_const(compiler, SLJIT_MEM1(SLJIT_S0), 0, -1234); + sljit_emit_const(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, -1234); sljit_emit_ijump(compiler, SLJIT_JUMP, SLJIT_R2, 0); sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_S0), 0, SLJIT_IMM, -1234); @@ -119,7 +119,7 @@ static void test_serialize1(void) label_addr = sljit_get_label_addr(label); sljit_free_compiler(compiler); - sljit_set_const(const_addr, 87654, executable_offset); + sljit_set_const(const_addr, SLJIT_MOV, 87654, executable_offset); sljit_set_jump_addr(jump_addr, label_addr, executable_offset); code.func1((sljit_sw)&buf); @@ -275,7 +275,7 @@ static void test_serialize3(void) sljit_emit_enter(compiler, 0, SLJIT_ARGS1V(P), 3, 3, 32); sljit_emit_mov_addr(compiler, SLJIT_R0, 0); - sljit_emit_const(compiler, SLJIT_R1, 0, 0); + sljit_emit_const(compiler, SLJIT_MOV, SLJIT_R1, 0, 0); sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_R2, 0, SLJIT_S0, 0); jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3V(W, W, W)); /* buf[0], buf[1] */ @@ -291,7 +291,7 @@ static void test_serialize3(void) FAILED(!compiler, "cannot deserialize compiler\n"); sljit_emit_mov_addr(compiler, SLJIT_R0, 0); - sljit_emit_const(compiler, SLJIT_R1, 0, 0); + sljit_emit_const(compiler, SLJIT_MOV, SLJIT_R1, 0, 0); sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S0, 0, SLJIT_IMM, 2 * sizeof(sljit_sw)); jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3V(W, W, W)); /* buf[2], buf[3] */ @@ -307,7 +307,7 @@ static void test_serialize3(void) FAILED(!compiler, "cannot deserialize compiler\n"); sljit_emit_mov_addr(compiler, SLJIT_R0, 0); - sljit_emit_const(compiler, SLJIT_R1, 0, 0); + sljit_emit_const(compiler, SLJIT_MOV, SLJIT_R1, 0, 0); sljit_emit_op2(compiler, SLJIT_ADD, SLJIT_R2, 0, SLJIT_S0, 0, SLJIT_IMM, 4 * sizeof(sljit_sw)); jump = sljit_emit_call(compiler, SLJIT_CALL, SLJIT_ARGS3V(W, W, W)); /* buf[4], buf[5] */ @@ -342,11 +342,11 @@ static void test_serialize3(void) executable_offset = sljit_get_executable_offset(compiler); const_ = sljit_get_first_const(compiler); - sljit_set_const(sljit_get_const_addr(const_), 0x5678, executable_offset); + sljit_set_const(sljit_get_const_addr(const_), SLJIT_MOV, 0x5678, executable_offset); const_ = sljit_get_next_const(const_); - sljit_set_const(sljit_get_const_addr(const_), -0x9876, executable_offset); + sljit_set_const(sljit_get_const_addr(const_), SLJIT_MOV, -0x9876, executable_offset); const_ = sljit_get_next_const(const_); - sljit_set_const(sljit_get_const_addr(const_), 0x2345, executable_offset); + sljit_set_const(sljit_get_const_addr(const_), SLJIT_MOV, 0x2345, executable_offset); SLJIT_ASSERT(sljit_get_next_const(const_) == NULL); label_addr = (sljit_sw)sljit_get_label_addr(label);