|
47 | 47 | ALU_SEL_RST = 2 |
48 | 48 |
|
49 | 49 | OPCODE_BRANCH = 8 |
| 50 | +# https://github.com/espressif/binutils-esp32ulp/blob/d61f86f97eda43fc118df30d019fc062aaa6bc8d/include/opcode/esp32ulp_esp32.h#L85 |
50 | 51 | SUB_OPCODE_BX = 0 |
| 52 | +SUB_OPCODE_BR = 1 |
| 53 | +SUB_OPCODE_BS = 2 |
51 | 54 | BX_JUMP_TYPE_DIRECT = 0 |
52 | 55 | BX_JUMP_TYPE_ZERO = 1 |
53 | 56 | 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 |
61 | 63 |
|
62 | 64 | OPCODE_END = 9 |
63 | 65 | SUB_OPCODE_END = 0 |
@@ -210,23 +212,23 @@ def make_ins(layout): |
210 | 212 | """) |
211 | 213 |
|
212 | 214 |
|
213 | | -_b = make_ins(""" |
| 215 | +_br = make_ins(""" |
214 | 216 | 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 |
216 | 218 | offset : 7 # Absolute value of target PC offset w.r.t. current PC, expressed in words |
217 | 219 | 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) |
219 | 221 | opcode : 4 # Opcode (OPCODE_BRANCH) |
220 | 222 | """) |
221 | 223 |
|
222 | 224 |
|
223 | | -_bc = make_ins(""" |
| 225 | +_bs = make_ins(""" |
224 | 226 | imm : 8 # Immediate value to compare against |
225 | 227 | 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 |
227 | 229 | offset : 7 # Absolute value of target PC offset w.r.t. current PC, expressed in words |
228 | 230 | 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) |
230 | 232 | opcode : 4 # Opcode (OPCODE_BRANCH) |
231 | 233 | """) |
232 | 234 |
|
@@ -639,36 +641,36 @@ def i_jumpr(offset, threshold, condition): |
639 | 641 | threshold = get_imm(threshold) |
640 | 642 | condition = get_cond(condition) |
641 | 643 | if condition == 'lt': |
642 | | - cmp_op = B_CMP_L |
| 644 | + cmp_op = BRCOND_LT |
643 | 645 | elif condition == 'ge': |
644 | | - cmp_op = B_CMP_GE |
| 646 | + cmp_op = BRCOND_GE |
645 | 647 | else: |
646 | 648 | 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 |
654 | 656 |
|
655 | 657 |
|
656 | 658 | def i_jumps(offset, threshold, condition): |
657 | 659 | offset = get_rel(offset) |
658 | 660 | threshold = get_imm(threshold) |
659 | 661 | condition = get_cond(condition) |
660 | 662 | if condition == 'lt': |
661 | | - cmp_op = BC_CMP_LT |
| 663 | + cmp_op = BRCOND_LT |
662 | 664 | elif condition == 'gt': |
663 | | - cmp_op = BC_CMP_GT |
| 665 | + cmp_op = BRCOND_GT |
664 | 666 | elif condition == 'eq': |
665 | | - cmp_op = BC_CMP_EQ |
| 667 | + cmp_op = BRCOND_EQ |
666 | 668 | else: |
667 | 669 | 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