Skip to content

Commit

Permalink
Merge pull request sampsyo#266 from he-andy/main
Browse files Browse the repository at this point in the history
Add vectorization/simd benchmark
  • Loading branch information
sampsyo authored Aug 30, 2023
2 parents 61db389 + 883b43b commit 38c867f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions benchmarks/mem/vsmul.bril
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@rand(seq: ptr<int>, max: int) : int {
a: int = const 25214903917;
c: int = const 11;
m: int = const 281474976710656;
x: int = load seq;
ax: int = mul a x;
axpc: int = add ax c;
next: int = div axpc m;
next: int = mul next m;
next: int = sub axpc next;
store seq next;
val: int = div next max;
val: int = mul val max;
val: int = sub next val;
ret val;
}

# Generates a random array of length `size`
@randarray(size: int, rng: ptr<int>) : ptr<int> {
arr: ptr<int> = alloc size;
i: int = const 0;
max: int = const 1000;
one: int = const 1;
.loop:
cond: bool = lt i size;
br cond .body .done;
.body:
val: int = call @rand rng max;
loc: ptr<int> = ptradd arr i;
store loc val;
.loop_end:
i: int = add i one;
jmp .loop;
.done:
ret arr;
}

# ARGS: 4096 2023
@main(size: int, seed: int) {
two: int = const 2;
rng: ptr<int> = alloc seed;
store rng seed;
arr: ptr<int> = call @randarray size rng;
i: int = const 0;
.loop:
cond: bool = lt i size;
br cond .body .done;
.body:
loc: ptr<int> = ptradd arr i;
val: int = load loc;
val: int = mul val two;
store loc val;
.done:
free arr;
free rng;
}
Empty file added benchmarks/mem/vsmul.out
Empty file.
1 change: 1 addition & 0 deletions benchmarks/mem/vsmul.prof
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
total_dyn_inst: 86036
1 change: 1 addition & 0 deletions docs/tools/bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The current benchmarks are:
* `sum-divisors`: Prints the positive integer divisors of the input integer, followed by the sum of the divisors.
* `sum-sq-diff`: Output the difference between the sum of the squares of the first *n* natural numbers and the square of their sum.
* `up-arrow`: Computes [Knuth's up arrow][uparrow] notation, with the first argument being the number, the second argument being the number of Knuth's up arrows, and the third argument being the number of repeats.
* `vsmul`: Multiplies a constant scalar to each element of a large array. Tests the performance of vectorization optimizations.
* `reverse`: Compute number with reversed digits (e.g. 123 -> 321).

Credit for several of these benchmarks goes to Alexa VanHattum and Gregory Yauney, who implemented them for their [global value numbering project][gvnblog].
Expand Down

0 comments on commit 38c867f

Please sign in to comment.