Module: xenomai-jki
Branch: for-upstream
Commit: 379c9c91a3197e000a0a9fe3d6915d382b94bb94
URL:    
http://git.xenomai.org/?p=xenomai-jki.git;a=commit;h=379c9c91a3197e000a0a9fe3d6915d382b94bb94

Author: Jan Kiszka <jan.kis...@siemens.com>
Date:   Wed Jan 30 17:00:58 2013 +0100

x86-64: Clean up fxsave/fxrstor

We always work against kernel memory and state here, and we did not
check the returned error code anyway. So downgrade __save_i387_checking/
__restore_i387_checking to non-checking versions and clean up the
corresponding assembly lines.

At this chance, we can pick up the kernel's micro-optimization when
CONFIG_AS_FXSAVEQ is set, i.e. we do not deal with prehistoric gas.

Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>

---

 include/asm-x86/bits/pod.h |   57 +++++++++++++------------------------------
 1 files changed, 17 insertions(+), 40 deletions(-)

diff --git a/include/asm-x86/bits/pod.h b/include/asm-x86/bits/pod.h
index 2af4379..49c57a7 100644
--- a/include/asm-x86/bits/pod.h
+++ b/include/asm-x86/bits/pod.h
@@ -227,33 +227,22 @@ static inline void xnarch_init_fpu(xnarchtcb_t * tcb)
        }
 }
 
-static inline int __save_i387_checking(x86_fpustate *fpup)
+static inline void __save_i387(x86_fpustate *fpup)
 {
-       int err = 0;
-
 #ifdef CONFIG_X86_32
        if (cpu_has_fxsr)
                __asm__ __volatile__("fxsave %0; fnclex":"=m"(*fpup));
        else
                __asm__ __volatile__("fnsave %0; fwait":"=m"(*fpup));
 #else /* CONFIG_X86_64 */
-       struct i387_fxsave_struct __user *fx = &fpup->fxsave;
-
-       asm volatile("1:  rex64/fxsave (%[fx])\n\t"
-                    "2:\n"
-                    ".section .fixup,\"ax\"\n"
-                    "3:  movl $-1,%[err]\n"
-                    "    jmp  2b\n"
-                    ".previous\n"
-                    ".section __ex_table,\"a\"\n"
-                    "   .align 8\n"
-                    "   .quad  1b,3b\n"
-                    ".previous"
-                    : [err] "=r" (err), "=m" (*fx)
-                    : [fx] "cdaSDb" (fx), "0" (0));
+#ifdef CONFIG_AS_FXSAVEQ
+       asm volatile("fxsaveq %0" : "=m" (fpup->fxsave));
+#else /* !CONFIG_AS_FXSAVEQ */
+       asm volatile("rex64/fxsave (%[fx])"
+                    : "=m" (fpup->fxsave)
+                    : [fx] "R" (&fpup->fxsave));
+#endif /* !CONFIG_AS_FXSAVEQ */
 #endif /* CONFIG_X86_64 */
-
-       return err;
 }
 
 static inline void xnarch_save_fpu(xnarchtcb_t *tcb)
@@ -280,13 +269,11 @@ static inline void xnarch_save_fpu(xnarchtcb_t *tcb)
 
        clts();
 
-       __save_i387_checking(tcb->fpup);
+       __save_i387(tcb->fpup);
 }
 
-static inline int __restore_i387_checking(x86_fpustate *fpup)
+static inline void __restore_i387(x86_fpustate *fpup)
 {
-       int err = 0;
-
 #ifdef CONFIG_X86_32
        if (cpu_has_fxsr)
                __asm__ __volatile__("fxrstor %0": /* no output */
@@ -295,23 +282,13 @@ static inline int __restore_i387_checking(x86_fpustate 
*fpup)
                __asm__ __volatile__("frstor %0": /* no output */
                                     :"m"(*fpup));
 #else /* CONFIG_X86_64 */
-       struct i387_fxsave_struct __user *fx = &fpup->fxsave;
-
-       asm volatile("1:  rex64/fxrstor (%[fx])\n\t"
-                    "2:\n"
-                    ".section .fixup,\"ax\"\n"
-                    "3:  movl $-1,%[err]\n"
-                    "    jmp  2b\n"
-                    ".previous\n"
-                    ".section __ex_table,\"a\"\n"
-                    "   .align 8\n"
-                    "   .quad  1b,3b\n"
-                    ".previous"
-                    : [err] "=r" (err)
-                    : [fx] "cdaSDb" (fx), "m" (*fx), "0" (0));
+#ifdef CONFIG_AS_FXSAVEQ
+       asm volatile("fxrstorq %0" : : "m" (fpup->fxsave));
+#else /* !CONFIG_AS_FXSAVEQ */
+       asm volatile("rex64/fxrstor (%0)"
+                    : : "R" (&fpup->fxsave), "m" (fpup->fxsave));
+#endif /* !CONFIG_AS_FXSAVEQ */
 #endif /* CONFIG_X86_64 */
-
-       return err;
 }
 
 static inline void xnarch_restore_fpu(xnarchtcb_t * tcb)
@@ -351,7 +328,7 @@ static inline void xnarch_restore_fpu(xnarchtcb_t * tcb)
           user-space or kernel thread. */
        clts();
 
-       __restore_i387_checking(tcb->fpup);
+       __restore_i387(tcb->fpup);
 }
 
 static inline void xnarch_enable_fpu(xnarchtcb_t *tcb)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to