| 5 | ) |
| 6 | |
| 7 | func (s *System) GetCpuArchitecture() (string, error) { |
| 8 | // Check if we are on i686; otherwiese we know it is i586 with MMX as Go does require MMX instructions |
| 9 | isI686 := hasCMOV() |
| 10 | // We need to check for LM (Long Mode) as there are CPUs that support SSE2 but not x86_64 (e.g. Core Duo) |
| 11 | isX86_64 := isI686 && hasLM() && cpu.X86.HasSSE2 |
| 12 | isX86_64V2 := isX86_64 && cpu.X86.HasPOPCNT && cpu.X86.HasSSE3 && cpu.X86.HasSSE41 && cpu.X86.HasSSE42 && cpu.X86.HasSSSE3 |
| 13 | isX86_64V3 := isX86_64V2 && cpu.X86.HasAVX && cpu.X86.HasAVX2 && cpu.X86.HasBMI1 && cpu.X86.HasBMI2 && cpu.X86.HasFMA && cpu.X86.HasOSXSAVE |
| 14 | isX86_64V4 := isX86_64V3 && cpu.X86.HasAVX512F && cpu.X86.HasAVX512BW && cpu.X86.HasAVX512CD && cpu.X86.HasAVX512DQ && cpu.X86.HasAVX512VL |
| 15 | |
| 16 | switch { |
| 17 | case isX86_64V4: |
| 18 | return X86_64_V4, nil |
| 19 | case isX86_64V3: |
| 20 | return X86_64_V3, nil |
| 21 | case isX86_64V2: |
| 22 | return X86_64_V2, nil |
| 23 | case isX86_64: |
| 24 | return X86_64, nil |
| 25 | case isI686: |
| 26 | return I686, nil |
| 27 | default: |
| 28 | return I586, nil |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // Implemented at system_386.s |
| 33 | func hasLM() bool |