2018-01-26 04:14:27 -07:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2019-10-10 10:16:54 -06:00
|
|
|
// +build 386 amd64
|
2018-01-26 04:14:27 -07:00
|
|
|
|
|
|
|
package cpu_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "internal/cpu"
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestX86ifAVX2hasAVX(t *testing.T) {
|
|
|
|
if X86.HasAVX2 && !X86.HasAVX {
|
|
|
|
t.Fatalf("HasAVX expected true when HasAVX2 is true, got false")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDisableSSE2(t *testing.T) {
|
2018-11-14 12:48:40 -07:00
|
|
|
runDebugOptionsTest(t, "TestSSE2DebugOption", "cpu.sse2=off")
|
2018-01-26 04:14:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSSE2DebugOption(t *testing.T) {
|
2018-10-12 08:48:38 -06:00
|
|
|
MustHaveDebugOptionsSupport(t)
|
2018-01-26 04:14:27 -07:00
|
|
|
|
2018-11-14 12:48:40 -07:00
|
|
|
if os.Getenv("GODEBUG") != "cpu.sse2=off" {
|
|
|
|
t.Skipf("skipping test: GODEBUG=cpu.sse2=off not set")
|
2018-01-26 04:14:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
want := runtime.GOARCH != "386" // SSE2 can only be disabled on 386.
|
|
|
|
if got := X86.HasSSE2; got != want {
|
|
|
|
t.Errorf("X86.HasSSE2 on %s expected %v, got %v", runtime.GOARCH, want, got)
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 11:17:21 -06:00
|
|
|
|
|
|
|
func TestDisableSSE3(t *testing.T) {
|
2018-11-14 12:48:40 -07:00
|
|
|
runDebugOptionsTest(t, "TestSSE3DebugOption", "cpu.sse3=off")
|
2018-10-12 11:17:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSSE3DebugOption(t *testing.T) {
|
|
|
|
MustHaveDebugOptionsSupport(t)
|
|
|
|
|
2018-11-14 12:48:40 -07:00
|
|
|
if os.Getenv("GODEBUG") != "cpu.sse3=off" {
|
|
|
|
t.Skipf("skipping test: GODEBUG=cpu.sse3=off not set")
|
2018-10-12 11:17:21 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
want := false
|
|
|
|
if got := X86.HasSSE3; got != want {
|
|
|
|
t.Errorf("X86.HasSSE3 expected %v, got %v", want, got)
|
|
|
|
}
|
|
|
|
}
|