Files
micropython/tests/inlineasm/thumb/asmbcc.py
T
Alessandro Gatti b67c55cb4f py/emitinlinethumb: Shrink condition code lookups.
This commit optimises the lookup of opcodes' condition codes, in order
to take up less code than before.

The original data was held in a table containing the condition code
value (an incrementing 0-based integer) and the two condition ASCII
characters.  Given that the condition code value also matches the
entry's index in the table, that can be safely omitted.

This saves 52 bytes when compiled for Thumb.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2026-04-15 15:35:27 +10:00

66 lines
882 B
Python

# test bcc instructions, narrow and wide versions
RESULT = []
TEMPLATE = """
@micropython.asm_thumb
def t(r0):
mov(r1, r0)
mov(r0, 10)
cmp(r1, 1)
b{}(next1)
b(end)
label(next1)
mov(r0, 20)
cmp(r1, 2)
b{}_n(next2)
b(end)
label(next2)
mov(r0, 30)
cmp(r1, 3)
b{}_w(next3)
b(end)
label(next3)
mov(r0, 0)
label(end)
"""
try:
for code in (
"eq",
"ne",
"cs",
"cc",
"mi",
"pl",
"vs",
"vc",
"hi",
"ls",
"ge",
"lt",
"gt",
"le",
):
exec(TEMPLATE.format(code, code, code))
RESULT.append("B" + code.upper())
for i in range(4):
RESULT.append(t(i))
except MemoryError:
print("SKIP-TOO-LARGE")
raise SystemExit
for line in RESULT:
print(line)