[Pixman] [PATCH] fill: Special-case single pixel wide lines

Chris Wilson chris at chris-wilson.co.uk
Sun Aug 21 06:32:04 PDT 2011


A common condition (in benchmarks at least) are single pixel wide
vertical lines. This is the worst-cast behaviour for the fast-paths like
SSE2 which require long runs in order to offset the ramp up cost of
aligning and using the SIMD registers.

For example, box-outline consists of drawing a single aligned box with a
hairline outline:

before: 2327 (stroke), 2509 (fill)
after: 674 (stroke), 843 (fill)

[measured in *ns* on an i7-640]

(Double-pixel wide lines, such as a stroke-width 1 outline of a
misaligned box are also very common, but cannot hit pixman_fill(), so
rapidly diminishing returns for optimising other widths.)

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 pixman/pixman.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 49 insertions(+), 0 deletions(-)

diff --git a/pixman/pixman.c b/pixman/pixman.c
index 409330b..6376d46 100644
--- a/pixman/pixman.c
+++ b/pixman/pixman.c
@@ -1163,6 +1163,55 @@ pixman_fill (uint32_t *bits,
              int       height,
              uint32_t xor)
 {
+    if (width <= 0 || height <= 0)
+	return;
+
+    /* Special case single-pixel wide fills to avoid ramp-up cost for the
+     * common case of a thin vertical line.
+     */
+    if (width == 1)
+    {
+	uint8_t *d;
+
+	stride *= 4;
+	d = (uint8_t *)bits + stride * y + x * bpp / 8;
+	if (bpp == 8)
+	{
+	    do
+	    {
+		*(uint8_t *)d = xor;
+		d += stride;
+	    }
+	    while (--height);
+
+	    return TRUE;
+	}
+	else if (bpp == 16)
+	{
+	    do
+	    {
+		*(uint16_t *)d = xor;
+		d += stride;
+	    }
+	    while (--height);
+
+	    return TRUE;
+	}
+	else if (bpp == 32)
+	{
+	    do
+	    {
+		*(uint32_t *)d = xor;
+		d += stride;
+	    }
+	    while (--height);
+
+	    return TRUE;
+	}
+
+	stride /= 4;
+    }
+
     return _pixman_implementation_fill (
 	get_implementation(), bits, stride, bpp, x, y, width, height, xor);
 }
-- 
1.7.5.4



More information about the Pixman mailing list