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

12345678910111213141516171819202122232425262728293031323334353637
  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. #include <cpuid.h>
  6. #include <stdint.h>
  7. #include <x86intrin.h>
  8. // Need to wrap __get_cpuid_count because it's declared as static.
  9. int
  10. gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf,
  11. uint32_t *eax, uint32_t *ebx,
  12. uint32_t *ecx, uint32_t *edx)
  13. {
  14. return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx);
  15. }
  16. #pragma GCC diagnostic ignored "-Wunknown-pragmas"
  17. #pragma GCC push_options
  18. #pragma GCC target("xsave")
  19. #pragma clang attribute push (__attribute__((target("xsave"))), apply_to=function)
  20. // xgetbv reads the contents of an XCR (Extended Control Register)
  21. // specified in the ECX register into registers EDX:EAX.
  22. // Currently, the only supported value for XCR is 0.
  23. void
  24. gccgoXgetbv(uint32_t *eax, uint32_t *edx)
  25. {
  26. uint64_t v = _xgetbv(0);
  27. *eax = v & 0xffffffff;
  28. *edx = v >> 32;
  29. }
  30. #pragma clang attribute pop
  31. #pragma GCC pop_options