Tech News
← Back to articles

The Weird Concept of Branchless Programming

read original related products more articles

THE WEIRD CONCEPT OF 'BRANCHLESS PROGRAMMING'

2025-07-08 01:37 • 19+ min read • #c #branchless

DISCLAIMERS

If you came for readable code, sorry, branchless programming is basically code golf with caffeine.

Code examples are going to be ran in C code.

Drastic measures (e.g. -O3 -ffast-math -march=native -fomit-this-entire-function ) were taken.

0×00 FUNKY INTRODUCTION

Modern CPUs are predictive creatures. They guess what you're about to do, like a nosy algorithm trying to sell you sneakers after you Googled "foot pain." Branch predictors make CPUs fast by speculating on branches... until they guess wrong and everything grinds to a halt for 15,20 cycles.

Branchless programming is how we get around this: we rewrite our code to not branch at all. Instead of jumping to conclusions, we manipulate bits like 1980s assembly gremlins.

WHAT IS A BRANCH

... continue reading