how much the increasing of performance i can expected after convert the algorithm from C code to ASM (in normal ASM and Optimized ASM codes) ? at least 2 times?

because i've done some stuff with C code (opitmized C code), and the speed is the most important for this stuff, but the algorithm is not easy so it would be better if i can know how much i'll get from the converting before start codeing ASM.

Thank you,
Posted on 2002-04-28 17:55:50 by doby
Sorry, but that's plain nonsense to ask.

First (as you know) "converting" to assembly means nothing per se. It is wrong, very wrong, to think that *just* writing asm makes things faster. Compilers can write asm too, and some do a better job than a blind asm programmer.

Knowing how the hardware in *depth* works, and your algorithm as well, can do wonders and can outperform any HLL compiler by far, in many circumstances (and never get slower anyway).

So your question just cannot be answered, because:
1) The question is simplicistic.
2) The algorithm is not known.
3) The skills and experience of the assembly programmer are not known.

How can we solve an equation of which we don't know anything?

I'm not one of those who says that HLL compilers are better than humans, at all (although I sure know that some of the best designed ones can do an extremely decent job in many frequent circumstances).. but I think that most humans can mess things up worse than any HLL compiler, just pretending that writing asm statements makes things faster by magic, instead of by careful knowledge, deep thinking and tuning up.
Posted on 2002-04-28 18:20:44 by Maverick
thanks for quick answer, Maverick

ok, i'll try to fullfill some information may be it can help or can not to answer my question but i just want to discuss. :)

if i assume that i've optimized the algorithm (optimized "algorithm" not depend on specific language) and i just want to convert that alogorithm in C souce code to ASM code by ASM programmer that has not much experiece in ASM optimization the programmer who know only simple intruction.

the algorithm is MoveGenerater for Checkers Game (actually Thai Checkers). it used in Thinking Engine for the game. so if it faster it can search more nodes, and it will be stronger player.

i know that the compiler can generate the asm code, but from the syntax of HLL may be it is the factor that make it gen bad ASM code.

and if i just convert C to ASM code, nothing improve in algorithm but is there any improve in term of "reduce overhead" of HLL?
is there any one have experience on converting?

may be i'm wrong but i just want to know the opinion and suggestion of many experience ASM programmer here. if nothing good and waste of the time to just convert C to ASM, it better to try more optimazition in C code, so i'll go on continue my C code.

sorry for my bad english,
thank you very much,

Posted on 2002-04-28 18:53:52 by doby
If you really know ASM instructions, I think you can do a good optimization. ASM instructions are in an average of 4 clock cycles, and they use an average of 2 bytes. So, if you know or you have access to these properties of the instructions you can make a good optimization if you really want it. Not only in speed but also in size.
Posted on 2002-04-28 21:00:39 by CodeLover
doby, have you done any profiling (speed measurements) of your code? You can inline some ASM to help the compiler at critical points. This would be a good way to convert present algo to ASM. Redesign of the algo to take advantage of the CPU architecture will provide further performance. I am assuming that your algorithm has been optimized from a strictly mathematical perspective.
Posted on 2002-04-28 21:09:17 by bitRAKE
bitRake, yes i've done the speed measurement but it is the overall speed not only the part that i want to convert to asm (MoveGenerater).

i've done the optimization on somethings like: bitboard representation (use 4 of 32-bits number(whiteman,whiteking,blackman,blackking) to represent board instead of array[32]), table look up for some calculation, etc...

from the answers it seem that it's a worth to try converting.

if anyone interested in this kind of algorithm or have some idea or want to help me (both idea of algorithm or coding) i'm very glad to talk with.

Posted on 2002-04-28 22:18:09 by doby

It will depend on how much you know about writing code in assembler. I would be inclined to isolate the section that the profiler shows as slow and get the compiler to produce it in asm so that you can do some analysis on what the compiler is doing.

What you are trying to do is reduce the number of instructions in the algorithm path and this is where your knowledge of assembler will be important. Often if the compiler does not do smart things in its variable choice or if it does not transfer indexes from one part of the algorithm to another, you will have room to rewrite that part of the algorithm to make it go faster but be aware that you can end up with a slower result if you don't get the code design right.

Another approach is to try and break down the critical algorithm into smaller parts and replace each part one at a time to se if you get any speed increase.

Posted on 2002-04-29 03:40:09 by hutch--