forked from sampsyo/bril
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
139 changed files
with
2,812 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
1 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 | ||
0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
total_dyn_inst: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
total_dyn_inst: 248 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
92 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
total_dyn_inst: 1006454 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
75 100 | ||
44 117 | ||
35 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
total_dyn_inst: 61518 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
total_dyn_inst: 73 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist/ |
Oops, something went wrong.