RTL Studio Open IDE

LFSR, PRBS & CRC

Xorshift32 PRNG — L2 Upgrade

32-bit Xorshift pseudo-random number generator with reference-based stall and lock detection.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

Xorshift32 PRNG — L2 Upgrade is a Verilog reference block in the LFSR, PRBS & CRC catalog. LFSR, PRBS, CRC, and pseudo-random sequence generators. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

The xorshift32_prng_lock_detect module implements a 32-bit Xorshift Pseudo-Random Number Generator (PRNG). It is designed for verification environments requiring reproducible random sequences, state monitoring, and robustness against infinite loops.

### Key Features

  • Algorithm: Standard Xorshift32 (shifts: 13, 17, 5).
  • Configurable Seeding: Initialize the generator state with a 32-bit seed via the start signal.
  • Stall Control: Halt state progression when the current state matches a user-defined reference value (ref_val), enabled by compare_en.
  • Lock Detection: Monitor for repetitive states (where prev_out == current_state) and assert lock_detected if a lock condition persists.
  • Deterministic: Fully synchronous design with an asynchronous active-low reset (rst_n).
  • Status Signals: valid indicates when output data is ready; lock_detected indicates a potential infinite loop.

This IP implements a 32-bit Xorshift Pseudo-Random Number Generator (PRNG) with advanced features for verification and debugging. Key capabilities include configurable seeding, reference-value-based stall control, and automatic lock detection to identify repetitive state loops. The design is fully synchronous with an asynchronous reset, ensuring deterministic behavior suitable for rigorous system verification.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for Xorshift32 PRNG — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: 32-bit Xorshift pseudo-random number generator with reference-based stall and lock detection.
  3. Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
  4. Run Yosys in the same IDE for a generic netlist. Sky130 liberty mapping is a separate Pro library option.

RTL Studio is the Verilog simulator and IDE around this block: Slang lint, Verilator, VCD waveforms, and Yosys, in the browser. Simulation guide · Yosys guide.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low asynchronous reset
startInput1Assert to initialize generator with seed_in
seed_inInput32Initial seed value for the state register
compare_enInput1Enable reference value comparison for stalling
ref_valInput32Reference value to trigger stall when matched
outOutput32Generated pseudo-random value
validOutput1High when out contains valid data
lock_detectedOutput1High when a repetitive state loop is detected

Architecture

The design consists of two main parts:

  1. Combinational Logic: Implements the Xorshift32 state update function and comparison logic.
  2. Sequential Logic: Manages the state register, running status, and stall/lock flags.

### State Machine

  • Idle: Waiting for start signal.
  • Running: On start, the state is initialized to seed_in. Subsequent cycles update the state using Xorshift32 logic.
  • Stall: If compare_en is high and state == ref_val, the generator stalls, holding the current output.
  • Lock Detection: If the current state equals the previous output (prev_out), a lock condition is flagged.

Verification

The provided testbench validates the following scenarios:

Test CaseDescriptionExpected Result
TC1Basic Seed and Runvalid asserted, output is non-zero and changes each cycle.
TC2Lock Detection / StallGenerator stalls when state == ref_val; lock_detected asserts if loop persists.
TC3Reset FunctionalityOn rst_n low, valid and lock_detected deassert; state resets.
TC4Seed DiversityDifferent seed_in values produce different output sequences.

### Simulation Log Example

More in LFSR, PRBS & CRC

All LFSR, PRBS & CRC blocks