[Pixman] [PATCH] lowlevel-blt-bench: Parse test name strings in general case

Ben Avison bavison at riscosopen.org
Tue Apr 7 11:26:22 PDT 2015


There are many types of composite operation that are useful to benchmark but
which are omitted from the table. Continually having to add extra entries to
the table is a nuisance and is prone to human error, so this patch adds the
ability to break down unknow strings of the format
  <operation>_<src>[_<mask]<dst>[_ca]
where bitmap formats are specified by number of bits of each component
(assumed in ARGB order) or 'n' to indicate a solid source or mask.

The only downside to this approach is that specifying 'all' instead of a
specific operation will remain limited to the set of operations from the
table.
---
 test/lowlevel-blt-bench.c |  141 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 133 insertions(+), 8 deletions(-)

diff --git a/test/lowlevel-blt-bench.c b/test/lowlevel-blt-bench.c
index 3da094a..c8501d4 100644
--- a/test/lowlevel-blt-bench.c
+++ b/test/lowlevel-blt-bench.c
@@ -51,6 +51,12 @@
 
 #define EXCLUDE_OVERHEAD 1
 
+typedef struct
+{
+    const char *name;
+    uint32_t    number;
+} name_to_number_t;
+
 uint32_t *dst;
 uint32_t *src;
 uint32_t *mask;
@@ -367,14 +373,14 @@ bench_RT (pixman_op_t              op,
 }
 
 void
-bench_composite (char * testname,
-                 int    src_fmt,
-                 int    src_flags,
-                 int    op,
-                 int    mask_fmt,
-                 int    mask_flags,
-                 int    dst_fmt,
-                 double npix)
+bench_composite (const char * testname,
+                 int          src_fmt,
+                 int          src_flags,
+                 int          op,
+                 int          mask_fmt,
+                 int          mask_flags,
+                 int          dst_fmt,
+                 double       npix)
 {
     pixman_image_t *                src_img;
     pixman_image_t *                dst_img;
@@ -719,12 +725,124 @@ tests_tbl[] =
     { "rpixbuf",               PIXMAN_x8b8g8r8,    0, PIXMAN_OP_SRC,     PIXMAN_a8b8g8r8, 0, PIXMAN_a8b8g8r8 },
 };
 
+static uint32_t
+lookup_name_to_number (const char **string, const name_to_number_t *array, size_t entries)
+{
+    size_t entry, i;
+    for (entry = 0; entry < entries; entry++)
+    {
+        for (i = 0; (*string)[i] == array[entry].name[i]; i++)
+        {
+            if ((*string)[i] == 0)
+            {
+                *string += i;
+                return array[entry].number;
+            }
+        }
+        if ((*string)[i] == '_' && array[entry].name[i] == 0)
+        {
+            *string += i;
+            return array[entry].number;
+        }
+    }
+    return 0;
+}
+
+static int
+parse_and_test (const char *pattern)
+{
+    static const name_to_number_t combine_type[] = {
+            { "src",          PIXMAN_OP_SRC },
+            { "over_reverse", PIXMAN_OP_OVER_REVERSE },
+            { "overrev",      PIXMAN_OP_OVER_REVERSE },
+            { "over",         PIXMAN_OP_OVER },
+            { "in_reverse",   PIXMAN_OP_IN_REVERSE },
+            { "inrev",        PIXMAN_OP_IN_REVERSE },
+            { "in",           PIXMAN_OP_IN },
+            { "out_reverse",  PIXMAN_OP_OUT_REVERSE },
+            { "outrev",       PIXMAN_OP_OUT_REVERSE },
+            { "out",          PIXMAN_OP_OUT },
+            { "atop_reverse", PIXMAN_OP_ATOP_REVERSE },
+            { "atoprev",      PIXMAN_OP_ATOP_REVERSE },
+            { "atop",         PIXMAN_OP_ATOP },
+            { "xor",          PIXMAN_OP_XOR },
+            { "add",          PIXMAN_OP_ADD }
+    };
+    static const name_to_number_t format[] = {
+            { "8888",         PIXMAN_a8r8g8b8 },
+            { "x888",         PIXMAN_x8r8g8b8 },
+            { "0565",         PIXMAN_r5g6b5 },
+            { "1555",         PIXMAN_a1r5g5b5 },
+            { "8",            PIXMAN_a8 }
+    };
+
+    const char *p = pattern;
+    int         src_fmt;
+    int         src_flags = 0;
+    int         mask_fmt;
+    int         mask_flags = 0;
+    int         dst_fmt;
+    int         op = lookup_name_to_number(&p, combine_type, sizeof combine_type / sizeof *combine_type);
+    if (op == 0 || *p++ != '_')
+        return 0;
+
+    if (p[0] == 'n' && p[1] == '_')
+    {
+        src_fmt = PIXMAN_a8r8g8b8;
+        src_flags = SOLID_FLAG;
+        ++p;
+    }
+    else
+        src_fmt = lookup_name_to_number(&p, format, sizeof format / sizeof *format);
+    if (src_fmt == 0 || *p++ != '_')
+        return 0;
+
+    if (p[0] == 'n' && p[1] == '_')
+    {
+        mask_fmt = PIXMAN_a8r8g8b8;
+        mask_flags = SOLID_FLAG;
+        ++p;
+    }
+    else
+        mask_fmt = lookup_name_to_number(&p, format, sizeof format / sizeof *format);
+    if (mask_fmt == 0)
+        return 0;
+
+    if (*p == 0)
+    {
+        dst_fmt = mask_fmt;
+        mask_fmt = PIXMAN_null;
+    }
+    else
+    {
+        ++p;
+        dst_fmt = lookup_name_to_number(&p, format, sizeof format / sizeof *format);
+        if (strcmp (p, "_ca") == 0)
+            mask_flags |= CA_FLAG;
+        else if (*p != 0)
+            dst_fmt = 0;
+    }
+    if (dst_fmt == 0)
+        return 0;
+
+    bench_composite (pattern,
+                     src_fmt,
+                     src_flags,
+                     op,
+                     mask_fmt,
+                     mask_flags,
+                     dst_fmt,
+                     bandwidth/8);
+    return 1;
+}
+
 int
 main (int argc, char *argv[])
 {
     double x;
     int i;
     const char *pattern = NULL;
+    int matches = 0;
     for (i = 1; i < argc; i++)
     {
 	if (argv[i][0] == '-')
@@ -805,6 +923,7 @@ main (int argc, char *argv[])
     {
 	if (strcmp (pattern, "all") == 0 || strcmp (tests_tbl[i].testname, pattern) == 0)
 	{
+	    ++matches;
 	    bench_composite (tests_tbl[i].testname,
 			     tests_tbl[i].src_fmt,
 			     tests_tbl[i].src_flags,
@@ -816,6 +935,12 @@ main (int argc, char *argv[])
 	}
     }
 
+    if (matches == 0)
+        matches = parse_and_test (pattern);
+
+    if (matches == 0)
+        printf ("Unrecognised test pattern\n");
+
     free (src);
     return 0;
 }
-- 
1.7.5.4



More information about the Pixman mailing list