Skip to content

Commit c0bcf00

Browse files
committed
py/asm*.c: Remove unnecessary check for num_locals<0 in asm entry func.
All callers of the asm entry function guarantee that num_locals>=0, so no need to add an explicit check for it. Use an assertion instead. Also, the signature of asm_x86_entry is changed to match the other asm entry functions.
1 parent 7dfa56e commit c0bcf00

5 files changed

Lines changed: 7 additions & 12 deletions

File tree

py/asmarm.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,7 @@ void asm_arm_bkpt(asm_arm_t *as) {
150150
// | low address | high address in RAM
151151

152152
void asm_arm_entry(asm_arm_t *as, int num_locals) {
153-
154-
if (num_locals < 0) {
155-
num_locals = 0;
156-
}
153+
assert(num_locals >= 0);
157154

158155
as->stack_adjust = 0;
159156
as->push_reglist = 1 << ASM_ARM_REG_R1

py/asmthumb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,15 @@ STATIC void asm_thumb_write_word32(asm_thumb_t *as, int w32) {
104104
// | low address | high address in RAM
105105

106106
void asm_thumb_entry(asm_thumb_t *as, int num_locals) {
107+
assert(num_locals >= 0);
108+
107109
// work out what to push and how many extra spaces to reserve on stack
108110
// so that we have enough for all locals and it's aligned an 8-byte boundary
109111
// we push extra regs (r1, r2, r3) to help do the stack adjustment
110112
// we probably should just always subtract from sp, since this would be more efficient
111113
// for push rlist, lowest numbered register at the lowest address
112114
uint reglist;
113115
uint stack_adjust;
114-
if (num_locals < 0) {
115-
num_locals = 0;
116-
}
117116
// don't pop r0 because it's used for return value
118117
switch (num_locals) {
119118
case 0:

py/asmx64.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,11 +526,9 @@ void asm_x64_jcc_label(asm_x64_t *as, int jcc_type, mp_uint_t label) {
526526
}
527527

528528
void asm_x64_entry(asm_x64_t *as, int num_locals) {
529+
assert(num_locals >= 0);
529530
asm_x64_push_r64(as, ASM_X64_REG_RBP);
530531
asm_x64_mov_r64_r64(as, ASM_X64_REG_RBP, ASM_X64_REG_RSP);
531-
if (num_locals < 0) {
532-
num_locals = 0;
533-
}
534532
num_locals |= 1; // make it odd so stack is aligned on 16 byte boundary
535533
asm_x64_sub_r64_i32(as, ASM_X64_REG_RSP, num_locals * WORD_SIZE);
536534
asm_x64_push_r64(as, ASM_X64_REG_RBX);

py/asmx86.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ void asm_x86_jcc_label(asm_x86_t *as, mp_uint_t jcc_type, mp_uint_t label) {
387387
}
388388
}
389389

390-
void asm_x86_entry(asm_x86_t *as, mp_uint_t num_locals) {
390+
void asm_x86_entry(asm_x86_t *as, int num_locals) {
391+
assert(num_locals >= 0);
391392
asm_x86_push_r32(as, ASM_X86_REG_EBP);
392393
asm_x86_mov_r32_r32(as, ASM_X86_REG_EBP, ASM_X86_REG_ESP);
393394
if (num_locals > 0) {

py/asmx86.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void asm_x86_test_r8_with_r8(asm_x86_t* as, int src_r32_a, int src_r32_b);
104104
void asm_x86_setcc_r8(asm_x86_t* as, mp_uint_t jcc_type, int dest_r8);
105105
void asm_x86_jmp_label(asm_x86_t* as, mp_uint_t label);
106106
void asm_x86_jcc_label(asm_x86_t* as, mp_uint_t jcc_type, mp_uint_t label);
107-
void asm_x86_entry(asm_x86_t* as, mp_uint_t num_locals);
107+
void asm_x86_entry(asm_x86_t* as, int num_locals);
108108
void asm_x86_exit(asm_x86_t* as);
109109
void asm_x86_mov_arg_to_r32(asm_x86_t *as, int src_arg_num, int dest_r32);
110110
void asm_x86_mov_local_to_r32(asm_x86_t* as, int src_local_num, int dest_r32);

0 commit comments

Comments
 (0)