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
This commit is contained in:
2026-04-15 17:32:43 +03:00
parent 1bf5e6a051
commit aaade52146

View File

@@ -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