Debian Codegraph @

cpu/cpu_test.go

raw
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 package cpu_test
6
7 import (
8 "runtime"
9 "testing"
10
11 "golang.org/x/sys/cpu"
12 )
13
14 func TestAMD64minimalFeatures(t *testing.T) {
15 if runtime.GOARCH == "amd64" {
16 if !cpu.Initialized {
17 t.Fatal("Initialized expected true, got false")
18 }
19 if !cpu.X86.HasSSE2 {
20 t.Fatal("HasSSE2 expected true, got false")
21 }
22 }
23 }
24
25 func TestAVX2hasAVX(t *testing.T) {
26 if runtime.GOARCH == "amd64" {
27 if cpu.X86.HasAVX2 && !cpu.X86.HasAVX {
28 t.Fatal("HasAVX expected true, got false")
29 }
30 }
31 }
32
33 func TestAVX512HasAVX2AndAVX(t *testing.T) {
34 if runtime.GOARCH == "amd64" {
35 if cpu.X86.HasAVX512 && !cpu.X86.HasAVX {
36 t.Fatal("HasAVX expected true, got false")
37 }
38 if cpu.X86.HasAVX512 && !cpu.X86.HasAVX2 {
39 t.Fatal("HasAVX2 expected true, got false")
40 }
41 }
42 }
43
44 func TestAVX512BF16HasAVX512(t *testing.T) {
45 if runtime.GOARCH == "amd64" {
46 if cpu.X86.HasAVX512BF16 && !cpu.X86.HasAVX512 {
47 t.Fatal("HasAVX512 expected true, got false")
48 }
49 }
50 }
51
52 func TestAVXVNNIHasAVX(t *testing.T) {
53 if cpu.X86.HasAVXVNNI && !cpu.X86.HasAVX {
54 t.Fatal("HasAVX expected true, got false")
55 }
56 }
57
58 func TestAVXIFMAHasAVXVNNIAndAVX(t *testing.T) {
59 if cpu.X86.HasAVXIFMA && !cpu.X86.HasAVX {
60 t.Fatal("HasAVX expected true, got false")
61 }
62
63 if cpu.X86.HasAVXIFMA && !cpu.X86.HasAVXVNNI {
64 t.Fatal("HasAVXVNNI expected true, got false")
65 }
66 }
67
68 func TestAVXVNNIInt8HasAVXVNNIAndAVX(t *testing.T) {
69 if cpu.X86.HasAVXVNNIInt8 && !cpu.X86.HasAVXVNNI {
70 t.Fatal("HasAVXVNNI expected true, got false")
71 }
72
73 if cpu.X86.HasAVXVNNIInt8 && !cpu.X86.HasAVX {
74 t.Fatal("HasAVX expected true, got false")
75 }
76 }
77
78 func TestARM64minimalFeatures(t *testing.T) {
79 if runtime.GOARCH != "arm64" || runtime.GOOS == "ios" {
80 return
81 }
82 if !cpu.ARM64.HasASIMD {
83 t.Fatal("HasASIMD expected true, got false")
84 }
85 if !cpu.ARM64.HasFP {
86 t.Fatal("HasFP expected true, got false")
87 }
88 }
89
90 func TestLOONG64Initialized(t *testing.T) {
91 if runtime.GOARCH == "loong64" {
92 if !cpu.Initialized {
93 t.Fatal("Initialized expected true, got false")
94 }
95 }
96 }
97
98 func TestMIPS64Initialized(t *testing.T) {
99 if runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le" {
100 if !cpu.Initialized {
101 t.Fatal("Initialized expected true, got false")
102 }
103 }
104 }
105
106 func TestRISCV64Initialized(t *testing.T) {
107 if runtime.GOARCH == "riscv64" {
108 if !cpu.Initialized {
109 t.Fatal("Initialized expected true, got false")
110 }
111 }
112 }
113
114 // On ppc64x, the ISA bit for POWER8 should always be set on POWER8 and beyond.
115 func TestPPC64minimalFeatures(t *testing.T) {
116 // Do not run this with gccgo on ppc64, as it doesn't have POWER8 as a minimum
117 // requirement.
118 if runtime.Compiler == "gccgo" && runtime.GOARCH == "ppc64" {
119 t.Skip("gccgo does not require POWER8 on ppc64; skipping")
120 }
121 if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
122 if !cpu.PPC64.IsPOWER8 {
123 t.Fatal("IsPOWER8 expected true, got false")
124 }
125 }
126 }