github.com/nibnait/go-learn@v0.0.0-20220227013611-dfa47ea6d2da/src/pkg/mod/golang.org/x/sys@v0.0.0-20210630005230-0f9fa26af87c/cpu/cpu_test.go (about)

     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 TestARM64minimalFeatures(t *testing.T) {
    45  	if runtime.GOARCH != "arm64" || (runtime.GOOS == "darwin" || runtime.GOOS == "ios") {
    46  		return
    47  	}
    48  	if !cpu.ARM64.HasASIMD {
    49  		t.Fatal("HasASIMD expected true, got false")
    50  	}
    51  	if !cpu.ARM64.HasFP {
    52  		t.Fatal("HasFP expected true, got false")
    53  	}
    54  }
    55  
    56  func TestMIPS64Initialized(t *testing.T) {
    57  	if runtime.GOARCH == "mips64" || runtime.GOARCH == "mips64le" {
    58  		if !cpu.Initialized {
    59  			t.Fatal("Initialized expected true, got false")
    60  		}
    61  	}
    62  }
    63  
    64  // On ppc64x, the ISA bit for POWER8 should always be set on POWER8 and beyond.
    65  func TestPPC64minimalFeatures(t *testing.T) {
    66  	// Do not run this with gccgo on ppc64, as it doesn't have POWER8 as a minimum
    67  	// requirement.
    68  	if runtime.Compiler == "gccgo" && runtime.GOARCH == "ppc64" {
    69  		t.Skip("gccgo does not require POWER8 on ppc64; skipping")
    70  	}
    71  	if runtime.GOARCH == "ppc64" || runtime.GOARCH == "ppc64le" {
    72  		if !cpu.PPC64.IsPOWER8 {
    73  			t.Fatal("IsPOWER8 expected true, got false")
    74  		}
    75  	}
    76  }