From e9ed24bd4eb1369c32e3d8da3d870e5a0363e3a7 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Fri, 8 Dec 2023 10:42:41 -0800 Subject: [PATCH] vcacheoptimizer: Tweak condition to help MSVC generate branchless code (#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. --- src/vcacheoptimizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcacheoptimizer.cpp b/src/vcacheoptimizer.cpp index 5cb7743680..e4ecc71d36 100644 --- a/src/vcacheoptimizer.cpp +++ b/src/vcacheoptimizer.cpp @@ -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;