RTL Studio Open IDE

Code Conversion

N-bit Priority Encoder — L1 Upgrade — L2 Upgrade

N-bit priority encoder with registered output and valid/ready skid buffer for flow control.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

N-bit Priority Encoder — L1 Upgrade — L2 Upgrade is a Verilog reference block in the Code Conversion catalog. Encoders, decoders, priority encoders, and binary/gray converters. Marked Medium: more state or a wider datapath, still one workspace in the IDE.

This IP provides a robust priority encoder with flow control.

It is suitable for systems requiring deterministic latency and back-pressure handling.

The skid buffer ensures data integrity during stalls, making it ideal for high-throughput data paths where consumer readiness may vary.

  1. Choose Open in IDE. RTL Studio loads the packaged workspace for N-bit Priority Encoder — L1 Upgrade — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: N-bit priority encoder with registered output and valid/ready skid buffer for flow control.
  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.

Features

  • Priority Encoding: Encodes the index of the highest set bit in an 8-bit vector.
  • MSB-First Priority: Bit 7 has the highest priority, down to Bit 0.
  • Registered Output: Improves timing closure by registering the output index and valid signal.
  • Flow Control: Implements a valid/ready handshake with a skid buffer to handle back-pressure.
  • Synchronous Reset: All internal registers are reset synchronously using an active-low reset signal.

Interface

The module uses a standard valid/ready handshake protocol. The module acts as a Producer (Master) driving valid_out and index_out. The ready_in signal is an Input from the downstream consumer, indicating it is ready to accept data.

Signal NameDirectionWidthDescription
clkInput1Clock signal
rst_nInput1Active-low synchronous reset
data_inInput8Input data vector to be encoded
valid_inInput1Input valid signal (asserted when data_in is valid)
ready_inInput1Ready signal from downstream consumer (asserted when consumer can accept data)
valid_outOutput1Output valid signal (asserted when index_out is valid)
index_outOutput3Encoded index of the highest priority set bit

Architecture

The design consists of a combinational priority encoder and a registered output stage. A skid buffer holds data when the ready_in signal is deasserted, preventing data loss.

Verification

The provided testbench covers basic encoding, skid buffer behavior, and back-to-back transactions.

Test CaseDescriptionExpected Result
TC1aSingle bit 0 setindex_out = 0, valid_out = 1
TC1bSingle bit 7 setindex_out = 7, valid_out = 1
TC1cBits 0 and 7 setindex_out = 7, valid_out = 1
TC1dNo bits setvalid_out = 0
TC2aStall with valid datavalid_out = 0 (initially)
TC2bRelease stallindex_out = 0, valid_out = 1
TC2cStall with new dataSkid buffer updates
TC2dRelease stall with new dataindex_out = 2, valid_out = 1
TC3aBack-to-back bit 0index_out = 0, valid_out = 1
TC3bBack-to-back bit 1index_out = 1, valid_out = 1

All test cases passed successfully in simulation.

More in Code Conversion

All Code Conversion blocks