2016-11-22 01:22:08 -08:00
|
|
|
// Copyright (c) 2016 The Bitcoin Core developers
|
2023-01-23 10:31:54 -08:00
|
|
|
// Copyright (c) 2020-2023 The Zcash developers
|
2016-11-22 01:22:08 -08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2020-12-12 16:33:22 -08:00
|
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php .
|
2016-11-22 01:22:08 -08:00
|
|
|
|
|
|
|
/** Functions for measurement of CPU cycles */
|
2018-03-22 07:19:44 -07:00
|
|
|
#ifndef BITCOIN_BENCH_PERF_H
|
|
|
|
#define BITCOIN_BENCH_PERF_H
|
2016-11-22 01:22:08 -08:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#if defined(__i386__)
|
|
|
|
|
|
|
|
static inline uint64_t perf_cpucycles(void)
|
|
|
|
{
|
|
|
|
uint64_t x;
|
|
|
|
__asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
|
|
|
|
static inline uint64_t perf_cpucycles(void)
|
|
|
|
{
|
|
|
|
uint32_t hi, lo;
|
|
|
|
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
|
|
|
|
return ((uint64_t)lo)|(((uint64_t)hi)<<32);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
|
|
|
uint64_t perf_cpucycles(void);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void perf_init(void);
|
|
|
|
void perf_fini(void);
|
|
|
|
|
2018-03-22 07:19:44 -07:00
|
|
|
#endif // BITCOIN_BENCH_PERF_H
|