Commit 7d3cebc4 authored by Martin Storsjö's avatar Martin Storsjö

checkasm: Don't use readtime for checkasm seed

On ARM, the readtime implementations are instructions that might
not always be allowed at runtime (depending on whether the kernel
has allowed user mode code to access the cycle counter registers).
In order to allow building checkasm with the option for benchmarking,
while still running on devices where benchmarking isn't possible,
don't use readtime anywhere unless --bench has been specified.

Use GetTickCount for the seed on windows, and gettimeofday on unix.
parent d9b1ca87
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h>
#include "src/cpu.h" #include "src/cpu.h"
...@@ -39,11 +38,22 @@ ...@@ -39,11 +38,22 @@
#define COLOR_RED FOREGROUND_RED #define COLOR_RED FOREGROUND_RED
#define COLOR_GREEN FOREGROUND_GREEN #define COLOR_GREEN FOREGROUND_GREEN
#define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN) #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
static unsigned get_seed(void) {
return GetTickCount();
}
#else #else
#include <unistd.h> #include <unistd.h>
#include <sys/time.h>
#define COLOR_RED 1 #define COLOR_RED 1
#define COLOR_GREEN 2 #define COLOR_GREEN 2
#define COLOR_YELLOW 3 #define COLOR_YELLOW 3
static unsigned get_seed(void) {
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_usec + tv.tv_sec * 1000000;
}
#endif #endif
/* List of tests to invoke */ /* List of tests to invoke */
...@@ -411,11 +421,7 @@ static void print_cpu_name(void) { ...@@ -411,11 +421,7 @@ static void print_cpu_name(void) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
(void)func_new, (void)func_ref; (void)func_new, (void)func_ref;
#ifdef readtime unsigned int seed = get_seed();
unsigned int seed = readtime();
#else
unsigned int seed = time(NULL);
#endif
int ret = 0; int ret = 0;
while (argc > 1) { while (argc > 1) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment