From 462a3b82cdc5a44918751360675a13a8ac3a3a7e Mon Sep 17 00:00:00 2001 From: alifarahbakhsh <139010854+alifarahbakhsh@users.noreply.github.com> Date: Wed, 30 Aug 2023 13:28:54 +0000 Subject: [PATCH 1/3] Added palindrome benchmark Benchmark for 6120'23 task 2 --- benchmarks/core/palindrome.bril | 80 +++++++++++++++++++++++++++++++++ benchmarks/core/palindrome.out | 1 + docs/tools/bench.md | 2 + 3 files changed, 83 insertions(+) create mode 100644 benchmarks/core/palindrome.bril create mode 100644 benchmarks/core/palindrome.out diff --git a/benchmarks/core/palindrome.bril b/benchmarks/core/palindrome.bril new file mode 100644 index 000000000..bbfcbdcb3 --- /dev/null +++ b/benchmarks/core/palindrome.bril @@ -0,0 +1,80 @@ +# ARGS: 12321 +@main(in: int) { +#in: int = const 2343553432; +ten: int = const 10; +zero: int = const 0; +one: int = const 1; +index: int = const 1; +not_finished: bool = const true; +.for.cond: + br not_finished .for.body .for.end; +.for.body: + power: int = call @pow ten index; + d: int = div in power; + check: bool = eq d zero; + br check .if.true .if.false; + .if.true: + not_finished: bool = const false; + jmp .for.cond; + .if.false: + index: int = add index one; + jmp .for.cond; +.for.end: + exp: int = sub index one; + is_palindrome: bool = call @palindrome in exp; + print is_palindrome; +} + +@pow(base: int, exp: int): int { +res: int = const 1; +zero: int = const 0; +one: int = const 1; +not_finished: bool = const true; +.for.cond.pow: + br not_finished .for.body.pow .for.end.pow; +.for.body.pow: + finished: bool = eq exp zero; + br finished .if.true.pow .if.false.pow; + .if.true.pow: + not_finished: bool = const false; + jmp .for.cond.pow; + .if.false.pow: + res: int = mul res base; + exp: int = sub exp one; + jmp .for.cond.pow; +.for.end.pow: + ret res; +} + +@palindrome(in: int, len: int): bool { + is_palindrome: bool = const false; + zero: int = const 0; + two: int = const 2; + ten: int = const 10; + check: bool = le len zero; + br check .if.true.palindrome .if.false.palindrome; + .if.true.palindrome: + is_palindrome: bool = const true; + jmp .if.end.palindrome; + .if.false.palindrome: + power: int = call @pow ten len; + left: int = div in power; + v1: int = div in ten; + v2: int = mul v1 ten; + right: int = sub in v2; + is_equal: bool = eq left right; + br is_equal .if.true.mirror .if.false.mirror; + .if.true.mirror: + temp: int = mul power left; + temp: int = sub in temp; + temp: int = sub temp right; + next_in: int = div temp ten; + next_len: int = sub len two; + is_palindrome: bool = call @palindrome next_in next_len; + jmp .if.end.palindrome; + .if.false.mirror: + is_palindrome: bool = const false; + jmp .if.end.palindrome; + .if.end.palindrome: + ret is_palindrome; +} \ No newline at end of file diff --git a/benchmarks/core/palindrome.out b/benchmarks/core/palindrome.out new file mode 100644 index 000000000..f32a5804e --- /dev/null +++ b/benchmarks/core/palindrome.out @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/docs/tools/bench.md b/docs/tools/bench.md index 95445b416..7ed5e25ae 100644 --- a/docs/tools/bench.md +++ b/docs/tools/bench.md @@ -36,6 +36,7 @@ The current benchmarks are: * `n_root`: Calculate nth root of a float using newton's method. * `orders`: Compute the order ord(u) for each u in a cyclic group [][cgroup] of integers modulo *n* under the group operation + (modulo *n*). Set the second argument *is_lcm* to true if you would like to compute the orders using the lowest common multiple and otherwise the program will use the greatest common divisor. * `pascals-row`: Computes a row in Pascal's Triangle. +* `palindrome`: Outputs a 0-1 value indicating whether the input is a [palindrome][palindrome] number. * `perfect`: Check if input argument is a perfect number. Returns output as Unix style return code. * `pow`: Computes the n^th power of a given (float) number. * `primes-between`: Print the primes in the interval `[a, b]`. @@ -77,3 +78,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 +[palindrome]: https://en.wikipedia.org/wiki/Palindrome From b34083c9f37b3bf359ffc895216018d82b473f11 Mon Sep 17 00:00:00 2001 From: alifarahbakhsh <139010854+alifarahbakhsh@users.noreply.github.com> Date: Wed, 30 Aug 2023 16:43:44 +0000 Subject: [PATCH 2/3] Add newline at the end of palindrome.out --- benchmarks/core/palindrome.out | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarks/core/palindrome.out b/benchmarks/core/palindrome.out index f32a5804e..27ba77dda 100644 --- a/benchmarks/core/palindrome.out +++ b/benchmarks/core/palindrome.out @@ -1 +1 @@ -true \ No newline at end of file +true From 3743131847d5a4e20ad17f5764febaf583334aa3 Mon Sep 17 00:00:00 2001 From: alifarahbakhsh <139010854+alifarahbakhsh@users.noreply.github.com> Date: Thu, 31 Aug 2023 03:20:14 +0000 Subject: [PATCH 3/3] Add .prof --- benchmarks/core/palindrome.prof | 1 + 1 file changed, 1 insertion(+) create mode 100644 benchmarks/core/palindrome.prof diff --git a/benchmarks/core/palindrome.prof b/benchmarks/core/palindrome.prof new file mode 100644 index 000000000..29ad635b8 --- /dev/null +++ b/benchmarks/core/palindrome.prof @@ -0,0 +1 @@ +total_dyn_inst: 298