Skip to content

Commit bd413d3

Browse files
agattidpgeorge
authored andcommitted
py/asmthumb: Fix T3 encoding of conditional branches.
This commit fixes the encoding of conditional branch opcodes emitted for ARMv7-M targets, when the emitter decides to use the T3 encoding for said operation. Fields J1 and J2 are now present in the generated opcode word, along with correcting some minor issues in bitmasks and shifts computation. This fixes #17940. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
1 parent 22deeeb commit bd413d3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

py/asmthumb.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,8 @@ bool asm_thumb_b_n_label(asm_thumb_t *as, uint label) {
267267

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

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

274273
bool asm_thumb_bcc_nw_label(asm_thumb_t *as, int cond, uint label, bool wide) {
275274
mp_uint_t dest = get_label_dest(as, label);

tests/micropython/viper_large_jump.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
COUNT = 600
2+
3+
4+
try:
5+
code = """
6+
@micropython.viper
7+
def f() -> int:
8+
x = 0
9+
while x < 10:
10+
"""
11+
for i in range(COUNT):
12+
code += " x += 1\n"
13+
code += " return x"
14+
exec(code)
15+
except MemoryError:
16+
print("SKIP-TOO-LARGE")
17+
raise SystemExit
18+
19+
20+
print(f())
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
600

0 commit comments

Comments
 (0)