Convert from double to uint64_t in two steps.

We want wraparound behavior here but we don't want to trigger sanitizer
warnings.  Converting to int64_t and then wraping around by cast to
uint64_t avoids the UB issue that triggers the sanitizer warning.

Change-Id: I9400b988dce7899e9ba42cab3e35c7ffedec8fe1


[ROCm/ROCR-Runtime commit: 5f43778a51]
This commit is contained in:
Sean Keely
2020-08-25 20:12:52 -05:00
parent 7f409a38c1
commit ecf5e6ca8f
@@ -1188,7 +1188,7 @@ uint64_t GpuAgent::TranslateTime(uint64_t tick) {
uint64_t system_tick = 0;
double ratio = double(t1_.SystemClockCounter - t0_.SystemClockCounter) /
double(t1_.GPUClockCounter - t0_.GPUClockCounter);
system_tick = uint64_t(ratio * double(int64_t(tick - t1_.GPUClockCounter))) + t1_.SystemClockCounter;
system_tick = uint64_t(int64_t(ratio * double(int64_t(tick - t1_.GPUClockCounter)))) + t1_.SystemClockCounter;
// tick predates HSA startup - extrapolate with fixed clock ratio
if (tick < t0_.GPUClockCounter) {