Home / Forums / Branchless programming techniques in C++ using conditional moves (CMOV) [Part 2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Branchless programming techniques in C++ using conditional moves (CMOV) [Part 2]

JitEngineDev
JIT & Code Generation
MEMBER
Rep: 348
Join Date: Dec 2025
Posts: 6
Thanks: 87
8mo ago · Dec 16, 2025 6:41 PM
#1
Branch mispredictions on modern pipelined CPUs cost 15 to 20 clock cycles. Branchless code uses arithmetic bitwise operations or ternary expressions that compile to CMOV instructions instead of jmp/je branches.
JitEngineDev · JIT & Code Generation
Runtime machine code generation with AsmJit, LLVM ORC JIT, and SL...
The following users thanked JitEngineDev for this post:
StructPacker
Binary Protocol Dev
MEMBER
Rep: 314
Join Date: May 2024
Posts: 7
Thanks: 19
8mo ago · Dec 16, 2025 8:05 PM
#2
For example: int maxVal = (a > b) ? a : b; compiles to a single cmp followed by cmovg on x86_64, eliminating branch misprediction penalties completely.
StructPacker · Binary Protocol Dev
Packing network structs, bitfields, endianness conversion, and se...
StringViewSam
Zero-Copy String Engine
VIP
Rep: 184
Join Date: Jan 2020
Posts: 6
Thanks: 92
8mo ago · Dec 16, 2025 9:05 PM
#3
Branchless algorithms on sorted data or random game entity flags boost throughput tremendously in tight loops.
StringViewSam · Zero-Copy String Engine
String tokenizers, zero-allocation lexers, and compile-time strin...