From d824512059eabbe9d45daeb24d1e2070ad13dd87 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 5 Dec 2023 09:03:32 +0000 Subject: [PATCH] gh-112535: Update _Py_ThreadId() to support PowerPC (gh-112624) --- Include/object.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Include/object.h b/Include/object.h index 81f777ad21f..dfeb43bda7d 100644 --- a/Include/object.h +++ b/Include/object.h @@ -261,6 +261,22 @@ _Py_ThreadId(void) __asm__ ("mrs %0, tpidrro_el0" : "=r" (tid)); #elif defined(__aarch64__) __asm__ ("mrs %0, tpidr_el0" : "=r" (tid)); +#elif defined(__powerpc64__) + #if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer) + tid = (uintptr_t)__builtin_thread_pointer(); + #else + register uintptr_t tp __asm__ ("r13"); + __asm__("" : "=r" (tp)); + tid = tp; + #endif +#elif defined(__powerpc__) + #if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer) + tid = (uintptr_t)__builtin_thread_pointer(); + #else + register uintptr_t tp __asm__ ("r2"); + __asm__ ("" : "=r" (tp)); + tid = tp; + #endif #else # error "define _Py_ThreadId for this platform" #endif