Skip to content

Commit 2f94d4c

Browse files
committed
Avoid using ebx as an asm! operand
failes compilation as it is sometimes reserved by LLVM.
1 parent 8b8ccfb commit 2f94d4c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

measureme/src/counters.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,20 @@ mod hw {
543543
asm!(
544544
// Dummy `cpuid(0)` to serialize instruction execution.
545545
"xor eax, eax",
546+
// LLVM sometimes reserves `ebx` for its internal use, we so we need to use
547+
// a scratch register for it instead.
548+
"mov {tmp_rbx}, rbx",
546549
"cpuid",
550+
"mov rbx, {tmp_rbx}",
547551

548552
"mov ecx, {rdpmc_ecx:e}",
549553
"rdpmc",
550554
rdpmc_ecx = in(reg) reg_idx,
555+
tmp_rbx = out(reg) _,
551556
out("eax") lo,
552557
out("edx") hi,
553558

554559
// `cpuid` clobbers (not overwritten by `rdpmc`).
555-
out("ebx") _,
556560
out("ecx") _,
557561

558562
options(nostack),
@@ -574,7 +578,11 @@ mod hw {
574578
asm!(
575579
// Dummy `cpuid(0)` to serialize instruction execution.
576580
"xor eax, eax",
581+
// LLVM sometimes reserves `ebx` for its internal use, we so we need to use
582+
// a scratch register for it instead.
583+
"mov {tmp_rbx}, rbx",
577584
"cpuid",
585+
"mov rbx, {tmp_rbx}",
578586

579587
"mov ecx, {a_rdpmc_ecx:e}",
580588
"rdpmc",
@@ -586,11 +594,11 @@ mod hw {
586594
a_rdpmc_eax = out(reg) a_lo,
587595
a_rdpmc_edx = out(reg) a_hi,
588596
b_rdpmc_ecx = in(reg) b_reg_idx,
597+
tmp_rbx = out(reg) _,
589598
out("eax") b_lo,
590599
out("edx") b_hi,
591600

592601
// `cpuid` clobbers (not overwritten by `rdpmc`).
593-
out("ebx") _,
594602
out("ecx") _,
595603

596604
options(nostack),

0 commit comments

Comments
 (0)