From f7ee99ec2a4a406382438bb0adaf706c4902b478 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 19:27:16 -0500 Subject: [PATCH 1/9] Reorganize makefile targets --- src/Makefile | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/src/Makefile b/src/Makefile index 484740b5df2ad..8998792da5ad3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -752,14 +752,13 @@ test/compile-fail/%.rustc.out.tmp: test/compile-fail/%.rs $(SREQ) $(CFG_QUIET)grep --text --quiet \ "$$(grep error-pattern $< | cut -d : -f 2- | tr -d '\n\r')" $@ -test/run-pass/%.boot$(CFG_EXE_SUFFIX): test/run-pass/%.rc $(BREQ) - @$(call CFG_ECHO, compile [boot]: $<) - $(BOOT) -o $@ $< +%.bc: %.rc $(SREQ) + @$(call CFG_ECHO, compile [rustc]: $<) + $(RUSTC) -o $@ $< -test/bench/shootout/%.boot$(CFG_EXE_SUFFIX): \ - test/bench/shootout/%.rs $(BREQ) - @$(call CFG_ECHO, compile [boot]: $<) - $(BOOT) -o $@ $< +%.bc: %.rs $(SREQ) + @$(call CFG_ECHO, compile [rustc]: $<) + $(RUSTC) -o $@ $< %.ll: %.bc @$(call CFG_ECHO, dis [llvm]: $<) @@ -782,26 +781,14 @@ test/bench/shootout/%.boot$(CFG_EXE_SUFFIX): \ @# programs, I\'ll live with the noise. -$(CFG_QUIET)$(DSYMUTIL) $@ -test/run-pass/%.bc: test/run-pass/%.rc $(SREQ) - @$(call CFG_ECHO, compile [rustc]: $<) - $(RUSTC) -o $@ $< - -test/run-pass/%.boot$(CFG_EXE_SUFFIX): test/run-pass/%.rs $(BREQ) +%.boot$(CFG_EXE_SUFFIX): %.rs $(BREQ) @$(call CFG_ECHO, compile [boot]: $<) $(BOOT) -o $@ $< -test/run-pass/%.bc: test/run-pass/%.rs $(SREQ) - @$(call CFG_ECHO, compile [rustc]: $<) - $(RUSTC) -o $@ $< - -test/run-fail/%.boot$(CFG_EXE_SUFFIX): test/run-fail/%.rs $(BREQ) +%.boot$(CFG_EXE_SUFFIX): %.rc $(BREQ) @$(call CFG_ECHO, compile [boot]: $<) $(BOOT) -o $@ $< -test/run-fail/%.bc: test/run-fail/%.rs $(SREQ) - @$(call CFG_ECHO, compile [rustc]: $<) - $(RUSTC) -o $@ $< - ###################################################################### # Auto-dependency From 7c810e86f315ab32c1009eb3a480d2b659d15b3a Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 18:35:07 -0500 Subject: [PATCH 2/9] Integrate shootout benchmarks into testsuite --- src/Makefile | 15 ++++++++++++--- src/test/bench/shootout/binary-trees.rs | 10 +++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 8998792da5ad3..a79718843f4f1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -567,7 +567,8 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \ while-type-error.rs \ wrong-ret-type.rs \ ), \ - $(wildcard test/*fail/*.rs test/*fail/*.rc)) + $(wildcard test/*fail/*.rs test/*fail/*.rc)) \ + test/bench/shootout/fasta.rs ifdef MINGW_CROSS @@ -579,8 +580,10 @@ TEST_XFAILS_BOOT += test/run-pass/native-mod.rc TEST_XFAILS_RUSTC += test/run-pass/native-mod.rc endif -RPASS_RC := $(wildcard test/run-pass/*.rc) -RPASS_RS := $(wildcard test/run-pass/*.rs) +BENCH_RC := $(wildcard test/bench/shootout/*rc) +BENCH_RS := $(wildcard test/bench/shootout/*rs) +RPASS_RC := $(wildcard test/run-pass/*.rc) $(BENCH_RC) +RPASS_RS := $(wildcard test/run-pass/*.rs) $(BENCH_RS) RFAIL_RC := $(wildcard test/run-fail/*.rc) RFAIL_RS := $(wildcard test/run-fail/*.rs) CFAIL_RC := $(wildcard test/compile-fail/*.rc) @@ -724,6 +727,12 @@ test/run-pass/%.out.tmp: test/run-pass/%$(CFG_EXE_SUFFIX) $(CFG_RUNTIME) @$(call CFG_ECHO, run: $<) $(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@ +test/bench/shootout/%.out.tmp: test/bench/shootout/%$(CFG_EXE_SUFFIX) \ + $(CFG_RUNTIME) + $(CFG_QUIET)rm -f $<.tmp + @$(call CFG_ECHO, run: $<) + $(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@ + test/run-fail/%.out.tmp: test/run-fail/%$(CFG_EXE_SUFFIX) \ $(CFG_RUNTIME) $(CFG_QUIET)rm -f $<.tmp diff --git a/src/test/bench/shootout/binary-trees.rs b/src/test/bench/shootout/binary-trees.rs index 669cd809915df..5f87943484fe1 100644 --- a/src/test/bench/shootout/binary-trees.rs +++ b/src/test/bench/shootout/binary-trees.rs @@ -1,14 +1,14 @@ tag tree { - nil(); + nil; node(@tree, @tree, int); } -fn item_check(&tree t) -> int { - alt (t) { - case (nil()) { +fn item_check(@tree t) -> int { + alt (*t) { + case (nil) { ret 0; } - case (node(@tree left, @tree right, int item)) { + case (node(?left, ?right, ?item)) { ret item + item_check(left) - item_check(right); } } From 52e6952cf590287ae09372e451e01cb6affe3871 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 20:11:57 -0500 Subject: [PATCH 3/9] Add 99-bottles benchmarks to testsuite --- src/Makefile | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index a79718843f4f1..2f6179c44aa30 100644 --- a/src/Makefile +++ b/src/Makefile @@ -568,8 +568,8 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \ wrong-ret-type.rs \ ), \ $(wildcard test/*fail/*.rs test/*fail/*.rc)) \ - test/bench/shootout/fasta.rs - + test/bench/shootout/fasta.rs \ + $(wildcard test/bench/99-bottles/*rs) ifdef MINGW_CROSS TEST_XFAILS_BOOT += test/run-pass/native-mod.rc @@ -580,9 +580,9 @@ TEST_XFAILS_BOOT += test/run-pass/native-mod.rc TEST_XFAILS_RUSTC += test/run-pass/native-mod.rc endif -BENCH_RC := $(wildcard test/bench/shootout/*rc) -BENCH_RS := $(wildcard test/bench/shootout/*rs) -RPASS_RC := $(wildcard test/run-pass/*.rc) $(BENCH_RC) +BENCH_RS := $(wildcard test/bench/shootout/*rs) \ + $(wildcard test/bench/99-bottles/*rs) +RPASS_RC := $(wildcard test/run-pass/*.rc) RPASS_RS := $(wildcard test/run-pass/*.rs) $(BENCH_RS) RFAIL_RC := $(wildcard test/run-fail/*.rc) RFAIL_RS := $(wildcard test/run-fail/*.rs) @@ -733,6 +733,12 @@ test/bench/shootout/%.out.tmp: test/bench/shootout/%$(CFG_EXE_SUFFIX) \ @$(call CFG_ECHO, run: $<) $(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@ +test/bench/99-bottles/%.out.tmp: test/bench/99-bottles/%$(CFG_EXE_SUFFIX) \ + $(CFG_RUNTIME) + $(CFG_QUIET)rm -f $<.tmp + @$(call CFG_ECHO, run: $<) + $(CFG_QUIET)$(call CFG_RUN_TARG, $<) > $@ + test/run-fail/%.out.tmp: test/run-fail/%$(CFG_EXE_SUFFIX) \ $(CFG_RUNTIME) $(CFG_QUIET)rm -f $<.tmp From a3b3e5c76f6fffc75398ffb1c8c95befea8030d1 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 6 Mar 2011 20:15:03 -0500 Subject: [PATCH 4/9] Remove broken 99-bottles makefile and run script --- src/test/bench/99-bottles/Makefile | 20 -------------------- src/test/bench/99-bottles/r.sh | 3 --- 2 files changed, 23 deletions(-) delete mode 100644 src/test/bench/99-bottles/Makefile delete mode 100755 src/test/bench/99-bottles/r.sh diff --git a/src/test/bench/99-bottles/Makefile b/src/test/bench/99-bottles/Makefile deleted file mode 100644 index 8d1d27f99f839..0000000000000 --- a/src/test/bench/99-bottles/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -RC:=../../../rustboot -RFLAGS:=-L ../../.. -TARGETS:= 99bob-simple 99bob-iter 99bob-tail 99bob-pattern -TARGET_X86:=$(addsuffix .x86,$(TARGETS)) -TARGET_LLVM:=$(addsuffix .llvm,$(TARGETS)) - -all : x86s llvms - -clean: - rm $(TARGET_X86) $(TARGET_LLVM) - -x86s : $(TARGET_X86) - -llvms: $(TARGET_LLVM) - -%.x86 : %.rs - $(RC) $(RFLAGS) $^ -o $@ - -%.llvm : %.rs - $(RC) $(RFLAGS) -llvm $^ -o $@ \ No newline at end of file diff --git a/src/test/bench/99-bottles/r.sh b/src/test/bench/99-bottles/r.sh deleted file mode 100755 index 9da274e41f905..0000000000000 --- a/src/test/bench/99-bottles/r.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -make -k $1.x86 -DYLD_LIBRARY_PATH=../../.. ./$1.x86 From bd84ca8074957cd984c0237529225cf6b665239d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sat, 12 Mar 2011 01:40:32 -0500 Subject: [PATCH 5/9] Mention test/bench in README --- src/README | 1 + 1 file changed, 1 insertion(+) diff --git a/src/README b/src/README index 05d701bd380f6..f3ce45857360d 100644 --- a/src/README +++ b/src/README @@ -24,5 +24,6 @@ test/ Testsuite (for both bootstrap and self-hosted) test/compile-fail - Tests that should fail to compile test/run-fail - Tests that should compile, run and fail test/run-pass - Tests that should compile, run and succeed +test/bench - Benchmarks and miscellanea Please be gentle, it's a work in progress. From ec39c33da6f308466b368a2a4791e00cd20141b0 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 13 Mar 2011 18:29:10 -0400 Subject: [PATCH 6/9] Add _int.pow --- src/lib/_int.rs | 17 +++++++++++++++++ src/test/run-pass/lib-int.rs | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/lib/_int.rs b/src/lib/_int.rs index ee660f013b226..ef1b3b668dee0 100644 --- a/src/lib/_int.rs +++ b/src/lib/_int.rs @@ -34,6 +34,23 @@ fn to_str(mutable int n, uint radix) -> str } } +fn pow(int base, uint exponent) -> int { + + if (exponent == 0u) { + ret 1; + } else if (base == 0) { + ret 0; + } else { + auto accum = base; + auto count = exponent; + while (count > 1u) { + accum *= base; + count -= 1u; + } + ret accum; + } +} + // Local Variables: // mode: rust; // fill-column: 78; diff --git a/src/test/run-pass/lib-int.rs b/src/test/run-pass/lib-int.rs index 153c368338134..2e85abf6509f2 100644 --- a/src/test/run-pass/lib-int.rs +++ b/src/test/run-pass/lib-int.rs @@ -11,6 +11,17 @@ fn test_to_str() { check (eq(_int.to_str(100, 10u), "100")); } +fn test_pow() { + check (_int.pow(0, 0u) == 1); + check (_int.pow(0, 1u) == 0); + check (_int.pow(0, 2u) == 0); + check (_int.pow(-1, 0u) == -1); + check (_int.pow(1, 0u) == 1); + check (_int.pow(-3, 2u) == 9); + check (_int.pow(-3, 3u) == -27); + check (_int.pow(4, 9u) == 262144); +} + fn main() { test_to_str(); } From 51cf5776771ee7d26d0d885ba8b5b7a6f1824a00 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 13 Mar 2011 18:43:39 -0400 Subject: [PATCH 7/9] Implement the rest of the binary trees shootout benchmark --- src/Makefile | 1 + src/test/bench/shootout/binary-trees.rs | 56 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/Makefile b/src/Makefile index 0a56e742902a0..fa84017b2617a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -575,6 +575,7 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \ ), \ $(wildcard test/*fail/*.rs test/*fail/*.rc)) \ test/bench/shootout/fasta.rs \ + test/bench/shootout/binary-trees.rs \ $(wildcard test/bench/99-bottles/*rs) ifdef MINGW_CROSS diff --git a/src/test/bench/shootout/binary-trees.rs b/src/test/bench/shootout/binary-trees.rs index 5f87943484fe1..92bedb8b9e64d 100644 --- a/src/test/bench/shootout/binary-trees.rs +++ b/src/test/bench/shootout/binary-trees.rs @@ -1,3 +1,7 @@ +use std; + +import std._int; + tag tree { nil; node(@tree, @tree, int); @@ -14,5 +18,57 @@ fn item_check(@tree t) -> int { } } +fn bottom_up_tree(int item, int depth) -> @tree{ + if (depth > 0) { + ret @node(bottom_up_tree(2 * item - 1, depth - 1), + bottom_up_tree(2 * item, depth - 1), + item); + } else { + ret @nil; + } +} + fn main() { + + auto n = 8; + auto min_depth = 4; + auto max_depth; + if (min_depth + 2 > n) { + max_depth = min_depth + 2; + } else { + max_depth = n; + } + + auto stretch_depth = max_depth + 1; + + auto stretch_tree = bottom_up_tree(0, stretch_depth); + log #fmt("stretch tree of depth %d\t check: %d", + stretch_depth, item_check(stretch_tree)); + + auto long_lived_tree = bottom_up_tree(0, max_depth); + + auto depth = min_depth; + while (depth <= max_depth) { + auto iterations = _int.pow(2, (max_depth - depth + min_depth) as uint); + auto chk = 0; + + auto i = 1; + while (i <= iterations) { + auto temp_tree = bottom_up_tree(i, depth); + chk += item_check(temp_tree); + + temp_tree = bottom_up_tree(-i, depth); + chk += item_check(temp_tree); + + i += 1; + } + + log #fmt("%d\t trees of depth %d\t check: %d", + iterations * 2, depth, chk); + + depth += 2; + } + + log #fmt("long lived trees of depth %d\t check: %d", + max_depth, item_check(long_lived_tree)); } \ No newline at end of file From 1b506f50133a9c200abc868679f9f5b4f04d732d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 13 Mar 2011 18:53:03 -0400 Subject: [PATCH 8/9] Rename binary trees benchmark to match the original shootout source --- src/Makefile | 2 +- src/test/bench/shootout/{binary-trees.rs => binarytrees.rs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/test/bench/shootout/{binary-trees.rs => binarytrees.rs} (100%) diff --git a/src/Makefile b/src/Makefile index fa84017b2617a..e626b8075319b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -575,7 +575,7 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \ ), \ $(wildcard test/*fail/*.rs test/*fail/*.rc)) \ test/bench/shootout/fasta.rs \ - test/bench/shootout/binary-trees.rs \ + test/bench/shootout/binarytrees.rs \ $(wildcard test/bench/99-bottles/*rs) ifdef MINGW_CROSS diff --git a/src/test/bench/shootout/binary-trees.rs b/src/test/bench/shootout/binarytrees.rs similarity index 100% rename from src/test/bench/shootout/binary-trees.rs rename to src/test/bench/shootout/binarytrees.rs From c7e7369d2ecac8c49e113ae06a950b29211d838d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 13 Mar 2011 21:22:27 -0400 Subject: [PATCH 9/9] Add fannkuchredux shootout benchmark --- src/Makefile | 1 + src/test/bench/shootout/fannkuchredux.rs | 99 ++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 src/test/bench/shootout/fannkuchredux.rs diff --git a/src/Makefile b/src/Makefile index e626b8075319b..edcd9b269f588 100644 --- a/src/Makefile +++ b/src/Makefile @@ -574,6 +574,7 @@ TEST_XFAILS_RUSTC := $(addprefix test/run-pass/, \ wrong-ret-type.rs \ ), \ $(wildcard test/*fail/*.rs test/*fail/*.rc)) \ + test/bench/shootout/fannkuchredux.rs \ test/bench/shootout/fasta.rs \ test/bench/shootout/binarytrees.rs \ $(wildcard test/bench/99-bottles/*rs) diff --git a/src/test/bench/shootout/fannkuchredux.rs b/src/test/bench/shootout/fannkuchredux.rs new file mode 100644 index 0000000000000..2d44067bec33c --- /dev/null +++ b/src/test/bench/shootout/fannkuchredux.rs @@ -0,0 +1,99 @@ +// Based on Isaac Gouy's fannkuchredux.csharp + +use std; + +import std._int; +import std._vec; + +impure fn fannkuch(int n) -> int { + + fn perm1init(uint i) -> mutable int { + ret i as int; + } + auto perm1init_ = perm1init; // Rustboot workaround + + auto perm = _vec.init_elt[mutable int](0, n as uint); + auto perm1 = _vec.init_fn[mutable int](perm1init_, n as uint); + auto count = _vec.init_elt[mutable int](0, n as uint); + + auto f = 0; + auto i = 0; + auto k = 0; + auto r = 0; + auto flips = 0; + auto nperm = 0; + auto checksum = 0; + + r = n; + while (r > 0) { + i = 0; + + while (r != 1) { + count.(r - 1) = r; + r -=1; + } + + while (i < n) { + perm.(i) = perm1.(i); + i += 1; + } + + // Count flips and update max and checksum + f = 0; + k = perm.(0); + while (k != 0) { + i = 0; + while (2 * i < k) { + auto t = perm.(i); + perm.(i) = perm.(k - i); + perm.(k - i) = t; + i += 1; + } + k = perm.(0); + f += 1; + } + + if (f > flips) { + flips = f; + } + + if ((nperm & 0x1) == 0) { + checksum += f; + } else { + checksum -= f; + } + + // Use incremental change to generate another permutation + auto go = true; + while (go) { + if (r == n) { + log checksum; + ret flips; + } + auto p0 = perm1.(0); + i = 0; + while (i < r) { + auto j = i + 1; + perm1.(i) = perm1.(j); + i = j; + } + perm1.(r) = p0; + + count.(r) -= 1; + if (count.(r) > 0) { + go = false; + } else { + r += 1; + } + } + + nperm += 1; + } + + ret flips; +} + +impure fn main(vec[str] args) { + auto n = 7; + log #fmt("Pfannkuchen(%d) = %d", n, fannkuch(n)); +} \ No newline at end of file