Skip to content

Commit 7be9ea4

Browse files
committed
xrCore: refactor counters
1 parent 07e806b commit 7be9ea4

File tree

2 files changed

+16
-44
lines changed

2 files changed

+16
-44
lines changed

src/xrCore/_math.cpp

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,10 @@ XRCORE_API Dmatrix Didentity;
4343
XRCORE_API CRandom Random;
4444

4545
#if defined(LINUX)
46-
#define nsec_per_sec 1000*1000*1000
47-
/**
48-
* From https://stackoverflow.com/questions/12468331/queryperformancecounter-linux-equivalent
49-
* @return
50-
*/
51-
void QueryPerformanceCounter(PLARGE_INTEGER result)
52-
{
53-
u64 nsec_count, nsec_per_tick;
54-
/*
55-
* clock_gettime() returns the number of secs. We translate that to number of nanosecs.
56-
* clock_getres() returns number of seconds per tick. We translate that to number of nanosecs per tick.
57-
* Number of nanosecs divided by number of nanosecs per tick - will give the number of ticks.
58-
*/
59-
struct timespec ts1, ts2;
60-
61-
if (clock_gettime(CLOCK_MONOTONIC, &ts1) != 0) {
62-
return;
63-
}
64-
65-
nsec_count = ts1.tv_nsec + ts1.tv_sec * nsec_per_sec;
66-
67-
if (clock_getres(CLOCK_MONOTONIC, &ts2) != 0) {
68-
return;
69-
}
70-
71-
nsec_per_tick = ts2.tv_nsec + ts2.tv_sec * nsec_per_sec;
72-
73-
*result = (nsec_count / nsec_per_tick);
74-
}
75-
7646
DWORD timeGetTime()
7747
{
78-
/* std::chrono::time_point<std::chrono::high_resolution_clock> now = std::chrono::high_resolution_clock::now();
79-
80-
auto nanosec = now.time_since_epoch();
81-
82-
return nanosec.count()/(1000000000.0 *60.0 *60.0);
83-
*/
8448
return SDL_GetTicks();
8549
}
86-
8750
#endif
8851

8952
/*
@@ -220,8 +183,7 @@ XRCORE_API processor_info ID;
220183

221184
XRCORE_API u64 QPC() noexcept
222185
{
223-
u64 _dest;
224-
QueryPerformanceCounter((PLARGE_INTEGER)&_dest);
186+
u64 _dest = SDL_GetPerformanceCounter();
225187
qpc_counter++;
226188
return _dest;
227189
}
@@ -269,9 +231,10 @@ void _initialize_cpu()
269231
Msg("* CPU%zu current freq: %lu MHz, max freq: %lu MHz",
270232
i, cpuInfo.CurrentMhz, cpuInfo.MaxMhz);
271233
}
272-
273-
Log("");
234+
#else
235+
Msg("* CPU current freq: %lu MHz", CPU::qpc_freq);
274236
#endif
237+
Log("");
275238
Fidentity.identity(); // Identity matrix
276239
Didentity.identity(); // Identity matrix
277240
pvInitializeStatics(); // Lookup table for compressed normals
@@ -306,9 +269,9 @@ void _initialize_cpu_thread()
306269
{
307270
//_mm_setcsr ( _mm_getcsr() | (_MM_FLUSH_ZERO_ON+_MM_DENORMALS_ZERO_ON) );
308271
_MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
309-
#if defined(WINDOWS)
310272
if (_denormals_are_zero_supported)
311273
{
274+
#if defined(WINDOWS)
312275
__try
313276
{
314277
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
@@ -317,8 +280,18 @@ void _initialize_cpu_thread()
317280
{
318281
_denormals_are_zero_supported = FALSE;
319282
}
320-
}
283+
#else
284+
try
285+
{
286+
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
287+
}
288+
catch (...)
289+
{
290+
_denormals_are_zero_supported = FALSE;
291+
}
321292
#endif
293+
}
294+
322295
}
323296
}
324297

src/xrCore/_math.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ extern XRCORE_API void thread_name(const char* name);
3333
extern XRCORE_API void thread_spawn(thread_t* entry, const char* name, unsigned stack, void* arglist);
3434

3535
#if defined(LINUX)
36-
void QueryPerformanceCounter(PLARGE_INTEGER result);
3736
XRCORE_API DWORD timeGetTime();
3837
#endif

0 commit comments

Comments
 (0)