]> granicus.if.org Git - llvm/commitdiff
[RISCV] Implement benchmark::cycleclock::Now
authorRoger Ferrer Ibanez <rofirrim@gmail.com>
Wed, 24 Jul 2019 05:33:46 +0000 (05:33 +0000)
committerRoger Ferrer Ibanez <rofirrim@gmail.com>
Wed, 24 Jul 2019 05:33:46 +0000 (05:33 +0000)
This is a cherrypick of D64237 onto llvm/utils/benchmark and
libcxx/utils/google-benchmark.

Differential Revision: https://reviews.llvm.org/D65142

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366868 91177308-0d34-0410-b5e6-96231b3b80d8

utils/benchmark/README.LLVM
utils/benchmark/src/cycleclock.h

index c493ff4f5c641c86f6a3c632f635f0e2dc62222b..d2aa87e86e796f0b9af10cf62af7d076e705af77 100644 (file)
@@ -23,3 +23,5 @@ Changes:
   is applied to disable exceptions in Microsoft STL when exceptions are disabled
 * Disabled CMake get_git_version as it is meaningless for this in-tree build,
   and hardcoded a null version
+* https://github.com/google/benchmark/commit/4abdfbb802d1b514703223f5f852ce4a507d32d2
+  is applied on top of v1.4.1 to add RISC-V timer support.
index e1f18cc64d20222237b5595d90c1fbe56bab95a9..7b54b2530378b495012ded8023fd38cce912d2ad 100644 (file)
@@ -164,6 +164,21 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
   uint64_t tsc;
   asm("stck %0" : "=Q" (tsc) : : "cc");
   return tsc;
+#elif defined(__riscv) // RISC-V
+  // Use RDCYCLE (and RDCYCLEH on riscv32)
+#if __riscv_xlen == 32
+  uint64_t cycles_low, cycles_hi0, cycles_hi1;
+  asm("rdcycleh %0" : "=r"(cycles_hi0));
+  asm("rdcycle %0" : "=r"(cycles_lo));
+  asm("rdcycleh %0" : "=r"(cycles_hi1));
+  // This matches the PowerPC overflow detection, above
+  cycles_lo &= -static_cast<int64_t>(cycles_hi0 == cycles_hi1);
+  return (cycles_hi1 << 32) | cycles_lo;
+#else
+  uint64_t cycles;
+  asm("rdcycle %0" : "=r"(cycles));
+  return cycles;
+#endif
 #else
 // The soft failover to a generic implementation is automatic only for ARM.
 // For other platforms the developer is expected to make an attempt to create