Skip to content

Commit 25d9041

Browse files
committed
py: Adjust regs for x86 so that 1 more local can live in a reg.
1 parent 91fe0d4 commit 25d9041

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

py/asmx86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,9 @@ void asm_x86_jcc_label(asm_x86_t *as, mp_uint_t jcc_type, mp_uint_t label) {
413413
void asm_x86_entry(asm_x86_t *as, mp_uint_t num_locals) {
414414
asm_x86_push_r32(as, REG_EBP);
415415
asm_x86_mov_r32_to_r32(as, REG_ESP, REG_EBP);
416-
asm_x86_sub_i32_from_r32(as, num_locals * WORD_SIZE, REG_ESP);
416+
if (num_locals > 0) {
417+
asm_x86_sub_i32_from_r32(as, num_locals * WORD_SIZE, REG_ESP);
418+
}
417419
asm_x86_push_r32(as, REG_EBX);
418420
asm_x86_push_r32(as, REG_ESI);
419421
asm_x86_push_r32(as, REG_EDI);

py/asmx86.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#define ASM_X86_CC_JL (0xc) // less, signed
5454

5555
#define REG_RET REG_EAX
56-
#define REG_ARG_1 REG_EBX
56+
#define REG_ARG_1 REG_EAX
5757
#define REG_ARG_2 REG_ECX
5858
#define REG_ARG_3 REG_EDX
5959

py/emitnative.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,16 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
189189

190190
#define EXPORT_FUN(name) emit_native_x86_##name
191191

192+
// caller-save, so can be used as temporaries
192193
#define REG_TEMP0 (REG_EAX)
193-
#define REG_TEMP1 (REG_EBX)
194-
#define REG_TEMP2 (REG_ECX)
194+
#define REG_TEMP1 (REG_ECX)
195+
#define REG_TEMP2 (REG_EDX)
195196

196-
#define REG_LOCAL_1 (REG_ESI)
197-
#define REG_LOCAL_2 (REG_EDI)
198-
#define REG_LOCAL_NUM (2)
197+
// callee-save, so can be used as locals
198+
#define REG_LOCAL_1 (REG_EBX)
199+
#define REG_LOCAL_2 (REG_ESI)
200+
#define REG_LOCAL_3 (REG_EDI)
201+
#define REG_LOCAL_NUM (3)
199202

200203
#define ASM_PASS_COMPUTE ASM_X86_PASS_COMPUTE
201204
#define ASM_PASS_EMIT ASM_X86_PASS_EMIT
@@ -528,6 +531,8 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
528531
asm_x86_mov_arg_to_r32(emit->as, i, REG_LOCAL_1);
529532
} else if (i == 1) {
530533
asm_x86_mov_arg_to_r32(emit->as, i, REG_LOCAL_2);
534+
} else if (i == 2) {
535+
asm_x86_mov_arg_to_r32(emit->as, i, REG_LOCAL_3);
531536
} else {
532537
asm_x86_mov_arg_to_r32(emit->as, i, REG_TEMP0);
533538
asm_x86_mov_r32_to_local(emit->as, REG_TEMP0, i - REG_LOCAL_NUM);
@@ -1022,6 +1027,8 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qstr, uint id_flags, int lo
10221027
emit_post_push_reg(emit, vtype, REG_LOCAL_1);
10231028
} else if (local_num == 1) {
10241029
emit_post_push_reg(emit, vtype, REG_LOCAL_2);
1030+
} else if (local_num == 2) {
1031+
emit_post_push_reg(emit, vtype, REG_LOCAL_3);
10251032
} else {
10261033
need_reg_single(emit, REG_EAX, 0);
10271034
asm_x86_mov_local_to_r32(emit->as, local_num - REG_LOCAL_NUM, REG_EAX);
@@ -1125,6 +1132,8 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
11251132
emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
11261133
} else if (local_num == 1) {
11271134
emit_pre_pop_reg(emit, &vtype, REG_LOCAL_2);
1135+
} else if (local_num == 2) {
1136+
emit_pre_pop_reg(emit, &vtype, REG_LOCAL_3);
11281137
} else {
11291138
emit_pre_pop_reg(emit, &vtype, REG_EAX);
11301139
asm_x86_mov_r32_to_local(emit->as, REG_EAX, local_num - REG_LOCAL_NUM);

0 commit comments

Comments
 (0)