1、采用循環(huán)語(yǔ)句+移位+邏輯& 1來計(jì)算1的數(shù)量
如下所示,采用循環(huán)語(yǔ)句+移位+邏輯與1+累加來實(shí)現(xiàn)1的統(tǒng)計(jì)。最終調(diào)用函數(shù)獲得輸入信號(hào)中1的數(shù)量。
module clk_mux #(parameter CLK_MASK = 16'hffff) ( input xxxx, input xxxx, output xxxx, output xxxx ); localparam NUM_INPUT_CLK = 16; function integer countones; input [NUM_INPUT_CLK-1:0] x; integer k; begin countones = 0; while(x > 0) begin countones += x & 1; x = x >> 1; end end endfunction localparam NUM_CLK = countones(CLK_MASK); endmodule
2、采用for循環(huán)來計(jì)算1的數(shù)量
采用for循環(huán)語(yǔ)句,逐個(gè)bit位判斷是否為1,為1則累加,否則保持不變,最終輸出輸入信號(hào)中1的數(shù)量。
wire [64-1:0] mem_addr_hit ; // reg [7-1:0] mem_addr_hit_cnt ; // always@(*) begin mem_addr_hit_cnt = 'b0 ; for(int i=0; i<64;i=i+1) begin : mem_addr_hit_cnt if(mem_addr_hit[i]) mem_addr_hit_cnt = mem_addr_hit_cnt + 1'b1 ; //spyglass disable W415a W484 else mem_addr_hit_cnt = mem_addr_hit_cnt ; //spyglass disable W415a W484 end end
審核編輯:湯梓紅
-
IC設(shè)計(jì)
+關(guān)注
關(guān)注
38文章
1356瀏覽量
105656 -
信號(hào)
+關(guān)注
關(guān)注
11文章
2851瀏覽量
78195 -
Verilog
+關(guān)注
關(guān)注
29文章
1367瀏覽量
112190 -
函數(shù)
+關(guān)注
關(guān)注
3文章
4379瀏覽量
64737 -
調(diào)用函數(shù)
+關(guān)注
關(guān)注
0文章
11瀏覽量
2403
原文標(biāo)題:IC設(shè)計(jì)基礎(chǔ):Verilog計(jì)算1的數(shù)量
文章出處:【微信號(hào):IP與SoC設(shè)計(jì),微信公眾號(hào):IP與SoC設(shè)計(jì)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
H[1].264 Verilog H.264 的Verilog實(shí)現(xiàn)的opencore
Verilog HDL語(yǔ)言簡(jiǎn)介
如何計(jì)算UPS所配電池的數(shù)量
基于EP1C3的進(jìn)階實(shí)驗(yàn)_reference_verilog
基于EP1C3的進(jìn)階實(shí)驗(yàn)eference_verilog
基于EP1C3的進(jìn)階實(shí)驗(yàn)_reference_verilog
Verilog_HDL基礎(chǔ)知識(shí)非常好的學(xué)習(xí)教程 (1)
verilog是什么_verilog的用途和特征是什么

數(shù)字IC設(shè)計(jì)入門(6)初識(shí)verilog

Verilog的程序框架案例
實(shí)時(shí)計(jì)算汽車數(shù)量開源分享

評(píng)論