Skip to content

Commit d065eed

Browse files
committed
Micro optimization
1 parent ca6c832 commit d065eed

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/Global.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,27 @@ void Global::computeHistogram(const byte block[], int length, uint freqs[], bool
177177
uint f2[256] = { 0 };
178178
uint f3[256] = { 0 };
179179
const uint8* end16 = reinterpret_cast<const uint8*>(&block[length & -16]);
180+
uint64 q;
180181

181182
while (p < end16) {
182-
f0[p[0]]++;
183-
f1[p[1]]++;
184-
f2[p[2]]++;
185-
f3[p[3]]++;
186-
f0[p[4]]++;
187-
f1[p[5]]++;
188-
f2[p[6]]++;
189-
f3[p[7]]++;
190-
f0[p[8]]++;
191-
f1[p[9]]++;
192-
f2[p[10]]++;
193-
f3[p[11]]++;
194-
f0[p[12]]++;
195-
f1[p[13]]++;
196-
f2[p[14]]++;
197-
f3[p[15]]++;
183+
memcpy(&q, &p[0], 8);
184+
f0[uint8(q>>56)]++;
185+
f1[uint8(q>>48)]++;
186+
f2[uint8(q>>40)]++;
187+
f3[uint8(q>>32)]++;
188+
f0[uint8(q>>24)]++;
189+
f1[uint8(q>>16)]++;
190+
f2[uint8(q>>8)]++;
191+
f3[uint8(q)]++;
192+
memcpy(&q, &p[8], 8);
193+
f0[uint8(q>>56)]++;
194+
f1[uint8(q>>48)]++;
195+
f2[uint8(q>>40)]++;
196+
f3[uint8(q>>32)]++;
197+
f0[uint8(q>>24)]++;
198+
f1[uint8(q>>16)]++;
199+
f2[uint8(q>>8)]++;
200+
f3[uint8(q)]++;
198201
p += 16;
199202
}
200203

0 commit comments

Comments
 (0)