From nobody Mon Sep 17 00:00:00 2001 From: Pavel Afremov Date: Fri, 23 Mar 2007 20:56:04 +0300 Subject: [PATCH] Fast TLS access via intrinsics. --- vm/include/open/hythread.h | 21 +++++++++++++-------- vm/include/open/hythread_ext.h | 31 ------------------------------- vm/thread/src/thread_native_basic.c | 18 +++++++++++++----- vm/thread/src/thread_private.h | 9 --------- 4 files changed, 26 insertions(+), 53 deletions(-) 766ff4eb540f04d792d00912165e8205d27d8d40 diff --git a/vm/include/open/hythread.h b/vm/include/open/hythread.h index 8a2d00a..d6b2d4c 100644 --- a/vm/include/open/hythread.h +++ b/vm/include/open/hythread.h @@ -366,9 +366,6 @@ #define ASM_MONITOR_HELPER // http://www.microsoft.com/msj/archive/S2CE.aspx #define FS14_TLS_USE -#elif defined _EM64T_ && defined WINDOWS - -#define APR_TLS_USE #endif @@ -400,11 +397,19 @@ extern "C" { #endif /* __cplusplus */ hy_inline hythread_t VMCALL hythread_self() { - register hythread_t t; - _asm { mov eax, fs:[0x14] - mov t, eax; - } - return t; +#ifndef _WIN64 +# if (_MSC_VER >= 1400) + return __readfsdword(offsetof(NT_TIB, ArbitraryUserPointer)); +# else + register hythread_t t; + _asm { mov eax, fs:[0x14] + mov t, eax; + } + return t; +# endif +#else + return __readgsqword(offsetof(NT_TIB, ArbitraryUserPointer)); +#endif } #define tm_self_tls (hythread_self()) diff --git a/vm/include/open/hythread_ext.h b/vm/include/open/hythread_ext.h index 44d3819..962573d 100644 --- a/vm/include/open/hythread_ext.h +++ b/vm/include/open/hythread_ext.h @@ -349,24 +349,8 @@ hy_inline void VMCALL hythread_suspend_e register struct HyThread_public *thread; assert(!hythread_is_suspend_enabled()); -#ifdef FS14_TLS_USE - __asm { - mov eax, fs:[0x14] - dec [eax]HyThread_public.suspend_disable_count - mov eax, [eax]HyThread_public.suspend_request - test eax, eax - jnz suspended - } - return; - -suspended: - thread=(struct HyThread_public *)hythread_self(); - -#else thread=(struct HyThread_public *)hythread_self(); thread->suspend_disable_count--; - -#endif } /** @@ -384,23 +368,8 @@ hy_inline void VMCALL hythread_suspend_d { register hythread_t thread; -#ifdef FS14_TLS_USE - __asm { - mov eax, fs:[0x14] - inc [eax]HyThread_public.suspend_disable_count - mov eax, [eax]HyThread_public.suspend_request - test eax, eax - jnz suspended - } - return; - -suspended: - thread=hythread_self(); - -#else thread=hythread_self(); ((struct HyThread_public *)thread)->suspend_disable_count++; -#endif if(!((struct HyThread_public *)thread)->suspend_request || ((struct HyThread_public *)thread)->suspend_disable_count!=1) { diff --git a/vm/thread/src/thread_native_basic.c b/vm/thread/src/thread_native_basic.c index 2e0147e..0f053c4 100644 --- a/vm/thread/src/thread_native_basic.c +++ b/vm/thread/src/thread_native_basic.c @@ -364,7 +364,7 @@ hythread_t hythread_self_slow() { static void thread_set_self(hythread_t thread) { apr_threadkey_private_set(thread, TM_THREAD_KEY); } -#else +#else #ifdef FS14_TLS_USE /** * Return the hythread_t for the current thread. @@ -382,10 +382,18 @@ hythread_t hythread_self_slow() { static void thread_set_self(hythread_t thread) { //tm_self_tls = thread; - _asm{ - mov eax, thread - mov fs:[0x14], eax - } +#ifndef _WIN64 +# if (_MSC_VER >= 1400) + __writefsdword(offsetof(NT_TIB, ArbitraryUserPointer), thread); +# else + _asm{ + mov eax, thread + mov fs:[0x14], eax + } +# endif +#else + __writegsqword(offsetof(NT_TIB, ArbitraryUserPointer), thread); +#endif } #else /** diff --git a/vm/thread/src/thread_private.h b/vm/thread/src/thread_private.h index de708af..4fbab23 100644 --- a/vm/thread/src/thread_private.h +++ b/vm/thread/src/thread_private.h @@ -56,15 +56,6 @@ #define SPIN_COUNT 5 #endif // !defined (_IPF_) -#if defined(WIN32) && !defined (_EM64T_) -//use optimized asm monitor enter and exit helpers -#define ASM_MONITOR_HELPER -// FS14_TLS_USE define turns on windows specific TLS access optimization -// We use free TIB slot with 14 offset, see following article for details -// http://www.microsoft.com/msj/archive/S2CE.aspx -//#define FS14_TLS_USE -#endif - #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -- 1.3.3