File: igt_rand.c

package info (click to toggle)
intel-gpu-tools 2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 62,024 kB
  • sloc: xml: 769,439; ansic: 348,692; python: 8,307; yacc: 2,781; perl: 1,196; sh: 1,178; lex: 487; asm: 227; makefile: 27; lisp: 11
file content (37 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "igt_rand.h"

/**
 * SECTION:igt_rand
 * @short_description: Random numbers helper library
 * @title: Random
 * @include: igt_rand.h
 */

static uint32_t global = 0x12345678;

uint32_t hars_petruska_f54_1_random_seed(uint32_t new_state)
{
	uint32_t old_state = global;
	global = new_state;
	return old_state;
}

uint32_t hars_petruska_f54_1_random(uint32_t *s)
{
#define rol(x,k) ((x << k) | (x >> (32-k)))
	return *s = (*s ^ rol(*s, 5) ^ rol(*s, 24)) + 0x37798849;
#undef rol
}

uint64_t hars_petruska_f54_1_random64(uint32_t *s)
{
	uint32_t l = hars_petruska_f54_1_random(s);
	uint32_t h = hars_petruska_f54_1_random(s);

	return (uint64_t)h << 32 | l;
}

uint32_t hars_petruska_f54_1_random_unsafe(void)
{
	return hars_petruska_f54_1_random(&global);
}