[XviD-devel] Decoder performance
Edouard Gomez
ed.gomez at free.fr
Sun Aug 10 16:33:57 CEST 2003
Christoph Lampert (chl at math.uni-bonn.de) wrote:
> please be careful when replacing
>
> if (quarterpel)
>
> [... usually sthg like this ...]
> (current->vol_flags & XVID_VOL_QUARTERPEL)
Oh, i had a nicer solution than the ? operator for that (on the
paper). Completely branchless.
#define IS_SET_FLAG(a, flag) \
(!!((a)&(flag)))
It 'returns':
- 1 for (a & flag) != 0
- 0 for (a & flag) == 0
It's translated to that sort of assembly in ia32:
-O2 int test(a, flag);
080482f4 <test>:
function prolog
80482f7: 8b 45 0c mov eax, a
80482fa: 85 45 08 test flag, eax
80482fd: 0f 95 c0 setne al
8048300: 0f b6 c0 movzbl eax, al
function termination
The -O0 int test(a, flag); adds a few instructions more , doing a real
bitwise and operation, not the 'test' fake one.
Now the point is that the ? operator is implemented the same way when
doing a simple bitwise and returning 1 or 0 :-) The best thing we should
do, is define two macros, one for boolean returned value required, and
one just to do the 'and'. This would explicit what is intended in the
code.
Something like:
FLAG_IS_SET_BOOL(a, flag) returns 1 if 'flag' is set in 'a' or 0 otherwise.
FLAG_IS_SET(a, flag) returns != 0 if 'flag' is set oin 'a' or 0 otherwise.
--
Edouard Gomez
More information about the XviD-devel
mailing list