diff mbox series

libgo patch committed: Use inline assembler for xgetbv

Message ID CAOyqgcVHOkNe9vj_8nRxdTbQQdOs9hD0u65LJ=tKYZuhC2NZmA@mail.gmail.com
State New
Headers show
Series libgo patch committed: Use inline assembler for xgetbv | expand

Commit Message

Ian Lance Taylor Oct. 5, 2018, 5:52 p.m. UTC
This patch by Than McIntosh uses inline assembler instead of the
_xgetbv intrinsic, so that libgo can be built by compilers that don't
support the intrinsic.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
diff mbox series

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 264872)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-9f4cf23e716bcf65e071260afa032a64acd3fdde
+d0739c13ca3686df1f8d0fae7c6c5caaed058503
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/go/internal/cpu/cpu_gccgo.c
===================================================================
--- libgo/go/internal/cpu/cpu_gccgo.c	(revision 264813)
+++ libgo/go/internal/cpu/cpu_gccgo.c	(working copy)
@@ -52,12 +52,18 @@  struct xgetbv_ret xgetbv(void)
 #pragma GCC target("xsave")
 
 struct xgetbv_ret xgetbv(void) {
-	long long r;
 	struct xgetbv_ret ret;
 
-	r = _xgetbv(0);
-	ret.eax = r & 0xffffffff;
-	ret.edx = r >> 32;
+        // At some point, use call to _xgetbv() instead:
+        //
+        //       long long r = _xgetbv(0);
+        //       ret.eax = r & 0xffffffff;
+        //       ret.edx = r >> 32;
+        //
+        unsigned int __eax, __edx, __xcr_no = 0;
+        __asm__ ("xgetbv" : "=a" (__eax), "=d" (__edx) : "c" (__xcr_no));
+        ret.eax = __eax;
+        ret.edx = __edx;
 	return ret;
 }