Skip to content

Commit a3b84c3

Browse files
committed
add EQ condition for JUMPS
1 parent 180885d commit a3b84c3

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

esp32_ulp/opcodes.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,19 @@ def i_jumpr(offset, threshold, condition):
675675
return _jump_relr(threshold, cmp_op, offset)
676676

677677

678+
def _jump_rels(threshold, cond, offset):
679+
"""
680+
Equivalent of I_JUMP_RELS macro in binutils-esp32ulp
681+
"""
682+
_bs.imm = threshold
683+
_bs.cmp = cond
684+
_bs.offset = abs(offset)
685+
_bs.sign = 0 if offset >= 0 else 1
686+
_bs.sub_opcode = SUB_OPCODE_BS
687+
_bs.opcode = OPCODE_BRANCH
688+
return _bs.all
689+
690+
678691
def i_jumps(offset, threshold, condition):
679692
offset = get_rel(offset)
680693
threshold = get_imm(threshold)
@@ -685,19 +698,27 @@ def i_jumps(offset, threshold, condition):
685698
cmp_op = BRCOND_LE
686699
elif condition == 'ge':
687700
cmp_op = BRCOND_GE
701+
elif condition == 'eq': # eq == le but not lt
702+
skip_cond = BRCOND_LT
703+
jump_cond = BRCOND_LE
704+
705+
# jump over next JUMPS
706+
skip_ins = _jump_rels(threshold, skip_cond, 2)
707+
# jump to target
708+
offset -= 1 # adjust for the additional JUMPS instruction
709+
jump_ins = _jump_rels(threshold, jump_cond, offset)
710+
711+
return (skip_ins, jump_ins)
688712
else:
689713
raise ValueError("invalid comparison condition")
690-
_bs.imm = threshold
691-
_bs.cmp = cmp_op
692-
_bs.offset = abs(offset)
693-
_bs.sign = 0 if offset >= 0 else 1
694-
_bs.sub_opcode = SUB_OPCODE_BS
695-
_bs.opcode = OPCODE_BRANCH
696-
return _bs.all
714+
return _jump_rels(threshold, cmp_op, offset)
697715

698716

699717
def no_of_instr(opcode, args):
700718
if opcode == 'jumpr' and get_cond(args[2]) == 'eq':
701719
return 2
702720

721+
if opcode == 'jumps' and get_cond(args[2]) == 'eq':
722+
return 2
723+
703724
return 1

tests/compat/jumps.S

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ entry:
1010
jumps later, 42, le
1111
jumps entry, 42, ge
1212
jumps later, 42, ge
13+
jumps entry, 42, eq
14+
jumps later, 42, eq
1315

1416
jumpr entry, 42, lt
1517
jumpr later, 42, lt

0 commit comments

Comments
 (0)