mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/emitnative: Clean up int-indexed Viper load/store code.
This commit performs some minor clean up for the code involved in Viper load/store operations when said operations have an integer index. Most platform-specific code blocks were able to generate correct opcodes even when the index is 0, but they would still fall back to the general case. The general case would still emit a shortened opcode sequence so this commit does not alter the overall behaviour, but makes it easier to extend platform-specific code whenever the full index range is going to be handled rather than a subset of indices as it is now. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
@@ -1537,11 +1537,8 @@ static void emit_native_load_subscr(emit_t *emit) {
|
||||
switch (vtype_base) {
|
||||
case VTYPE_PTR8: {
|
||||
// pointer to 8-bit memory
|
||||
// TODO optimise to use thumb ldrb r1, [r2, r3]
|
||||
if (index_value != 0) {
|
||||
// index is non-zero
|
||||
#if N_THUMB
|
||||
if (index_value > 0 && index_value < 32) {
|
||||
if (index_value >= 0 && index_value < 32) {
|
||||
asm_thumb_ldrb_rlo_rlo_i5(emit->as, REG_RET, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
@@ -1551,11 +1548,13 @@ static void emit_native_load_subscr(emit_t *emit) {
|
||||
break;
|
||||
}
|
||||
#elif N_XTENSA || N_XTENSAWIN
|
||||
if (index_value > 0 && index_value < 256) {
|
||||
if (index_value >= 0 && index_value < 256) {
|
||||
asm_xtensa_op_l8ui(emit->as, REG_RET, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (index_value != 0) {
|
||||
// index is non-zero
|
||||
need_reg_single(emit, reg_index, 0);
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value);
|
||||
ASM_ADD_REG_REG(emit->as, reg_index, reg_base); // add index to base
|
||||
@@ -1566,10 +1565,8 @@ static void emit_native_load_subscr(emit_t *emit) {
|
||||
}
|
||||
case VTYPE_PTR16: {
|
||||
// pointer to 16-bit memory
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
#if N_THUMB
|
||||
if (index_value > 0 && index_value < 32) {
|
||||
if (index_value >= 0 && index_value < 32) {
|
||||
asm_thumb_ldrh_rlo_rlo_i5(emit->as, REG_RET, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
@@ -1579,11 +1576,13 @@ static void emit_native_load_subscr(emit_t *emit) {
|
||||
break;
|
||||
}
|
||||
#elif N_XTENSA || N_XTENSAWIN
|
||||
if (index_value > 0 && index_value < 256) {
|
||||
if (index_value >= 0 && index_value < 256) {
|
||||
asm_xtensa_op_l16ui(emit->as, REG_RET, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
need_reg_single(emit, reg_index, 0);
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value << 1);
|
||||
ASM_ADD_REG_REG(emit->as, reg_index, reg_base); // add 2*index to base
|
||||
@@ -1594,10 +1593,8 @@ static void emit_native_load_subscr(emit_t *emit) {
|
||||
}
|
||||
case VTYPE_PTR32: {
|
||||
// pointer to 32-bit memory
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
#if N_THUMB
|
||||
if (index_value > 0 && index_value < 32) {
|
||||
if (index_value >= 0 && index_value < 32) {
|
||||
asm_thumb_ldr_rlo_rlo_i5(emit->as, REG_RET, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
@@ -1607,11 +1604,13 @@ static void emit_native_load_subscr(emit_t *emit) {
|
||||
break;
|
||||
}
|
||||
#elif N_XTENSA || N_XTENSAWIN
|
||||
if (index_value > 0 && index_value < 256) {
|
||||
if (index_value >= 0 && index_value < 256) {
|
||||
asm_xtensa_l32i_optimised(emit->as, REG_RET, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
need_reg_single(emit, reg_index, 0);
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value << 2);
|
||||
ASM_ADD_REG_REG(emit->as, reg_index, reg_base); // add 4*index to base
|
||||
@@ -1811,10 +1810,8 @@ static void emit_native_store_subscr(emit_t *emit) {
|
||||
case VTYPE_PTR8: {
|
||||
// pointer to 8-bit memory
|
||||
// TODO optimise to use thumb strb r1, [r2, r3]
|
||||
if (index_value != 0) {
|
||||
// index is non-zero
|
||||
#if N_THUMB
|
||||
if (index_value > 0 && index_value < 32) {
|
||||
if (index_value >= 0 && index_value < 32) {
|
||||
asm_thumb_strb_rlo_rlo_i5(emit->as, reg_value, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
@@ -1824,15 +1821,17 @@ static void emit_native_store_subscr(emit_t *emit) {
|
||||
break;
|
||||
}
|
||||
#elif N_XTENSA || N_XTENSAWIN
|
||||
if (index_value > 0 && index_value < 256) {
|
||||
asm_xtensa_op_s8i(emit->as, REG_RET, reg_base, index_value);
|
||||
if (index_value >= 0 && index_value < 256) {
|
||||
asm_xtensa_op_s8i(emit->as, reg_value, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (index_value != 0) {
|
||||
// index is non-zero
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value);
|
||||
#if N_ARM
|
||||
asm_arm_strb_reg_reg_reg(emit->as, reg_value, reg_base, reg_index);
|
||||
return;
|
||||
break;
|
||||
#endif
|
||||
ASM_ADD_REG_REG(emit->as, reg_index, reg_base); // add index to base
|
||||
reg_base = reg_index;
|
||||
@@ -1842,10 +1841,8 @@ static void emit_native_store_subscr(emit_t *emit) {
|
||||
}
|
||||
case VTYPE_PTR16: {
|
||||
// pointer to 16-bit memory
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
#if N_THUMB
|
||||
if (index_value > 0 && index_value < 32) {
|
||||
if (index_value >= 0 && index_value < 32) {
|
||||
asm_thumb_strh_rlo_rlo_i5(emit->as, reg_value, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
@@ -1855,11 +1852,13 @@ static void emit_native_store_subscr(emit_t *emit) {
|
||||
break;
|
||||
}
|
||||
#elif N_XTENSA || N_XTENSAWIN
|
||||
if (index_value > 0 && index_value < 256) {
|
||||
asm_xtensa_op_s16i(emit->as, REG_RET, reg_base, index_value);
|
||||
if (index_value >= 0 && index_value < 256) {
|
||||
asm_xtensa_op_s16i(emit->as, reg_value, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value << 1);
|
||||
ASM_ADD_REG_REG(emit->as, reg_index, reg_base); // add 2*index to base
|
||||
reg_base = reg_index;
|
||||
@@ -1869,10 +1868,8 @@ static void emit_native_store_subscr(emit_t *emit) {
|
||||
}
|
||||
case VTYPE_PTR32: {
|
||||
// pointer to 32-bit memory
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
#if N_THUMB
|
||||
if (index_value > 0 && index_value < 32) {
|
||||
if (index_value >= 0 && index_value < 32) {
|
||||
asm_thumb_str_rlo_rlo_i5(emit->as, reg_value, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
@@ -1882,14 +1879,17 @@ static void emit_native_store_subscr(emit_t *emit) {
|
||||
break;
|
||||
}
|
||||
#elif N_XTENSA || N_XTENSAWIN
|
||||
if (index_value > 0 && index_value < 256) {
|
||||
asm_xtensa_s32i_optimised(emit->as, REG_RET, reg_base, index_value);
|
||||
if (index_value >= 0 && index_value < 256) {
|
||||
asm_xtensa_s32i_optimised(emit->as, reg_value, reg_base, index_value);
|
||||
break;
|
||||
}
|
||||
#elif N_ARM
|
||||
#endif
|
||||
if (index_value != 0) {
|
||||
// index is a non-zero immediate
|
||||
#if N_ARM
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value);
|
||||
asm_arm_str_reg_reg_reg(emit->as, reg_value, reg_base, reg_index);
|
||||
return;
|
||||
break;
|
||||
#endif
|
||||
ASM_MOV_REG_IMM(emit->as, reg_index, index_value << 2);
|
||||
ASM_ADD_REG_REG(emit->as, reg_index, reg_base); // add 4*index to base
|
||||
|
||||
Reference in New Issue
Block a user