From 0d2f423cec902068b76fa6d0e4905a13c75963bc Mon Sep 17 00:00:00 2001 From: bcarlet <8906114+bcarlet@users.noreply.github.com> Date: Tue, 29 Aug 2023 23:08:24 -0400 Subject: [PATCH] Add Hanoi benchmark --- benchmarks/core/hanoi.bril | 26 ++++++++++++++++++++++++++ benchmarks/core/hanoi.out | 7 +++++++ benchmarks/core/hanoi.prof | 1 + docs/tools/bench.md | 2 ++ 4 files changed, 36 insertions(+) create mode 100644 benchmarks/core/hanoi.bril create mode 100644 benchmarks/core/hanoi.out create mode 100644 benchmarks/core/hanoi.prof diff --git a/benchmarks/core/hanoi.bril b/benchmarks/core/hanoi.bril new file mode 100644 index 000000000..c32df92d5 --- /dev/null +++ b/benchmarks/core/hanoi.bril @@ -0,0 +1,26 @@ +# Three-disk Tower of Hanoi puzzle. +# +# Moves are printed in order, one on each line, where a move `src dst` indicates +# that the top disk from rod `src` should be moved to rod `dst`. + +@hanoi (disk: int, src: int, dst: int, spare: int) { + zero: int = const 0; + nonneg: bool = ge disk zero; + br nonneg .then .else; +.then: + one: int = const 1; + above: int = sub disk one; + call @hanoi above src spare dst; + print src dst; + call @hanoi above spare dst src; +.else: + ret; +} + +@main { + disk: int = const 2; + src: int = const 0; + dst: int = const 2; + spare: int = const 1; + call @hanoi disk src dst spare; +} diff --git a/benchmarks/core/hanoi.out b/benchmarks/core/hanoi.out new file mode 100644 index 000000000..57c7c1bc4 --- /dev/null +++ b/benchmarks/core/hanoi.out @@ -0,0 +1,7 @@ +0 2 +0 1 +2 1 +0 2 +1 0 +1 2 +0 2 diff --git a/benchmarks/core/hanoi.prof b/benchmarks/core/hanoi.prof new file mode 100644 index 000000000..a02ef5fe2 --- /dev/null +++ b/benchmarks/core/hanoi.prof @@ -0,0 +1 @@ +total_dyn_inst: 100 diff --git a/docs/tools/bench.md b/docs/tools/bench.md index 4cbcf3906..bc1602c58 100644 --- a/docs/tools/bench.md +++ b/docs/tools/bench.md @@ -28,6 +28,7 @@ The current benchmarks are: * `fizz-buzz`: The infamous [programming test][fizzbuzz]. * `function_call`: For benchmarking the overhead of simple function calls. * `gcd`: Calculate Greatest Common Divisor (GCD) of two input positive integer using [Euclidean algorithm][euclidean_into]. +* `hanoi`: Print the solution to the 3-disk [Tower of Hanoi][hanoi] puzzle. * `loopfact`: Compute *n!* imperatively using a loop. * `mandelbrot`: Generates a really low resolution, ascii, [mandelbrot set][mandelbrot]. * `mat-inv` : Calculates the inverse of a 3x3 matrix and prints it out. @@ -78,3 +79,4 @@ Credit for several of these benchmarks goes to Alexa VanHattum and Gregory Yaune [uparrow]: https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation [riemann]: https://en.wikipedia.org/wiki/Riemann_sum [mandelbrot]: https://en.wikipedia.org/wiki/Mandelbrot_set +[hanoi]: https://en.wikipedia.org/wiki/Tower_of_Hanoi