Skip to content

Commit fefd521

Browse files
committed
Add dot product implementation using std::inner_product
Signed-off-by: Stefan Weil <[email protected]>
1 parent 7d3e132 commit fefd521

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/arch/simddetect.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// limitations under the License.
1616
///////////////////////////////////////////////////////////////////////
1717

18+
#include <numeric> // for std::inner_product
1819
#include "simddetect.h"
1920
#include "dotproduct.h"
2021
#include "dotproductavx.h"
@@ -69,6 +70,11 @@ static double DotProductGeneric(const double* u, const double* v, int n) {
6970
return total;
7071
}
7172

73+
// Compute dot product using std::inner_product.
74+
static double DotProductStdInnerProduct(const double* u, const double* v, int n) {
75+
return std::inner_product(u, u + n, v, 0.0);
76+
}
77+
7278
static void SetDotProduct(DotProductFunction f, const IntSimdMatrix* m = nullptr) {
7379
DotProduct = f;
7480
IntSimdMatrix::intSimdMatrix = m;
@@ -185,6 +191,10 @@ void SIMDDetect::Update() {
185191
SetDotProduct(DotProductSSE, &IntSimdMatrix::intSimdMatrixSSE);
186192
dotproduct_method = "sse";
187193
#endif
194+
} else if (!strcmp(dotproduct.string(), "std::inner_product")) {
195+
// std::inner_product selected by config variable.
196+
SetDotProduct(DotProductStdInnerProduct);
197+
dotproduct_method = "std::inner_product";
188198
} else {
189199
// Unsupported value of config variable.
190200
tprintf("Warning, ignoring unsupported config variable value: dotproduct=%s\n",
@@ -196,7 +206,7 @@ void SIMDDetect::Update() {
196206
#if defined(SSE4_1)
197207
" sse"
198208
#endif
199-
".\n");
209+
" std::inner_product.\n");
200210
}
201211

202212
dotproduct.set_value(dotproduct_method);

0 commit comments

Comments
 (0)