summaryrefslogtreecommitdiff
path: root/lib/igt_aux.c
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2014-12-18 09:08:13 +0000
committerChris Wilson <chris@chris-wilson.co.uk>2014-12-18 11:49:11 +0000
commit71e9e9c564419cd1f4563c628dc80e707a512065 (patch)
tree59ee5a78a7afe385ba20fdd3826f1fb785a02c33 /lib/igt_aux.c
parent6999b70a8438789c3afaad0cb76cf364bd4274c1 (diff)
lib: random() is too slow
random() being a good multithread-safe RNG is too slow to be used in stress tests, especially for a seemingly trivial task of randomising the order of an array. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Diffstat (limited to 'lib/igt_aux.c')
-rw-r--r--lib/igt_aux.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 11618282..193d771b 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -190,6 +190,15 @@ void igt_exchange_int(void *array, unsigned i, unsigned j)
int_arr[j] = tmp;
}
+static uint32_t
+hars_petruska_f54_1_random_unsafe(void)
+{
+ static uint32_t state = 0x12345678;
+#define rol(x,k) ((x << k) | (x >> (32-k)))
+ return state = (state ^ rol (state, 5) ^ rol (state, 24)) + 0x37798849;
+#undef rol
+}
+
/**
* igt_permute_array:
* @array: pointer to array
@@ -209,7 +218,7 @@ void igt_permute_array(void *array, unsigned size,
for (i = size - 1; i > 1; i--) {
/* yes, not perfectly uniform, who cares */
- long l = random() % (i +1);
+ long l = hars_petruska_f54_1_random_unsafe() % (i +1);
if (i != l)
exchange_func(array, i, l);
}