Skip to content

Commit f4acfd7

Browse files
committed
Update asm to use the new format for inline assembly.
Also adds Arm support https://github.com/rust-lang/rfcs/blob/master/text/2843-llvm-asm.md rust-lang/rfcs#2873
1 parent 7564a33 commit f4acfd7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/cpucounter.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
uint64_t cpucounter(void)
55
{
66
uint64_t low, high;
7-
__asm__ __volatile__ ("rdtscp" : "=a" (low), "=d" (high) : : "%ecx");
7+
__asm__ __volatile__("rdtscp"
8+
: "=a"(low), "=d"(high)
9+
:
10+
: "%ecx");
811
return (high << 32) | low;
912
}
1013
#elif defined(__aarch64__)
1114
uint64_t cpucounter(void)
1215
{
1316
uint64_t virtual_timer_value;
14-
__asm__ __volatile__ ("mrs %0, cntvct_el0" : "=r"(virtual_timer_value));
17+
__asm__ __volatile__("mrs %0, cntvct_el0"
18+
: "=r"(virtual_timer_value));
1519
return virtual_timer_value;
1620
}
1721
#endif

src/cpucounter.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ pub(crate) struct CPUCounter;
66
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
77
unsafe fn cpucounter() -> u64 {
88
let (low, high): (u64, u64);
9-
asm!("rdtscp" : "={eax}" (low), "={edx}" (high) : : "ecx");
9+
//asm!("rdtscp" : "={eax}" (low), "={edx}" (high) : : "ecx");
10+
asm!("rdtscp", out(eax) low, out(edx) high, out(ecx) _);
1011
(high << 32) | low
1112
}
1213

13-
14-
// https://github.com/google/benchmark/blob/v1.1.0/src/cycleclock.h#L116
1514
#[cfg(asm)]
1615
#[inline]
1716
#[cfg(any(target_arch = "aarch64"))]
1817
unsafe fn cpucounter() -> u64 {
1918
let (vtm): (u64);
20-
asm!("mrs %0, cntvct_el0" : "=r"(vtm));
19+
asm!("mrs {}, cntvct_el0", out(reg) vtm);
2120
vtm
2221
}
2322

0 commit comments

Comments
 (0)