[Pixman] [PATCH 7/8] test: use random data in *rand* if -f used.

bansan85 legarrec.vincent at gmail.com
Wed Dec 13 19:41:38 UTC 2017


---
 test/utils-prng.c | 27 +++++++++++++++------------
 test/utils-prng.h | 43 ++++++++++++++++++++++++++++++-------------
 2 files changed, 45 insertions(+), 25 deletions(-)

diff --git a/test/utils-prng.c b/test/utils-prng.c
index 1d62129..0981f12 100644
--- a/test/utils-prng.c
+++ b/test/utils-prng.c
@@ -57,23 +57,26 @@ void smallprng_srand_r (smallprng_t *x, uint32_t seed)
 void prng_srand_r (prng_t *x, uint32_t seed)
 {
 #ifdef HAVE_GCC_VECTOR_EXTENSIONS
-    int i;
-    prng_rand_128_data_t dummy;
-    smallprng_srand_r (&x->p0, seed);
-    x->a[0] = x->a[1] = x->a[2] = x->a[3] = 0xf1ea5eed;
-    x->b[0] = x->c[0] = x->d[0] = (seed = seed * 1103515245 + 12345);
-    x->b[1] = x->c[1] = x->d[1] = (seed = seed * 1103515245 + 12345);
-    x->b[2] = x->c[2] = x->d[2] = (seed = seed * 1103515245 + 12345);
-    x->b[3] = x->c[3] = x->d[3] = (seed = seed * 1103515245 + 12345);
-    for (i = 0; i < 20; ++i)
-        prng_rand_128_r (x, &dummy);
-#else
+    if (random_data == NULL)
+    {
+        int i;
+        prng_rand_128_data_t dummy;
+        smallprng_srand_r (&x->p0, seed);
+        x->a[0] = x->a[1] = x->a[2] = x->a[3] = 0xf1ea5eed;
+        x->b[0] = x->c[0] = x->d[0] = (seed = seed * 1103515245 + 12345);
+        x->b[1] = x->c[1] = x->d[1] = (seed = seed * 1103515245 + 12345);
+        x->b[2] = x->c[2] = x->d[2] = (seed = seed * 1103515245 + 12345);
+        x->b[3] = x->c[3] = x->d[3] = (seed = seed * 1103515245 + 12345);
+        for (i = 0; i < 20; ++i)
+            prng_rand_128_r (x, &dummy);
+        return;
+    }
+#endif
     smallprng_srand_r (&x->p0, seed);
     smallprng_srand_r (&x->p1, (seed = seed * 1103515245 + 12345));
     smallprng_srand_r (&x->p2, (seed = seed * 1103515245 + 12345));
     smallprng_srand_r (&x->p3, (seed = seed * 1103515245 + 12345));
     smallprng_srand_r (&x->p4, (seed = seed * 1103515245 + 12345));
-#endif
 }
 
 static force_inline void
diff --git a/test/utils-prng.h b/test/utils-prng.h
index 98022d8..cb36517 100644
--- a/test/utils-prng.h
+++ b/test/utils-prng.h
@@ -102,6 +102,7 @@ typedef struct
     smallprng_t p1, p2, p3, p4;
 #endif
     smallprng_t p0;
+#else
 } prng_t;
 
 typedef union
@@ -117,14 +118,16 @@ typedef union
 /*****************************************************************************/
 
 static force_inline uint8_t
-get_rand_data_8() {
+get_rand_data_8 ()
+{
     uint8_t retour = random_data[running_data];
     running_data = (running_data + 1) % size_data;
     return retour;
 }
 
 static force_inline uint32_t
-get_rand_data_32() {
+get_rand_data_32 ()
+{
     /* Do not use 4 get_rand_data_8 () in the same line
      * to be sure of the execution order. */
     uint8_t un = get_rand_data_8();
@@ -137,11 +140,21 @@ get_rand_data_32() {
 static force_inline uint32_t
 smallprng_rand_r (smallprng_t *x)
 {
-    uint32_t e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
-    x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
-    x->b = x->c + x->d;
-    x->c = x->d + e;
-    x->d = e + x->a;
+    if (random_data == NULL)
+    {
+	uint32_t e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
+	x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
+	x->b = x->c + x->d;
+	x->c = x->d + e;
+	x->d = e + x->a;
+    }
+    else
+    {
+	x->a = get_rand_data_32 ();
+	x->b = get_rand_data_32 ();
+	x->c = get_rand_data_32 ();
+	x->d = get_rand_data_32 ();
+    }
     return x->d;
 }
 
@@ -157,12 +170,16 @@ static force_inline void
 prng_rand_128_r (prng_t *x, prng_rand_128_data_t *data)
 {
 #ifdef HAVE_GCC_VECTOR_EXTENSIONS
-    uint32x4 e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
-    x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
-    x->b = x->c + x->d;
-    x->c = x->d + e;
-    x->d = e + x->a;
-    data->vw = x->d;
+    if (random_data == NULL)
+    {
+	uint32x4 e = x->a - ((x->b << 27) + (x->b >> (32 - 27)));
+	x->a = x->b ^ ((x->c << 17) ^ (x->c >> (32 - 17)));
+	x->b = x->c + x->d;
+	x->c = x->d + e;
+	x->d = e + x->a;
+	data->vw = x->d;
+	return;
+    }
 #else
     data->w[0] = smallprng_rand_r (&x->p1);
     data->w[1] = smallprng_rand_r (&x->p2);
-- 
2.15.0



More information about the Pixman mailing list