Asm speed test - asm vs. compiler
PHP Code:
void ColComparing()
{
Col c1(100,100,100,240), c2(100,100,99,240);
uint i, ii=0;
asm volatile(
";"
::"r"(c1), "r"(c2), "r"(&ii):);
ResetAndStartTimer("Asm ");
for(i= 0; i<loops; ++i)
{
asm volatile(
"cmpl %0,%1;"
"jne endA;"
"incl (%2);"
"endA:;"
::"r"(c1), "r"(c2), "r"(&ii):);
}
StopAndLog();
DD(ii);
ii=0;
ResetAndStartTimer("4byte");
for(i= 0; i<loops; ++i)
{
if(*((uint32*)&c1)==*((uint32*)&c2)) ++ii;
}
StopAndLog();
DD(ii);
ii=0;
ResetAndStartTimer("1byte");
for(i= 0; i<loops; ++i)
{
if(c1.b == c2.b && c1.g == c2.g && c1.r == c2.r && c1.a==c2.a) ++ii;
}
StopAndLog();
DD(ii);
testInt += c1.b+ii;
}
Output:
Loops: 1410065408
Asm 1.359000
4byte 3.531000
1byte 1.828000
How is it that the 4byte comparison is so much slower?
It should exactly the same as the Asm.
I am using gcc with ALL optimizations turned on.
Re: Asm speed test - asm vs. compiler
Optimization doesn't mean "make it as good as assembly", it means "make it as good as you can". A program written by a good asm programmer can always beat the execution time of a program written in a high-level language - there's very little of what a language like C calls optimization to be done when writing in asm. (C "optimization" tries to make the canned routines more applicable to the particular usage. It comes close. ASM programmers don't use canned, one-size-fits-all routines.)