Close

Popcount (better)

A project log for miniMAC - Not an Ethernet Transceiver

custom(izable) circuit for sending some megabytes over differential pairs.

yann-guidon-ygdesYann Guidon / YGDES 03/23/2025 at 15:340 Comments

As noted in the precedent log, there's a flaw in the popcount8 circuit and it's larger than I expected, 4 flips but 5 too and it's not manageable.

The issue with the popcount circuit is the addition of multiple values simultaneously, which is not possible with the typical adder circuit. The byte is split into two 3-bit groups (each with their own Full Adder) and the remaining 2 bits use a Half Adder.

The result : 3 2-bit values that must be added together. This usually creates 2 levels of adders, a 2-bit adder combines the two FA then a 3-bit adder adds the remaining 2 bits. This is wasteful since we use only the LSB (parity) and MSB (carry) of the result.

But what about a bit-by-bit approach ?

The first step is to combine the LSB of the first three add groups : that's a FA, which gives the parity as well.

We are left with 4 signals to add : that's larger than a FA but that's spot on for two HA.

We still get two bits but we bumped up the meaningfulness.

For the input to be 3>, one of the AND must set, or both XORs simultaneously. This is done with two more gates.

Tadam !

The full circuit becomes

and the cirtuit is simulated here.

Sim passes with no flip error : 4 doesn't flip at all anymore. Case closed.

Discussions