shithub: dav1d

Download patch

ref: 7d3cebc41913609e33c3ee46e64f6c5a23de2f89
parent: d9b1ca877f5de06237db0aa6ffe10b16103e2db4
author: Martin Storsjö <martin@martin.st>
date: Fri Oct 12 10:40:41 EDT 2018

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.

--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -30,7 +30,6 @@
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
-#include <time.h>
 
 #include "src/cpu.h"
 
@@ -39,11 +38,22 @@
 #define COLOR_RED    FOREGROUND_RED
 #define COLOR_GREEN  FOREGROUND_GREEN
 #define COLOR_YELLOW (FOREGROUND_RED|FOREGROUND_GREEN)
+
+static unsigned get_seed(void) {
+    return GetTickCount();
+}
 #else
 #include <unistd.h>
+#include <sys/time.h>
 #define COLOR_RED    1
 #define COLOR_GREEN  2
 #define COLOR_YELLOW 3
+
+static unsigned get_seed(void) {
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return tv.tv_usec + tv.tv_sec * 1000000;
+}
 #endif
 
 /* List of tests to invoke */
@@ -411,11 +421,7 @@
 
 int main(int argc, char *argv[]) {
     (void)func_new, (void)func_ref;
-#ifdef readtime
-    unsigned int seed = readtime();
-#else
-    unsigned int seed = time(NULL);
-#endif
+    unsigned int seed = get_seed();
     int ret = 0;
 
     while (argc > 1) {