From 132260d84cb7f7e8bfee169d2b337ae777ada1f1 Mon Sep 17 00:00:00 2001 From: Blaise Tine Date: Mon, 27 Sep 2021 09:23:58 -0400 Subject: [PATCH] minor update --- hw/rtl/libs/VX_popcount.v | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 hw/rtl/libs/VX_popcount.v diff --git a/hw/rtl/libs/VX_popcount.v b/hw/rtl/libs/VX_popcount.v new file mode 100644 index 00000000..3144f106 --- /dev/null +++ b/hw/rtl/libs/VX_popcount.v @@ -0,0 +1,58 @@ +`include "VX_platform.vh" + +`TRACING_OFF +module VX_popcount #( + parameter MODEL = 1, + parameter N = 1, + parameter LOGN = $clog2(N), + parameter M = LOGN+1 +) ( + input wire [N-1:0] in_i, + output wire [M-1:0] cnt_o +); + if (N == 1) begin + + assign cnt_o = in_i; + + end else if (MODEL == 1) begin + `IGNORE_WARNINGS_BEGIN + localparam PN = 1 << $clog2(N); + localparam LOGPN = $clog2(PN); + + wire [M-1:0] tmp [0:PN-1] [0:PN-1]; + + for (genvar i = 0; i < N; ++i) begin + assign tmp[0][i] = in_i[i]; + end + + for (genvar i = N; i < PN; ++i) begin + assign tmp[0][i] = '0; + end + + for (genvar j = 0; j < LOGPN; ++j) begin + for (genvar i = 0; i < (1 << (LOGPN-j-1)); ++i) begin + assign tmp[j+1][i] = tmp[j][i*2] + tmp[j][i*2+1]; + end + end + + assign cnt_o = tmp[LOGPN][0]; + `IGNORE_WARNINGS_END + end else begin + + reg [M-1:0] cnt_r; + + always @(*) begin + cnt_r = '0; + for (integer i = 0; i < N; ++i) begin + `IGNORE_WARNINGS_BEGIN + cnt_r = cnt_r + in_i[i]; + `IGNORE_WARNINGS_END + end + end + + assign cnt_o = cnt_r; + + end + +endmodule +`TRACING_ON \ No newline at end of file