From c23c694affb76b79cdf71003249ce4ca3868b46e Mon Sep 17 00:00:00 2001 From: noraabiakar <nora.abiakar@gmail.com> Date: Fri, 18 Jan 2019 14:42:24 +0100 Subject: [PATCH] Optimize vectorized compound_indexed_add (#673) * Optimize "none" index_constraint specialization of compound_indexed_add, so that it only reads/writes each distinct memory index once per vector. Related to issue #637. --- include/arbor/simd/simd.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/arbor/simd/simd.hpp b/include/arbor/simd/simd.hpp index 4a319216..535b8233 100644 --- a/include/arbor/simd/simd.hpp +++ b/include/arbor/simd/simd.hpp @@ -220,9 +220,15 @@ namespace simd_detail { scalar_type a[width]; Impl::copy_to(s, a); - for (unsigned i = 0; i<width; ++i) { - p[o[i]] += a[i]; + scalar_type temp = 0; + for (unsigned i = 0; i<width-1; ++i) { + temp += a[i]; + if (o[i] != o[i+1]) { + p[o[i]] += temp; + temp = 0; + } } + p[o[width-1]] = temp; } break; case index_constraint::independent: -- GitLab