-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update inline assembly to support new syntax (#2)
* Update inline assembly for x86 to support new syntax https://github.com/rust-lang/rfcs/blob/master/text/2843-llvm-asm.md rust-lang/rfcs#2873 * Add support for Arm
- Loading branch information
Showing
2 changed files
with
25 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
#include <stdint.h> | ||
|
||
#if defined(__x86_64__) || defined(__amd64__) | ||
uint64_t cpucounter(void) | ||
{ | ||
uint64_t low, high; | ||
__asm__ __volatile__ ("rdtscp" : "=a" (low), "=d" (high) : : "%ecx"); | ||
__asm__ __volatile__("rdtscp" | ||
: "=a"(low), "=d"(high) | ||
: | ||
: "%ecx"); | ||
return (high << 32) | low; | ||
} | ||
#elif defined(__aarch64__) | ||
uint64_t cpucounter(void) | ||
{ | ||
uint64_t virtual_timer_value; | ||
__asm__ __volatile__("mrs %0, cntvct_el0" | ||
: "=r"(virtual_timer_value)); | ||
return virtual_timer_value; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters