diff --git a/magyarsort.h b/magyarsort.h index 65812f4..667bcf7 100644 --- a/magyarsort.h +++ b/magyarsort.h @@ -89,6 +89,9 @@ namespace MagyarSort { static inline void countOccurences(uint32_t arr[], COUNTER_TYP size, COUNTER_TYP *radicsOut) noexcept { #pragma GCC unroll 64 for(COUNTER_TYP i = 0; i < size; ++i) { + // Prefetch caches + __builtin_prefetch(&arr[i]); // TODO: is good? + __builtin_prefetch(&arr[i + 64]); // Creates no object, struct is empty OccurenceMagic(arr, i, radicsOut); } @@ -139,6 +142,9 @@ namespace MagyarSort { #pragma GCC unroll 64 for(COUNTER_TYP i = size; i > 0; --i) { // right-to-left to ensure already sorted digits order we keep for iterations + // Prefetch caches + __builtin_prefetch(&from[i]); // TODO: is good? + if(i >= 64) { __builtin_prefetch(&from[i - 64]); } // TODO: manually unroll? // Get num and its new offset / location auto num = from[i - 1]; auto digVal = getDigit(num);