-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockcycle.h
More file actions
36 lines (28 loc) · 862 Bytes
/
clockcycle.h
File metadata and controls
36 lines (28 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**************************************************************/
/* clock_now(): returns a 64 bit counter of cycles for POWER9 */
/* clock rate is 512MHz */
/**************************************************************/
#ifndef CLOCKCYCLE_H
#define CLOCKCYCLE_H
#include <ctime>
#include <stdint.h>
typedef uint64_t ticks;
inline ticks clock_now(void)
{
unsigned int tbl, tbu0, tbu1;
do {
__asm__ __volatile__ ("mftbu %0" : "=r"(tbu0));
__asm__ __volatile__ ("mftb %0" : "=r"(tbl));
__asm__ __volatile__ ("mftbu %0" : "=r"(tbu1));
} while (tbu0 != tbu1);
return (((uint64_t)tbu0) << 32) | tbl;
}
inline double getElapsedSeconds(ticks start, ticks end)
{
return (double)((end - start) / 1e9);
}
inline ticks getCycles(ticks start, ticks end)
{
return (end - start);
}
#endif // CLOCKCYCLE_H