Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmwilliams authored Aug 31, 2023
2 parents f5e9b9f + 3d971e4 commit 34c3087
Show file tree
Hide file tree
Showing 19 changed files with 666 additions and 0 deletions.
65 changes: 65 additions & 0 deletions benchmarks/core/dot-product.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
@dot_product(vectorA: ptr<int>, vectorB: ptr<int>, size: int): int {
one: int = const 1;
index: int = const 0;
answer: int = const 0;
.loop:
ptrA: ptr<int> = ptradd vectorA index;
ptrB: ptr<int> = ptradd vectorB index;
valA: int = load ptrA;
valB: int = load ptrB;
tmp: int = mul valA valB;
answer: int = add answer tmp;
index: int = add index one;
cond: bool = lt index size;
br cond .loop .done;
.done:
ret answer;
}

@main {
a: int = const 25;
b: int = const 50;
c: int = const 100;
d: int = const 150;
e: int = const 250;
f: int = const 2;
g: int = const 10;
h: int = const 20;
i: int = const 30;
j: int = const 40;
one: int = const 1;
zero: int = const 0;
size: int = const 5;

# Create and fill vectorA
vectorA: ptr<int> = alloc size;
indexPtr: ptr<int> = ptradd vectorA zero;
store indexPtr a;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr b;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr c;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr d;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr e;

# Create and fill vectorB
vectorB: ptr<int> = alloc size;
indexPtr: ptr<int> = ptradd vectorB zero;
store indexPtr f;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr g;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr h;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr i;
indexPtr: ptr<int> = ptradd indexPtr one;
store indexPtr j;

val: int = call @dot_product vectorA vectorB size;
print val;

free vectorA;
free vectorB;
}
1 change: 1 addition & 0 deletions benchmarks/core/dot-product.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
17050
1 change: 1 addition & 0 deletions benchmarks/core/dot-product.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 88
90 changes: 90 additions & 0 deletions benchmarks/core/mod_inv.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# ARGS: 46, 10007
@main(n: int, p: int) {
v0: int = const 2;
two: int = id v0;
v1: int = id p;
v2: int = id two;
v3: int = sub v1 v2;
m: int = id v3;
v4: int = const 1;
ans: int = id v4;
v5: int = id n;
a: int = id v5;
v7: int = const 1;
i: int = id v7;
.for.cond.6:
v8: int = id m;
v9: int = const 0;
v10: bool = gt v8 v9;
br v10 .for.body.6 .for.end.6;
.for.body.6:
v12: int = id m;
v13: int = id m;
v14: int = id two;
v15: int = div v13 v14;
v16: int = id two;
v17: int = mul v15 v16;
v18: bool = eq v12 v17;
br v18 .then.11 .else.11;
.then.11:
jmp .endif.11;
.else.11:
v19: int = id ans;
v20: int = id a;
v21: int = mul v19 v20;
v22: int = id p;
v23: int = call @mod v21 v22;
ans: int = id v23;
.endif.11:
v24: int = id a;
v25: int = id a;
v26: int = mul v24 v25;
v27: int = id p;
v28: int = call @mod v26 v27;
a: int = id v28;
v29: int = id m;
v30: int = id two;
v31: int = div v29 v30;
m: int = id v31;
jmp .for.cond.6;
.for.end.6:
v32: int = id ans;
print v32;
v33: int = const 0;
}
@mod(n: int, p: int): int {
v0: int = id n;
v1: int = id n;
v2: int = id p;
v3: int = div v1 v2;
v4: int = id p;
v5: int = mul v3 v4;
v6: int = sub v0 v5;
ret v6;
}

# ts2bril inv.ts | bril2txt | tail +3 | sed -E 's/float/int/g' | sed -E 's/fgt/gt/g' > inv.bril
# generated by typescript code below:
#
# function main(n: bigint, p: bigint) {
# var two: bigint = 2;
# var m: bigint = p - two;
# var ans: bigint = 1;
# var a: bigint = n;
# for (let i = 1; m > 0; m = m / two) {
# if (m == m / two * two) {
# }
# else {
# ans = mod(ans * a, p);
# }
# a = mod(a * a, p);
# }
# console.log(ans);
# }
#
# function mod(n: bigint, p: bigint): bigint {
# return n - n / p * p;
# }
#


1 change: 1 addition & 0 deletions benchmarks/core/mod_inv.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2393
1 change: 1 addition & 0 deletions benchmarks/core/mod_inv.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 558
80 changes: 80 additions & 0 deletions benchmarks/core/palindrome.bril
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions benchmarks/core/palindrome.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
1 change: 1 addition & 0 deletions benchmarks/core/palindrome.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 298
66 changes: 66 additions & 0 deletions benchmarks/core/totient.bril
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 2 additions & 0 deletions benchmarks/core/totient.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
2023
1632
1 change: 1 addition & 0 deletions benchmarks/core/totient.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 253
Loading

0 comments on commit 34c3087

Please sign in to comment.