[XviD-devel] log2 hacking...
Jim Hauxwell
xvid-devel@xvid.org
Sat, 4 Jan 2003 12:41:59 -0000
theres a similar function in
bitstream.c
log2bin(uint32_t value)
I would probably set it out in that format for consistancy
Jim
> -----Original Message-----
> From: xvid-devel-admin@xvid.org [mailto:xvid-devel-admin@xvid.org]On
> Behalf Of Christoph Lampert
> Sent: 04 January 2003 12:12
> To: xvid-devel@xvid.org
> Subject: [XviD-devel] log2 hacking...
>
>
>
> Hi,
>
> not really XVID related, although I'll use it in GMC:
>
>
> I'm need a quick way to calculate the next higher (or equal) power
> of two than a given value X:
>
> So for X=320 is should be 512 and for X=720 it should be 1024. For X=1024
> it should be 1024 as well, etc.
> I also need the log2() of this value, so the routine should be something
> like
>
> {
> exponent = log2(X);
> value = 1<< exponent;
> }
>
>
> * I can either use float log() for that (boooh!), but there is no
> direct log2() function, so this sucks...
>
> exponent = round(log(X)/log(2)) ;
> value = 1 << exponent;
>
> * Or I can use a loop:
>
> value=16; // lower than 16 won't happen
> exponent=4;
>
> while (value<X) { exponent++; value+=value; }
>
>
>
> * Or I can use Intel "bitsearch" instruction:
>
> function IntLog2( Value: integer ): integer;
> asm
> BSR EAX, EAX
> end;
>
>
> which is of course very clever, but only possible on i386, and
> also I don't want to use inline assembler.
> Do you know any way to let the compiler "know" what I want and
> make him call 'BSR' or an equivalent on another plattform directly?
>
> gruel
>
>
>
>
>
>
> _______________________________________________
> XviD-devel mailing list
> XviD-devel@xvid.org
> http://list.xvid.org/mailman/listinfo/xvid-devel