Skip to main content
T J
Senior III
Jul 30, 2018 12:59 PM UTC
Solved

How fast is a double floating point Square root function on a 48MHz Cortex M0 ?

I made an integer Square root function:

   int integerSQRT, result,result2;

   for (integerSQRT = 0; integerSQRT < 100; integerSQRT++)

       if (integerSQRT*integerSQRT >= squaredResult) {           

           result = integerSQRT - 1;      // just larger than the sqroot -1 is just less than

           integerSQRT = 100;

       }

   

// easily adapted to cube root, quad root etc...

    This topic has been closed for replies.
    henry.dick
    henry.dickBest answer
    Associate II
    Jul 31, 2018 11:47 PM UTC

    by halving the initial guess (similar to the cordic approach), I got about 230 ticks (-O1 optimized) to 290 ticks (no optimization) to calculate the integer sqrt of 65535, on a CM0.

    running at 48Mhz, that means 5 - 6us per calculation, inclusive of overhead.

    see if your code can beat that.

    12 replies

    T J
    T JAuthor
    Senior III
    Aug 1, 2018 12:57 AM UTC

    that part of the code is finished... working on LinearTouch

    To calculate the Y coordinate on a triangle shaped sensor, I needed the Sqrt function twice

    but only needs to resolve from 4 bits ( max value is 30) Sqrt is 5.

    I could have used 4 if statements, maybe a little faster.

    henry.dick
    Associate II
    Aug 1, 2018 1:08 AM UTC

    "I could have used 4 if statements, maybe a little faster."

    LUT.