日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Verilog_寻找最高有效位的位置

發(fā)布時間:2023/12/19 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Verilog_寻找最高有效位的位置 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

近來在校內(nèi)論壇上看到有位師兄面試海思的時候面試官問了個尋找最高有效位位置的問題,手癢試試看。

題:尋找一16bit無符號數(shù)最高bit位的位置

思:主要想法是輸出的時延要固定,時延不能跟著位置走。于是想到了二分法,這樣的話不論什么數(shù),找到結(jié)果的時延都是固定的,且吞吐率還高,每個時鐘周期都能吃數(shù),啟動間隔為1。

module top_valid(input clk,input rst,input [15:0] d_in,output reg [3:0] place );reg [7:0] d_temp_8;reg [3:0] d_temp_4;reg [1:0] d_temp_2;reg base_place_8,base_place_4,base_place_2;reg base_place_8_q1,base_place_8_q2;reg [7:0] d_temp_8_q1,d_temp_8_q2;reg [3:0] d_temp_4_q1;reg base_place_4_q1;wire top_eight;wire top_four;wire top_two;assign top_eight = |d_in[15:8];assign top_four = |d_temp_8[7:4];assign top_two = |d_temp_4[3:2];always @(posedge clk or posedge rst) beginif(rst == 1'b1) begind_temp_8 <= 'd0;base_place_8 <= 1'b0;endelse begind_temp_8 <= top_eight ? d_in[15:8] : d_in[7:0];base_place_8 <= top_eight ? 1'b1 : 1'b0;endendalways @(posedge clk or posedge rst) beginif(rst == 1'b1) begind_temp_4 <= 'd0;base_place_4 <= 1'b0;endelse begind_temp_4 <= top_four ? d_temp_8[7:4] : d_temp_8[3:0];base_place_4 <= top_four ? 1'b1 : 1'b0;endendalways @(posedge clk or posedge rst) beginif(rst == 1'b1) begind_temp_2 <= 'd0;base_place_2 <= 1'b0;endelse begind_temp_2 <= top_two ? d_temp_4[3:2] : d_temp_4[1:0];base_place_2 <= top_two ? 1'b1 : 1'b0;endendalways @(posedge clk or posedge rst) beginif(rst == 1'b1) beginbase_place_8_q1 <= 'b0;base_place_8_q2 <= 'b0;d_temp_8_q1 <= 'b0; d_temp_8_q2 <= 'b0; d_temp_4_q1 <= 'b0; base_place_4_q1 <= 'b0;endelse beginbase_place_8_q1 <= base_place_8;base_place_8_q2 <= base_place_8_q1;d_temp_8_q1 <= d_temp_8; d_temp_8_q2 <= d_temp_8_q1; d_temp_4_q1 <= d_temp_4; base_place_4_q1 <= base_place_4;endendalways @(posedge clk or posedge rst) beginif(rst == 1'b1) beginplace <= 'b0;endelse beginplace <= (base_place_8_q2 << 3) + (base_place_4_q1 << 2) + (base_place_2 << 1) + d_temp_2[1];endendendmodule

測試結(jié)果如下,很完美


大家如果有什么其他想法歡迎在評論區(qū)交流。

總結(jié)

以上是生活随笔為你收集整理的Verilog_寻找最高有效位的位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。