cpu_gccgo_x86.c 1.1 KB

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