tech-x11 archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: unaligned access problem in XAA



On Monday 29 November 2010 07:40:54 Nick Hudson wrote:
> Hi,
> 
> I found an unaligned access that I've fixed with the attached patch. 
>  Anyone see any problems with it and/or test it on a big endian platform?

Some helpful people (you know who you are) spotted some problems with this 
version.  Updated version attached.

Nick
Index: external/mit/xorg-server/dist/hw/xfree86/xaa/xaaPCache.c
===================================================================
RCS file: 
/cvsroot/xsrc/external/mit/xorg-server/dist/hw/xfree86/xaa/xaaPCache.c,v
retrieving revision 1.1.1.3
diff -u -p -u -r1.1.1.3 xaaPCache.c
--- external/mit/xorg-server/dist/hw/xfree86/xaa/xaaPCache.c    23 Nov 2010 
05:21:41 -0000      1.1.1.3
+++ external/mit/xorg-server/dist/hw/xfree86/xaa/xaaPCache.c    29 Nov 2010 
08:28:47 -0000
@@ -1188,6 +1188,22 @@ XAACheckStippleReducibility(PixmapPtr pP
     return TRUE;
 }
 
+static inline CARD32
+load_24bits(void *where)
+{
+    unsigned char *bytes = where;
+
+    if (__predict_true(((uintptr_t)where & (4 - 1)) == 0)) {
+        return (*(CARD32 *)where) & 0x00ffffff;
+    }
+
+#if X_BYTE_ORDER == X_LITTLE_ENDIAN
+    return bytes[2] << 16 + bytes[1] << 8 + bytes[0];
+#endif
+#if X_BYTE_ORDER == X_BIG_ENDIAN
+    return bytes[0] << 16 + bytes[1] << 8 + bytes[2];
+#endif
+}
 
 Bool
 XAACheckTileReducibility(PixmapPtr pPixmap, Bool checkMono)
@@ -1323,13 +1339,13 @@ XAACheckTileReducibility(PixmapPtr pPixm
        } else if(pPixmap->drawable.bitsPerPixel == 24) {
            CARD32 val;
            unsigned char *srcp = pPixmap->devPrivate.ptr;
-           fg = *((CARD32*)srcp) & 0x00FFFFFF;
+           fg = load_24bits(srcp);
            pitch = pPixmap->devKind;
            j *= 3;
            for(y = 0; y < i; y++) {
                bits[y] = 0;
                for(x = 0; x < j; x+=3) {
-                  val = *((CARD32*)(srcp+x)) & 0x00FFFFFF;
+                  val = load_24bits(srcp+x);
                   if(val != fg) {
                        if(bg == -1) bg = val;
                        else if(bg != val) 


Home | Main Index | Thread Index | Old Index