diff --git a/src/popcount.sv b/src/popcount.sv index 463e57c7..0764b168 100644 --- a/src/popcount.sv +++ b/src/popcount.sv @@ -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 @@ -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 diff --git a/test/popcount_tb.sv b/test/popcount_tb.sv index c7cfbdb1..9c43ac11 100644 --- a/test/popcount_tb.sv +++ b/test/popcount_tb.sv @@ -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; @@ -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