cancel
Showing results for 
Search instead for 
Did you mean: 

ST7 based SQRT algorithm

vdeokar
Associate
Posted on May 07, 2003 at 17:41

ST7 based SQRT algorithm

9 REPLIES 9
vdeokar
Associate
Posted on October 28, 2002 at 17:59

Would like to know if there is a sqrt algorithm - word, no floating point in assembly. I dont want use the C library function. The execution time of less than 150uS at 16MHz clock

Posted on November 07, 2002 at 19:25

The enclosed assembly sqrt subroutine computes the square root of word and return the nearest word (floating number not supported). Just extract the assembly code between the 2 pragma in this C file and you should be all set.

Execution time is 187us at Fcpu = 8MHz (maximum ST7 speed). That's the best I have

but maybe this subroutine can still be optimized

Regards

Jojo

________________

Attachments :

sqrt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I09t&d=%2Fa%2F0X0000000bUZ%2FeZKWGOo.QiTa20RsHFauIPxTIistBgSJsqF388drd6Q&asPdf=false
johanpauvert1
Associate II
Posted on November 08, 2002 at 12:20

Cosmic sqrt function computes the square root of a double variable, returning the nearest double floating value. The problem is the execution time : ~1.55ms.

Do you also have sqrt algorithm in assembly that supports doubles instead of words and get faster result ?

Breizh

Posted on November 08, 2002 at 13:37

I don't have better than the Cosmic one regarding double. If an integer variable sqrt algorithm is fine with you, I also have a sqrt long no floating point in assembly language. Both sqrt word and sqrt long have been included in this new attachment.

FYI :

Execution time word = 187us at Fcpu = 8MHz

Execution time long = 360us at Fcpu = 8MHz

Jojo

[ This message was edited by: jojo on 14-11-2002 20:46 ]

________________

Attachments :

sqrt.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I09o&d=%2Fa%2F0X0000000bUa%2FL8nIobjKxQzJmf4lQcy.FJIQrzqKPf2gP3L5JFRK6sg&asPdf=false
Posted on March 12, 2003 at 15:40

I just got better result with the latest sqrt functions from Cosmic : isqrt (word) and lsqrt (long).

At Fcpu = 8MHz using their modm model, I have :

Execution time word = from 17us to 34us

Execution time long = from ~22us to 57us

(result depends on the input parameter value)

It looks like this Cosmic subroutine is the best we have so far.

Take care,

Jojo

coor
Associate II
Posted on March 19, 2003 at 07:01

try this simple algoritm:

unsigned int sqrt_cpu_newton (unsigned int num) {

unsigned temp, div = num;

unsigned rslt = num;

if (num <= 0)

return 0;

for(;

{

temp = num / div + div;

div = temp >> 1;

div += temp & 1;

if (rslt > div)

rslt = div;

else

return rslt;

}

}

Posted on April 03, 2003 at 20:05

Pretty simple but still longer than the Cosmic functions. I have :

Execution time word = 190us at Fcpu = 8MHz

Take care,

Jojo

daffy_19722
Associate
Posted on April 04, 2003 at 03:23

These isqrt (word) and lsqrt (long) subroutines are not included in the latest Cosmic compiler (4.4d).

Where can we get them ?

Posted on May 07, 2003 at 17:41

These standard library subroutines are available with the latest Cosmic compiler 4.4e.

Take care,

Jojo