CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Arithmetic

8-bit Combinational Popcount

MediumVerilog / SystemVerilogBuild

Error correction codes and neural network accelerators frequently rely on population count operations to determine the number of set bits in a data vector. While a sequential shift-and-count approach takes multiple clock cycles, a combinational popcount provides immediate results. However, a naive chain of additions creates a long critical path that can cause severe routing congestion and limit the maximum operating frequency of the entire system.

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

ArithmeticCombinational LogicDatapath

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

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.

Related problems

  • Binary to Gray Code DatapathEasy
  • Fixed Point Multiplication with SaturationHard
  • Twos Complement Overflow in SubtractionMedium
  • 8 bit Basic ALU with FlagsEasy
  • 8-bit Logical Barrel ShifterMedium
  • Absolute Value with Bit GrowthMedium
  • 16-bit Arithmetic Barrel ShifterHard
  • Parameterized ALU with Safe DefaultsMedium

Browse all problems · Learning tracks