aboutsummaryrefslogtreecommitdiff
path: root/pixman/test/utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'pixman/test/utils.h')
-rw-r--r--pixman/test/utils.h58
1 files changed, 29 insertions, 29 deletions
diff --git a/pixman/test/utils.h b/pixman/test/utils.h
index f7ea34c5f..78cf0d16d 100644
--- a/pixman/test/utils.h
+++ b/pixman/test/utils.h
@@ -4,6 +4,7 @@
#include <assert.h>
#include "pixman-private.h" /* For 'inline' definition */
+#include "utils-prng.h"
#define ARRAY_LENGTH(A) ((int) (sizeof (A) / sizeof ((A) [0])))
@@ -11,49 +12,44 @@
* taken from POSIX.1-2001 example
*/
-extern uint32_t lcg_seed;
+extern prng_t prng_state_data;
+extern prng_t *prng_state;
#ifdef USE_OPENMP
-#pragma omp threadprivate(lcg_seed)
+#pragma omp threadprivate(prng_state_data)
+#pragma omp threadprivate(prng_state)
#endif
static inline uint32_t
-lcg_rand (void)
+prng_rand (void)
{
- lcg_seed = lcg_seed * 1103515245 + 12345;
- return ((uint32_t)(lcg_seed / 65536) % 32768);
+ return prng_rand_r (prng_state);
}
static inline void
-lcg_srand (uint32_t seed)
+prng_srand (uint32_t seed)
{
- lcg_seed = seed;
+ if (!prng_state)
+ {
+ /* Without setting a seed, PRNG does not work properly (is just
+ * returning zeros). So we only initialize the pointer here to
+ * make sure that 'prng_srand' is always called before any
+ * other 'prng_*' function. The wrongdoers violating this order
+ * will get a segfault. */
+ prng_state = &prng_state_data;
+ }
+ prng_srand_r (prng_state, seed);
}
static inline uint32_t
-lcg_rand_n (int max)
+prng_rand_n (int max)
{
- return lcg_rand () % max;
+ return prng_rand () % max;
}
-static inline uint32_t
-lcg_rand_N (int max)
-{
- uint32_t lo = lcg_rand ();
- uint32_t hi = lcg_rand () << 15;
- return (lo | hi) % max;
-}
-
-static inline uint32_t
-lcg_rand_u32 (void)
+static inline void
+prng_randmemset (void *buffer, size_t size, prng_randmemset_flags_t flags)
{
- /* This uses the 10/11 most significant bits from the 3 lcg results
- * (and mixes them with the low from the adjacent one).
- */
- uint32_t lo = lcg_rand() >> -(32 - 15 - 11 * 2);
- uint32_t mid = lcg_rand() << (32 - 15 - 11 * 1);
- uint32_t hi = lcg_rand() << (32 - 15 - 11 * 0);
-
- return (hi ^ mid ^ lo);
+ prng_randmemset_r (prng_state, buffer, size, flags);
}
/* CRC 32 computation
@@ -69,8 +65,12 @@ compute_crc32_for_image (uint32_t in_crc32,
/* Returns TRUE if running on a little endian system
*/
-pixman_bool_t
-is_little_endian (void);
+static force_inline pixman_bool_t
+is_little_endian (void)
+{
+ unsigned long endian_check_var = 1;
+ return *(unsigned char *)&endian_check_var == 1;
+}
/* perform endian conversion of pixel data
*/