github.com/icodeface/tls@v0.0.0-20230910023335-34df9250cd12/internal/cpu/cpu_x86_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 //go:build 386 || amd64 || amd64p32 6 // +build 386 amd64 amd64p32 7 8 package cpu_test 9 10 import ( 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 }