Skip to content

Commit 351424e

Browse files
pfalcondpgeorge
authored andcommitted
emitnative: Revamp ARM codegen compile after full-arg support refactors.
The code was apparently broken after 9988618 "py: Implement full func arg passing for native emitter.". This attempts to propagate those changes to ARM emitter.
1 parent d792d9e commit 351424e

3 files changed

Lines changed: 41 additions & 10 deletions

File tree

py/asmarm.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ STATIC byte *asm_arm_get_cur_to_write_bytes(asm_arm_t *as, int num_bytes_to_writ
111111
}
112112
}
113113

114+
uint asm_arm_get_code_pos(asm_arm_t *as) {
115+
return as->code_offset;
116+
}
117+
114118
uint asm_arm_get_code_size(asm_arm_t *as) {
115119
return as->code_size;
116120
}
@@ -245,6 +249,14 @@ void asm_arm_exit(asm_arm_t *as) {
245249
emit_al(as, asm_arm_op_pop(as->push_reglist | (1 << ASM_ARM_REG_PC)));
246250
}
247251

252+
void asm_arm_push(asm_arm_t *as, uint reglist) {
253+
emit_al(as, asm_arm_op_push(reglist));
254+
}
255+
256+
void asm_arm_pop(asm_arm_t *as, uint reglist) {
257+
emit_al(as, asm_arm_op_pop(reglist));
258+
}
259+
248260
void asm_arm_label_assign(asm_arm_t *as, uint label) {
249261
assert(label < as->max_num_labels);
250262
if (as->pass < ASM_ARM_PASS_EMIT) {
@@ -358,9 +370,9 @@ void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs) {
358370
emit_al(as, 0x1a00050 | (rd << 12) | (rs << 8) | rd);
359371
}
360372

361-
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn) {
362-
// ldr rd, [rn]
363-
emit_al(as, 0x5900000 | (rn << 16) | (rd << 12));
373+
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset) {
374+
// ldr rd, [rn, #off]
375+
emit_al(as, 0x5900000 | (rn << 16) | (rd << 12) | byte_offset);
364376
}
365377

366378
void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn) {
@@ -373,9 +385,9 @@ void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn) {
373385
emit_al(as, 0x5d00000 | (rn << 16) | (rd << 12));
374386
}
375387

376-
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm) {
377-
// str rd, [rm]
378-
emit_al(as, 0x5800000 | (rm << 16) | (rd << 12));
388+
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset) {
389+
// str rd, [rm, #off]
390+
emit_al(as, 0x5800000 | (rm << 16) | (rd << 12) | byte_offset);
379391
}
380392

381393
void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm) {

py/asmarm.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ asm_arm_t *asm_arm_new(uint max_num_labels);
7474
void asm_arm_free(asm_arm_t *as, bool free_code);
7575
void asm_arm_start_pass(asm_arm_t *as, uint pass);
7676
void asm_arm_end_pass(asm_arm_t *as);
77+
uint asm_arm_get_code_pos(asm_arm_t *as);
7778
uint asm_arm_get_code_size(asm_arm_t *as);
7879
void *asm_arm_get_code(asm_arm_t *as);
7980

@@ -108,17 +109,21 @@ void asm_arm_lsl_reg_reg(asm_arm_t *as, uint rd, uint rs);
108109
void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs);
109110

110111
// memory
111-
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn);
112+
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset);
112113
void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn);
113114
void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn);
114-
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm);
115+
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset);
115116
void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm);
116117
void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm);
117118
// store to array
118119
void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
119120
void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
120121
void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
121122

123+
// stack
124+
void asm_arm_push(asm_arm_t *as, uint reglist);
125+
void asm_arm_pop(asm_arm_t *as, uint reglist);
126+
122127
// control flow
123128
void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label);
124129
void asm_arm_b_label(asm_arm_t *as, uint label);

py/emitnative.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
399399

400400
#include "py/asmarm.h"
401401

402+
#define ASM_WORD_SIZE (4)
403+
402404
#define EXPORT_FUN(name) emit_native_arm_##name
403405

404406
#define REG_RET ASM_ARM_REG_R0
@@ -423,12 +425,16 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
423425
#define ASM_NEW asm_arm_new
424426
#define ASM_FREE asm_arm_free
425427
#define ASM_GET_CODE asm_arm_get_code
428+
#define ASM_GET_CODE_POS asm_arm_get_code_pos
426429
#define ASM_GET_CODE_SIZE asm_arm_get_code_size
427430
#define ASM_START_PASS asm_arm_start_pass
428431
#define ASM_END_PASS asm_arm_end_pass
429432
#define ASM_ENTRY asm_arm_entry
430433
#define ASM_EXIT asm_arm_exit
431434

435+
#define ASM_ALIGN asm_arm_align
436+
#define ASM_DATA asm_arm_data
437+
432438
#define ASM_LABEL_ASSIGN asm_arm_label_assign
433439
#define ASM_JUMP asm_arm_b_label
434440
#define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
@@ -468,11 +474,13 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
468474
#define ASM_ADD_REG_REG(as, reg_dest, reg_src) asm_arm_add_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
469475
#define ASM_SUB_REG_REG(as, reg_dest, reg_src) asm_arm_sub_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
470476

471-
#define ASM_LOAD_REG_REG(as, reg_dest, reg_base) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base))
477+
#define ASM_LOAD_REG_REG(as, reg_dest, reg_base) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base), 0)
478+
#define ASM_LOAD_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base), 4 * (word_offset))
472479
#define ASM_LOAD8_REG_REG(as, reg_dest, reg_base) asm_arm_ldrb_reg_reg((as), (reg_dest), (reg_base))
473480
#define ASM_LOAD16_REG_REG(as, reg_dest, reg_base) asm_arm_ldrh_reg_reg((as), (reg_dest), (reg_base))
474481

475-
#define ASM_STORE_REG_REG(as, reg_value, reg_base) asm_arm_str_reg_reg((as), (reg_value), (reg_base))
482+
#define ASM_STORE_REG_REG(as, reg_value, reg_base) asm_arm_str_reg_reg((as), (reg_value), (reg_base), 0)
483+
#define ASM_STORE_REG_REG_OFFSET(as, reg_dest, reg_base, word_offset) asm_arm_str_reg_reg((as), (reg_dest), (reg_base), 4 * (word_offset))
476484
#define ASM_STORE8_REG_REG(as, reg_value, reg_base) asm_arm_strb_reg_reg((as), (reg_value), (reg_base))
477485
#define ASM_STORE16_REG_REG(as, reg_value, reg_base) asm_arm_strh_reg_reg((as), (reg_value), (reg_base))
478486

@@ -723,6 +731,8 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
723731
#else
724732
#if N_THUMB
725733
ASM_MOV_REG_REG(emit->as, ASM_THUMB_REG_R4, REG_ARG_4);
734+
#elif N_ARM
735+
ASM_MOV_REG_REG(emit->as, ASM_ARM_REG_R4, REG_ARG_4);
726736
#else
727737
ASM_MOV_REG_REG(emit->as, REG_ARG_5, REG_ARG_4);
728738
#endif
@@ -750,6 +760,10 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
750760
asm_thumb_op16(emit->as, 0xb400 | (1 << ASM_THUMB_REG_R4)); // push 5th arg
751761
asm_thumb_bl_ind(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE, ASM_THUMB_REG_R4);
752762
asm_thumb_op16(emit->as, 0xbc00 | (1 << REG_RET)); // pop dummy (was 5th arg)
763+
#elif N_ARM
764+
asm_arm_push(emit->as, 1 << ASM_ARM_REG_R4); // push 5th arg
765+
asm_arm_bl_ind(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE, ASM_ARM_REG_R4);
766+
asm_arm_pop(emit->as, 1 << REG_RET); // pop dummy (was 5th arg)
753767
#else
754768
ASM_CALL_IND(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE);
755769
#endif

0 commit comments

Comments
 (0)