用下面的平方根求法不需要乘法,只需简单的移位就能实现。文章来源:https://www.toymoban.com/news/detail-762352.html
function [15:0] sqrt;
input [31:0] num; //declare input
//intermediate signals.
reg [31:0] a;
reg [15:0] q;
reg [17:0] left,right,r;
integer i;
begin
//initialize all the variables.
a = num;
q = 0;
i = 0;
left = 0; //input to adder/sub
right = 0; //input to adder/sub
r = 0; //remainder
//run the calculations for 16 iterations.
for(i=0;i<16;i=i+1) begin
right = {q,r[17],1'b1};
left = {r[15:0],a[31:30]};
a = {a[29:0],2'b00}; //left shift by 2 bits.
if (r[17] == 1) //add if r is negative
r = left + right;
else //subtract if r is positive
r = left - right;
q = {q[14:0],!r[17]};
end
sqrt = q; //final assignment of output.
end
endfunction
原理参照论文A New Non-Restoring Square Root Algorithm and Its VLSI Implementations文章来源地址https://www.toymoban.com/news/detail-762352.html
到了这里,关于FPGA verilog 简单的平方根求法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!