Fix reading CPU id using rdtscp.

As pointed out in #2527, the correct register containing CPU id should be ecx
instead edx.
This commit is contained in:
Qi Wang 2023-08-28 10:21:11 -07:00 committed by Qi Wang
parent 87c56c8df8
commit b71da25b8a

View File

@ -19,9 +19,9 @@ malloc_getcpu(void) {
#elif defined(JEMALLOC_HAVE_SCHED_GETCPU) #elif defined(JEMALLOC_HAVE_SCHED_GETCPU)
return (malloc_cpuid_t)sched_getcpu(); return (malloc_cpuid_t)sched_getcpu();
#elif defined(JEMALLOC_HAVE_RDTSCP) #elif defined(JEMALLOC_HAVE_RDTSCP)
unsigned int ax, cx, dx; unsigned int ecx;
asm volatile("rdtscp" : "=a"(ax), "=d"(dx), "=c"(cx) ::); asm volatile("rdtscp" : "=c" (ecx) :: "eax", "edx");
return (malloc_cpuid_t)(dx & 0xfff); return (malloc_cpuid_t)(ecx & 0xfff);
#elif defined(__aarch64__) && defined(__APPLE__) #elif defined(__aarch64__) && defined(__APPLE__)
/* Other oses most likely use tpidr_el0 instead */ /* Other oses most likely use tpidr_el0 instead */
uintptr_t c; uintptr_t c;