tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
cycle_counter_arm.h
Go to the documentation of this file.
1#pragma once
2
8namespace detail
9{
10
19 {
20 unsigned long long start_cycles;
21 unsigned long long total_cycles = 0;
22 unsigned long long runs = 0;
23
25 FORCE_INLINE void start() noexcept
26 {
27 unsigned long long val;
28 asm volatile("mrs %0, cntvct_el0" : "=r"(val));
29 start_cycles = val;
30 }
31
33 FORCE_INLINE void stop() noexcept
34 {
35 unsigned long long end;
36 asm volatile("mrs %0, cntvct_el0" : "=r"(end));
37 total_cycles += (end - start_cycles);
38 ++runs;
39 }
40
42 void reset() noexcept
43 {
44 total_cycles = 0;
45 runs = 0;
46 }
47
49 double avg_cycles() const { return static_cast<double>(total_cycles) / runs; }
50 };
51
52} // namespace detail
#define FORCE_INLINE
Hint the compiler to always inline a function.
Definition config.h:26
Definition BaseExpr.h:4
Hardware cycle counter for AArch64/ARM.
Definition cycle_counter_arm.h:19
unsigned long long runs
Definition cycle_counter_arm.h:22
unsigned long long total_cycles
Definition cycle_counter_arm.h:21
unsigned long long start_cycles
Definition cycle_counter_arm.h:20
void reset() noexcept
Reset accumulated ticks and run count to zero.
Definition cycle_counter_arm.h:42
FORCE_INLINE void stop() noexcept
Record the ending tick count and accumulate.
Definition cycle_counter_arm.h:33
FORCE_INLINE void start() noexcept
Record the starting tick count.
Definition cycle_counter_arm.h:25
double avg_cycles() const
Return the average ticks per start/stop pair.
Definition cycle_counter_arm.h:49