Skip to content
STIMSMITH

generate_directed_instr_stream

CodeArtifact WIKI v1 · 5/26/2026

generate_directed_instr_stream() is a function in the riscv-dv assembly program generation flow. It is called during gen_program() after program header and GPR initialization steps, and it decides directed-instruction ratios, inserts directed instruction streams, and randomizes instruction operands such as rs1, rs2, and rd based on instruction type.

Overview

generate_directed_instr_stream() is part of the RISC-V assembly program generation flow described for the riscv_asm_program_gen class in the open-source CHIPS Alliance riscv-dv random instruction generator. The broader generator produces complete RISC-V assembly programs used for RISC-V IP verification, including initialization routines, instruction sections, data sections, stack sections, page tables, and interrupt/exception handling sections.

Role in the generation flow

Within gen_program(), the assembly generator performs several steps before and around directed instruction generation:

  1. gen_program() is the main function that generates all sections of the program.
  2. It calls get_directed_instr_stream() and uses add_directed_instr_stream() to select directed-instruction generation ratios.
  3. It calls gen_program_header(), which fills an instr_stream string array with header content and calls gen_section("_start", str) to insert header instructions.
  4. It calls init_gpr(), which initializes general-purpose registers with random values.
  5. It then calls generate_directed_instr_stream().

Function behavior

According to the available evidence, generate_directed_instr_stream() performs three main tasks:

  • decides the ratio for directed instruction stream insertion;
  • inserts directed instruction streams into the generated program flow;
  • randomizes instructions, including selecting rs1, rs2, and rd operands according to instruction type.

This behavior contributes to producing an assembly program that exercises instructions using different RISC-V general-purpose registers, from x0 through x31. The evidence also states that the post_random() function of riscv_instr helps with this GPR variation.

Interaction with instruction stream conversion

After directed instruction stream generation, the riscv_instr_sequence flow uses generate_instr_stream, which has the instruction stream available and uses convert2asm() to convert generated instructions into assembly text. The riscv_asm_program_gen class also calls main_program[hart].generate_instr_stream() to convert the instruction stream into string format.

Constraints and related checks

The generation flow includes checks for illegal and HINT instruction ratios. If those ratios are zero, no illegal or HINT instructions are generated. This check is described as part of the surrounding instruction generation process after directed instruction stream generation.

CITATIONS

8 sources
8 citations
[1] riscv-dv is an open-source CHIPS Alliance random instruction generator for RISC-V processor verification. RISC-V source class riscv_asm_program_gen, the brain behind ...
[2] riscv_asm_program_gen generates complete RISC-V assembly programs, including initialization, instruction, data, stack, page-table, interrupt, and exception-handling sections. RISC-V source class riscv_asm_program_gen, the brain behind ...
[3] gen_program() is the main function that generates all sections of the program and calls other riscv_asm_program_gen functions in sequence. RISC-V source class riscv_asm_program_gen, the brain behind ...
[4] Before generate_directed_instr_stream(), gen_program() calls get_directed_instr_stream(), uses add_directed_instr_stream() to select directed-instruction ratios, generates the program header, and initializes GPRs. RISC-V source class riscv_asm_program_gen, the brain behind ...
[5] generate_directed_instr_stream() decides the ratio, inserts directed instruction streams, randomizes instructions, and selects rs1, rs2, and rd based on instruction type. RISC-V source class riscv_asm_program_gen, the brain behind ...
[6] The directed instruction generation flow helps produce assembly programs using GPRs x0 through x31, with support from riscv_instr.post_random(). RISC-V source class riscv_asm_program_gen, the brain behind ...
[7] After directed instruction stream generation, riscv_instr_sequence.generate_instr_stream uses the available instruction stream and convert2asm(), and main_program[hart].generate_instr_stream() converts the instruction stream to string format. RISC-V source class riscv_asm_program_gen, the brain behind ...
[8] The generation flow checks illegal and HINT instruction ratios, and if those ratios are zero then no illegal or HINT instructions are generated. RISC-V source class riscv_asm_program_gen, the brain behind ...