Skip to content

Commit

Permalink
cmd/compile: add remaining >v1 instructions to v1-only test
Browse files Browse the repository at this point in the history
roundsd and FMA (vfmadd231sd).

Change-Id: I2d91332667e577bd9bb903ac58904f62b8454128
Reviewed-on: https://go-review.googlesource.com/c/go/+/354069
Trust: Keith Randall <[email protected]>
Run-TryBot: Keith Randall <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
  • Loading branch information
randall77 committed Oct 5, 2021
1 parent 5140ad1 commit 5d946f1
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/cmd/compile/internal/amd64/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"internal/testenv"
"io"
"math"
"math/bits"
"os"
"os/exec"
Expand Down Expand Up @@ -107,7 +108,7 @@ func clobber(t *testing.T, src string, dst *os.File, opcodes map[string]bool) {
if err := cmd.Start(); err != nil {
t.Fatal(err)
}
re = regexp.MustCompile(`^\s*([0-9a-f]+):\s*((?:[0-9a-f][0-9a-f] )+)\s*([a-z]+)`)
re = regexp.MustCompile(`^\s*([0-9a-f]+):\s*((?:[0-9a-f][0-9a-f] )+)\s*([a-z0-9]+)`)
}

// Find all the instruction addresses we need to edit.
Expand Down Expand Up @@ -209,7 +210,8 @@ var featureToOpcodes = map[string][]string{
// native objdump doesn't include [QL] on linux.
"popcnt": []string{"popcntq", "popcntl", "popcnt"},
"bmi1": []string{"andnq", "andnl", "andn", "blsiq", "blsil", "blsi", "blsmskq", "blsmskl", "blsmsk", "blsrq", "blsrl", "blsr", "tzcntq", "tzcntl", "tzcnt"},
// TODO: more?
"sse41": []string{"roundsd"},
"fma": []string{"vfmadd231sd"},
}

// Test to use POPCNT instruction, if available
Expand Down Expand Up @@ -333,3 +335,34 @@ func TestTrailingZeros(t *testing.T) {
}
}
}

func TestRound(t *testing.T) {
for _, tt := range []struct {
x, want float64
}{
{1.4, 1},
{1.5, 2},
{1.6, 2},
{2.4, 2},
{2.5, 2},
{2.6, 3},
} {
if got := math.RoundToEven(tt.x); got != tt.want {
t.Errorf("RoundToEven(%f) = %f, want %f", tt.x, got, tt.want)
}
}
}

func TestFMA(t *testing.T) {
for _, tt := range []struct {
x, y, z, want float64
}{
{2, 3, 4, 10},
{3, 4, 5, 17},
} {
if got := math.FMA(tt.x, tt.y, tt.z); got != tt.want {
t.Errorf("FMA(%f,%f,%f) = %f, want %f", tt.x, tt.y, tt.z, got, tt.want)
}
}

}

0 comments on commit 5d946f1

Please sign in to comment.