summaryrefslogtreecommitdiff
path: root/py/emitnative.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-08-04 22:03:49 +1000
committerDamien George <damien.p.george@gmail.com>2018-08-04 22:03:49 +1000
commit10830059c5d3651abdb2d3532b28a9bb0a9425ee (patch)
treedb4c54f5f9d54d5833546e345c23f08f1adc1df0 /py/emitnative.c
parent4b1e8bdebdf5feb48a51dbf1e584735395069384 (diff)
py/emitnative: Fix x86 native zero checks by comparing full word.
On x86 archs (both 32 and 64 bit) a bool return value only sets the 8-bit al register, and the higher bits of the ax register have an undefined value. When testing the return value of such cases it is required to just test al for zero/non-zero. On the other hand, checking for truth or zero/non-zero on an integer return value requires checking all bits of the register. These two cases must be distinguished and handled correctly in generated native code. This patch makes sure of this. For other supported native archs (ARM, Thumb2, Xtensa) there is no such distinction and this patch does not change anything for them.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 00d322d75..7071062a7 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1547,9 +1547,9 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bo
need_stack_settled(emit);
// Emit the jump
if (cond) {
- ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label, vtype == VTYPE_PYOBJ);
} else {
- ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label, vtype == VTYPE_PYOBJ);
}
if (!pop) {
adjust_stack(emit, -1);
@@ -1607,7 +1607,7 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
need_stack_settled(emit);
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf
emit_call(emit, MP_F_NLR_PUSH);
- ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label, true);
emit_access_stack(emit, sizeof(nlr_buf_t) / sizeof(mp_uint_t) + 1, &vtype, REG_RET); // access return value of __enter__
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // push return value of __enter__
@@ -1624,7 +1624,7 @@ STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) {
need_stack_settled(emit);
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf
emit_call(emit, MP_F_NLR_PUSH);
- ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label, true);
emit_post(emit);
}
}
@@ -1688,7 +1688,7 @@ STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) {
ASM_MOV_REG_REG(emit->as, REG_ARG_1, REG_RET);
}
emit_call(emit, MP_F_OBJ_IS_TRUE);
- ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label + 1);
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label + 1, true);
// replace exc with None
emit_pre_pop_discard(emit);
@@ -1736,7 +1736,7 @@ STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) {
emit_call(emit, MP_F_NATIVE_ITERNEXT);
#ifdef NDEBUG
MP_STATIC_ASSERT(MP_OBJ_STOP_ITERATION == 0);
- ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label, false);
#else
ASM_MOV_REG_IMM(emit->as, REG_TEMP1, (mp_uint_t)MP_OBJ_STOP_ITERATION);
ASM_JUMP_IF_REG_EQ(emit->as, REG_RET, REG_TEMP1, label);