[FFmpeg-devel] [RFC] support encrypted asf

Uoti Urpala uoti.urpala
Mon Oct 8 22:34:20 CEST 2007


On Mon, 2007-10-08 at 21:29 +0200, Michael Niedermayer wrote:
> interresting, btw a multiply based variant with fewer multiplies is:
> 
> static uint32_t inverse(uint32_t v) {
>     uint32_t v3, v6, v12;
> #define POW3(v)  v*=v; v*=v; v*=v
> #define POW6(v)  POW3(v); POW3(v)
> #define POW12(v) POW6(v); POW6(v)
>     v3= v*v*v;
>     v6=v3= v3*v3*v;
>     POW3(v6);
>     v12=v6= v6*v3;
>     POW6(v12);
>     v3=v12= v12*v6;
>     POW12(v3);
>     v3*=v12;
>     POW6(v3);
>     v3 *=v6;
>     return v3*v3*v;
> }

You can do one multiplication better with:
static uint32_t inverse(uint32_t v) {
#define SQ2 v *= v; v *= v;
#define SQ4 SQ2; SQ2; 
#define SQ8 SQ4; SQ4;
#define SQ16 SQ8; SQ8;

    uint32_t v2;

    v = v*v*v; v2 = v;
    SQ2;
    v *= v2; v2 = v;
    SQ4;
    v *= v2; v2 = v;
    SQ8;
    v *= v2; v2 = v;
    SQ16;
    return v2 * v;
}

I already showed this variant on IRC when Reimar was discussing it
yesterday.





More information about the ffmpeg-devel mailing list