1、采用循環(huán)語句+移位+邏輯& 1來計(jì)算1的數(shù)量
如下所示,采用循環(huán)語句+移位+邏輯與1+累加來實(shí)現(xiàn)1的統(tǒng)計(jì)。最終調(diào)用函數(shù)獲得輸入信號中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)語句,逐個(gè)bit位判斷是否為1,為1則累加,否則保持不變,最終輸出輸入信號中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文章
1302瀏覽量
104331 -
信號
+關(guān)注
關(guān)注
11文章
2809瀏覽量
77167 -
Verilog
+關(guān)注
關(guān)注
28文章
1352瀏覽量
110460 -
函數(shù)
+關(guān)注
關(guān)注
3文章
4349瀏覽量
63027 -
調(diào)用函數(shù)
+關(guān)注
關(guān)注
0文章
11瀏覽量
2353
原文標(biāo)題:IC設(shè)計(jì)基礎(chǔ):Verilog計(jì)算1的數(shù)量
文章出處:【微信號:IP與SoC設(shè)計(jì),微信公眾號:IP與SoC設(shè)計(jì)】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
H[1].264 Verilog H.264 的Verilog實(shí)現(xiàn)的opencore
Verilog HDL語言簡介
如何計(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ǔ)知識非常好的學(xué)習(xí)教程 (1)
verilog是什么_verilog的用途和特征是什么
![<b class='flag-5'>verilog</b>是什么_<b class='flag-5'>verilog</b>的用途和特征是什么](https://file.elecfans.com/web1/M00/50/9E/o4YBAFr5LheAfWmCAAD10sAJWLo768.jpg)
數(shù)字IC設(shè)計(jì)入門(6)初識verilog
![數(shù)字<b class='flag-5'>IC</b>設(shè)計(jì)入門(6)初識<b class='flag-5'>verilog</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
Verilog的程序框架案例
實(shí)時(shí)計(jì)算汽車數(shù)量開源分享
![實(shí)時(shí)<b class='flag-5'>計(jì)算</b>汽車<b class='flag-5'>數(shù)量</b>開源分享](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
評論