1 /*
2  * Benchmark support functions.
3  *
4  * Copyright (c) 2020, Arm Limited.
5  * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
6  */
7 
8 #include <stdint.h>
9 #include <time.h>
10 
11 /* Fast and accurate timer returning nanoseconds.  */
12 static inline uint64_t
clock_get_ns(void)13 clock_get_ns (void)
14 {
15   struct timespec ts;
16   clock_gettime (CLOCK_MONOTONIC, &ts);
17   return ts.tv_sec * (uint64_t) 1000000000 + ts.tv_nsec;
18 }
19 
20 /* Fast 32-bit random number generator.  Passing a non-zero seed
21    value resets the internal state.  */
22 static inline uint32_t
rand32(uint32_t seed)23 rand32 (uint32_t seed)
24 {
25   static uint64_t state = 0xb707be451df0bb19ULL;
26   if (seed != 0)
27     state = seed;
28   uint32_t res = state >> 32;
29   state = state * 6364136223846793005ULL + 1;
30   return res;
31 }
32 
33 
34