2003-05-07 08:41 AM
2002-10-28 08:59 AM
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
2002-11-07 10:25 AM
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=false2002-11-08 03:20 AM
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 ? Breizh2002-11-08 04:37 AM
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=false2003-03-12 06:40 AM
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, Jojo2003-03-18 10:01 PM
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; } }2003-04-03 10:05 AM
Pretty simple but still longer than the Cosmic functions. I have :
Execution time word = 190us at Fcpu = 8MHz Take care, Jojo2003-04-03 05:23 PM
These isqrt (word) and lsqrt (long) subroutines are not included in the latest Cosmic compiler (4.4d).
Where can we get them ?2003-05-07 08:41 AM
These standard library subroutines are available with the latest Cosmic compiler 4.4e.
Take care, Jojo