diff mbox series

[RFC,31/34] hurd: Microoptimize _hurd_self_sigstate ()

Message ID 20230319151017.531737-32-bugaevc@gmail.com
State New
Headers show
Series The rest of the x86_64-gnu port | expand

Commit Message

Sergey Bugaev March 19, 2023, 3:10 p.m. UTC
When THREAD_GETMEM is defined with inline assembly, the compiler may not
optimize away the two reads of _hurd_sigstate. Help it out a little bit
by only reading it once. This also makes for a slightly cleaner code.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
---
 hurd/hurd/signal.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Samuel Thibault April 2, 2023, 11:26 p.m. UTC | #1
Applied, thanks!

Sergey Bugaev, le dim. 19 mars 2023 18:10:14 +0300, a ecrit:
> When THREAD_GETMEM is defined with inline assembly, the compiler may not
> optimize away the two reads of _hurd_sigstate. Help it out a little bit
> by only reading it once. This also makes for a slightly cleaner code.
> 
> Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
> ---
>  hurd/hurd/signal.h | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
> index c33f974b..662e955e 100644
> --- a/hurd/hurd/signal.h
> +++ b/hurd/hurd/signal.h
> @@ -166,13 +166,15 @@ extern void _hurd_sigstate_delete (thread_t thread);
>  _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
>  _hurd_self_sigstate (void)
>  {
> -  if (THREAD_GETMEM (THREAD_SELF, _hurd_sigstate) == NULL)
> +  struct hurd_sigstate *ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
> +  if (__glibc_unlikely (ss == NULL))
>      {
>        thread_t self = __mach_thread_self ();
> -      THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, _hurd_thread_sigstate (self));
> +      ss = _hurd_thread_sigstate (self);
> +      THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, ss);
>        __mach_port_deallocate (__mach_task_self (), self);
>      }
> -  return THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
> +  return ss;
>  }
>  # endif
>  #endif
> -- 
> 2.39.2
>
diff mbox series

Patch

diff --git a/hurd/hurd/signal.h b/hurd/hurd/signal.h
index c33f974b..662e955e 100644
--- a/hurd/hurd/signal.h
+++ b/hurd/hurd/signal.h
@@ -166,13 +166,15 @@  extern void _hurd_sigstate_delete (thread_t thread);
 _HURD_SIGNAL_H_EXTERN_INLINE struct hurd_sigstate *
 _hurd_self_sigstate (void)
 {
-  if (THREAD_GETMEM (THREAD_SELF, _hurd_sigstate) == NULL)
+  struct hurd_sigstate *ss = THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
+  if (__glibc_unlikely (ss == NULL))
     {
       thread_t self = __mach_thread_self ();
-      THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, _hurd_thread_sigstate (self));
+      ss = _hurd_thread_sigstate (self);
+      THREAD_SETMEM (THREAD_SELF, _hurd_sigstate, ss);
       __mach_port_deallocate (__mach_task_self (), self);
     }
-  return THREAD_GETMEM (THREAD_SELF, _hurd_sigstate);
+  return ss;
 }
 # endif
 #endif