summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--py/asmrv32.h2
-rw-r--r--py/emitnative.c15
2 files changed, 12 insertions, 5 deletions
diff --git a/py/asmrv32.h b/py/asmrv32.h
index 584e3ffd2..b09f48eb1 100644
--- a/py/asmrv32.h
+++ b/py/asmrv32.h
@@ -694,6 +694,7 @@ static inline void asm_rv32_opcode_xori(asm_rv32_t *state, mp_uint_t rd, mp_uint
#define REG_LOCAL_1 ASM_RV32_REG_S3
#define REG_LOCAL_2 ASM_RV32_REG_S4
#define REG_LOCAL_3 ASM_RV32_REG_S5
+#define REG_ZERO ASM_RV32_REG_ZERO
void asm_rv32_meta_comparison_eq(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2, mp_uint_t rd);
void asm_rv32_meta_comparison_ne(asm_rv32_t *state, mp_uint_t rs1, mp_uint_t rs2, mp_uint_t rd);
@@ -756,6 +757,7 @@ void asm_rv32_emit_store_reg_reg_offset(asm_rv32_t *state, mp_uint_t source, mp_
#define ASM_STORE_REG_REG(state, rs1, rs2) ASM_STORE32_REG_REG(state, rs1, rs2)
#define ASM_SUB_REG_REG(state, rd, rs) asm_rv32_opcode_sub(state, rd, rd, rs)
#define ASM_XOR_REG_REG(state, rd, rs) asm_rv32_emit_optimised_xor(state, rd, rs)
+#define ASM_CLR_REG(state, rd)
#endif
diff --git a/py/emitnative.c b/py/emitnative.c
index 7d856e13f..f846e8bb4 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -288,6 +288,11 @@ struct _emit_t {
ASM_T *as;
};
+#ifndef REG_ZERO
+#define REG_ZERO REG_TEMP0
+#define ASM_CLR_REG(state, rd) ASM_XOR_REG_REG(state, rd, rd)
+#endif
+
static void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj);
static void emit_native_global_exc_entry(emit_t *emit);
static void emit_native_global_exc_exit(emit_t *emit);
@@ -1200,12 +1205,12 @@ static void emit_native_global_exc_entry(emit_t *emit) {
ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, start_label, true);
} else {
// Clear the unwind state
- ASM_XOR_REG_REG(emit->as, REG_TEMP0, REG_TEMP0);
- ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_UNWIND(emit), REG_TEMP0);
+ ASM_CLR_REG(emit->as, REG_ZERO);
+ ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_UNWIND(emit), REG_ZERO);
// clear nlr.ret_val, because it's passed to mp_native_raise regardless
// of whether there was an exception or not
- ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_VAL(emit), REG_TEMP0);
+ ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_VAL(emit), REG_ZERO);
// Put PC of start code block into REG_LOCAL_1
ASM_MOV_REG_PCREL(emit->as, REG_LOCAL_1, start_label);
@@ -1221,8 +1226,8 @@ static void emit_native_global_exc_entry(emit_t *emit) {
ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, global_except_label, true);
// Clear PC of current code block, and jump there to resume execution
- ASM_XOR_REG_REG(emit->as, REG_TEMP0, REG_TEMP0);
- ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_PC(emit), REG_TEMP0);
+ ASM_CLR_REG(emit->as, REG_ZERO);
+ ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_PC(emit), REG_ZERO);
ASM_JUMP_REG(emit->as, REG_LOCAL_1);
// Global exception handler: check for valid exception handler