From: Marko S on
How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?

The signals a and b are 32 bit signed fix point numbers (std_logic_vector
(31 downto 0)).


From: Michael Schöberl on
Marko S schrieb:
> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?
> The signals a and b are 32 bit signed fix point numbers (std_logic_vector
> (31 downto 0)).

how accurate? how fast? latency?

a table with 64 Bits input, 32 Bits output will not fit into an FPGA
(but if you need the result with low latency, you might store some
precomputed data in an external ram)


or you could do something like max(a, b) + 0.5*min(a,b) ... and add a
newton raphson stage?


just for the sqrt(x) I once worked an idea to take len=ceil(log_2(x)) by
counting the length of x (leading 0s) ...
then you shift x>>(len/2) or something (+1?) ... this worked as a good
approximation and I added only one or two stages of a newton-raphson

The second approach was better in the first stage but uses more
cycles/ressources ... I'm not sure if the ressources balance on an FPGA
I did it for a TI-DSP - look at the thread "sqrt on C6414 DSP" on comp.dsp


bye,
Michael
From: Ad on
Marko

a cordic algorithim in vectroing mode will calcualtes sqrt(a^2 - b^2)
which i am sure you can manipulate to get sqrt(a^2+b^2) by using signed
numbers and making b the negative (-6 as opposed to 6)

have a look at Ray Andrakas, survey of CORDIC algorithms for FPGA based
computers for infor on cordics, opencore.org also have a the vhdl for a
synthesisable cordic.

I ve just finished writing a excel function that performs the function
of a cordic if you want the vb for that then let me know and you can
have it test out your application before coding it.

good luck

Adam

From: Kolja Sulimma on
Marko S schrieb:
> How do i calculate sqrt(a^2 + b^2) in synthesizable VHDL?

If you really need the results in random order, use cordic.
But often you can rearrange your computations to get away without the
root. That is your application?

Do you want to draw circles?

Kolja Sulimma
From: Ad on
corerction the sqrt(a^2 - b^2) is for gven during the hyperbolic
extension, a normal cordic algorithim will provide sqrt(a^2 + b^2)

sorry about that

Ad