style: modernize the new tooling code to match the repo conventions
This commit is contained in:
+9
-6
@@ -10,7 +10,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"slices"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"sourcedock.dev/petrbalvin/gasm-devkit/arch"
|
"sourcedock.dev/petrbalvin/gasm-devkit/arch"
|
||||||
@@ -80,9 +81,9 @@ mnemonic, so the audit tracks whatever toolchain `+"`go env GOROOT`"+` names.
|
|||||||
// GO-ONLY is not enumerable by probing: Go's table is only visible
|
// GO-ONLY is not enumerable by probing: Go's table is only visible
|
||||||
// through names we already know, so nothing can be reported there.
|
// through names we already know, so nothing can be reported there.
|
||||||
|
|
||||||
sort.Strings(superset)
|
slices.Sort(superset)
|
||||||
sort.Strings(backlog)
|
slices.Sort(backlog)
|
||||||
sort.Strings(shared)
|
slices.Sort(shared)
|
||||||
|
|
||||||
w := os.Stdout
|
w := os.Stdout
|
||||||
fmt.Fprintf(w, "gasm table (amd64, families excluded): %d mnemonics\n", len(names))
|
fmt.Fprintf(w, "gasm table (amd64, families excluded): %d mnemonics\n", len(names))
|
||||||
@@ -176,8 +177,10 @@ func probeGoAsm(names []string) (map[string]bool, error) {
|
|||||||
if m == nil {
|
if m == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var lineNo int
|
lineNo, err := strconv.Atoi(m[1])
|
||||||
fmt.Sscanf(m[1], "%d", &lineNo)
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if name, ok := lineMnemonic[lineNo]; ok && unrecognizedRe.MatchString(l) {
|
if name, ok := lineMnemonic[lineNo]; ok && unrecognizedRe.MatchString(l) {
|
||||||
result[name] = false
|
result[name] = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ bodies, place the file in the kernel's package, and run it in CI.
|
|||||||
|
|
||||||
fmt.Fprintf(&out, "func Test%sDifferential(t *testing.T) {\n", strings.ToUpper(name[:1])+name[1:])
|
fmt.Fprintf(&out, "func Test%sDifferential(t *testing.T) {\n", strings.ToUpper(name[:1])+name[1:])
|
||||||
fmt.Fprintf(&out, "\trng := rand.New(rand.NewSource(1))\n")
|
fmt.Fprintf(&out, "\trng := rand.New(rand.NewSource(1))\n")
|
||||||
fmt.Fprintf(&out, "\tfor iter := 0; iter < 1000; iter++ {\n")
|
fmt.Fprintf(&out, "\tfor range 1000 {\n")
|
||||||
// Seed two independent argument sets per iteration: the kernel runs
|
// Seed two independent argument sets per iteration: the kernel runs
|
||||||
// on set A, the portable reference on set B, so in-place writes
|
// on set A, the portable reference on set B, so in-place writes
|
||||||
// through pointer/slice arguments cannot contaminate the other side.
|
// through pointer/slice arguments cannot contaminate the other side.
|
||||||
@@ -97,11 +97,11 @@ bodies, place the file in the kernel's package, and run it in CI.
|
|||||||
fmt.Fprintf(&out, "\t\tgot := %s(%s)\n", name, strings.Join(aArgs, ", "))
|
fmt.Fprintf(&out, "\t\tgot := %s(%s)\n", name, strings.Join(aArgs, ", "))
|
||||||
fmt.Fprintf(&out, "\t\twant := %sPortable(%s)\n", name, strings.Join(bArgs, ", "))
|
fmt.Fprintf(&out, "\t\twant := %sPortable(%s)\n", name, strings.Join(bArgs, ", "))
|
||||||
fmt.Fprintf(&out, "\t\tif !bytes.Equal(outputBytes(got), outputBytes(want)) {\n")
|
fmt.Fprintf(&out, "\t\tif !bytes.Equal(outputBytes(got), outputBytes(want)) {\n")
|
||||||
fmt.Fprintf(&out, "\t\t\tt.Fatalf(\"iter %%d: kernel diverges from the portable spec\", iter)\n")
|
fmt.Fprintf(&out, "\t\t\tt.Fatalf(\"kernel diverges from the portable spec (seed 1, deterministic)\")\n")
|
||||||
fmt.Fprintf(&out, "\t\t}\n")
|
fmt.Fprintf(&out, "\t\t}\n")
|
||||||
for _, s := range sliceNames {
|
for _, s := range sliceNames {
|
||||||
fmt.Fprintf(&out, "\t\tif !bytes.Equal(outputBytes(%sA), outputBytes(%sB)) {\n", s, s)
|
fmt.Fprintf(&out, "\t\tif !bytes.Equal(outputBytes(%sA), outputBytes(%sB)) {\n", s, s)
|
||||||
fmt.Fprintf(&out, "\t\t\tt.Fatalf(\"iter %%d: kernel mutated %%s differently\", iter, %q)\n", s)
|
fmt.Fprintf(&out, "\t\t\tt.Fatalf(\"kernel mutated %%q differently (seed 1, deterministic)\", %q)\n", s)
|
||||||
fmt.Fprintf(&out, "\t\t}\n")
|
fmt.Fprintf(&out, "\t\t}\n")
|
||||||
}
|
}
|
||||||
fmt.Fprintf(&out, "\t}\n}\n\n")
|
fmt.Fprintf(&out, "\t}\n}\n\n")
|
||||||
@@ -334,7 +334,7 @@ func outputBytes(v any) []byte {
|
|||||||
return b
|
return b
|
||||||
case int:
|
case int:
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
for i := 0; i < 8; i++ {
|
for i := range 8 {
|
||||||
b[i] = byte(uint64(t) >> (8 * i))
|
b[i] = byte(uint64(t) >> (8 * i))
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
|
|||||||
+6
-13
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@@ -200,21 +201,13 @@ func ParseScalarArgs(spec string) (map[string]uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func splitScalar(part string) (string, uint64, error) {
|
func splitScalar(part string) (string, uint64, error) {
|
||||||
eq := strings.Index(part, "=")
|
name, valStr, ok := strings.Cut(part, "=")
|
||||||
if eq <= 0 {
|
if !ok || strings.TrimSpace(name) == "" {
|
||||||
return "", 0, fmt.Errorf("scalar arg spec %q: want name=value", part)
|
return "", 0, fmt.Errorf("scalar arg spec %q: want name=value", part)
|
||||||
}
|
}
|
||||||
name := strings.TrimSpace(part[:eq])
|
val, err := strconv.ParseUint(strings.TrimSpace(valStr), 0, 64)
|
||||||
valStr := strings.TrimSpace(part[eq+1:])
|
if err != nil {
|
||||||
var val uint64
|
|
||||||
var err error
|
|
||||||
if strings.HasPrefix(valStr, "0x") || strings.HasPrefix(valStr, "0X") {
|
|
||||||
_, err = fmt.Sscanf(valStr, "0x%x", &val)
|
|
||||||
} else {
|
|
||||||
_, err = fmt.Sscanf(valStr, "%d", &val)
|
|
||||||
}
|
|
||||||
if err != nil || name == "" {
|
|
||||||
return "", 0, fmt.Errorf("scalar arg spec %q: bad value", part)
|
return "", 0, fmt.Errorf("scalar arg spec %q: bad value", part)
|
||||||
}
|
}
|
||||||
return name, val, nil
|
return strings.TrimSpace(name), val, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user