From b71da25b8a12c2c3f0c10b0811d15a61980186e8 Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Mon, 28 Aug 2023 10:21:11 -0700 Subject: [PATCH] Fix reading CPU id using rdtscp. As pointed out in #2527, the correct register containing CPU id should be ecx instead edx. --- include/jemalloc/internal/jemalloc_internal_inlines_a.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/jemalloc/internal/jemalloc_internal_inlines_a.h b/include/jemalloc/internal/jemalloc_internal_inlines_a.h index 8d5e22fd..111cda42 100644 --- a/include/jemalloc/internal/jemalloc_internal_inlines_a.h +++ b/include/jemalloc/internal/jemalloc_internal_inlines_a.h @@ -19,9 +19,9 @@ malloc_getcpu(void) { #elif defined(JEMALLOC_HAVE_SCHED_GETCPU) return (malloc_cpuid_t)sched_getcpu(); #elif defined(JEMALLOC_HAVE_RDTSCP) - unsigned int ax, cx, dx; - asm volatile("rdtscp" : "=a"(ax), "=d"(dx), "=c"(cx) ::); - return (malloc_cpuid_t)(dx & 0xfff); + unsigned int ecx; + asm volatile("rdtscp" : "=c" (ecx) :: "eax", "edx"); + return (malloc_cpuid_t)(ecx & 0xfff); #elif defined(__aarch64__) && defined(__APPLE__) /* Other oses most likely use tpidr_el0 instead */ uintptr_t c;