Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix popcount output width #251

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/popcount.sv
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

// Description: This module calculates the hamming weight (number of ones) in
// its input vector. Any unsigned INPUT_WIDTH larger or equal 1 is legal. The output result
// width is ceil(log2(INPUT_WIDTH))+1.
// width is ceil(log2(INPUT_WIDTH+1)).
//
// This module used to be implemented using a binary added tree. However,
// the heuristics of modern logic Synthesizers work much better with a flat high
Expand All @@ -21,7 +21,7 @@

module popcount #(
parameter int unsigned INPUT_WIDTH = 256,
localparam int unsigned PopcountWidth = $clog2(INPUT_WIDTH) + 1
localparam int unsigned PopcountWidth = $clog2(INPUT_WIDTH+1)
) (
input logic [ INPUT_WIDTH-1:0] data_i,
output logic [PopcountWidth-1:0] popcount_o
Expand Down
4 changes: 2 additions & 2 deletions test/popcount_tb.sv
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module popcount_tb;
logic popcount_w1;

logic [4:0] data_w5;
logic [3:0] popcount_w5;
logic [2:0] popcount_w5;

logic [15:0] data_w16;
logic [4:0] popcount_w16;
Expand All @@ -47,7 +47,7 @@ module popcount_tb;
logic [6:0] popcount_w64;

logic [980:0] data_w981;
logic [10:0] popcount_w981;
logic [9:0] popcount_w981;

//--------------------- Instantiate MUT ---------------------
popcount #(.INPUT_WIDTH(1)) i_popcount_w1
Expand Down
Loading