Skip to content

Commit

Permalink
fix: build on risc-v (#9215)
Browse files Browse the repository at this point in the history
Summary:
Patch is modified from ~~https://reviews.llvm.org/file/data/du5ol5zctyqw53ma7dwz/PHID-FILE-knherxziu4tl4erti5ab/file~~

Tested on Arch Linux riscv64gc (qemu)

UPDATE: Seems like the above link is broken, so I tried to search for a link pointing to the original merge request. It turned out to me that the LLVM guys are cherry-picking from `google/benchmark`, and the upstream should be this:

https://github.com/google/benchmark/blob/808571a52fd6cc7e9f0788e08f71f0f4175b6673/src/cycleclock.h#L190

Pull Request resolved: #9215

Reviewed By: siying, jay-zhuang

Differential Revision: D34170586

Pulled By: riversand963

fbshipit-source-id: 41b16b9f7f3bb0f3e7b26bb078eb575499c0f0f4
  • Loading branch information
XieJiSS authored and facebook-github-bot committed May 18, 2022
1 parent 3573558 commit 8b1df10
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,23 @@ static inline tokutime_t toku_time_now(void) {
uint64_t result;
asm volatile("stckf %0" : "=Q"(result) : : "cc");
return result;
#elif defined(__riscv) && __riscv_xlen == 32
uint32_t cycles_lo, cycles_hi0, cycles_hi1;
// Implemented in assembly because Clang insisted on branching.
asm volatile(
"rdcycleh %0\n"
"rdcycle %1\n"
"rdcycleh %2\n"
"sub %0, %0, %2\n"
"seqz %0, %0\n"
"sub %0, zero, %0\n"
"and %1, %1, %0\n"
: "=r"(cycles_hi0), "=r"(cycles_lo), "=r"(cycles_hi1));
return (static_cast<uint64_t>(cycles_hi1) << 32) | cycles_lo;
#elif defined(__riscv) && __riscv_xlen == 64
uint64_t cycles;
asm volatile("rdcycle %0" : "=r"(cycles));
return cycles;
#else
#error No timer implementation for this platform
#endif
Expand Down

0 comments on commit 8b1df10

Please sign in to comment.