You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cpu_gccgo_x86.c 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build (386 || amd64 || amd64p32) && gccgo
  5. // +build 386 amd64 amd64p32
  6. // +build gccgo
  7. #include <cpuid.h>
  8. #include <stdint.h>
  9. #include <x86intrin.h>
  10. // Need to wrap __get_cpuid_count because it's declared as static.
  11. int
  12. gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf,
  13. uint32_t *eax, uint32_t *ebx,
  14. uint32_t *ecx, uint32_t *edx)
  15. {
  16. return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx);
  17. }
  18. #pragma GCC diagnostic ignored "-Wunknown-pragmas"
  19. #pragma GCC push_options
  20. #pragma GCC target("xsave")
  21. #pragma clang attribute push (__attribute__((target("xsave"))), apply_to=function)
  22. // xgetbv reads the contents of an XCR (Extended Control Register)
  23. // specified in the ECX register into registers EDX:EAX.
  24. // Currently, the only supported value for XCR is 0.
  25. void
  26. gccgoXgetbv(uint32_t *eax, uint32_t *edx)
  27. {
  28. uint64_t v = _xgetbv(0);
  29. *eax = v & 0xffffffff;
  30. *edx = v >> 32;
  31. }
  32. #pragma clang attribute pop
  33. #pragma GCC pop_options