RTL Studio Open IDE

Code Conversion

16-Bit Priority Encoder — L1 Upgrade — L2 Upgrade

16-bit priority encoder with registered outputs and Valid/Ready skid buffer for backpressure handling.

About this block

Simulate it in the Verilog IDE

Mediumverilogsimsyn

16-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 implements a 16-bit priority encoder that identifies the index of the highest-priority set bit in a 16-bit input vector.

It features registered outputs and a Valid/Ready handshake interface with a skid buffer to handle backpressure without data loss.

The design ensures minimal latency for the combinational logic while maintaining data integrity under flow control constraints.

  • valid_in: Asserted by the producer when data is valid.
  • ready_out: Asserted by the consumer when it can accept data.
  • valid_out: Asserted when the encoder has a valid result to send.
  1. Choose Open in IDE. RTL Studio loads the packaged workspace for 16-Bit Priority Encoder — L1 Upgrade — L2 Upgrade.
  2. Read the Verilog module in the editor. The catalog line for this block: 16-bit priority encoder with registered outputs and Valid/Ready skid buffer for backpressure handling.
  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

  • 16-bit Input Processing: Encodes the highest set bit index.
  • Registered Outputs: index_out and valid_out are registered to improve timing.
  • Valid/Ready Handshake: Supports backpressure via a skid buffer.
  • Low Latency: Combinational priority logic for immediate encoding.
  • Synchronous Reset: Active-low synchronous reset for all internal registers.

Ports

Port NameDirectionWidthDescription
clkInput1Clock input
rst_nInput1Active-low synchronous reset
data_inInput[15:0]Input data vector
valid_inInput1Input valid signal (producer ready)
ready_outInput1Output ready signal (consumer ready)
index_outOutput[3:0]Encoded index of highest set bit
valid_outOutput1Output valid signal

Architecture

The design consists of two main stages:

  1. Combinational Priority Encoder: Determines the highest set bit index and validity.
  2. Registered Output with Skid Buffer: Manages the Valid/Ready handshake, holding data if the output is not ready.

The encoder determines the highest set bit index. It outputs a 4-bit index and a valid flag. The skid buffer manages the Valid/Ready handshake. It holds new data if the output is not ready. It releases held data when the output becomes ready.

Verification

The testbench validates reset behavior and encoding accuracy. It checks basic priority encoding for bits 0 and 15. It verifies skid buffer hold and release operations. It confirms output deassertion when input is invalid.

Test CaseDescription
TC1Reset check
TC2Basic priority encoding bit 15
TC3Basic priority encoding bit 0
TC4Skid hold output check
TC5Skid release check
TC6Skid hold output check 2
TC7Skid release check 2
TC8No valid input check

More in Code Conversion

All Code Conversion blocks