From aaade52146624a4488b4e3cb47d53784ac4a90d4 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 15 Apr 2026 17:32:43 +0300 Subject: [PATCH] LibC: Use __builtin_thread_pointer for _get_uthread() This generates much nicer assembly as it does not have to read thread pointer for every access to TCB (errno, cancel_state, cancelled) and instead it can read it once and use the same value for all accesses --- .../libraries/LibC/include/bits/types/uthread.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/userspace/libraries/LibC/include/bits/types/uthread.h b/userspace/libraries/LibC/include/bits/types/uthread.h index 9b83d83a..f83b1d4e 100644 --- a/userspace/libraries/LibC/include/bits/types/uthread.h +++ b/userspace/libraries/LibC/include/bits/types/uthread.h @@ -48,19 +48,7 @@ struct uthread uintptr_t dtv[1 + 256]; }; -#if defined(__x86_64__) -#define _get_uthread() ({ \ - struct uthread* _uthread; \ - __asm__ volatile("movq %%fs:0, %0" : "=r"(_uthread)); \ - _uthread; \ - }) -#elif defined(__i686__) -#define _get_uthread() ({ \ - struct uthread* _uthread; \ - __asm__ volatile("movl %%gs:0, %0" : "=r"(_uthread)); \ - _uthread; \ - }) -#endif +#define _get_uthread() ((struct uthread*)__builtin_thread_pointer()) __END_DECLS