News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Function to calcualte Square Root in HLA help.

Started by sasmaster, September 13, 2011, 04:47:33 PM

Previous topic - Next topic

sasmaster

Hi to all assemblers! .I am new to assembly .I am trying to write a compact math library with the stress on optimization which is going to be used in a game engine .I would like to write some of the methods in assembly like HLA and compile it to DLL.I am curious how sqrt calculation method could look like in HLA .Also my question is can MASM implementation of such a method be faster than in HLA or it really depends mostly on the coder proficiency? Any help will be appreciated.
thanks .

jj2007

#1
First of all: Welcome to the Forum :thumbu
Re sqrt, a Forum search for sqrt yields three pages of threads. The simplest solution, though, is the FPU fsqrt opcode.
If that is not fast enough, take Olly and have a look what HLA or C do.

Attached an example showing the differences in speed. The first in the list refers to Jack Crenshaw's algo. No. 2 uses an SSE2 instruction, the last ones the FPU, "pure" and in its MasmBasic form.
Intel(R) Celeron(R) M CPU        420  @ 1.60GHz (SSE3)
215     cycles for Jack C, res=  12345
51      cycles for sqrtsd, res=  12345
64      cycles for fsqrt, res=   12345
66      cycles for MB Sqrt, res= 12345

sasmaster

Wow !Thanks for that.This info is really helpful.Another question is where can I find an example of one of these algorithms written in HLA and wrapped into a method like sqrt(long number) ?
Also what do you mean by : "If that is not fast enough, take Olly and have a look what HLA or C do."  Sorry for too much Noobie questions.

Thanks a lot . :U

jj2007

Quote from: sasmaster on September 14, 2011, 07:04:36 AM
Wow !Thanks for that.This info is really helpful.Another question is where can I find an example of one of these algorithms written in HLA and wrapped into a method like sqrt(long number) ?
Also what do you mean by : "If that is not fast enough, take Olly and have a look what HLA or C do."  Sorry for too much Noobie questions.

Can't help you with HLA, sorry. Olly is a debugger, and using Olly you can see how high-level languages translate e.g. Print Str$("The root is %i", Sqrt(12345)) into assembler instructions.

sasmaster

Thanks for that tip .I guess I will find the rest of the answers in Rendal Hyde's book :)