From ba6d5d00d97ba11ce4a61a2c98cf8b75131d8aa8 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 30 Jul 2020 02:10:11 +0300 Subject: [PATCH] Apply one of the variants --- src/AggregateFunctions/IAggregateFunction.h | 57 ++++++++++++++------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/src/AggregateFunctions/IAggregateFunction.h b/src/AggregateFunctions/IAggregateFunction.h index a0876d457b8..251cf521d1a 100644 --- a/src/AggregateFunctions/IAggregateFunction.h +++ b/src/AggregateFunctions/IAggregateFunction.h @@ -222,24 +222,6 @@ public: static_cast(this)->add(places[i] + place_offset, columns, i, arena); } - void addBatchLookupTable8( - size_t batch_size, - AggregateDataPtr * places, - size_t place_offset, - std::function init, - const UInt8 * key, - const IColumn ** columns, - Arena * arena) const override - { - for (size_t i = 0; i < batch_size; ++i) - { - AggregateDataPtr & place = places[key[i]]; - if (unlikely(!place)) - init(place); - static_cast(this)->add(place + place_offset, columns, i, arena); - } - } - void addBatchSinglePlace(size_t batch_size, AggregateDataPtr place, const IColumn ** columns, Arena * arena) const override { for (size_t i = 0; i < batch_size; ++i) @@ -274,6 +256,45 @@ public: current_offset = next_offset; } } + + void addBatchLookupTable8( + size_t batch_size, + AggregateDataPtr * map, + size_t place_offset, + std::function init, + const UInt8 * key, + const IColumn ** columns, + Arena * arena) const override + { + static constexpr size_t UNROLL_COUNT = 8; + + size_t i = 0; + + size_t batch_size_unrolled = batch_size / UNROLL_COUNT * UNROLL_COUNT; + for (; i < batch_size_unrolled; i += UNROLL_COUNT) + { + AggregateDataPtr places[UNROLL_COUNT]; + for (size_t j = 0; j < UNROLL_COUNT; ++j) + { + AggregateDataPtr & place = map[key[i + j]]; + if (unlikely(!place)) + init(place); + + places[j] = place; + } + + for (size_t j = 0; j < UNROLL_COUNT; ++j) + static_cast(this)->add(places[j] + place_offset, columns, i + j, arena); + } + + for (; i < batch_size; ++i) + { + AggregateDataPtr & place = map[key[i]]; + if (unlikely(!place)) + init(place); + static_cast(this)->add(place + place_offset, columns, i, arena); + } + } };