xref: /haiku/src/system/libroot/os/arch/x86_64/system_time.cpp (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2  * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <stdint.h>
8 
9 //#include <x86intrin.h>
10 #define _X86INTRIN_H_INCLUDED
11 #include <ia32intrin.h>
12 
13 
14 
15 static uint64_t cv_factor;
16 static uint64_t cv_factor_nsec;
17 
18 
19 extern "C" void
20 __x86_setup_system_time(uint64_t cv, uint64_t cv_nsec)
21 {
22 	cv_factor = cv;
23 	cv_factor_nsec = cv_nsec;
24 }
25 
26 
27 extern "C" [[gnu::optimize("omit-frame-pointer")]] int64_t
28 system_time()
29 {
30 	__uint128_t time = static_cast<__uint128_t>(__rdtsc()) * cv_factor;
31 	return time >> 64;
32 }
33 
34 
35 extern "C" [[gnu::optimize("omit-frame-pointer")]] int64_t
36 system_time_nsecs()
37 {
38 	__uint128_t t = static_cast<__uint128_t>(__rdtsc()) * cv_factor_nsec;
39 	return t >> 32;
40 }
41 
42