<div dir="auto">Please don't locally patch Google benchmark. The changes will be reverted the next time the library is upgraded unless they're sent upstream.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat., Jul. 27, 2019, 10:13 a.m. Roger Ferrer Ibanez via libcxx-commits, <<a href="mailto:libcxx-commits@lists.llvm.org">libcxx-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rogfer01<br>
Date: Tue Jul 23 22:33:46 2019<br>
New Revision: 366868<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=366868&view=rev" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=366868&view=rev</a><br>
Log:<br>
[RISCV] Implement benchmark::cycleclock::Now<br>
<br>
This is a cherrypick of D64237 onto llvm/utils/benchmark and<br>
libcxx/utils/google-benchmark.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D65142" rel="noreferrer noreferrer" target="_blank">https://reviews.llvm.org/D65142</a><br>
<br>
Modified:<br>
    libcxx/trunk/utils/google-benchmark/README.LLVM<br>
    libcxx/trunk/utils/google-benchmark/src/cycleclock.h<br>
<br>
Modified: libcxx/trunk/utils/google-benchmark/README.LLVM<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/google-benchmark/README.LLVM?rev=366868&r1=366867&r2=366868&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/google-benchmark/README.LLVM?rev=366868&r1=366867&r2=366868&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/utils/google-benchmark/README.LLVM (original)<br>
+++ libcxx/trunk/utils/google-benchmark/README.LLVM Tue Jul 23 22:33:46 2019<br>
@@ -4,3 +4,9 @@ LLVM notes<br>
 This directory contains the Google Benchmark source code with some unnecessary<br>
 files removed. Note that this directory is under a different license than<br>
 libc++.<br>
+<br>
+Changes:<br>
+* <a href="https://github.com/google/benchmark/commit/4abdfbb802d1b514703223f5f852ce4a507d32d2" rel="noreferrer noreferrer" target="_blank">https://github.com/google/benchmark/commit/4abdfbb802d1b514703223f5f852ce4a507d32d2</a><br>
+  is applied on top of<br>
+  <a href="https://github.com/google/benchmark/commit/4528c76b718acc9b57956f63069c699ae21edcab" rel="noreferrer noreferrer" target="_blank">https://github.com/google/benchmark/commit/4528c76b718acc9b57956f63069c699ae21edcab</a><br>
+  to add RISC-V timer support.<br>
<br>
Modified: libcxx/trunk/utils/google-benchmark/src/cycleclock.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/google-benchmark/src/cycleclock.h?rev=366868&r1=366867&r2=366868&view=diff" rel="noreferrer noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/google-benchmark/src/cycleclock.h?rev=366868&r1=366867&r2=366868&view=diff</a><br>
==============================================================================<br>
--- libcxx/trunk/utils/google-benchmark/src/cycleclock.h (original)<br>
+++ libcxx/trunk/utils/google-benchmark/src/cycleclock.h Tue Jul 23 22:33:46 2019<br>
@@ -164,6 +164,21 @@ inline BENCHMARK_ALWAYS_INLINE int64_t N<br>
   uint64_t tsc;<br>
   asm("stck %0" : "=Q"(tsc) : : "cc");<br>
   return tsc;<br>
+#elif defined(__riscv) // RISC-V<br>
+  // Use RDCYCLE (and RDCYCLEH on riscv32)<br>
+#if __riscv_xlen == 32<br>
+  uint64_t cycles_low, cycles_hi0, cycles_hi1;<br>
+  asm("rdcycleh %0" : "=r"(cycles_hi0));<br>
+  asm("rdcycle %0" : "=r"(cycles_lo));<br>
+  asm("rdcycleh %0" : "=r"(cycles_hi1));<br>
+  // This matches the PowerPC overflow detection, above<br>
+  cycles_lo &= -static_cast<int64_t>(cycles_hi0 == cycles_hi1);<br>
+  return (cycles_hi1 << 32) | cycles_lo;<br>
+#else<br>
+  uint64_t cycles;<br>
+  asm("rdcycle %0" : "=r"(cycles));<br>
+  return cycles;<br>
+#endif<br>
 #else<br>
 // The soft failover to a generic implementation is automatic only for ARM.<br>
 // For other platforms the developer is expected to make an attempt to create<br>
<br>
<br>
_______________________________________________<br>
libcxx-commits mailing list<br>
<a href="mailto:libcxx-commits@lists.llvm.org" target="_blank" rel="noreferrer">libcxx-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/libcxx-commits</a><br>
</blockquote></div>