summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYi Luo <luoyi@google.com>2016-04-21 15:59:05 -0700
committerYi Luo <luoyi@google.com>2016-04-22 09:34:35 -0700
commitb547a2f38cfab81f6cbe392b9eb48ab0c12b80cf (patch)
treeb5a05fed347a6ad885daf4dc3241d4b11582e68e
parentb816eea5ef619edcef92e8723139e7414d2cf0ba (diff)
downloadlibvpx-b547a2f38cfab81f6cbe392b9eb48ab0c12b80cf.tar
libvpx-b547a2f38cfab81f6cbe392b9eb48ab0c12b80cf.tar.gz
libvpx-b547a2f38cfab81f6cbe392b9eb48ab0c12b80cf.tar.bz2
libvpx-b547a2f38cfab81f6cbe392b9eb48ab0c12b80cf.zip
Add the 64-bit CPU cycle count utility function
Change-Id: Ie87245bbdf5735bc9729199eeb07899d81dbf267
-rw-r--r--vpx_ports/x86.h25
1 files changed, 24 insertions, 1 deletions
diff --git a/vpx_ports/x86.h b/vpx_ports/x86.h
index 5da346e58..e3ebc5320 100644
--- a/vpx_ports/x86.h
+++ b/vpx_ports/x86.h
@@ -216,6 +216,11 @@ x86_simd_caps(void) {
unsigned __int64 __rdtsc(void);
#pragma intrinsic(__rdtsc)
#endif
+// Note:
+// 32-bit CPU cycle counter is light-weighted for most function performance
+// measurement. For large function (CPU time > a couple of seconds), 64-bit
+// counter should be used.
+// 32-bit CPU cycle counter
static INLINE unsigned int
x86_readtsc(void) {
#if defined(__GNUC__) && __GNUC__
@@ -234,7 +239,25 @@ x86_readtsc(void) {
#endif
#endif
}
-
+// 64-bit CPU cycle counter
+static INLINE uint64_t
+x86_readtsc64(void) {
+#if defined(__GNUC__) && __GNUC__
+ uint32_t hi, lo;
+ __asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
+ return ((uint64_t)hi << 32) | lo;
+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+ uint_t hi, lo;
+ asm volatile("rdtsc\n\t" : "=a"(lo), "=d"(hi));
+ return ((uint64_t)hi << 32) | lo;
+#else
+#if ARCH_X86_64
+ return (uint64_t)__rdtsc();
+#else
+ __asm rdtsc;
+#endif
+#endif
+}
#if defined(__GNUC__) && __GNUC__
#define x86_pause_hint()\