[libav-commits] x86/cpu: implement support for xgetbv through intrinsics

Ronald S. Bultje git at libav.org
Tue Jul 10 13:42:40 CEST 2012


Module: libav
Branch: master
Commit: 3f150ffba31e404ca48624dc6af27b85c1704862

Author:    Ronald S. Bultje <rsbultje at gmail.com>
Committer: Martin Storsjö <martin at martin.st>
Date:      Mon Jul  9 02:21:26 2012 +0200

x86/cpu: implement support for xgetbv through intrinsics

Signed-off-by: Martin Storsjö <martin at martin.st>

---

 configure           |    2 ++
 libavutil/x86/cpu.c |   11 +++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/configure b/configure
index a1506c9..76ad4c7 100755
--- a/configure
+++ b/configure
@@ -1169,6 +1169,7 @@ HAVE_LIST="
     windows_h
     winsock2_h
     xform_asm
+    xgetbv
     xmm_clobbers
     yasm
 "
@@ -2742,6 +2743,7 @@ elif enabled sparc; then
 
 elif enabled x86; then
 
+    check_code ld immintrin.h "__xgetbv(0)" && enable xgetbv
     check_code ld intrin.h "__rdtsc()" && enable rdtsc
 
     check_code ld mmintrin.h "_mm_empty()" && enable mm_empty
diff --git a/libavutil/x86/cpu.c b/libavutil/x86/cpu.c
index 5d77b0c..dfdc123 100644
--- a/libavutil/x86/cpu.c
+++ b/libavutil/x86/cpu.c
@@ -34,8 +34,19 @@
         : "=a" (eax), "=S" (ebx), "=c" (ecx), "=d" (edx)        \
         : "0" (index))
 
+#if HAVE_INLINE_ASM
 #define xgetbv(index, eax, edx)                                 \
     __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (index))
+#elif HAVE_XGETBV
+#include <immintrin.h>
+
+#define xgetbv(index, eax, edx)                 \
+    do {                                        \
+        uint64_t res = __xgetbv(index);         \
+        eax = res;                              \
+        edx = res >> 32;                        \
+    } while (0)
+#endif /* HAVE_XGETBV */
 
 #define get_eflags(x)                           \
     __asm__ volatile ("pushfl     \n"           \



More information about the libav-commits mailing list