Skip to content

Commit

Permalink
Merge pull request #279 from collinzrj/main
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo authored Aug 31, 2023
2 parents ff58218 + 6af3a75 commit a5ebd57
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
81 changes: 81 additions & 0 deletions benchmarks/core/bitshift.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# ARGS: 3 5 10000 4
@pow(x: int, n: int): int {
v1: int = id n;
v2: int = const 1;
v3: bool = eq v1 v2;
br v3 .then.0 .else.0;
.then.0:
v4: int = id x;
ret v4;
jmp .endif.0;
.else.0:
v5: int = id x;
v6: int = id n;
v7: int = const 2;
v8: int = div v6 v7;
half: int = call @pow v5 v8;
half: int = id half;
v9: int = id half;
v10: int = id half;
v11: int = mul v9 v10;
half2: int = id v11;
v13: int = id n;
v14: int = const 2;
v15: int = call @mod v13 v14;
v16: int = const 1;
v17: bool = eq v15 v16;
br v17 .then.12 .else.12;
.then.12:
v18: int = id half2;
v19: int = id x;
v20: int = mul v18 v19;
ans: int = id v20;
jmp .endif.12;
.else.12:
v21: int = id half2;
ans: int = id v21;
.endif.12:
v22: int = id ans;
ret v22;
.endif.0:
}
@mod(a: int, b: int): int {
v0: int = id a;
v1: int = id a;
v2: int = id b;
v3: int = div v1 v2;
v4: int = id b;
v5: int = mul v3 v4;
v6: int = sub v0 v5;
ret v6;
}
@LEFTSHIFT(x: int, step: int): int {
v0: int = const 2;
v1: int = id step;
p: int = call @pow v0 v1;
p: int = id p;
v2: int = id x;
v3: int = id p;
v4: int = mul v2 v3;
ret v4;
}
@RIGHTSHIFT(x: int, step: int): int {
v0: int = const 2;
v1: int = id step;
p: int = call @pow v0 v1;
p: int = id p;
v2: int = id x;
v3: int = id p;
v4: int = div v2 v3;
ret v4;
}
@main(a: int, b: int, c: int, d: int) {
v2: int = id a;
v3: int = id b;
ans1: int = call @LEFTSHIFT v2 v3;
print ans1;
v4: int = id c;
v5: int = id d;
ans2: int = call @RIGHTSHIFT v4 v5;
print ans2;
}
2 changes: 2 additions & 0 deletions benchmarks/core/bitshift.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
96
625
1 change: 1 addition & 0 deletions benchmarks/core/bitshift.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 167
1 change: 1 addition & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The current benchmarks are:
* `binary-fmt`: Print the binary format for the given positive integer.
* `binary-search`: Search a target integer within an integer array, outputs the index of target.
* `bitwise-ops`: Computes the OR, AND, or XOR between two 64-bit integers. (Three modes: 0 = AND, 1 = OR, 2 = XOR)
* `bitshift`: Computes the LEFTSHIFT and RIGHTSHIFT for any integer, also implements an efficient pow function for integers
* `bubblesort`: Sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
* `catalan`: Print the *n*th term in the [Catalan][catalan] sequence, compute using recursive function calls.
* `check-primes`: Check the first *n* natural numbers for primality, printing out a 1 if the number is prime and a 0 if it's not.
Expand Down

0 comments on commit a5ebd57

Please sign in to comment.