基於Verilog的以2為底取對數函數log2(x)


參考資料:xilinx AXI4 Stream Peripherals 源碼

//************************************************************************

Verilog中函數使用方法這里不再贅述,只給出函數原型及其調用方式。

//************************************************************************

//function called clogb2 that returns an integer which has the
//value of the ceiling of the log base 2.
function integer clogb2 (input integer bit_depth);
begin
for(clogb2=0; bit_depth>0; clogb2=clogb2+1)
bit_depth = bit_depth>>1;
end
endfunction
//************************************************************************
 
localparam WIDTH_SRL = 32; 
localparam WIDTH_CNT = clogb2(WIDTH_SRL/8-1);
 
轉載:http://www.eefocus.com/mastershifu2015/blog/16-08/389919_64de0.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM