Overview
mixin_dir_instr_list(riscv_instr_stream[] dir_list) is presented as Listing 6, titled “Lazy merging of directed streams to make RISCV-DV scalable.” The function merges directed instruction streams into an existing randomized instruction list without immediately inserting each stream into the queue at its chosen location. Instead, it records where streams should be injected and later constructs a merged instruction dump in one pass. [C1]
Motivation
The original RISCV-DV merge process is described as greedy: it randomly chooses an injection point for each directed stream, retries if that point falls inside an already inserted directed sequence, and eventually adjusts the point to preserve directed sequence boundaries. This approach requires inserting slices into a SystemVerilog queue, which is costly because elements after the insertion point must be moved. As instruction counts and directed-stream counts grow, the average moved block size also grows, producing O(n²) complexity and poor scaling for instruction counts larger than one hundred thousand. [C2]
Algorithm
The refactored function uses a lazy merge strategy:
- It initializes bookkeeping based on the current
instr_listlength and stores the provided directed stream list inthis.dir_instr_list. [C3] - For each directed stream, it adds the stream length to
mixed_count, chooses a random target indexrnd_idx, and records the directed stream index indir_nat that location. [C3] - If another directed stream is already recorded at the same location, the function chains the streams using each stream object’s
next_streamfield, creating a linked-list-like structure for streams assigned to the same insertion point. [C4] - After all insertion locations are recorded, the function allocates
mixed_listtomixed_countand iterates over the originalinstr_list. At each original instruction index, it first emits any directed streams chained at that location, then emits the original instruction. [C5] - Finally, it replaces the original instruction list by calling
instr_list.assimilate(mixed_list). [C5]
Complexity and scaling behavior
The paper states that this algorithmic refactoring reduces the insertion process to O(n), making it scale linearly. The key change is that directed streams are not inserted into the queue one at a time; instead, their locations are tabulated first, and the merged instruction dump is created in one pass. After re-profiling, the merge process was reported to scale well and no longer be a bottleneck for large test-program generation. [C6]
Role in RISCV-DV generation
The function is part of a RISCV-DV scalability improvement aimed at generating large test programs. The surrounding discussion notes that larger test programs can produce increasingly complex program flows that are more likely to uncover processor bugs. [C7]