Skip to content

Commit

Permalink
vcacheoptimizer: Tweak condition to help MSVC generate branchless code (
Browse files Browse the repository at this point in the history
#639)

gcc/clang lower the condition to cmov sequence but MSVC uses branches
here; it's important to use branchless lowering as these branches are
difficult to predict. This change makes optimizeVertexCache ~7% faster
on MSVC on large meshes.
  • Loading branch information
zeux authored Dec 8, 2023
1 parent abb12d3 commit e9ed24b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/vcacheoptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void meshopt_optimizeVertexCacheTable(unsigned int* destination, const unsigned
unsigned int index = cache[i];

cache_new[cache_write] = index;
cache_write += (index != a && index != b && index != c);
cache_write += (index != a) & (index != b) & (index != c);
}

unsigned int* cache_temp = cache;
Expand Down

0 comments on commit e9ed24b

Please sign in to comment.