Skip to content

Commit ffb07ec

Browse files
patrick-rivosrbertran
authored andcommitted
Add -combinations flag to mp_seq.py
Currently mp_seq.py emits permuations of each insn pair within a group or between groups. The -combinations flag allows the user to only generate unique insn combinations. Signed-Off-By: Patrick O'Neill <[email protected]>
1 parent 1965787 commit ffb07ec

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

targets/generic/tools/mp_seq.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ def main():
362362
group=groupname,
363363
)
364364

365+
cmdline.add_flag(
366+
"combinations",
367+
"combinations",
368+
"Only generate combinations of the given instructions",
369+
group=groupname,
370+
)
371+
365372
cmdline.add_flag(
366373
"shortnames",
367374
"sn",
@@ -392,7 +399,7 @@ def main():
392399
@typeguard_testsuite
393400
def _generate_sequences(slots: int, instruction_groups, instruction_map,
394401
group_max: List[int], group_min: List[int],
395-
base_seq: List[InstructionType]):
402+
base_seq: List[InstructionType], combinations: bool):
396403

397404
instr_names = []
398405
instr_objs = []
@@ -435,6 +442,8 @@ def _generate_sequences(slots: int, instruction_groups, instruction_map,
435442
f"\tMax intr: {group_max[idx]}")
436443
print_info("")
437444

445+
seen = set()
446+
438447
for seq in itertools.product(*[descr[1] for descr in slot_dsrc]):
439448
valid = True
440449
for idx, igroup in enumerate(instruction_groups):
@@ -460,6 +469,13 @@ def _generate_sequences(slots: int, instruction_groups, instruction_map,
460469
instr_obj for instr_obj in instr_objs
461470
if instr_obj.name == instrname
462471
]
472+
if combinations:
473+
# Only generate combinations, not permutations
474+
if tuple(sorted(sequence)) in seen:
475+
continue
476+
else:
477+
seen.add(tuple(sorted(sequence)))
478+
463479
yield base_seq + sequence
464480

465481

@@ -591,11 +607,13 @@ def _main(arguments):
591607
if 'base_seq' in arguments:
592608
base_seq = parse_instruction_list(target, arguments['base_seq'])
593609

610+
combinations = "combinations" in arguments
611+
594612
sequences = [base_seq]
595613
if len(instruction_groups) > 0:
596614
sequences = _generate_sequences(slots, instruction_groups,
597615
instruction_map, group_max, group_min,
598-
base_seq)
616+
base_seq, combinations)
599617

600618
sequences = [seq for seq in sequences if seq]
601619
if not sequences:
@@ -634,7 +652,7 @@ def _main(arguments):
634652
arguments['compress'] = False
635653

636654
# process batches
637-
print_info("Num sequences difined: %d" % len(sequences))
655+
print_info("Num sequences defined: %d" % len(sequences))
638656
print_info("Number of batches: %d " % arguments["num_batches"])
639657
print_info("Batch number: %d " % arguments["batch_number"])
640658

0 commit comments

Comments
 (0)