proost commented on code in PR #553:
URL: https://github.com/apache/datasketches-cpp/pull/553#discussion_r4410084597
##########
hll/include/Hll8Array-internal.hpp:
##########
@@ -120,30 +120,26 @@ void Hll8Array<A>::mergeHll(const HllArray<A>& src) {
// we can optimize further when the k values are equal
if (this->getLgConfigK() == src.getLgConfigK()) {
if (src.getTgtHllType() == target_hll_type::HLL_8) {
+ // Hoist the data pointer out of the loop to encourage vectorization
+ uint8_t* data = this->hllByteArr_.data();
uint32_t i = 0;
for (const auto value: src.getHllArray()) {
- this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
+ data[i] = std::max(data[i], value);
++i;
}
} else if (src.getTgtHllType() == target_hll_type::HLL_6) {
const uint32_t src_k = 1 << src.getLgConfigK();
- uint32_t i = 0;
- const uint8_t* ptr = src.getHllArray().data();
- while (i < src_k) {
- uint8_t value = *ptr & 0x3f;
- this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
- ++i;
- value = *ptr++ >> 6;
- value |= (*ptr & 0x0f) << 2;
- this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
- ++i;
- value = *ptr++ >> 4;
- value |= (*ptr & 3) << 4;
- this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
- ++i;
- value = *ptr++ >> 2;
- this->hllByteArr_[i] = std::max(this->hllByteArr_[i], value);
- ++i;
+ const uint8_t* src_data = src.getHllArray().data();
+ uint8_t* data = this->hllByteArr_.data();
+ for (uint32_t i = 0, j = 0; i < src_k; i += 4, j += 3) {
Review Comment:
```
const size_t num_groups = src_k / 4;
for (size_t g = 0; g < num_groups; ++g) {
const size_t i = 4 * g;
const size_t j = 3 * g;
```
##########
hll/include/Hll8Array-internal.hpp:
##########
@@ -120,30 +120,26 @@ void Hll8Array<A>::mergeHll(const HllArray<A>& src) {
// we can optimize further when the k values are equal
if (this->getLgConfigK() == src.getLgConfigK()) {
if (src.getTgtHllType() == target_hll_type::HLL_8) {
+ // Hoist the data pointer out of the loop to encourage vectorization
+ uint8_t* data = this->hllByteArr_.data();
Review Comment:
```
const uint8_t* src_data = src.getHllArray().data();
const size_t n = src.getHllArray().size();
for (size_t i = 0; i < n; ++i) {
data[i] = std::max(data[i], src_data[i]);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]