summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitnative.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c599
1 files changed, 358 insertions, 241 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index c24f380696..782f4b60dd 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -69,7 +69,10 @@
#endif
// wrapper around everything in this file
-#if (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) || (MICROPY_EMIT_ARM && N_ARM)
+#if (MICROPY_EMIT_X64 && N_X64) \
+ || (MICROPY_EMIT_X86 && N_X86) \
+ || (MICROPY_EMIT_THUMB && N_THUMB) \
+ || (MICROPY_EMIT_ARM && N_ARM)
#if N_X64
@@ -77,21 +80,165 @@
#include "asmx64.h"
-#define REG_LOCAL_1 (REG_RBX)
-#define REG_LOCAL_NUM (1)
-
#define EXPORT_FUN(name) emit_native_x64_##name
#define REG_TEMP0 (REG_RAX)
#define REG_TEMP1 (REG_RDI)
#define REG_TEMP2 (REG_RSI)
-#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_x64_mov_r64_to_local(emit->as, (reg), (local_num))
-#define ASM_MOV_IMM_TO_REG(imm, reg) asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg))
-#define ASM_MOV_ALIGNED_IMM_TO_REG(imm, reg) asm_x64_mov_i64_to_r64_aligned(emit->as, (imm), (reg))
-#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_x64_mov_i64_to_r64_optimised(emit->as, (imm), (reg_temp)); asm_x64_mov_r64_to_local(emit->as, (reg_temp), (local_num)); } while (false)
-#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_x64_mov_local_to_r64(emit->as, (local_num), (reg))
-#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_x64_mov_r64_to_r64(emit->as, (reg_src), (reg_dest))
-#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_x64_mov_local_addr_to_r64(emit->as, (local_num), (reg))
+
+#define REG_LOCAL_1 (REG_RBX)
+#define REG_LOCAL_NUM (1)
+
+#define ASM_PASS_COMPUTE ASM_X64_PASS_COMPUTE
+#define ASM_PASS_EMIT ASM_X64_PASS_EMIT
+
+#define ASM_T asm_x64_t
+#define ASM_NEW asm_x64_new
+#define ASM_FREE asm_x64_free
+#define ASM_GET_CODE asm_x64_get_code
+#define ASM_GET_CODE_SIZE asm_x64_get_code_size
+#define ASM_START_PASS asm_x64_start_pass
+#define ASM_END_PASS asm_x64_end_pass
+#define ASM_ENTRY asm_x64_entry
+#define ASM_EXIT asm_x64_exit
+
+#define ASM_LABEL_ASSIGN asm_x64_label_assign
+#define ASM_JUMP asm_x64_jmp_label
+#define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
+ do { \
+ asm_x64_test_r8_with_r8(as, reg, reg); \
+ asm_x64_jcc_label(as, ASM_X64_CC_JZ, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_NONZERO(as, reg, label) \
+ do { \
+ asm_x64_test_r8_with_r8(as, reg, reg); \
+ asm_x64_jcc_label(as, ASM_X64_CC_JNZ, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \
+ do { \
+ asm_x64_cmp_r64_with_r64(as, reg1, reg2); \
+ asm_x64_jcc_label(as, ASM_X64_CC_JE, label); \
+ } while (0)
+#define ASM_CALL_IND(as, ptr, idx) asm_x64_call_ind(as, ptr, REG_RAX)
+
+#define ASM_MOV_REG_TO_LOCAL asm_x64_mov_r64_to_local
+#define ASM_MOV_IMM_TO_REG asm_x64_mov_i64_to_r64_optimised
+#define ASM_MOV_ALIGNED_IMM_TO_REG asm_x64_mov_i64_to_r64_aligned
+#define ASM_MOV_IMM_TO_LOCAL_USING(as, imm, local_num, reg_temp) \
+ do { \
+ asm_x64_mov_i64_to_r64_optimised(as, (imm), (reg_temp)); \
+ asm_x64_mov_r64_to_local(as, (reg_temp), (local_num)); \
+ } while (false)
+#define ASM_MOV_LOCAL_TO_REG asm_x64_mov_local_to_r64
+#define ASM_MOV_REG_TO_REG asm_x64_mov_r64_to_r64
+#define ASM_MOV_LOCAL_ADDR_TO_REG asm_x64_mov_local_addr_to_r64
+
+#elif N_X86
+
+// x86 specific stuff
+
+#include "asmx86.h"
+
+STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = {
+ [MP_F_CONVERT_OBJ_TO_NATIVE] = 2,
+ [MP_F_CONVERT_NATIVE_TO_OBJ] = 2,
+ [MP_F_LOAD_CONST_INT] = 1,
+ [MP_F_LOAD_CONST_DEC] = 1,
+ [MP_F_LOAD_CONST_STR] = 1,
+ [MP_F_LOAD_CONST_BYTES] = 1,
+ [MP_F_LOAD_NAME] = 1,
+ [MP_F_LOAD_GLOBAL] = 1,
+ [MP_F_LOAD_BUILD_CLASS] = 0,
+ [MP_F_LOAD_ATTR] = 2,
+ [MP_F_LOAD_METHOD] = 3,
+ [MP_F_STORE_NAME] = 2,
+ [MP_F_STORE_GLOBAL] = 2,
+ [MP_F_STORE_ATTR] = 3,
+ [MP_F_OBJ_SUBSCR] = 3,
+ [MP_F_OBJ_IS_TRUE] = 1,
+ [MP_F_UNARY_OP] = 2,
+ [MP_F_BINARY_OP] = 3,
+ [MP_F_BUILD_TUPLE] = 2,
+ [MP_F_BUILD_LIST] = 2,
+ [MP_F_LIST_APPEND] = 2,
+ [MP_F_BUILD_MAP] = 1,
+ [MP_F_STORE_MAP] = 3,
+#if MICROPY_PY_BUILTINS_SET
+ [MP_F_BUILD_SET] = 2,
+ [MP_F_STORE_SET] = 2,
+#endif
+ [MP_F_MAKE_FUNCTION_FROM_RAW_CODE] = 3,
+ [MP_F_NATIVE_CALL_FUNCTION_N_KW] = 3,
+ [MP_F_CALL_METHOD_N_KW] = 3,
+ [MP_F_GETITER] = 1,
+ [MP_F_ITERNEXT] = 1,
+ [MP_F_NLR_PUSH] = 1,
+ [MP_F_NLR_POP] = 0,
+ [MP_F_NATIVE_RAISE] = 1,
+ [MP_F_IMPORT_NAME] = 3,
+ [MP_F_IMPORT_FROM] = 2,
+ [MP_F_IMPORT_ALL] = 1,
+#if MICROPY_PY_BUILTINS_SLICE
+ [MP_F_NEW_SLICE] = 3,
+#endif
+ [MP_F_UNPACK_SEQUENCE] = 3,
+ [MP_F_UNPACK_EX] = 3,
+ [MP_F_DELETE_NAME] = 1,
+ [MP_F_DELETE_GLOBAL] = 1,
+};
+
+#define EXPORT_FUN(name) emit_native_x86_##name
+
+#define REG_TEMP0 (REG_EAX)
+#define REG_TEMP1 (REG_EDI)
+#define REG_TEMP2 (REG_ESI)
+
+#define REG_LOCAL_1 (REG_EBX)
+#define REG_LOCAL_NUM (1)
+
+#define ASM_PASS_COMPUTE ASM_X86_PASS_COMPUTE
+#define ASM_PASS_EMIT ASM_X86_PASS_EMIT
+
+#define ASM_T asm_x86_t
+#define ASM_NEW asm_x86_new
+#define ASM_FREE asm_x86_free
+#define ASM_GET_CODE asm_x86_get_code
+#define ASM_GET_CODE_SIZE asm_x86_get_code_size
+#define ASM_START_PASS asm_x86_start_pass
+#define ASM_END_PASS asm_x86_end_pass
+#define ASM_ENTRY asm_x86_entry
+#define ASM_EXIT asm_x86_exit
+
+#define ASM_LABEL_ASSIGN asm_x86_label_assign
+#define ASM_JUMP asm_x86_jmp_label
+#define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
+ do { \
+ asm_x86_test_r8_with_r8(as, reg, reg); \
+ asm_x86_jcc_label(as, ASM_X86_CC_JZ, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_NONZERO(as, reg, label) \
+ do { \
+ asm_x86_test_r8_with_r8(as, reg, reg); \
+ asm_x86_jcc_label(as, ASM_X86_CC_JNZ, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \
+ do { \
+ asm_x86_cmp_r32_with_r32(as, reg1, reg2); \
+ asm_x86_jcc_label(as, ASM_X86_CC_JE, label); \
+ } while (0)
+#define ASM_CALL_IND(as, ptr, idx) asm_x86_call_ind(as, ptr, mp_f_n_args[idx], REG_EAX)
+
+#define ASM_MOV_REG_TO_LOCAL asm_x86_mov_r32_to_local
+#define ASM_MOV_IMM_TO_REG asm_x86_mov_i32_to_r32
+#define ASM_MOV_ALIGNED_IMM_TO_REG asm_x86_mov_i32_to_r32_aligned
+#define ASM_MOV_IMM_TO_LOCAL_USING(as, imm, local_num, reg_temp) \
+ do { \
+ asm_x86_mov_i32_to_r32(as, (imm), (reg_temp)); \
+ asm_x86_mov_r32_to_local(as, (reg_temp), (local_num)); \
+ } while (false)
+#define ASM_MOV_LOCAL_TO_REG asm_x86_mov_local_to_r32
+#define ASM_MOV_REG_TO_REG asm_x86_mov_r32_to_r32
+#define ASM_MOV_LOCAL_ADDR_TO_REG asm_x86_mov_local_addr_to_r32
#elif N_THUMB
@@ -99,23 +246,60 @@
#include "asmthumb.h"
-#define REG_LOCAL_1 (REG_R4)
-#define REG_LOCAL_2 (REG_R5)
-#define REG_LOCAL_3 (REG_R6)
-#define REG_LOCAL_NUM (3)
-
#define EXPORT_FUN(name) emit_native_thumb_##name
#define REG_TEMP0 (REG_R0)
#define REG_TEMP1 (REG_R1)
#define REG_TEMP2 (REG_R2)
-#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_thumb_mov_local_reg(emit->as, (local_num), (reg))
-#define ASM_MOV_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_optimised(emit->as, (reg), (imm))
-#define ASM_MOV_ALIGNED_IMM_TO_REG(imm, reg) asm_thumb_mov_reg_i32_aligned(emit->as, (reg), (imm))
-#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_thumb_mov_reg_i32_optimised(emit->as, (reg_temp), (imm)); asm_thumb_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (false)
-#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_thumb_mov_reg_local(emit->as, (reg), (local_num))
-#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_thumb_mov_reg_reg(emit->as, (reg_dest), (reg_src))
-#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_thumb_mov_reg_local_addr(emit->as, (reg), (local_num))
+
+#define REG_LOCAL_1 (REG_R4)
+#define REG_LOCAL_2 (REG_R5)
+#define REG_LOCAL_3 (REG_R6)
+#define REG_LOCAL_NUM (3)
+
+#define ASM_PASS_COMPUTE ASM_THUMB_PASS_COMPUTE
+#define ASM_PASS_EMIT ASM_THUMB_PASS_EMIT
+
+#define ASM_T asm_thumb_t
+#define ASM_NEW asm_thumb_new
+#define ASM_FREE asm_thumb_free
+#define ASM_GET_CODE asm_thumb_get_code
+#define ASM_GET_CODE_SIZE asm_thumb_get_code_size
+#define ASM_START_PASS asm_thumb_start_pass
+#define ASM_END_PASS asm_thumb_end_pass
+#define ASM_ENTRY asm_thumb_entry
+#define ASM_EXIT asm_thumb_exit
+
+#define ASM_LABEL_ASSIGN asm_thumb_label_assign
+#define ASM_JUMP asm_thumb_b_label
+#define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
+ do { \
+ asm_thumb_cmp_rlo_i8(as, reg, 0); \
+ asm_thumb_bcc_label(as, THUMB_CC_EQ, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_NONZERO(as, reg, label) \
+ do { \
+ asm_thumb_cmp_rlo_i8(as, reg, 0); \
+ asm_thumb_bcc_label(as, THUMB_CC_NE, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \
+ do { \
+ asm_thumb_cmp_rlo_rlo(as, reg1, reg2); \
+ asm_thumb_bcc_label(as, THUMB_CC_EQ, label); \
+ } while (0)
+#define ASM_CALL_IND(as, ptr, idx) asm_thumb_bl_ind(as, ptr, idx, REG_R3)
+
+#define ASM_MOV_REG_TO_LOCAL(as, reg, local_num) asm_thumb_mov_local_reg(as, (local_num), (reg))
+#define ASM_MOV_IMM_TO_REG(as, imm, reg) asm_thumb_mov_reg_i32_optimised(as, (reg), (imm))
+#define ASM_MOV_ALIGNED_IMM_TO_REG(as, imm, reg) asm_thumb_mov_reg_i32_aligned(as, (reg), (imm))
+#define ASM_MOV_IMM_TO_LOCAL_USING(as, imm, local_num, reg_temp) \
+ do { \
+ asm_thumb_mov_reg_i32_optimised(as, (reg_temp), (imm)); \
+ asm_thumb_mov_local_reg(as, (local_num), (reg_temp)); \
+ } while (false)
+#define ASM_MOV_LOCAL_TO_REG(as, local_num, reg) asm_thumb_mov_reg_local(as, (reg), (local_num))
+#define ASM_MOV_REG_TO_REG(as, reg_src, reg_dest) asm_thumb_mov_reg_reg(as, (reg_dest), (reg_src))
+#define ASM_MOV_LOCAL_ADDR_TO_REG(as, local_num, reg) asm_thumb_mov_reg_local_addr(as, (reg), (local_num))
#elif N_ARM
@@ -123,23 +307,64 @@
#include "asmarm.h"
-#define REG_LOCAL_1 (REG_R4)
-#define REG_LOCAL_2 (REG_R5)
-#define REG_LOCAL_3 (REG_R6)
-#define REG_LOCAL_NUM (3)
-
#define EXPORT_FUN(name) emit_native_arm_##name
#define REG_TEMP0 (REG_R0)
#define REG_TEMP1 (REG_R1)
#define REG_TEMP2 (REG_R2)
-#define ASM_MOV_REG_TO_LOCAL(reg, local_num) asm_arm_mov_local_reg(emit->as, (local_num), (reg))
-#define ASM_MOV_IMM_TO_REG(imm, reg) asm_arm_mov_reg_i32(emit->as, (reg), (imm))
-#define ASM_MOV_ALIGNED_IMM_TO_REG(imm, reg) asm_arm_mov_reg_i32(emit->as, (reg), (imm))
-#define ASM_MOV_IMM_TO_LOCAL_USING(imm, local_num, reg_temp) do { asm_arm_mov_reg_i32(emit->as, (reg_temp), (imm)); asm_arm_mov_local_reg(emit->as, (local_num), (reg_temp)); } while (false)
-#define ASM_MOV_LOCAL_TO_REG(local_num, reg) asm_arm_mov_reg_local(emit->as, (reg), (local_num))
-#define ASM_MOV_REG_TO_REG(reg_src, reg_dest) asm_arm_mov_reg_reg(emit->as, (reg_dest), (reg_src))
-#define ASM_MOV_LOCAL_ADDR_TO_REG(local_num, reg) asm_arm_mov_reg_local_addr(emit->as, (reg), (local_num))
+
+#define REG_LOCAL_1 (REG_R4)
+#define REG_LOCAL_2 (REG_R5)
+#define REG_LOCAL_3 (REG_R6)
+#define REG_LOCAL_NUM (3)
+
+#define ASM_PASS_COMPUTE ASM_ARM_PASS_COMPUTE
+#define ASM_PASS_EMIT ASM_ARM_PASS_EMIT
+
+#define ASM_T asm_arm_t
+#define ASM_NEW asm_arm_new
+#define ASM_FREE asm_arm_free
+#define ASM_GET_CODE asm_arm_get_code
+#define ASM_GET_CODE_SIZE asm_arm_get_code_size
+#define ASM_START_PASS asm_arm_start_pass
+#define ASM_END_PASS asm_arm_end_pass
+#define ASM_ENTRY asm_arm_entry
+#define ASM_EXIT asm_arm_exit
+
+#define ASM_LABEL_ASSIGN asm_arm_label_assign
+#define ASM_JUMP asm_arm_b_label
+#define ASM_JUMP_IF_REG_ZERO(as, reg, label) \
+ do { \
+ asm_arm_cmp_reg_i8(as, reg, 0); \
+ asm_arm_bcc_label(as, ARM_CC_EQ, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_NONZERO(as, reg, label) \
+ do { \
+ asm_arm_cmp_reg_i8(as, reg, 0); \
+ asm_arm_bcc_label(as, ARM_CC_NE, label); \
+ } while (0)
+#define ASM_JUMP_IF_REG_EQ(as, reg1, reg2, label) \
+ do { \
+ asm_arm_cmp_reg_reg(as, reg1, reg2); \
+ asm_arm_bcc_label(as, ARM_CC_EQ, label); \
+ } while (0)
+#define ASM_CALL_IND(as, ptr, idx) asm_arm_bl_ind(as, ptr, idx, REG_R3)
+
+#define ASM_MOV_REG_TO_LOCAL(as, reg, local_num) asm_arm_mov_local_reg(as, (local_num), (reg))
+#define ASM_MOV_IMM_TO_REG(as, imm, reg) asm_arm_mov_reg_i32(as, (reg), (imm))
+#define ASM_MOV_ALIGNED_IMM_TO_REG(as, imm, reg) asm_arm_mov_reg_i32(as, (reg), (imm))
+#define ASM_MOV_IMM_TO_LOCAL_USING(as, imm, local_num, reg_temp) \
+ do { \
+ asm_arm_mov_reg_i32(as, (reg_temp), (imm)); \
+ asm_arm_mov_local_reg(as, (local_num), (reg_temp)); \
+ } while (false)
+#define ASM_MOV_LOCAL_TO_REG(as, local_num, reg) asm_arm_mov_reg_local(as, (reg), (local_num))
+#define ASM_MOV_REG_TO_REG(as, reg_src, reg_dest) asm_arm_mov_reg_reg(as, (reg_dest), (reg_src))
+#define ASM_MOV_LOCAL_ADDR_TO_REG(as, local_num, reg) asm_arm_mov_reg_local_addr(as, (reg), (local_num))
+
+#else
+
+#error unknown native emitter
#endif
@@ -189,35 +414,17 @@ struct _emit_t {
scope_t *scope;
-#if N_X64
- asm_x64_t *as;
-#elif N_THUMB
- asm_thumb_t *as;
-#elif N_ARM
- asm_arm_t *as;
-#endif
+ ASM_T *as;
};
emit_t *EXPORT_FUN(new)(uint max_num_labels) {
emit_t *emit = m_new0(emit_t, 1);
-#if N_X64
- emit->as = asm_x64_new(max_num_labels);
-#elif N_THUMB
- emit->as = asm_thumb_new(max_num_labels);
-#elif N_ARM
- emit->as = asm_arm_new(max_num_labels);
-#endif
+ emit->as = ASM_NEW(max_num_labels);
return emit;
}
void EXPORT_FUN(free)(emit_t *emit) {
-#if N_X64
- asm_x64_free(emit->as, false);
-#elif N_THUMB
- asm_thumb_free(emit->as, false);
-#elif N_ARM
- asm_arm_free(emit->as, false);
-#endif
+ ASM_FREE(emit->as, false);
m_del(vtype_kind_t, emit->local_vtype, emit->local_vtype_alloc);
m_del(stack_info_t, emit->stack_info, emit->stack_info_alloc);
m_del_obj(emit_t, emit);
@@ -286,13 +493,7 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
emit->stack_info[i].vtype = VTYPE_UNBOUND;
}
-#if N_X64
- asm_x64_start_pass(emit->as, pass == MP_PASS_EMIT ? ASM_X64_PASS_EMIT : ASM_X64_PASS_COMPUTE);
-#elif N_THUMB
- asm_thumb_start_pass(emit->as, pass == MP_PASS_EMIT ? ASM_THUMB_PASS_EMIT : ASM_THUMB_PASS_COMPUTE);
-#elif N_ARM
- asm_arm_start_pass(emit->as, pass == MP_PASS_EMIT ? ASM_ARM_PASS_EMIT : ASM_ARM_PASS_COMPUTE);
-#endif
+ ASM_START_PASS(emit->as, pass == MP_PASS_EMIT ? ASM_PASS_EMIT : ASM_PASS_COMPUTE);
// entry to function
int num_locals = 0;
@@ -304,13 +505,7 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
emit->stack_start = num_locals;
num_locals += scope->stack_size;
}
-#if N_X64
- asm_x64_entry(emit->as, num_locals);
-#elif N_THUMB
- asm_thumb_entry(emit->as, num_locals);
-#elif N_ARM
- asm_arm_entry(emit->as, num_locals);
-#endif
+ ASM_ENTRY(emit->as, num_locals);
// initialise locals from parameters
#if N_X64
@@ -326,6 +521,21 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
assert(0);
}
}
+#elif N_X86
+ for (int i = 0; i < scope->num_pos_args; i++) {
+ // TODO
+ assert(0);
+ if (i == 0) {
+ asm_x86_mov_r32_to_r32(emit->as, REG_ARG_1, REG_LOCAL_1);
+ } else if (i == 1) {
+ asm_x86_mov_r32_to_local(emit->as, REG_ARG_2, i - REG_LOCAL_NUM);
+ } else if (i == 2) {
+ asm_x86_mov_r32_to_local(emit->as, REG_ARG_3, i - REG_LOCAL_NUM);
+ } else {
+ // TODO not implemented
+ assert(0);
+ }
+ }
#elif N_THUMB
for (int i = 0; i < scope->num_pos_args; i++) {
if (i == 0) {
@@ -360,26 +570,16 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop
}
asm_arm_mov_reg_i32(emit->as, REG_R7, (mp_uint_t)mp_fun_table);
+#else
+ #error not implemented
#endif
}
STATIC void emit_native_end_pass(emit_t *emit) {
-#if N_X64
- if (!emit->last_emit_was_return_value) {
- asm_x64_exit(emit->as);
- }
- asm_x64_end_pass(emit->as);
-#elif N_THUMB
- if (!emit->last_emit_was_return_value) {
- asm_thumb_exit(emit->as);
- }
- asm_thumb_end_pass(emit->as);
-#elif N_ARM
if (!emit->last_emit_was_return_value) {
- asm_arm_exit(emit->as);
+ ASM_EXIT(emit->as);
}
- asm_arm_end_pass(emit->as);
-#endif
+ ASM_END_PASS(emit->as);
// check stack is back to zero size
if (emit->stack_size != 0) {
@@ -387,16 +587,8 @@ STATIC void emit_native_end_pass(emit_t *emit) {
}
if (emit->pass == MP_PASS_EMIT) {
-#if N_X64
- void *f = asm_x64_get_code(emit->as);
- mp_uint_t f_len = asm_x64_get_code_size(emit->as);
-#elif N_THUMB
- void *f = asm_thumb_get_code(emit->as);
- mp_uint_t f_len = asm_thumb_get_code_size(emit->as);
-#elif N_ARM
- void *f = asm_arm_get_code(emit->as);
- mp_uint_t f_len = asm_arm_get_code_size(emit->as);
-#endif
+ void *f = ASM_GET_CODE(emit->as);
+ mp_uint_t f_len = ASM_GET_CODE_SIZE(emit->as);
// compute type signature
// TODO check that viper types here convert correctly to valid types for emit glue
@@ -450,7 +642,7 @@ STATIC void emit_native_pre(emit_t *emit) {
case STACK_REG:
// TODO only push reg if in regs_needed
emit->stack_info[i].kind = STACK_VALUE;
- ASM_MOV_REG_TO_LOCAL(emit->stack_info[i].u_reg, emit->stack_start + i);
+ ASM_MOV_REG_TO_LOCAL(emit->as, emit->stack_info[i].u_reg, emit->stack_start + i);
break;
case STACK_IMM:
@@ -476,7 +668,7 @@ STATIC void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) {
stack_info_t *si = &emit->stack_info[i];
if (si->kind == STACK_REG && si->u_reg == reg_needed) {
si->kind = STACK_VALUE;
- ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
+ ASM_MOV_REG_TO_LOCAL(emit->as, si->u_reg, emit->stack_start + i);
}
}
}
@@ -487,7 +679,7 @@ STATIC void need_reg_all(emit_t *emit) {
stack_info_t *si = &emit->stack_info[i];
if (si->kind == STACK_REG) {
si->kind = STACK_VALUE;
- ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
+ ASM_MOV_REG_TO_LOCAL(emit->as, si->u_reg, emit->stack_start + i);
}
}
}
@@ -497,14 +689,14 @@ STATIC void need_stack_settled(emit_t *emit) {
stack_info_t *si = &emit->stack_info[i];
if (si->kind == STACK_REG) {
si->kind = STACK_VALUE;
- ASM_MOV_REG_TO_LOCAL(si->u_reg, emit->stack_start + i);
+ ASM_MOV_REG_TO_LOCAL(emit->as, si->u_reg, emit->stack_start + i);
}
}
for (int i = 0; i < emit->stack_size; i++) {
stack_info_t *si = &emit->stack_info[i];
if (si->kind == STACK_IMM) {
si->kind = STACK_VALUE;
- ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + i, REG_TEMP0);
+ ASM_MOV_IMM_TO_LOCAL_USING(emit->as, si->u_imm, emit->stack_start + i, REG_TEMP0);
}
}
}
@@ -516,17 +708,17 @@ STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re
*vtype = si->vtype;
switch (si->kind) {
case STACK_VALUE:
- ASM_MOV_LOCAL_TO_REG(emit->stack_start + emit->stack_size - pos, reg_dest);
+ ASM_MOV_LOCAL_TO_REG(emit->as, emit->stack_start + emit->stack_size - pos, reg_dest);
break;
case STACK_REG:
if (si->u_reg != reg_dest) {
- ASM_MOV_REG_TO_REG(si->u_reg, reg_dest);
+ ASM_MOV_REG_TO_REG(emit->as, si->u_reg, reg_dest);
}
break;
case STACK_IMM:
- ASM_MOV_IMM_TO_REG(si->u_imm, reg_dest);
+ ASM_MOV_IMM_TO_REG(emit->as, si->u_imm, reg_dest);
break;
}
}
@@ -592,66 +784,36 @@ STATIC void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, in
STATIC void emit_call(emit_t *emit, mp_fun_kind_t fun_kind) {
need_reg_all(emit);
-#if N_X64
- asm_x64_call_ind(emit->as, mp_fun_table[fun_kind], REG_RAX);
-#elif N_THUMB
- asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#elif N_ARM
- asm_arm_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#endif
+ ASM_CALL_IND(emit->as, mp_fun_table[fun_kind], fun_kind);
}
STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg) {
need_reg_all(emit);
- ASM_MOV_IMM_TO_REG(arg_val, arg_reg);
-#if N_X64
- asm_x64_call_ind(emit->as, mp_fun_table[fun_kind], REG_RAX);
-#elif N_THUMB
- asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#elif N_ARM
- asm_arm_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#endif
+ ASM_MOV_IMM_TO_REG(emit->as, arg_val, arg_reg);
+ ASM_CALL_IND(emit->as, mp_fun_table[fun_kind], fun_kind);
}
// the first arg is stored in the code aligned on a mp_uint_t boundary
STATIC void emit_call_with_imm_arg_aligned(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg) {
need_reg_all(emit);
- ASM_MOV_ALIGNED_IMM_TO_REG(arg_val, arg_reg);
-#if N_X64
- asm_x64_call_ind(emit->as, mp_fun_table[fun_kind], REG_RAX);
-#elif N_THUMB
- asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#elif N_ARM
- asm_arm_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#endif
+ ASM_MOV_ALIGNED_IMM_TO_REG(emit->as, arg_val, arg_reg);
+ ASM_CALL_IND(emit->as, mp_fun_table[fun_kind], fun_kind);
}
STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2) {
need_reg_all(emit);
- ASM_MOV_IMM_TO_REG(arg_val1, arg_reg1);
- ASM_MOV_IMM_TO_REG(arg_val2, arg_reg2);
-#if N_X64
- asm_x64_call_ind(emit->as, mp_fun_table[fun_kind], REG_RAX);
-#elif N_THUMB
- asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#elif N_ARM
- asm_arm_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#endif
+ ASM_MOV_IMM_TO_REG(emit->as, arg_val1, arg_reg1);
+ ASM_MOV_IMM_TO_REG(emit->as, arg_val2, arg_reg2);
+ ASM_CALL_IND(emit->as, mp_fun_table[fun_kind], fun_kind);
}
// the first arg is stored in the code aligned on a mp_uint_t boundary
STATIC void emit_call_with_3_imm_args_and_first_aligned(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2, mp_int_t arg_val3, int arg_reg3) {
need_reg_all(emit);
- ASM_MOV_ALIGNED_IMM_TO_REG(arg_val1, arg_reg1);
- ASM_MOV_IMM_TO_REG(arg_val2, arg_reg2);
- ASM_MOV_IMM_TO_REG(arg_val3, arg_reg3);
-#if N_X64
- asm_x64_call_ind(emit->as, mp_fun_table[fun_kind], REG_RAX);
-#elif N_THUMB
- asm_thumb_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#elif N_ARM
- asm_arm_bl_ind(emit->as, mp_fun_table[fun_kind], fun_kind, REG_R3);
-#endif
+ ASM_MOV_ALIGNED_IMM_TO_REG(emit->as, arg_val1, arg_reg1);
+ ASM_MOV_IMM_TO_REG(emit->as, arg_val2, arg_reg2);
+ ASM_MOV_IMM_TO_REG(emit->as, arg_val3, arg_reg3);
+ ASM_CALL_IND(emit->as, mp_fun_table[fun_kind], fun_kind);
}
// vtype of all n_pop objects is VTYPE_PYOBJ
@@ -670,19 +832,19 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de
si->kind = STACK_VALUE;
switch (si->vtype) {
case VTYPE_PYOBJ:
- ASM_MOV_IMM_TO_LOCAL_USING(si->u_imm, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
+ ASM_MOV_IMM_TO_LOCAL_USING(emit->as, si->u_imm, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
break;
case VTYPE_BOOL:
if (si->u_imm == 0) {
- ASM_MOV_IMM_TO_LOCAL_USING((mp_uint_t)mp_const_false, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
+ ASM_MOV_IMM_TO_LOCAL_USING(emit->as, (mp_uint_t)mp_const_false, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
} else {
- ASM_MOV_IMM_TO_LOCAL_USING((mp_uint_t)mp_const_true, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
+ ASM_MOV_IMM_TO_LOCAL_USING(emit->as, (mp_uint_t)mp_const_true, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
}
si->vtype = VTYPE_PYOBJ;
break;
case VTYPE_INT:
case VTYPE_UINT:
- ASM_MOV_IMM_TO_LOCAL_USING((si->u_imm << 1) | 1, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
+ ASM_MOV_IMM_TO_LOCAL_USING(emit->as, (si->u_imm << 1) | 1, emit->stack_start + emit->stack_size - 1 - i, reg_dest);
si->vtype = VTYPE_PYOBJ;
break;
default:
@@ -700,16 +862,16 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de
stack_info_t *si = &emit->stack_info[emit->stack_size - 1 - i];
if (si->vtype != VTYPE_PYOBJ) {
mp_uint_t local_num = emit->stack_start + emit->stack_size - 1 - i;
- ASM_MOV_LOCAL_TO_REG(local_num, REG_ARG_1);
+ ASM_MOV_LOCAL_TO_REG(emit->as, local_num, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_CONVERT_NATIVE_TO_OBJ, si->vtype, REG_ARG_2); // arg2 = type
- ASM_MOV_REG_TO_LOCAL(REG_RET, local_num);
+ ASM_MOV_REG_TO_LOCAL(emit->as, REG_RET, local_num);
si->vtype = VTYPE_PYOBJ;
}
}
// Adujust the stack for a pop of n_pop items, and load the stack pointer into reg_dest.
adjust_stack(emit, -n_pop);
- ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size, reg_dest);
+ ASM_MOV_LOCAL_ADDR_TO_REG(emit->as, emit->stack_start + emit->stack_size, reg_dest);
}
// vtype of all n_push objects is VTYPE_PYOBJ
@@ -719,7 +881,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_d
emit->stack_info[emit->stack_size + i].kind = STACK_VALUE;
emit->stack_info[emit->stack_size + i].vtype = VTYPE_PYOBJ;
}
- ASM_MOV_LOCAL_ADDR_TO_REG(emit->stack_start + emit->stack_size, reg_dest);
+ ASM_MOV_LOCAL_ADDR_TO_REG(emit->as, emit->stack_start + emit->stack_size, reg_dest);
adjust_stack(emit, n_push);
}
@@ -739,13 +901,7 @@ STATIC void emit_native_label_assign(emit_t *emit, uint l) {
emit_native_pre(emit);
// need to commit stack because we can jump here from elsewhere
need_stack_settled(emit);
-#if N_X64
- asm_x64_label_assign(emit->as, l);
-#elif N_THUMB
- asm_thumb_label_assign(emit->as, l);
-#elif N_ARM
- asm_arm_label_assign(emit->as, l);
-#endif
+ ASM_LABEL_ASSIGN(emit->as, l);
emit_post(emit);
}
@@ -864,6 +1020,14 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qstr, uint id_flags, int lo
asm_x64_mov_local_to_r64(emit->as, local_num - REG_LOCAL_NUM, REG_RAX);
emit_post_push_reg(emit, vtype, REG_RAX);
}
+#elif N_X86
+ if (local_num == 0) {
+ emit_post_push_reg(emit, vtype, REG_LOCAL_1);
+ } else {
+ need_reg_single(emit, REG_EAX, 0);
+ asm_x86_mov_local_to_r32(emit->as, local_num - REG_LOCAL_NUM, REG_EAX);
+ emit_post_push_reg(emit, vtype, REG_EAX);
+ }
#elif N_THUMB
if (local_num == 0) {
emit_post_push_reg(emit, vtype, REG_LOCAL_1);
@@ -888,6 +1052,8 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qstr, uint id_flags, int lo
asm_arm_mov_reg_local(emit->as, REG_R0, local_num - REG_LOCAL_NUM);
emit_post_push_reg(emit, vtype, REG_R0);
}
+#else
+ #error not implemented
#endif
}
@@ -955,6 +1121,13 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre_pop_reg(emit, &vtype, REG_RAX);
asm_x64_mov_r64_to_local(emit->as, REG_RAX, local_num - REG_LOCAL_NUM);
}
+#elif N_X86
+ if (local_num == 0) {
+ emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
+ } else {
+ emit_pre_pop_reg(emit, &vtype, REG_EAX);
+ asm_x86_mov_r32_to_local(emit->as, REG_EAX, local_num - REG_LOCAL_NUM);
+ }
#elif N_THUMB
if (local_num == 0) {
emit_pre_pop_reg(emit, &vtype, REG_LOCAL_1);
@@ -977,6 +1150,8 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qstr, int local_num) {
emit_pre_pop_reg(emit, &vtype, REG_R0);
asm_arm_mov_local_reg(emit->as, local_num - REG_LOCAL_NUM, REG_R0);
}
+#else
+ #error not implemented
#endif
emit_post(emit);
@@ -1012,7 +1187,7 @@ STATIC void emit_native_store_global(emit_t *emit, qstr qstr) {
} else {
emit_pre_pop_reg(emit, &vtype, REG_ARG_1);
emit_call_with_imm_arg(emit, MP_F_CONVERT_NATIVE_TO_OBJ, vtype, REG_ARG_2); // arg2 = type
- ASM_MOV_REG_TO_REG(REG_RET, REG_ARG_2);
+ ASM_MOV_REG_TO_REG(emit->as, REG_RET, REG_ARG_2);
}
emit_call_with_imm_arg(emit, MP_F_STORE_GLOBAL, qstr, REG_ARG_1); // arg1 = name
emit_post(emit);
@@ -1110,13 +1285,7 @@ STATIC void emit_native_jump(emit_t *emit, uint label) {
emit_native_pre(emit);
// need to commit stack because we are jumping elsewhere
need_stack_settled(emit);
-#if N_X64
- asm_x64_jmp_label(emit->as, label);
-#elif N_THUMB
- asm_thumb_b_label(emit->as, label);
-#elif N_ARM
- asm_arm_b_label(emit->as, label);
-#endif
+ ASM_JUMP(emit->as, label);
emit_post(emit);
}
@@ -1143,62 +1312,26 @@ STATIC void emit_native_jump_helper(emit_t *emit, uint label, bool pop) {
STATIC void emit_native_pop_jump_if_true(emit_t *emit, uint label) {
emit_native_jump_helper(emit, label, true);
-#if N_X64
- asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
- asm_x64_jcc_label(emit->as, JCC_JNZ, label);
-#elif N_THUMB
- asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
- asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label);
-#elif N_ARM
- asm_arm_cmp_reg_i8(emit->as, REG_RET, 0);
- asm_arm_bcc_label(emit->as, ARM_CC_NE, label);
-#endif
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
emit_post(emit);
}
STATIC void emit_native_pop_jump_if_false(emit_t *emit, uint label) {
emit_native_jump_helper(emit, label, true);
-#if N_X64
- asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
- asm_x64_jcc_label(emit->as, JCC_JZ, label);
-#elif N_THUMB
- asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
- asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
-#elif N_ARM
- asm_arm_cmp_reg_i8(emit->as, REG_RET, 0);
- asm_arm_bcc_label(emit->as, ARM_CC_EQ, label);
-#endif
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
emit_post(emit);
}
STATIC void emit_native_jump_if_true_or_pop(emit_t *emit, uint label) {
emit_native_jump_helper(emit, label, false);
-#if N_X64
- asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
- asm_x64_jcc_label(emit->as, JCC_JNZ, label);
-#elif N_THUMB
- asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
- asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label);
-#elif N_ARM
- asm_arm_cmp_reg_i8(emit->as, REG_RET, 0);
- asm_arm_bcc_label(emit->as, ARM_CC_NE, label);
-#endif
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
adjust_stack(emit, -1);
emit_post(emit);
}
STATIC void emit_native_jump_if_false_or_pop(emit_t *emit, uint label) {
emit_native_jump_helper(emit, label, false);
-#if N_X64
- asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
- asm_x64_jcc_label(emit->as, JCC_JZ, label);
-#elif N_THUMB
- asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
- asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
-#elif N_ARM
- asm_arm_cmp_reg_i8(emit->as, REG_RET, 0);
- asm_arm_bcc_label(emit->as, ARM_CC_EQ, label);
-#endif
+ ASM_JUMP_IF_REG_ZERO(emit->as, REG_RET, label);
adjust_stack(emit, -1);
emit_post(emit);
}
@@ -1226,16 +1359,7 @@ STATIC void emit_native_setup_except(emit_t *emit, uint label) {
need_stack_settled(emit);
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf
emit_call(emit, MP_F_NLR_PUSH);
-#if N_X64
- asm_x64_test_r8_with_r8(emit->as, REG_RET, REG_RET);
- asm_x64_jcc_label(emit->as, JCC_JNZ, label);
-#elif N_THUMB
- asm_thumb_cmp_rlo_i8(emit->as, REG_RET, 0);
- asm_thumb_bcc_label(emit->as, THUMB_CC_NE, label);
-#elif N_ARM
- asm_arm_cmp_reg_i8(emit->as, REG_RET, 0);
- asm_arm_bcc_label(emit->as, ARM_CC_NE, label);
-#endif
+ ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
emit_post(emit);
}
@@ -1265,17 +1389,8 @@ STATIC void emit_native_for_iter(emit_t *emit, uint label) {
emit_access_stack(emit, 1, &vtype, REG_ARG_1);
assert(vtype == VTYPE_PYOBJ);
emit_call(emit, MP_F_ITERNEXT);
- ASM_MOV_IMM_TO_REG((mp_uint_t)MP_OBJ_STOP_ITERATION, REG_TEMP1);
-#if N_X64
- asm_x64_cmp_r64_with_r64(emit->as, REG_RET, REG_TEMP1);
- asm_x64_jcc_label(emit->as, JCC_JE, label);
-#elif N_THUMB
- asm_thumb_cmp_rlo_rlo(emit->as, REG_RET, REG_TEMP1);
- asm_thumb_bcc_label(emit->as, THUMB_CC_EQ, label);
-#elif N_ARM
- asm_arm_cmp_reg_i8(emit->as, REG_RET, 0);
- asm_arm_bcc_label(emit->as, ARM_CC_EQ, label);
-#endif
+ ASM_MOV_IMM_TO_REG(emit->as, (mp_uint_t)MP_OBJ_STOP_ITERATION, REG_TEMP1);
+ ASM_JUMP_IF_REG_EQ(emit->as, REG_RET, REG_TEMP1, label);
emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET);
}
@@ -1322,17 +1437,25 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
if (op == MP_BINARY_OP_ADD || op == MP_BINARY_OP_INPLACE_ADD) {
#if N_X64
asm_x64_add_r64_to_r64(emit->as, REG_ARG_3, REG_ARG_2);
+#elif N_X86
+ asm_x86_add_r32_to_r32(emit->as, REG_ARG_3, REG_ARG_2);
#elif N_THUMB
asm_thumb_add_rlo_rlo_rlo(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3);
#elif N_ARM
asm_arm_add_reg(emit->as, REG_ARG_2, REG_ARG_2, REG_ARG_3);
+#else
+ #error not implemented
#endif
emit_post_push_reg(emit, VTYPE_INT, REG_ARG_2);
} else if (op == MP_BINARY_OP_LESS) {
#if N_X64
asm_x64_xor_r64_to_r64(emit->as, REG_RET, REG_RET);
asm_x64_cmp_r64_with_r64(emit->as, REG_ARG_3, REG_ARG_2);
- asm_x64_setcc_r8(emit->as, JCC_JL, REG_RET);
+ asm_x64_setcc_r8(emit->as, ASM_X64_CC_JL, REG_RET);
+#elif N_X86
+ asm_x86_xor_r32_to_r32(emit->as, REG_RET, REG_RET);
+ asm_x86_cmp_r32_with_r32(emit->as, REG_ARG_3, REG_ARG_2);
+ asm_x86_setcc_r8(emit->as, ASM_X86_CC_JL, REG_RET);
#elif N_THUMB
asm_thumb_cmp_rlo_rlo(emit->as, REG_ARG_2, REG_ARG_3);
asm_thumb_ite_ge(emit->as);
@@ -1340,6 +1463,8 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
asm_thumb_mov_rlo_i8(emit->as, REG_RET, 1); // if r0 < r1
#elif N_ARM
asm_arm_less_op(emit->as, REG_ARG_2, REG_ARG_3);
+#else
+ #error not implemented
#endif
emit_post_push_reg(emit, VTYPE_BOOL, REG_RET);
} else {
@@ -1558,7 +1683,7 @@ STATIC void emit_native_return_value(emit_t *emit) {
if (emit->do_viper_types) {
if (vtype == VTYPE_PTR_NONE) {
if (emit->return_vtype == VTYPE_PYOBJ) {
- ASM_MOV_IMM_TO_REG((mp_uint_t)mp_const_none, REG_RET);
+ ASM_MOV_IMM_TO_REG(emit->as, (mp_uint_t)mp_const_none, REG_RET);
}
} else if (vtype != emit->return_vtype) {
printf("ViperTypeError: incompatible return type\n");
@@ -1567,16 +1692,8 @@ STATIC void emit_native_return_value(emit_t *emit) {
assert(vtype == VTYPE_PYOBJ);
}
emit->last_emit_was_return_value = true;
-#if N_X64
- //asm_x64_call_ind(emit->as, 0, REG_RAX); to seg fault for debugging with gdb
- asm_x64_exit(emit->as);
-#elif N_THUMB
- //asm_thumb_call_ind(emit->as, 0, REG_R0); to seg fault for debugging with gdb
- asm_thumb_exit(emit->as);
-#elif N_ARM
- //asm_arm_bkpt(emit->as); to insert a bkpt and not segfault for debugging
- asm_arm_exit(emit->as);
-#endif
+ //ASM_BREAK_POINT(emit->as); // to insert a break-point for debugging
+ ASM_EXIT(emit->as);
}
STATIC void emit_native_raise_varargs(emit_t *emit, int n_args) {
@@ -1704,4 +1821,4 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
emit_native_end_except_handler,
};
-#endif // (MICROPY_EMIT_X64 && N_X64) || (MICROPY_EMIT_THUMB && N_THUMB) || (MICROPY_EMIT_ARM && N_ARM)
+#endif