Remove division from inner loop

Michael Abbott michael at araneidae.co.uk
Wed Jun 17 04:43:15 CDT 2009


On Wed, 17 Jun 2009, Henri Verbeet wrote:
> 2009/6/16 Michael Abbott <michael at araneidae.co.uk>:
> > -                    /* The depth data is normalized, so needs to be
> > scaled, the stencil data isn't. */
> Looks like the patch got wrapped. You'll probably want to just attach 
> the output of git format-patch.

Oops!  Thank you for spotting that.  Here's a resubmission.  My fault for 
pasting into the mailer.


From 1cd94f6e852a53f6c5ad1c2084105a7562229e93 Mon Sep 17 00:00:00 2001
From: Michael Abbott <michael at araneidae.co.uk>
Date: Tue, 16 Jun 2009 16:20:05 +0100
Subject: [PATCH] Remove division from inner loop

When rescaling D15S1 data to D24 data it isn't necessary to do full
arithmetic, instead bit shifts are sufficient.
---
 dlls/wined3d/surface.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 6ab0443..f6c0f8c 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -2461,9 +2461,11 @@ static HRESULT d3dfmt_convert_surface(const BYTE *src, BYTE *dst, UINT pitch, UI
 
                 for (x = 0; x < width; ++x)
                 {
-                    /* The depth data is normalized, so needs to be scaled, the stencil data isn't. */
-                    WORD d15 = source[x] & 0xfffe;
-                    DWORD d24 = d15 * 0x100 + (d15 * 0xff80 + 0x3fff80) / 0x7fff00;
+                    /* The depth data is normalized, so needs to be scaled,
+                     * the stencil data isn't.  Scale depth data by
+                     *      (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
+                    WORD d15 = source[x] >> 1;
+                    DWORD d24 = (d15 << 9) + (d15 >> 6);
                     dest[x] = (d24 << 8) | (source[x] & 0x1);
                 }
             }
-- 
1.6.0.4


More information about the wine-devel mailing list