Skip to content

Commit 00bd6ed

Browse files
committed
[test-suite] Fix RISC-V Support in benchmark 1.3.0
Summary: Fixed by backporting the upstream fix from here: google/benchmark#833 Reviewers: lebedev.ri Reviewed By: lebedev.ri Subscribers: asb, kito-cheng, shiva0217, rogfer01, rkruppe, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64237 llvm-svn: 365610
1 parent 6389144 commit 00bd6ed

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
LLVM notes
2+
----------
3+
This directory contains the Google Benchmark source code. Currently, the checked out
4+
Benchmark library version is v1.3.0.
5+
6+
This directory is under a different license than LLVM.
7+
8+
Changes:
9+
* https://github.com/google/benchmark/commit/ff2c255af5bb2fc2e5cd3b3685f0c6283117ce73
10+
is applied on top of v1.3.0 to add s390x Support.
11+
* https://github.com/google/benchmark/commit/aad6a5fa767529d3353bd3beb89e126c7b0868ca
12+
is applied on top of v1.3.0 to add NetBSD Support.
13+
* https://github.com/google/benchmark/commit/4abdfbb802d1b514703223f5f852ce4a507d32d2
14+
is applied on top of v1.3.0 to add RISC-V timer support.

MicroBenchmarks/libs/benchmark-1.3.0/src/cycleclock.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,21 @@ inline BENCHMARK_ALWAYS_INLINE int64_t Now() {
164164
uint64_t tsc;
165165
asm("stck %0" : "=Q" (tsc) : : "cc");
166166
return tsc;
167+
#elif defined(__riscv) // RISC-V
168+
// Use RDCYCLE (and RDCYCLEH on riscv32)
169+
#if __riscv_xlen == 32
170+
uint64_t cycles_low, cycles_hi0, cycles_hi1;
171+
asm("rdcycleh %0" : "=r"(cycles_hi0));
172+
asm("rdcycle %0" : "=r"(cycles_lo));
173+
asm("rdcycleh %0" : "=r"(cycles_hi1));
174+
// This matches the PowerPC overflow detection, above
175+
cycles_lo &= -static_cast<int64_t>(cycles_hi0 == cycles_hi1);
176+
return (cycles_hi1 << 32) | cycles_lo;
177+
#else
178+
uint64_t cycles;
179+
asm("rdcycle %0" : "=r"(cycles));
180+
return cycles;
181+
#endif
167182
#else
168183
// The soft failover to a generic implementation is automatic only for ARM.
169184
// For other platforms the developer is expected to make an attempt to create

0 commit comments

Comments
 (0)