diff --git a/benchmarks/core/dot-product.bril b/benchmarks/core/dot-product.bril new file mode 100644 index 000000000..0f044b989 --- /dev/null +++ b/benchmarks/core/dot-product.bril @@ -0,0 +1,65 @@ +@dot_product(vectorA: ptr, vectorB: ptr, size: int): int { + one: int = const 1; + index: int = const 0; + answer: int = const 0; +.loop: + ptrA: ptr = ptradd vectorA index; + ptrB: ptr = ptradd vectorB index; + valA: int = load ptrA; + valB: int = load ptrB; + tmp: int = mul valA valB; + answer: int = add answer tmp; + index: int = add index one; + cond: bool = lt index size; + br cond .loop .done; +.done: + ret answer; +} + +@main { + a: int = const 25; + b: int = const 50; + c: int = const 100; + d: int = const 150; + e: int = const 250; + f: int = const 2; + g: int = const 10; + h: int = const 20; + i: int = const 30; + j: int = const 40; + one: int = const 1; + zero: int = const 0; + size: int = const 5; + + # Create and fill vectorA + vectorA: ptr = alloc size; + indexPtr: ptr = ptradd vectorA zero; + store indexPtr a; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr b; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr c; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr d; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr e; + + # Create and fill vectorB + vectorB: ptr = alloc size; + indexPtr: ptr = ptradd vectorB zero; + store indexPtr f; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr g; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr h; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr i; + indexPtr: ptr = ptradd indexPtr one; + store indexPtr j; + + val: int = call @dot_product vectorA vectorB size; + print val; + + free vectorA; + free vectorB; +} diff --git a/benchmarks/core/dot-product.out b/benchmarks/core/dot-product.out new file mode 100644 index 000000000..038b87558 --- /dev/null +++ b/benchmarks/core/dot-product.out @@ -0,0 +1 @@ +17050 diff --git a/benchmarks/core/dot-product.prof b/benchmarks/core/dot-product.prof new file mode 100644 index 000000000..1e1f19cef --- /dev/null +++ b/benchmarks/core/dot-product.prof @@ -0,0 +1 @@ +total_dyn_inst: 88 diff --git a/docs/tools/bench.md b/docs/tools/bench.md index 949923543..6a67b2f22 100644 --- a/docs/tools/bench.md +++ b/docs/tools/bench.md @@ -21,6 +21,7 @@ The current benchmarks are: * `conjugate-gradient`: Uses conjugate gradients to solve `Ax=b` for any arbitrary positive semidefinite `A`. * `cordic`: Print an approximation of sine(radians) using 8 iterations of the [CORDIC algorithm](https://en.wikipedia.org/wiki/CORDIC). * `digial-root`: Computes the digital root of the input number. +* `dot-product`: Computes the dot product of two vectors. * `eight-queens`: Counts the number of solutions for *n* queens problem, a generalization of [Eight queens puzzle][eight_queens]. * `euclid`: Calculates the greatest common divisor between two large numbers using the [Euclidean Algorithm][euclid] with a helper function for the modulo operator. * `euler`: Approximates [Euler's number][euler] using the Taylor series.