[PATCH] nptl: hppa: replace __get_cr27 with __thread_pointer

Michael Jeanson mjeanson@efficios.com
Sun Dec 22 20:51:19 GMT 2024


The addition of the new thread_pointer.h header on HPPA resulted in
duplicated inline asm to get the current thread pointer from the cr27
register.

Include thread_pointer.h in tls.h and replace __get/set_cr27() with
__set_/thread_pointer() with the appropriate casts.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
---
Cc: John David Anglin <danglin@gcc.gnu.org>
---
 sysdeps/hppa/nptl/thread_pointer.h | 10 ++++++++++
 sysdeps/hppa/nptl/tls.h            | 26 ++++++--------------------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/sysdeps/hppa/nptl/thread_pointer.h b/sysdeps/hppa/nptl/thread_pointer.h
index 96f5e9b4c0..acd6fa5901 100644
--- a/sysdeps/hppa/nptl/thread_pointer.h
+++ b/sysdeps/hppa/nptl/thread_pointer.h
@@ -27,4 +27,14 @@ __thread_pointer (void)
   return __thread_register;
 }
 
+/* We write to cr27, clobber r26 as the input argument, and clobber
+   r31 as the link register.  */
+static inline void
+__set_thread_pointer(void *__thread_pointer)
+{
+  asm ( "ble	0xe0(%%sr2, %%r0)\n\t"
+	"copy	%0, %%r26"
+	: : "r" (__thread_pointer) : "r26", "r31" );
+}
+
 #endif /* _SYS_THREAD_POINTER_H */
diff --git a/sysdeps/hppa/nptl/tls.h b/sysdeps/hppa/nptl/tls.h
index 82055fa8a3..c97bdbcff1 100644
--- a/sysdeps/hppa/nptl/tls.h
+++ b/sysdeps/hppa/nptl/tls.h
@@ -40,6 +40,8 @@
 /* Get the thread descriptor definition.  */
 # include <nptl/descr.h>
 
+# include <thread_pointer.h>
+
 typedef struct
 {
   dtv_t *dtv;
@@ -62,7 +64,7 @@ typedef struct
 
 /* Install new dtv for current thread.  */
 # define INSTALL_NEW_DTV(dtv) \
-  ({ tcbhead_t *__tcbp = (tcbhead_t *)__get_cr27();	\
+  ({ tcbhead_t *__tcbp = (tcbhead_t *)__thread_pointer();	\
 	__tcbp->dtv = dtv;				\
    })
 
@@ -74,21 +76,21 @@ typedef struct
    special attention since 'errno' is not yet available and if the
    operation can cause a failure 'errno' must not be touched.  */
 # define TLS_INIT_TP(tcbp) \
-  ({ __set_cr27(tcbp); true; })
+  ({ __set_thread_pointer((void *) tcbp); true; })
 
 /* Value passed to 'clone' for initialization of the thread register.  */
 # define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1
 
 /* Return the address of the dtv for the current thread.  */
 # define THREAD_DTV() \
-  ({ tcbhead_t *__tcbp = (tcbhead_t *)__get_cr27();	\
+  ({ tcbhead_t *__tcbp = (tcbhead_t *)__thread_pointer();	\
 	__tcbp->dtv;					\
    })
 
 /* Return the thread descriptor for the current thread.  */
 # define THREAD_SELF \
   ({ struct pthread *__self;			\
-	__self = __get_cr27();			\
+	__self = (struct pthread *)__thread_pointer();	\
 	__self - 1;				\
    })
 
@@ -100,22 +102,6 @@ typedef struct
 
 # include <tcb-access.h>
 
-static inline struct pthread *__get_cr27(void)
-{
-  long cr27;
-  asm ("mfctl %%cr27, %0" : "=r" (cr27) : );
-  return (struct pthread *) cr27;
-}
-
-/* We write to cr27, clobber r26 as the input argument, and clobber
-   r31 as the link register.  */
-static inline void __set_cr27(struct pthread *cr27)
-{
-  asm ( "ble	0xe0(%%sr2, %%r0)\n\t"
-	"copy	%0, %%r26"
-	: : "r" (cr27) : "r26", "r31" );
-}
-
 /* Get and set the global scope generation counter in struct pthread.  */
 #define THREAD_GSCOPE_FLAG_UNUSED 0
 #define THREAD_GSCOPE_FLAG_USED   1
-- 
2.39.5



More information about the Libc-alpha mailing list