mirror of
https://github.com/tiagovignatti/intel-gpu-tools.git
synced 2025-06-22 23:36:30 +00:00
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>
This commit is contained in:
parent
6999b70a84
commit
71e9e9c564
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user