aboutsummaryrefslogtreecommitdiff
path: root/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c')
-rw-r--r--vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c b/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c
index e363c7d..a4605e6 100644
--- a/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c
+++ b/vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c
@@ -7,6 +7,7 @@
#include <cpuid.h>
#include <stdint.h>
+#include <x86intrin.h>
// Need to wrap __get_cpuid_count because it's declared as static.
int
@@ -17,27 +18,21 @@ gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf,
return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx);
}
+#pragma GCC diagnostic ignored "-Wunknown-pragmas"
+#pragma GCC push_options
+#pragma GCC target("xsave")
+#pragma clang attribute push (__attribute__((target("xsave"))), apply_to=function)
+
// xgetbv reads the contents of an XCR (Extended Control Register)
// specified in the ECX register into registers EDX:EAX.
// Currently, the only supported value for XCR is 0.
-//
-// TODO: Replace with a better alternative:
-//
-// #include <xsaveintrin.h>
-//
-// #pragma GCC target("xsave")
-//
-// void gccgoXgetbv(uint32_t *eax, uint32_t *edx) {
-// unsigned long long x = _xgetbv(0);
-// *eax = x & 0xffffffff;
-// *edx = (x >> 32) & 0xffffffff;
-// }
-//
-// Note that _xgetbv is defined starting with GCC 8.
void
gccgoXgetbv(uint32_t *eax, uint32_t *edx)
{
- __asm(" xorl %%ecx, %%ecx\n"
- " xgetbv"
- : "=a"(*eax), "=d"(*edx));
+ uint64_t v = _xgetbv(0);
+ *eax = v & 0xffffffff;
+ *edx = v >> 32;
}
+
+#pragma clang attribute pop
+#pragma GCC pop_options