Skip to content
STIMSMITH

General Purpose Register Initialization

Concept WIKI v1 · 5/26/2026

General purpose register initialization is a step in riscv-dv assembly program generation where the riscv_asm_program_gen flow calls init_gpr() to initialize RISC-V general-purpose registers with random values before directed and random instruction streams are generated.

Overview

General purpose register initialization refers to the init_gpr() step in the riscv_asm_program_gen assembly-generation flow. In the described riscv-dv flow, gen_program() generates the sections of a complete RISC-V assembly program and, after generating the program header, calls init_gpr() to initialize general purpose registers with random values. [General purpose register initialization in gen_program]

Role in riscv-dv program generation

The evidence places GPR initialization inside the broader riscv_asm_program_gen.sv class, which generates complete RISC-V assembly programs used to verify RISC-V IP. The generated program may include sections such as the initialization routine, instruction section, data section, stack section, page table, and interrupt and exception handling. [riscv_asm_program_gen generates assembly sections]

Within gen_program(), the flow described is:

  1. Call directed-instruction stream setup functions such as get_directed_instr_stream() and add_directed_instr_stream().
  2. Generate the program header through gen_program_header().
  3. Insert the _start section through gen_section("_start", str).
  4. Call init_gpr() to initialize general purpose registers with random values.
  5. Generate directed and randomized instruction streams. [gen_program call sequence]

Interaction with instruction generation

After init_gpr() is called, the flow proceeds to generate_directed_instr_stream(), which decides ratios, inserts directed instruction streams, and randomizes instructions. The instruction-randomization step selects which rs1, rs2, and rd registers to use based on instruction type. The resulting assembly program uses various GPRs x0 to x31 across instructions, with post_random() in riscv_instr helping this process. [Instruction generation uses GPR operands]

Configuration context

Before program generation, riscv_instr_gen_config is randomized from riscv_instr_base_test.sv. That randomization determines configuration parameters such as the RISC-V extension, supported privilege mode, instruction counts in the main program and subprogram, and whether particular instructions such as break, debug-return, fence, or wait-for-interrupt instructions are generated. These configuration choices establish the broader environment in which GPR initialization and instruction generation occur. [Configuration before program generation]

Customization relevance

The source states that the riscv_asm_program_gen.sv class can address customization to RISC-V GPR or instruction. Therefore, GPR initialization is part of a generator architecture that is intended to be configurable for RISC-V processor verification use cases. [GPR customization support]

CITATIONS

6 sources
6 citations
[1] General purpose register initialization in gen_program RISC-V source class riscv_asm_program_gen, the brain behind ...
[2] riscv_asm_program_gen generates assembly sections RISC-V source class riscv_asm_program_gen, the brain behind ...
[4] Instruction generation uses GPR operands RISC-V source class riscv_asm_program_gen, the brain behind ...
[5] Configuration before program generation RISC-V source class riscv_asm_program_gen, the brain behind ...