[Pixman] [PATCH] test: detection of possible floating point registers corruption

Siarhei Siamashka siarhei.siamashka at gmail.com
Thu Sep 9 02:41:00 PDT 2010


From: Siarhei Siamashka <siarhei.siamashka at nokia.com>

Added a pair of macros which can help to detect corruption
of floating point registers after a function call. This may
happen if _mm_empty() call is forgotten in MMX/SSE2 fast
path code, or ARM NEON assembly optimized function
forgets to save/restore d8-d15 registers before use.
---
 test/blitters-test.c |    3 ++-
 test/scaling-test.c  |    3 +++
 test/utils.h         |   36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 1 deletions(-)

diff --git a/test/blitters-test.c b/test/blitters-test.c
index fb2c4b9..9dd9163 100644
--- a/test/blitters-test.c
+++ b/test/blitters-test.c
@@ -267,6 +267,7 @@ test_composite (int testnum, int verbose)
     uint32_t *dstbuf, *srcbuf, *maskbuf;
     uint32_t crc32;
     int max_width, max_height, max_extra_stride;
+    FLOAT_REGS_CORRUPTION_DETECTOR_START ();
 
     max_width = max_height = 24 + testnum / 10000;
     max_extra_stride = 4 + testnum / 1000000;
@@ -410,7 +411,7 @@ test_composite (int testnum, int verbose)
 	    free_random_image (0, mask_img, -1);
     }
 
-
+    FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
     return crc32;
 }
 
diff --git a/test/scaling-test.c b/test/scaling-test.c
index 6aef823..b90584b 100644
--- a/test/scaling-test.c
+++ b/test/scaling-test.c
@@ -46,6 +46,7 @@ test_composite (int      testnum,
     uint32_t *         srcbuf;
     uint32_t *         dstbuf;
     uint32_t           crc32;
+    FLOAT_REGS_CORRUPTION_DETECTOR_START ();
 
     lcg_srand (testnum);
 
@@ -234,6 +235,8 @@ test_composite (int      testnum,
     crc32 = compute_crc32 (0, dstbuf, dst_stride * dst_height);
     free (srcbuf);
     free (dstbuf);
+
+    FLOAT_REGS_CORRUPTION_DETECTOR_FINISH ();
     return crc32;
 }
 
diff --git a/test/utils.h b/test/utils.h
index bfb76a5..a39af02 100644
--- a/test/utils.h
+++ b/test/utils.h
@@ -1,5 +1,6 @@
 #include <stdlib.h>
 #include <config.h>
+#include <assert.h>
 #include "pixman-private.h" /* For 'inline' definition */
 
 /* A primitive pseudorandom number generator,
@@ -65,3 +66,38 @@ fuzzer_test_main (const char *test_name,
 
 void
 fail_after (int seconds, const char *msg);
+
+/* A pair of macros which can help to detect corruption of
+ * floating point registers after a function call. This may
+ * happen if _mm_empty() call is forgotten in MMX/SSE2 fast
+ * path code, or ARM NEON assembly optimized function forgets
+ * to save/restore d8-d15 registers before use.
+ */
+
+#define FLOAT_REGS_CORRUPTION_DETECTOR_START()                 \
+    static volatile double frcd_volatile_constant1 = 123451;   \
+    static volatile double frcd_volatile_constant2 = 123452;   \
+    static volatile double frcd_volatile_constant3 = 123453;   \
+    static volatile double frcd_volatile_constant4 = 123454;   \
+    static volatile double frcd_volatile_constant5 = 123455;   \
+    static volatile double frcd_volatile_constant6 = 123456;   \
+    static volatile double frcd_volatile_constant7 = 123457;   \
+    static volatile double frcd_volatile_constant8 = 123458;   \
+    double frcd_canary_variable1 = frcd_volatile_constant1;    \
+    double frcd_canary_variable2 = frcd_volatile_constant2;    \
+    double frcd_canary_variable3 = frcd_volatile_constant3;    \
+    double frcd_canary_variable4 = frcd_volatile_constant4;    \
+    double frcd_canary_variable5 = frcd_volatile_constant5;    \
+    double frcd_canary_variable6 = frcd_volatile_constant6;    \
+    double frcd_canary_variable7 = frcd_volatile_constant7;    \
+    double frcd_canary_variable8 = frcd_volatile_constant8;
+
+#define FLOAT_REGS_CORRUPTION_DETECTOR_FINISH()                \
+    assert (frcd_canary_variable1 == frcd_volatile_constant1); \
+    assert (frcd_canary_variable2 == frcd_volatile_constant2); \
+    assert (frcd_canary_variable3 == frcd_volatile_constant3); \
+    assert (frcd_canary_variable4 == frcd_volatile_constant4); \
+    assert (frcd_canary_variable5 == frcd_volatile_constant5); \
+    assert (frcd_canary_variable6 == frcd_volatile_constant6); \
+    assert (frcd_canary_variable7 == frcd_volatile_constant7); \
+    assert (frcd_canary_variable8 == frcd_volatile_constant8);
-- 
1.7.2.2



More information about the Pixman mailing list