Author: ion
Date: Sat Jul 23 12:08:36 2011
New Revision: 52807

URL: http://svn.reactos.org/svn/reactos?rev=52807&view=rev
Log:
[KERNEL32]: Optimize SwitchToFiber to simply use "ret" to jump between fibers, 
instead of saving EIP and doing a JMP.
Bug #50: SwitchToFiber needs to check if FXSR is *NOT* present in order to skip 
using ldmxcsr/stmxcsr. Previously, it would check if it's unsupported, and jump 
past the instruction if it was (resulting in invalid opcode instructions on 
older systems)
50 bugs. Penance has been paid.

Modified:
    trunk/reactos/dll/win32/kernel32/client/i386/fiber.S

Modified: trunk/reactos/dll/win32/kernel32/client/i386/fiber.S
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/kernel32/client/i386/fiber.S?rev=52807&r1=52806&r2=52807&view=diff
==============================================================================
--- trunk/reactos/dll/win32/kernel32/client/i386/fiber.S [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/kernel32/client/i386/fiber.S [iso-8859-1] Sat Jul 
23 12:08:36 2011
@@ -26,20 +26,16 @@
     mov [eax+FIBER_CONTEXT_EDI], edi
     mov [eax+FIBER_CONTEXT_EBP], ebp
 
-    /* Save the return address */
-    mov ebx, [esp]
-    mov [eax+FIBER_CONTEXT_EIP], ebx
-
     /* Check if we're to save FPU State */
     cmp dword ptr [eax+FIBER_CONTEXT_FLAGS], CONTEXT_FULL OR 
CONTEXT_FLOATING_POINT
     jnz NoFpuStateSave
     
     /* Save the FPU State (Status and Control)*/
     fstsw [eax+FIBER_CONTEXT_FLOAT_SAVE_STATUS_WORD]
-    fstcw [eax+FIBER_CONTEXT_FLOAT_SAVE_CONTROL_WORD]
+    fnstcw [eax+FIBER_CONTEXT_FLOAT_SAVE_CONTROL_WORD]
     
     /* Check if the CPU supports SIMD MXCSR State Save */
-    cmp byte ptr ds:[PROCESSOR_FEATURE_FXSR], 0
+    cmp byte ptr ds:[PROCESSOR_FEATURE_FXSR], 1
     jnz NoFpuStateSave
     stmxcsr [eax+FIBER_CONTEXT_DR6]
     
@@ -103,7 +99,7 @@
 ControlWordEqual:
 
     /* Load the new one */
-    cmp byte ptr ds:[PROCESSOR_FEATURE_FXSR], 0
+    cmp byte ptr ds:[PROCESSOR_FEATURE_FXSR], 1
     jnz NoFpuStateRestore
     ldmxcsr [ecx+FIBER_CONTEXT_DR6]
     
@@ -121,7 +117,8 @@
     mov [edx+TEB_FLS_DATA], eax
 
     /* Jump to new fiber */
-    jmp dword ptr [ecx+FIBER_CONTEXT_EIP]
+    mov esp, [ecx+FIBER_CONTEXT_ESP]
+    ret 4
+END
 
-END
 /* EOF */


Reply via email to