From 4cfec3e47bed1254f7b1a32b294c8d547b2b8639 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 5 Dec 2023 20:25:30 +0900 Subject: [PATCH 1/5] gh-112535: Update _Py_ThreadId() to support s390/s390x --- Include/object.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Include/object.h b/Include/object.h index 85abd30b5ad7d6..f663eb02b81354 100644 --- a/Include/object.h +++ b/Include/object.h @@ -279,6 +279,13 @@ _Py_ThreadId(void) __asm__ ("" : "=r" (tp)); tid = tp; #endif +#elif defined(__s390__) + #if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer) + tid = (uintptr_t)__builtin_thread_pointer(); + #else + // s390/s390x: Access register 0 is used as thread pointer. + __asm__ ("ear %0,%%a0" : "=d"(tid)); + #endif #else # error "define _Py_ThreadId for this platform" #endif From b296c646172388adcce3fae5518ff9652e83d335 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 5 Dec 2023 20:34:06 +0900 Subject: [PATCH 2/5] Update Include/object.h Co-authored-by: Victor Stinner --- Include/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/object.h b/Include/object.h index f663eb02b81354..1b99e7bccbed2b 100644 --- a/Include/object.h +++ b/Include/object.h @@ -283,7 +283,7 @@ _Py_ThreadId(void) #if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer) tid = (uintptr_t)__builtin_thread_pointer(); #else - // s390/s390x: Access register 0 is used as thread pointer. + // Access register 0 is used as the thread pointer. __asm__ ("ear %0,%%a0" : "=d"(tid)); #endif #else From 30dd74ef0fed2af7e5002c75d540c600b4626a64 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 6 Dec 2023 00:46:05 +0900 Subject: [PATCH 3/5] Address code review --- Include/object.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Include/object.h b/Include/object.h index 1b99e7bccbed2b..510494af56deb7 100644 --- a/Include/object.h +++ b/Include/object.h @@ -279,13 +279,9 @@ _Py_ThreadId(void) __asm__ ("" : "=r" (tp)); tid = tp; #endif -#elif defined(__s390__) - #if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer) +#elif defined(__s390__) && _Py__has_builtin(__builtin_thread_pointer) + // Both GCC and Clang have supported __builtin_thread_pointer for s390 tid = (uintptr_t)__builtin_thread_pointer(); - #else - // Access register 0 is used as the thread pointer. - __asm__ ("ear %0,%%a0" : "=d"(tid)); - #endif #else # error "define _Py_ThreadId for this platform" #endif From b932f6bb8188f4477aa3edd6156747699a7a9d1b Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 6 Dec 2023 00:47:48 +0900 Subject: [PATCH 4/5] nit --- Include/object.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Include/object.h b/Include/object.h index 510494af56deb7..2746cf87788abc 100644 --- a/Include/object.h +++ b/Include/object.h @@ -280,7 +280,8 @@ _Py_ThreadId(void) tid = tp; #endif #elif defined(__s390__) && _Py__has_builtin(__builtin_thread_pointer) - // Both GCC and Clang have supported __builtin_thread_pointer for s390 + // Both GCC and Clang have supported __builtin_thread_pointer + // for s390 from long time ago. tid = (uintptr_t)__builtin_thread_pointer(); #else # error "define _Py_ThreadId for this platform" From 13e5a4bfb4cf00ecc63c48a3f5742ac087aeda07 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 6 Dec 2023 00:51:54 +0900 Subject: [PATCH 5/5] Address code review --- Include/object.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/object.h b/Include/object.h index 2746cf87788abc..bd576b0bd43211 100644 --- a/Include/object.h +++ b/Include/object.h @@ -279,7 +279,7 @@ _Py_ThreadId(void) __asm__ ("" : "=r" (tp)); tid = tp; #endif -#elif defined(__s390__) && _Py__has_builtin(__builtin_thread_pointer) +#elif defined(__s390__) && defined(__GNUC__) // Both GCC and Clang have supported __builtin_thread_pointer // for s390 from long time ago. tid = (uintptr_t)__builtin_thread_pointer();