From cbd6407b931ef1ec95c96bc5fc8b657300ea55bb Mon Sep 17 00:00:00 2001 From: Omkar Bhalerao Date: Wed, 30 Aug 2023 15:19:20 -0400 Subject: [PATCH] add euler's totient function benchmark --- benchmarks/core/totient.bril | 66 ++++++++++++++++++++++++++++++++++++ benchmarks/core/totient.out | 2 ++ benchmarks/core/totient.prof | 1 + 3 files changed, 69 insertions(+) create mode 100644 benchmarks/core/totient.bril create mode 100644 benchmarks/core/totient.out create mode 100644 benchmarks/core/totient.prof diff --git a/benchmarks/core/totient.bril b/benchmarks/core/totient.bril new file mode 100644 index 000000000..02ac090e2 --- /dev/null +++ b/benchmarks/core/totient.bril @@ -0,0 +1,66 @@ +# ARGS: 2023 +@main (n: int) { + print n; + tot: int = call @totient n; + print tot; +} + +@totient (n: int): int { + result: int = id n; + p: int = const 2; + one: int = const 1; + zero: int = const 0; + +.for.set.cond: + pp: int = mul p p; + cond: bool = le pp n; + br cond .for.set.body .for.set.end; + +.for.set.body: + + npmod: int = call @mod n p; + if_cond: bool = eq npmod zero; + br if_cond .if_lbl .else_lbl; +.if_lbl: + +.while.set.cond: + + npmod: int = call @mod n p; + while_cond: bool = eq npmod zero; + br while_cond .while.body .while.end; + +.while.body: + npdiv: int = div n p; + n: int = id npdiv; + jmp .while.set.cond; + +.while.end: + + resdiv: int = div result p; + result: int = sub result resdiv; + +.else_lbl: + + p: int = add p one; + jmp .for.set.cond; + +.for.set.end: + + final_if_cond: bool = gt n one; + br final_if_cond .final_if_label .final_else_label; + +.final_if_label: + resdiv: int = div result n; + result: int = sub result resdiv; + +.final_else_label: + + ret result; +} + +@mod (a: int, b: int): int { + ad: int = div a b; + mad: int = mul b ad; + ans: int = sub a mad; + ret ans; +} diff --git a/benchmarks/core/totient.out b/benchmarks/core/totient.out new file mode 100644 index 000000000..0dd06b31d --- /dev/null +++ b/benchmarks/core/totient.out @@ -0,0 +1,2 @@ +2023 +1632 diff --git a/benchmarks/core/totient.prof b/benchmarks/core/totient.prof new file mode 100644 index 000000000..d8c8e70f1 --- /dev/null +++ b/benchmarks/core/totient.prof @@ -0,0 +1 @@ +total_dyn_inst: 253