[MPlayer-users] CopyBlock Alignment Problem on Sparc/Solaris

Ken Mandelberg km at mathcs.emory.edu
Mon Jan 7 17:14:01 CET 2002


There is an alignment problem in the opendivx code running
on Sparc/Solaris, which yields a bus error on divx playback.
This is on the 0.60 distribution (and earlier).

Specifically in opendivx/basic_prediction.c

======
void CopyBlock(unsigned char * Src, unsigned char * Dst, int Stride)
{
    int dy;
    long *lpSrc = (long *) Src;
    long *lpDst = (long *) Dst;
    int lpStride = Stride >> 2;

    for (dy = 0; dy < 8; dy++) {
        lpDst[0] = lpSrc[0];
        lpDst[1] = lpSrc[1];
        lpSrc += lpStride;
        lpDst += lpStride;
    }
======

CopyBlock is sometimes passed non fullword aligned addresses (I think
they are even odd), which will cause a buserror at "pDst[0] = lpSrc[0];"

I replaced this with
     
    int dy;
    char *lpSrc = Src;
    char *lpDst = Dst;

    for (dy = 0; dy < 8; dy++) {
        memcpy(lpDst, lpSrc, 8);
        lpSrc += Stride;
        lpDst += Stride;
        }

which worked. I presume this could be integrated with an appropriate
#ifdef, but I don't see any that perpetuate down to the opendivx Makefile.

The same error occurs in one more spot in the same file. I replaced

=====
void CopyMBlock(unsigned char * Src, unsigned char * Dst, int Stride)
{
    int dy;
    long *lpSrc = (long *) Src;
    long *lpDst = (long *) Dst;
    int lpStride = Stride >> 2;

    for (dy = 0; dy < 16; dy++) {
        lpDst[0] = lpSrc[0];
        lpDst[1] = lpSrc[1];
        lpDst[2] = lpSrc[2];
        lpDst[3] = lpSrc[3];
        lpSrc += lpStride;
        lpDst += lpStride;
    }

=====
with

    int dy;
    char *lpSrc = Src;
    char *lpDst = Dst;

    for (dy = 0; dy < 16; dy++) {
        memcpy(lpDst, lpSrc, 16);
        lpSrc += Stride;
        lpDst += Stride;
        }





----


Ken Mandelberg      | km at mathcs.emory.edu          
Emory University    | 
Dept of Math and CS | Phone: Voice (404) 727-7963 
Atlanta, GA 30322   |        FAX 727-5611




More information about the MPlayer-users mailing list