xserver/fb fbpict.h,1.24,1.25
Billy Biggs
xserver-commit at pdx.freedesktop.org
Thu Aug 11 11:04:33 EST 2005
Committed by: vektor
Update of /cvs/xserver/xserver/fb
In directory gabe:/tmp/cvs-serv5794/fb
Modified Files:
fbpict.h
Log Message:
* fb/fbpict.h: Fix a rounding error in many of the division by
255 macros. The code used was: ((x + (x >> 8) + 0x80) >> 8).
This is incorrect, the inner shift must also be rounded up. The
correct formula is: (t = x + 0x80), ((t + (t >> 8)) >> 8).
Index: fbpict.h
===================================================================
RCS file: /cvs/xserver/xserver/fb/fbpict.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- fbpict.h 12 Jul 2005 09:57:00 -0000 1.24
+++ fbpict.h 11 Aug 2005 01:04:31 -0000 1.25
@@ -147,12 +147,12 @@
x_c = (x_c * a) / 255
*/
#define FbByteMul(x, a) do { \
- CARD32 t = (x & 0xff00ff) *a; \
- t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; \
+ CARD32 t = ((x & 0xff00ff) * a) + 0x800080; \
+ t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
t &= 0xff00ff; \
\
- x = ((x >> 8) & 0xff00ff) * a; \
- x = (x + ((x >> 8) & 0xff00ff) + 0x800080); \
+ x = (((x >> 8) & 0xff00ff) * a) + 0x800080; \
+ x = (x + ((x >> 8) & 0xff00ff)); \
x &= 0xff00ff00; \
x += t; \
} while (0)
@@ -161,15 +161,15 @@
x_c = (x_c * a) / 255 + y
*/
#define FbByteMulAdd(x, a, y) do { \
- CARD32 t = (x & 0xff00ff) * a; \
- t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; \
+ CARD32 t = ((x & 0xff00ff) * a) + 0x800080; \
+ t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
t &= 0xff00ff; \
t += y & 0xff00ff; \
t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
t &= 0xff00ff; \
\
- x = ((x >> 8) & 0xff00ff) * a; \
- x = (x + ((x >> 8) & 0xff00ff) + 0x800080) >> 8; \
+ x = (((x >> 8) & 0xff00ff) * a) + 0x800080; \
+ x = (x + ((x >> 8) & 0xff00ff)) >> 8; \
x &= 0xff00ff; \
x += (y >> 8) & 0xff00ff; \
x |= 0x1000100 - ((t >> 8) & 0xff00ff); \
@@ -183,12 +183,12 @@
*/
#define FbByteAddMul(x, a, y, b) do { \
CARD32 t; \
- CARD32 r = (x >> 24) * a + (y >> 24) * b; \
- r += (r >> 8) + 0x80; \
+ CARD32 r = (x >> 24) * a + (y >> 24) * b + 0x80; \
+ r += (r >> 8); \
r >>= 8; \
\
- t = (x & 0xff00) * a + (y & 0xff00) * b; \
- t += (t >> 8) + 0x8000; \
+ t = (x & 0xff00) * a + (y & 0xff00) * b + 0x8000; \
+ t += (t >> 8); \
t >>= 16; \
\
t |= r << 16; \
@@ -196,12 +196,12 @@
t &= 0xff00ff; \
t <<= 8; \
\
- r = ((x >> 16) & 0xff) * a + ((y >> 16) & 0xff) * b; \
- r += (r >> 8) + 0x80; \
+ r = ((x >> 16) & 0xff) * a + ((y >> 16) & 0xff) * b + 0x80; \
+ r += (r >> 8); \
r >>= 8; \
\
- x = (x & 0xff) * a + (y & 0xff) * b; \
- x += (x >> 8) + 0x80; \
+ x = (x & 0xff) * a + (y & 0xff) * b + 0x80; \
+ x += (x >> 8); \
x >>= 8; \
x |= r << 16; \
x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
@@ -228,13 +228,15 @@
CARD32 t; \
CARD32 r = (x & 0xff) * (a & 0xff); \
r |= (x & 0xff0000) * ((a >> 16) & 0xff); \
- r = (r + ((r >> 8) & 0xff00ff) + 0x800080) >> 8; \
+ r += 0x800080; \
+ r = (r + ((r >> 8) & 0xff00ff)) >> 8; \
r &= 0xff00ff; \
\
x >>= 8; \
t = (x & 0xff) * ((a >> 8) & 0xff); \
t |= (x & 0xff0000) * (a >> 24); \
- t = (t + ((t >> 8) & 0xff00ff) + 0x800080); \
+ t += 0x800080; \
+ t = t + ((t >> 8) & 0xff00ff); \
x = r | (t & 0xff00ff00); \
\
} while (0)
@@ -246,7 +248,8 @@
CARD32 t; \
CARD32 r = (x & 0xff) * (a & 0xff); \
r |= (x & 0xff0000) * ((a >> 16) & 0xff); \
- r = (r + ((r >> 8) & 0xff00ff) + 0x800080) >> 8; \
+ r += 0x800080; \
+ r = (r + ((r >> 8) & 0xff00ff)) >> 8; \
r &= 0xff00ff; \
r += y & 0xff00ff; \
r |= 0x1000100 - ((r >> 8) & 0xff00ff); \
@@ -255,7 +258,8 @@
x >>= 8; \
t = (x & 0xff) * ((a >> 8) & 0xff); \
t |= (x & 0xff0000) * (a >> 24); \
- t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8; \
+ t += 0x800080; \
+ t = (t + ((t >> 8) & 0xff00ff)) >> 8; \
t &= 0xff00ff; \
t += (y >> 8) & 0xff00ff; \
t |= 0x1000100 - ((t >> 8) & 0xff00ff); \
@@ -268,12 +272,12 @@
*/
#define FbByteAddMulC(x, a, y, b) do { \
CARD32 t; \
- CARD32 r = (x >> 24) * (a >> 24) + (y >> 24) * b; \
- r += (r >> 8) + 0x80; \
+ CARD32 r = (x >> 24) * (a >> 24) + (y >> 24) * b + 0x80; \
+ r += (r >> 8); \
r >>= 8; \
\
- t = (x & 0xff00) * ((a >> 8) & 0xff) + (y & 0xff00) * b; \
- t += (t >> 8) + 0x8000; \
+ t = (x & 0xff00) * ((a >> 8) & 0xff) + (y & 0xff00) * b + 0x8000; \
+ t += (t >> 8); \
t >>= 16; \
\
t |= r << 16; \
@@ -281,12 +285,12 @@
t &= 0xff00ff; \
t <<= 8; \
\
- r = ((x >> 16) & 0xff) * ((a >> 16) & 0xff) + ((y >> 16) & 0xff) * b; \
- r += (r >> 8) + 0x80; \
+ r = ((x >> 16) & 0xff) * ((a >> 16) & 0xff) + ((y >> 16) & 0xff) * b + 0x80; \
+ r += (r >> 8); \
r >>= 8; \
\
- x = (x & 0xff) * (a & 0xff) + (y & 0xff) * b; \
- x += (x >> 8) + 0x80; \
+ x = (x & 0xff) * (a & 0xff) + (y & 0xff) * b + 0x80; \
+ x += (x >> 8); \
x >>= 8; \
x |= r << 16; \
x |= 0x1000100 - ((x >> 8) & 0xff00ff); \
@@ -309,7 +313,7 @@
x = r; \
} while (0)
-#define div_255(x) (((x) + ((x) >> 8) + 0x80) >> 8)
+#define div_255(x) (((x) + 0x80 + (((x) + 0x80) >> 8)) >> 8)
#if defined(__i386__) && defined(__GNUC__)
#define FASTCALL __attribute__((regparm(3)))
More information about the xserver-commit
mailing list