1) Move these functions to intrin-impl.h:

__readfsbyte, __readfsword, __readfsdword
__writefsbyte, __writefsword, __writefsdword
__readgsbyte, __readgsword, __readgsdword, __readgsqword
__writegsbyte, __writegsword, __writegsdword, __writegsqword

2) Update inline asm code:

*a) Change __write* so "Data" is an input. Without this, the wrong value gets written.*
/b) Change __write* routines so they are NOT volatile./
c) Change __write* so "Data" uses "ri" constraint for (potentially)(slightly) better performance.
d) Change __read* so they are not volatile.
e) Change __read* so offset is an input param
f) Support both att and intel asm formats for both __read* and __write*

3) Change NtCurrentTeb, GetCurrentFiber, and GetFiberData to use existing routines instead of inline asm.

dw
Index: mingw-w64-crt/intrincs/currentfiber.c
===================================================================
--- mingw-w64-crt/intrincs/currentfiber.c       (revision 5948)
+++ mingw-w64-crt/intrincs/currentfiber.c       (working copy)
@@ -1,3 +1,5 @@
+/* todo - delete this file.  This is not an intrinsic.  It is only available 
thru winnt.h
+
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #endif
@@ -16,3 +18,4 @@
 #endif
  }
 
+*/
Index: mingw-w64-crt/intrincs/currentteb.c
===================================================================
--- mingw-w64-crt/intrincs/currentteb.c (revision 5948)
+++ mingw-w64-crt/intrincs/currentteb.c (working copy)
@@ -1,3 +1,5 @@
+/* todo - delete this file.  This is not an intrinsic.  It is only available 
thru winnt.h
+
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #endif
@@ -19,3 +21,4 @@
  }
 #endif
 
+*/
Index: mingw-w64-crt/intrincs/fiberdata.c
===================================================================
--- mingw-w64-crt/intrincs/fiberdata.c  (revision 5948)
+++ mingw-w64-crt/intrincs/fiberdata.c  (working copy)
@@ -1,3 +1,5 @@
+/* todo - delete this file.  This is not an intrinsic.  It is only available 
thru winnt.h
+
 #ifndef WIN32_LEAN_AND_MEAN
 #define WIN32_LEAN_AND_MEAN
 #endif
@@ -16,4 +18,4 @@
   return ret;
 #endif
  }
-
+*/
Index: mingw-w64-crt/intrincs/readfsbyte.c
===================================================================
--- mingw-w64-crt/intrincs/readfsbyte.c (revision 5948)
+++ mingw-w64-crt/intrincs/readfsbyte.c (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readfsbyte // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for x86 only */
-unsigned char __readfsbyte(unsigned __LONG32 Offset)
-{
-   unsigned char ret;
-   __asm__ volatile ("movb     %%fs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) Offset)));
-   return ret;
-}
-
Index: mingw-w64-crt/intrincs/readfsdword.c
===================================================================
--- mingw-w64-crt/intrincs/readfsdword.c        (revision 5948)
+++ mingw-w64-crt/intrincs/readfsdword.c        (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readfsdword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for x86 only */
-unsigned __LONG32 __readfsdword(unsigned __LONG32 Offset)
-{
-   unsigned __LONG32 ret;
-   __asm__ volatile ("movl     %%fs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) Offset)));
-   return ret;
-}
-
Index: mingw-w64-crt/intrincs/readfsword.c
===================================================================
--- mingw-w64-crt/intrincs/readfsword.c (revision 5948)
+++ mingw-w64-crt/intrincs/readfsword.c (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readfsword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for x86 only */
-unsigned short __readfsword(unsigned __LONG32 Offset)
-{
-   unsigned short ret;
-   __asm__ volatile ("movw     %%fs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) Offset)));
-   return ret;
-}
-
Index: mingw-w64-crt/intrincs/readgsbyte.c
===================================================================
--- mingw-w64-crt/intrincs/readgsbyte.c (revision 5948)
+++ mingw-w64-crt/intrincs/readgsbyte.c (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readgsbyte // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-unsigned char __readgsbyte(unsigned __LONG32 Offset)
-{
-   unsigned char ret;
-   __asm__ volatile ("movb     %%gs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) Offset)));
-   return ret;
-}
-
Index: mingw-w64-crt/intrincs/readgsdword.c
===================================================================
--- mingw-w64-crt/intrincs/readgsdword.c        (revision 5948)
+++ mingw-w64-crt/intrincs/readgsdword.c        (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readgsdword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-unsigned __LONG32 __readgsdword(unsigned __LONG32 Offset)
-{
-   unsigned __LONG32 ret;
-   __asm__ volatile ("movl     %%gs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) Offset)));
-   return ret;
-}
-
Index: mingw-w64-crt/intrincs/readgsqword.c
===================================================================
--- mingw-w64-crt/intrincs/readgsqword.c        (revision 5948)
+++ mingw-w64-crt/intrincs/readgsqword.c        (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readgsqword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-unsigned __int64 __readgsqword(unsigned __LONG32 Offset)
-{
-   void *ret;
-   __asm__ volatile ("movq     %%gs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) Offset)));
-   return (unsigned __int64) ret;
-}
-
Index: mingw-w64-crt/intrincs/readgsword.c
===================================================================
--- mingw-w64-crt/intrincs/readgsword.c (revision 5948)
+++ mingw-w64-crt/intrincs/readgsword.c (working copy)
@@ -1,11 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___readgsword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-unsigned short __readgsword(unsigned __LONG32 Offset)
-{
-   unsigned short ret;
-   __asm__ volatile ("movw     %%gs:%1,%0"
-     : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) Offset)));
-   return ret;
-}
-
Index: mingw-w64-crt/intrincs/writefsbyte.c
===================================================================
--- mingw-w64-crt/intrincs/writefsbyte.c        (revision 5948)
+++ mingw-w64-crt/intrincs/writefsbyte.c        (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writefsbyte // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for x86 only */
-void __writefsbyte(unsigned __LONG32 Offset, unsigned char Data)
-{
-    __asm__ volatile ("movb    %0,%%fs:%1"
-      : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) Offset)));
-}
-
Index: mingw-w64-crt/intrincs/writefsdword.c
===================================================================
--- mingw-w64-crt/intrincs/writefsdword.c       (revision 5948)
+++ mingw-w64-crt/intrincs/writefsdword.c       (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writefsdword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for x86 only */
-void __writefsdword(unsigned __LONG32 Offset, unsigned __LONG32 Data)
-{
-   __asm__ volatile ("movl     %0,%%fs:%1"
-     : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) Offset)));
-}
-
Index: mingw-w64-crt/intrincs/writefsword.c
===================================================================
--- mingw-w64-crt/intrincs/writefsword.c        (revision 5948)
+++ mingw-w64-crt/intrincs/writefsword.c        (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writefsword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for x86 only */
-void __writefsword(unsigned __LONG32 Offset, unsigned short Data)
-{
-    __asm__ volatile ("movw    %0,%%fs:%1"
-      : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) Offset)));
-}
-
Index: mingw-w64-crt/intrincs/writegsbyte.c
===================================================================
--- mingw-w64-crt/intrincs/writegsbyte.c        (revision 5948)
+++ mingw-w64-crt/intrincs/writegsbyte.c        (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writegsbyte // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-void __writegsbyte(unsigned __LONG32 Offset, unsigned char Data)
-{
-    __asm__ volatile ("movb    %0,%%gs:%1"
-      : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) 
Offset)));
-}
-
Index: mingw-w64-crt/intrincs/writegsdword.c
===================================================================
--- mingw-w64-crt/intrincs/writegsdword.c       (revision 5948)
+++ mingw-w64-crt/intrincs/writegsdword.c       (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writegsdword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-void __writegsdword(unsigned __LONG32 Offset, unsigned __LONG32 Data)
-{
-   __asm__ volatile ("movl     %0,%%gs:%1"
-     : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) Offset)));
-}
-
Index: mingw-w64-crt/intrincs/writegsqword.c
===================================================================
--- mingw-w64-crt/intrincs/writegsqword.c       (revision 5948)
+++ mingw-w64-crt/intrincs/writegsqword.c       (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writegsqword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-void __writegsqword(unsigned __LONG32 Offset, unsigned __int64 Data)
-{
-   __asm__ volatile ("movq     %0,%%gs:%1"
-     : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) Offset)));
-}
-
Index: mingw-w64-crt/intrincs/writegsword.c
===================================================================
--- mingw-w64-crt/intrincs/writegsword.c        (revision 5948)
+++ mingw-w64-crt/intrincs/writegsword.c        (working copy)
@@ -1,9 +1,4 @@
+#define __INTRINSIC_ONLYSPECIAL
+#define __INTRINSIC_SPECIAL___writegsword // Causes code generation in 
intrin-impl.h
+
 #include <intrin.h>
-
-/* for __x86_64 only */
-void __writegsword(unsigned __LONG32 Offset, unsigned short Data)
-{
-    __asm__ volatile ("movw    %0,%%gs:%1"
-      : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (unsigned __int64) 
Offset)));
-}
-
Index: mingw-w64-headers/crt/intrin.h
===================================================================
--- mingw-w64-headers/crt/intrin.h      (revision 5949)
+++ mingw-w64-headers/crt/intrin.h      (working copy)
@@ -1022,14 +1022,14 @@
     __MACHINEI(void __movsw(unsigned short *,unsigned short const *,size_t))
     __MACHINEI(void __movsd(unsigned __LONG32 *,unsigned __LONG32 const 
*,size_t))
     __MACHINEX64(__MINGW_EXTENSION void __movsq(unsigned long long *,unsigned 
long long const *,size_t))
-    __MACHINEX64(unsigned char __readgsbyte(unsigned __LONG32 Offset))
-    __MACHINEX64(unsigned short __readgsword(unsigned __LONG32 Offset))
-    __MACHINEX64(unsigned __LONG32 __readgsdword(unsigned __LONG32 Offset))
-    __MACHINEX64(__MINGW_EXTENSION unsigned __int64 __readgsqword(unsigned 
__LONG32 Offset))
-    __MACHINEX64(void __writegsbyte(unsigned __LONG32 Offset,unsigned char 
Data))
-    __MACHINEX64(void __writegsword(unsigned __LONG32 Offset,unsigned short 
Data))
-    __MACHINEX64(void __writegsdword(unsigned __LONG32 Offset,unsigned 
__LONG32 Data))
-    __MACHINEX64(__MINGW_EXTENSION void __writegsqword(unsigned __LONG32 
Offset,unsigned __int64 Data))
+    /* __MACHINEX64(unsigned char __readgsbyte(unsigned __LONG32 Offset)) 
moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(unsigned short __readgsword(unsigned __LONG32 Offset)) 
moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(unsigned __LONG32 __readgsdword(unsigned __LONG32 Offset)) 
moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(__MINGW_EXTENSION unsigned __int64 __readgsqword(unsigned 
__LONG32 Offset)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(void __writegsbyte(unsigned __LONG32 Offset,unsigned char 
Data)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(void __writegsword(unsigned __LONG32 Offset,unsigned short 
Data)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(void __writegsdword(unsigned __LONG32 Offset,unsigned 
__LONG32 Data)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEX64(__MINGW_EXTENSION void __writegsqword(unsigned __LONG32 
Offset,unsigned __int64 Data)) moved to psdk_inc/intrin-impl.h */
     __MACHINEI(unsigned char __inbyte(unsigned short Port))
     __MACHINEI(unsigned short __inword(unsigned short Port))
     __MACHINEI(unsigned __LONG32 __indword(unsigned short Port))
@@ -1084,14 +1084,14 @@
     __MACHINEI(__MINGW_EXTENSION unsigned __int64 __readpmc(unsigned __LONG32 
a))
     __MACHINEI(unsigned __LONG32 __segmentlimit(unsigned __LONG32 a))
 
-    __MACHINEIA32(unsigned char __readfsbyte(unsigned __LONG32 Offset))
-    __MACHINEIA32(unsigned short __readfsword(unsigned __LONG32 Offset))
-    __MACHINEIA32(unsigned __LONG32 __readfsdword(unsigned __LONG32 Offset))
-    __MACHINEIA32(__MINGW_EXTENSION unsigned __int64 __readfsqword(unsigned 
__LONG32 Offset))
-    __MACHINEIA32(void __writefsbyte(unsigned __LONG32 Offset,unsigned char 
Data))
-    __MACHINEIA32(void __writefsword(unsigned __LONG32 Offset,unsigned short 
Data))
-    __MACHINEIA32(void __writefsdword(unsigned __LONG32 Offset,unsigned 
__LONG32 Data))
-    __MACHINEIA32(__MINGW_EXTENSION void __writefsqword(unsigned __LONG32 
Offset,unsigned __int64 Data))
+    /* __MACHINEIA32(unsigned char __readfsbyte(unsigned __LONG32 Offset)) 
moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEIA32(unsigned short __readfsword(unsigned __LONG32 Offset)) 
moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEIA32(unsigned __LONG32 __readfsdword(unsigned __LONG32 
Offset)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEIA32(__MINGW_EXTENSION unsigned __int64 __readfsqword(unsigned 
__LONG32 Offset)) intrinsic doesn't actually exist */
+    /* __MACHINEIA32(void __writefsbyte(unsigned __LONG32 Offset,unsigned char 
Data)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEIA32(void __writefsword(unsigned __LONG32 Offset,unsigned 
short Data)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEIA32(void __writefsdword(unsigned __LONG32 Offset,unsigned 
__LONG32 Data)) moved to psdk_inc/intrin-impl.h */
+    /* __MACHINEIA32(__MINGW_EXTENSION void __writefsqword(unsigned __LONG32 
Offset,unsigned __int64 Data)) intrinsic doesn't actually exist */
 
     __MACHINE(__MINGW_EXTENSION __int64 __cdecl _abs64(__int64))
 
Index: mingw-w64-headers/include/psdk_inc/intrin-impl.h
===================================================================
--- mingw-w64-headers/include/psdk_inc/intrin-impl.h    (revision 5949)
+++ mingw-w64-headers/include/psdk_inc/intrin-impl.h    (working copy)
@@ -147,6 +147,20 @@
 #define __INTRINSIC_SPECIAL__InterlockedCompareExchange64
 #define __INTRINSIC_SPECIAL__InterlockedExchangePointer
 #define __INTRINSIC_SPECIAL__InterlockedCompareExchangePointer
+#define __INTRINSIC_SPECIAL___readgsbyte
+#define __INTRINSIC_SPECIAL___readgsword
+#define __INTRINSIC_SPECIAL___readgsdword
+#define __INTRINSIC_SPECIAL___readgsqword
+#define __INTRINSIC_SPECIAL___writegsbyte
+#define __INTRINSIC_SPECIAL___writegsword
+#define __INTRINSIC_SPECIAL___writegsdword
+#define __INTRINSIC_SPECIAL___writegsqword
+#define __INTRINSIC_SPECIAL___readfsbyte
+#define __INTRINSIC_SPECIAL___readfsword
+#define __INTRINSIC_SPECIAL___readfsdword
+#define __INTRINSIC_SPECIAL___writefsbyte
+#define __INTRINSIC_SPECIAL___writefsword
+#define __INTRINSIC_SPECIAL___writefsdword
 
 #endif /* __INTRINSIC_GROUP_WINNT */
 
@@ -277,8 +291,64 @@
 #define __INTRINSIC_DEFINED__InterlockedExchangeAdd64
 #endif /* __INTRINSIC_PROLOG */
 
-#endif // __x86_64__
+#if __INTRINSIC_PROLOG(__readgsbyte)
+unsigned char __readgsbyte(unsigned __LONG32 Offset);
+__INTRINSICS_USEINLINE
+__buildreadseg(__readgsbyte, unsigned char, "gs")
+#define __INTRINSIC_DEFINED___readgsbyte
+#endif /* __INTRINSIC_PROLOG */
 
+#if __INTRINSIC_PROLOG(__readgsword)
+unsigned short __readgsword(unsigned __LONG32 Offset);
+__INTRINSICS_USEINLINE
+__buildreadseg(__readgsword, unsigned short, "gs")
+#define __INTRINSIC_DEFINED___readgsword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__readgsdword)
+unsigned __LONG32 __readgsdword(unsigned __LONG32 Offset);
+__INTRINSICS_USEINLINE
+__buildreadseg(__readgsdword, unsigned __LONG32, "gs")
+#define __INTRINSIC_DEFINED___readgsdword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__readgsqword)
+__MINGW_EXTENSION unsigned __int64 __readgsqword(unsigned __LONG32 Offset);
+__MINGW_EXTENSION __INTRINSICS_USEINLINE
+__buildreadseg(__readgsqword, unsigned __int64, "gs")
+#define __INTRINSIC_DEFINED___readgsqword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writegsbyte)
+void __writegsbyte(unsigned __LONG32 Offset,unsigned char Data);
+__INTRINSICS_USEINLINE
+__buildwriteseg(__writegsbyte, unsigned char, "gs")
+#define __INTRINSIC_DEFINED___writegsbyte
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writegsword)
+void __writegsword(unsigned __LONG32 Offset,unsigned short Data);
+__INTRINSICS_USEINLINE
+__buildwriteseg(__writegsword, unsigned short, "gs")
+#define __INTRINSIC_DEFINED___writegsword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writegsdword)
+void __writegsdword(unsigned __LONG32 Offset,unsigned __LONG32 Data);
+__INTRINSICS_USEINLINE
+__buildwriteseg(__writegsdword, unsigned __LONG32, "gs")
+#define __INTRINSIC_DEFINED___writegsdword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writegsqword)
+__MINGW_EXTENSION void __writegsqword(unsigned __LONG32 Offset,unsigned 
__int64 Data);
+__MINGW_EXTENSION __INTRINSICS_USEINLINE
+__buildwriteseg(__writegsqword, unsigned __int64, "gs")
+#define __INTRINSIC_DEFINED___writegsqword
+#endif /* __INTRINSIC_PROLOG */
+
+#endif /* __x86_64__ */
+
 /* ***************************************************** */
 
 #if defined(__x86_64__) || defined(_X86_)
@@ -475,8 +545,54 @@
 #define __INTRINSIC_DEFINED__InterlockedExchangePointer
 #endif /* __INTRINSIC_PROLOG */
 
-#endif // defined(__x86_64__) || (defined(_X86_)
+#endif /* defined(__x86_64__) || (defined(_X86_) */
 
+#if defined(_X86_)
+
+#if __INTRINSIC_PROLOG(__readfsbyte)
+unsigned char __readfsbyte(unsigned __LONG32 Offset);
+__INTRINSICS_USEINLINE
+__buildreadseg(__readfsbyte, unsigned char, "fs")
+#define __INTRINSIC_DEFINED___readfsbyte
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__readfsword)
+unsigned short __readfsword(unsigned __LONG32 Offset);
+__INTRINSICS_USEINLINE
+__buildreadseg(__readfsword, unsigned short, "fs")
+#define __INTRINSIC_DEFINED___readfsword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__readfsdword)
+unsigned __LONG32 __readfsdword(unsigned __LONG32 Offset);
+__INTRINSICS_USEINLINE
+__buildreadseg(__readfsdword, unsigned __LONG32, "fs")
+#define __INTRINSIC_DEFINED___readfsdword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writefsbyte)
+void __writefsbyte(unsigned __LONG32 Offset,unsigned char Data);
+__INTRINSICS_USEINLINE
+__buildwriteseg(__writefsbyte, unsigned char, "fs")
+#define __INTRINSIC_DEFINED___writefsbyte
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writefsword)
+void __writefsword(unsigned __LONG32 Offset,unsigned short Data);
+__INTRINSICS_USEINLINE
+__buildwriteseg(__writefsword, unsigned short, "fs")
+#define __INTRINSIC_DEFINED___writefsword
+#endif /* __INTRINSIC_PROLOG */
+
+#if __INTRINSIC_PROLOG(__writefsdword)
+void __writefsdword(unsigned __LONG32 Offset,unsigned __LONG32 Data);
+__INTRINSICS_USEINLINE
+__buildwriteseg(__writefsdword, unsigned __LONG32, "fs")
+#define __INTRINSIC_DEFINED___writefsdword
+#endif /* __INTRINSIC_PROLOG */
+
+#endif /* defined(_X86_) */
+
 #ifdef __cplusplus
 }
 #endif
Index: mingw-w64-headers/include/psdk_inc/intrin-mac.h
===================================================================
--- mingw-w64-headers/include/psdk_inc/intrin-mac.h     (revision 5948)
+++ mingw-w64-headers/include/psdk_inc/intrin-mac.h     (working copy)
@@ -74,4 +74,34 @@
 __asm__ __volatile__("xchg{b %%| }al, %0" :"=m" (Barrier) : /* no inputs */ : 
"eax", "memory"); \
 }
 
+/* This macro is used by __readfsbyte, __readfsword, __readfsdword
+                         __readgsbyte, __readgsword, __readgsdword, 
__readgsqword
+
+Parameters: (FunctionName, DataType, Segment)
+   FunctionName: Any valid function name
+   DataType: char, short, __LONG32 or __int64
+   Segment: fs or gs */
+
+#define __buildreadseg(x, y, z) y x(unsigned __LONG32 Offset) { \
+    y ret; \
+    __asm__ ("mov{%z[ret] %%" z ":%[offset], %[ret] | %[ret], %%" z 
":%[offset]}" \
+        : [ret] "=r" (ret) \
+        : [offset] "m" ((*(y *) (size_t) Offset))); \
+    return ret; \
+}
+
+/* This macro is used by __writefsbyte, __writefsword, __writefsdword
+                         __writegsbyte, __writegsword, __writegsdword, 
__writegsqword
+
+Parameters: (FunctionName, DataType, Segment)
+   FunctionName: Any valid function name
+   DataType: char, short, __LONG32 or __int64
+   Segment: fs or gs */
+
+#define __buildwriteseg(x, y, z) void x(unsigned __LONG32 Offset, y Data) { \
+    __asm__ ("mov{%z[offset] %[Data], %%" z ":%[offset] | %%" z ":%[offset], 
%[Data]}" \
+        : [offset] "=m" ((*(y *) (size_t) Offset)) \
+        : [Data] "ri" (Data)); \
+}
+
 #endif /* _INTRIN_MAC_ */
Index: mingw-w64-headers/include/winnt.h
===================================================================
--- mingw-w64-headers/include/winnt.h   (revision 5949)
+++ mingw-w64-headers/include/winnt.h   (working copy)
@@ -1449,57 +1449,15 @@
     }
 #endif
 
-    unsigned char __readgsbyte(unsigned __LONG32 Offset);
-    unsigned short __readgsword(unsigned __LONG32 Offset);
-    unsigned __LONG32 __readgsdword(unsigned __LONG32 Offset);
-    __MINGW_EXTENSION unsigned __int64 __readgsqword(unsigned __LONG32 Offset);
+    /* unsigned char __readgsbyte(unsigned __LONG32 Offset); moved to 
psdk_inc/intrin-impl.h */
+    /* unsigned short __readgsword(unsigned __LONG32 Offset); moved to 
psdk_inc/intrin-impl.h */
+    /* unsigned __LONG32 __readgsdword(unsigned __LONG32 Offset); moved to 
psdk_inc/intrin-impl.h */
+    /* __MINGW_EXTENSION unsigned __int64 __readgsqword(unsigned __LONG32 
Offset); moved to psdk_inc/intrin-impl.h */
 
-    void __writegsbyte(unsigned __LONG32 Offset,unsigned char Data);
-    void __writegsword(unsigned __LONG32 Offset,unsigned short Data);
-    void __writegsdword(unsigned __LONG32 Offset,unsigned __LONG32 Data);
-    __MINGW_EXTENSION void __writegsqword(unsigned __LONG32 Offset,unsigned 
__int64 Data);
+    /* void __writegsbyte(unsigned __LONG32 Offset,unsigned char Data); moved 
to psdk_inc/intrin-impl.h */
+    /* void __writegsword(unsigned __LONG32 Offset,unsigned short Data); moved 
to psdk_inc/intrin-impl.h */
+    /* void __writegsdword(unsigned __LONG32 Offset,unsigned __LONG32 Data); 
moved to psdk_inc/intrin-impl.h */
 
-    __CRT_INLINE BYTE __readgsbyte(DWORD Offset) {
-      BYTE ret;
-      __asm__ volatile ("movb  %%gs:%1,%0"
-       : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-      return ret;
-    }
-    __CRT_INLINE WORD __readgsword(DWORD Offset) {
-      WORD ret;
-      __asm__ volatile ("movw  %%gs:%1,%0"
-       : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-      return ret;
-    }
-    __CRT_INLINE DWORD __readgsdword(DWORD Offset) {
-      DWORD ret;
-      __asm__ volatile ("movl  %%gs:%1,%0"
-       : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-      return ret;
-    }
-    __CRT_INLINE DWORD64 __readgsqword(DWORD Offset) {
-      void *ret;
-      __asm__ volatile ("movq  %%gs:%1,%0"
-       : "=r" (ret) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-      return (DWORD64) ret;
-    }
-    __CRT_INLINE VOID __writegsbyte(DWORD Offset,BYTE Data) {
-      __asm__ volatile ("movb  %0,%%gs:%1"
-       : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-    }
-    __CRT_INLINE VOID __writegsword(DWORD Offset,WORD Data) {
-      __asm__ volatile ("movw  %0,%%gs:%1"
-       : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-    }
-    __CRT_INLINE VOID __writegsdword(DWORD Offset,DWORD Data) {
-      __asm__ volatile ("movl  %0,%%gs:%1"
-       : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-    }
-    __CRT_INLINE VOID __writegsqword(DWORD Offset,DWORD64 Data) {
-      __asm__ volatile ("movq  %0,%%gs:%1"
-       : "=r" (Data) ,"=m" ((*(volatile __LONG32 *) (DWORD64) Offset)));
-    }
-
 #ifdef __cplusplus
   }
 #endif
@@ -1668,12 +1626,12 @@
 #define InterlockedCompareExchange16 _InterlockedCompareExchange16
 
 #ifdef _PREFIX_
-    BYTE __readfsbyte(DWORD Offset);
-    WORD __readfsword(DWORD Offset);
-    DWORD __readfsdword(DWORD Offset);
-    VOID __writefsbyte(DWORD Offset,BYTE Data);
-    VOID __writefsword(DWORD Offset,WORD Data);
-    VOID __writefsdword(DWORD Offset,DWORD Data);
+    /* BYTE __readfsbyte(DWORD Offset); moved to psdk_inc/intrin-impl.h */
+    /* WORD __readfsword(DWORD Offset); moved to psdk_inc/intrin-impl.h */
+    /* DWORD __readfsdword(DWORD Offset); moved to psdk_inc/intrin-impl.h */
+    /* VOID __writefsbyte(DWORD Offset,BYTE Data); moved to 
psdk_inc/intrin-impl.h */
+    /* VOID __writefsword(DWORD Offset,WORD Data); moved to 
psdk_inc/intrin-impl.h */
+    /* VOID __writefsdword(DWORD Offset,DWORD Data); moved to 
psdk_inc/intrin-impl.h */
 #endif
 
 #ifdef __cplusplus
@@ -1708,25 +1666,15 @@
 
   __CRT_INLINE struct _TEB *NtCurrentTeb(void)
   {
-    struct _TEB *ret;
-    __asm__ volatile ("movl    %%fs:0x18,%0"
-       : "=r" (ret));
-    return ret;
+    return (struct _TEB *)__readfsdword(PcTeb);
   }
   __CRT_INLINE PVOID GetCurrentFiber(void)
   {
-    void *ret;
-    __asm__ volatile ("movl    %%fs:0x10,%0"
-       : "=r" (ret));
-    return ret;
+    return(PVOID)__readfsdword(0x10);
   }
   __CRT_INLINE PVOID GetFiberData(void)
   {
-    void *ret;
-    __asm__ volatile ("movl    %%fs:0x10,%0\n"
-       "movl   (%0),%0"
-       : "=r" (ret));
-    return ret;
+      return *(PVOID *)GetCurrentFiber();
   }
 #endif /* defined(__i386__) && !defined(__x86_64) */
 
------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics
Get end-to-end visibility with application monitoring from AppDynamics
Isolate bottlenecks and diagnose root cause in seconds.
Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to