Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
NgaiJustin committed Sep 7, 2023
2 parents 61e4344 + 4923027 commit 23af9ab
Show file tree
Hide file tree
Showing 23 changed files with 1,370 additions and 1 deletion.
47 changes: 47 additions & 0 deletions benchmarks/core/birthday.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ARGS: 23
@main(n: float) {
v0: float = id n;
c: float = call @probability v0;
c: float = id c;
v1: float = id c;
print v1;
v2: int = const 0;
}
@probability(n: float): float {
v0: float = const 1;
prob: float = id v0;
v2: float = const 1;
i: float = id v2;
.for.cond.1:
v3: float = id i;
v4: float = id n;
v5: bool = flt v3 v4;
br v5 .for.body.1 .for.end.1;
.for.body.1:
v6: float = const 365;
v7: float = id i;
v8: float = fsub v6 v7;
log: float = id v8;
v9: float = id log;
v10: float = const 365;
v11: float = fdiv v9 v10;
logUpdated: float = id v11;
v12: float = id prob;
v13: float = id logUpdated;
v14: float = fmul v12 v13;
prob: float = id v14;
v15: float = id i;
v16: float = const 1;
v17: float = fadd v15 v16;
i: float = id v17;
jmp .for.cond.1;
.for.end.1:
v18: float = const 1;
v19: float = id prob;
v20: float = const 100;
v21: float = fmul v19 v20;
v22: float = const 100;
v23: float = fdiv v21 v22;
v24: float = fsub v18 v23;
ret v24;
}
1 change: 1 addition & 0 deletions benchmarks/core/birthday.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.50729723432398566
1 change: 1 addition & 0 deletions benchmarks/core/birthday.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 484
16 changes: 16 additions & 0 deletions benchmarks/core/fitsinside.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ARGS: 12 4 5 13
@main (width1:int, height1:int, width2:int, height2:int){
output: bool = call @fitsInside width1 height1 width2 height2;
print output;
}

@fitsInside(w1: int, h1: int, w2: int, h2: int) : bool {
width_check: bool = le w1 w2;
height_check: bool = le h1 h2;
first_check: bool = and width_check height_check;
widthheight_check: bool = le w1 h2;
heightwidth_check: bool = le h1 w2;
second_check: bool = and widthheight_check heightwidth_check;
ret_val: bool = or first_check second_check;
ret ret_val;
}
1 change: 1 addition & 0 deletions benchmarks/core/fitsinside.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
1 change: 1 addition & 0 deletions benchmarks/core/fitsinside.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 10
34 changes: 34 additions & 0 deletions benchmarks/core/lcm.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ARGS: 64 24
@main(x: int, y: int) {
greater: int = id y;
v4: bool = gt x y;
br v4 .then.1 .else.1;
.then.1:
greater: int = id x;
jmp .endif.1;
.else.1:
.endif.1:
.foreverloop:
modX : int = call @getMod greater x;
modY : int = call @getMod greater y;
zero: int = const 0;
xZero : bool = eq modX zero;
yZero : bool = eq modY zero;
bothZero : bool = and xZero yZero;
br bothZero .then.2 .else.2;
.then.2:
print greater;
jmp .loopend;
.else.2:
one: int = const 1;
greater:int = add greater one;
jmp .foreverloop;
.loopend:
}

@getMod(val: int, mod: int): int{
divisor: int = div val mod;
multiple: int = mul divisor mod;
rem: int = sub val multiple;
ret rem;
}
1 change: 1 addition & 0 deletions benchmarks/core/lcm.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
192
1 change: 1 addition & 0 deletions benchmarks/core/lcm.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 2326
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
Loading

0 comments on commit 23af9ab

Please sign in to comment.