Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bit Shift Benchmark #279

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider removing this dead jump and associated label? While this doesn't affect an interpreter, this trips up both brilift and brillvm as during compilation they get tricked in generating empty returns for the final label.

This could be fixed in both tools, but it's kind of a weird edge case the more I looked into it. I lean more towards this should be avoided in benchmark files than this is worth the added complexity in the above tools.

Is this a bug in the typescript compiler?

Let me know what you think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question about whether this is something the TypeScript compiler should avoid… maybe a good step for investigating this would be to try to reproduce it with a minimal TS program that produces this weird CFG pattern?

.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