Skip to content

Commit

Permalink
Add sum-check benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur-Chang016 committed Aug 31, 2023
1 parent 111d864 commit d1dcfd3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions benchmarks/core/sum-check.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# compute the sum of [1, n] by both loop and formula
# and compare them to see if the result is the same

# ARGS: 1000
@main(n: int) {
first: int = call @sum_by_loop n;
second: int = call @sum_by_formula n;
isSame: bool = eq first second;
print first;
print second;
print isSame;
}

@sum_by_loop(n: int): int {
one: int = const 1;
sum: int = const 0;
i: int = const 1;

.for_start:
con: bool = le i n;
br con .for .end;
.for:
sum: int = add sum i;
i: int = add i one;
jmp .for_start;
.end:
ret sum;
}

# sum = (1 + n) * n / 2
@sum_by_formula(n: int): int {
one: int = const 1;
two: int = const 2;
n_1: int = add one n;
multi: int = mul n_1 n;
sum: int = div multi two;
ret sum;
}
3 changes: 3 additions & 0 deletions benchmarks/core/sum-check.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
500500
500500
true
1 change: 1 addition & 0 deletions benchmarks/core/sum-check.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 5018

0 comments on commit d1dcfd3

Please sign in to comment.