[XviD-devel] Hadamard Transform
pascal massimino
xvid-devel@xvid.org
06 Sep 2002 12:23:30 +0200
--=-JV5ptsbEeHWO3xbncxuu
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Gruel,
On Thu, 2002-09-05 at 14:03, Christoph Lampert wrote:
> Could you try and tell me how much work calculation of
>
> Hadamard's transform (e.g.
> http://www.iro.umontreal.ca/~pigeon/science/ondelettes/Hadamard/Hadamard.html
> )
>
> is compared to fDCT and/or SAD?
Arg.. you shouldn't be teasing me. I failed miserably in
the trap :)
Here are some Hadamard stuff. I let you imagine what
the ASM version (or 8bits) would look like :)
bye,
Skal
--=-JV5ptsbEeHWO3xbncxuu
Content-Disposition: attachment; filename=hadamard.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c; name=hadamard.c; charset=ISO-8859-1
//////////////////////////////////////////////////////////
// Hadamard
void Hadamard_Ref( int16_t *Out, const int16_t *In )
{
static int H8[8*8] =3D {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1,-1,-1,-1,-1,
1, 1,-1,-1,-1,-1, 1, 1,
1, 1,-1,-1, 1, 1,-1,-1,
1,-1,-1, 1, 1,-1,-1, 1,
1,-1,-1, 1,-1, 1, 1,-1,
1,-1, 1,-1,-1, 1,-1, 1,
1,-1, 1,-1, 1,-1, 1,-1
};
for (int j=3D0; j<8; j++) {
for (int i=3D0; i<8; i++)
{
int Sum =3D 0;
for (int k=3D0; k<8; k++) Sum +=3D H8[j*8+k]*In[k*8+i];
Out[j*8+i] =3D Sum / 8;
}
}
}
//////////////////////////////////////////////////////////
void Hadamard_C( int16_t *Out, const int16_t *In )
{
int i;
const int16_t *Eax =3D In;
int16_t *Ecx =3D Out;
for(i=3D0; i<8; i++, Eax++, Ecx++) // Emulates MMX=20
{
int16_t mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7;
#define LOAD_BUTF(m1, m2, a, b) \
(m1) =3D Eax[(a)*8] - Eax[(b)*8]; \
(m2) =3D Eax[(a)*8] + Eax[(b)*8]
#define BUTF(a, b, tmp) \
(tmp) =3D (a)+(b); \
(a) =3D (a)-(b); \
(b) =3D (tmp)
#define STORE(m, a) Ecx[(a)*8] =3D (m)
#define RECALL(m, a) (m) =3D Ecx[(a)*8]
// stage1
LOAD_BUTF( mm0, mm1, 0, 1 );
LOAD_BUTF( mm2, mm3, 2, 3 );
BUTF( mm3, mm1, mm6 );
BUTF( mm0, mm2, mm7 );
STORE( mm3, 3 ); // we spill 1 regs here
// stage2
LOAD_BUTF( mm4, mm5, 4, 5 ); =20
LOAD_BUTF( mm6, mm7, 6, 7 );
BUTF( mm4, mm6, mm3 );
BUTF( mm7, mm5, mm3 );
// stage3
BUTF( mm2, mm6, mm3 );
BUTF( mm1, mm5, mm3 );
BUTF( mm0, mm4, mm3 );
STORE( mm2, 6);
STORE( mm6, 7);
STORE( mm1, 1);
STORE( mm5, 0);
STORE( mm0, 5);
STORE( mm4, 4);
RECALL(mm3, 3);
BUTF(mm7, mm3, mm0);
STORE(-mm3, 3);
STORE(mm7, 2);
}
for(i=3D0; i<64; i++) Out[i] /=3D 8;
}
//////////////////////////////////////////////////////////
--=-JV5ptsbEeHWO3xbncxuu--