cpu_gccgo.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. // 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. // xgetbv reads the contents of an XCR (Extended Control Register)
  17. // specified in the ECX register into registers EDX:EAX.
  18. // Currently, the only supported value for XCR is 0.
  19. //
  20. // TODO: Replace with a better alternative:
  21. //
  22. // #include <xsaveintrin.h>
  23. //
  24. // #pragma GCC target("xsave")
  25. //
  26. // void gccgoXgetbv(uint32_t *eax, uint32_t *edx) {
  27. // unsigned long long x = _xgetbv(0);
  28. // *eax = x & 0xffffffff;
  29. // *edx = (x >> 32) & 0xffffffff;
  30. // }
  31. //
  32. // Note that _xgetbv is defined starting with GCC 8.
  33. void
  34. gccgoXgetbv(uint32_t *eax, uint32_t *edx)
  35. {
  36. __asm(" xorl %%ecx, %%ecx\n"
  37. " xgetbv"
  38. : "=a"(*eax), "=d"(*edx));
  39. }