Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Unified Diff: base/time/time_win.cc

Issue 429743002: Make QPCValueToMicroseconds faster in case the value is less than 44 bits (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time_win.cc
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index cf7be687d2e5a0b292414796f1b3c25e2535f518..330ee3d68401d2abf42cb283596a0102a0b88cb1 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -391,17 +391,21 @@ class HighResNowSingleton {
}
int64 QPCValueToMicroseconds(LONGLONG qpc_value) {
- if (!ticks_per_second_)
brianderson 2014/07/29 23:53:29 I remember you had an explanation for why this cou
fmeawad 2014/07/30 00:49:49 I added that check in the CPUReliablySupportsHighR
brianderson 2014/07/30 00:58:19 Thanks for the explanation. I was thinking about
- return 0;
-
- // Intentionally calculate microseconds in a round about manner to avoid
- // overflow and precision issues. Think twice before simplifying!
- int64 whole_seconds = qpc_value / ticks_per_second_;
- int64 leftover_ticks = qpc_value % ticks_per_second_;
- int64 microseconds = (whole_seconds * Time::kMicrosecondsPerSecond) +
- ((leftover_ticks * Time::kMicrosecondsPerSecond) /
- ticks_per_second_);
- return microseconds;
+ // Time::kMicrosecondsPerSecond has 20 bits, to avoid overflow we do a
+ // simple multiplication then division if the qpc_value has less than 44
+ // bits.
+ if (qpc_value & 0xFFFFF00000000000)
jar (doing other things) 2014/07/30 23:43:09 Please unit test at exactly above and below this b
jar (doing other things) 2014/07/31 00:01:43 I think the largest positive 64 bit number is 2^63
fmeawad 2014/07/31 18:54:21 Done.
fmeawad 2014/07/31 18:54:21 Done.
+ {
+ // Intentionally calculate microseconds in a round about manner to avoid
+ // overflow and precision issues. Think twice before simplifying!
+ int64 whole_seconds = qpc_value / ticks_per_second_;
+ int64 leftover_ticks = qpc_value % ticks_per_second_;
+ int64 microseconds = (whole_seconds * Time::kMicrosecondsPerSecond) +
+ ((leftover_ticks * Time::kMicrosecondsPerSecond) /
+ ticks_per_second_);
+ return microseconds;
+ }
+ return qpc_value * Time::kMicrosecondsPerSecond / ticks_per_second_;
brianderson 2014/07/29 23:53:29 Would a single double-precision multiplication be
fmeawad 2014/07/30 00:49:49 I made a quick experiment, and I have found no win
brianderson 2014/07/30 00:58:19 Thanks for testing that.
}
private:
@@ -447,7 +451,8 @@ NowFunction now_function = RolloverProtectedNow;
bool CPUReliablySupportsHighResTime() {
base::CPU cpu;
- if (!cpu.has_non_stop_time_stamp_counter())
+ if (!cpu.has_non_stop_time_stamp_counter() ||
+ !GetHighResNowSingleton()->IsUsingHighResClock())
return false;
if (IsBuggyAthlon(cpu))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698