1 #include <stdint.h>
2 #include "ArchTimer.h"
3 
4 #if defined(_WIN32) && defined(_XBOX)
5 #include <xtl.h>
6 #elif defined(_WIN32)
7 #include <windows.h>
8 #endif
9 
10 #ifdef PSP
11 //#include <pspkernel.h>
12 #include <psptypes.h>
13 #include <sys/time.h>
14 #include <psprtc.h>
15 
archGetSystemUpTime(UInt32 frequency)16 UInt32 archGetSystemUpTime(UInt32 frequency)
17 {
18    u64 rtc_tick;
19    sceRtcGetCurrentTick(&rtc_tick);
20    return (rtc_tick / frequency);
21 }
22 
23 #elif defined(__PSL1GHT__)
24 
25 #include <ppu_intrinsics.h>
26 
27 
archGetSystemUpTime(UInt32 frequency)28 UInt32 archGetSystemUpTime(UInt32 frequency)
29 {
30    uint64_t rtc_tick = __mftb();
31    return (rtc_tick / frequency);
32 }
33 
34 #elif defined(__CELLOS_LV2__)
35 #include <sys/sys_time.h>
36 
37 
archGetSystemUpTime(UInt32 frequency)38 UInt32 archGetSystemUpTime(UInt32 frequency)
39 {
40    uint64_t rtc_tick;
41    asm volatile ("mftb %0" : "=r"(rtc_tick));
42    return (rtc_tick / frequency);
43 }
44 
45 #elif defined(_WIN32)
46 static LONGLONG uptime_hfFrequency = 0;
47 static signed long long uptime_offset = 0;
48 
archGetSystemUpTime(UInt32 frequency)49 UInt32 archGetSystemUpTime(UInt32 frequency)
50 {
51    LARGE_INTEGER li;
52 
53    if (!uptime_hfFrequency) {
54       if (QueryPerformanceFrequency(&li)) {
55          uptime_hfFrequency = li.QuadPart;
56       }
57       else {
58          return 0;
59       }
60    }
61 
62    QueryPerformanceCounter(&li);
63 
64    return (DWORD)((li.QuadPart + uptime_offset) * frequency / uptime_hfFrequency);
65 }
66 #else
67 
68 #include <stdlib.h>
69 #include <sys/time.h>
70 
archGetSystemUpTime(UInt32 frequency)71 UInt32 archGetSystemUpTime(UInt32 frequency)
72 {
73     struct timeval tv;
74 
75     gettimeofday(&tv, NULL);
76 
77     return tv.tv_sec * frequency + tv.tv_usec / (1000000 / frequency);
78 }
79 #endif
80 
81