Path: blob/main/contrib/arm-optimized-routines/string/include/benchlib.h
39530 views
/*1* Benchmark support functions.2*3* Copyright (c) 2020, Arm Limited.4* SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception5*/67#include <stdint.h>8#include <time.h>910/* Fast and accurate timer returning nanoseconds. */11static inline uint64_t12clock_get_ns (void)13{14struct timespec ts;15clock_gettime (CLOCK_MONOTONIC, &ts);16return ts.tv_sec * (uint64_t) 1000000000 + ts.tv_nsec;17}1819/* Fast 32-bit random number generator. Passing a non-zero seed20value resets the internal state. */21static inline uint32_t22rand32 (uint32_t seed)23{24static uint64_t state = 0xb707be451df0bb19ULL;25if (seed != 0)26state = seed;27uint32_t res = state >> 32;28state = state * 6364136223846793005ULL + 1;29return res;30}3132/* Macros to run a benchmark BENCH using string function FN. */33#define RUN(BENCH, FN) BENCH(#FN, FN)3435#if __aarch64__36# define RUNA64(BENCH, FN) BENCH(#FN, FN)37#else38# define RUNA64(BENCH, FN)39#endif4041#if __ARM_FEATURE_SVE42# define RUNSVE(BENCH, FN) BENCH(#FN, FN)43#else44# define RUNSVE(BENCH, FN)45#endif4647#if WANT_MOPS48# define RUNMOPS(BENCH, FN) BENCH(#FN, FN)49#else50# define RUNMOPS(BENCH, FN)51#endif5253#if __arm__54# define RUNA32(BENCH, FN) BENCH(#FN, FN)55#else56# define RUNA32(BENCH, FN)57#endif5859#if __arm__ && __ARM_ARCH >= 6 && __ARM_ARCH_ISA_THUMB == 260# define RUNT32(BENCH, FN) BENCH(#FN, FN)61#else62# define RUNT32(BENCH, FN)63#endif646566