projects
/
mesa.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
driconf: add workarounds for SPECviewperf13
[mesa.git]
/
src
/
util
/
rand_xor.c
diff --git
a/src/util/rand_xor.c
b/src/util/rand_xor.c
index b34b4e40bfa5233badb8a0b5d78d7dc279294081..81b64f1ea71712a49338e5b77bf9ae166413e671 100644
(file)
--- a/
src/util/rand_xor.c
+++ b/
src/util/rand_xor.c
@@
-22,17
+22,18
@@
*
*/
*
*/
-#if defined(__linux__)
+#include "detect_os.h"
+
+#if !DETECT_OS_WINDOWS
#if defined(HAVE_GETRANDOM)
#include <sys/random.h>
#endif
#if defined(HAVE_GETRANDOM)
#include <sys/random.h>
#endif
-#include <sys/file.h>
#include <unistd.h>
#include <fcntl.h>
#include <unistd.h>
#include <fcntl.h>
-#else
-#include <time.h>
#endif
#endif
+#include <time.h>
+
#include "rand_xor.h"
/* Super fast random number generator.
#include "rand_xor.h"
/* Super fast random number generator.
@@
-57,10
+58,14
@@
rand_xorshift128plus(uint64_t seed[2])
void
s_rand_xorshift128plus(uint64_t seed[2], bool randomised_seed)
{
void
s_rand_xorshift128plus(uint64_t seed[2], bool randomised_seed)
{
- if (!randomised_seed)
- goto fixed_seed;
+ if (!randomised_seed) {
+ /* Use a fixed seed */
+ seed[0] = 0x3bffb83978e24f88;
+ seed[1] = 0x9238d5d56c71cd35;
+ return;
+ }
-#if
defined(__linux__)
+#if
!DETECT_OS_WINDOWS
size_t seed_size = sizeof(uint64_t) * 2;
#if defined(HAVE_GETRANDOM)
size_t seed_size = sizeof(uint64_t) * 2;
#if defined(HAVE_GETRANDOM)
@@
-70,27
+75,15
@@
s_rand_xorshift128plus(uint64_t seed[2], bool randomised_seed)
#endif
int fd = open("/dev/urandom", O_RDONLY);
#endif
int fd = open("/dev/urandom", O_RDONLY);
- if (fd < 0)
- goto fixed_seed;
-
- if (read(fd, seed, seed_size) != seed_size) {
+ if (fd >= 0) {
+ if (read(fd, seed, seed_size) == seed_size) {
+ close(fd);
+ return;
+ }
close(fd);
close(fd);
- goto fixed_seed;
}
}
-
- close(fd);
- return;
-
-#else
- seed[0] = 0x3bffb83978e24f88;
- seed[1] = time(NULL);
-
- return;
#endif
#endif
-fixed_seed:
-
- /* Fallback to a fixed seed */
seed[0] = 0x3bffb83978e24f88;
seed[0] = 0x3bffb83978e24f88;
- seed[1] =
0x9238d5d56c71cd35
;
+ seed[1] =
time(NULL)
;
}
}