[FFmpeg-devel] [RFC] support encrypted asf

Reimar Döffinger Reimar.Doeffinger
Mon Oct 8 08:42:56 CEST 2007

since it was such an interesting problem I could not stop myself from
optimizing the inverse() function.
It probably is easier to understand without algebra knowledge, but a
bit more obfuscated for those with.
On x86 the speed difference is only about 10%, multiplication is just
too fast on those ;-).
Here it is (tell me if you'd prefer an updated complete patch instead):

static uint32_t inverse(uint32_t v) {
    uint32_t factor = 1;
    uint32_t product = v;
    uint32_t mask = 2;
    do {
      v <<= 1;
      factor |= product & mask;
      product += v & -(product & mask);
      // should be mask <<= 1; but then gcc misses the
      // optimization opportunity to use the Z-flag for the while test
      mask += mask;
    } while (mask);
    return factor;

Reimar D?ffinger

More information about the ffmpeg-devel mailing list