8-bit Combinational Popcount
Counting the set bits in a word shows up in ECC and in neural network accelerators. Adding the bits one after another makes a long chain; adding them as a tree keeps the depth to three levels for 8 bits.
The module evaluates an 8-bit input vector and computes the total number of bits set to logic 1. To optimize the critical path delay, the computation should be structured as a parallel hierarchical adder tree. Adjacent bits are first added in pairs to form 2-bit sums; adjacent pairs are then added to form 3-bit sums; and finally, the two halves are added to produce the final 4-bit count.
This circuit is purely combinational. There is no clock or reset signal. The output must reflect the current input continuously.
| Signal | Direction | Width | Description |
|---|---|---|---|
in_val |
input | 8 | The data vector to be evaluated |
pop_count |
output | 4 | The total number of bits set to 1 in in_val |
Constraints
- The design must be purely combinational with no sequential logic, clocks, or resets.
- The output width must be 4 bits to accommodate the maximum possible count of 8.
- Intermediate addition stages must be correctly sized to prevent arithmetic overflow.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of Datapath Design
Problem 13 of 27 in the Datapath Design track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks