Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hj424 committed Dec 7, 2020
2 parents e7d128f + 8042ac1 commit 28f5541
Show file tree
Hide file tree
Showing 139 changed files with 2,812 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ There are some quick-start instructions below for some of the main tools, but
check out the docs for more details about what's available.

[docs]: https://capra.cs.cornell.edu/bril/
[langref]: https://capra.cs.cornell.edu/bril/langref.html
[langref]: https://capra.cs.cornell.edu/bril/lang/index.html
[brilts]: https://github.com/sampsyo/bril/blob/master/bril-ts/bril.ts


Expand Down Expand Up @@ -65,5 +65,5 @@ Install it with [pip][]:
Then run all the tests by typing `make test`.

[pip]: https://packaging.python.org/tutorials/installing-packages/
[cs6120]: https://www.cs.cornell.edu/courses/cs6120/2019fa/
[cs6120]: https://www.cs.cornell.edu/courses/cs6120/2020fa/
[turnt]: https://github.com/cucapra/turnt
26 changes: 26 additions & 0 deletions benchmarks/binary-fmt.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ARGS: 128
@main(n: int) {
call @printBinary n;
}

@printBinary(n: int) {
zero: int = const 0;
cond: bool = eq n zero;
br cond .end .rec;
.rec:
two: int = const 2;
v0: int = call @mod n two;
v1: int = div n two;
call @printBinary v1;
print v0;
.end:
}

@mod(a0: int, a1: int) : int {
v0: int = div a0 a1;
v1: int = mul v0 a1;
v2: int = sub a0 v1;
ret v2;
}


8 changes: 8 additions & 0 deletions benchmarks/binary-fmt.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1
0
0
0
0
0
0
0
1 change: 1 addition & 0 deletions benchmarks/binary-fmt.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 100
51 changes: 51 additions & 0 deletions benchmarks/digital-root.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ARGS: 645634654

# Computes the digital root of the given argument. This is done by iteratively
# adding each digit together until the result is a single number.
# This is equivalent to the input mod 9 except if that value would be zero
# in which case the digital root is nine.

@main(input: int) {
zero: int = const 0;
ten: int = const 10;
result: int = const 0;
.begin:
digit: int = call @peel_last_digit input;
input: int = div input ten;
result: int = add result digit;

.check_result:
print result;
processed: bool = call @is_single_digit result;
br processed .check_done .process_result;
.process_result:
r0: int = call @peel_last_digit result;
result: int = div result ten;
result: int = add result r0;
jmp .check_result;

.check_done:
done: bool = eq input zero;
br done .done .begin;

.done:
print result;
ret result;
}

@is_single_digit(input: int): bool {
ten: int = const 10;
zero: int = const 0;
divided: int = div input ten;
mul_by_ten: int = mul divided ten;
result: bool = eq mul_by_ten zero;
ret result;
}

@peel_last_digit(input: int): int {
ten: int = const 10;
div_by_ten: int = div input ten;
mul_by_ten: int = mul div_by_ten ten;
last_digit: int = sub input mul_by_ten;
ret last_digit;
}
14 changes: 14 additions & 0 deletions benchmarks/digital-root.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
4
9
15
6
10
1
4
10
1
6
10
1
7
7
1 change: 1 addition & 0 deletions benchmarks/digital-root.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 248
70 changes: 70 additions & 0 deletions benchmarks/eight-queens.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# ARGS: 8
@main(input: int) {
n: int = id input;
zero: int = const 0;
icount: int = id zero;
site: ptr<int> = alloc n;
result: int = call @queen zero n icount site;
print result;
free site;
}
@queen(n: int, queens: int, icount: int, site: ptr<int>): int {
one: int = const 1;
ite: int = id one;
ret_cond: bool = eq n queens;
br ret_cond .next.ret .for.cond;
.next.ret:
icount: int = add icount one;
ret icount;
.for.cond:
for_cond_0: bool = le ite queens;
br for_cond_0 .for.body .next.ret.1;
.for.body:
nptr: ptr<int> = ptradd site n;
store nptr ite;
is_valid: bool = call @valid n site;
br is_valid .rec.func .next.loop;
.rec.func:
n_1: int = add n one;
icount: int = call @queen n_1 queens icount site;
.next.loop:
ite: int = add ite one;
jmp .for.cond;
.next.ret.1:
ret icount;
}
@valid(n: int, site: ptr<int>): bool {
zero: int = const 0;
one: int = const 1;
true: bool = eq one one;
false: bool = eq zero one;
ite: int = id zero;
.for.cond:
for_cond: bool = lt ite n;
br for_cond .for.body .ret.end;
.for.body:
iptr: ptr<int> = ptradd site ite;
nptr: ptr<int> = ptradd site n;
help_0: int = const 500;
vali: int = load iptr;
valn: int = load nptr;
eq_cond_0: bool = eq vali valn;
br eq_cond_0 .true.ret.0 .false.else;
.true.ret.0:
ret false;
.false.else:
sub_0: int = sub vali valn;
sub_1: int = sub valn vali;
sub_2: int = sub n ite;
eq_cond_1: bool = eq sub_0 sub_2;
eq_cond_2: bool = eq sub_1 sub_2;
eq_cond_12: bool = or eq_cond_1 eq_cond_2;
br eq_cond_12 .true.ret.1 .false.loop;
.true.ret.1:
ret false;
.false.loop:
ite: int = add ite one;
jmp .for.cond;
.ret.end:
ret true;
}
1 change: 1 addition & 0 deletions benchmarks/eight-queens.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
92
1 change: 1 addition & 0 deletions benchmarks/eight-queens.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 1006454
41 changes: 41 additions & 0 deletions benchmarks/pythagorean_triple.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ARGS: 125

# Checks to see if the given n is the long side of
# a Pythagorean triple in the most naive way possible.
# If a pair of sides a and b are found, then they are
# printed; otherwise, nothing is printed. If there are
# multiple triples for the given n then all are printed.

@main(n: int) {
one: int = const 1;

n_sq: int = mul n n;

a: int = id one;

.outer_loop:
b: int = id one;

.inner_loop:
a_sq: int = mul a a;
b_sq: int = mul b b;
sum: int = add a_sq b_sq;

found: bool = eq sum n_sq;
br found .found .inner_continue;

.found:
print b a;

.inner_continue:
b: int = add b one;
done: bool = ge b a;
br done .outer_continue .inner_loop;

.outer_continue:
a: int = add a one;
done: bool = ge a n;
br done .finish .outer_loop;

.finish:
}
3 changes: 3 additions & 0 deletions benchmarks/pythagorean_triple.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
75 100
44 117
35 120
1 change: 1 addition & 0 deletions benchmarks/pythagorean_triple.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 61518
2 changes: 1 addition & 1 deletion benchmarks/sieve.bril
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# Find the next value `p` in `table` that's greater than
# `currentP`, and is not marked. If there are no numbers
# in the table left that meet those criteria, return 0.
@findNextP(table: ptr<book>, tableSize: int, currentP: int) : int {
@findNextP(table: ptr<bool>, tableSize: int, currentP: int) : int {
zero: int = const 0;
one: int = const 1;
p: int = id currentP;
Expand Down
25 changes: 25 additions & 0 deletions benchmarks/sum-bits.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ARGS: 42
@main(input : int) {
sum : int = const 0;
two : int = const 2;
zero : int = const 0;
.loop:
cond : bool = eq input zero;
br cond .done .body;
.body:
bit : int = call @mod input two;
input : int = div input two;
sum : int = add sum bit;
jmp .loop;
.done:
print sum;
ret;
}

@mod(dividend : int, divisor : int) : int {
quotient : int = div dividend divisor;
two : int = const 2;
prod : int = mul two quotient;
diff : int = sub dividend prod;
ret diff;
}
1 change: 1 addition & 0 deletions benchmarks/sum-bits.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions benchmarks/sum-bits.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 73
1 change: 1 addition & 0 deletions brench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
Loading

0 comments on commit 28f5541

Please sign in to comment.