github.com/Kalvelign/golang-windows-sys-lib@v0.0.0-20221121121202-63da651435e1/cpu/cpu_gccgo_x86.c (about)

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