summaryrefslogtreecommitdiffstats
path: root/src/cmd/compile/internal/ssa/fmahash_test.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-16 19:19:13 +0000
commitccd992355df7192993c666236047820244914598 (patch)
treef00fea65147227b7743083c6148396f74cd66935 /src/cmd/compile/internal/ssa/fmahash_test.go
parentInitial commit. (diff)
downloadgolang-1.21-ccd992355df7192993c666236047820244914598.tar.xz
golang-1.21-ccd992355df7192993c666236047820244914598.zip
Adding upstream version 1.21.8.upstream/1.21.8
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cmd/compile/internal/ssa/fmahash_test.go')
-rw-r--r--src/cmd/compile/internal/ssa/fmahash_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/fmahash_test.go b/src/cmd/compile/internal/ssa/fmahash_test.go
new file mode 100644
index 0000000..dfa1aa1
--- /dev/null
+++ b/src/cmd/compile/internal/ssa/fmahash_test.go
@@ -0,0 +1,52 @@
+// Copyright 2022 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.
+
+package ssa_test
+
+import (
+ "internal/testenv"
+ "path/filepath"
+ "regexp"
+ "runtime"
+ "testing"
+)
+
+// TestFmaHash checks that the hash-test machinery works properly for a single case.
+// It also runs ssa/check and gccheck to be sure that those are checked at least a
+// little in each run.bash. It does not check or run the generated code.
+// The test file is however a useful example of fused-vs-cascaded multiply-add.
+func TestFmaHash(t *testing.T) {
+ switch runtime.GOOS {
+ case "linux", "darwin":
+ default:
+ t.Skipf("Slow test, usually avoid it, os=%s not linux or darwin", runtime.GOOS)
+ }
+ switch runtime.GOARCH {
+ case "amd64", "arm64":
+ default:
+ t.Skipf("Slow test, usually avoid it, arch=%s not amd64 or arm64", runtime.GOARCH)
+ }
+
+ testenv.MustHaveGoBuild(t)
+ gocmd := testenv.GoToolPath(t)
+ tmpdir := t.TempDir()
+ source := filepath.Join("testdata", "fma.go")
+ output := filepath.Join(tmpdir, "fma.exe")
+ cmd := testenv.Command(t, gocmd, "build", "-o", output, source)
+ // The hash-dependence on file path name is dodged by specifying "all hashes ending in 1" plus "all hashes ending in 0"
+ // i.e., all hashes. This will print all the FMAs; this test is only interested in one of them (that should appear near the end).
+ cmd.Env = append(cmd.Env, "GOCOMPILEDEBUG=fmahash=1/0", "GOOS=linux", "GOARCH=arm64", "HOME="+tmpdir)
+ t.Logf("%v", cmd)
+ t.Logf("%v", cmd.Env)
+ b, e := cmd.CombinedOutput()
+ if e != nil {
+ t.Error(e)
+ }
+ s := string(b) // Looking for "GOFMAHASH triggered main.main:24"
+ re := "fmahash(0?) triggered .*fma.go:29:..;.*fma.go:18:.."
+ match := regexp.MustCompile(re)
+ if !match.MatchString(s) {
+ t.Errorf("Expected to match '%s' with \n-----\n%s-----", re, s)
+ }
+}