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//go:build (386 || amd64 || amd64p32) && gc 6// +build 386 amd64 amd64p32 7// +build gc 8 9#include "textflag.h" 10 11// func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) 12TEXT ·cpuid(SB), NOSPLIT, $0-24 13 MOVL eaxArg+0(FP), AX 14 MOVL ecxArg+4(FP), CX 15 CPUID 16 MOVL AX, eax+8(FP) 17 MOVL BX, ebx+12(FP) 18 MOVL CX, ecx+16(FP) 19 MOVL DX, edx+20(FP) 20 RET 21 22// func xgetbv() (eax, edx uint32) 23TEXT ·xgetbv(SB),NOSPLIT,$0-8 24 MOVL $0, CX 25 XGETBV 26 MOVL AX, eax+0(FP) 27 MOVL DX, edx+4(FP) 28 RET 29 30// func darwinSupportsAVX512() bool 31TEXT ·darwinSupportsAVX512(SB), NOSPLIT, $0-1 32 MOVB $0, ret+0(FP) // default to false 33#ifdef GOOS_darwin // return if not darwin 34#ifdef GOARCH_amd64 // return if not amd64 35// These values from: 36// https://github.com/apple/darwin-xnu/blob/xnu-4570.1.46/osfmk/i386/cpu_capabilities.h 37#define commpage64_base_address 0x00007fffffe00000 38#define commpage64_cpu_capabilities64 (commpage64_base_address+0x010) 39#define commpage64_version (commpage64_base_address+0x01E) 40#define hasAVX512F 0x0000004000000000 41 MOVQ $commpage64_version, BX 42 CMPW (BX), $13 // cpu_capabilities64 undefined in versions < 13 43 JL no_avx512 44 MOVQ $commpage64_cpu_capabilities64, BX 45 MOVQ $hasAVX512F, CX 46 TESTQ (BX), CX 47 JZ no_avx512 48 MOVB $1, ret+0(FP) 49no_avx512: 50#endif 51#endif 52 RET 53