emitnative: Revamp ARM codegen compile after full-arg support refactors.

The code was apparently broken after 9988618e0e
"py: Implement full func arg passing for native emitter.". This attempts to
propagate those changes to ARM emitter.
This commit is contained in:
Paul Sokolovsky 2015-05-07 23:08:09 +03:00 committed by Damien George
parent d792d9e49e
commit 351424e719
3 changed files with 41 additions and 10 deletions

View File

@ -111,6 +111,10 @@ STATIC byte *asm_arm_get_cur_to_write_bytes(asm_arm_t *as, int num_bytes_to_writ
} }
} }
uint asm_arm_get_code_pos(asm_arm_t *as) {
return as->code_offset;
}
uint asm_arm_get_code_size(asm_arm_t *as) { uint asm_arm_get_code_size(asm_arm_t *as) {
return as->code_size; return as->code_size;
} }
@ -245,6 +249,14 @@ void asm_arm_exit(asm_arm_t *as) {
emit_al(as, asm_arm_op_pop(as->push_reglist | (1 << ASM_ARM_REG_PC))); emit_al(as, asm_arm_op_pop(as->push_reglist | (1 << ASM_ARM_REG_PC)));
} }
void asm_arm_push(asm_arm_t *as, uint reglist) {
emit_al(as, asm_arm_op_push(reglist));
}
void asm_arm_pop(asm_arm_t *as, uint reglist) {
emit_al(as, asm_arm_op_pop(reglist));
}
void asm_arm_label_assign(asm_arm_t *as, uint label) { void asm_arm_label_assign(asm_arm_t *as, uint label) {
assert(label < as->max_num_labels); assert(label < as->max_num_labels);
if (as->pass < ASM_ARM_PASS_EMIT) { 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) {
emit_al(as, 0x1a00050 | (rd << 12) | (rs << 8) | rd); emit_al(as, 0x1a00050 | (rd << 12) | (rs << 8) | rd);
} }
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn) { void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset) {
// ldr rd, [rn] // ldr rd, [rn, #off]
emit_al(as, 0x5900000 | (rn << 16) | (rd << 12)); emit_al(as, 0x5900000 | (rn << 16) | (rd << 12) | byte_offset);
} }
void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn) { 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) {
emit_al(as, 0x5d00000 | (rn << 16) | (rd << 12)); emit_al(as, 0x5d00000 | (rn << 16) | (rd << 12));
} }
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm) { void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset) {
// str rd, [rm] // str rd, [rm, #off]
emit_al(as, 0x5800000 | (rm << 16) | (rd << 12)); emit_al(as, 0x5800000 | (rm << 16) | (rd << 12) | byte_offset);
} }
void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm) { void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm) {

View File

@ -74,6 +74,7 @@ asm_arm_t *asm_arm_new(uint max_num_labels);
void asm_arm_free(asm_arm_t *as, bool free_code); void asm_arm_free(asm_arm_t *as, bool free_code);
void asm_arm_start_pass(asm_arm_t *as, uint pass); void asm_arm_start_pass(asm_arm_t *as, uint pass);
void asm_arm_end_pass(asm_arm_t *as); void asm_arm_end_pass(asm_arm_t *as);
uint asm_arm_get_code_pos(asm_arm_t *as);
uint asm_arm_get_code_size(asm_arm_t *as); uint asm_arm_get_code_size(asm_arm_t *as);
void *asm_arm_get_code(asm_arm_t *as); void *asm_arm_get_code(asm_arm_t *as);
@ -108,10 +109,10 @@ void asm_arm_lsl_reg_reg(asm_arm_t *as, uint rd, uint rs);
void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs); void asm_arm_asr_reg_reg(asm_arm_t *as, uint rd, uint rs);
// memory // memory
void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn); void asm_arm_ldr_reg_reg(asm_arm_t *as, uint rd, uint rn, uint byte_offset);
void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn); void asm_arm_ldrh_reg_reg(asm_arm_t *as, uint rd, uint rn);
void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn); void asm_arm_ldrb_reg_reg(asm_arm_t *as, uint rd, uint rn);
void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm); void asm_arm_str_reg_reg(asm_arm_t *as, uint rd, uint rm, uint byte_offset);
void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm); void asm_arm_strh_reg_reg(asm_arm_t *as, uint rd, uint rm);
void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm); void asm_arm_strb_reg_reg(asm_arm_t *as, uint rd, uint rm);
// store to array // store to array
@ -119,6 +120,10 @@ void asm_arm_str_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn); void asm_arm_strh_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn); void asm_arm_strb_reg_reg_reg(asm_arm_t *as, uint rd, uint rm, uint rn);
// stack
void asm_arm_push(asm_arm_t *as, uint reglist);
void asm_arm_pop(asm_arm_t *as, uint reglist);
// control flow // control flow
void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label); void asm_arm_bcc_label(asm_arm_t *as, int cond, uint label);
void asm_arm_b_label(asm_arm_t *as, uint label); void asm_arm_b_label(asm_arm_t *as, uint label);

View File

@ -399,6 +399,8 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
#include "py/asmarm.h" #include "py/asmarm.h"
#define ASM_WORD_SIZE (4)
#define EXPORT_FUN(name) emit_native_arm_##name #define EXPORT_FUN(name) emit_native_arm_##name
#define REG_RET ASM_ARM_REG_R0 #define REG_RET ASM_ARM_REG_R0
@ -423,12 +425,16 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
#define ASM_NEW asm_arm_new #define ASM_NEW asm_arm_new
#define ASM_FREE asm_arm_free #define ASM_FREE asm_arm_free
#define ASM_GET_CODE asm_arm_get_code #define ASM_GET_CODE asm_arm_get_code
#define ASM_GET_CODE_POS asm_arm_get_code_pos
#define ASM_GET_CODE_SIZE asm_arm_get_code_size #define ASM_GET_CODE_SIZE asm_arm_get_code_size
#define ASM_START_PASS asm_arm_start_pass #define ASM_START_PASS asm_arm_start_pass
#define ASM_END_PASS asm_arm_end_pass #define ASM_END_PASS asm_arm_end_pass
#define ASM_ENTRY asm_arm_entry #define ASM_ENTRY asm_arm_entry
#define ASM_EXIT asm_arm_exit #define ASM_EXIT asm_arm_exit
#define ASM_ALIGN asm_arm_align
#define ASM_DATA asm_arm_data
#define ASM_LABEL_ASSIGN asm_arm_label_assign #define ASM_LABEL_ASSIGN asm_arm_label_assign
#define ASM_JUMP asm_arm_b_label #define ASM_JUMP asm_arm_b_label
#define ASM_JUMP_IF_REG_ZERO(as, reg, label) \ #define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
@ -468,11 +474,13 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
#define ASM_ADD_REG_REG(as, reg_dest, reg_src) asm_arm_add_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src)) #define ASM_ADD_REG_REG(as, reg_dest, reg_src) asm_arm_add_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
#define ASM_SUB_REG_REG(as, reg_dest, reg_src) asm_arm_sub_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src)) #define ASM_SUB_REG_REG(as, reg_dest, reg_src) asm_arm_sub_reg_reg_reg((as), (reg_dest), (reg_dest), (reg_src))
#define ASM_LOAD_REG_REG(as, reg_dest, reg_base) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base)) #define ASM_LOAD_REG_REG(as, reg_dest, reg_base) asm_arm_ldr_reg_reg((as), (reg_dest), (reg_base), 0)
#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))
#define ASM_LOAD8_REG_REG(as, reg_dest, reg_base) asm_arm_ldrb_reg_reg((as), (reg_dest), (reg_base)) #define ASM_LOAD8_REG_REG(as, reg_dest, reg_base) asm_arm_ldrb_reg_reg((as), (reg_dest), (reg_base))
#define ASM_LOAD16_REG_REG(as, reg_dest, reg_base) asm_arm_ldrh_reg_reg((as), (reg_dest), (reg_base)) #define ASM_LOAD16_REG_REG(as, reg_dest, reg_base) asm_arm_ldrh_reg_reg((as), (reg_dest), (reg_base))
#define ASM_STORE_REG_REG(as, reg_value, reg_base) asm_arm_str_reg_reg((as), (reg_value), (reg_base)) #define ASM_STORE_REG_REG(as, reg_value, reg_base) asm_arm_str_reg_reg((as), (reg_value), (reg_base), 0)
#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))
#define ASM_STORE8_REG_REG(as, reg_value, reg_base) asm_arm_strb_reg_reg((as), (reg_value), (reg_base)) #define ASM_STORE8_REG_REG(as, reg_value, reg_base) asm_arm_strb_reg_reg((as), (reg_value), (reg_base))
#define ASM_STORE16_REG_REG(as, reg_value, reg_base) asm_arm_strh_reg_reg((as), (reg_value), (reg_base)) #define ASM_STORE16_REG_REG(as, reg_value, reg_base) asm_arm_strh_reg_reg((as), (reg_value), (reg_base))
@ -723,6 +731,8 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
#else #else
#if N_THUMB #if N_THUMB
ASM_MOV_REG_REG(emit->as, ASM_THUMB_REG_R4, REG_ARG_4); ASM_MOV_REG_REG(emit->as, ASM_THUMB_REG_R4, REG_ARG_4);
#elif N_ARM
ASM_MOV_REG_REG(emit->as, ASM_ARM_REG_R4, REG_ARG_4);
#else #else
ASM_MOV_REG_REG(emit->as, REG_ARG_5, REG_ARG_4); ASM_MOV_REG_REG(emit->as, REG_ARG_5, REG_ARG_4);
#endif #endif
@ -750,6 +760,10 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
asm_thumb_op16(emit->as, 0xb400 | (1 << ASM_THUMB_REG_R4)); // push 5th arg asm_thumb_op16(emit->as, 0xb400 | (1 << ASM_THUMB_REG_R4)); // push 5th arg
asm_thumb_bl_ind(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE, ASM_THUMB_REG_R4); asm_thumb_bl_ind(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE, ASM_THUMB_REG_R4);
asm_thumb_op16(emit->as, 0xbc00 | (1 << REG_RET)); // pop dummy (was 5th arg) asm_thumb_op16(emit->as, 0xbc00 | (1 << REG_RET)); // pop dummy (was 5th arg)
#elif N_ARM
asm_arm_push(emit->as, 1 << ASM_ARM_REG_R4); // push 5th arg
asm_arm_bl_ind(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE, ASM_ARM_REG_R4);
asm_arm_pop(emit->as, 1 << REG_RET); // pop dummy (was 5th arg)
#else #else
ASM_CALL_IND(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE); ASM_CALL_IND(emit->as, mp_fun_table[MP_F_SETUP_CODE_STATE], MP_F_SETUP_CODE_STATE);
#endif #endif