Skip to content

py/asmthumb: Fix T3 encoding of conditional branches. #17946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions py/asmthumb.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ bool asm_thumb_b_n_label(asm_thumb_t *as, uint label) {

#define OP_BCC_N(cond, byte_offset) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff))

// all these bit-arithmetic operations need coverage testing!
#define OP_BCC_W_HI(cond, byte_offset) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f))
#define OP_BCC_W_LO(byte_offset) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff))
#define OP_BCC_W_HI(cond, byte_offset) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 12) & 0x003f))
#define OP_BCC_W_LO(byte_offset) (0x8000 | (((byte_offset) >> 5) & 0x2000) | (((byte_offset) >> 8) & 0x0800) | (((byte_offset) >> 1) & 0x07ff))

bool asm_thumb_bcc_nw_label(asm_thumb_t *as, int cond, uint label, bool wide) {
mp_uint_t dest = get_label_dest(as, label);
Expand Down
20 changes: 20 additions & 0 deletions tests/micropython/viper_large_jump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
COUNT = 600


try:
code = """
@micropython.viper
def f() -> int:
x = 0
while x < 10:
"""
for i in range(COUNT):
code += " x += 1\n"
code += " return x"
exec(code)
except MemoryError:
print("SKIP-TOO-LARGE")
raise SystemExit


print(f())
1 change: 1 addition & 0 deletions tests/micropython/viper_large_jump.py.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
600
Loading