Black Lives Matter. Support the Equal Justice Initiative.

Source file src/internal/cpu/cpu_x86_test.go

Documentation: internal/cpu

     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  // +build 386 amd64
     6  
     7  package cpu_test
     8  
     9  import (
    10  	. "internal/cpu"
    11  	"os"
    12  	"runtime"
    13  	"testing"
    14  )
    15  
    16  func TestX86ifAVX2hasAVX(t *testing.T) {
    17  	if X86.HasAVX2 && !X86.HasAVX {
    18  		t.Fatalf("HasAVX expected true when HasAVX2 is true, got false")
    19  	}
    20  }
    21  
    22  func TestDisableSSE2(t *testing.T) {
    23  	runDebugOptionsTest(t, "TestSSE2DebugOption", "cpu.sse2=off")
    24  }
    25  
    26  func TestSSE2DebugOption(t *testing.T) {
    27  	MustHaveDebugOptionsSupport(t)
    28  
    29  	if os.Getenv("GODEBUG") != "cpu.sse2=off" {
    30  		t.Skipf("skipping test: GODEBUG=cpu.sse2=off not set")
    31  	}
    32  
    33  	want := runtime.GOARCH != "386" // SSE2 can only be disabled on 386.
    34  	if got := X86.HasSSE2; got != want {
    35  		t.Errorf("X86.HasSSE2 on %s expected %v, got %v", runtime.GOARCH, want, got)
    36  	}
    37  }
    38  
    39  func TestDisableSSE3(t *testing.T) {
    40  	runDebugOptionsTest(t, "TestSSE3DebugOption", "cpu.sse3=off")
    41  }
    42  
    43  func TestSSE3DebugOption(t *testing.T) {
    44  	MustHaveDebugOptionsSupport(t)
    45  
    46  	if os.Getenv("GODEBUG") != "cpu.sse3=off" {
    47  		t.Skipf("skipping test: GODEBUG=cpu.sse3=off not set")
    48  	}
    49  
    50  	want := false
    51  	if got := X86.HasSSE3; got != want {
    52  		t.Errorf("X86.HasSSE3 expected %v, got %v", want, got)
    53  	}
    54  }
    55  

View as plain text