From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- gcc/testsuite/go.test/test/garbage/Makefile | 27 ++++ gcc/testsuite/go.test/test/garbage/parser.go | 215 +++++++++++++++++++++++++++ gcc/testsuite/go.test/test/garbage/peano.go | 137 +++++++++++++++++ gcc/testsuite/go.test/test/garbage/tree.go | 104 +++++++++++++ 4 files changed, 483 insertions(+) create mode 100644 gcc/testsuite/go.test/test/garbage/Makefile create mode 100644 gcc/testsuite/go.test/test/garbage/parser.go create mode 100644 gcc/testsuite/go.test/test/garbage/peano.go create mode 100644 gcc/testsuite/go.test/test/garbage/tree.go (limited to 'gcc/testsuite/go.test/test/garbage') diff --git a/gcc/testsuite/go.test/test/garbage/Makefile b/gcc/testsuite/go.test/test/garbage/Makefile new file mode 100644 index 000000000..ab29e0956 --- /dev/null +++ b/gcc/testsuite/go.test/test/garbage/Makefile @@ -0,0 +1,27 @@ +# Copyright 2010 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. + +include ../../src/Make.inc + +ALL=\ + parser\ + peano\ + tree\ + +all: $(addsuffix .out, $(ALL)) + +%.$O: %.go + $(GC) $*.go + +%.out: %.$O + $(LD) -o $@ $*.$O + +%.bench: %.out + ./$*.out + +bench: $(addsuffix .bench, $(ALL)) + +clean: + rm -f *.[$(OS)] $(addsuffix .out, $(ALL)) + diff --git a/gcc/testsuite/go.test/test/garbage/parser.go b/gcc/testsuite/go.test/test/garbage/parser.go new file mode 100644 index 000000000..cf68737fb --- /dev/null +++ b/gcc/testsuite/go.test/test/garbage/parser.go @@ -0,0 +1,215 @@ +// Copyright 2010 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. + +// Garbage collection benchmark: parse Go packages repeatedly. + +package main + +import ( + "flag" + "fmt" + "go/ast" + "go/parser" + "os" + "path" + "runtime" + "strings" + "time" +) + +func isGoFile(dir *os.FileInfo) bool { + return dir.IsRegular() && + !strings.HasPrefix(dir.Name, ".") && // ignore .files + path.Ext(dir.Name) == ".go" +} + +func isPkgFile(dir *os.FileInfo) bool { + return isGoFile(dir) && + !strings.HasSuffix(dir.Name, "_test.go") // ignore test files +} + +func pkgName(filename string) string { + file, err := parser.ParseFile(filename, nil, parser.PackageClauseOnly) + if err != nil || file == nil { + return "" + } + return file.Name.Name +} + +func parseDir(dirpath string) map[string]*ast.Package { + // the package name is the directory name within its parent + // (use dirname instead of path because dirname is clean; i.e. has no trailing '/') + _, pkgname := path.Split(dirpath) + + // filter function to select the desired .go files + filter := func(d *os.FileInfo) bool { + if isPkgFile(d) { + // Some directories contain main packages: Only accept + // files that belong to the expected package so that + // parser.ParsePackage doesn't return "multiple packages + // found" errors. + // Additionally, accept the special package name + // fakePkgName if we are looking at cmd documentation. + name := pkgName(dirpath + "/" + d.Name) + return name == pkgname + } + return false + } + + // get package AST + pkgs, err := parser.ParseDir(dirpath, filter, parser.ParseComments) + if err != nil { + println("parse", dirpath, err.String()) + panic("fail") + } + return pkgs +} + +func main() { + st := &runtime.MemStats + n := flag.Int("n", 4, "iterations") + p := flag.Int("p", len(packages), "# of packages to keep in memory") + flag.BoolVar(&st.DebugGC, "d", st.DebugGC, "print GC debugging info (pause times)") + flag.Parse() + + var t0 int64 + pkgroot := runtime.GOROOT() + "/src/pkg/" + for pass := 0; pass < 2; pass++ { + // Once the heap is grown to full size, reset counters. + // This hides the start-up pauses, which are much smaller + // than the normal pauses and would otherwise make + // the average look much better than it actually is. + st.NumGC = 0 + st.PauseNs = 0 + t0 = time.Nanoseconds() + + for i := 0; i < *n; i++ { + parsed := make([]map[string]*ast.Package, *p) + for j := range parsed { + parsed[j] = parseDir(pkgroot + packages[j%len(packages)]) + } + } + runtime.GC() + } + t1 := time.Nanoseconds() + + fmt.Printf("Alloc=%d/%d Heap=%d Mallocs=%d PauseTime=%.3f/%d = %.3f\n", + st.Alloc, st.TotalAlloc, + st.Sys, + st.Mallocs, float64(st.PauseNs)/1e9, + st.NumGC, float64(st.PauseNs)/1e9/float64(st.NumGC)) + + fmt.Printf("%10s %10s %10s\n", "size", "#alloc", "#free") + for _, s := range st.BySize { + fmt.Printf("%10d %10d %10d\n", s.Size, s.Mallocs, s.Frees) + } + + // Standard gotest benchmark output, collected by build dashboard. + fmt.Printf("garbage.BenchmarkParser %d %d ns/op\n", *n, (t1-t0)/int64(*n)) + fmt.Printf("garbage.BenchmarkParserPause %d %d ns/op\n", st.NumGC, int64(st.PauseNs)/int64(st.NumGC)) +} + + +var packages = []string{ + "archive/tar", + "asn1", + "big", + "bufio", + "bytes", + "cmath", + "compress/flate", + "compress/gzip", + "compress/zlib", + "container/heap", + "container/list", + "container/ring", + "container/vector", + "crypto/aes", + "crypto/block", + "crypto/blowfish", + "crypto/hmac", + "crypto/md4", + "crypto/md5", + "crypto/rand", + "crypto/rc4", + "crypto/rsa", + "crypto/sha1", + "crypto/sha256", + "crypto/sha512", + "crypto/subtle", + "crypto/tls", + "crypto/x509", + "crypto/xtea", + "debug/dwarf", + "debug/macho", + "debug/elf", + "debug/gosym", + "debug/proc", + "ebnf", + "encoding/ascii85", + "encoding/base64", + "encoding/binary", + "encoding/git85", + "encoding/hex", + "encoding/pem", + "exec", + "exp/datafmt", + "exp/draw", + "exp/eval", + "exp/iterable", + "expvar", + "flag", + "fmt", + "go/ast", + "go/doc", + "go/parser", + "go/printer", + "go/scanner", + "go/token", + "gob", + "hash", + "hash/adler32", + "hash/crc32", + "hash/crc64", + "http", + "image", + "image/jpeg", + "image/png", + "io", + "io/ioutil", + "json", + "log", + "math", + "mime", + "net", + "nntp", + "os", + "os/signal", + "patch", + "path", + "rand", + "reflect", + "regexp", + "rpc", + "runtime", + "scanner", + "sort", + "strconv", + "strings", + "sync", + "syscall", + "syslog", + "tabwriter", + "template", + "testing", + "testing/iotest", + "testing/quick", + "testing/script", + "time", + "unicode", + "utf8", + "utf16", + "websocket", + "xml", +} diff --git a/gcc/testsuite/go.test/test/garbage/peano.go b/gcc/testsuite/go.test/test/garbage/peano.go new file mode 100644 index 000000000..b026354e8 --- /dev/null +++ b/gcc/testsuite/go.test/test/garbage/peano.go @@ -0,0 +1,137 @@ +// $G $F.go && $L $F.$A && ./$A.out + +// Copyright 2009 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 main + +import ( + "fmt" + "runtime" + "time" +) + + +type Number struct { + next *Number +} + + +// ------------------------------------- +// Peano primitives + +func zero() *Number { return nil } + + +func is_zero(x *Number) bool { return x == nil } + + +func add1(x *Number) *Number { + e := new(Number) + e.next = x + return e +} + + +func sub1(x *Number) *Number { return x.next } + + +func add(x, y *Number) *Number { + if is_zero(y) { + return x + } + + return add(add1(x), sub1(y)) +} + + +func mul(x, y *Number) *Number { + if is_zero(x) || is_zero(y) { + return zero() + } + + return add(mul(x, sub1(y)), x) +} + + +func fact(n *Number) *Number { + if is_zero(n) { + return add1(zero()) + } + + return mul(fact(sub1(n)), n) +} + + +// ------------------------------------- +// Helpers to generate/count Peano integers + +func gen(n int) *Number { + if n > 0 { + return add1(gen(n - 1)) + } + + return zero() +} + + +func count(x *Number) int { + if is_zero(x) { + return 0 + } + + return count(sub1(x)) + 1 +} + + +func check(x *Number, expected int) { + var c = count(x) + if c != expected { + panic(fmt.Sprintf("error: found %d; expected %d", c, expected)) + } +} + + +// ------------------------------------- +// Test basic functionality + +func verify() { + check(zero(), 0) + check(add1(zero()), 1) + check(gen(10), 10) + + check(add(gen(3), zero()), 3) + check(add(zero(), gen(4)), 4) + check(add(gen(3), gen(4)), 7) + + check(mul(zero(), zero()), 0) + check(mul(gen(3), zero()), 0) + check(mul(zero(), gen(4)), 0) + check(mul(gen(3), add1(zero())), 3) + check(mul(add1(zero()), gen(4)), 4) + check(mul(gen(3), gen(4)), 12) + + check(fact(zero()), 1) + check(fact(add1(zero())), 1) + check(fact(gen(5)), 120) +} + + +// ------------------------------------- +// Factorial + + +func main() { + st := &runtime.MemStats + t0 := time.Nanoseconds() + verify() + for i := 0; i <= 9; i++ { + print(i, "! = ", count(fact(gen(i))), "\n") + } + runtime.GC() + t1 := time.Nanoseconds() + + fmt.Printf("garbage.BenchmarkPeano 1 %d ns/op\n", t1-t0) + fmt.Printf("garbage.BenchmarkPeanoPause %d %d ns/op\n", st.NumGC, int64(st.PauseNs)/int64(st.NumGC)) +} diff --git a/gcc/testsuite/go.test/test/garbage/tree.go b/gcc/testsuite/go.test/test/garbage/tree.go new file mode 100644 index 000000000..816693fbe --- /dev/null +++ b/gcc/testsuite/go.test/test/garbage/tree.go @@ -0,0 +1,104 @@ +/* +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + * Neither the name of "The Computer Language Benchmarks Game" nor the + name of "The Computer Language Shootout Benchmarks" nor the names of + its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. +*/ + +/* The Computer Language Benchmarks Game + * http://shootout.alioth.debian.org/ + * + * contributed by The Go Authors. + * based on C program by Kevin Carson + */ + +package main + +import ( + "flag" + "fmt" + "runtime" + "time" +) + +var n = flag.Int("n", 16, "depth") + +type Node struct { + item int + left, right *Node +} + +func bottomUpTree(item, depth int) *Node { + if depth <= 0 { + return &Node{item: item} + } + return &Node{item, bottomUpTree(2*item-1, depth-1), bottomUpTree(2*item, depth-1)} +} + +func (n *Node) itemCheck() int { + if n.left == nil { + return n.item + } + return n.item + n.left.itemCheck() - n.right.itemCheck() +} + +const minDepth = 4 + +func main() { + flag.Parse() + + t0 := time.Nanoseconds() + + maxDepth := *n + if minDepth+2 > *n { + maxDepth = minDepth + 2 + } + stretchDepth := maxDepth + 1 + + check := bottomUpTree(0, stretchDepth).itemCheck() + fmt.Printf("stretch tree of depth %d\t check: %d\n", stretchDepth, check) + + longLivedTree := bottomUpTree(0, maxDepth) + + for depth := minDepth; depth <= maxDepth; depth += 2 { + iterations := 1 << uint(maxDepth-depth+minDepth) + check = 0 + + for i := 1; i <= iterations; i++ { + check += bottomUpTree(i, depth).itemCheck() + check += bottomUpTree(-i, depth).itemCheck() + } + fmt.Printf("%d\t trees of depth %d\t check: %d\n", iterations*2, depth, check) + } + fmt.Printf("long lived tree of depth %d\t check: %d\n", maxDepth, longLivedTree.itemCheck()) + + t1 := time.Nanoseconds() + st := &runtime.MemStats + + // Standard gotest benchmark output, collected by build dashboard. + fmt.Printf("garbage.BenchmarkTree %d %d ns/op\n", *n, (t1-t0)/int64(*n)) + fmt.Printf("garbage.BenchmarkTreePause %d %d ns/op\n", st.NumGC, int64(st.PauseNs)/int64(st.NumGC)) + +} -- cgit v1.2.3