in reply to
Re: The 10**21 Problem (Part 3)

in thread The 10**21 Problem (Part 3)

Thanks for the great ideas to try.
I suspect you work in this domain in your day job, is that right?
In any case, you seem to have a lot more experience in HPC than me.

I was able to quickly test one of your
excellent tips:

*
Better still: prefetch the data needed for next loop iteration, that is vecM[m7next].
It will then be ready at the right time.
*

Simply changing the inner loop from:

`for (q7 = 1; q7 < 128; ++q7) {
if (q7 == 10 || q7 == 13) continue;
m7 = (m6 ^ q7) * H_PRIME;
s7 = _mm_mullo_epi32(_mm_xor_si128(s6, _mm_set1_epi32(q7)), hp);
_mm_prefetch(&bytevecM[(unsigned int)m7 & 0xffffff80], _MM_HINT_T0
+);
_mm_prefetch(&bytevecM[64+((unsigned int)m7 & 0xffffff80)], _MM_HI
+NT_T0);
UNROLL(1)
UNROLL(2)
UNROLL(3)
UNROLL(4)
UNROLL(5)
UNROLL(6)
UNROLL(7)
UNROLL(8)
UNROLL(9)
UNROLL(11)
UNROLL(12)
for (q8 = 14; q8 < 128; ++q8) {
UNROLL(q8)
}
}
`

to two inner loops:

`for (q7 = 1; q7 < 128; ++q7) {
if (q7 == 10 || q7 == 13) continue;
m7 = (m6 ^ q7) * H_PRIME;
m7arr[q7] = m7;
_mm_prefetch(&bytevecM[(unsigned int)m7 & 0xffffff80], _MM_HINT_T0
+);
_mm_prefetch(&bytevecM[64+((unsigned int)m7 & 0xffffff80)], _MM_HI
+NT_T0);
}
for (q7 = 1; q7 < 128; ++q7) {
if (q7 == 10 || q7 == 13) continue;
m7 = m7arr[q7];
s7 = _mm_mullo_epi32(_mm_xor_si128(s6, _mm_set1_epi32(q7)), hp);
UNROLL(1)
UNROLL(2)
UNROLL(3)
UNROLL(4)
UNROLL(5)
UNROLL(6)
UNROLL(7)
UNROLL(8)
UNROLL(9)
UNROLL(11)
UNROLL(12)
for (q8 = 14; q8 < 128; ++q8) {
UNROLL(q8)
}
}
`

reduced the running time by 11 seconds, from 48 seconds to 37 seconds (371 to 286 years).
The cost of the extra loop and storing 128 m7 values in an array is well worth
it to reduce memory latency.

Update: This variation was 43 seconds, six seconds slower:

`for (q7 = 1; q7 < 128; ++q7) {
if (q7 == 10 || q7 == 13) continue;
m7 = (m6 ^ q7) * H_PRIME;
m7arr[q7] = m7;
_mm_prefetch(&bytevecM[(unsigned int)m7 & 0xffffff80], _MM_HINT_T0
+);
_mm_prefetch(&bytevecM[64+((unsigned int)m7 & 0xffffff80)], _MM_HI
+NT_T0);
s7 = _mm_mullo_epi32(_mm_xor_si128(s6, _mm_set1_epi32(q7)), hp);
s7arr[q7] = s7;
}
for (q7 = 1; q7 < 128; ++q7) {
if (q7 == 10 || q7 == 13) continue;
m7 = m7arr[q7];
s7 = s7arr[q7];
// ... same UNROLL as before
}
`