Previously, the input[i] was strength reduced to advance by 4 and the loop was made downwards counted; that's no longer the case, leading to worse code gen.
Windows diff (.NET9 vs .NET10): https://www.diffchecker.com/VvxRltlX/
Code in compiler explorer: https://godbolt.org/z/bbdhnP16c
public static unsafe void RadixSort(Span<int> input, Span<int> output, Vector128<float>[] mins, Vector128<float>[] maxs, int axis)
{
const int radixSize = 11;
const int binSize = 1 << radixSize;
const int mask = binSize - 1;
const int passes = 3;
int* prefixSum = stackalloc int[binSize * passes];
// Compute histogram for all passes
for (int i = 0; i < input.Length; i++)
{
uint key = GetKey(input[i]);
GetPrefixSumRef(key, 0)++;
GetPrefixSumRef(key, 1)++;
GetPrefixSumRef(key, 2)++;
}
ref int GetPrefixSumRef(uint key, int pass)
{
uint radix = (key >> (pass * radixSize)) & mask;
ref int offset = ref prefixSum[radix + pass * binSize];
return ref offset;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
uint GetKey(int el)
{
return FloatToKey(mins[el][axis] + maxs[el][axis]);
}
}
Previously, the
input[i]was strength reduced to advance by 4 and the loop was made downwards counted; that's no longer the case, leading to worse code gen.Windows diff (.NET9 vs .NET10): https://www.diffchecker.com/VvxRltlX/
Code in compiler explorer: https://godbolt.org/z/bbdhnP16c