Results 1 to 2 of 2

Thread: Asm speed test - asm vs. compiler

  1. #1

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Asm speed test - asm vs. compiler

    PHP Code:
    void ColComparing()
    {
        
    Col c1(100,100,100,240), c2(100,100,99,240);
        
    uint iii=0;

        
    asm volatile(
        
    ";"
        
    ::"r"(c1), "r"(c2), "r"(&ii):);

        
    ResetAndStartTimer("Asm ");
        for(
    i0i<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(
    i0i<loops; ++i)
        {
            if(*((
    uint32*)&c1)==*((uint32*)&c2)) ++ii;
        }
        
    StopAndLog();
    DD(ii);
        
    ii=0;
        
    ResetAndStartTimer("1byte");
        for(
    i0i<loops; ++i)
        {
            if(
    c1.== c2.&& c1.== c2.&& c1.== c2.&& 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.

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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.)
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width