Skip to content

Commit

Permalink
Removed a branch from HashTable::SetControlValue (#1360)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouwe authored Nov 27, 2024
1 parent cb9cc9b commit 7e83db6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Jolt/Core/HashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,14 @@ class HashTable
JPH_ASSERT(inIndex < mMaxSize);
mControl[inIndex] = inValue;

// Mirror the first 15 bytes at the end of the control values
if (inIndex < 15)
mControl[mMaxSize + inIndex] = inValue;
// Mirror the first 15 bytes to the 15 bytes beyond mMaxSize
// Note that this is equivalent to:
// if (inIndex < 15)
// mControl[inIndex + mMaxSize] = inValue
// else
// mControl[inIndex] = inValue
// Which performs a needless write if inIndex >= 15 but at least it is branch-less
mControl[((inIndex - 15) & (mMaxSize - 1)) + 15] = inValue;
}

/// Get the index and control value for a particular key
Expand Down

0 comments on commit 7e83db6

Please sign in to comment.