Skip to content

Commit

Permalink
Simplify hllDenseRegHisto()
Browse files Browse the repository at this point in the history
In HyperLogLog, every register has 6 bits and every 8 registers can be
processed with same logic. Therefore, the code for handling 16 registers
can be simplified to only handle 8.
  • Loading branch information
panzhongxian committed Apr 7, 2024
1 parent 4581d43 commit c346ce5
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions src/hyperloglog.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,10 +504,9 @@ void hllDenseRegHisto(uint8_t *registers, int* reghisto) {
* we take a faster path with unrolled loops. */
if (HLL_REGISTERS == 16384 && HLL_BITS == 6) {
uint8_t *r = registers;
unsigned long r0, r1, r2, r3, r4, r5, r6, r7, r8, r9,
r10, r11, r12, r13, r14, r15;
for (j = 0; j < 1024; j++) {
/* Handle 16 registers per iteration. */
unsigned long r0, r1, r2, r3, r4, r5, r6, r7;
for (j = 0; j < 2048; j++) {
/* Handle 8 registers per iteration. */
r0 = r[0] & 63;
r1 = (r[0] >> 6 | r[1] << 2) & 63;
r2 = (r[1] >> 4 | r[2] << 4) & 63;
Expand All @@ -516,14 +515,6 @@ void hllDenseRegHisto(uint8_t *registers, int* reghisto) {
r5 = (r[3] >> 6 | r[4] << 2) & 63;
r6 = (r[4] >> 4 | r[5] << 4) & 63;
r7 = (r[5] >> 2) & 63;
r8 = r[6] & 63;
r9 = (r[6] >> 6 | r[7] << 2) & 63;
r10 = (r[7] >> 4 | r[8] << 4) & 63;
r11 = (r[8] >> 2) & 63;
r12 = r[9] & 63;
r13 = (r[9] >> 6 | r[10] << 2) & 63;
r14 = (r[10] >> 4 | r[11] << 4) & 63;
r15 = (r[11] >> 2) & 63;

reghisto[r0]++;
reghisto[r1]++;
Expand All @@ -533,16 +524,8 @@ void hllDenseRegHisto(uint8_t *registers, int* reghisto) {
reghisto[r5]++;
reghisto[r6]++;
reghisto[r7]++;
reghisto[r8]++;
reghisto[r9]++;
reghisto[r10]++;
reghisto[r11]++;
reghisto[r12]++;
reghisto[r13]++;
reghisto[r14]++;
reghisto[r15]++;

r += 12;

r += 6;
}
} else {
for(j = 0; j < HLL_REGISTERS; j++) {
Expand Down

0 comments on commit c346ce5

Please sign in to comment.