r256686 - Reimplement __readeflags and __writeeflags on top of intrinsics

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 31 22:50:08 PST 2015


Author: majnemer
Date: Fri Jan  1 00:50:08 2016
New Revision: 256686

URL: http://llvm.org/viewvc/llvm-project?rev=256686&view=rev
Log:
Reimplement __readeflags and __writeeflags on top of intrinsics

Lean on LLVM to provide this functionality now that it provides the
necessary intrinsics.

Modified:
    cfe/trunk/include/clang/Basic/BuiltinsX86.def
    cfe/trunk/lib/Headers/ia32intrin.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=256686&r1=256685&r2=256686&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Fri Jan  1 00:50:08 2016
@@ -41,6 +41,13 @@ TARGET_BUILTIN(__builtin_ia32_undef128,
 TARGET_BUILTIN(__builtin_ia32_undef256, "V4d", "nc", "")
 TARGET_BUILTIN(__builtin_ia32_undef512, "V8d", "nc", "")
 
+// FLAGS
+//
+TARGET_BUILTIN(__builtin_ia32_readeflags_u32, "Ui", "n", "")
+TARGET_BUILTIN(__builtin_ia32_readeflags_u64, "ULLi", "n", "")
+TARGET_BUILTIN(__builtin_ia32_writeeflags_u32, "vUi", "n", "")
+TARGET_BUILTIN(__builtin_ia32_writeeflags_u64, "vULLi", "n", "")
+
 // 3DNow!
 //
 TARGET_BUILTIN(__builtin_ia32_femms, "v", "", "3dnow")

Modified: cfe/trunk/lib/Headers/ia32intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/ia32intrin.h?rev=256686&r1=256685&r2=256686&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/ia32intrin.h (original)
+++ cfe/trunk/lib/Headers/ia32intrin.h Fri Jan  1 00:50:08 2016
@@ -32,50 +32,26 @@
 static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
 __readeflags(void)
 {
-  unsigned long long __res = 0;
-  __asm__ __volatile__ ("pushf\n\t"
-                        "popq %0\n"
-                        :"=r"(__res)
-                        :
-                        :
-                       );
-  return __res;
+  return __builtin_ia32_readeflags_u64();
 }
 
 static __inline__ void __attribute__((__always_inline__, __nodebug__))
 __writeeflags(unsigned long long __f)
 {
-  __asm__ __volatile__ ("pushq %0\n\t"
-                        "popf\n"
-                        :
-                        :"r"(__f)
-                        :"flags"
-                       );
+  __builtin_ia32_writeeflags_u64(__f);
 }
 
 #else /* !__x86_64__ */
 static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
 __readeflags(void)
 {
-  unsigned int __res = 0;
-  __asm__ __volatile__ ("pushf\n\t"
-                        "popl %0\n"
-                        :"=r"(__res)
-                        :
-                        :
-                       );
-  return __res;
+  return __builtin_ia32_readeflags_u32();
 }
 
 static __inline__ void __attribute__((__always_inline__, __nodebug__))
 __writeeflags(unsigned int __f)
 {
-  __asm__ __volatile__ ("pushl %0\n\t"
-                        "popf\n"
-                        :
-                        :"r"(__f)
-                        :"flags"
-                       );
+  __builtin_ia32_writeeflags_u32(__f);
 }
 #endif /* !__x86_64__ */
 




More information about the cfe-commits mailing list