Code Conversion
Trailing-One Encoder 8-bit — L1 Upgrade
Registered pipeline for encoding the index of the first trailing one in an 8-bit input vector.
About this block
Simulate it in the Verilog IDE
Trailing-One Encoder 8-bit — L1 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 registered, low-latency trailing-one encoder for 8-bit vectors.
It identifies the index of the least significant bit (LSB) set to '1' and outputs the result on the next clock cycle.
This module is ideal for applications requiring fast priority encoding with synchronous output, such as interrupt controllers or memory management units.
- Input Width: 8 bits.
- Output Width: 3 bits (indices 0-7).
- Latency: 1 cycle (registered output).
- Priority: LSB (bit 0) has highest priority.
- Reset: Synchronous active-low reset.
- Valid Logic:
valid_outis asserted whenvalid_inis asserted.
- Choose Open in IDE. RTL Studio loads the packaged workspace for Trailing-One Encoder 8-bit — L1 Upgrade.
- Read the Verilog module in the editor. The catalog line for this block: Registered pipeline for encoding the index of the first trailing one in an 8-bit input vector.
- Run the packaged testbench with the in-browser Verilator simulator, then open the VCD in the waveform viewer.
- 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.
Architecture
The design consists of two main stages:
- Combinational Priority Encoder: Determines the index of the first set bit in
data_in. - Registered Output Stage: Captures the combinational result and valid status on the positive clock edge, synchronized with
rst_n.
Verification
The provided testbench (tb_trailing_one_encoder_8bit.v) verifies the encoder against standard test cases.
### Test Cases
| Test Case | Input Data | Expected Index | Description |
|---|---|---|---|
| TC1 | 0x01 | 0 | LSB set |
| TC2 | 0x80 | 7 | MSB set |
| TC3 | 0x00 | N/A | No bits set (valid=0) |
| TC4 | 0x02 | 1 | Bit 1 set |
| TC5 | 0x04 | 2 | Bit 2 set |
| TC6 | Reset | 0 | Reset condition |
| TC7 | 0xFF | 0 | All bits set (LSB priority) |
### Running Simulation
- Ensure ModelSim/Vivado/Verilator is installed.
- Run the simulation script provided in the
sim/directory. - Check the log output for "PASS" messages for each test case.
More in Code Conversion
- 16-Bit Priority Encoder — L1 Upgrade — L2 Upgrade
- 4-Bit BCD to Binary Converter — L2 Upgrade
- 4-Bit Binary to BCD Converter (Shift-and-Add-3)
- 4-Bit Thermometer to Binary Encoder
- 8-Bit One-Hot Encoder
- 8-Bit Priority Decoder (One-Hot to Binary) — L1 Upgrade — L2 Upgrade
- 8-Bit Thermometer to Binary Encoder
- 8-Bit to 16-Bit Sign Extender
- 8-to-16 Zero Extension — L1 Upgrade
- Binary to Excess-3 4-bit — L1 Upgrade — L2 Upgrade
- Binary→Thermometer Compare-Gen (8→9)
- Binary→Thermometer LUT (4→15, Case) — L1 Upgrade — L2 Upgrade
- Gray-Code Incrementer 8-Bit
- N-Bit Gray to Binary Decoder
- N-bit Priority Encoder — L1 Upgrade — L2 Upgrade
- One-Hot→Binary Case Decode (4→2) — L1 Upgrade — L2 Upgrade