Document and streamline GPU candidate kernel guards
This commit is contained in:
1 parent
4d8ea9dccd
commit
5b973fb513
1 file changed
+21
-36
@@ -25,47 +25,32 @@ internal static class DivisorByDivisorKernels
|
|||||||
GpuUInt128 stride)
|
GpuUInt128 stride)
|
||||||
{
|
{
|
||||||
int globalIndex = index;
|
int globalIndex = index;
|
||||||
int candidateLength = (int)candidates.Length;
|
// EvenPerfectBitScanner always launches this kernel with an extent matching the candidate view length,
|
||||||
if (globalIndex >= candidateLength)
|
// so the bounds guard stays commented out to keep the hot path branch-free.
|
||||||
{
|
// int candidateLength = (int)candidates.Length;
|
||||||
return;
|
// if (globalIndex >= candidateLength)
|
||||||
}
|
// {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
ulong offset = (ulong)globalIndex;
|
ulong offset = (ulong)globalIndex;
|
||||||
GpuUInt128 candidateValue;
|
GpuUInt128 candidateValue = stride;
|
||||||
if (offset == 0UL)
|
candidateValue.Mul(offset);
|
||||||
{
|
candidateValue.Add(startValue);
|
||||||
candidateValue = startValue;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
candidateValue = stride;
|
|
||||||
candidateValue.Mul(offset);
|
|
||||||
candidateValue.Add(startValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
candidates[globalIndex] = candidateValue.Low;
|
candidates[globalIndex] = candidateValue.Low;
|
||||||
|
|
||||||
int gapLength = (int)gaps.Length;
|
// The scanner supplies gap buffers that mirror the candidate view length,
|
||||||
if (globalIndex >= gapLength)
|
// so the additional bounds guard remains commented out for the same reason as above.
|
||||||
{
|
// int gapLength = (int)gaps.Length;
|
||||||
return;
|
// if (globalIndex >= gapLength)
|
||||||
}
|
// {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
if (offset == 0UL)
|
ulong previousOffset = offset > 0UL ? offset - 1UL : 0UL;
|
||||||
{
|
GpuUInt128 previousValue = stride;
|
||||||
gaps[globalIndex] = 0UL;
|
previousValue.Mul(previousOffset);
|
||||||
return;
|
previousValue.Add(startValue);
|
||||||
}
|
|
||||||
|
|
||||||
GpuUInt128 previousValue = startValue;
|
|
||||||
ulong previousOffset = offset - 1UL;
|
|
||||||
if (previousOffset != 0UL)
|
|
||||||
{
|
|
||||||
GpuUInt128 scaledStride = stride;
|
|
||||||
scaledStride.Mul(previousOffset);
|
|
||||||
previousValue.Add(scaledStride);
|
|
||||||
}
|
|
||||||
|
|
||||||
GpuUInt128 gapValue = candidateValue;
|
GpuUInt128 gapValue = candidateValue;
|
||||||
gapValue.Sub(previousValue);
|
gapValue.Sub(previousValue);
|
||||||
|
|||||||
Reference in new issue
Block a user