File: cpuid_amd64.go

package info (click to toggle)
golang-github-henrydcase-nobs 0.1%2Bgit20200305.7d891c7-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 2,904 kB
  • sloc: asm: 6,587; makefile: 53; python: 38
file content (33 lines) | stat: -rw-r--r-- 924 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// +build amd64,!noasm

// Sets capabilities flags for x86 according to information received from
// CPUID. It was written in accordance with
// "IntelĀ® 64 and IA-32 Architectures Developer's Manual: Vol. 2A".
// https://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-vol-2a-manual.html

package utils

// Performs CPUID and returns values of registers
// go:nosplit
func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)

// Returns true in case bit 'n' in 'bits' is set, otherwise false
func bitn(bits uint32, n uint8) bool {
	return (bits>>n)&1 == 1
}

func init() {
	// CPUID returns max possible input that can be requested
	max, _, _, _ := cpuid(0, 0)
	if max < 7 {
		return
	}

	_, ecx, _, _ := cpuid(1, 0)
	X86.HasAES = bitn(ecx, 25)

	_, ebx, _, _ := cpuid(7, 0)
	X86.HasBMI2 = bitn(ebx, 8)
	X86.HasADX = bitn(ebx, 19)
	X86.HasRDSEED = bitn(ebx, 18)
}