Skip to content

Commit a96a7ee

Browse files
committed
refactor: rename sub_opcode and condition constants for JUMPR/JUMPS instructions as per latest binutils-esp32ulp naming
Only renames. No change in behaviour/functionality.
1 parent a5601e8 commit a96a7ee

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

esp32_ulp/opcodes.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,19 @@
4747
ALU_SEL_RST = 2
4848

4949
OPCODE_BRANCH = 8
50+
# https://github.com/espressif/binutils-esp32ulp/blob/d61f86f97eda43fc118df30d019fc062aaa6bc8d/include/opcode/esp32ulp_esp32.h#L85
5051
SUB_OPCODE_BX = 0
52+
SUB_OPCODE_BR = 1
53+
SUB_OPCODE_BS = 2
5154
BX_JUMP_TYPE_DIRECT = 0
5255
BX_JUMP_TYPE_ZERO = 1
5356
BX_JUMP_TYPE_OVF = 2
54-
SUB_OPCODE_B = 1
55-
B_CMP_L = 0
56-
B_CMP_GE = 1
57-
SUB_OPCODE_BC = 2
58-
BC_CMP_LT = 0
59-
BC_CMP_GT = 1
60-
BC_CMP_EQ = 2
57+
# https://github.com/espressif/binutils-esp32ulp/blob/d61f86f97eda43fc118df30d019fc062aaa6bc8d/gas/config/tc-esp32ulp.h#L91
58+
BRCOND_LT = 0
59+
BRCOND_GE = 1
60+
BRCOND_LE = 2
61+
BRCOND_EQ = 3
62+
BRCOND_GT = 4
6163

6264
OPCODE_END = 9
6365
SUB_OPCODE_END = 0
@@ -210,23 +212,23 @@ def make_ins(layout):
210212
""")
211213

212214

213-
_b = make_ins("""
215+
_br = make_ins("""
214216
imm : 16 # Immediate value to compare against
215-
cmp : 1 # Comparison to perform: B_CMP_L or B_CMP_GE
217+
cmp : 1 # Comparison to perform: BRCOND_LT or BRCOND_GE
216218
offset : 7 # Absolute value of target PC offset w.r.t. current PC, expressed in words
217219
sign : 1 # Sign of target PC offset: 0: positive, 1: negative
218-
sub_opcode : 3 # Sub opcode (SUB_OPCODE_B)
220+
sub_opcode : 3 # Sub opcode (SUB_OPCODE_BR)
219221
opcode : 4 # Opcode (OPCODE_BRANCH)
220222
""")
221223

222224

223-
_bc = make_ins("""
225+
_bs = make_ins("""
224226
imm : 8 # Immediate value to compare against
225227
unused : 7 # Unused
226-
cmp : 2 # Comparison to perform: BC_CMP_LT, GT or EQ
228+
cmp : 2 # Comparison to perform: BRCOND_LT, GT or EQ
227229
offset : 7 # Absolute value of target PC offset w.r.t. current PC, expressed in words
228230
sign : 1 # Sign of target PC offset: 0: positive, 1: negative
229-
sub_opcode : 3 # Sub opcode (SUB_OPCODE_BC)
231+
sub_opcode : 3 # Sub opcode (SUB_OPCODE_BS)
230232
opcode : 4 # Opcode (OPCODE_BRANCH)
231233
""")
232234

@@ -639,36 +641,36 @@ def i_jumpr(offset, threshold, condition):
639641
threshold = get_imm(threshold)
640642
condition = get_cond(condition)
641643
if condition == 'lt':
642-
cmp_op = B_CMP_L
644+
cmp_op = BRCOND_LT
643645
elif condition == 'ge':
644-
cmp_op = B_CMP_GE
646+
cmp_op = BRCOND_GE
645647
else:
646648
raise ValueError("invalid comparison condition")
647-
_b.imm = threshold
648-
_b.cmp = cmp_op
649-
_b.offset = abs(offset)
650-
_b.sign = 0 if offset >= 0 else 1
651-
_b.sub_opcode = SUB_OPCODE_B
652-
_b.opcode = OPCODE_BRANCH
653-
return _b.all
649+
_br.imm = threshold
650+
_br.cmp = cmp_op
651+
_br.offset = abs(offset)
652+
_br.sign = 0 if offset >= 0 else 1
653+
_br.sub_opcode = SUB_OPCODE_BR
654+
_br.opcode = OPCODE_BRANCH
655+
return _br.all
654656

655657

656658
def i_jumps(offset, threshold, condition):
657659
offset = get_rel(offset)
658660
threshold = get_imm(threshold)
659661
condition = get_cond(condition)
660662
if condition == 'lt':
661-
cmp_op = BC_CMP_LT
663+
cmp_op = BRCOND_LT
662664
elif condition == 'gt':
663-
cmp_op = BC_CMP_GT
665+
cmp_op = BRCOND_GT
664666
elif condition == 'eq':
665-
cmp_op = BC_CMP_EQ
667+
cmp_op = BRCOND_EQ
666668
else:
667669
raise ValueError("invalid comparison condition")
668-
_bc.imm = threshold
669-
_bc.cmp = cmp_op
670-
_bc.offset = abs(offset)
671-
_bc.sign = 0 if offset >= 0 else 1
672-
_bc.sub_opcode = SUB_OPCODE_BC
673-
_bc.opcode = OPCODE_BRANCH
674-
return _bc.all
670+
_bs.imm = threshold
671+
_bs.cmp = cmp_op
672+
_bs.offset = abs(offset)
673+
_bs.sign = 0 if offset >= 0 else 1
674+
_bs.sub_opcode = SUB_OPCODE_BS
675+
_bs.opcode = OPCODE_BRANCH
676+
return _bs.all

0 commit comments

Comments
 (0)