Skip to content

Commit 50fab08

Browse files
agattidpgeorge
authored andcommitted
py/emitinlinextensa: Simplify register name lookup.
This commit changes the Xtensa inline assembly parser to use a slightly simpler (and probably a tiny bit more efficient) way to look up register names when decoding instruction parameters. Signed-off-by: Alessandro Gatti <[email protected]>
1 parent 8633abc commit 50fab08

File tree

1 file changed

+10
-39
lines changed

1 file changed

+10
-39
lines changed

py/emitinlinextensa.c

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -115,50 +115,21 @@ static bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_nu
115115
return true;
116116
}
117117

118-
typedef struct _reg_name_t { byte reg;
119-
byte name[3];
120-
} reg_name_t;
121-
static const reg_name_t reg_name_table[] = {
122-
{0, "a0\0"},
123-
{1, "a1\0"},
124-
{2, "a2\0"},
125-
{3, "a3\0"},
126-
{4, "a4\0"},
127-
{5, "a5\0"},
128-
{6, "a6\0"},
129-
{7, "a7\0"},
130-
{8, "a8\0"},
131-
{9, "a9\0"},
132-
{10, "a10"},
133-
{11, "a11"},
134-
{12, "a12"},
135-
{13, "a13"},
136-
{14, "a14"},
137-
{15, "a15"},
118+
static const qstr_short_t REGISTERS[16] = {
119+
MP_QSTR_a0, MP_QSTR_a1, MP_QSTR_a2, MP_QSTR_a3, MP_QSTR_a4, MP_QSTR_a5, MP_QSTR_a6, MP_QSTR_a7,
120+
MP_QSTR_a8, MP_QSTR_a9, MP_QSTR_a10, MP_QSTR_a11, MP_QSTR_a12, MP_QSTR_a13, MP_QSTR_a14, MP_QSTR_a15
138121
};
139122

140-
// return empty string in case of error, so we can attempt to parse the string
141-
// without a special check if it was in fact a string
142-
static const char *get_arg_str(mp_parse_node_t pn) {
143-
if (MP_PARSE_NODE_IS_ID(pn)) {
144-
qstr qst = MP_PARSE_NODE_LEAF_ARG(pn);
145-
return qstr_str(qst);
146-
} else {
147-
return "";
148-
}
149-
}
150-
151123
static mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) {
152-
const char *reg_str = get_arg_str(pn);
153-
for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) {
154-
const reg_name_t *r = &reg_name_table[i];
155-
if (reg_str[0] == r->name[0]
156-
&& reg_str[1] == r->name[1]
157-
&& reg_str[2] == r->name[2]
158-
&& (reg_str[2] == '\0' || reg_str[3] == '\0')) {
159-
return r->reg;
124+
if (MP_PARSE_NODE_IS_ID(pn)) {
125+
qstr node_qstr = MP_PARSE_NODE_LEAF_ARG(pn);
126+
for (size_t i = 0; i < MP_ARRAY_SIZE(REGISTERS); i++) {
127+
if (node_qstr == REGISTERS[i]) {
128+
return i;
129+
}
160130
}
161131
}
132+
162133
emit_inline_xtensa_error_exc(emit,
163134
mp_obj_new_exception_msg_varg(&mp_type_SyntaxError,
164135
MP_ERROR_TEXT("'%s' expects a register"), op));

0 commit comments

Comments
 (0)