Skip to content

Commit

Permalink
Avoid using ebx as an asm! operand
Browse files Browse the repository at this point in the history
failes compilation as it is sometimes reserved by LLVM.
  • Loading branch information
andjo403 committed Oct 3, 2021
1 parent 8b8ccfb commit 326c6a4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions measureme/src/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,16 +543,20 @@ mod hw {
asm!(
// Dummy `cpuid(0)` to serialize instruction execution.
"xor eax, eax",
// LLVM sometimes reserves `ebx` for its internal use, we so we need to use
// a scratch register for it instead.
"mov {tmp_rbx:r}, rbx",
"cpuid",
"mov rbx, {tmp_rbx:r}",

"mov ecx, {rdpmc_ecx:e}",
"rdpmc",
rdpmc_ecx = in(reg) reg_idx,
tmp_rbx = out(reg) _,
out("eax") lo,
out("edx") hi,

// `cpuid` clobbers (not overwritten by `rdpmc`).
out("ebx") _,
out("ecx") _,

options(nostack),
Expand All @@ -574,7 +578,11 @@ mod hw {
asm!(
// Dummy `cpuid(0)` to serialize instruction execution.
"xor eax, eax",
// LLVM sometimes reserves `ebx` for its internal use, we so we need to use
// a scratch register for it instead.
"mov {tmp_rbx:r}, rbx",
"cpuid",
"mov rbx, {tmp_rbx:r}",

"mov ecx, {a_rdpmc_ecx:e}",
"rdpmc",
Expand All @@ -586,11 +594,11 @@ mod hw {
a_rdpmc_eax = out(reg) a_lo,
a_rdpmc_edx = out(reg) a_hi,
b_rdpmc_ecx = in(reg) b_reg_idx,
tmp_rbx = out(reg) _,
out("eax") b_lo,
out("edx") b_hi,

// `cpuid` clobbers (not overwritten by `rdpmc`).
out("ebx") _,
out("ecx") _,

options(nostack),
Expand Down

0 comments on commit 326c6a4

Please sign in to comment.