This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Which square root function is more accurate?

Other Parts Discussed in Thread: CONTROLSUITE

Hi all,

It seems to me that we have two equivalent optimized square root functions:

1. sqrt() which is in the rts2800_fpu32_fast_supplement.lib

2. __ffsqrtf() which is in the c28x_fpu_dsp_library.lib

My question is: which one is more accurate? The speed aspect is of less importance for me. Is there someone who actually did some tests?

I could make some tests by myself, but i'd rather ask first.

Best regards,

Andy

 

  • Hi Andy,

    When it comes to accuracy I felt IQMath based sqrt function is more accurate. Had made an excel sheet long way back which I'm unable to trace as of now.

    Regards,
    Gautam

  • AndyP,

    It could depend on the range of numbers you are working with.
    As you are aware, given IQ (depending on the chosen Q) offers a fixed resolution across the number line where as floating point precision is not the same across.

    -Bharathi.
  • I'm not using IQMath, and I really don't want to.
    Are there any real differences between the two functions I mentioned?
    According to documentation, the sqrt() takes 28 cycles, and __ffsqrt() takes 22 cycles. If you look into the assembly there is additional check in the sqrt() which may be responsible for the additional cycles. Otherwise both routines seems to be the same, hence the same accuracy. Am I right? I'm using 28335 MCU.

    - Andy
  • Both those routines use the same assembly instruction EISQRTF32 to get an estimate of the inverse square root of x and then use two iterations of newton rahpson to get a better estimate of 1/sqrt(x) and finally multiply with x to give you sqrt(x). They have the same accuracy.

  • Thanks Vishal for explanation.

    But question arises: why two routines? What is the advantage of using one instead of the other?

    - Andy

  • the __ffsqrt is an intrinsic so you dont incur the call/return overhead. Normally a single __ffsqrt takes 22 cycles (thereabouts) and if you look at the code there are NOPs every other line. IF you have two back to back __ffsqrt() the compiler will interleave the two sqrts together so now you do 2 sqrts in 22 cycles. I think there is an example of this in the FPU DSP Library.

    C:\ti\controlSUITE\libs\dsp\FPU\v1_50_00_00\examples\math\2837x_fastsqrt

    you will need to look at the disassembly.