cpu_x86.s 1.5 KB

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