Skip to content

Commit

Permalink
fix: compatible with lower clang version (#2252)
Browse files Browse the repository at this point in the history
Summary:
* At least the Clang 11.0.0 can support "asm volatile inline", the lower version (e.g. 9.0.1) can only support "asm volatile".

Pull Request resolved: #2252

Reviewed By: yfeldblum

Differential Revision: D59772068

Pulled By: Orvid

fbshipit-source-id: cfba03e79aa3dc3437564772608971bceb3b8d83
  • Loading branch information
YouSenRong authored and facebook-github-bot committed Jul 30, 2024
1 parent fe6cca8 commit a6f991a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions folly/chrono/Hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ inline std::uint64_t hardware_timestamp_measurement_start() noexcept {
return ret;
#elif defined(__GNUC__) && FOLLY_X64
uint64_t ret = 0;
#if !defined(__clang_major__) || __clang_major__ >= 11
asm volatile inline(
#else
asm volatile(
#endif
"lfence\n"
"rdtsc\n" // loads 64-bit tsc into edx:eax
"shl $32, %%rdx\n" // prep rdx for combine into rax
Expand Down Expand Up @@ -124,7 +128,11 @@ inline std::uint64_t hardware_timestamp_measurement_stop() noexcept {
return ret;
#elif defined(__GNUC__) && FOLLY_X64
uint64_t ret = 0;
#if !defined(__clang_major__) || __clang_major__ >= 11
asm volatile inline(
#else
asm volatile(
#endif
"rdtscp\n" // loads 64-bit tsc into edx:eax, clobbers ecx
"shl $32, %%rdx\n" // prep rdx for combine into rax
"or %%rdx, %[ret]\n" // combine rdx into rax
Expand Down

0 comments on commit a6f991a

Please sign in to comment.