aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-25 14:33:25 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2022-09-18 10:59:24 +0000
commit15fe741ca71f55a1d516ae42be4f36dab87ae284 (patch)
tree314e91eda2414eb466e52973c09a90f457f377f1
parent588c0a6cde62871760d8f85b621f451b63e9af03 (diff)
Move helper methods.
-rw-r--r--vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp b/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp
index 76072aa6906..a58de582547 100644
--- a/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp
+++ b/vespalib/src/vespa/vespalib/hwaccelrated/private_helpers.hpp
@@ -8,6 +8,56 @@
namespace vespalib::hwaccelrated::helper {
namespace {
+template <typename ACCUM, typename T, size_t UNROLL>
+ACCUM
+multiplyAdd(const T * a, const T * b, size_t sz)
+{
+ ACCUM partial[UNROLL];
+ for (size_t i(0); i < UNROLL; i++) {
+ partial[i] = 0;
+ }
+ size_t i(0);
+ for (; i + UNROLL <= sz; i+= UNROLL) {
+ for (size_t j(0); j < UNROLL; j++) {
+ partial[j] += a[i+j] * b[i+j];
+ }
+ }
+ for (;i < sz; i++) {
+ partial[i%UNROLL] += a[i] * b[i];
+ }
+ ACCUM sum(0);
+ for (size_t j(0); j < UNROLL; j++) {
+ sum += partial[j];
+ }
+ return sum;
+}
+
+template<size_t UNROLL, typename Operation>
+void
+bitOperation(Operation operation, void * aOrg, const void * bOrg, size_t bytes) {
+
+ const size_t sz(bytes/sizeof(uint64_t));
+ {
+ uint64_t *a(static_cast<uint64_t *>(aOrg));
+ const uint64_t *b(static_cast<const uint64_t *>(bOrg));
+ size_t i(0);
+ for (; i + UNROLL <= sz; i += UNROLL) {
+ for (size_t j(0); j < UNROLL; j++) {
+ a[i + j] = operation(a[i + j], b[i + j]);
+ }
+ }
+ for (; i < sz; i++) {
+ a[i] = operation(a[i], b[i]);
+ }
+ }
+
+ uint8_t *a(static_cast<uint8_t *>(aOrg));
+ const uint8_t *b(static_cast<const uint8_t *>(bOrg));
+ for (size_t i(sz*sizeof(uint64_t)); i < bytes; i++) {
+ a[i] = operation(a[i], b[i]);
+ }
+}
+
inline size_t
populationCount(const uint64_t *a, size_t sz) {
size_t count(0);