Skip to content

Commit f76b1bf

Browse files
committed
py: Add inline Xtensa assembler.
This patch adds the MICROPY_EMIT_INLINE_XTENSA option, which, when enabled, allows the @micropython.asm_xtensa decorator to be used. The following opcodes are currently supported (ax is a register, a0-a15): ret_n() callx0(ax) j(label) jx(ax) beqz(ax, label) bnez(ax, label) mov(ax, ay) movi(ax, imm) # imm can be full 32-bit, uses l32r if needed and_(ax, ay, az) or_(ax, ay, az) xor(ax, ay, az) add(ax, ay, az) sub(ax, ay, az) mull(ax, ay, az) l8ui(ax, ay, imm) l16ui(ax, ay, imm) l32i(ax, ay, imm) s8i(ax, ay, imm) s16i(ax, ay, imm) s32i(ax, ay, imm) l16si(ax, ay, imm) addi(ax, ay, imm) ball(ax, ay, label) bany(ax, ay, label) bbc(ax, ay, label) bbs(ax, ay, label) beq(ax, ay, label) bge(ax, ay, label) bgeu(ax, ay, label) blt(ax, ay, label) bnall(ax, ay, label) bne(ax, ay, label) bnone(ax, ay, label) Upon entry to the assembly function the registers a0, a12, a13, a14 are pushed to the stack and the stack pointer (a1) decreased by 16. Upon exit, these registers and the stack pointer are restored, and ret.n is executed to return to the caller (caller address is in a0). Note that the ABI for the Xtensa emitters is non-windowing.
1 parent ad297a1 commit f76b1bf

6 files changed

Lines changed: 380 additions & 3 deletions

File tree

py/asmxtensa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include "py/mpconfig.h"
3131

3232
// wrapper around everything in this file
33-
#if MICROPY_EMIT_XTENSA
33+
#if MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA
3434

3535
#include "py/asmxtensa.h"
3636

@@ -167,4 +167,4 @@ void asm_xtensa_mov_reg_local_addr(asm_xtensa_t *as, uint reg_dest, int local_nu
167167
asm_xtensa_op_addi(as, reg_dest, reg_dest, (4 + local_num) * WORD_SIZE);
168168
}
169169

170-
#endif // MICROPY_EMIT_XTENSA
170+
#endif // MICROPY_EMIT_XTENSA || MICROPY_EMIT_INLINE_XTENSA

py/compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ typedef enum {
9191
#if MICROPY_EMIT_INLINE_THUMB
9292
#define ASM_DECORATOR_QSTR MP_QSTR_asm_thumb
9393
#define ASM_EMITTER(f) emit_inline_thumb_##f
94+
#elif MICROPY_EMIT_INLINE_XTENSA
95+
#define ASM_DECORATOR_QSTR MP_QSTR_asm_xtensa
96+
#define ASM_EMITTER(f) emit_inline_xtensa_##f
9497
#else
9598
#error "unknown asm emitter"
9699
#endif

py/emit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,13 @@ typedef struct _emit_inline_asm_method_table_t {
272272
} emit_inline_asm_method_table_t;
273273

274274
extern const emit_inline_asm_method_table_t emit_inline_thumb_method_table;
275+
extern const emit_inline_asm_method_table_t emit_inline_xtensa_method_table;
275276

276277
emit_inline_asm_t *emit_inline_thumb_new(mp_uint_t max_num_labels);
278+
emit_inline_asm_t *emit_inline_xtensa_new(mp_uint_t max_num_labels);
279+
277280
void emit_inline_thumb_free(emit_inline_asm_t *emit);
281+
void emit_inline_xtensa_free(emit_inline_asm_t *emit);
278282

279283
#if MICROPY_WARNINGS
280284
void mp_emitter_warning(pass_kind_t pass, const char *msg);

0 commit comments

Comments
 (0)