mirror of
https://github.com/golang/go
synced 2024-11-21 18:04:40 -07:00
test: avoid interface conversion in rotate.go
It is not necessary for the test to be effective and uses a lot of resources in the compiler. Memory usage is halved and compilation around 8x faster. R=golang-dev, r, rsc, r CC=golang-dev https://golang.org/cl/6290044
This commit is contained in:
parent
787adb6eb3
commit
7ab62b0bac
@ -9,7 +9,7 @@
|
|||||||
// Generate test of shift and rotate by constants.
|
// Generate test of shift and rotate by constants.
|
||||||
// The output is compiled and run.
|
// The output is compiled and run.
|
||||||
//
|
//
|
||||||
// The output takes around a minute or two to compile, link, and run
|
// The output takes around a gigabyte of memory to compile, link, and run
|
||||||
// but it is only done during ./run, not in normal builds using run.go.
|
// but it is only done during ./run, not in normal builds using run.go.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
@ -19,6 +19,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -30,6 +31,9 @@ func main() {
|
|||||||
fmt.Fprintf(b, "%s\n", prolog)
|
fmt.Fprintf(b, "%s\n", prolog)
|
||||||
|
|
||||||
for logBits := uint(3); logBits <= 6; logBits++ {
|
for logBits := uint(3); logBits <= 6; logBits++ {
|
||||||
|
typ := fmt.Sprintf("int%d", 1<<logBits)
|
||||||
|
fmt.Fprint(b, strings.Replace(checkFunc, "XXX", typ, -1))
|
||||||
|
fmt.Fprint(b, strings.Replace(checkFunc, "XXX", "u"+typ, -1))
|
||||||
for mode := 0; mode < 1<<2; mode++ {
|
for mode := 0; mode < 1<<2; mode++ {
|
||||||
gentest(b, 1<<logBits, mode&1 != 0, mode&2 != 0)
|
gentest(b, 1<<logBits, mode&1 != 0, mode&2 != 0)
|
||||||
}
|
}
|
||||||
@ -67,7 +71,16 @@ var (
|
|||||||
|
|
||||||
var nfail = 0
|
var nfail = 0
|
||||||
|
|
||||||
func check(desc string, have, want interface{}) {
|
func main() {
|
||||||
|
if nfail > 0 {
|
||||||
|
fmt.Printf("BUG\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
const checkFunc = `
|
||||||
|
func check_XXX(desc string, have, want XXX) {
|
||||||
if have != want {
|
if have != want {
|
||||||
nfail++
|
nfail++
|
||||||
fmt.Printf("%s = %T(%#x), want %T(%#x)\n", desc, have, have, want, want)
|
fmt.Printf("%s = %T(%#x), want %T(%#x)\n", desc, have, have, want, want)
|
||||||
@ -77,13 +90,6 @@ func check(desc string, have, want interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
|
||||||
if nfail > 0 {
|
|
||||||
fmt.Printf("BUG\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -144,8 +150,8 @@ func gentest(b *bufio.Writer, bits uint, unsigned, inverted bool) {
|
|||||||
result = fmt.Sprintf("%#x", v)
|
result = fmt.Sprintf("%#x", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(b, "\tcheck(%q, %s, %s(%s))\n", expr1, expr1, typ, result)
|
fmt.Fprintf(b, "\tcheck_%s(%q, %s, %s(%s))\n", typ, expr1, expr1, typ, result)
|
||||||
fmt.Fprintf(b, "\tcheck(%q, %s, %s(%s))\n", expr2, expr2, typ, result)
|
fmt.Fprintf(b, "\tcheck_%s(%q, %s, %s(%s))\n", typ, expr2, expr2, typ, result)
|
||||||
|
|
||||||
// Chop test into multiple functions so that there's not one
|
// Chop test into multiple functions so that there's not one
|
||||||
// enormous function to compile/link.
|
// enormous function to compile/link.
|
||||||
|
Loading…
Reference in New Issue
Block a user