[theora-dev] theora 1.0a3 opt hint

Sean lakese at sas.upenn.edu
Wed Jun 2 11:11:35 PDT 2004



> in lib/blockmap.c,v 1.5 2003/12/03
>  func CreateMapping, inner loop code:
>            if ( i<2 ){
>              MB = ( j<2 ? 0 : 1 );
>            }else{
>              MB = ( j<2 ? 2 : 3 );
>            }
>
>
>           if ( i%2 ){
>              B = ( j%2 ? 3 : 2 );
>            }else{
>              B = ( j%2 ? 1 : 0 );
>            }
>  wouldn't this do better:
>            MB = (i >> 1) * 2 + (j >> 1);
>            B = (i % 2) * 2 + j % 2;
>  ?
>
>
> P.S.: I believe it could be optimized even further, but...

For that line:
        MB = (i >>1) *2 + (j >> 1);
It should be noted that the following are equivalent:
        i*2;
        i << 1;
So, you can simplify the first term with a bitwise mask:
        MB = (i & ~1) + (j >>1);
Considering that ~1 is a constant (data size dependent), the compiler 
should reduce that term to one operation.

Likewise, that second line could read:
        B = ((i & 1) << 1) + j & 1;
taking advantage of what should be lower computational overhead for 
bitwise operators than integer arithmetic (especially multiplication).

This is all assuming that these are unsigned integers, or at least 
never negative.

Sean
--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'theora-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Theora-dev mailing list