From cca08922d9ce78afba419a8303d88b5c123f0baa Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 26 May 2022 11:54:48 +1000 Subject: [PATCH] py/emitinlinethumb: Make ARMv7-M instruction use dynamically selectable. This follows on from a5324a10747dfba921bb363ed904f05ebb6de010 and allows mpy-cross to dynamically select whether ARMv7-M instructions are supported in @micropython.asm_thumb functions. The config option MICROPY_EMIT_INLINE_THUMB_ARMV7M is no longer needed, it is now controlled by MICROPY_EMIT_THUMB_ARMV7M. Signed-off-by: Damien George --- mpy-cross/mpconfigport.h | 1 - ports/rp2/mpconfigport.h | 1 - py/emitinlinethumb.c | 12 +++++------- py/mpconfig.h | 5 ----- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/mpy-cross/mpconfigport.h b/mpy-cross/mpconfigport.h index 4c10afe9bb..11aeaeeab7 100644 --- a/mpy-cross/mpconfigport.h +++ b/mpy-cross/mpconfigport.h @@ -42,7 +42,6 @@ #define MICROPY_EMIT_X86 (1) #define MICROPY_EMIT_THUMB (1) #define MICROPY_EMIT_INLINE_THUMB (1) -#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1) #define MICROPY_EMIT_INLINE_THUMB_FLOAT (1) #define MICROPY_EMIT_ARM (1) #define MICROPY_EMIT_XTENSA (1) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 3ded45fa10..a733f750d4 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -55,7 +55,6 @@ #define MICROPY_EMIT_THUMB_ARMV7M (0) #define MICROPY_EMIT_INLINE_THUMB (1) #define MICROPY_EMIT_INLINE_THUMB_FLOAT (0) -#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (0) // Optimisations #define MICROPY_OPT_COMPUTED_GOTO (1) diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 1a9c06a2ad..40f0028954 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -423,7 +423,7 @@ STATIC const format_vfp_op_t format_vfp_op_table[] = { #endif // shorthand alias for whether we allow ARMv7-M instructions -#define ARMV7M MICROPY_EMIT_INLINE_THUMB_ARMV7M +#define ARMV7M asm_thumb_allow_armv7m(&emit->as) STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { // TODO perhaps make two tables: @@ -715,24 +715,23 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a } else if (op == MP_QSTR_sub) { op_code = ASM_THUMB_FORMAT_3_SUB; goto op_format_3; - #if ARMV7M - } else if (op == MP_QSTR_movw) { + } else if (ARMV7M && op == MP_QSTR_movw) { op_code = ASM_THUMB_OP_MOVW; mp_uint_t reg_dest; op_movw_movt: reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15); int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff); asm_thumb_mov_reg_i16(&emit->as, op_code, reg_dest, i_src); - } else if (op == MP_QSTR_movt) { + } else if (ARMV7M && op == MP_QSTR_movt) { op_code = ASM_THUMB_OP_MOVT; goto op_movw_movt; - } else if (op == MP_QSTR_movwt) { + } else if (ARMV7M && op == MP_QSTR_movwt) { // this is a convenience instruction mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15); uint32_t i_src = get_arg_i(emit, op_str, pn_args[1], 0xffffffff); asm_thumb_mov_reg_i16(&emit->as, ASM_THUMB_OP_MOVW, reg_dest, i_src & 0xffff); asm_thumb_mov_reg_i16(&emit->as, ASM_THUMB_OP_MOVT, reg_dest, (i_src >> 16) & 0xffff); - } else if (op == MP_QSTR_ldrex) { + } else if (ARMV7M && op == MP_QSTR_ldrex) { mp_uint_t r_dest = get_arg_reg(emit, op_str, pn_args[0], 15); mp_parse_node_t pn_base, pn_offset; if (get_arg_addr(emit, op_str, pn_args[1], &pn_base, &pn_offset)) { @@ -740,7 +739,6 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a mp_uint_t i8 = get_arg_i(emit, op_str, pn_offset, 0xff) >> 2; asm_thumb_op32(&emit->as, 0xe850 | r_base, 0x0f00 | (r_dest << 12) | i8); } - #endif } else { // search table for ldr/str instructions for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(format_9_10_op_table); i++) { diff --git a/py/mpconfig.h b/py/mpconfig.h index bac6362d17..00890942bb 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -361,11 +361,6 @@ #define MICROPY_EMIT_INLINE_THUMB (0) #endif -// Whether to enable ARMv7-M instruction support in the Thumb2 inline assembler -#ifndef MICROPY_EMIT_INLINE_THUMB_ARMV7M -#define MICROPY_EMIT_INLINE_THUMB_ARMV7M (1) -#endif - // Whether to enable float support in the Thumb2 inline assembler #ifndef MICROPY_EMIT_INLINE_THUMB_FLOAT #define MICROPY_EMIT_INLINE_THUMB_FLOAT (1)