上一篇文章分治法(Divide and Conquer)以 Leading Zero Count 為例解釋了分治法帶來的好處,本篇文章再舉一個類似的例子。
Count Number of Ones,計算一個32-bit輸入中 1 的個數(shù)。
For 循環(huán)
always_comb begin
count = 0;
for (int i=0; i<32; i++) begin
count = count + data_i[i];
end
end
分治法
第一級:6-3 compressor (需要三個LUT6)
第三級:ternary adder
logic [4:0][2:0] temp1; logic [1:0] temp1_1; always_comb for (int i=0; i<5; i++) begin case(data_i[i*6 +: 6]) 6'b000000 : temp1[i] = 0; 6'b000001 : temp1[i] = 1; 6'b000010 : temp1[i] = 1; 6'b000011 : temp1[i] = 2; ... 6'b111111 : temp1[i] = 6; endcase end end assign temp1_1 = data_i[30] + data_i[31]: logic [1:0][4:0] temp2; always_comb begin temp2[0] = temp1[0] + temp1[1] + temp[2]; temp2[1] = temp1[3] + temp1[4] + temp[5]; end logic [5:0] count; assign count = temp2[0] + temp2[1] + temp1_1;
綜合結(jié)果對比
| WNS | Logic Levels | Num of LUTs | |
|---|---|---|---|
| For loop | 8.496 | 5 | 34 |
| Divide and Conquer | 8.718 | 4 | 29 |
審核編輯:劉清
-
MWNs
+關(guān)注
關(guān)注
0文章
3瀏覽量
5465 -
for循環(huán)
+關(guān)注
關(guān)注
0文章
61瀏覽量
2851
原文標題:分治法(二)
文章出處:【微信號:FPGA開發(fā)之路,微信公眾號:FPGA開發(fā)之路】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
USB MP4流媒體帶來的好處
現(xiàn)場總線技術(shù)帶來哪些好處
用分治法找出最大值和最小值的問題
CPLD可為便攜設(shè)計帶來哪些好處呢?
電子設(shè)計師設(shè)計思想篇--分治法利弊
聚類和劃分的SAT分治判定
云計算可以帶來以下哪些好處
FPGA開發(fā)中分治法的應(yīng)用

分治法帶來的好處
評論