Re: 1080p HD Video on custom FPGA/VDAC/2MBx18 SyncRAM board
Posted: Mon Aug 11, 2014 4:57 pm
I modified Jack's square root algorithm on page 86 to work in Verilog. Takes 50 cycles and actually works on 2 16-bit numbers up to a value of 46,340 (for the formula SQRT(X^2+Y^2)), except I had to perform the last shift right 2x, not 1x like in his algorithm on the last line.
Jack's Code:
My copy of his work in Verilog. The variable 'a' is 32-bit.:
At the conclusion of the chapter on page 87 he says: So maybe he did this on purpose?
Looks like the ISE 14.7 has offloaded some work to the DSP48A1 tiles:
Jack's Code:
Code: Select all
unsigned short sqrt(unsigned long a){
unsigned long rem = 0;
unsigned long root = 0;
for(int i=0; i<16; i++){
root <<= 1;
rem = ((rem << 2) + (a >> 30));
a <<= 2;
root ++;
if(root <= rem){
rem -= root;
root++;
}
else
root--;
}
return (unsigned short)(root >> 1);
}Code: Select all
.......//SQRT state machine
SQRTINIT:
state <= CALC3;
CALC3:
state <= CALC4;
CALC4:
state <= CALC5;
CALC5:
if (i<16)
state <= CALC3;
else state <= CALC6;
CALC6:
state <= WAIT;
............................................
//square root generator
SQRTINIT:
begin
LGREADY <= 0;
i <= 0;
rem <= 0;
Root <= 0;
a <= Xs*Xs + Ys*Ys;
end
CALC3:
begin
Root <= Root << 1;
rem <= ((rem << 2) + (a >> 30));
end
CALC4:
begin
a <= a << 2;
Root <= Root + 1;
end
CALC5:
begin
i <= i + 1;
if (Root <= rem) begin
rem <= rem - Root;
Root <= Root + 1;
end
else Root <= Root - 1;
end
CALC6:
Root <= Root >> 2;Quote:
If there’s any one lesson to be learned from this chapter, it is this:
Never trust a person who merely hands you an equation.
Never trust a person who merely hands you an equation.
Looks like the ISE 14.7 has offloaded some work to the DSP48A1 tiles: